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

example range-series.html has extra, unused, dimension and group #1537

Open joergplewe opened 5 years ago

joergplewe commented 5 years ago

example range-series.html reads like that:

ndx = crossfilter(experiments);
  runDimension = ndx.dimension(function(d) {return [+d.Expt, +d.Run]; });
  overviewRunDimension = ndx.dimension(function(d) {return [+d.Expt, +d.Run]; });
  runGroup = runDimension.group().reduceSum(function(d) { return +d.Speed; });
  overviewRunGroup = overviewRunDimension.group().reduceSum(function(d) { return +d.Speed; });

Hence, overviewRunDimension and overviewRunGroup are never used, which confuses newbies (like myself)

OTOH I cannot understand why this works at all. If overviewChart sets a filter on runDimension it should not have any effect on runGroup due to https://github.com/crossfilter/crossfilter/wiki/Crossfilter-Gotchas#a-group-does-not-observe-its-dimensions-filters

Next, in case doing it presumably right (using overviewRunDimension and overviewRunGroup in overviewChart) it does not work any more. All values go to 0 in case of filtering.

Additionially. is there a constraint that a charts dimension and group need to be related?

Confused, thanks in advance,

. J

gordonwoodhull commented 5 years ago

Yeah, you're right, overviewRunDimension and overviewRunGroup shouldn't be there. They must have been a mistake in development which I forgot to remove.

Focus and range charts will almost always be on the same dimension (and group). Normally you don't want them to filter each other. (Arguably you may not want them to filter other charts, and just use them as a navigational aid, but that's the way dc.js works by default. This example disables filtering.)

For the same reason, you'll usually want a chart's group to be associated with the chart's dimension, because you don't want the chart to filter itself. It's not a hard and fast rule, but there are very few situations where it makes sense to do it another way.

gordonwoodhull commented 5 years ago

I'll leave this open as reminder to remove the dead code, but general support questions are better suited for Stack Overflow.

I'm not really clear on your question "I cannot understand why this works at all". Why what works? Focus/range charts bind the zoom of one chart to the brush of another chart. That's separate from the filtering - as I mentioned in the other issue, charts don't pull range information from crossfilter dimension filters.

In part because they can't (no getter), in part because there is no magic binding between charts. It's just brush => set a dimension filter => redraw all charts => read data from groups. There is less "framework" than you might expect.

The issue tracker is for reporting bugs and making enhancement requests, not for general support questions. Please ask on Stack Overflow with the dc.js tag, or on the user group, and we will be glad to help you there.

When you post, creating a fiddle or a block demonstrating the problem, will help others help you. You can fork this fiddle or this block to get started!

joergplewe commented 5 years ago

Thank you Gordon, I will head over to the media you mention.

Just to answer you question and bring that to an end here:

overviewChart, when brushing, sets a filter on runDimension, right? focusChart then renders runGroup, right? As well es overviewChart does itself?

But runGroup should not be affected by filters on runDimension, otherwise overviewChart would always show it's own brush.

But ok, I meanwhile found that https://github.com/crossfilter/crossfilter/wiki/Crossfilter-Gotchas#a-group-does-not-observe-its-dimensions-filters explicitely mentions that case:

One exception is when multiple charts display and/or filter the same dimension, for example in dc.js range/focus charts where one chart zooms to the range selected in another chart. Although you typically want other charts to reflect this selection, if the range chart were affected by the focus chart, you'd see it droop to zero outside of the filtered area. This pattern can be extended to multiple charts all displaying or manipulating the same filter.

I just don't get it, must be due to some basic misconception of mine. I will read that as often until I understand....

Thank you for your support and your patience of me misusing the issue tracker!!

gordonwoodhull commented 5 years ago

It always takes a little time for the crossfilter & dc.js concepts to sink in. They are simple but non-intuitive. Took me months to finally get all of it.

I think you've got the main idea, though. Feel free to ask any specific questions you may have.