import * as d3 from 'd3' ; function getScalers ( data , height , width ) { const minX = Math . min ( ... data . map ( el => el . x ) ) ; const maxX = Math . max ( ... data . map ( el => el . x ) ) ; const x = d3 . scaleLinear ( ) . domain ( [ minX , maxX ] ) . range ( [ 0 , width ] ) ; const y = d3 . scaleLinear ( ) . domain ( [ 0 , 1 ] ) . range ( [ height , 0 ] ) ; return { x , y } ; } export function getDotsCoords ( data , height , width ) { const { x , y } = getScalers ( data , height , width ) ; return data . map ( p => ( { x : x ( p . x ) , y : y ( p . y ) , } ) ) ; } type Point = { x : number ; y : number ; } ; export function getPathCoords ( data , height , width ) { const { x , y } = getScalers ( data , height , width ) ; const pathD = d3 . line < Point > ( ) . x ( d => x ( d . x ) ) . y ( d => y ( d . y ) ) . curve ( d3 . curveMonotoneX ) ; return pathD ( data ) ; } export function getAreaCords ( data , height , width ) { const { x , y } = getScalers ( data , height , width ) ; const pathD = d3 . area < Point > ( ) . x ( d => x ( d . x ) ) . y0 ( d => y ( d . y ) ) . y1 ( d => height ) . curve ( d3 . curveMonotoneX ) ; return pathD ( data ) ; }