Created
September 26, 2018 12:37
-
-
Save DavidSanwald/3694379f80190a4bf0b45180d541ba10 to your computer and use it in GitHub Desktop.
do not directly apply scales to data, compose them with accessor functions instead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// accessor functions to decouple from data shape | |
const x = d => d.date | |
const y = d => d.score | |
const xScale = d3.scaleTime() | |
.range([0, width]) | |
.domain(xExtent) | |
const yScale = d3.scaleLinear() | |
.range([height, 0]) | |
.domain(yDomainPadded) | |
// compose scaling with accessors of path generator | |
const line =d3.line() | |
.x(d => xScale(x(d))) | |
.y(d => yScale(y(d))) | |
/* do not scale data directly | |
const data = rawData.map(datum=>({...datum, x: xScale(datum.date),y: yScale(datum.score)}))* / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment