@visactor/react-vchart 1.1.0-beta.1 → 1.1.0-beta.3

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 CHANGED
@@ -1,8 +1,18 @@
1
- # React-VChart
1
+ # @visactor/react-vchart
2
2
 
3
- The VChart component encapsulated based on [React](https://react.dev/).
3
+ `@visactor/react-vchart` 是由 [VisActor](visactor.io) 为您提供的 React 封装版本 VChart 图表库。它提供了一系列易于使用的 React 组件,用于方便的在 React 开发环境中创建各种类型的图表,包括折线图、柱状图、饼图等。`@visactor/react-vchart` 的组件具有高度的可定制性和可扩展性,可以通过传递不同的参数和配置来实现不同的图表效果。
4
4
 
5
- ## Usage
5
+ `@visactor/react-vchart` 的主要特点包括:
6
+
7
+ - **易于使用**:`@visactor/react-vchart` 提供了一系列易于使用的 React 组件,可以快速创建各种类型的图表。
8
+ - **可定制性强**:`@visactor/react-vchart` 的组件具有高度的可定制性,可以通过传递不同的参数和配置来实现不同的图表效果。
9
+ - **可扩展性强**:`@visactor/react-vchart` 的组件可以轻松地扩展和定制,可以根据需要添加新的功能和特性。
10
+ - **兼容性好**:`@visactor/react-vchart` 完全继承了 VChart 的可视化能力,可以在不同的浏览器和设备上运行。
11
+ - **支持多种图表类型**:`@visactor/react-vchart` 支持多种类型的图表,包括折线图、柱状图、饼图、雷达图等。
12
+
13
+ `@visactor/react-vchart` 在能力上完全对齐 VChart,并且 API 配置也与 VChart 几乎一致,关于图表的定义和配置可参考[VChart](todo)。
14
+
15
+ ## 开发指引
6
16
 
7
17
  ### Build
8
18
 
@@ -24,3 +34,21 @@ or
24
34
  $ cd packages/react-vchart
25
35
  $ rushx start
26
36
  ```
37
+
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)
@@ -40,8 +40,9 @@ const vchart_1 = __importDefault(require("@visactor/vchart")), react_1 = __impor
40
40
  (0, react_1.useImperativeHandle)(ref, (() => chartContext.current.chart));
41
41
  const hasSpec = !!props.spec, [view, setView] = (0, react_1.useState)(null), isUnmount = (0,
42
42
  react_1.useRef)(!1), prevSpec = (0, react_1.useRef)((0, vutils_1.pickWithout)(props, notSpecKeys)), eventsBinded = react_1.default.useRef(null), parseSpec = props => hasSpec && props.spec ? props.spec : Object.assign(Object.assign({}, prevSpec.current), chartContext.current.specFromChildren), handleChartRender = () => {
43
+ (0, eventsUtils_1.bindEventsToChart)(chartContext.current.chart, props, eventsBinded.current, eventsUtils_1.CHART_EVENTS);
43
44
  const newView = chartContext.current.chart.getCompiler().getVGrammarView();
44
- newView === view || isUnmount.current || (setUpdateId(updateId + 1), props.onReady && props.onReady(chartContext.current.chart, 0 === updateId)),
45
+ isUnmount.current || (setUpdateId(updateId + 1), props.onReady && props.onReady(chartContext.current.chart, 0 === updateId)),
45
46
  setView(newView);
46
47
  };
47
48
  return (0, react_1.useEffect)((() => {
@@ -59,8 +60,7 @@ const vchart_1 = __importDefault(require("@visactor/vchart")), react_1 = __impor
59
60
  chartContext.current = Object.assign(Object.assign({}, chartContext.current), {
60
61
  isChildrenUpdated: !1
61
62
  }), void (eventsBinded.current = props);
62
- if ((0, eventsUtils_1.bindEventsToChart)(chartContext.current.chart, props, eventsBinded.current, eventsUtils_1.CHART_EVENTS),
63
- hasSpec) return void ((0, vutils_1.isEqual)(eventsBinded.current.spec, props.spec) || chartContext.current.chart.updateSpec(parseSpec(props), void 0, {
63
+ if (hasSpec) return void ((0, vutils_1.isEqual)(eventsBinded.current.spec, props.spec) || chartContext.current.chart.updateSpec(parseSpec(props), void 0, {
64
64
  morph: !1
65
65
  }).then(handleChartRender));
66
66
  const newSpec = (0, vutils_1.pickWithout)(props, notSpecKeys);
@@ -1 +1 @@
1
- {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAA8D;AAC9D,+CAAgF;AAChF,gFAA4E;AAC5E,6DAAsE;AAEtE,6CAAwD;AACxD,2DAA0C;AAC1C,kCAAkC;AAClC,4CAAmD;AAEnD,gDAAiG;AA2BjG,MAAM,WAAW,GAAG,CAAC,GAAG,+BAAmB,EAAE,GAAG,+BAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AAEnG,MAAM,SAAS,GAAoB,eAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACjE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAS,CAAC,CAAC,CAAC;IACpD,MAAM,YAAY,GAAG,IAAA,cAAM,EAAmB;QAC5C,gBAAgB,EAAE,EAAE;KACrB,CAAC,CAAC;IAEH,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3D,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,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AAb,KAAK,uBAAL,KAAK,CAAU,EAAE,mCAAI,SAAS,KAAK,EAAE,IACrF,eAAK,CAAC,YAAY,CAAC,KAAqB,EAAE;gBACzC,QAAQ,EAAE,QAAQ;aACnB,CAAC,CACa,CAClB,CAAC;QACJ,CAAC,CAAC,CACmB,CACG,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEI,MAAM,WAAW,GAAG,CAAkB,aAAqB,EAAE,IAAa,EAAE,QAA0B,EAAE,EAAE;IAC/G,MAAM,GAAG,GAAG,IAAA,uBAAa,EAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAU,EAAE,EAAE;QAC3F,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,IAAI,IAAI,EAAE;YACR,uCAAY,KAAK,KAAE,IAAI,IAAG;SAC3B;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,aAAa,CAAC;IAChC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAfW,QAAA,WAAW,eAetB","file":"BaseChart.js","sourcesContent":["import VChart, { IData, IInitOption } from '@visactor/vchart';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport withContainer, { ContainerProps } from '../containers/withContainer';\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport type { IView } from '@visactor/vgrammar';\nimport { isEqual, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport { IMarkElement } from '../components';\nimport { bindEventsToChart, EventsProps, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps extends EventsProps {\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: any;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, 'spec', 'container', 'options'];\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({\n specFromChildren: {}\n });\n\n useImperativeHandle(ref, () => chartContext.current.chart);\n\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 eventsBinded = React.useRef<BaseChartProps>(null);\n\n const parseSpec = (props: Props) => {\n if (hasSpec && props.spec) {\n return props.spec;\n }\n\n return {\n ...prevSpec.current,\n ...chartContext.current.specFromChildren\n };\n };\n\n const createChart = (props: Props) => {\n const cs = new VChart(parseSpec(props), {\n ...props.options,\n autoFit: true,\n mode: 'desktop-browser',\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n };\n\n const handleChartRender = () => {\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n if (newView !== view && !isUnmount.current) {\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n }\n setView(newView);\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart.renderAsync().then(handleChartRender);\n }\n };\n\n useEffect(() => {\n if (!chartContext.current.chart) {\n createChart(props);\n renderChart();\n bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS);\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n eventsBinded.current = props;\n return;\n }\n\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec)) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (!isEqual(newSpec, prevSpec.current) || chartContext.current.isChildrenUpdated) {\n prevSpec.current = newSpec;\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current.chart) {\n chartContext.current.chart.release();\n }\n chartContext.current = null;\n }\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 return (\n <React.Fragment key={(child as any)?.props?.id ?? (child as any)?.id ?? `child-${index}`}>\n {React.cloneElement(child as IMarkElement, {\n updateId: updateId\n })}\n </React.Fragment>\n );\n })}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(componentName: string, type?: string, callback?: (props: T) => T) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: any) => {\n props.type = type;\n\n if (callback) {\n return callback(props);\n }\n\n if (type) {\n return { ...props, type };\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
1
+ {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAA8D;AAC9D,+CAAgF;AAChF,gFAA4E;AAC5E,6DAAsE;AAEtE,6CAAwD;AACxD,2DAA0C;AAC1C,kCAAkC;AAClC,4CAAmD;AAEnD,gDAAiG;AA2BjG,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aseChart.js","sourcesContent":["import VChart, { IData, IInitOption } from '@visactor/vchart';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport withContainer, { ContainerProps } from '../containers/withContainer';\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport type { IView } from '@visactor/vgrammar';\nimport { isEqual, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport { IMarkElement } from '../components';\nimport { bindEventsToChart, EventsProps, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps extends EventsProps {\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: any;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, 'spec', 'container', 'options'];\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({\n specFromChildren: {}\n });\n\n useImperativeHandle(ref, () => chartContext.current.chart);\n\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 eventsBinded = React.useRef<BaseChartProps>(null);\n\n const parseSpec = (props: Props) => {\n if (hasSpec && props.spec) {\n return props.spec;\n }\n\n return {\n ...prevSpec.current,\n ...chartContext.current.specFromChildren\n };\n };\n\n const createChart = (props: Props) => {\n const cs = new VChart(parseSpec(props), {\n ...props.options,\n autoFit: true,\n mode: 'desktop-browser',\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n };\n\n const handleChartRender = () => {\n // rebind events after render\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n if (!isUnmount.current) {\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n }\n setView(newView);\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart.renderAsync().then(handleChartRender);\n }\n };\n\n useEffect(() => {\n if (!chartContext.current.chart) {\n createChart(props);\n renderChart();\n bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS);\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec)) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (!isEqual(newSpec, prevSpec.current) || chartContext.current.isChildrenUpdated) {\n prevSpec.current = newSpec;\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current.chart) {\n chartContext.current.chart.release();\n }\n chartContext.current = null;\n }\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 return (\n <React.Fragment key={(child as any)?.props?.id ?? (child as any)?.id ?? `child-${index}`}>\n {React.cloneElement(child as IMarkElement, {\n updateId: updateId\n })}\n </React.Fragment>\n );\n })}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(componentName: string, type?: string, callback?: (props: T) => T) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: any) => {\n props.type = type;\n\n if (callback) {\n return callback(props);\n }\n\n if (type) {\n return { ...props, type };\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  export interface BaseComponentProps {
3
3
  id?: string | number;
4
4
  }
@@ -38,9 +38,11 @@ const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vu
38
38
  const context = (0, react_1.useContext)(chart_1.default), id = react_1.default.useRef((0,
39
39
  vutils_1.isNil)(props.id) ? (0, util_1.uid)(specName) : props.id), eventsBinded = react_1.default.useRef(null), updateId = react_1.default.useRef(props.updateId), componentSpec = (0,
40
40
  vutils_1.pickWithout)(props, notSpecKeys);
41
- return !!supportedEvents && (0, eventsUtils_1.bindEventsToChart)(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props),
42
- props.updateId !== updateId.current ? updateId.current = props.updateId : updateToContext(context, id.current, specName, isSingle, componentSpec),
43
- (0, react_1.useEffect)((() => () => {
41
+ if (props.updateId !== updateId.current) {
42
+ updateId.current = props.updateId;
43
+ !!supportedEvents && (0, eventsUtils_1.bindEventsToChart)(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
44
+ } else updateToContext(context, id.current, specName, isSingle, componentSpec);
45
+ return (0, react_1.useEffect)((() => () => {
44
46
  supportedEvents && (0, eventsUtils_1.bindEventsToChart)(context.chart, null, eventsBinded.current, supportedEvents),
45
47
  deleteToContext(context, id.current, specName, isSingle);
46
48
  }), []), null;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CA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AC,mBACV,EAAE,IACC,KAAK,CACT,CAAC;SACH;aAAM;YACL,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,IAAI,iBACrC,EAAE,IACC,KAAK,EACR,CAAC;SACJ;KACF;IACD,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,OAAyB,EACzB,EAAmB,EACnB,QAAgB,EAChB,QAAiB,EACjB,EAAE;;IACF,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;QAC7B,OAAO;KACR;IAED,IAAI,QAAQ,EAAE;QACZ,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;KAC3C;SAAM;QACL,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAE/D,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YAE1E,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;YAC9C,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;SAClC;KACF;AACH,CAAC,CAAC","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from \"react\";\nimport { isNil, pickWithout } from \"@visactor/vutils\";\n\nimport RootChartContext, { ChartContextType } from \"../context/chart\";\nimport { bindEventsToChart } from \"../eventsUtils\";\nimport { uid } from \"../util\";\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean\n) => {\n const ignoreKeys = [\"id\", \"updateId\"];\n const notSpecKeys = supportedEvents\n ? Object.keys(supportedEvents).concat(ignoreKeys)\n : ignoreKeys;\n\n const Comp: React.FC<T> = (props: T) => {\n const context = useContext(RootChartContext);\n const id = React.useRef<string | number>(\n isNil(props.id) ? uid(specName) : props.id\n );\n\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n\n const componentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n const hasPrevEventsBinded =\n !!supportedEvents &&\n bindEventsToChart(\n context.chart,\n props,\n eventsBinded.current,\n supportedEvents\n );\n if (hasPrevEventsBinded) {\n eventsBinded.current = props;\n }\n\n if (props.updateId !== updateId.current) {\n updateId.current = props.updateId;\n } else {\n updateToContext(context, id.current, specName, isSingle, componentSpec);\n }\n\n useEffect(() => {\n return () => {\n !!supportedEvents &&\n bindEventsToChart(\n context.chart,\n null,\n eventsBinded.current,\n supportedEvents\n );\n deleteToContext(context, id.current, specName, isSingle);\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n\nconst updateToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean,\n props: Partial<ComponentProps>\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = { ...props };\n } else {\n if (!context.specFromChildren[specName]) {\n context.specFromChildren[specName] = [];\n }\n\n const comps = context.specFromChildren[specName];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n comps[index] = {\n id,\n ...props,\n };\n } else {\n context.specFromChildren[specName].push({\n id,\n ...props,\n });\n }\n }\n context.isChildrenUpdated = true;\n};\n\nconst deleteToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = null;\n } else {\n const comps = context.specFromChildren[specName] ?? [];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));\n\n context.specFromChildren[specName] = newComps;\n context.isChildrenUpdated = true;\n }\n }\n};\n"]}
1
+ {"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAAsD;AAEtD,6DAAsE;AACtE,gDAAmD;AACnD,kCAA8B;AAQvB,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,QAAgB,EAChB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAEnG,MAAM,IAAI,GAAgB,CAAC,KAAQ,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,eAAgB,CAAC,CAAC;QAC7C,MAAM,EAAE,GAAG,eAAK,CAAC,MAAM,CAAkB,IAAA,cAAK,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAA,UAAG,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAErF,MAAM,YAAY,GAAG,eAAK,CAAC,MAAM,CAAI,IAAI,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAS,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEtD,MAAM,aAAa,GAAe,IAAA,oBAAW,EAAI,KAAK,EAAE,WAAW,CAAC,CAAC;QAErE,IAAI,KAAK,CAA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,CAAC,CAAC,CAAC,CAAC;YAE1E,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;YAC9C,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;SAClC;KACF;AACH,CAAC,CAAC","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil, pickWithout } from '@visactor/vutils';\n\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport { bindEventsToChart } from '../eventsUtils';\nimport { uid } from '../util';\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean\n) => {\n const ignoreKeys = ['id', 'updateId'];\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 id = React.useRef<string | number>(isNil(props.id) ? uid(specName) : props.id);\n\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n\n const componentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\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 } else {\n updateToContext(context, id.current, specName, isSingle, componentSpec);\n }\n\n useEffect(() => {\n return () => {\n if (supportedEvents) {\n bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);\n }\n deleteToContext(context, id.current, specName, isSingle);\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n\nconst updateToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean,\n props: Partial<ComponentProps>\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = { ...props };\n } else {\n if (!context.specFromChildren[specName]) {\n context.specFromChildren[specName] = [];\n }\n\n const comps = context.specFromChildren[specName];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n comps[index] = {\n id,\n ...props\n };\n } else {\n context.specFromChildren[specName].push({\n id,\n ...props\n });\n }\n }\n context.isChildrenUpdated = true;\n};\n\nconst deleteToContext = (context: ChartContextType, id: string | number, specName: string, isSingle: boolean) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = null;\n } else {\n const comps = context.specFromChildren[specName] ?? [];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));\n\n context.specFromChildren[specName] = newComps;\n context.isChildrenUpdated = true;\n }\n }\n};\n"]}
@@ -43,8 +43,9 @@ Object.defineProperty(exports, "__esModule", {
43
43
 
44
44
  const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vutils"), view_1 = __importDefault(require("../context/view")), util_1 = require("../util"), Mark = props => {
45
45
  const context = (0, react_1.useContext)(view_1.default), id = react_1.default.useRef((0,
46
- vutils_1.isNil)(props.id) ? (0, util_1.uid)("mark") : props.id);
47
- return context && addOrUpdateMark(context, id.current, props), (0, react_1.useEffect)((() => () => {
46
+ vutils_1.isNil)(props.id) ? (0, util_1.uid)("mark") : props.id), updateId = react_1.default.useRef(props.updateId);
47
+ return props.updateId !== updateId.current && (updateId.current = props.updateId,
48
+ context && addOrUpdateMark(context, id.current, props)), (0, react_1.useEffect)((() => () => {
48
49
  context && removeMark(context, id.current);
49
50
  }), []), null;
50
51
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Mark.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAAyC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CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aACvG,IAAI,CAAC,EAAE,CAAC,CAAC;KACb;IAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAU,EAAE,EAAE;IAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACjC,IAAY,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC","file":"Mark.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil } from '@visactor/vutils';\nimport type { IView, MarkSpec } from '@visactor/vgrammar';\n\nimport ViewContext from '../context/view';\nimport { uid } from '../util';\n\nexport interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {\n id?: string | number;\n glyphType?: string;\n}\n\nexport interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {\n id: string | number;\n}\n\ntype Props = MarkProps & { updateId: number };\n\nexport const Mark: React.FC<Props> = (props: Props) => {\n const context = useContext(ViewContext);\n const id = React.useRef<string | number>(isNil(props.id) ? uid('mark') : props.id);\n\n if (context) {\n addOrUpdateMark(context, id.current as string, props);\n }\n\n useEffect(() => {\n return () => {\n if (context) {\n removeMark(context, id.current as string);\n }\n };\n }, []);\n\n return null;\n};\n\nconst addOrUpdateMark = (view: IView, id: string, props: Props) => {\n if (!view.renderer) {\n // view has been released\n return;\n }\n\n let mark = view.getMarkById(id);\n const { group, glyphType, updateId, ...others } = props;\n if (!mark) {\n mark = (view as any)\n .mark(props.type, props.group ?? view.rootMark, props.glyphType ? { glyphType: props.glyphType } : null)\n .name(id);\n }\n\n mark.parse(others);\n view.runAsync();\n};\n\nconst removeMark = (view: IView, id: string) => {\n if (view.renderer) {\n const mark = view.get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I,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,KAAgB,KAAK,EAAhB,MAAM,UAAK,KAAK,EAAjD,kCAAyC,CAAQ,CAAC;IACxD,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAI,IAAY;aACjB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAA,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aACvG,IAAI,CAAC,EAAE,CAAC,CAAC;KACb;IAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAU,EAAE,EAAE;IAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACjC,IAAY,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC","file":"Mark.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil } from '@visactor/vutils';\nimport type { IView, MarkSpec } from '@visactor/vgrammar';\n\nimport ViewContext from '../context/view';\nimport { uid } from '../util';\n\nexport interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {\n id?: string | number;\n glyphType?: string;\n}\n\nexport interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {\n id: string | number;\n}\n\ntype Props = MarkProps & { updateId: number };\n\nexport const Mark: React.FC<Props> = (props: Props) => {\n const context = useContext(ViewContext);\n const id = React.useRef<string | number>(isNil(props.id) ? uid('mark') : props.id);\n const updateId = React.useRef<number>(props.updateId);\n\n if (props.updateId !== updateId.current) {\n // only update mark when chart finished render\n updateId.current = props.updateId;\n if (context) {\n addOrUpdateMark(context, id.current as string, props);\n }\n }\n\n useEffect(() => {\n return () => {\n if (context) {\n removeMark(context, id.current as string);\n }\n };\n }, []);\n\n return null;\n};\n\nconst addOrUpdateMark = (view: IView, id: string, props: Props) => {\n if (!view.renderer) {\n // view has been released\n return;\n }\n\n let mark = view.getMarkById(id);\n const { group, glyphType, updateId, ...others } = props;\n if (!mark) {\n mark = (view as any)\n .mark(props.type, props.group ?? view.rootMark, props.glyphType ? { glyphType: props.glyphType } : null)\n .name(id);\n }\n\n mark.parse(others);\n view.runAsync();\n};\n\nconst removeMark = (view: IView, id: string) => {\n if (view.renderer) {\n const mark = view.getMarkById(id);\n (view as any).removeGrammar(id);\n }\n};\n"]}
@@ -22,8 +22,9 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "spec", "con
22
22
  });
23
23
  useImperativeHandle(ref, (() => chartContext.current.chart));
24
24
  const hasSpec = !!props.spec, [view, setView] = useState(null), isUnmount = useRef(!1), prevSpec = useRef(pickWithout(props, notSpecKeys)), eventsBinded = React.useRef(null), parseSpec = props => hasSpec && props.spec ? props.spec : Object.assign(Object.assign({}, prevSpec.current), chartContext.current.specFromChildren), handleChartRender = () => {
25
+ bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);
25
26
  const newView = chartContext.current.chart.getCompiler().getVGrammarView();
26
- newView === view || isUnmount.current || (setUpdateId(updateId + 1), props.onReady && props.onReady(chartContext.current.chart, 0 === updateId)),
27
+ isUnmount.current || (setUpdateId(updateId + 1), props.onReady && props.onReady(chartContext.current.chart, 0 === updateId)),
27
28
  setView(newView);
28
29
  };
29
30
  return useEffect((() => {
@@ -40,8 +41,7 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "spec", "con
40
41
  bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS), chartContext.current = Object.assign(Object.assign({}, chartContext.current), {
41
42
  isChildrenUpdated: !1
42
43
  }), void (eventsBinded.current = props);
43
- if (bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS),
44
- hasSpec) return void (isEqual(eventsBinded.current.spec, props.spec) || chartContext.current.chart.updateSpec(parseSpec(props), void 0, {
44
+ if (hasSpec) return void (isEqual(eventsBinded.current.spec, props.spec) || chartContext.current.chart.updateSpec(parseSpec(props), void 0, {
45
45
  morph: !1
46
46
  }).then(handleChartRender));
47
47
  const newSpec = pickWithout(props, notSpecKeys);
@@ -1 +1 @@
1
- {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":"AAAA,OAAO,MAA8B,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,aAAiC,MAAM,6BAA6B,CAAC;AAC5E,OAAO,gBAAsC,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAe,iBAAiB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA2BjG,MAAM,WAAW,GAAG,CAAC,GAAG,mBAAmB,EAAE,GAAG,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AAEnG,MAAM,SAAS,GAAoB,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACjE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAS,CAAC,CAAC,CAAC;IACpD,MAAM,YAAY,GAAG,M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C,QAAQ,IAAC,GAAG,EAAE,MAAA,MAAA,MAAC,KAAa,aAAb,KAAK,uBAAL,KAAK,CAAU,KAAK,0CAAE,EAAE,mCAAK,KAAa,aAAb,KAAK,uBAAL,KAAK,CAAU,EAAE,mCAAI,SAAS,KAAK,EAAE,IACrF,KAAK,CAAC,YAAY,CAAC,KAAqB,EAAE;gBACzC,QAAQ,EAAE,QAAQ;aACnB,CAAC,CACa,CAClB,CAAC;QACJ,CAAC,CAAC,CACmB,CACG,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAkB,aAAqB,EAAE,IAAa,EAAE,QAA0B,EAAE,EAAE;IAC/G,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAU,EAAE,EAAE;QAC3F,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,IAAI,IAAI,EAAE;YACR,uCAAY,KAAK,KAAE,IAAI,IAAG;SAC3B;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 VChart, { IData, IInitOption } from '@visactor/vchart';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport withContainer, { ContainerProps } from '../containers/withContainer';\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport type { IView } from '@visactor/vgrammar';\nimport { isEqual, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport { IMarkElement } from '../components';\nimport { bindEventsToChart, EventsProps, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps extends EventsProps {\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: any;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, 'spec', 'container', 'options'];\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({\n specFromChildren: {}\n });\n\n useImperativeHandle(ref, () => chartContext.current.chart);\n\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 eventsBinded = React.useRef<BaseChartProps>(null);\n\n const parseSpec = (props: Props) => {\n if (hasSpec && props.spec) {\n return props.spec;\n }\n\n return {\n ...prevSpec.current,\n ...chartContext.current.specFromChildren\n };\n };\n\n const createChart = (props: Props) => {\n const cs = new VChart(parseSpec(props), {\n ...props.options,\n autoFit: true,\n mode: 'desktop-browser',\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n };\n\n const handleChartRender = () => {\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n if (newView !== view && !isUnmount.current) {\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n }\n setView(newView);\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart.renderAsync().then(handleChartRender);\n }\n };\n\n useEffect(() => {\n if (!chartContext.current.chart) {\n createChart(props);\n renderChart();\n bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS);\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n eventsBinded.current = props;\n return;\n }\n\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec)) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (!isEqual(newSpec, prevSpec.current) || chartContext.current.isChildrenUpdated) {\n prevSpec.current = newSpec;\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current.chart) {\n chartContext.current.chart.release();\n }\n chartContext.current = null;\n }\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 return (\n <React.Fragment key={(child as any)?.props?.id ?? (child as any)?.id ?? `child-${index}`}>\n {React.cloneElement(child as IMarkElement, {\n updateId: updateId\n })}\n </React.Fragment>\n );\n })}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(componentName: string, type?: string, callback?: (props: T) => T) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: any) => {\n props.type = type;\n\n if (callback) {\n return callback(props);\n }\n\n if (type) {\n return { ...props, type };\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
1
+ {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":"AAAA,OAAO,MAA8B,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,EAAE,QAAQ,EA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F,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,IAAI,IAAI,EAAE;YACR,uCAAY,KAAK,KAAE,IAAI,IAAG;SAC3B;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 VChart, { IData, IInitOption } from '@visactor/vchart';\nimport React, { useState, useEffect, useRef, useImperativeHandle } from 'react';\nimport withContainer, { ContainerProps } from '../containers/withContainer';\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport type { IView } from '@visactor/vgrammar';\nimport { isEqual, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport { IMarkElement } from '../components';\nimport { bindEventsToChart, EventsProps, CHART_EVENTS_KEYS, CHART_EVENTS } from '../eventsUtils';\n\nexport type ChartOptions = Omit<IInitOption, 'dom'>;\n\nexport interface BaseChartProps extends EventsProps {\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: any;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, 'spec', 'container', 'options'];\n\nconst BaseChart: React.FC<Props> = React.forwardRef((props, ref) => {\n const [updateId, setUpdateId] = useState<number>(0);\n const chartContext = useRef<ChartContextType>({\n specFromChildren: {}\n });\n\n useImperativeHandle(ref, () => chartContext.current.chart);\n\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 eventsBinded = React.useRef<BaseChartProps>(null);\n\n const parseSpec = (props: Props) => {\n if (hasSpec && props.spec) {\n return props.spec;\n }\n\n return {\n ...prevSpec.current,\n ...chartContext.current.specFromChildren\n };\n };\n\n const createChart = (props: Props) => {\n const cs = new VChart(parseSpec(props), {\n ...props.options,\n autoFit: true,\n mode: 'desktop-browser',\n dom: props.container\n });\n chartContext.current = { ...chartContext.current, chart: cs };\n };\n\n const handleChartRender = () => {\n // rebind events after render\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\n\n const newView = chartContext.current.chart.getCompiler().getVGrammarView();\n if (!isUnmount.current) {\n setUpdateId(updateId + 1);\n if (props.onReady) {\n props.onReady(chartContext.current.chart, updateId === 0);\n }\n }\n setView(newView);\n };\n\n const renderChart = () => {\n if (chartContext.current.chart) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart.renderAsync().then(handleChartRender);\n }\n };\n\n useEffect(() => {\n if (!chartContext.current.chart) {\n createChart(props);\n renderChart();\n bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS);\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec)) {\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (!isEqual(newSpec, prevSpec.current) || chartContext.current.isChildrenUpdated) {\n prevSpec.current = newSpec;\n // eslint-disable-next-line promise/catch-or-return\n chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false }) // morph临时关掉\n .then(handleChartRender);\n }\n chartContext.current = {\n ...chartContext.current,\n isChildrenUpdated: false\n };\n }, [props]);\n\n useEffect(() => {\n return () => {\n if (chartContext) {\n if (chartContext.current.chart) {\n chartContext.current.chart.release();\n }\n chartContext.current = null;\n }\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 return (\n <React.Fragment key={(child as any)?.props?.id ?? (child as any)?.id ?? `child-${index}`}>\n {React.cloneElement(child as IMarkElement, {\n updateId: updateId\n })}\n </React.Fragment>\n );\n })}\n </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(componentName: string, type?: string, callback?: (props: T) => T) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: any) => {\n props.type = type;\n\n if (callback) {\n return callback(props);\n }\n\n if (type) {\n return { ...props, type };\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
  export interface BaseComponentProps {
3
3
  id?: string | number;
4
4
  }
@@ -11,9 +11,11 @@ import { uid } from "../util";
11
11
  export const createComponent = (componentName, specName, supportedEvents, isSingle) => {
12
12
  const ignoreKeys = [ "id", "updateId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
13
13
  const context = useContext(RootChartContext), id = React.useRef(isNil(props.id) ? uid(specName) : props.id), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId), componentSpec = pickWithout(props, notSpecKeys);
14
- return !!supportedEvents && bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props),
15
- props.updateId !== updateId.current ? updateId.current = props.updateId : updateToContext(context, id.current, specName, isSingle, componentSpec),
16
- useEffect((() => () => {
14
+ if (props.updateId !== updateId.current) {
15
+ updateId.current = props.updateId;
16
+ !!supportedEvents && bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
17
+ } else updateToContext(context, id.current, specName, isSingle, componentSpec);
18
+ return useEffect((() => () => {
17
19
  supportedEvents && bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents),
18
20
  deleteToContext(context, id.current, specName, isSingle);
19
21
  }), []), null;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,gBAAsC,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAQ9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,QAAgB,EAChB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,eAAe;QACjC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;QACjD,CAAC,CAAC,UAAU,CAAC;IAEf,MAAM,IAAI,GAAgB,CAAC,KAAQ,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;QAC7C,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CACrB,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAC3C,CAAC;QAEF,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAI,IAAI,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAS,KAAK,CAAC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AAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YAE1E,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;YAC9C,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;SAClC;KACF;AACH,CAAC,CAAC","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from \"react\";\nimport { isNil, pickWithout } from \"@visactor/vutils\";\n\nimport RootChartContext, { ChartContextType } from \"../context/chart\";\nimport { bindEventsToChart } from \"../eventsUtils\";\nimport { uid } from \"../util\";\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean\n) => {\n const ignoreKeys = [\"id\", \"updateId\"];\n const notSpecKeys = supportedEvents\n ? Object.keys(supportedEvents).concat(ignoreKeys)\n : ignoreKeys;\n\n const Comp: React.FC<T> = (props: T) => {\n const context = useContext(RootChartContext);\n const id = React.useRef<string | number>(\n isNil(props.id) ? uid(specName) : props.id\n );\n\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n\n const componentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n const hasPrevEventsBinded =\n !!supportedEvents &&\n bindEventsToChart(\n context.chart,\n props,\n eventsBinded.current,\n supportedEvents\n );\n if (hasPrevEventsBinded) {\n eventsBinded.current = props;\n }\n\n if (props.updateId !== updateId.current) {\n updateId.current = props.updateId;\n } else {\n updateToContext(context, id.current, specName, isSingle, componentSpec);\n }\n\n useEffect(() => {\n return () => {\n !!supportedEvents &&\n bindEventsToChart(\n context.chart,\n null,\n eventsBinded.current,\n supportedEvents\n );\n deleteToContext(context, id.current, specName, isSingle);\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n\nconst updateToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean,\n props: Partial<ComponentProps>\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = { ...props };\n } else {\n if (!context.specFromChildren[specName]) {\n context.specFromChildren[specName] = [];\n }\n\n const comps = context.specFromChildren[specName];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n comps[index] = {\n id,\n ...props,\n };\n } else {\n context.specFromChildren[specName].push({\n id,\n ...props,\n });\n }\n }\n context.isChildrenUpdated = true;\n};\n\nconst deleteToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = null;\n } else {\n const comps = context.specFromChildren[specName] ?? [];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));\n\n context.specFromChildren[specName] = newComps;\n context.isChildrenUpdated = true;\n }\n }\n};\n"]}
1
+ {"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,gBAAsC,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAQ9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,aAAqB,EACrB,QAAgB,EAChB,eAA+C,EAC/C,QAAkB,EAClB,EAAE;IACF,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAU,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gB,EAAE;QAC7B,OAAO;KACR;IAED,IAAI,QAAQ,EAAE;QACZ,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;KAC3C;SAAM;QACL,MAAM,KAAK,GAAG,MAAA,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAE/D,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;YAE1E,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;YAC9C,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;SAClC;KACF;AACH,CAAC,CAAC","file":"BaseComponent.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil, pickWithout } from '@visactor/vutils';\n\nimport RootChartContext, { ChartContextType } from '../context/chart';\nimport { bindEventsToChart } from '../eventsUtils';\nimport { uid } from '../util';\n\nexport interface BaseComponentProps {\n id?: string | number;\n}\n\ntype ComponentProps = BaseComponentProps & { updateId?: number };\n\nexport const createComponent = <T extends ComponentProps>(\n componentName: string,\n specName: string,\n supportedEvents?: Record<string, string> | null,\n isSingle?: boolean\n) => {\n const ignoreKeys = ['id', 'updateId'];\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 id = React.useRef<string | number>(isNil(props.id) ? uid(specName) : props.id);\n\n const eventsBinded = React.useRef<T>(null);\n const updateId = React.useRef<number>(props.updateId);\n\n const componentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\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 } else {\n updateToContext(context, id.current, specName, isSingle, componentSpec);\n }\n\n useEffect(() => {\n return () => {\n if (supportedEvents) {\n bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);\n }\n deleteToContext(context, id.current, specName, isSingle);\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n\nconst updateToContext = (\n context: ChartContextType,\n id: string | number,\n specName: string,\n isSingle: boolean,\n props: Partial<ComponentProps>\n) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = { ...props };\n } else {\n if (!context.specFromChildren[specName]) {\n context.specFromChildren[specName] = [];\n }\n\n const comps = context.specFromChildren[specName];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n comps[index] = {\n id,\n ...props\n };\n } else {\n context.specFromChildren[specName].push({\n id,\n ...props\n });\n }\n }\n context.isChildrenUpdated = true;\n};\n\nconst deleteToContext = (context: ChartContextType, id: string | number, specName: string, isSingle: boolean) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (isSingle) {\n context.specFromChildren[specName] = null;\n } else {\n const comps = context.specFromChildren[specName] ?? [];\n const index = comps.findIndex((entry: any) => entry.id === id);\n\n if (index >= 0) {\n const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));\n\n context.specFromChildren[specName] = newComps;\n context.isChildrenUpdated = true;\n }\n }\n};\n"]}
@@ -17,8 +17,9 @@ import ViewContext from "../context/view";
17
17
  import { uid } from "../util";
18
18
 
19
19
  export const Mark = props => {
20
- const context = useContext(ViewContext), id = React.useRef(isNil(props.id) ? uid("mark") : props.id);
21
- return context && addOrUpdateMark(context, id.current, props), useEffect((() => () => {
20
+ const context = useContext(ViewContext), id = React.useRef(isNil(props.id) ? uid("mark") : props.id), updateId = React.useRef(props.updateId);
21
+ return props.updateId !== updateId.current && (updateId.current = props.updateId,
22
+ context && addOrUpdateMark(context, id.current, props)), useEffect((() => () => {
22
23
  context && removeMark(context, id.current);
23
24
  }), []), null;
24
25
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Mark.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAa9B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,KAAY,EAAE,EAAE;IACpD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAkB,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEnF,IAAI,OAAO,EAAE;QACX,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,OAAiB,EAAE,KAAK,CAAC,CAAC;KACvD;IAED,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE;YACV,IAAI,OAAO,EAAE;gBACX,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,OAAiB,CAAC,CAAC;aAC3C;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAW,EAAE,EAAU,EAAE,KAAY,EAAE,EAAE;;IAChE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;QAElB,OAAO;KACR;IAED,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,KAAgB,KAAK,EAAhB,MAAM,UAAK,KAAK,EAAjD,kCAAyC,CAAQ,CAAC;IACxD,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAI,IAAY;aACjB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAA,KAAK,CAAC,KAAK,mCAAI,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aACvG,IAAI,CAAC,EAAE,CAAC,CAAC;KACb;IAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,IAAW,EAAE,EAAU,EAAE,EAAE;IAC7C,IAAI,IAAI,CAAC,QAAQ,EAAE;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACjC,IAAY,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC","file":"Mark.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil } from '@visactor/vutils';\nimport type { IView, MarkSpec } from '@visactor/vgrammar';\n\nimport ViewContext from '../context/view';\nimport { uid } from '../util';\n\nexport interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {\n id?: string | number;\n glyphType?: string;\n}\n\nexport interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {\n id: string | number;\n}\n\ntype Props = MarkProps & { updateId: number };\n\nexport const Mark: React.FC<Props> = (props: Props) => {\n const context = useContext(ViewContext);\n const id = React.useRef<string | number>(isNil(props.id) ? uid('mark') : props.id);\n\n if (context) {\n addOrUpdateMark(context, id.current as string, props);\n }\n\n useEffect(() => {\n return () => {\n if (context) {\n removeMark(context, id.current as string);\n }\n };\n }, []);\n\n return null;\n};\n\nconst addOrUpdateMark = (view: IView, id: string, props: Props) => {\n if (!view.renderer) {\n // view has been released\n return;\n }\n\n let mark = view.getMarkById(id);\n const { group, glyphType, updateId, ...others } = props;\n if (!mark) {\n mark = (view as any)\n .mark(props.type, props.group ?? view.rootMark, props.glyphType ? { glyphType: props.glyphType } : null)\n .name(id);\n }\n\n mark.parse(others);\n view.runAsync();\n};\n\nconst removeMark = (view: IView, id: string) => {\n if (view.renderer) {\n const mark = view.getMarkById(id);\n (view as any).removeGrammar(id);\n }\n};\n"]}
1
+ {"version":3,"sources":["components/Mark.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGzC,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAa9B,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,KAAY,EAAE,EAAE;IACpD,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAkB,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnF,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAS,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEtD,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,EAAE;QAEvC,QAAQ,CAAC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AC,WAAW,CAAC,EAAE,CAAC,CAAC;QACjC,IAAY,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;KACjC;AACH,CAAC,CAAC","file":"Mark.js","sourcesContent":["import React, { useContext, useEffect } from 'react';\nimport { isNil } from '@visactor/vutils';\nimport type { IView, MarkSpec } from '@visactor/vgrammar';\n\nimport ViewContext from '../context/view';\nimport { uid } from '../util';\n\nexport interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {\n id?: string | number;\n glyphType?: string;\n}\n\nexport interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {\n id: string | number;\n}\n\ntype Props = MarkProps & { updateId: number };\n\nexport const Mark: React.FC<Props> = (props: Props) => {\n const context = useContext(ViewContext);\n const id = React.useRef<string | number>(isNil(props.id) ? uid('mark') : props.id);\n const updateId = React.useRef<number>(props.updateId);\n\n if (props.updateId !== updateId.current) {\n // only update mark when chart finished render\n updateId.current = props.updateId;\n if (context) {\n addOrUpdateMark(context, id.current as string, props);\n }\n }\n\n useEffect(() => {\n return () => {\n if (context) {\n removeMark(context, id.current as string);\n }\n };\n }, []);\n\n return null;\n};\n\nconst addOrUpdateMark = (view: IView, id: string, props: Props) => {\n if (!view.renderer) {\n // view has been released\n return;\n }\n\n let mark = view.getMarkById(id);\n const { group, glyphType, updateId, ...others } = props;\n if (!mark) {\n mark = (view as any)\n .mark(props.type, props.group ?? view.rootMark, props.glyphType ? { glyphType: props.glyphType } : null)\n .name(id);\n }\n\n mark.parse(others);\n view.runAsync();\n};\n\nconst removeMark = (view: IView, id: string) => {\n if (view.renderer) {\n const mark = view.getMarkById(id);\n (view as any).removeGrammar(id);\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/react-vchart",
3
- "version": "1.1.0-beta.1",
3
+ "version": "1.1.0-beta.3",
4
4
  "description": "The react version of VChart 4.x",
5
5
  "keywords": [
6
6
  "react",
@@ -22,10 +22,10 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@visactor/vchart": "1.1.0-beta.1",
25
+ "@visactor/vchart": "1.1.0-beta.3",
26
26
  "@visactor/vutils": "~0.11.1",
27
- "@visactor/vgrammar": "~0.3.0",
28
- "@visactor/vrender": "~0.11.1",
27
+ "@visactor/vgrammar": "~0.3.2",
28
+ "@visactor/vrender": "~0.12.0",
29
29
  "react-is": "^18.2.0"
30
30
  },
31
31
  "devDependencies": {
@@ -53,8 +53,8 @@
53
53
  "@vitejs/plugin-react": "3.1.0",
54
54
  "vite": "3.2.6",
55
55
  "@internal/bundler": "0.0.1",
56
- "@internal/eslint-config": "0.0.1",
57
- "@internal/ts-config": "0.0.1"
56
+ "@internal/ts-config": "0.0.1",
57
+ "@internal/eslint-config": "0.0.1"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": ">=16.0.0",