Javascript d3.scale.linear() 与 d3.scaleLinear()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35953892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
d3.scale.linear() vs d3.scaleLinear()
提问by Hyman blank
Hi I'm looking at the documentationfor scales and it shows a format like this var x = d3.scaleLinear([10,130]).range([0,960])
I feel like this is strange because most examplesthat I see online use something like this:
嗨,我正在查看scales的文档,它显示了这样的格式,var x = d3.scaleLinear([10,130]).range([0,960])
我觉得这很奇怪,因为我在网上看到的大多数示例都使用以下内容:
var x = d3.scale.linear().domain([10,130]).range([0,960])
and it works.
var x = d3.scale.linear().domain([10,130]).range([0,960])
它有效。
If I use var x = d3.scaleLinear([10,130]).range([0,960]);
I get an error like
如果我使用,var x = d3.scaleLinear([10,130]).range([0,960]);
我会收到类似的错误
TypeError: d3.scaleLinear is not a function
类型错误:d3.scaleLinear 不是函数
Why do you think there is a discrepancy between the examples in the documentation and what I see in examples online? maybe I don't understand how to read documentation.
为什么您认为文档中的示例与我在在线示例中看到的存在差异?也许我不明白如何阅读文档。
EDIT : Thisis the current documentation for scales.
编辑:这是秤的当前文档。
采纳答案by Lars Kotthoff
The documentation you're looking at is for a plugin for D3 -- how to install it is described further down on that same page. It will eventually be part of the next major release of D3.
您正在查看的文档是关于 D3 插件的——如何安装它在同一页面上进一步描述。它最终将成为 D3 下一个主要版本的一部分。
回答by Hina Dawood
To create a linear scale with d3.js version 3use API d3.scale.linear()
要使用 d3.js版本 3创建线性比例,请使用 APId3.scale.linear()
and to create a linear scale with version 4 and 5use API d3.scaleLinear()
并使用 API 4 和 5创建线性比例尺d3.scaleLinear()
API references for creating a linear scale for both the versions can be found here:
可以在此处找到用于为两个版本创建线性比例的 API 参考:
回答by Alireza
They are doing exactly the same thing, but it's just code change happen to D3.js
from version 3to version 4...
他们正在做完全相同的事情,但只是D3.js
从版本 3到版本 4发生了代码更改......
So linear is not property of scale object of d3framework anymore...
所以线性不再是d3框架的缩放对象的属性......
instead it's part of d3 with camelCasesyntax...
相反,它是 d3 的一部分,使用驼峰式语法...
So d3.js
v3use d3.scale.linear()
所以d3.js
v3使用d3.scale.linear()
and to create a linear scale with v4use d3.scaleLinear()
instead...
并创建具有线性刻度v4的使用d3.scaleLinear()
,而不是...
version 3:
版本 3:
d3.scale.linear()
Constructs a new linear scale with the default domain [0,1] and the default range [0,1]. Thus, the default linear scale is equivalent to the identity function for numbers; for example linear(0.5) returns 0.5.
d3.scale.linear()
使用默认域 [0,1] 和默认范围 [0,1] 构造一个新的线性标度。因此,默认的线性标度相当于数字的恒等函数;例如 linear(0.5) 返回 0.5。
version 4:
版本 4:
d3.scaleLinear()
Constructs a new continuous scale with the unit domain [0, 1], the unit range [0, 1], the default interpolator and clamping disabled. Linear scales are a good default choice for continuous quantitative data because they preserve proportional differences. Each range value y can be expressed as a function of the domain value x: y = mx + b.
d3.scaleLinear()
使用单位域 [0, 1]、单位范围 [0, 1]、默认插值器和钳位禁用构造一个新的连续比例尺。线性尺度是连续定量数据的一个很好的默认选择,因为它们保留了比例差异。每个范围值 y 可以表示为域值 x 的函数:y = mx + b。
回答by David Israwi
As specified by Hina, d3.scale.linear() is used on D3 3.0, and d3 4.0 adopted the flat namespace convention. Here is a snippet from the d3 changelog summary
按照 Hina 的规定,d3.scale.linear() 在 D3 3.0 上使用,而 d3 4.0 采用了平面命名空间约定。这是 d3 更改日志摘要中的一个片段
If you don't care about modularity, you can mostly ignore this change and keep using the default bundle. However, there is one unavoidable consequence of adopting ES6 modules: every symbol in D3 4.0 now shares a flat namespace rather than the nested one of D3 3.x. For example, d3.scale.linear is now d3.scaleLinear,...
如果您不关心模块化,您可以忽略此更改并继续使用默认包。然而,采用 ES6 模块有一个不可避免的后果:D3 4.0 中的每个符号现在共享一个平面命名空间,而不是 D3 3.x 的嵌套命名空间。例如,d3.scale.linear 现在是 d3.scaleLinear,...
Source: https://github.com/d3/d3/blob/master/CHANGES.md
来源:https: //github.com/d3/d3/blob/master/CHANGES.md
EDIT: Forgot to mention - to fix your error, you may have to update the link or file to d3 that you have in your program. I call it directly from the website with:
编辑:忘记提及 - 要修复您的错误,您可能需要将链接或文件更新为您程序中的 d3。我直接从网站调用它:
<script src="https://d3js.org/d3.v4.min.js"></script>