d3 scale:如何使用.copy()? [英] d3 scale: How to use .copy()?
问题描述
我遇到了 log.copy()
,位于 API参考中。这是什么目的?有人可以展示一个例子吗?
I came across the log.copy()
in the API reference. What is the purpose of this? Can someone show an example?
如果我在一个函数中使用一个scale,可以使用 .copy
并稍后检索?
If I use a scale in one function, can I save it to a global variable by using .copy()
and retrieve it later?
推荐答案
目的是, 。你基本上获得相同类型的缩放,域和范围两次,而不必设置一切两次。例如,请考虑此处的画笔演示。而不是
The purpose is, as the name suggests, to copy a scale. You essentially get the same type of scale, domain and range twice without having to set everything twice. For example, consider the brush demo here. Instead of
var x = d3.time.scale().range([0, width]),
x2 = d3.time.scale().range([0, width]),
可以
var x = d3.time.scale().range([0, width]),
x2 = x.copy(),
我已经做了此处。唯一的区别是代码稍短一点。
which I have done here. The only difference is that the code is very slightly shorter.
如果你只想检索一个刻度,就没有必要复制它。只有当你想要以两种不同的方式独立地修改它,你需要不同的尺度。
If you only want to retrieve a scale, there's no need to copy it. Only when you want to modify it in two different ways independently you need different scales.
这篇关于d3 scale:如何使用.copy()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!