如何计算秤的结果? [英] How to calculate the scale's result?

查看:21
本文介绍了如何计算秤的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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 相同......但为什么 180 作为输入返回 300?我如何计算这个值?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆