سؤال

I'm working on a dashboard builded with d3, dc and crossfilter. the dataset is a tsv like this:
ID type val
1 pop 10000
1 var 100
2 pop 15000
2 var -500
etc...

the first dimension I make is on "type" column and I filter it to use only I indicator type. In this case the absolute value of population "pop" per municipality
than using dc.js I make a map (with scale.threshold or scale.quantize) and some chart with the dataset filtered in this way.

I also have a button that allow to change the "type" filter to use the other indicator in the dataset. In this example "var" is the number of new resident in a municipality.
this is the code that update the dimension.filter on button click:

$(settings.container + " > button").click(function() {
      //change the active state of the button
      $(settings.container + " > button").removeClass('active');
      $(this).addClass('active');

      //get the name of the indicator type to be filtered from the data-filter button attribute
      var val = $(this).attr('data-filter');


      if(val){// if data-filter exist -> filter the crossfilter dimension
          prinDashboard.dim[settings.dim.dim].filter(val);
      }else{// else filterAll
          prinDashboard.dim[settings.dim.dim].filterAll();
      }

      //redraw all the dc chart and mapp
      dc.redrawAll();
  })

dc.js take care of all the map and chart updating and all work fine but the map scale doesn't update to fit the new dataset.
for example if I initially define a scale.quantize that output these 5 brakes:0-5000, 5000-1000, 10000-15000, 15000-20000, 20000-25000 When I update the dataset the "var" values are also fitted in these brakes that are now meaningless.
What I want is to be able to rebuild the scale with the new dataset and than update the map.
Is there any way to do this in dc? or how can I "hack" what dc does using plain d3?

I'll really appreciate any idea!

Thanks

هل كانت مفيدة؟

المحلول

Have you tried calculateColorDomain?

I don't think you should need to do this, but a number of things don't automatically rescale in dc.js when they should.

Another more hacky thing you could do is simply reassign the color scale. That's pretty awful though.

Whether or not you come up with a solution, please file an issue. The color scale should be recalculated automatically.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top