Download wp-calypso/client/components/chart-uplot/lib/get-gradient-fill.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/components/chart-uplot/lib/get-gradient-fill.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/components/chart-uplot/lib/get-gradient-fill.ts
-
curl -L -o get-gradient-fill.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/components/chart-uplot/lib/get-gradient-fill.ts
1.31 kB
| import type { ScaleGradientFunction } from '../hooks/use-scale-gradient'; | |
| import type uPlot from 'uplot'; | |
| export default function getGradientFill( | |
| fillColorFrom: string, | |
| fillColorTo: string, | |
| scaleGradient: ScaleGradientFunction | |
| ): ( self: uPlot, seriesIdx: number ) => CanvasRenderingContext2D[ 'fillStyle' ] { | |
| return ( u, seriesIdx ) => { | |
| // Find min and max values for the visible parts of all y axis' and map it to color values to draw a gradient. | |
| const s = u.series[ seriesIdx ]; // data set | |
| const sc = u.scales[ s.scale || 1 ]; // y axis values | |
| // if values are not initialised default to a solid color | |
| if ( s.min === Infinity || s.max === -Infinity ) { | |
| return fillColorFrom; | |
| } | |
| let min = Infinity; | |
| let max = -Infinity; | |
| // get in-view y range for this scale | |
| u.series.forEach( ( ser ) => { | |
| if ( ser.show && ser.scale === s.scale ) { | |
| min = Math.min( min, ser.min || 0 ); | |
| max = Math.max( max, ser.max || 0 ); | |
| } | |
| } ); | |
| let range = max - min; | |
| // if `range` from data is 0, apply axis range | |
| if ( range === 0 ) { | |
| range = sc?.max !== undefined && sc?.min !== undefined ? sc.max - sc.min : 0; | |
| min = sc?.min || 0; | |
| } | |
| return scaleGradient( u, s.scale || 'y', 1, [ | |
| [ min + range * 0.0, fillColorTo ], | |
| [ min + range * 1.0, fillColorFrom ], | |
| ] ); | |
| }; | |
| } | |