@visactor/react-vchart 1.13.8-alpha.6 → 1.13.8-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -18
- package/cjs/charts/BaseChart.js +2 -4
- package/cjs/charts/BaseChart.js.map +1 -1
- package/cjs/components/BaseComponent.js +1 -1
- package/cjs/components/BaseComponent.js.map +1 -1
- package/cjs/containers/withContainer.js +1 -1
- package/cjs/context/chart.js +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/esm/charts/BaseChart.js +2 -4
- package/esm/charts/BaseChart.js.map +1 -1
- package/esm/components/BaseComponent.js +1 -1
- package/esm/components/BaseComponent.js.map +1 -1
- package/esm/containers/withContainer.js +1 -1
- package/esm/context/chart.js +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# @visactor/react-vchart
|
|
2
2
|
|
|
3
|
-
`@visactor/react-vchart`
|
|
3
|
+
`@visactor/react-vchart` 是由 [VisActor](visactor.io) 为您提供的 React 封装版本 VChart 图表库。它提供了一系列易于使用的 React 组件,用于方便的在 React 开发环境中创建各种类型的图表,包括折线图、柱状图、饼图等。`@visactor/react-vchart` 的组件具有高度的可定制性和可扩展性,可以通过传递不同的参数和配置来实现不同的图表效果。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
`@visactor/react-vchart` 的主要特点包括:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- **易于使用**:`@visactor/react-vchart` 提供了一系列易于使用的 React 组件,可以快速创建各种类型的图表。
|
|
8
|
+
- **可定制性强**:`@visactor/react-vchart` 的组件具有高度的可定制性,可以通过传递不同的参数和配置来实现不同的图表效果。
|
|
9
|
+
- **可扩展性强**:`@visactor/react-vchart` 的组件可以轻松地扩展和定制,可以根据需要添加新的功能和特性。
|
|
10
|
+
- **兼容性好**:`@visactor/react-vchart` 完全继承了 VChart 的可视化能力,可以在不同的浏览器和设备上运行。
|
|
11
|
+
- **支持多种图表类型**:`@visactor/react-vchart` 支持多种类型的图表,包括折线图、柱状图、饼图、雷达图等。
|
|
12
12
|
|
|
13
|
-
`@visactor/react-vchart`
|
|
13
|
+
`@visactor/react-vchart` 在能力上完全对齐 VChart,并且 API 配置也与 VChart 几乎一致,关于图表的定义和配置可参考[VChart](https://www.visactor.io/vchart)。
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## 开发指引
|
|
16
16
|
|
|
17
17
|
### Build
|
|
18
18
|
|
|
@@ -35,12 +35,20 @@ $ cd packages/react-vchart
|
|
|
35
35
|
$ rushx start
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
##
|
|
39
|
-
|
|
40
|
-
[
|
|
41
|
-
|
|
42
|
-
[
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
## 文档指引
|
|
39
|
+
|
|
40
|
+
项目文档位于 `@visactor/react-vchart` 目录中的 [docs](./docs) 路径。
|
|
41
|
+
|
|
42
|
+
1. [快速开始](./docs/1.%20%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B.md)
|
|
43
|
+
- 环境要求
|
|
44
|
+
- 安装
|
|
45
|
+
- 引入 `@visactor/react-vchart`
|
|
46
|
+
- 绘制一个简单的柱状图
|
|
47
|
+
2. 入门
|
|
48
|
+
- [API 设计](./docs/2.1%20API%E8%AE%BE%E8%AE%A1.md)
|
|
49
|
+
- [统一图表标签](./docs//2.2%20%E7%BB%9F%E4%B8%80%E5%9B%BE%E8%A1%A8%E6%A0%87%E7%AD%BE.md)
|
|
50
|
+
- [语法化标签](./docs/2.3%20%E8%AF%AD%E6%B3%95%E5%8C%96%E6%A0%87%E7%AD%BE.md)
|
|
51
|
+
3. [事件交互](./docs/3.%20%E4%BA%8B%E4%BB%B6%E4%BA%A4%E4%BA%92.md)
|
|
52
|
+
4. [主题样式](./docs/4.%20%E4%B8%BB%E9%A2%98%E6%A0%B7%E5%BC%8F.md)
|
|
53
|
+
5. [FAQ](./docs/5.%20FAQ.md)
|
|
54
|
+
6. [更新日志](./docs/6.%20%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97.md)
|
package/cjs/charts/BaseChart.js
CHANGED
|
@@ -98,10 +98,8 @@ const react_1 = __importStar(require("react")), withContainer_1 = __importDefaul
|
|
|
98
98
|
const newSpec = (0, vutils_1.pickWithout)(props, notSpecKeys);
|
|
99
99
|
(0, vutils_1.isEqual)(newSpec, prevSpec.current, {
|
|
100
100
|
skipFunction: skipFunctionDiff
|
|
101
|
-
}) && (0, vutils_1.isEqual)(newSpecFromChildren, specFromChildren.current,
|
|
102
|
-
|
|
103
|
-
}) || (prevSpec.current = newSpec, specFromChildren.current = newSpecFromChildren,
|
|
104
|
-
chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, null !== (_c = props.morphConfig) && void 0 !== _c ? _c : defaultMorphConfig),
|
|
101
|
+
}) && (0, vutils_1.isEqual)(newSpecFromChildren, specFromChildren.current) || (prevSpec.current = newSpec,
|
|
102
|
+
specFromChildren.current = newSpecFromChildren, chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, null !== (_c = props.morphConfig) && void 0 !== _c ? _c : defaultMorphConfig),
|
|
105
103
|
handleChartRender(!0), eventsBinded.current = props);
|
|
106
104
|
}), [ props ]), (0, react_1.useEffect)((() => () => {
|
|
107
105
|
chartContext && chartContext.current && chartContext.current.chart && (chartContext.current.chart.release(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/BaseChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,+CAAgF;AAEhF,gFAAwD;AAExD,6DAAgD;AAEhD,6CAAwE;AACxE,2DAA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QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,OAAO;iBACrB,CAAC,CACa,CAClB,CAAC;YACJ,CAAC,CAAC;YACD,WAAW,CACS,CACG,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEI,MAAM,WAAW,GAAG,CACzB,aAAqB,EACrB,YAAyB,EACzB,SAA0B,EAC1B,EAAE;IACF,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE;QACpE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KACzD;IAED,MAAM,GAAG,GAAG,IAAA,uBAAa,EAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,IAAI,YAAY,EAAE;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAjBW,QAAA,WAAW,eAiBtB","file":"BaseChart.js","sourcesContent":["import type {\n IVChart,\n IData,\n IInitOption,\n ISpec,\n IVChartConstructor,\n IHierarchyData,\n IVChartRenderOption\n} from '@visactor/vchart';\nimport type { ReactNode } from 'react';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport type { ContainerProps } from '../containers/withContainer';\nimport withContainer from '../containers/withContainer';\nimport type { ChartContextType } from '../context/chart';\nimport RootChartContext from '../context/chart';\nimport type { IView } from '@visactor/vgrammar-core';\nimport { isEqual, isNil, isValid, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport type {\n EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\nimport { bindEventsToChart, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\nimport type { IReactTooltipProps } from '../components/tooltip/interface';\nimport { initCustomTooltip } from '../components/tooltip/util';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps\n extends EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps,\n IReactTooltipProps {\n vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData | IHierarchyData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\n /**\n * add `morphConfig` for chart\n * @since 1.12.7\n */\n morphConfig?: IVChartRenderOption['morphConfig'];\n /** 图表渲染完成事件 */\n onReady?: (instance: IVChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n /**\n * use sync render\n *\n * @since 1.8.3\n * @deprecated 1.9.0\n **/\n useSyncRender?: boolean;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\n 'vchartConstrouctor',\n 'useSyncRender',\n 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'spec',\n 'container',\n 'options',\n 'morphConfig'\n];\nconst defaultMorphConfig = {\n morph: false,\n enableExitAnimation: false\n};\n\nconst getComponentId = (child: React.ReactNode, index: number) => {\n const componentName = child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n return `${componentName}-${index}`;\n};\n\nconst parseSpecFromChildren = (props: Props) => {\n const specFromChildren: Omit<ISpec, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map((child, index) => {\n const parseSpec = child && (child as any).type && (child as any).type.parseSpec;\n\n if (parseSpec && (child as any).props) {\n const childProps = isNil((child as any).props.componentId)\n ? {\n ...(child as any).props,\n componentId: getComponentId(child, index)\n }\n : (child as any).props;\n\n const specResult = parseSpec(childProps);\n\n if (specResult.isSingle) {\n (specFromChildren as any)[specResult.specName] = specResult.spec;\n } else {\n if (!(specFromChildren as any)[specResult.specName]) {\n (specFromChildren as any)[specResult.specName] = [];\n }\n\n (specFromChildren as any)[specResult.specName].push(specResult.spec);\n }\n }\n });\n\n return specFromChildren;\n};\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({});\n useImperativeHandle(ref, () => chartContext.current?.chart);\n const hasSpec = !!props.spec;\n const [view, setView] = useState<IView>(null);\n const isUnmount = useRef<boolean>(false);\n const prevSpec = useRef(pickWithout(props, notSpecKeys));\n const specFromChildren = useRef<Omit<ISpec, 'type' | 'data' | 'width' | 'height'>>(null);\n const eventsBinded = React.useRef<BaseChartProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\n const [tooltipNode, setTooltipNode] = useState<ReactNode>(null);\n\n const parseSpec = (props: Props) => {\n let spec: ISpec;\n\n if (hasSpec && props.spec) {\n spec = props.spec;\n\n if (isValid(props.data)) {\n spec = {\n ...props.spec,\n data: props.data\n } as ISpec;\n }\n } else {\n spec = {\n ...prevSpec.current,\n ...specFromChildren.current\n } as ISpec;\n }\n\n const tooltipSpec = initCustomTooltip(setTooltipNode, props, spec.tooltip);\n if (tooltipSpec) {\n spec.tooltip = tooltipSpec;\n }\n return spec;\n };\n\n const createChart = (props: Props) => {\n const cs = new props.vchartConstrouctor(parseSpec(props), {\n ...props.options,\n onError: props.onError,\n autoFit: true,\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n isUnmount.current = false;\n };\n\n const handleChartRender = (rebindEvent?: boolean) => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n if (rebindEvent) {\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n }\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n setView(newView);\n }\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // event should bind before render when the chart has not been rendered\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n chartContext.current.chart.renderSync({\n reuse: false\n });\n handleChartRender();\n }\n };\n\n useEffect(() => {\n const newSpecFromChildren = hasSpec ? null : parseSpecFromChildren(props);\n\n if (!chartContext.current?.chart) {\n if (!hasSpec) {\n specFromChildren.current = newSpecFromChildren;\n }\n\n createChart(props);\n renderChart();\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n } else if (eventsBinded.current.data !== props.data) {\n chartContext.current.chart.updateFullDataSync(props.data as any);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (\n !isEqual(newSpec, prevSpec.current, { skipFunction: skipFunctionDiff }) ||\n !isEqual(newSpecFromChildren, specFromChildren.current, { skipFunction: skipFunctionDiff })\n ) {\n prevSpec.current = newSpec;\n specFromChildren.current = newSpecFromChildren;\n\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current && chartContext.current.chart) {\n chartContext.current.chart.release();\n chartContext.current.chart = null;\n }\n }\n eventsBinded.current = null;\n isUnmount.current = true;\n };\n }, []);\n\n return (\n <RootChartContext.Provider value={chartContext.current}>\n <ViewContext.Provider value={view}>\n {toArray(props.children).map((child, index) => {\n if (typeof child === 'string') {\n return null;\n }\n\n const childId = getComponentId(child, index);\n\n return (\n <React.Fragment key={childId}>\n {React.cloneElement(child as React.ReactElement<any, React.JSXElementConstructor<any>>, {\n updateId: updateId,\n componentId: childId\n })}\n </React.Fragment>\n );\n })}\n {tooltipNode}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(\n componentName: string,\n defaultProps?: Partial<T>,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length && defaultProps.vchartConstrouctor) {\n defaultProps.vchartConstrouctor.useRegisters(registers);\n }\n\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (defaultProps) {\n return Object.assign(props, defaultProps);\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/charts/BaseChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,+CAAgF;AAEhF,gFAAwD;AAExD,6DAAgD;AAEhD,6CAAwE;AACxE,2DAA0C;AAC1C,kCAAkC;AAClC,4CAAmD;AAYnD,gDAAoF;AAEpF,qDAA+D;AAqD/D,MAAM,WAAW,GAAG;IAClB,GAAG,+BAAmB;IACtB,GAAG,+BAAiB;IACpB,oBAAoB;IACpB,eAAe;IACf,kBAAkB;IAClB,SAAS;IACT,SAAS;IACT,MAAM;IACN,WAAW;IACX,SAAS;IACT,aAAa;CACd,CAAC;AACF,MAAM,kBAAkB,GAAG;IACzB,KAAK,EAAE,KAAK;IACZ,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,KAAsB,EAAE,KAAa,EAAE,EAAE;IAC/D,M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AQ,EAAE,EAAE;QACzF,IAAI,YAAY,EAAE;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAjBW,QAAA,WAAW,eAiBtB","file":"BaseChart.js","sourcesContent":["import type {\n IVChart,\n IData,\n IInitOption,\n ISpec,\n IVChartConstructor,\n IHierarchyData,\n IVChartRenderOption\n} from '@visactor/vchart';\nimport type { ReactNode } from 'react';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport type { ContainerProps } from '../containers/withContainer';\nimport withContainer from '../containers/withContainer';\nimport type { ChartContextType } from '../context/chart';\nimport RootChartContext from '../context/chart';\nimport type { IView } from '@visactor/vgrammar-core';\nimport { isEqual, isNil, isValid, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport type {\n EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\nimport { bindEventsToChart, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\nimport type { IReactTooltipProps } from '../components/tooltip/interface';\nimport { initCustomTooltip } from '../components/tooltip/util';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps\n extends EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps,\n IReactTooltipProps {\n vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData | IHierarchyData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\n /**\n * add `morphConfig` for chart\n * @since 1.12.7\n */\n morphConfig?: IVChartRenderOption['morphConfig'];\n /** 图表渲染完成事件 */\n onReady?: (instance: IVChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n /**\n * use sync render\n *\n * @since 1.8.3\n * @deprecated 1.9.0\n **/\n useSyncRender?: boolean;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\n 'vchartConstrouctor',\n 'useSyncRender',\n 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'spec',\n 'container',\n 'options',\n 'morphConfig'\n];\nconst defaultMorphConfig = {\n morph: false,\n enableExitAnimation: false\n};\n\nconst getComponentId = (child: React.ReactNode, index: number) => {\n const componentName = child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n return `${componentName}-${index}`;\n};\n\nconst parseSpecFromChildren = (props: Props) => {\n const specFromChildren: Omit<ISpec, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map((child, index) => {\n const parseSpec = child && (child as any).type && (child as any).type.parseSpec;\n\n if (parseSpec && (child as any).props) {\n const childProps = isNil((child as any).props.componentId)\n ? {\n ...(child as any).props,\n componentId: getComponentId(child, index)\n }\n : (child as any).props;\n\n const specResult = parseSpec(childProps);\n\n if (specResult.isSingle) {\n (specFromChildren as any)[specResult.specName] = specResult.spec;\n } else {\n if (!(specFromChildren as any)[specResult.specName]) {\n (specFromChildren as any)[specResult.specName] = [];\n }\n\n (specFromChildren as any)[specResult.specName].push(specResult.spec);\n }\n }\n });\n\n return specFromChildren;\n};\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({});\n useImperativeHandle(ref, () => chartContext.current?.chart);\n const hasSpec = !!props.spec;\n const [view, setView] = useState<IView>(null);\n const isUnmount = useRef<boolean>(false);\n const prevSpec = useRef(pickWithout(props, notSpecKeys));\n const specFromChildren = useRef<Omit<ISpec, 'type' | 'data' | 'width' | 'height'>>(null);\n const eventsBinded = React.useRef<BaseChartProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\n const [tooltipNode, setTooltipNode] = useState<ReactNode>(null);\n\n const parseSpec = (props: Props) => {\n let spec: ISpec;\n\n if (hasSpec && props.spec) {\n spec = props.spec;\n\n if (isValid(props.data)) {\n spec = {\n ...props.spec,\n data: props.data\n } as ISpec;\n }\n } else {\n spec = {\n ...prevSpec.current,\n ...specFromChildren.current\n } as ISpec;\n }\n\n const tooltipSpec = initCustomTooltip(setTooltipNode, props, spec.tooltip);\n if (tooltipSpec) {\n spec.tooltip = tooltipSpec;\n }\n return spec;\n };\n\n const createChart = (props: Props) => {\n const cs = new props.vchartConstrouctor(parseSpec(props), {\n ...props.options,\n onError: props.onError,\n autoFit: true,\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n isUnmount.current = false;\n };\n\n const handleChartRender = (rebindEvent?: boolean) => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n if (rebindEvent) {\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n }\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n setView(newView);\n }\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // event should bind before render when the chart has not been rendered\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n chartContext.current.chart.renderSync({\n reuse: false\n });\n handleChartRender();\n }\n };\n\n useEffect(() => {\n const newSpecFromChildren = hasSpec ? null : parseSpecFromChildren(props);\n\n if (!chartContext.current?.chart) {\n if (!hasSpec) {\n specFromChildren.current = newSpecFromChildren;\n }\n\n createChart(props);\n renderChart();\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n } else if (eventsBinded.current.data !== props.data) {\n chartContext.current.chart.updateFullDataSync(props.data as any);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (\n !isEqual(newSpec, prevSpec.current, { skipFunction: skipFunctionDiff }) ||\n !isEqual(newSpecFromChildren, specFromChildren.current)\n ) {\n prevSpec.current = newSpec;\n specFromChildren.current = newSpecFromChildren;\n\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current && chartContext.current.chart) {\n chartContext.current.chart.release();\n chartContext.current.chart = null;\n }\n }\n eventsBinded.current = null;\n isUnmount.current = true;\n };\n }, []);\n\n return (\n <RootChartContext.Provider value={chartContext.current}>\n <ViewContext.Provider value={view}>\n {toArray(props.children).map((child, index) => {\n if (typeof child === 'string') {\n return null;\n }\n\n const childId = getComponentId(child, index);\n\n return (\n <React.Fragment key={childId}>\n {React.cloneElement(child as React.ReactElement<any, React.JSXElementConstructor<any>>, {\n updateId: updateId,\n componentId: childId\n })}\n </React.Fragment>\n );\n })}\n {tooltipNode}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(\n componentName: string,\n defaultProps?: Partial<T>,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length && defaultProps.vchartConstrouctor) {\n defaultProps.vchartConstrouctor.useRegisters(registers);\n }\n\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (defaultProps) {\n return Object.assign(props, defaultProps);\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
35
35
|
|
|
36
36
|
const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vutils"), chart_1 = __importDefault(require("../context/chart")), eventsUtils_1 = require("../eventsUtils"), vchart_1 = require("@visactor/vchart"), createComponent = (componentName, specName, supportedEvents, isSingle, registers) => {
|
|
37
37
|
registers && registers.length && vchart_1.VChart.useRegisters(registers);
|
|
38
|
-
const ignoreKeys = [ "updateId", "componentId"
|
|
38
|
+
const ignoreKeys = [ "updateId", "componentId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
39
39
|
const context = (0, react_1.useContext)(chart_1.default), eventsBinded = react_1.default.useRef(null), updateId = react_1.default.useRef(props.updateId);
|
|
40
40
|
if (props.updateId !== updateId.current) {
|
|
41
41
|
updateId.current = props.updateId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAA+C;AAE/C,6DAAgD;AAChD,gDAAmD;AACnD,6CAA0C;AAQnC,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,QAAgB,EAChB,eAA+C,EAC/C,QAAkB,EAClB,SAA0B,EAC1B,EAAE;IACF,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,EAAE;QACjC,eAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KAChC;
|
|
1
|
+
{"version":3,"sources":["../src/components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;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B,IAAA,+BAAiB,EAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;iBAC/E;YACH,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,IAAY,CAAC,SAAS,GAAG,CAAC,KAAsD,EAAE,EAAE;QACnF,MAAM,gBAAgB,GAAe,IAAA,oBAAW,EAAI,KAAK,EAAE,WAAW,CAAC,CAAC;QAExE,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAtDW,QAAA,eAAe,mBAsD1B","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { pickWithout } from '@visactor/vutils';\n\nimport RootChartContext from '../context/chart';\nimport { bindEventsToChart } from '../eventsUtils';\nimport { VChart } from '@visactor/vchart';\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number; componentId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length) {\n VChart.useRegisters(registers);\n }\n\n const ignoreKeys = ['updateId', 'componentId'];\n const notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys;\n\n const Comp: React.FC<T> = (props: T) => {\n const context = useContext(RootChartContext);\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n if (props.updateId !== updateId.current) {\n // update triggered by chart when chart is rendered\n updateId.current = props.updateId;\n\n // rebind events after chart render\n const hasPrevEventsBinded = supportedEvents\n ? bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents)\n : false;\n if (hasPrevEventsBinded) {\n eventsBinded.current = props;\n }\n }\n\n useEffect(() => {\n return () => {\n if (supportedEvents) {\n bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);\n }\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n (Comp as any).parseSpec = (props: T & { updateId?: number; componentId?: string }) => {\n const newComponentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\n return {\n spec: newComponentSpec,\n specName,\n isSingle\n };\n };\n\n return Comp;\n};\n"]}
|
package/cjs/context/chart.js
CHANGED
package/cjs/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export * from './components';
|
|
|
4
4
|
export * from './VChart';
|
|
5
5
|
export * from './VChartSimple';
|
|
6
6
|
export { VChart as VChartCore } from '@visactor/vchart';
|
|
7
|
-
export declare const version = "1.13.8-alpha.
|
|
7
|
+
export declare const version = "1.13.8-alpha.8";
|
|
8
8
|
export type { IAreaChartSpec, IBarChartSpec, IBar3dChartSpec, IBoxPlotChartSpec, ICirclePackingChartSpec, ICommonChartSpec, IFunnelChartSpec, IFunnel3dChartSpec, IGaugeChartSpec, IHeatmapChartSpec, IHistogramChartSpec, IHistogram3dChartSpec, ILineChartSpec, IMapChartSpec, IPieChartSpec, IPie3dChartSpec, ICircularProgressChartSpec, ILinearProgressChartSpec, IRadarChartSpec, IRangeColumnChartSpec, IRangeColumn3dChartSpec, IRangeAreaChartSpec, IRoseChartSpec, IScatterChartSpec, ISankeyChartSpec, ISequenceChartSpec, ISunburstChartSpec, ITreemapChartSpec, IWaterfallChartSpec, ICorrelationChartSpec, ILiquidChartSpec, IWordCloud3dChartSpec, IWordCloudChartSpec, IPolarChartSpec, ICartesianChartSpec, ITheme, IInitOption, ISpec, IVChart } from '@visactor/vchart';
|
package/cjs/index.js
CHANGED
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB;AACzB,iDAA+B;AAC/B,2CAAwD;AAA/C,oGAAA,MAAM,OAAc;AAGhB,QAAA,OAAO,GAAG,gBAAgB,CAAC","file":"index.js","sourcesContent":["export * from './charts';\nexport * from './series';\nexport * from './components';\nexport * from './VChart';\nexport * from './VChartSimple';\nexport { VChart as VChartCore } from '@visactor/vchart';\n\n// export the version, since @1.8.3\nexport const version = \"1.13.8-alpha.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB;AACzB,iDAA+B;AAC/B,2CAAwD;AAA/C,oGAAA,MAAM,OAAc;AAGhB,QAAA,OAAO,GAAG,gBAAgB,CAAC","file":"index.js","sourcesContent":["export * from './charts';\nexport * from './series';\nexport * from './components';\nexport * from './VChart';\nexport * from './VChartSimple';\nexport { VChart as VChartCore } from '@visactor/vchart';\n\n// export the version, since @1.8.3\nexport const version = \"1.13.8-alpha.8\";\n\nexport type {\n IAreaChartSpec,\n IBarChartSpec,\n IBar3dChartSpec,\n IBoxPlotChartSpec,\n ICirclePackingChartSpec,\n ICommonChartSpec,\n IFunnelChartSpec,\n IFunnel3dChartSpec,\n IGaugeChartSpec,\n IHeatmapChartSpec,\n IHistogramChartSpec,\n IHistogram3dChartSpec,\n ILineChartSpec,\n IMapChartSpec,\n IPieChartSpec,\n IPie3dChartSpec,\n ICircularProgressChartSpec,\n ILinearProgressChartSpec,\n IRadarChartSpec,\n IRangeColumnChartSpec,\n IRangeColumn3dChartSpec,\n IRangeAreaChartSpec,\n IRoseChartSpec,\n IScatterChartSpec,\n ISankeyChartSpec,\n ISequenceChartSpec,\n ISunburstChartSpec,\n ITreemapChartSpec,\n IWaterfallChartSpec,\n ICorrelationChartSpec,\n ILiquidChartSpec,\n IWordCloud3dChartSpec,\n IWordCloudChartSpec,\n IPolarChartSpec,\n ICartesianChartSpec,\n ITheme,\n IInitOption,\n ISpec,\n IVChart\n} from '@visactor/vchart';\n"]}
|
package/esm/charts/BaseChart.js
CHANGED
|
@@ -78,10 +78,8 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "vchartConst
|
|
|
78
78
|
const newSpec = pickWithout(props, notSpecKeys);
|
|
79
79
|
isEqual(newSpec, prevSpec.current, {
|
|
80
80
|
skipFunction: skipFunctionDiff
|
|
81
|
-
}) && isEqual(newSpecFromChildren, specFromChildren.current,
|
|
82
|
-
|
|
83
|
-
}) || (prevSpec.current = newSpec, specFromChildren.current = newSpecFromChildren,
|
|
84
|
-
chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, null !== (_c = props.morphConfig) && void 0 !== _c ? _c : defaultMorphConfig),
|
|
81
|
+
}) && isEqual(newSpecFromChildren, specFromChildren.current) || (prevSpec.current = newSpec,
|
|
82
|
+
specFromChildren.current = newSpecFromChildren, chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, null !== (_c = props.morphConfig) && void 0 !== _c ? _c : defaultMorphConfig),
|
|
85
83
|
handleChartRender(!0), eventsBinded.current = props);
|
|
86
84
|
}), [ props ]), useEffect((() => () => {
|
|
87
85
|
chartContext && chartContext.current && chartContext.current.chart && (chartContext.current.chart.release(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/BaseChart.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAExD,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,WAAW,MAAM,iBAAiB,C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,CAAC,KAAkE,EAAE;oBACtF,QAAQ,EAAE,QAAQ;oBAClB,WAAW,EAAE,OAAO;iBACrB,CAAC,CACa,CAClB,CAAC;YACJ,CAAC,CAAC;YACD,WAAW,CACS,CACG,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,aAAqB,EACrB,YAAyB,EACzB,SAA0B,EAC1B,EAAE;IACF,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE;QACpE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KACzD;IAED,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,IAAI,YAAY,EAAE;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","file":"BaseChart.js","sourcesContent":["import type {\n IVChart,\n IData,\n IInitOption,\n ISpec,\n IVChartConstructor,\n IHierarchyData,\n IVChartRenderOption\n} from '@visactor/vchart';\nimport type { ReactNode } from 'react';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport type { ContainerProps } from '../containers/withContainer';\nimport withContainer from '../containers/withContainer';\nimport type { ChartContextType } from '../context/chart';\nimport RootChartContext from '../context/chart';\nimport type { IView } from '@visactor/vgrammar-core';\nimport { isEqual, isNil, isValid, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport type {\n EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\nimport { bindEventsToChart, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\nimport type { IReactTooltipProps } from '../components/tooltip/interface';\nimport { initCustomTooltip } from '../components/tooltip/util';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps\n extends EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps,\n IReactTooltipProps {\n vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData | IHierarchyData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\n /**\n * add `morphConfig` for chart\n * @since 1.12.7\n */\n morphConfig?: IVChartRenderOption['morphConfig'];\n /** 图表渲染完成事件 */\n onReady?: (instance: IVChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n /**\n * use sync render\n *\n * @since 1.8.3\n * @deprecated 1.9.0\n **/\n useSyncRender?: boolean;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\n 'vchartConstrouctor',\n 'useSyncRender',\n 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'spec',\n 'container',\n 'options',\n 'morphConfig'\n];\nconst defaultMorphConfig = {\n morph: false,\n enableExitAnimation: false\n};\n\nconst getComponentId = (child: React.ReactNode, index: number) => {\n const componentName = child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n return `${componentName}-${index}`;\n};\n\nconst parseSpecFromChildren = (props: Props) => {\n const specFromChildren: Omit<ISpec, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map((child, index) => {\n const parseSpec = child && (child as any).type && (child as any).type.parseSpec;\n\n if (parseSpec && (child as any).props) {\n const childProps = isNil((child as any).props.componentId)\n ? {\n ...(child as any).props,\n componentId: getComponentId(child, index)\n }\n : (child as any).props;\n\n const specResult = parseSpec(childProps);\n\n if (specResult.isSingle) {\n (specFromChildren as any)[specResult.specName] = specResult.spec;\n } else {\n if (!(specFromChildren as any)[specResult.specName]) {\n (specFromChildren as any)[specResult.specName] = [];\n }\n\n (specFromChildren as any)[specResult.specName].push(specResult.spec);\n }\n }\n });\n\n return specFromChildren;\n};\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({});\n useImperativeHandle(ref, () => chartContext.current?.chart);\n const hasSpec = !!props.spec;\n const [view, setView] = useState<IView>(null);\n const isUnmount = useRef<boolean>(false);\n const prevSpec = useRef(pickWithout(props, notSpecKeys));\n const specFromChildren = useRef<Omit<ISpec, 'type' | 'data' | 'width' | 'height'>>(null);\n const eventsBinded = React.useRef<BaseChartProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\n const [tooltipNode, setTooltipNode] = useState<ReactNode>(null);\n\n const parseSpec = (props: Props) => {\n let spec: ISpec;\n\n if (hasSpec && props.spec) {\n spec = props.spec;\n\n if (isValid(props.data)) {\n spec = {\n ...props.spec,\n data: props.data\n } as ISpec;\n }\n } else {\n spec = {\n ...prevSpec.current,\n ...specFromChildren.current\n } as ISpec;\n }\n\n const tooltipSpec = initCustomTooltip(setTooltipNode, props, spec.tooltip);\n if (tooltipSpec) {\n spec.tooltip = tooltipSpec;\n }\n return spec;\n };\n\n const createChart = (props: Props) => {\n const cs = new props.vchartConstrouctor(parseSpec(props), {\n ...props.options,\n onError: props.onError,\n autoFit: true,\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n isUnmount.current = false;\n };\n\n const handleChartRender = (rebindEvent?: boolean) => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n if (rebindEvent) {\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n }\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n setView(newView);\n }\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // event should bind before render when the chart has not been rendered\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n chartContext.current.chart.renderSync({\n reuse: false\n });\n handleChartRender();\n }\n };\n\n useEffect(() => {\n const newSpecFromChildren = hasSpec ? null : parseSpecFromChildren(props);\n\n if (!chartContext.current?.chart) {\n if (!hasSpec) {\n specFromChildren.current = newSpecFromChildren;\n }\n\n createChart(props);\n renderChart();\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n } else if (eventsBinded.current.data !== props.data) {\n chartContext.current.chart.updateFullDataSync(props.data as any);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (\n !isEqual(newSpec, prevSpec.current, { skipFunction: skipFunctionDiff }) ||\n !isEqual(newSpecFromChildren, specFromChildren.current, { skipFunction: skipFunctionDiff })\n ) {\n prevSpec.current = newSpec;\n specFromChildren.current = newSpecFromChildren;\n\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current && chartContext.current.chart) {\n chartContext.current.chart.release();\n chartContext.current.chart = null;\n }\n }\n eventsBinded.current = null;\n isUnmount.current = true;\n };\n }, []);\n\n return (\n <RootChartContext.Provider value={chartContext.current}>\n <ViewContext.Provider value={view}>\n {toArray(props.children).map((child, index) => {\n if (typeof child === 'string') {\n return null;\n }\n\n const childId = getComponentId(child, index);\n\n return (\n <React.Fragment key={childId}>\n {React.cloneElement(child as React.ReactElement<any, React.JSXElementConstructor<any>>, {\n updateId: updateId,\n componentId: childId\n })}\n </React.Fragment>\n );\n })}\n {tooltipNode}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(\n componentName: string,\n defaultProps?: Partial<T>,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length && defaultProps.vchartConstrouctor) {\n defaultProps.vchartConstrouctor.useRegisters(registers);\n }\n\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (defaultProps) {\n return Object.assign(props, defaultProps);\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/charts/BaseChart.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAEhF,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAExD,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAYnD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEpF,OAAO,EAAE,i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B,SAA0B,EAC1B,EAAE;IACF,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE;QACpE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;KACzD;IAED,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,IAAI,YAAY,EAAE;YAChB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SAC3C;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","file":"BaseChart.js","sourcesContent":["import type {\n IVChart,\n IData,\n IInitOption,\n ISpec,\n IVChartConstructor,\n IHierarchyData,\n IVChartRenderOption\n} from '@visactor/vchart';\nimport type { ReactNode } from 'react';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport type { ContainerProps } from '../containers/withContainer';\nimport withContainer from '../containers/withContainer';\nimport type { ChartContextType } from '../context/chart';\nimport RootChartContext from '../context/chart';\nimport type { IView } from '@visactor/vgrammar-core';\nimport { isEqual, isNil, isValid, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport type {\n EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\nimport { bindEventsToChart, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\nimport type { IReactTooltipProps } from '../components/tooltip/interface';\nimport { initCustomTooltip } from '../components/tooltip/util';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps\n extends EventsProps,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps,\n IReactTooltipProps {\n vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData | IHierarchyData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\n /**\n * add `morphConfig` for chart\n * @since 1.12.7\n */\n morphConfig?: IVChartRenderOption['morphConfig'];\n /** 图表渲染完成事件 */\n onReady?: (instance: IVChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n /**\n * use sync render\n *\n * @since 1.8.3\n * @deprecated 1.9.0\n **/\n useSyncRender?: boolean;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\n 'vchartConstrouctor',\n 'useSyncRender',\n 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'spec',\n 'container',\n 'options',\n 'morphConfig'\n];\nconst defaultMorphConfig = {\n morph: false,\n enableExitAnimation: false\n};\n\nconst getComponentId = (child: React.ReactNode, index: number) => {\n const componentName = child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n return `${componentName}-${index}`;\n};\n\nconst parseSpecFromChildren = (props: Props) => {\n const specFromChildren: Omit<ISpec, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map((child, index) => {\n const parseSpec = child && (child as any).type && (child as any).type.parseSpec;\n\n if (parseSpec && (child as any).props) {\n const childProps = isNil((child as any).props.componentId)\n ? {\n ...(child as any).props,\n componentId: getComponentId(child, index)\n }\n : (child as any).props;\n\n const specResult = parseSpec(childProps);\n\n if (specResult.isSingle) {\n (specFromChildren as any)[specResult.specName] = specResult.spec;\n } else {\n if (!(specFromChildren as any)[specResult.specName]) {\n (specFromChildren as any)[specResult.specName] = [];\n }\n\n (specFromChildren as any)[specResult.specName].push(specResult.spec);\n }\n }\n });\n\n return specFromChildren;\n};\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({});\n useImperativeHandle(ref, () => chartContext.current?.chart);\n const hasSpec = !!props.spec;\n const [view, setView] = useState<IView>(null);\n const isUnmount = useRef<boolean>(false);\n const prevSpec = useRef(pickWithout(props, notSpecKeys));\n const specFromChildren = useRef<Omit<ISpec, 'type' | 'data' | 'width' | 'height'>>(null);\n const eventsBinded = React.useRef<BaseChartProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\n const [tooltipNode, setTooltipNode] = useState<ReactNode>(null);\n\n const parseSpec = (props: Props) => {\n let spec: ISpec;\n\n if (hasSpec && props.spec) {\n spec = props.spec;\n\n if (isValid(props.data)) {\n spec = {\n ...props.spec,\n data: props.data\n } as ISpec;\n }\n } else {\n spec = {\n ...prevSpec.current,\n ...specFromChildren.current\n } as ISpec;\n }\n\n const tooltipSpec = initCustomTooltip(setTooltipNode, props, spec.tooltip);\n if (tooltipSpec) {\n spec.tooltip = tooltipSpec;\n }\n return spec;\n };\n\n const createChart = (props: Props) => {\n const cs = new props.vchartConstrouctor(parseSpec(props), {\n ...props.options,\n onError: props.onError,\n autoFit: true,\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n isUnmount.current = false;\n };\n\n const handleChartRender = (rebindEvent?: boolean) => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n if (rebindEvent) {\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n }\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n setView(newView);\n }\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // event should bind before render when the chart has not been rendered\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n chartContext.current.chart.renderSync({\n reuse: false\n });\n handleChartRender();\n }\n };\n\n useEffect(() => {\n const newSpecFromChildren = hasSpec ? null : parseSpecFromChildren(props);\n\n if (!chartContext.current?.chart) {\n if (!hasSpec) {\n specFromChildren.current = newSpecFromChildren;\n }\n\n createChart(props);\n renderChart();\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n } else if (eventsBinded.current.data !== props.data) {\n chartContext.current.chart.updateFullDataSync(props.data as any);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (\n !isEqual(newSpec, prevSpec.current, { skipFunction: skipFunctionDiff }) ||\n !isEqual(newSpecFromChildren, specFromChildren.current)\n ) {\n prevSpec.current = newSpec;\n specFromChildren.current = newSpecFromChildren;\n\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, props.morphConfig ?? defaultMorphConfig);\n handleChartRender(true);\n eventsBinded.current = props;\n }\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current && chartContext.current.chart) {\n chartContext.current.chart.release();\n chartContext.current.chart = null;\n }\n }\n eventsBinded.current = null;\n isUnmount.current = true;\n };\n }, []);\n\n return (\n <RootChartContext.Provider value={chartContext.current}>\n <ViewContext.Provider value={view}>\n {toArray(props.children).map((child, index) => {\n if (typeof child === 'string') {\n return null;\n }\n\n const childId = getComponentId(child, index);\n\n return (\n <React.Fragment key={childId}>\n {React.cloneElement(child as React.ReactElement<any, React.JSXElementConstructor<any>>, {\n updateId: updateId,\n componentId: childId\n })}\n </React.Fragment>\n );\n })}\n {tooltipNode}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(\n componentName: string,\n defaultProps?: Partial<T>,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length && defaultProps.vchartConstrouctor) {\n defaultProps.vchartConstrouctor.useRegisters(registers);\n }\n\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (defaultProps) {\n return Object.assign(props, defaultProps);\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
@@ -10,7 +10,7 @@ import { VChart } from "@visactor/vchart";
|
|
|
10
10
|
|
|
11
11
|
export const createComponent = (componentName, specName, supportedEvents, isSingle, registers) => {
|
|
12
12
|
registers && registers.length && VChart.useRegisters(registers);
|
|
13
|
-
const ignoreKeys = [ "updateId", "componentId"
|
|
13
|
+
const ignoreKeys = [ "updateId", "componentId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
14
14
|
const context = useContext(RootChartContext), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId);
|
|
15
15
|
if (props.updateId !== updateId.current) {
|
|
16
16
|
updateId.current = props.updateId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/BaseComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAQ1C,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,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AAE;YAEvC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;YAGlC,MAAM,mBAAmB,GAAG,eAAe;gBACzC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC;gBAChF,CAAC,CAAC,KAAK,CAAC;YACV,IAAI,mBAAmB,EAAE;gBACvB,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;aAC9B;SACF;QAED,SAAS,CAAC,GAAG,EAAE;YACb,OAAO,GAAG,EAAE;gBACV,IAAI,eAAe,EAAE;oBACnB,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;iBAC/E;YACH,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,IAAY,CAAC,SAAS,GAAG,CAAC,KAAsD,EAAE,EAAE;QACnF,MAAM,gBAAgB,GAAe,WAAW,CAAI,KAAK,EAAE,WAAW,CAAC,CAAC;QAExE,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { pickWithout } from '@visactor/vutils';\n\nimport RootChartContext from '../context/chart';\nimport { bindEventsToChart } from '../eventsUtils';\nimport { VChart } from '@visactor/vchart';\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number; componentId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean,\n registers?: (() => void)[]\n) => {\n if (registers && registers.length) {\n VChart.useRegisters(registers);\n }\n\n const ignoreKeys = ['updateId', 'componentId'];\n const notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys;\n\n const Comp: React.FC<T> = (props: T) => {\n const context = useContext(RootChartContext);\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n if (props.updateId !== updateId.current) {\n // update triggered by chart when chart is rendered\n updateId.current = props.updateId;\n\n // rebind events after chart render\n const hasPrevEventsBinded = supportedEvents\n ? bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents)\n : false;\n if (hasPrevEventsBinded) {\n eventsBinded.current = props;\n }\n }\n\n useEffect(() => {\n return () => {\n if (supportedEvents) {\n bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);\n }\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n (Comp as any).parseSpec = (props: T & { updateId?: number; componentId?: string }) => {\n const newComponentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\n return {\n spec: newComponentSpec,\n specName,\n isSingle\n };\n };\n\n return Comp;\n};\n"]}
|
package/esm/context/chart.js
CHANGED
package/esm/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export * from './components';
|
|
|
4
4
|
export * from './VChart';
|
|
5
5
|
export * from './VChartSimple';
|
|
6
6
|
export { VChart as VChartCore } from '@visactor/vchart';
|
|
7
|
-
export declare const version = "1.13.8-alpha.
|
|
7
|
+
export declare const version = "1.13.8-alpha.8";
|
|
8
8
|
export type { IAreaChartSpec, IBarChartSpec, IBar3dChartSpec, IBoxPlotChartSpec, ICirclePackingChartSpec, ICommonChartSpec, IFunnelChartSpec, IFunnel3dChartSpec, IGaugeChartSpec, IHeatmapChartSpec, IHistogramChartSpec, IHistogram3dChartSpec, ILineChartSpec, IMapChartSpec, IPieChartSpec, IPie3dChartSpec, ICircularProgressChartSpec, ILinearProgressChartSpec, IRadarChartSpec, IRangeColumnChartSpec, IRangeColumn3dChartSpec, IRangeAreaChartSpec, IRoseChartSpec, IScatterChartSpec, ISankeyChartSpec, ISequenceChartSpec, ISunburstChartSpec, ITreemapChartSpec, IWaterfallChartSpec, ICorrelationChartSpec, ILiquidChartSpec, IWordCloud3dChartSpec, IWordCloudChartSpec, IPolarChartSpec, ICartesianChartSpec, ITheme, IInitOption, ISpec, IVChart } from '@visactor/vchart';
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","file":"index.js","sourcesContent":["export * from './charts';\nexport * from './series';\nexport * from './components';\nexport * from './VChart';\nexport * from './VChartSimple';\nexport { VChart as VChartCore } from '@visactor/vchart';\n\n// export the version, since @1.8.3\nexport const version = \"1.13.8-alpha.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC","file":"index.js","sourcesContent":["export * from './charts';\nexport * from './series';\nexport * from './components';\nexport * from './VChart';\nexport * from './VChartSimple';\nexport { VChart as VChartCore } from '@visactor/vchart';\n\n// export the version, since @1.8.3\nexport const version = \"1.13.8-alpha.8\";\n\nexport type {\n IAreaChartSpec,\n IBarChartSpec,\n IBar3dChartSpec,\n IBoxPlotChartSpec,\n ICirclePackingChartSpec,\n ICommonChartSpec,\n IFunnelChartSpec,\n IFunnel3dChartSpec,\n IGaugeChartSpec,\n IHeatmapChartSpec,\n IHistogramChartSpec,\n IHistogram3dChartSpec,\n ILineChartSpec,\n IMapChartSpec,\n IPieChartSpec,\n IPie3dChartSpec,\n ICircularProgressChartSpec,\n ILinearProgressChartSpec,\n IRadarChartSpec,\n IRangeColumnChartSpec,\n IRangeColumn3dChartSpec,\n IRangeAreaChartSpec,\n IRoseChartSpec,\n IScatterChartSpec,\n ISankeyChartSpec,\n ISequenceChartSpec,\n ISunburstChartSpec,\n ITreemapChartSpec,\n IWaterfallChartSpec,\n ICorrelationChartSpec,\n ILiquidChartSpec,\n IWordCloud3dChartSpec,\n IWordCloudChartSpec,\n IPolarChartSpec,\n ICartesianChartSpec,\n ITheme,\n IInitOption,\n ISpec,\n IVChart\n} from '@visactor/vchart';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/react-vchart",
|
|
3
|
-
"version": "1.13.8-alpha.
|
|
3
|
+
"version": "1.13.8-alpha.8",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "The react version of VChart 4.x",
|
|
6
6
|
"keywords": [
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@visactor/vchart": "1.13.8-alpha.
|
|
26
|
+
"@visactor/vchart": "1.13.8-alpha.8",
|
|
27
27
|
"@visactor/vutils": "~0.19.4",
|
|
28
|
-
"@visactor/vrender-core": "0.22.
|
|
29
|
-
"@visactor/vrender-kits": "0.22.
|
|
30
|
-
"@visactor/vgrammar-core": "0.16.3",
|
|
28
|
+
"@visactor/vrender-core": "0.22.7-alpha.8",
|
|
29
|
+
"@visactor/vrender-kits": "0.22.7-alpha.8",
|
|
30
|
+
"@visactor/vgrammar-core": "0.16.3-alpha.1",
|
|
31
31
|
"react-is": "^18.2.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@vitejs/plugin-react": "3.1.0",
|
|
56
56
|
"vite": "3.2.6",
|
|
57
57
|
"@internal/bundler": "0.0.1",
|
|
58
|
-
"@internal/
|
|
59
|
-
"@internal/
|
|
58
|
+
"@internal/eslint-config": "0.0.1",
|
|
59
|
+
"@internal/ts-config": "0.0.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": ">=16.0.0",
|