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. 给指定的用户无需密码执行 sudo 的权限

    给指定的用户无需密码执行 sudo 的权限 cat /etc/passwd 可以查看所有用户的列表 w 可以查看当前活跃的用户列表 cat /etc/group 查看用户组 cat /etc/pass ...

  2. Android学习笔记技巧之垂直和水平滚动视图

    <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...

  3. Python 标准库 csv —— csv 文件的读写

    csv 文件,逗号分割文件. 0. 读取 csv 到 list from csv import reader def load_csv(csvfile): dataset = [] with open ...

  4. java产生随机数的三种方式

    转自:https://blog.csdn.net/YTTmiao/article/details/78187448 随机数在实际中使用很广泛,比如要随即生成一个固定长度的字符串.数字.或者随即生成一个 ...

  5. 团队作业-Beta冲刺(1)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cnblo ...

  6. [NOI2008]假面舞会(DFS)

    Description 一年一度的假面舞会又开始了,栋栋也兴致勃勃的参加了今年的舞会.今年的面具都是主办方特别定制的.每个参加舞会的人都可以在入场时选择一 个自己喜欢的面具.每个面具都有一个编号,主办 ...

  7. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  8. Android学习之图片压缩,压缩程度高且失真度小

    曾经在做手机上传图片的时候.直接获取相机拍摄的原图上传,原图大小一般1~2M.因此上传一张都比較浪费资源,有些场景还须要图片多张上传,所以近期查看了好多前辈写的关于图片处理的资料.然后试着改了一个图片 ...

  9. Google 免费公共 DNS 服务器

    Google 免费公共 DNS 服务器 http://googleblog.blogspot.com/2009/12/introducing-google-public-dns.html DNS 8. ...

  10. Jenkins学习总结(1)——Jenkins详细安装与构建部署使用教程

    Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能.Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发 ...