@visactor/react-vchart 1.4.0-alpha.4 → 1.4.0-alpha.5

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAqE;AACrE,+CAAgF;AAChF,gFAA4E;AAC5E,6DAAsE;AAEtE,6CAAwD;AACxD,2DAA0C;AAC1C,kCAAkC;AAClC,4CAAmD;AAEnD,gDAUwB;AAmCxB,MAAM,WAAW,GAAG;IAClB,GAAG,+BAAmB;IACtB,GAAG,+BAAiB;IACpB,SAAS;IACT,SAAS;IACT,MAAM;IACN,WAAW;IACX,SAAS;CACV,CAAC;AAEF,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;IACH,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAQ,IAAI,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAA,cAAM,EAAU,KAAK,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAA,cAAM,EAAC,IAAA,oBAAW,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IACzD,MAAM,YAAY,GAAG,eAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;IAEx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AAC,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,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,KAAQ,EAAE,EAAE;QACzF,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, ISpec } 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 {\n bindEventsToChart,\n EventsProps,\n CHART_EVENTS_KEYS,\n CHART_EVENTS,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps\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 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\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\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\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 const renderPromise = chartContext.current.chart.renderAsync().then(handleChartRender);\n\n if (props.onError) {\n renderPromise.catch(props.onError);\n }\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 eventsBinded.current = props;\n // eslint-disable-next-line promise/catch-or-return\n const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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 const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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: T) => {\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,8DAAqE;AACrE,+CAAgF;AAChF,gFAA4E;AAC5E,6DAAsE;AAEtE,6CAAwD;AACxD,2DAA0C;AAC1C,kCAAkC;AAClC,4CAAmD;AAEnD,gDAUwB;AAmCxB,MAAM,WAAW,GAAG;IAClB,GAAG,+BAAmB;IACtB,GAAG,+BAAiB;IACpB,SAAS;IACT,SAAS;IACT,MAAM;IACN,WAAW;IACX,SAAS;CACV,CAAC;AAEF,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;IACH,IAAA,2BAAmB,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;IAC7B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAQ,IAAI,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAA,cAAM,EAAU,KAAK,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG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,IAAA,cAAO,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;;YAC5C,OAAO,CACL,8BAAC,eAAK,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,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,KAAQ,EAAE,EAAE;QACzF,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, ISpec } 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} 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 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\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\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\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 const renderPromise = chartContext.current.chart.renderAsync().then(handleChartRender);\n\n if (props.onError) {\n renderPromise.catch(props.onError);\n }\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 eventsBinded.current = props;\n // eslint-disable-next-line promise/catch-or-return\n const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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 const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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: T) => {\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,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { MarkSpec } from '@visactor/vgrammar';
2
+ import type { MarkSpec } from '@visactor/vgrammar-core';
3
3
  export interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {
4
4
  id?: string | number;
5
5
  glyphType?: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Mark.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAAyC;AAGzC,2DAA0C;AAC1C,kCAA8B;AAavB,MAAM,IAAI,GAAoB,CAAC,KAAY,EAAE,EAAE;IACpD,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,cAAW,CAAC,CAAC;IACxC,MAAM,EAAE,GAAG,eAAK,CAAC,MAAM,CAAkB,IAAA,cAAK,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAA,UAAG,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnF,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAS,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEtD,IAAI,KAAK,CAAC,QAAQ,KAAK,QAAQ,CAAC,OAAO,EAAE;QAEvC,Q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AAQ,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"]}
1
+ {"version":3,"sources":["components/Mark.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAqD;AACrD,6CAAyC;AAGzC,2DAA0C;AAC1C,kCAA8B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AI,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-core';\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"]}
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- import type { IView } from "@visactor/vgrammar";
1
+ import React from 'react';
2
+ import type { IView } from '@visactor/vgrammar-core';
3
3
  declare const ViewContext: React.Context<IView>;
4
4
  export declare function withView<T>(Component: typeof React.Component): React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<any>>;
5
5
  export default ViewContext;
@@ -1 +1 @@
1
- {"version":3,"sources":["context/view.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,MAAM,WAAW,GAAG,eAAK,CAAC,aAAa,CAAQ,IAAI,CAAC,CAAC;AACrD,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,SAAgB,QAAQ,CAAI,SAAiC;IAC3D,MAAM,GAAG,GAAG,eAAK,CAAC,UAAU,CAAS,CAAC,KAAQ,EAAE,GAAG,EAAE,EAAE;QACrD,OAAO,CACL,8BAAC,WAAW,CAAC,QAAQ,QAClB,CAAC,GAAG,EAAE,EAAE,CAAC,8BAAC,SAAS,kBAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAM,KAAK,EAAI,CAClC,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAVD,4BAUC;AAED,kBAAe,WAAW,CAAC","file":"view.js","sourcesContent":["import React from \"react\";\nimport type { IView } from \"@visactor/vgrammar\";\n\nconst ViewContext = React.createContext<IView>(null);\nViewContext.displayName = \"ViewContext\";\n\nexport function withView<T>(Component: typeof React.Component) {\n const Com = React.forwardRef<any, T>((props: T, ref) => {\n return (\n <ViewContext.Consumer>\n {(ctx) => <Component ref={ref} view={ctx} {...props} />}\n </ViewContext.Consumer>\n );\n });\n Com.displayName = Component.name;\n return Com;\n}\n\nexport default ViewContext;\n"]}
1
+ {"version":3,"sources":["context/view.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,MAAM,WAAW,GAAG,eAAK,CAAC,aAAa,CAAQ,IAAI,CAAC,CAAC;AACrD,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,SAAgB,QAAQ,CAAI,SAAiC;IAC3D,MAAM,GAAG,GAAG,eAAK,CAAC,UAAU,CAAS,CAAC,KAAQ,EAAE,GAAG,EAAE,EAAE;QACrD,OAAO,8BAAC,WAAW,CAAC,QAAQ,QAAE,GAAG,CAAC,EAAE,CAAC,8BAAC,SAAS,kBAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAM,KAAK,EAAI,CAAwB,CAAC;IAC7G,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAND,4BAMC;AAED,kBAAe,WAAW,CAAC","file":"view.js","sourcesContent":["import React from 'react';\nimport type { IView } from '@visactor/vgrammar-core';\n\nconst ViewContext = React.createContext<IView>(null);\nViewContext.displayName = 'ViewContext';\n\nexport function withView<T>(Component: typeof React.Component) {\n const Com = React.forwardRef<any, T>((props: T, ref) => {\n return <ViewContext.Consumer>{ctx => <Component ref={ref} view={ctx} {...props} />}</ViewContext.Consumer>;\n });\n Com.displayName = Component.name;\n return Com;\n}\n\nexport default ViewContext;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["charts/BaseChart.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAqC,MAAM,kBA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,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,CAAkB,aAAqB,EAAE,IAAa,EAAE,QAA0B,EAAE,EAAE;IAC/G,MAAM,GAAG,GAAG,aAAa,CAAoB,SAAgB,EAAE,aAAa,EAAE,CAAC,KAAQ,EAAE,EAAE;QACzF,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, ISpec } 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 {\n bindEventsToChart,\n EventsProps,\n CHART_EVENTS_KEYS,\n CHART_EVENTS,\n LegendEventProps,\n ScrollBarEventProps,\n BrushEventProps,\n DataZoomEventProps,\n PlayerEventProps\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 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\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\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\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 const renderPromise = chartContext.current.chart.renderAsync().then(handleChartRender);\n\n if (props.onError) {\n renderPromise.catch(props.onError);\n }\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 eventsBinded.current = props;\n // eslint-disable-next-line promise/catch-or-return\n const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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 const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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: T) => {\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,MAAqC,MAAM,kBAAkB,CAAC;AACrE,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,EAMb,MAAM,gBAAgB,CAAC;AAmCxB,MAAM,WAAW,GAAG;IAClB,GAAG,mBAAmB;IACtB,GAAG,iBAAiB;IACpB,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,C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itOption, ISpec } 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} 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 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\n /** 图表渲染完成事件 */\n onReady?: (instance: VChart, isInitial: boolean) => void;\n /** throw error when chart run into an error */\n onError?: (err: Error) => void;\n}\n\ntype Props = React.PropsWithChildren<BaseChartProps>;\n\nconst notSpecKeys = [\n ...REACT_PRIVATE_PROPS,\n ...CHART_EVENTS_KEYS,\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\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 const renderPromise = chartContext.current.chart.renderAsync().then(handleChartRender);\n\n if (props.onError) {\n renderPromise.catch(props.onError);\n }\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 eventsBinded.current = props;\n // eslint-disable-next-line promise/catch-or-return\n const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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 const updatePromise = chartContext.current.chart\n .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉\n .then(handleChartRender);\n\n if (props.onError) {\n updatePromise.catch(props.onError);\n }\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: T) => {\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,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { MarkSpec } from '@visactor/vgrammar';
2
+ import type { MarkSpec } from '@visactor/vgrammar-core';
3
3
  export interface MarkProps extends Omit<MarkSpec, 'name' | 'id'> {
4
4
  id?: string | number;
5
5
  glyphType?: string;
@@ -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,M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AE,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"]}
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,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC;QAClC,IAAI,OAAO,EAAE;YACX,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,OAAiB,EAAE,KAAK,CAAC,CAAC;SACvD;KACF;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-core';\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"]}
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- import type { IView } from "@visactor/vgrammar";
1
+ import React from 'react';
2
+ import type { IView } from '@visactor/vgrammar-core';
3
3
  declare const ViewContext: React.Context<IView>;
4
4
  export declare function withView<T>(Component: typeof React.Component): React.ForwardRefExoticComponent<React.PropsWithoutRef<T> & React.RefAttributes<any>>;
5
5
  export default ViewContext;
@@ -1 +1 @@
1
- {"version":3,"sources":["context/view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAQ,IAAI,CAAC,CAAC;AACrD,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,UAAU,QAAQ,CAAI,SAAiC;IAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAS,CAAC,KAAQ,EAAE,GAAG,EAAE,EAAE;QACrD,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,QAClB,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAC,SAAS,kBAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAM,KAAK,EAAI,CAClC,CACxB,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,eAAe,WAAW,CAAC","file":"view.js","sourcesContent":["import React from \"react\";\nimport type { IView } from \"@visactor/vgrammar\";\n\nconst ViewContext = React.createContext<IView>(null);\nViewContext.displayName = \"ViewContext\";\n\nexport function withView<T>(Component: typeof React.Component) {\n const Com = React.forwardRef<any, T>((props: T, ref) => {\n return (\n <ViewContext.Consumer>\n {(ctx) => <Component ref={ref} view={ctx} {...props} />}\n </ViewContext.Consumer>\n );\n });\n Com.displayName = Component.name;\n return Com;\n}\n\nexport default ViewContext;\n"]}
1
+ {"version":3,"sources":["context/view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,WAAW,GAAG,KAAK,CAAC,aAAa,CAAQ,IAAI,CAAC,CAAC;AACrD,WAAW,CAAC,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,UAAU,QAAQ,CAAI,SAAiC;IAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAS,CAAC,KAAQ,EAAE,GAAG,EAAE,EAAE;QACrD,OAAO,oBAAC,WAAW,CAAC,QAAQ,QAAE,GAAG,CAAC,EAAE,CAAC,oBAAC,SAAS,kBAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAM,KAAK,EAAI,CAAwB,CAAC;IAC7G,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,eAAe,WAAW,CAAC","file":"view.js","sourcesContent":["import React from 'react';\nimport type { IView } from '@visactor/vgrammar-core';\n\nconst ViewContext = React.createContext<IView>(null);\nViewContext.displayName = 'ViewContext';\n\nexport function withView<T>(Component: typeof React.Component) {\n const Com = React.forwardRef<any, T>((props: T, ref) => {\n return <ViewContext.Consumer>{ctx => <Component ref={ref} view={ctx} {...props} />}</ViewContext.Consumer>;\n });\n Com.displayName = Component.name;\n return Com;\n}\n\nexport default ViewContext;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/react-vchart",
3
- "version": "1.4.0-alpha.4",
3
+ "version": "1.4.0-alpha.5",
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.4.0-alpha.4",
26
- "@visactor/vutils": "0.15.13-alpha.4",
27
- "@visactor/vgrammar": "0.7.0-alpha.3",
28
- "@visactor/vrender": "0.15.0-alpha.20",
25
+ "@visactor/vchart": "1.4.0-alpha.5",
26
+ "@visactor/vutils": "~0.16.0",
27
+ "@visactor/vgrammar-core": "~0.7.2",
28
+ "@visactor/vrender": "~0.15.2",
29
29
  "react-is": "^18.2.0"
30
30
  },
31
31
  "devDependencies": {
@@ -52,8 +52,8 @@
52
52
  "@types/node": "*",
53
53
  "@vitejs/plugin-react": "3.1.0",
54
54
  "vite": "3.2.6",
55
- "@internal/bundler": "0.0.1",
56
55
  "@internal/ts-config": "0.0.1",
56
+ "@internal/bundler": "0.0.1",
57
57
  "@internal/eslint-config": "0.0.1"
58
58
  },
59
59
  "peerDependencies": {