如何计算量表的结果? [英] How to calculate the scale's result?
问题描述
我是d3.js库的新手,我试图了解域和范围的概念.
I am new to d3.js library, and I am trying to understand the concept of domain and ranges.
我阅读了斯科特·默里(Scott Murray)的书,但我没有不知道如何计算.
I read Scott Murray's book, but I don't know how to calculate it.
我有这个:
var scale = d3.scale.linear()
.domain([100, 500])
.range([10, 350]);
scale(100); //Returns 10
scale(300); //Returns 180
scale(500); //Returns 350
我知道我的输入中有100个单位代表我的输出中有10个,而对于500和350来说却是相同的...但是为什么对于300作为输入返回180?我该如何计算这个值?
I know that 100 units of my input represent 10 in my output, and the same with 500 and 350... but why 180 is returned for 300 as input? How can I calculate this value?
我也阅读了本教程,它解释了如何计算它,但是当我遵循时该方法,我没有得到相同的值,即scale(300)
不返回180
.
I read this tutorial too, which explains how to calculate it, but when I follow the method, I don't get the same value, i.e., scale(300)
doesn't return 180
.
知道为什么吗?
推荐答案
是的,我将尝试解释您为什么要达到180.
Yes I will try to explain why you get 180.
我们拥有300的值,可以理想地将您的域划分为两个相同大小的子域,因此我们可以执行以下操作:
500 - 100 / 2 = 200
(这是子域的大小),
这意味着中间值位于:
200 + 100 = 300
(请注意,我们添加了起点100
)
We have that 300 is the value that ideally divide your domain into two subdomains of the same size, so we can do:
500 - 100 / 2 = 200
(this is the subdomain size),
this implies that the middle value is located at:
200 + 100 = 300
(note that we add the starting point 100
)
因此在范围内,我们将执行相同操作:
350 - 10 / 2 = 170
然后我们添加起点
170 + 10 = 180
So with the range we do the same:
350 - 10 / 2 = 170
and then we add the starting point
170 + 10 = 180
这篇关于如何计算量表的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!