dc.js - d3-tip on dc-js chart disappears upon filtering over 0-valued group -
i have number of graphs, simplicity take this example on jsfiddle, there brush-on graph, bar chart keyed on time , row chart keyed on categories. in addition, use d3-tip
library tooltips (in link above simplified version of tip).
in order avoid creation of bar-row in rowchart
, used fake-group outlined in faq of dc-js
(and here well).
the fake group works well, not displaying c
category on row chart.
however, if brush on months 0 data, when reset filter (just click anywhere filtered region on brushon chart), d3-tip
on row chart disappears.
notice if group created without fake-grouping-function, problem not arise.
- any explanation why happens?
- how avoid (without loosing
remove_empty_bins
)?
although can use dc.js , d3.js interchangeably, , dc.js intentionally "leaky abstraction", things go better if them idiomatic dc.js way.
i have 2 suggestions:
- apply tooltips in response dc.js events reapplied when new graphical objects created (or re-created).
- use chart.selectall instead of
d3.selectall
when modifying charts.
okay, #2 has no bearing on question, scope selects better it's harder them miss chart or accidentally modify stuff elsewhere in page.
implementing #1 looks this:
month_chart.on('pretransition', function(chart) { chart.selectall('rect.bar').call(month_tip) .on('mouseover', month_tip.show).on('mouseout', month_tip.hide); }); loc_chart1.on('pretransition', function(chart) { chart.selectall('g.row').call(loc_tip) .on('mouseover', loc_tip.show).on('mouseout', loc_tip.hide); });
the pretransition event fires right after render or redraw, it's best moment manipulate dc's elements. better running code globally. set up, call dc.renderall()
, allow renders , redraws take care of later on.
in particular, when bars added in when remove_empty_bins
stops removing them, these events pick them , re-tip them.
fork of fiddle: https://jsfiddle.net/gordonwoodhull/5fel3gko/4/
Comments
Post a Comment