d3.js d3.transform 方法移除的解决方案

rt

d3.transform在新版本中移除

需要自行写出该功能

function getTranslation(transform) {
// Create a dummy g for calculation purposes only. This will never
// be appended to the DOM and will be discarded once this function
// returns.
var g = document.createElementNS("http://www.w3.org/2000/svg", "g"); // Set the transform attribute to the provided string value.
g.setAttributeNS(null, "transform", transform); // consolidate the SVGTransformList containing all transformations
// to a single SVGTransform of type SVG_TRANSFORM_MATRIX and get
// its SVGMatrix.
var matrix = g.transform.baseVal.consolidate().matrix; // As per definition values e and f are the ones for the translation.
return [matrix.e, matrix.f];
} console.log(getTranslation("translate(20,30)")) // simple case: should return [20,30]
console.log(getTranslation("rotate(45) skewX(20) translate(20,30) translate(-5,40)"))
上一篇:老李推荐:第14章3节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-HierarchyViewer实例化


下一篇:判断页面中的js方法是否存在,存在就调用它,不存在则忽略