Mapping abstract values to visual representations is what data visualization is all about, and that’s exactly what D3 scales do. Turning a test score into a column height, or a percentage into an opacity requires translating from one set of possible values to another, and linear scales perform a direct, proportional conversion of inputs to outputs. In this lesson we’ll learn the basic API of D3 scales and how to use them.

var color = d3.scaleLinear()
.domain([-1, 0, 1])
.range(["red", "white", "green"]); console.log(color(-0.5)); // "rgb(255, 128, 128)"
console.log(color(+0.5)); // "rgb(128, 192, 128)" // If clamping is enabled, the return value of the scale is always within the scale’s range.
var number = d3.scaleLinear()
.domain([0, 100])
.range([0, 500])
.clamp(true); console.log(number(0)); //
console.log(number(50)); //
console.log(number(100)); //
console.log(number(105)); // 500 -- with clamp(true)
console.log(number(105)); // 525 -- without clamp(true) var number = d3.scaleLinear()
.domain([0, 100])
.range([0, 500]); // Given a value from the range, returns the corresponding value from the domain.
console.log(number.invert(500)); //
console.log(number.invert(250)); //
console.log(number.invert(100)); //
console.log(number.invert(0)); // 0 -- with clamp(true)
console.log(number.invert(-10)); // -2 -- without clamp(true)

[D3] Convert Input Data to Output Values with Linear Scales in D3的更多相关文章

  1. [D3] Convert Dates to Numeric Values with Time Scales in D3 v4

    Mapping abstract values to visual representations is what data visualization is all about, and that’ ...

  2. [D3] Create Labels from Numeric Data with Quantize Scales in D3 v4

    Sometimes data needs to be converted from a continuous range, like test scores, to a discrete set of ...

  3. How to decode input data from a contract transaction without ABI?

    1 I've found some libraries which decode input from transaction, but all of them require ABI of cont ...

  4. ABAP WB01 BDC ”No batch input data for screen & &“ ”没有屏幕 & & 的批输入数据“

    公司今年计划大批扩建门店,需要自动化维护相关主数据,其中就有一步通过调用 WB01的BDC录屏来自动创建地点,前台跑没有问题,但后台JOB死活不行,屏幕是以前同事录好的,只能硬着头皮修改. 后台任务日 ...

  5. sqoop导出hive数据到mysql错误: Caused by: java.lang.RuntimeException: Can't parse input data

    Sqoop Export数据到本地数据库时出现错误,命令如下: sqoop export \ --connect 'jdbc:mysql://202.193.60.117/dataweb?useUni ...

  6. 深入比特币原理(三)——交易的输入(input)与输出(output)

    本节内容非常重要,如果你不能很好的掌握本节内容,你无法真正理解比特币的运行原理,请务必要学习清楚. 比特币的交易模型为UTXO(unspend transaction output),即只记录未花费的 ...

  7. Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’

    一.部署 Django 到远程 Linux 服务器 利用 xshell 通过 ssh 连接到 Linux服务器,常规的启动命令是 python3 manage.py runserver 但是,关闭 x ...

  8. [D3] Create Labels from Non-numeric Data with Ordinal Scales in D3 v4

    When your data contains discrete, non-numeric property values that you need to format or convert bef ...

  9. STM32 Timer : Base Timer, Input Capture, PWM, Output Compare

    http://www.cs.indiana.edu/~geobrown/book.pdf An example of a basic timer is illustrated in Figure 10 ...

随机推荐

  1. 重构insert update 比较两个datatbale

    #region 下载时重构insert(数据带null处理) public void DownDataInsert(DataTable _dt, string TableName,DBHelper d ...

  2. 【D3 API 中文手冊】

    [D3 API 中文手冊] 声明:本文仅供学习所用,未经作者同意严禁转载和演绎 <D3 API 中文手冊>是D3官方API文档的中文翻译. 始于2014-3-23日,基于VisualCre ...

  3. Linux下设置ip和主机名进行绑定

    1:输入命令gedit   /etc/hosts 这样你就打开了一个文本,然后在文本的末尾进行加入例如以下: ip地址                主机名 192.168.0.125       h ...

  4. 使用MERGE语句同步表

    先建好測试环境: USE TEMPDB GO IF OBJECT_ID('T1') IS NOT NULL DROP TABLE T1 IF OBJECT_ID('T2') IS NOT NULL D ...

  5. onvif开发之设备发现功能的实现--转

    忙了一个多月,onvif总算告一段落了.这几个星期忙着其他的项目,也没有好好整理一下onvif的东西.接下来得好好整理一下自己的项目思路和项目经验,同时将自己的一些心得写出来,希望对人有所帮助. 相信 ...

  6. 一个奇怪的Java集合问题

    int size = list.size(); Integer existIndex = -1; for (int index = 0; index < size; index++) { Pho ...

  7. CList 点击表头排序 (1)SortItems函数

    点击表头排序整体的思路都是去 CListCtrl类中的方法SortItems去实现 CListCtrl::SortItems的原型是: BOOL SortItems( PFNLVCOMPARE pfn ...

  8. 一个虐你千百遍的问题:“RPC好,还是RESTful好?”

    看到知乎上有这样一个问题 WEB开发中,使用JSON-RPC好,还是RESTful API好? 还有其他优秀的推荐方案吗? -------------------------------------- ...

  9. 重排序列 & 拓扑排序

    http://bookshadow.com/weblog/2016/10/30/leetcode-sequence-reconstruction/ 这道题目,检查重排的序列是否一致. 用了拓扑排序. ...

  10. openstack之虚拟机创建流程分析

    这篇博文静静的呆在草稿箱大半年了.假设不是由于某些原因被问到,以及由于忽略它而导致的损失,否则我也不知道什么时候会将它完毕.感谢这段时间经历的挫折,让我知道不足.希望你能给我更大的决心! 本文试图具体 ...