Install
npm install @lunit/heatmap
Use
import { getAlpha, getRGBArray } from '@lunit/heatmap';
describe('getRGBArray', () => {
test('basic', () => {
expect(getRGBArray(0)).toEqual([0, 0, 255]);
expect(getRGBArray(0.25)).toEqual([0, 255, 255]);
expect(getRGBArray(0.5)).toEqual([0, 255, 0]);
expect(getRGBArray(0.75)).toEqual([255, 255, 0]);
expect(getRGBArray(1)).toEqual([255, 0, 0]);
});
test('alpha', () => {
expect(getAlpha({threshold: 0, stop: 0})).toEqual(0);
expect(getAlpha({threshold: 0, stop: 0.25})).toEqual(0.1875);
expect(getAlpha({threshold: 0, stop: 0.5})).toEqual(0.375);
expect(getAlpha({threshold: 0, stop: 0.75})).toEqual(0.5625);
expect(getAlpha({threshold: 0, stop: 1})).toEqual(0.75);
});
});
import { storiesOf } from '@storybook/react';
import React from 'react';
import { HeatmapLinearGradient } from '@lunit/heatmap';
storiesOf('<SVGLinearGradient>', module)
.add('basic', () => (
<svg width={300} height={100} style={{backgroundColor: '#000000'}}>
<defs>
<HeatmapLinearGradient id="test-linear-gradient"/>
</defs>
<rect width="100%" height="100%" fill="url(#test-linear-gradient)"/>
</svg>
));