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