diff --git a/src/components/Dataset.ts b/src/components/Dataset.ts new file mode 100644 index 0000000..6a79cf2 --- /dev/null +++ b/src/components/Dataset.ts @@ -0,0 +1,19 @@ +import * as echarts from 'echarts/core'; +import { DatasetComponent, type DatasetComponentOption } from 'echarts/components'; +import { symbols } from '../constants'; + +echarts.use([DatasetComponent]); + +export type DatasetProps = DatasetComponentOption; + +function Dataset(_: DatasetProps) { + return null; +} + +Dataset[symbols.typeKey] = symbols.dataset; + +if (process.env.NODE_ENV !== 'production') { + Dataset.displayName = 'Dataset'; +} + +export default Dataset; diff --git a/src/constants.ts b/src/constants.ts index 00e5382..3780f20 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -9,6 +9,7 @@ export const EChartsContext = React.createContext({}); export const symbols = { typeKey: Symbol.for('$$typeKey'), // components + dataset: Symbol.for('$$dataset'), dataZoom: Symbol.for('$$dataZoom'), legend: Symbol.for('$$legend'), radar: Symbol.for('$$radar'), diff --git a/src/index.ts b/src/index.ts index 5417005..464b65e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import ECharts from './ECharts'; // Components +import Dataset from './components/Dataset'; import DataZoom from './components/DataZoom'; import Legend from './components/Legend'; import Radar from './components/Radar'; @@ -35,7 +36,7 @@ import TreemapChart from './charts/TreemapChart'; export default ECharts; -export { DataZoom, Legend, Radar, Tooltip, VisualMap, XAxis, YAxis }; +export { Dataset, DataZoom, Legend, Radar, Tooltip, VisualMap, XAxis, YAxis }; export { Bars, Funnel, Line, Map, Pie, RadarLine, Sankey, Scatter, Tree, Treemap }; @@ -49,5 +50,5 @@ export { SankeyChart, ScatterChart, TreeChart, - TreemapChart, + TreemapChart }; diff --git a/src/utils.ts b/src/utils.ts index 430765a..301447b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,6 +7,7 @@ import { TitleComponent } from 'echarts/components'; import { symbols } from './constants'; import { ChartComponentProps } from './ECharts'; import type { YAxisProps } from './components/YAxis'; +import type { DatasetProps } from './components/Dataset'; echarts.use([TitleComponent]); @@ -65,6 +66,9 @@ const stackKey = randstr(); const createOptions = { // components + [symbols.dataset](option: any, props: DatasetProps, _:any) { + option.dataset = _merge({}, props); + }, [symbols.dataZoom](option: any, props: any, _: any) { function getOption() { return _merge(