나는 미로를 가지고 있으며 내가 원하는 것은 그 모든 셀에 원을 만들고 그 원을 미로의 오른쪽으로 트리로 옮기는 것이다. 나는 d3 전환과 html5 캔버스를 사용합니다. 내가 할 수있는 최적화가 있다면 내 질문입니다. 캔버스 성능을 알지 못해서 내가 얼마나 기대할 수 있는지 모르겠다.캔버스 렌더링 최적화
1600 개의 요소 (600px x 600px 및 15px cellSize)의 경우 애니메이션이 부드럽습니다. 3600 가지 요소는 그렇지 않습니다.
mazeSelection.selectAll('cell')
.data(root.descendants())
.enter()
.append('cell')
.attr('radius', 0)
.attr('cx', d => d.data.ix * cellSize + 0.5 * cellSize,)
.attr('cy', d => d.data.iy * cellSize + 0.5 * cellSize)
.transition().duration(2000)
.attr('radius', cellSize/2)
.transition().duration(3000)
.attr('radius', cellSize/4)
.tween('position', function(d) {
const i = d3.interpolate([this.getAttribute('cx'), this.getAttribute('cy')], [width + d.x, cellSize * 0.5 + d.y]);
return (t) => {
[d.cx, d.cy] = i(t);
this.setAttribute('cx', d.cx);
this.setAttribute('cy', d.cy);
};
});
context.fillStyle = "white";
let timer = d3.timer(function redraw() {
// clear maze
context.beginPath();
context.fillRect(0, 0, width * 2, height);
//drawMaze(grid, context, width, height, cellSize);
context.beginPath();
// here we must use a function to have access to "this"
mazeSelection.selectAll('cell')
.each(function (d) {
const radius = this.getAttribute('radius'),
x = this.getAttribute('cx'),
y = this.getAttribute('cy');
context.moveTo(x, y);
context.arc(x, y, radius * 0.5, 0, 2 * Math.PI);
(d.children || []).forEach(child => {
context.moveTo(x, y);
context.lineTo(child.cx, child.cy);
});
});
context.stroke();
context.fill();
});
DOM 요소를 여기에 만들면이를 피하고 자바 스크립트 구조의 목록을 만든 다음 반복합니다. –
답장을 보내 주셔서 감사합니다. 나는 두 가지 질문을 가지고있다. 1. append를 사용하더라도, chrome dev 툴을 사용하면 DOM 트리에 엘리먼트가 나타나지 않는다. 그들은 그렇게 나빠요? 2. DOM 요소를 만들지 않고 전환을 적용하는 방법을 알고 있습니까? –
1. DOM 트리 이상에서 만들 수있는 Chrome 개발자 도구는 문서에 첨부 한 도구 만 표시 할 수 있습니다. 1b) 예 2. 나의 초기 코멘트 당 recode. –