d3.js를 사용하여 게이지 바늘을 애니메이션하려고하지만 이상한 애니메이션이 생깁니다. 인터넷에서 일부 검색을했는데 문제를 해결하기 위해 어떤 솔루션을 사용할 수 있는지 파악할 수 없었습니다. 당신이 경로를 다시 그리는 대신 transform="rotate()"
을 적용 할 경우d3.js를 사용하여 게이지 바늘을 애니메이션화하십시오.
function createNeedle(sampleAngle){
topX = centerX - Math.cos(sampleAngle) * triLength
topY = centerY - Math.sin(sampleAngle) * triLength
leftX = centerX - 10 * Math.cos(sampleAngle - Math.PI/2)
leftY = centerY - 10 * Math.sin(sampleAngle - Math.PI/2)
rightX = centerX - 10 * Math.cos(sampleAngle + Math.PI/2)
rightY = centerY - 10 * Math.sin(sampleAngle + Math.PI/2)
return " M " + leftX + " " + leftY + " L " + topX + " " + topY + " L " + rightX + " " + rightY;
}
//animate the needle
d3.select('.moveNeedle')
.attr('d', createNeedle(sampleAngle1))
.transition()
.duration(2000)
.attr('d', createNeedle(sampleAngle2));
이 SO 질문을 볼 수있는 X를 계산하고 Y 예를 들어, 전환하는 동안 조정하는 customTween (https://stackoverflow.com/questions/30849961/d3-js-tween-arc-를 작성하는 것입니다 d3-js-arc) 및 관련 블록 (http://bl.ocks.org/mbostock/5100636) –
고맙습니다. http : : //bl.ocks.org/mbostock/5100636 –
거의 중복됨 : [* "D3 SVG 변환 회전 전환이 이상하게 작동 함 *] (/ q/40244530). – altocumulus