@visactor/react-vchart 1.2.0-beta.4 → 1.2.0-beta.6
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/components/BaseComponent.js +6 -3
- package/cjs/components/BaseComponent.js.map +1 -1
- package/cjs/series/BaseSeries.js +6 -6
- package/cjs/series/BaseSeries.js.map +1 -1
- package/esm/components/BaseComponent.js +7 -3
- package/esm/components/BaseComponent.js.map +1 -1
- package/esm/series/BaseSeries.js +6 -6
- package/esm/series/BaseSeries.js.map +1 -1
- package/package.json +2 -2
|
@@ -36,12 +36,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
36
36
|
const react_1 = __importStar(require("react")), vutils_1 = require("@visactor/vutils"), chart_1 = __importDefault(require("../context/chart")), eventsUtils_1 = require("../eventsUtils"), util_1 = require("../util"), createComponent = (componentName, specName, supportedEvents, isSingle) => {
|
|
37
37
|
const ignoreKeys = [ "id", "updateId" ], notSpecKeys = supportedEvents ? Object.keys(supportedEvents).concat(ignoreKeys) : ignoreKeys, Comp = props => {
|
|
38
38
|
const context = (0, react_1.useContext)(chart_1.default), id = react_1.default.useRef((0,
|
|
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 = (
|
|
40
|
-
vutils_1.pickWithout)(props, notSpecKeys);
|
|
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 = react_1.default.useRef();
|
|
41
40
|
if (props.updateId !== updateId.current) {
|
|
42
41
|
updateId.current = props.updateId;
|
|
43
42
|
!!supportedEvents && (0, eventsUtils_1.bindEventsToChart)(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
|
|
44
|
-
} else
|
|
43
|
+
} else {
|
|
44
|
+
const newComponentSpec = (0, vutils_1.pickWithout)(props, notSpecKeys);
|
|
45
|
+
(0, vutils_1.isEqual)(newComponentSpec, componentSpec.current) || (componentSpec.current = newComponentSpec,
|
|
46
|
+
updateToContext(context, id.current, specName, isSingle, newComponentSpec));
|
|
47
|
+
}
|
|
45
48
|
return (0, react_1.useEffect)((() => () => {
|
|
46
49
|
supportedEvents && (0, eventsUtils_1.bindEventsToChart)(context.chart, null, eventsBinded.current, supportedEvents),
|
|
47
50
|
deleteToContext(context, id.current, specName, isSingle);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,
|
|
1
|
+
{"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAA+D;AAE/D,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,MAA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C;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 { isEqual, 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 const componentSpec = React.useRef<Partial<T>>();\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 const newComponentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\n if (!isEqual(newComponentSpec, componentSpec.current)) {\n componentSpec.current = newComponentSpec;\n updateToContext(context, id.current, specName, isSingle, newComponentSpec);\n }\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"]}
|
package/cjs/series/BaseSeries.js
CHANGED
|
@@ -24,28 +24,28 @@ const react_1 = __importDefault(require("react")), vutils_1 = require("@visactor
|
|
|
24
24
|
(null == bindedEvents ? void 0 : bindedEvents[eventKey]) || (context.chart.on(eventsUtils_1.REACT_TO_VCHART_EVENTS[eventKey], handleEvent),
|
|
25
25
|
bindedEvents || (bindedEvents.current = {}), bindedEvents.current[eventKey] = !0);
|
|
26
26
|
})));
|
|
27
|
-
}, addMarkId =
|
|
27
|
+
}, addMarkId = spec => {
|
|
28
28
|
markNames.forEach((markName => {
|
|
29
29
|
const defaultMarkId = `${id.current}-${markName}`;
|
|
30
|
-
(0, vutils_1.isNil)(
|
|
30
|
+
(0, vutils_1.isNil)(spec[markName]) ? spec[markName] = {
|
|
31
31
|
id: defaultMarkId
|
|
32
|
-
} : (0, vutils_1.isNil)(
|
|
32
|
+
} : (0, vutils_1.isNil)(spec[markName].id) && (spec[markName].id = defaultMarkId);
|
|
33
33
|
}));
|
|
34
34
|
}, insertToContext = props => {
|
|
35
35
|
if (context.specFromChildren) {
|
|
36
36
|
context.specFromChildren.series || (context.specFromChildren.series = []);
|
|
37
|
-
const
|
|
37
|
+
const spec = (0, vutils_1.isNil)(type) ? Object.assign(Object.assign({}, props), {
|
|
38
38
|
id: id.current
|
|
39
39
|
}) : Object.assign(Object.assign({}, props), {
|
|
40
40
|
id: id.current,
|
|
41
41
|
type: type
|
|
42
42
|
});
|
|
43
|
-
addMarkId(
|
|
43
|
+
addMarkId(spec), context.specFromChildren.series.push(spec), context.isChildrenUpdated = !0;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
if (addMarkEvent((0, eventsUtils_1.findEventProps)(props)), props.updateId !== updateId.current) updateId.current = props.updateId; else {
|
|
47
47
|
const newSeriesSpec = (0, vutils_1.pickWithout)(props, notSpecKeys);
|
|
48
|
-
(0, vutils_1.isEqual)(newSeriesSpec, seriesSpec.current) || (seriesSpec.current = newSeriesSpec,
|
|
48
|
+
addMarkId(newSeriesSpec), (0, vutils_1.isEqual)(newSeriesSpec, seriesSpec.current) || (seriesSpec.current = newSeriesSpec,
|
|
49
49
|
(props => {
|
|
50
50
|
if (!context.specFromChildren) return;
|
|
51
51
|
if (!context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C;QAEF,YAAY,CAAC,IAAA,4BAAc,EAAC,KAAK,CAAC,CAAC,CAAC;QACpC,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,EAAE;YAEvC,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;SACnC;aAAM;YACL,MAAM,aAAa,GAAG,IAAA,oBAAW,EAAI,KAAK,EAAE,WAAW,CAAC,CAAC;YAEzD,SAAS,CAAC,aAAa,CAAC,CAAC;YACzB,IAAI,CAAC,IAAA,gBAAO,EAAC,aAAa,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE;gBAC/C,UAAU,CAAC,OAAO,GAAG,aAAa,CAAC;gBACnC,eAAe,CAAC,aAAa,CAAC,CAAC;aAChC;SACF;QAED,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;YACnB,OAAO,GAAG,EAAE;gBACV,eAAe,EAAE,CAAC;gBAClB,eAAe,EAAE,CAAC;YACpB,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;IACjC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA1IW,QAAA,YAAY,gBA0IvB","file":"BaseSeries.js","sourcesContent":["import React from 'react';\nimport { isNil, isEqual, pickWithout } from '@visactor/vutils';\nimport RootChartContext from '../context/chart';\nimport {\n REACT_TO_VCHART_EVENTS,\n EventsProps,\n findEventProps,\n COMMON_EVENTK_KEYS,\n VCHART_TO_REACT_EVENTS\n} from '../eventsUtils';\nimport { uid } from '../util';\n\nexport interface BaseSeriesProps extends EventsProps {\n id?: string | number;\n}\n\nexport const createSeries = <T extends BaseSeriesProps>(componentName: string, markNames: string[], type?: string) => {\n const ignoreKeys = ['id', 'updateId'];\n const notSpecKeys = COMMON_EVENTK_KEYS.concat(ignoreKeys);\n\n const Comp: React.FC<T & { updateId?: number }> = props => {\n const context = React.useContext(RootChartContext);\n\n const id = React.useRef<string | number>(isNil(props.id) ? uid(type ?? 'series') : props.id);\n\n const seriesSpec = React.useRef<Partial<T>>();\n const bindedEvents = React.useRef<Record<string, boolean>>({});\n const updateId = React.useRef<number>(props.updateId);\n\n const handleEvent = (e: any) => {\n const markIds = markNames.map(markName => `${id.current}-${markName}`);\n if (e?.mark && markIds.includes(e.mark.getUserId())) {\n props[VCHART_TO_REACT_EVENTS[e.event.type]](e);\n }\n };\n\n const addMarkEvent = (events: EventsProps) => {\n if (!events || !context.chart) {\n return;\n }\n\n if (bindedEvents) {\n Object.keys(bindedEvents).forEach(eventKey => {\n if (!events[eventKey]) {\n context.chart.off(REACT_TO_VCHART_EVENTS[eventKey], handleEvent);\n }\n bindedEvents.current[eventKey] = false;\n });\n }\n\n Object.keys(events).forEach(eventKey => {\n if (!bindedEvents?.[eventKey]) {\n context.chart.on(REACT_TO_VCHART_EVENTS[eventKey], handleEvent);\n\n if (!bindedEvents) {\n bindedEvents.current = {};\n }\n bindedEvents.current[eventKey] = true;\n }\n });\n };\n\n const removeMarkEvent = () => {\n addMarkEvent({});\n };\n\n const addMarkId = (spec: any) => {\n markNames.forEach(markName => {\n const defaultMarkId = `${id.current}-${markName}`;\n\n if (isNil(spec[markName])) {\n spec[markName] = { id: defaultMarkId };\n } else if (isNil(spec[markName].id)) {\n spec[markName].id = defaultMarkId;\n }\n });\n };\n\n const insertToContext = (props: Partial<T>) => {\n if (context.specFromChildren) {\n if (!context.specFromChildren.series) {\n context.specFromChildren.series = [];\n }\n\n const spec = isNil(type) ? { ...props, id: id.current } : { ...props, id: id.current, type };\n\n addMarkId(spec);\n context.specFromChildren.series.push(spec);\n context.isChildrenUpdated = true;\n }\n };\n\n const updateToContext = (props: Partial<T>) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (!context.specFromChildren.series) {\n insertToContext(props);\n return;\n }\n\n const series = context.specFromChildren.series;\n const index = series.findIndex((entry: any) => entry.id === id.current);\n\n if (index >= 0) {\n series[index] = isNil(type) ? { ...props, id: id.current } : { ...props, id: id.current, type };\n addMarkId(series[index]);\n } else {\n insertToContext(props);\n }\n context.isChildrenUpdated = true;\n };\n\n const deleteToContext = () => {\n if (!context.specFromChildren) {\n return;\n }\n const series = context.specFromChildren.series ?? [];\n const index = series.findIndex((entry: any) => entry.id === id.current);\n\n if (index >= 0) {\n const newSeries = series.slice(0, index - 1).concat(series.slice(index + 1));\n context.specFromChildren.series = newSeries;\n context.isChildrenUpdated = true;\n }\n };\n\n addMarkEvent(findEventProps(props));\n if (props.updateId !== updateId.current) {\n // chart render\n updateId.current = props.updateId;\n } else {\n const newSeriesSpec = pickWithout<T>(props, notSpecKeys);\n\n addMarkId(newSeriesSpec);\n if (!isEqual(newSeriesSpec, seriesSpec.current)) {\n seriesSpec.current = newSeriesSpec;\n updateToContext(newSeriesSpec);\n }\n }\n\n React.useEffect(() => {\n return () => {\n deleteToContext();\n removeMarkEvent();\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useContext, useEffect } from "react";
|
|
2
2
|
|
|
3
|
-
import { isNil, pickWithout } from "@visactor/vutils";
|
|
3
|
+
import { isEqual, isNil, pickWithout } from "@visactor/vutils";
|
|
4
4
|
|
|
5
5
|
import RootChartContext from "../context/chart";
|
|
6
6
|
|
|
@@ -10,11 +10,15 @@ import { uid } from "../util";
|
|
|
10
10
|
|
|
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
|
-
const context = useContext(RootChartContext), id = React.useRef(isNil(props.id) ? uid(specName) : props.id), eventsBinded = React.useRef(null), updateId = React.useRef(props.updateId), componentSpec =
|
|
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 = React.useRef();
|
|
14
14
|
if (props.updateId !== updateId.current) {
|
|
15
15
|
updateId.current = props.updateId;
|
|
16
16
|
!!supportedEvents && bindEventsToChart(context.chart, props, eventsBinded.current, supportedEvents) && (eventsBinded.current = props);
|
|
17
|
-
} else
|
|
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
|
+
}
|
|
18
22
|
return useEffect((() => () => {
|
|
19
23
|
supportedEvents && bindEventsToChart(context.chart, null, eventsBinded.current, supportedEvents),
|
|
20
24
|
deleteToContext(context, id.current, specName, isSingle);
|
|
@@ -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;
|
|
1
|
+
{"version":3,"sources":["components/BaseComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/D,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,UA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ACT,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,CAAC,OAAyB,EAAE,EAAmB,EAAE,QAAgB,EAAE,QAAiB,EAAE,EAAE;;IAC9G,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 { isEqual, 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 const componentSpec = React.useRef<Partial<T>>();\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 const newComponentSpec: Partial<T> = pickWithout<T>(props, notSpecKeys);\n\n if (!isEqual(newComponentSpec, componentSpec.current)) {\n componentSpec.current = newComponentSpec;\n updateToContext(context, id.current, specName, isSingle, newComponentSpec);\n }\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"]}
|
package/esm/series/BaseSeries.js
CHANGED
|
@@ -21,28 +21,28 @@ export const createSeries = (componentName, markNames, type) => {
|
|
|
21
21
|
(null == bindedEvents ? void 0 : bindedEvents[eventKey]) || (context.chart.on(REACT_TO_VCHART_EVENTS[eventKey], handleEvent),
|
|
22
22
|
bindedEvents || (bindedEvents.current = {}), bindedEvents.current[eventKey] = !0);
|
|
23
23
|
})));
|
|
24
|
-
}, addMarkId =
|
|
24
|
+
}, addMarkId = spec => {
|
|
25
25
|
markNames.forEach((markName => {
|
|
26
26
|
const defaultMarkId = `${id.current}-${markName}`;
|
|
27
|
-
isNil(
|
|
27
|
+
isNil(spec[markName]) ? spec[markName] = {
|
|
28
28
|
id: defaultMarkId
|
|
29
|
-
} : isNil(
|
|
29
|
+
} : isNil(spec[markName].id) && (spec[markName].id = defaultMarkId);
|
|
30
30
|
}));
|
|
31
31
|
}, insertToContext = props => {
|
|
32
32
|
if (context.specFromChildren) {
|
|
33
33
|
context.specFromChildren.series || (context.specFromChildren.series = []);
|
|
34
|
-
const
|
|
34
|
+
const spec = isNil(type) ? Object.assign(Object.assign({}, props), {
|
|
35
35
|
id: id.current
|
|
36
36
|
}) : Object.assign(Object.assign({}, props), {
|
|
37
37
|
id: id.current,
|
|
38
38
|
type: type
|
|
39
39
|
});
|
|
40
|
-
addMarkId(
|
|
40
|
+
addMarkId(spec), context.specFromChildren.series.push(spec), context.isChildrenUpdated = !0;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
if (addMarkEvent(findEventProps(props)), props.updateId !== updateId.current) updateId.current = props.updateId; else {
|
|
44
44
|
const newSeriesSpec = pickWithout(props, notSpecKeys);
|
|
45
|
-
isEqual(newSeriesSpec, seriesSpec.current) || (seriesSpec.current = newSeriesSpec,
|
|
45
|
+
addMarkId(newSeriesSpec), isEqual(newSeriesSpec, seriesSpec.current) || (seriesSpec.current = newSeriesSpec,
|
|
46
46
|
(props => {
|
|
47
47
|
if (!context.specFromChildren) return;
|
|
48
48
|
if (!context.specFromChildren.series) return void insertToContext(props);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["series/BaseSeries.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,sBAAsB,EAEtB,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAM9B,MAAM,CAAC,MAAM,YAAY,GAAG,CAA4B,aAAqB,EAAE,SAAmB,EAAE,IAAa,EAAE,EAAE;IACnH,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAE1D,MAAM,IAAI,GAAwC,KAAK,CAAC,EAAE;QACxD,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC;QAEnD,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAkB,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC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E,CAAC;gBAClB,eAAe,EAAE,CAAC;YACpB,CAAC,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;IACjC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","file":"BaseSeries.js","sourcesContent":["import React from 'react';\nimport { isNil, isEqual, pickWithout } from '@visactor/vutils';\nimport RootChartContext from '../context/chart';\nimport {\n REACT_TO_VCHART_EVENTS,\n EventsProps,\n findEventProps,\n COMMON_EVENTK_KEYS,\n VCHART_TO_REACT_EVENTS\n} from '../eventsUtils';\nimport { uid } from '../util';\n\nexport interface BaseSeriesProps extends EventsProps {\n id?: string | number;\n}\n\nexport const createSeries = <T extends BaseSeriesProps>(componentName: string, markNames: string[], type?: string) => {\n const ignoreKeys = ['id', 'updateId'];\n const notSpecKeys = COMMON_EVENTK_KEYS.concat(ignoreKeys);\n\n const Comp: React.FC<T & { updateId?: number }> = props => {\n const context = React.useContext(RootChartContext);\n\n const id = React.useRef<string | number>(isNil(props.id) ? uid(type ?? 'series') : props.id);\n\n const seriesSpec = React.useRef<Partial<T>>();\n const bindedEvents = React.useRef<Record<string, boolean>>({});\n const updateId = React.useRef<number>(props.updateId);\n\n const handleEvent = (e: any) => {\n const markIds = markNames.map(markName => `${id.current}-${markName}`);\n if (e?.mark && markIds.includes(e.mark.getUserId())) {\n props[VCHART_TO_REACT_EVENTS[e.event.type]](e);\n }\n };\n\n const addMarkEvent = (events: EventsProps) => {\n if (!events || !context.chart) {\n return;\n }\n\n if (bindedEvents) {\n Object.keys(bindedEvents).forEach(eventKey => {\n if (!events[eventKey]) {\n context.chart.off(REACT_TO_VCHART_EVENTS[eventKey], handleEvent);\n }\n bindedEvents.current[eventKey] = false;\n });\n }\n\n Object.keys(events).forEach(eventKey => {\n if (!bindedEvents?.[eventKey]) {\n context.chart.on(REACT_TO_VCHART_EVENTS[eventKey], handleEvent);\n\n if (!bindedEvents) {\n bindedEvents.current = {};\n }\n bindedEvents.current[eventKey] = true;\n }\n });\n };\n\n const removeMarkEvent = () => {\n addMarkEvent({});\n };\n\n const addMarkId = (spec: any) => {\n markNames.forEach(markName => {\n const defaultMarkId = `${id.current}-${markName}`;\n\n if (isNil(spec[markName])) {\n spec[markName] = { id: defaultMarkId };\n } else if (isNil(spec[markName].id)) {\n spec[markName].id = defaultMarkId;\n }\n });\n };\n\n const insertToContext = (props: Partial<T>) => {\n if (context.specFromChildren) {\n if (!context.specFromChildren.series) {\n context.specFromChildren.series = [];\n }\n\n const spec = isNil(type) ? { ...props, id: id.current } : { ...props, id: id.current, type };\n\n addMarkId(spec);\n context.specFromChildren.series.push(spec);\n context.isChildrenUpdated = true;\n }\n };\n\n const updateToContext = (props: Partial<T>) => {\n if (!context.specFromChildren) {\n return;\n }\n\n if (!context.specFromChildren.series) {\n insertToContext(props);\n return;\n }\n\n const series = context.specFromChildren.series;\n const index = series.findIndex((entry: any) => entry.id === id.current);\n\n if (index >= 0) {\n series[index] = isNil(type) ? { ...props, id: id.current } : { ...props, id: id.current, type };\n addMarkId(series[index]);\n } else {\n insertToContext(props);\n }\n context.isChildrenUpdated = true;\n };\n\n const deleteToContext = () => {\n if (!context.specFromChildren) {\n return;\n }\n const series = context.specFromChildren.series ?? [];\n const index = series.findIndex((entry: any) => entry.id === id.current);\n\n if (index >= 0) {\n const newSeries = series.slice(0, index - 1).concat(series.slice(index + 1));\n context.specFromChildren.series = newSeries;\n context.isChildrenUpdated = true;\n }\n };\n\n addMarkEvent(findEventProps(props));\n if (props.updateId !== updateId.current) {\n // chart render\n updateId.current = props.updateId;\n } else {\n const newSeriesSpec = pickWithout<T>(props, notSpecKeys);\n\n addMarkId(newSeriesSpec);\n if (!isEqual(newSeriesSpec, seriesSpec.current)) {\n seriesSpec.current = newSeriesSpec;\n updateToContext(newSeriesSpec);\n }\n }\n\n React.useEffect(() => {\n return () => {\n deleteToContext();\n removeMarkEvent();\n };\n }, []);\n\n return null;\n };\n\n Comp.displayName = componentName;\n return Comp;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/react-vchart",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.6",
|
|
4
4
|
"description": "The react version of VChart 4.x",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@visactor/vchart": "1.2.0-beta.
|
|
25
|
+
"@visactor/vchart": "1.2.0-beta.6",
|
|
26
26
|
"@visactor/vutils": "~0.13.3",
|
|
27
27
|
"@visactor/vgrammar": "~0.5.1",
|
|
28
28
|
"@visactor/vrender": "~0.13.4",
|