2
我想利用D3的縮放行爲功能,但我需要使用viewBox屬性而不是transform方法對SVG進行所有轉換/縮放,如D3例子:http://bl.ocks.org/mbostock/3680999如何在ViewBox中使用D3縮放行爲而不是轉換
我怎樣才能達到這個規模/只使用viewBox翻譯?這是我的代碼到目前爲止,這不像變換方法。
function zoomed(d) {
if (!scope.drawLine) {
var scale = d3.event.scale;
var translation = d3.event.translate;
//This works, but I can't use it for reason's I won't go into now
//mapSVG_G.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
var newViewBox = [
initialViewBox[0] - translation[0],
initialViewBox[1] - translation[1],
initialViewBox[2]/scale,
initialViewBox[3]/scale
];
mapSVG.attr('viewBox', newViewBox);
}
}
不幸的是,此解決方案的翻譯功能不正確。 – Doughy