@visactor/react-vchart 1.9.3 → 1.10.0-alpha.1
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/cjs/charts/BaseChart.js +28 -21
- package/cjs/charts/BaseChart.js.map +1 -1
- package/cjs/components/BaseComponent.d.ts +1 -0
- package/cjs/components/BaseComponent.js +9 -35
- package/cjs/components/BaseComponent.js.map +1 -1
- package/cjs/components/Mark.d.ts +4 -14
- package/cjs/components/Mark.js +2 -61
- package/cjs/components/Mark.js.map +1 -1
- package/cjs/context/chart.d.ts +0 -1
- package/cjs/context/chart.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/series/Area.d.ts +1 -0
- package/cjs/series/Bar.d.ts +1 -0
- package/cjs/series/BaseSeries.d.ts +1 -0
- package/cjs/series/BaseSeries.js +22 -49
- package/cjs/series/BaseSeries.js.map +1 -1
- package/cjs/series/BoxPlot.d.ts +1 -0
- package/cjs/series/CircularProgress.d.ts +1 -0
- package/cjs/series/Dot.d.ts +1 -0
- package/cjs/series/Funnel.d.ts +1 -0
- package/cjs/series/Line.d.ts +1 -0
- package/cjs/series/LinearProgress.d.ts +1 -0
- package/cjs/series/Link.d.ts +1 -0
- package/cjs/series/Map.d.ts +1 -0
- package/cjs/series/Pie.d.ts +1 -0
- package/cjs/series/Radar.d.ts +1 -0
- package/cjs/series/RangeColumn.d.ts +1 -0
- package/cjs/series/Rose.d.ts +1 -0
- package/cjs/series/Scatter.d.ts +1 -0
- package/cjs/series/Series.d.ts +1 -0
- package/cjs/series/WordCloud.d.ts +1 -0
- package/esm/charts/BaseChart.js +27 -21
- package/esm/charts/BaseChart.js.map +1 -1
- package/esm/components/BaseComponent.d.ts +1 -0
- package/esm/components/BaseComponent.js +9 -36
- package/esm/components/BaseComponent.js.map +1 -1
- package/esm/components/Mark.d.ts +4 -14
- package/esm/components/Mark.js +2 -39
- package/esm/components/Mark.js.map +1 -1
- package/esm/context/chart.d.ts +0 -1
- package/esm/context/chart.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/series/Area.d.ts +1 -0
- package/esm/series/Bar.d.ts +1 -0
- package/esm/series/BaseSeries.d.ts +1 -0
- package/esm/series/BaseSeries.js +22 -50
- package/esm/series/BaseSeries.js.map +1 -1
- package/esm/series/BoxPlot.d.ts +1 -0
- package/esm/series/CircularProgress.d.ts +1 -0
- package/esm/series/Dot.d.ts +1 -0
- package/esm/series/Funnel.d.ts +1 -0
- package/esm/series/Line.d.ts +1 -0
- package/esm/series/LinearProgress.d.ts +1 -0
- package/esm/series/Link.d.ts +1 -0
- package/esm/series/Map.d.ts +1 -0
- package/esm/series/Pie.d.ts +1 -0
- package/esm/series/Radar.d.ts +1 -0
- package/esm/series/RangeColumn.d.ts +1 -0
- package/esm/series/Rose.d.ts +1 -0
- package/esm/series/Scatter.d.ts +1 -0
- package/esm/series/Series.d.ts +1 -0
- package/esm/series/WordCloud.d.ts +1 -0
- package/package.json +6 -6
package/cjs/series/Line.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { ILineSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type LineProps = BaseSeriesProps & Omit<ILineSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Line: import("react").FC<BaseSeriesProps & Omit<ILineSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
|
@@ -3,4 +3,5 @@ import type { ILinearProgressSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type LinearProgressProps = BaseSeriesProps & Omit<ILinearProgressSeriesSpec, 'type'>;
|
|
4
4
|
export declare const LinearProgress: import("react").FC<BaseSeriesProps & Omit<ILinearProgressSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Link.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { ILinkSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type LinkProps = BaseSeriesProps & Omit<ILinkSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Link: import("react").FC<BaseSeriesProps & Omit<ILinkSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Map.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IMapSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type MapProps = BaseSeriesProps & Omit<IMapSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Map: import("react").FC<BaseSeriesProps & Omit<IMapSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Pie.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IPieSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type PieProps = BaseSeriesProps & Omit<IPieSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Pie: import("react").FC<BaseSeriesProps & Omit<IPieSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Radar.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IRadarSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type RadarProps = BaseSeriesProps & Omit<IRadarSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Radar: import("react").FC<BaseSeriesProps & Omit<IRadarSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
|
@@ -3,4 +3,5 @@ import type { IRangeColumnSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type RangeColumnProps = BaseSeriesProps & Omit<IRangeColumnSeriesSpec, 'type'>;
|
|
4
4
|
export declare const RangeColumn: import("react").FC<BaseSeriesProps & Omit<IRangeColumnSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Rose.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IRoseSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type RoseProps = BaseSeriesProps & Omit<IRoseSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Rose: import("react").FC<BaseSeriesProps & Omit<IRoseSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Scatter.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IScatterSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type ScatterProps = BaseSeriesProps & Omit<IScatterSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Scatter: import("react").FC<BaseSeriesProps & Omit<IScatterSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/cjs/series/Series.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IBarSeriesSpec, IAreaSeriesSpec, IBoxPlotSeriesSpec, ICircularProg
|
|
|
3
3
|
export type SeriesProps = (IBarSeriesSpec | IAreaSeriesSpec | IBoxPlotSeriesSpec | ICircularProgressSeriesSpec | IDotSeriesSpec | IFunnelSeriesSpec | ILineSeriesSpec | ILinearProgressSeriesSpec | ILinkSeriesSpec | IMapSeriesSpec | IPieSeriesSpec | IRadarSeriesSpec | IRangeColumnSeriesSpec | IRoseSeriesSpec | IScatterSeriesSpec | IWordCloudSeriesSpec) & BaseSeriesProps;
|
|
4
4
|
export declare const Series: import("react").FC<SeriesProps & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
|
@@ -3,4 +3,5 @@ import type { IWordCloudSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type WordCloudProps = BaseSeriesProps & Omit<IWordCloudSeriesSpec, 'type'>;
|
|
4
4
|
export declare const WordCloud: import("react").FC<BaseSeriesProps & Omit<IWordCloudSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/esm/charts/BaseChart.js
CHANGED
|
@@ -14,18 +14,23 @@ import { REACT_PRIVATE_PROPS } from "../constants";
|
|
|
14
14
|
|
|
15
15
|
import { bindEventsToChart, CHART_EVENTS_KEYS, CHART_EVENTS } from "../eventsUtils";
|
|
16
16
|
|
|
17
|
-
const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "skipFunctionDiff", "onError", "onReady", "spec", "container", "options" ],
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "vchartConstrouctor", "useSyncRender", "skipFunctionDiff", "onError", "onReady", "spec", "container", "options" ], parseSpecFromChildren = props => {
|
|
18
|
+
const specFromChildren = {};
|
|
19
|
+
return toArray(props.children).map((child => {
|
|
20
|
+
const parseSpec = child && child.type && child.type.parseSpec;
|
|
21
|
+
if (parseSpec && child.props) {
|
|
22
|
+
const specResult = parseSpec(child.props);
|
|
23
|
+
specResult.isSingle ? specFromChildren[specResult.specName] = specResult.spec : (specFromChildren[specResult.specName] || (specFromChildren[specResult.specName] = []),
|
|
24
|
+
specFromChildren[specResult.specName].push(specResult.spec));
|
|
25
|
+
}
|
|
26
|
+
})), specFromChildren;
|
|
27
|
+
}, BaseChart = React.forwardRef(((props, ref) => {
|
|
28
|
+
const [updateId, setUpdateId] = useState(0), chartContext = useRef({});
|
|
21
29
|
useImperativeHandle(ref, (() => {
|
|
22
30
|
var _a;
|
|
23
31
|
return null === (_a = chartContext.current) || void 0 === _a ? void 0 : _a.chart;
|
|
24
32
|
}));
|
|
25
|
-
const hasSpec = !!props.spec, [view, setView] = useState(null), isUnmount = useRef(!1), prevSpec = useRef(pickWithout(props, notSpecKeys)), eventsBinded = React.useRef(null), skipFunctionDiff = !!props.skipFunctionDiff, parseSpec = props => {
|
|
26
|
-
var _a;
|
|
27
|
-
return hasSpec && props.spec ? props.spec : Object.assign(Object.assign({}, prevSpec.current), null === (_a = chartContext.current) || void 0 === _a ? void 0 : _a.specFromChildren);
|
|
28
|
-
}, handleChartRender = () => {
|
|
33
|
+
const hasSpec = !!props.spec, [view, setView] = useState(null), isUnmount = useRef(!1), prevSpec = useRef(pickWithout(props, notSpecKeys)), specFromChildren = useRef(null), eventsBinded = React.useRef(null), skipFunctionDiff = !!props.skipFunctionDiff, parseSpec = props => hasSpec && props.spec ? props.spec : Object.assign(Object.assign({}, prevSpec.current), specFromChildren.current), handleChartRender = () => {
|
|
29
34
|
if (!isUnmount.current) {
|
|
30
35
|
if (!chartContext.current || !chartContext.current.chart) return;
|
|
31
36
|
bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);
|
|
@@ -36,7 +41,9 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "skipFunctio
|
|
|
36
41
|
};
|
|
37
42
|
return useEffect((() => {
|
|
38
43
|
var _a;
|
|
39
|
-
|
|
44
|
+
const newSpecFromChildren = hasSpec ? null : parseSpecFromChildren(props);
|
|
45
|
+
if (!(null === (_a = chartContext.current) || void 0 === _a ? void 0 : _a.chart)) return hasSpec || (specFromChildren.current = newSpecFromChildren),
|
|
46
|
+
(props => {
|
|
40
47
|
const cs = new props.vchartConstrouctor(parseSpec(props), Object.assign(Object.assign({}, props.options), {
|
|
41
48
|
onError: props.onError,
|
|
42
49
|
autoFit: !0,
|
|
@@ -48,9 +55,7 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "skipFunctio
|
|
|
48
55
|
})(props), chartContext.current.chart && (chartContext.current.chart.renderSync({
|
|
49
56
|
reuse: !1
|
|
50
57
|
}), handleChartRender()), bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS),
|
|
51
|
-
|
|
52
|
-
isChildrenUpdated: !1
|
|
53
|
-
}), void (eventsBinded.current = props);
|
|
58
|
+
void (eventsBinded.current = props);
|
|
54
59
|
if (hasSpec) return void (isEqual(eventsBinded.current.spec, props.spec, {
|
|
55
60
|
skipFunction: skipFunctionDiff
|
|
56
61
|
}) || (eventsBinded.current = props, chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, {
|
|
@@ -60,25 +65,26 @@ const notSpecKeys = [ ...REACT_PRIVATE_PROPS, ...CHART_EVENTS_KEYS, "skipFunctio
|
|
|
60
65
|
const newSpec = pickWithout(props, notSpecKeys);
|
|
61
66
|
isEqual(newSpec, prevSpec.current, {
|
|
62
67
|
skipFunction: skipFunctionDiff
|
|
63
|
-
}) &&
|
|
68
|
+
}) && isEqual(newSpecFromChildren, specFromChildren.current) || (prevSpec.current = newSpec,
|
|
69
|
+
specFromChildren.current = newSpecFromChildren, chartContext.current.chart.updateSpecSync(parseSpec(props), void 0, {
|
|
64
70
|
morph: !1,
|
|
65
71
|
enableExitAnimation: !1
|
|
66
|
-
}), handleChartRender())
|
|
67
|
-
isChildrenUpdated: !1
|
|
68
|
-
});
|
|
72
|
+
}), handleChartRender());
|
|
69
73
|
}), [ props ]), useEffect((() => () => {
|
|
70
|
-
chartContext &&
|
|
71
|
-
chartContext.current = null), isUnmount.current = !0;
|
|
74
|
+
chartContext && chartContext.current && chartContext.current.chart && (chartContext.current.chart.release(),
|
|
75
|
+
chartContext.current.chart = null), isUnmount.current = !0;
|
|
72
76
|
}), []), React.createElement(RootChartContext.Provider, {
|
|
73
77
|
value: chartContext.current
|
|
74
78
|
}, React.createElement(ViewContext.Provider, {
|
|
75
79
|
value: view
|
|
76
80
|
}, toArray(props.children).map(((child, index) => {
|
|
77
|
-
|
|
81
|
+
if ("string" == typeof child) return;
|
|
82
|
+
const childId = `${child && child.type && (child.type.displayName || child.type.name)}-${index}`;
|
|
78
83
|
return React.createElement(React.Fragment, {
|
|
79
|
-
key:
|
|
84
|
+
key: childId
|
|
80
85
|
}, React.cloneElement(child, {
|
|
81
|
-
updateId: updateId
|
|
86
|
+
updateId: updateId,
|
|
87
|
+
componentId: childId
|
|
82
88
|
}));
|
|
83
89
|
}))));
|
|
84
90
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/charts/BaseChart.tsx"],"names":[],"mappings":"AACA,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,EACL,iBAAiB,EAEjB,iBAAiB,EACjB,YAAY,EASb,MAAM,gBAAgB,CAAC;AA+CxB,MAAM,WAAW,GAAG;IAClB,GAAG,mBAAmB;IACtB,GAAG,iBAAiB;IACpB,kBAAkB;IAClB,SAAS;IACT,SAAS;IACT,MAAM;IACN,WAAW;IACX,SAAS;CACV,CAAC;AAEF,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,MAAM,CAAmB;QAC5C,gBAAgB,EAAE,EAAE;KACrB,CAAC,CAAC;IACH,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAC,OAA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E,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,CAAC,OAAO;QACpD,oBAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,IAC9B,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;;YAC5C,OAAO,CACL,oBAAC,KAAK,CAAC,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,CACzB,aAAqB,EACrB,YAAyB,EACzB,QAAqD,EACrD,EAAE;IACF,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SACtC;QAED,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 { IVChart, IData, IInitOption, ISpec, IVChartConstructor } 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-core';\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 {\n bindEventsToChart,\n EventsProps,\n CHART_EVENTS_KEYS,\n CHART_EVENTS,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\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 vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\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 'skipFunctionDiff',\n 'onError',\n 'onReady',\n 'spec',\n 'container',\n 'options'\n];\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 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 eventsBinded = React.useRef<BaseChartProps>(null);\n const skipFunctionDiff = !!props.skipFunctionDiff;\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 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 };\n\n const handleChartRender = () => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\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 chartContext.current.chart.renderSync({\n reuse: false\n });\n 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, { skipFunction: skipFunctionDiff })) {\n eventsBinded.current = props;\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {\n morph: false,\n enableExitAnimation: false\n });\n handleChartRender();\n }\n return;\n }\n\n const newSpec = pickWithout(props, notSpecKeys);\n\n if (\n !isEqual(newSpec, prevSpec.current, { skipFunction: skipFunctionDiff }) ||\n chartContext.current.isChildrenUpdated\n ) {\n prevSpec.current = newSpec;\n\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {\n morph: false,\n enableExitAnimation: false\n });\n 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>(\n componentName: string,\n defaultProps?: Partial<T>,\n callback?: (props: T, defaultProps?: Partial<T>) => T\n) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (callback) {\n return callback(props, defaultProps);\n }\n\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":"AACA,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;AAC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,KAAQ,EAAE,EAAE;QACzF,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SACtC;QAED,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 { IVChart, IData, IInitOption, ISpec, IVChartConstructor } 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-core';\nimport { isEqual, pickWithout } from '@visactor/vutils';\nimport ViewContext from '../context/view';\nimport { toArray } from '../util';\nimport { REACT_PRIVATE_PROPS } from '../constants';\nimport {\n bindEventsToChart,\n EventsProps,\n CHART_EVENTS_KEYS,\n CHART_EVENTS,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps,\n DimensionEventProps,\n HierarchyEventProps,\n ChartLifeCycleEventProps\n} from '../eventsUtils';\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 vchartConstrouctor?: IVChartConstructor;\n type?: string;\n /** 上层container */\n container?: HTMLDivElement;\n /**\n * used only by <VChart />\n */\n spec?: ISpec;\n /** 数据 */\n data?: IData;\n /** 画布宽度 */\n width?: number;\n /** 画布高度 */\n height?: number;\n /** 图表配置 */\n options?: ChartOptions;\n /** skip function diff when component update */\n skipFunctionDiff?: boolean;\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];\n\nconst parseSpecFromChildren = (props: Props) => {\n const specFromChildren: Omit<ISpec, 'type' | 'data' | 'width' | 'height'> = {};\n\n toArray(props.children).map(child => {\n const parseSpec = child && (child as any).type && (child as any).type.parseSpec;\n\n if (parseSpec && (child as any).props) {\n const specResult = parseSpec((child as any).props);\n\n if (specResult.isSingle) {\n specFromChildren[specResult.specName] = specResult.spec;\n } else {\n if (!specFromChildren[specResult.specName]) {\n specFromChildren[specResult.specName] = [];\n }\n\n specFromChildren[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\n const parseSpec = (props: Props) => {\n if (hasSpec && props.spec) {\n return props.spec;\n }\n\n return {\n ...prevSpec.current,\n ...specFromChildren.current\n } as ISpec;\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 };\n\n const handleChartRender = () => {\n // rebind events after render\n if (!isUnmount.current) {\n if (!chartContext.current || !chartContext.current.chart) {\n return;\n }\n\n bindEventsToChart(chartContext.current.chart, props, eventsBinded.current, CHART_EVENTS);\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 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 bindEventsToChart(chartContext.current.chart, props, null, CHART_EVENTS);\n eventsBinded.current = props;\n return;\n }\n\n if (hasSpec) {\n if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) {\n eventsBinded.current = props;\n chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, {\n morph: false,\n enableExitAnimation: false\n });\n handleChartRender();\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, {\n morph: false,\n enableExitAnimation: false\n });\n handleChartRender();\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 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;\n }\n\n const componentName =\n child && (child as any).type && ((child as any).type.displayName || (child as any).type.name);\n const childId = `${componentName}-${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 </ViewContext.Provider>\n </RootChartContext.Provider>\n );\n});\n\nexport const createChart = <T extends Props>(\n componentName: string,\n defaultProps?: Partial<T>,\n callback?: (props: T, defaultProps?: Partial<T>) => T\n) => {\n const Com = withContainer<ContainerProps, T>(BaseChart as any, componentName, (props: T) => {\n if (callback) {\n return callback(props, defaultProps);\n }\n\n if (defaultProps) {\n return Object.assign(props, defaultProps);\n }\n return props;\n });\n Com.displayName = componentName;\n return Com;\n};\n"]}
|
|
@@ -4,6 +4,7 @@ export interface BaseComponentProps {
|
|
|
4
4
|
}
|
|
5
5
|
type ComponentProps = BaseComponentProps & {
|
|
6
6
|
updateId?: number;
|
|
7
|
+
componentId?: number;
|
|
7
8
|
};
|
|
8
9
|
export declare const createComponent: <T extends ComponentProps>(componentName: string, specName: string, supportedEvents?: Record<string, string> | null, isSingle?: boolean) => React.FC<T>;
|
|
9
10
|
export {};
|
|
@@ -1,53 +1,26 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { pickWithout } from "@visactor/vutils";
|
|
4
4
|
|
|
5
5
|
import RootChartContext from "../context/chart";
|
|
6
6
|
|
|
7
7
|
import { bindEventsToChart } from "../eventsUtils";
|
|
8
8
|
|
|
9
|
-
import { uid } from "../util";
|
|
10
|
-
|
|
11
9
|
export const createComponent = (componentName, specName, supportedEvents, isSingle) => {
|
|
12
|
-
const ignoreKeys = [ "id", "updateId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
13
|
-
const context = useContext(RootChartContext),
|
|
10
|
+
const ignoreKeys = [ "id", "updateId", "componentId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
11
|
+
const context = useContext(RootChartContext), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId);
|
|
14
12
|
if (props.updateId !== updateId.current) {
|
|
15
13
|
updateId.current = props.updateId;
|
|
16
14
|
!!supportedEvents && bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
|
|
17
|
-
} else {
|
|
18
|
-
const newComponentSpec = pickWithout(props, notSpecKeys);
|
|
19
|
-
isEqual(newComponentSpec, componentSpec.current) || (componentSpec.current = newComponentSpec,
|
|
20
|
-
updateToContext(context, id.current, specName, isSingle, newComponentSpec));
|
|
21
15
|
}
|
|
22
16
|
return useEffect((() => () => {
|
|
23
|
-
supportedEvents && bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents)
|
|
24
|
-
deleteToContext(context, id.current, specName, isSingle);
|
|
17
|
+
supportedEvents && bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents);
|
|
25
18
|
}), []), null;
|
|
26
19
|
};
|
|
27
|
-
return Comp.displayName = componentName, Comp
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (isSingle) context.specFromChildren[specName] = Object.assign({}, props); else {
|
|
33
|
-
context.specFromChildren[specName] || (context.specFromChildren[specName] = []);
|
|
34
|
-
const comps = context.specFromChildren[specName], index = comps.findIndex((entry => entry.id === id));
|
|
35
|
-
index >= 0 ? comps[index] = Object.assign({
|
|
36
|
-
id: id
|
|
37
|
-
}, props) : context.specFromChildren[specName].push(Object.assign({
|
|
38
|
-
id: id
|
|
39
|
-
}, props));
|
|
40
|
-
}
|
|
41
|
-
context.isChildrenUpdated = !0;
|
|
42
|
-
}
|
|
43
|
-
}, deleteToContext = (context, id, specName, isSingle) => {
|
|
44
|
-
var _a;
|
|
45
|
-
if (context.specFromChildren) if (isSingle) context.specFromChildren[specName] = null; else {
|
|
46
|
-
const comps = null !== (_a = context.specFromChildren[specName]) && void 0 !== _a ? _a : [], index = comps.findIndex((entry => entry.id === id));
|
|
47
|
-
if (index >= 0) {
|
|
48
|
-
const newComps = comps.slice(0, index - 1).concat(comps.slice(index + 1));
|
|
49
|
-
context.specFromChildren[specName] = newComps, context.isChildrenUpdated = !0;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
20
|
+
return Comp.displayName = componentName, Comp.parseSpec = props => ({
|
|
21
|
+
spec: pickWithout(props, notSpecKeys),
|
|
22
|
+
specName: specName,
|
|
23
|
+
isSingle: isSingle
|
|
24
|
+
}), Comp;
|
|
52
25
|
};
|
|
53
26
|
//# sourceMappingURL=BaseComponent.js.map
|
|
@@ -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,
|
|
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;AAQnD,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,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,UAAU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AAC,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';\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) => {\n const ignoreKeys = ['id', '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/components/Mark.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
glyphType?: string;
|
|
6
|
-
}
|
|
7
|
-
export interface IMarkElement extends React.ReactElement<Props, React.JSXElementConstructor<Props>> {
|
|
8
|
-
id: string | number;
|
|
9
|
-
}
|
|
10
|
-
type Props = MarkProps & {
|
|
11
|
-
updateId?: number;
|
|
12
|
-
};
|
|
13
|
-
export declare const Mark: React.FC<Props>;
|
|
14
|
-
export {};
|
|
1
|
+
import type { ICustomMarkSpec, EnableMarkType } from '@visactor/vchart';
|
|
2
|
+
import { BaseComponentProps } from './BaseComponent';
|
|
3
|
+
export type MarkProps = ICustomMarkSpec<EnableMarkType> & BaseComponentProps;
|
|
4
|
+
export declare const Mark: import("react").FC<MarkProps>;
|
package/esm/components/Mark.js
CHANGED
|
@@ -1,41 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
|
|
4
|
-
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
|
|
5
|
-
var i = 0;
|
|
6
|
-
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
1
|
+
import { createComponent } from "./BaseComponent";
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { isNil } from "@visactor/vutils";
|
|
14
|
-
|
|
15
|
-
import ViewContext from "../context/view";
|
|
16
|
-
|
|
17
|
-
import { uid } from "../util";
|
|
18
|
-
|
|
19
|
-
export const Mark = props => {
|
|
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((() => () => {
|
|
23
|
-
context && removeMark(context, id.current);
|
|
24
|
-
}), []), null;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const addOrUpdateMark = (view, id, props) => {
|
|
28
|
-
var _a;
|
|
29
|
-
if (!view.renderer) return;
|
|
30
|
-
let mark = view.getMarkById(id);
|
|
31
|
-
const {group: group, glyphType: glyphType, updateId: updateId} = props, others = __rest(props, [ "group", "glyphType", "updateId" ]);
|
|
32
|
-
mark || (mark = view.mark(props.type, null !== (_a = props.group) && void 0 !== _a ? _a : view.rootMark, props.glyphType ? {
|
|
33
|
-
glyphType: props.glyphType
|
|
34
|
-
} : null).name(id)), mark.parse(others), view.run();
|
|
35
|
-
}, removeMark = (view, id) => {
|
|
36
|
-
if (view.renderer) {
|
|
37
|
-
view.getMarkById(id);
|
|
38
|
-
view.removeGrammar(id);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
3
|
+
export const Mark = createComponent("Mark", "customMark");
|
|
41
4
|
//# sourceMappingURL=Mark.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mark.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/components/Mark.tsx"],"names":[],"mappings":"AACA,OAAO,EAAsB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAItE,MAAM,CAAC,MAAM,IAAI,GAAG,eAAe,CAAY,MAAM,EAAE,YAAY,CAAC,CAAC","file":"Mark.js","sourcesContent":["import type { ICustomMarkSpec, EnableMarkType } from '@visactor/vchart';\nimport { BaseComponentProps, createComponent } from './BaseComponent';\n\nexport type MarkProps = ICustomMarkSpec<EnableMarkType> & BaseComponentProps;\n\nexport const Mark = createComponent<MarkProps>('Mark', 'customMark');\n"]}
|
package/esm/context/chart.d.ts
CHANGED
package/esm/context/chart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context/chart.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"sources":["../src/context/chart.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAQ1B,MAAM,YAAY,GAAG,KAAK,CAAC,aAAa,CAAmB,IAAI,CAAC,CAAC;AACjE,YAAY,CAAC,WAAW,GAAG,cAAc,CAAC;AAE1C,MAAM,UAAU,iBAAiB,CAAI,SAAiC;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAS,CAAC,KAAQ,EAAE,GAAG,EAAE,EAAE;QACrD,OAAO,CACL,oBAAC,YAAY,CAAC,QAAQ,QACnB,CAAC,GAAqB,EAAE,EAAE,CAAC,oBAAC,SAAS,kBAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,IAAM,KAAK,EAAI,CAC1D,CACzB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,eAAe,YAAY,CAAC","file":"chart.js","sourcesContent":["import React from 'react';\nimport type { IVChart } from '@visactor/vchart';\n\nexport interface ChartContextType {\n chart?: IVChart;\n isChildrenUpdated?: boolean;\n}\n\nconst ChartContext = React.createContext<ChartContextType>(null);\nChartContext.displayName = 'ChartContext';\n\nexport function withChartInstance<T>(Component: typeof React.Component) {\n const Com = React.forwardRef<any, T>((props: T, ref) => {\n return (\n <ChartContext.Consumer>\n {(ctx: ChartContextType) => <Component ref={ref} chart={ctx.chart} {...props} />}\n </ChartContext.Consumer>\n );\n });\n Com.displayName = Component.name;\n return Com;\n}\n\nexport default ChartContext;\n"]}
|
package/esm/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export * from './series';
|
|
|
3
3
|
export * from './components';
|
|
4
4
|
export * from './VChart';
|
|
5
5
|
export * from './VChartSimple';
|
|
6
|
-
export declare const version = "1.
|
|
6
|
+
export declare const version = "1.10.0-alpha.1";
|
|
7
7
|
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;AAG/B,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
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;AAG/B,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';\n\n// export the version, since @1.8.3\nexport const version = \"1.10.0-alpha.1\";\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/series/Area.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IAreaSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type AreaProps = BaseSeriesProps & Omit<IAreaSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Area: import("react").FC<BaseSeriesProps & Omit<IAreaSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/esm/series/Bar.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ import type { IBarSeriesSpec } from '@visactor/vchart';
|
|
|
3
3
|
export type BarProps = BaseSeriesProps & Omit<IBarSeriesSpec, 'type'>;
|
|
4
4
|
export declare const Bar: import("react").FC<BaseSeriesProps & Omit<IBarSeriesSpec, "type"> & {
|
|
5
5
|
updateId?: number;
|
|
6
|
+
componentId?: string;
|
|
6
7
|
}>;
|
package/esm/series/BaseSeries.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import { isNil,
|
|
3
|
+
import { isNil, pickWithout } from "@visactor/vutils";
|
|
4
4
|
|
|
5
5
|
import RootChartContext from "../context/chart";
|
|
6
6
|
|
|
7
7
|
import { REACT_TO_VCHART_EVENTS, findEventProps, COMMON_EVENTK_KEYS, VCHART_TO_REACT_EVENTS } from "../eventsUtils";
|
|
8
8
|
|
|
9
|
-
import { uid } from "../util";
|
|
10
|
-
|
|
11
9
|
export const createSeries = (componentName, markNames, type) => {
|
|
12
|
-
const notSpecKeys = COMMON_EVENTK_KEYS.concat([ "id", "updateId" ]), Comp = props => {
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const notSpecKeys = COMMON_EVENTK_KEYS.concat([ "id", "updateId", "componentId" ]), Comp = props => {
|
|
11
|
+
var _a;
|
|
12
|
+
const context = React.useContext(RootChartContext), id = null !== (_a = props.id) && void 0 !== _a ? _a : props.componentId, bindedEvents = React.useRef({}), handleEvent = e => {
|
|
13
|
+
const markIds = markNames.map((markName => `${id}-${markName}`));
|
|
15
14
|
(null == e ? void 0 : e.mark) && markIds.includes(e.mark.getUserId()) && props[VCHART_TO_REACT_EVENTS[e.event.type]](e);
|
|
16
15
|
}, addMarkEvent = events => {
|
|
17
16
|
events && context.chart && (bindedEvents && Object.keys(bindedEvents).forEach((eventKey => {
|
|
@@ -21,52 +20,25 @@ export const createSeries = (componentName, markNames, type) => {
|
|
|
21
20
|
(null == bindedEvents ? void 0 : bindedEvents[eventKey]) || (context.chart.on(REACT_TO_VCHART_EVENTS[eventKey], handleEvent),
|
|
22
21
|
bindedEvents || (bindedEvents.current = {}), bindedEvents.current[eventKey] = !0);
|
|
23
22
|
})));
|
|
24
|
-
}, addMarkId = spec => {
|
|
25
|
-
markNames.forEach((markName => {
|
|
26
|
-
const defaultMarkId = `${id.current}-${markName}`;
|
|
27
|
-
isNil(spec[markName]) ? spec[markName] = {
|
|
28
|
-
id: defaultMarkId
|
|
29
|
-
} : isNil(spec[markName].id) && (spec[markName].id = defaultMarkId);
|
|
30
|
-
}));
|
|
31
|
-
}, insertToContext = props => {
|
|
32
|
-
if (context.specFromChildren) {
|
|
33
|
-
context.specFromChildren.series || (context.specFromChildren.series = []);
|
|
34
|
-
const spec = isNil(type) ? Object.assign(Object.assign({}, props), {
|
|
35
|
-
id: id.current
|
|
36
|
-
}) : Object.assign(Object.assign({}, props), {
|
|
37
|
-
id: id.current,
|
|
38
|
-
type: type
|
|
39
|
-
});
|
|
40
|
-
addMarkId(spec), context.specFromChildren.series.push(spec), context.isChildrenUpdated = !0;
|
|
41
|
-
}
|
|
42
23
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
addMarkId(newSeriesSpec), isEqual(newSeriesSpec, seriesSpec.current) || (seriesSpec.current = newSeriesSpec,
|
|
46
|
-
(props => {
|
|
47
|
-
if (!context.specFromChildren) return;
|
|
48
|
-
if (!context.specFromChildren.series) return void insertToContext(props);
|
|
49
|
-
const series = context.specFromChildren.series, index = series.findIndex((entry => entry.id === id.current));
|
|
50
|
-
index >= 0 ? (series[index] = isNil(type) ? Object.assign(Object.assign({}, props), {
|
|
51
|
-
id: id.current
|
|
52
|
-
}) : Object.assign(Object.assign({}, props), {
|
|
53
|
-
id: id.current,
|
|
54
|
-
type: type
|
|
55
|
-
}), addMarkId(series[index])) : insertToContext(props), context.isChildrenUpdated = !0;
|
|
56
|
-
})(newSeriesSpec));
|
|
57
|
-
}
|
|
58
|
-
return React.useEffect((() => () => {
|
|
59
|
-
(() => {
|
|
60
|
-
var _a;
|
|
61
|
-
if (!context.specFromChildren) return;
|
|
62
|
-
const series = null !== (_a = context.specFromChildren.series) && void 0 !== _a ? _a : [], index = series.findIndex((entry => entry.id === id.current));
|
|
63
|
-
if (index >= 0) {
|
|
64
|
-
const newSeries = series.slice(0, index - 1).concat(series.slice(index + 1));
|
|
65
|
-
context.specFromChildren.series = newSeries, context.isChildrenUpdated = !0;
|
|
66
|
-
}
|
|
67
|
-
})(), addMarkEvent({});
|
|
24
|
+
return addMarkEvent(findEventProps(props)), React.useEffect((() => () => {
|
|
25
|
+
addMarkEvent({}), bindedEvents.current = {};
|
|
68
26
|
}), []), null;
|
|
69
27
|
};
|
|
70
|
-
return Comp.displayName = componentName, Comp
|
|
28
|
+
return Comp.displayName = componentName, Comp.parseSpec = compProps => {
|
|
29
|
+
var _a;
|
|
30
|
+
const newSeriesSpec = pickWithout(compProps, notSpecKeys);
|
|
31
|
+
var spec, seriesId;
|
|
32
|
+
return spec = newSeriesSpec, seriesId = null !== (_a = compProps.id) && void 0 !== _a ? _a : compProps.componentId,
|
|
33
|
+
markNames.forEach((markName => {
|
|
34
|
+
const defaultMarkId = `${seriesId}-${markName}`;
|
|
35
|
+
isNil(spec[markName]) ? spec[markName] = {
|
|
36
|
+
id: defaultMarkId
|
|
37
|
+
} : isNil(spec[markName].id) && (spec[markName].id = defaultMarkId);
|
|
38
|
+
})), isNil(type) || (newSeriesSpec.type = type), {
|
|
39
|
+
spec: newSeriesSpec,
|
|
40
|
+
specName: "series"
|
|
41
|
+
};
|
|
42
|
+
}, Comp;
|
|
71
43
|
};
|
|
72
44
|
//# sourceMappingURL=BaseSeries.js.map
|