dc-js / dc.js

Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js
Apache License 2.0
7.42k stars 1.81k forks source link

Alternate approach to Ordinal Brushing #1809

Closed kum-deepak closed 3 years ago

kum-deepak commented 3 years ago

This approach makes a key assumption that brushing makes logical sense only if the underlying data has a defined order.

In this approach:

The brushing and re-sorting, in my opinion, do not go well together. For example, if there is a selection and the data get re-sorted (for example because of activities on the other charts), the selection will now include different items, which may not be intended. In my opinion, unless there is a natural ordering in the data, range brushing does not make logical sense.

kum-deepak commented 3 years ago

In dc-v5, this approach simplifies http://127.0.0.1:8888/web/examples/focus-ordinal-bar.html significantly, with hardly any code that relies on the internal workings of dc. Please see commit https://github.com/dc-js/dc.js/pull/1810/commits/bf81f80211dfaa292fab47fbc2caf59907c8abc9.

gordonwoodhull commented 3 years ago

I agree this is a lot simpler and easier to understand, and also that it is a mess if there is an active selection when the domain gets rearranged. It's great not to have to use a filterHandler.

However, mapping the keys only at the start also precludes the use of remove_empty_bins() and streaming data.

Generally dc.js charts do try to adapt when the domain changes. That's why there was a fake group in the original example - it updated the mapping each time data was pulled. It is really messy to combine mapping and fake group, for sure, but that's the reason it was that way.

I think you've done three simplifications here:

  1. using the integers instead of ordinals throughout
  2. separating logic into a Mapper
  3. only read the set of keys once when the chart is first drawn

I think 1 and 2 are real improvements, but 3 may not work in all situations. So I'm merging this but preserving the old example under the name brush-ordinal-dynamic.