컨텍스트 브러시로 차원 차트를 만들려고 시도 할 때및 d3.js v4을 ES6 스타일 React와 함께 사용하고 있습니다. 기본적으로 this example을 가져 와서 ES6으로 변환했습니다.d3 v4 + react + es6 + crossfilter : Selection.exit(). remove() not working
내가 가진 문제는 selection.exit().remove()
이므로 각 그리기에서 더 많은 원이 svg g 요소에 추가됩니다. 브러시를 만들 때 다시 그리기가 트리거됩니다. 나는 실행하여 점검했다
selection.exit()
.attr('class', d => {
console.log('anything');
return 'anything';
})
.remove();
그러나 아무 것도 출력되지 않았으므로 나의 데이터 선택이 유효하지 않다고 생각하고있다. 여기
컨텍스트입니다 :componentDidMount() {
const el = ReactDOM.findDOMNode(this); // the 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 all = group.all(); // crossfilter group returns an array
xAxisGroup.call(xAxis);
yAxisGroup.call(yAxis);
circles = circles.data(all, d => d); // keyFn for data constancy
circles.enter().append('circle')
.attr('r', radius)
.attr('cx', plotX) // radius + plotX/Y are simple curry functions
.attr('cy', plotY);
circles.exit().remove(); // not working!!
}
redraw();
}
내가 V4에서 d3-selection의 변화를 알고도 모르지만, 나는 슈퍼있는 줄 확신 아니에요 내 update
내 update + enter
을있는 것.
도움을 주시면 감사하겠습니다. 고맙습니다!
'exit' 선택, 당신은 선택의 데이터, 데이터가 그들에게 언급하지 왼쪽 된 모든 요소를 결합 후 . 이제'let circles '를주의 깊게보십시오. 그들은 어떤 데이터에 구속되지 않습니다. 입력, 업데이트 및 나가기 선택을 올바르게 정의해야합니다. 지금은 제대로 정의되지 않았습니다. –
'circleles = circles.data (all, d => d)'를 설정하면 어떨까요? 그러면 적절한 조인 선택이 생성되지 않습니다. 따라서'circles.enter()'와'circles.exit()'? –
서클 데이터에 대한 고유 ID는 'circles = circles.data (all, d => d.id)'입니다. – Cyril