|
| 1 | +import React from 'react'; |
| 2 | +import { SuperChart, getChartTransformPropsRegistry } from '@superset-ui/chart'; |
| 3 | +import { boolean, number, select, withKnobs } from '@storybook/addon-knobs'; |
| 4 | +import { EchartsTimeseriesChartPlugin } from '@superset-ui/plugin-chart-echarts'; |
| 5 | +import transformProps from '@superset-ui/plugin-chart-echarts/lib/Timeseries/transformProps'; |
| 6 | +import { withResizableChartDemo } from '../../../shared/components/ResizableChartDemo'; |
| 7 | +import data from './data'; |
| 8 | + |
| 9 | +new EchartsTimeseriesChartPlugin().configure({ key: 'echarts-timeseries' }).register(); |
| 10 | + |
| 11 | +getChartTransformPropsRegistry().registerValue('echarts-timeseries', transformProps); |
| 12 | + |
| 13 | +export default { |
| 14 | + title: 'Chart Plugins|plugin-chart-echarts', |
| 15 | + decorators: [withKnobs, withResizableChartDemo], |
| 16 | +}; |
| 17 | + |
| 18 | +export const Timeseries = ({ width, height }) => { |
| 19 | + const forecastEnabled = boolean('Enable forecast', true); |
| 20 | + const queryData = data |
| 21 | + .map(row => |
| 22 | + forecastEnabled |
| 23 | + ? row |
| 24 | + : { |
| 25 | + __timestamp: row.__timestamp, |
| 26 | + Boston: row.Boston, |
| 27 | + California: row.California, |
| 28 | + WestTexNewMexico: row.WestTexNewMexico, |
| 29 | + }, |
| 30 | + ) |
| 31 | + .filter(row => forecastEnabled || !!row.Boston); |
| 32 | + return ( |
| 33 | + <SuperChart |
| 34 | + chartType="echarts-timeseries" |
| 35 | + width={width} |
| 36 | + height={height} |
| 37 | + queryData={{ data: queryData }} |
| 38 | + formData={{ |
| 39 | + contributionMode: undefined, |
| 40 | + forecastEnabled, |
| 41 | + colorScheme: 'supersetColors', |
| 42 | + seriesType: select( |
| 43 | + 'Line type', |
| 44 | + ['line', 'scatter', 'smooth', 'bar', 'start', 'middle', 'end'], |
| 45 | + 'line', |
| 46 | + ), |
| 47 | + logAxis: boolean('Log axis', false), |
| 48 | + yAxisFormat: 'SMART_NUMBER', |
| 49 | + stack: boolean('Stack', false), |
| 50 | + area: boolean('Area chart', false), |
| 51 | + markerEnabled: boolean('Enable markers', false), |
| 52 | + markerSize: number('Marker Size', 6), |
| 53 | + minorSplitLine: boolean('Minor splitline', false), |
| 54 | + opacity: number('Opacity', 0.2), |
| 55 | + zoomable: boolean('Zoomable', false), |
| 56 | + }} |
| 57 | + /> |
| 58 | + ); |
| 59 | +}; |
0 commit comments