简体   繁体   English

如何使用d3.js记录变换中的旋转属性?

[英]How to log rotate attribute in transform using d3.js?

How to log the value of rotate attribute using d3.js. 如何使用d3.js记录rotate属性的值。 For example <path transform="translate(315.51970228390724 335.28984670867146) rotate(-41.811111262071016)"></path> I want to get value -41.811111262071016 in console.log() 例如<path transform="translate(315.51970228390724 335.28984670867146) rotate(-41.811111262071016)"></path>我想在console.log()中获取值-41.811111262071016

In d3 it's easily done using d3.transform() : 在d3中,可以使用d3.transform()轻松完成:

 var myPath = d3.select("path"); var value = d3.transform(myPath.attr("transform")).rotate; console.log(value); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <path transform="translate(315.51970228390724 335.28984670867146) rotate(-41.811111262071016)"></path> 

Note : this only works in d3 version 3. 注意 :这仅在d3版本3中有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM