javascript - d3 v4 + react + es6 + crossfilter: Selection.exit().remove() not working -


i'm using crossfilter.js , d3.js v4 es6 style react in attempt make dimensional charts context brushing. essentially, took this example , converted es6.

the problem have selection.exit().remove() not working such on each redraw, more , more circles appended svg g element. redraws triggered when brush created. checked running

selection.exit()   .attr('class', d => {     console.log('anything');     return 'anything';   })   .remove(); 

but nothing outputted i'm thinking data selection not valid.

here context:

componentdidmount() {   const el = reactdom.finddomnode(this); // mounted svg element    const svg = d3.select(el)     .attr('width', 300)     .attr('height', 500);    const g = svg.append('g')     .attr('transform', 'translate(32,32)');    let circles = g.append('g')     .selectall('circle');    const brushgroup = g.append('g')     .attr('class', 'brush')     .call(brush);    function redraw() {     const = group.all(); // crossfilter group returns array      xaxisgroup.call(xaxis);     yaxisgroup.call(yaxis);      circles = circles.data(all, d => d); // keyfn data constancy      circles.enter().append('circle')       .attr('r', radius)       .attr('cx', plotx) // radius + plotx/y simple curry functions       .attr('cy', ploty);      circles.exit().remove(); // not working!!   }    redraw(); } 

i aware of change in d3-selection in v4 i'm not super confident lines update , ones update + enter.

any appreciated. thank you!

i suspect problem 1 of 2 things. #1 below. it's bit hard tell out working example test things out in, here go:

  1. i believe selectall , data join should happen in redraw function. because never redo selectall in redraw function, selection never contain elements. if check enter , exit selections in redraw function, enter selection contain data points because underlying selection empty.

  2. that data key function returns object. since object result of crossfilter's group.all, should comparable reference, safer circles.data(all, d => d.key).

the solution should like:

componentdidmount() {   const el = reactdom.finddomnode(this); // mounted svg element    const svg = d3.select(el)     .attr('width', 300)     .attr('height', 500);    const g = svg.append('g')     .attr('transform', 'translate(32,32)');    let circlesgroup = g.append('g'); // hang on group    const brushgroup = g.append('g')     .attr('class', 'brush')     .call(brush);    function redraw() {     const = group.all(); // crossfilter group returns array      xaxisgroup.call(xaxis);     yaxisgroup.call(yaxis);      let circles = circlesgroup // selection , data join here       .selectall('circle')         .data(all, d => d.key); // have key function return key, not object      circles.enter().append('circle')       .attr('r', radius)       .attr('cx', plotx) // radius + plotx/y simple curry functions       .attr('cy', ploty);      circles.exit().remove();   }    redraw(); } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -