1

I am trying to create a timechart to show the number of rooms occupied in a different scenarios using dc.js. To reduce data transmission, my room occupancy data is represented by discrete start and end times.

[{"room": "1", "start":"10/13/2018 08:10", "end":"10/18/2018 17:43"}, {"room":"2", "start":"10/15/2018 12:51", "end":"10/24/2018 19:17"}, {"room":"3", "start":"10/11/2018 23:09", "end":"11/01/2018 11:44"}]

All the examples I have seen have discrete event times - is there a better way to show date ranges, or manipulate the group/dimension to provide counts/time?

Jernigan
  • 11
  • 3

1 Answers1

1

I assume you want to aggregate over each time interval by counting the number of occupancies whose intervals intersect with that interval.

The reason you haven't seen too many examples is that it requires a specialized data structure called an interval tree to do it efficiently.

Some time ago I created an example using interval trees. It uses an interval tree library by Mikola Lysenko.

To illustrate how different this kind of filtering is, this chart will filter itself, i.e. its own bars will change as you brush over it. This behavior is different from most other dc.js/crossfilter charts - notice how many of the other bars outside of the range remain when you brush, because there are rows whose time intervals intersect both the brush and that bar's interval.

If you want the normal "don't filter yourself" behavior you can change

      projectsPerMonthTree = ndx.groupAll().reduce(

to

      projectsPerMonthTree = intervalDimension.groupAll().reduce(
Gordon
  • 19,811
  • 4
  • 36
  • 74