[D3] Convert Input Data to Output Values with Linear Scales in D3
to in with Data input VALUES convert output
2023-09-14 08:59:19 时间
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)); // 0 console.log(number(50)); // 250 console.log(number(100)); // 500 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)); // 100 console.log(number.invert(250)); // 50 console.log(number.invert(100)); // 20 console.log(number.invert(0)); // 0 -- with clamp(true) console.log(number.invert(-10)); // -2 -- without clamp(true)
相关文章
- ArcGIS Server启动服务报:ERROR: Unable to start Xvfb on any port in the range 6600 - 6619
- [Typescript] Using Generic Context to Avoid Distributivity in Conditional Types
- [Typescript] Tips: Use 'in' operator to transform a union to another union(watched)
- [Algorithm] Dynamic programming: Find Sets Of Numbers That Add Up To 16
- [React] Call setState with null to Avoid Triggering an Update in React 16
- [D3] Convert Dates to Numeric Values with Time Scales in D3 v4
- [React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability
- [Javascript] Keyword 'in' to check prop exists on Object
- [Svelte 3] Use an onMount lifecycle method to fetch and render data in Svelte 3
- [Tools] Convert SVG to a PDF in Node with PDFKit and SVG.js
- [Node.js] Write or Append to a File in Node.js with fs.writeFile and fs.writeFileSync
- [Angular] Remove divs to Preserve Style and Layout with ng-container in Angular
- [D3] Convert Dates to Numeric Values with Time Scales in D3 v4
- [FAQ] "cannot refer to unexported name" in Golang ?
- How to test Delta download in CRM Side
- How to get propose products in Sales Order
- how to find data source of F4 help in web client UI
- how to use object based exception combined with message class in SE91
- Cannot add product to Opportunity in Fiori - RFC error
- 成功解决Value Error: Unable to add relationship because child variable ‘name‘ in ‘cats_df‘ is also its i
- 成功解决No handles with labels found to put in legend.
- 已解决To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags
- Sqlachemy的警告SAWarning: The IN-predicate on "sns_object.BIZ_ID" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.
- xxx cannot be resolved to a type 错误解决方法
- [Maven in action] 解决办法:Project configuration is not up-to-date with pom.xml. Run project ...