From f922f04498941b16284cf3cd5bb794d2daf64798 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Fri, 27 Dec 2024 17:12:23 +0800 Subject: [PATCH 1/3] feat: package some hook in vgrammar --- packages/vchart/src/core/vchart.ts | 13 ++++++++++++- packages/vchart/src/typings/spec/common.ts | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index fdcb29a7de..e6553ad40f 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -1,7 +1,7 @@ import type { ISeries } from '../series/interface/series'; import { arrayParser } from '../data/parser/array'; import type { ILayoutConstructor, LayoutCallBack } from '../layout/interface'; -import type { IDataValues, IMarkStateSpec, IInitOption } from '../typings/spec/common'; +import type { IDataValues, IMarkStateSpec, IInitOption, IPerformanceHook } from '../typings/spec/common'; // eslint-disable-next-line no-duplicate-imports import { RenderModeEnum } from '../typings/spec/common'; import type { ISeriesConstructor } from '../series/interface'; @@ -414,6 +414,17 @@ export class VChart implements IVChart { // 桑基图默认记载滚动条组件 pluginList.push('scrollbar'); } + // 额外补充部分钩子 + const performanceHook = { ...(restOptions.performanceHook || {}) }; + (['beforeDoRender'] as (keyof IPerformanceHook)[]).forEach(hookKey => { + performanceHook[hookKey] && + // @ts-ignore + (restOptions.performanceHook[hookKey] = (...args) => { + // @ts-ignore + performanceHook[hookKey](...args, this as any); + }); + }); + this._compiler = new Compiler( { dom: this._container ?? 'none', diff --git a/packages/vchart/src/typings/spec/common.ts b/packages/vchart/src/typings/spec/common.ts index 0c31b0e210..9ea2bf63a5 100644 --- a/packages/vchart/src/typings/spec/common.ts +++ b/packages/vchart/src/typings/spec/common.ts @@ -634,6 +634,9 @@ export interface IPerformanceHook { beforeCreateVRenderMark?: () => void; afterCreateVRenderMark?: () => void; + // VGrammar 创建元素完成,vrender 绘图之前 + beforeDoRender?: (vchart?: IVChart) => void; + // VRender Draw 时间 beforeVRenderDraw?: () => void; afterVRenderDraw?: () => void; From f0b50b92e1eb1634d62059d8aa485a423cfc3998 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Fri, 27 Dec 2024 17:13:34 +0800 Subject: [PATCH 2/3] docs: update changlog of rush --- ...package-some-hook-in-grammar_2024-12-27-09-13.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/@visactor/vchart/feat-package-some-hook-in-grammar_2024-12-27-09-13.json diff --git a/common/changes/@visactor/vchart/feat-package-some-hook-in-grammar_2024-12-27-09-13.json b/common/changes/@visactor/vchart/feat-package-some-hook-in-grammar_2024-12-27-09-13.json new file mode 100644 index 0000000000..1ab00c53eb --- /dev/null +++ b/common/changes/@visactor/vchart/feat-package-some-hook-in-grammar_2024-12-27-09-13.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "feat: package some hook in vgrammar\n\n", + "type": "none", + "packageName": "@visactor/vchart" + } + ], + "packageName": "@visactor/vchart", + "email": "lixuef1313@163.com" +} \ No newline at end of file From ee3237dfa40fb9fd1180e49c23be05ff062ded07 Mon Sep 17 00:00:00 2001 From: "lixuefei.1313" Date: Fri, 27 Dec 2024 17:39:57 +0800 Subject: [PATCH 3/3] feat: add vchart params in all hooks --- packages/vchart/src/core/vchart.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/vchart/src/core/vchart.ts b/packages/vchart/src/core/vchart.ts index e6553ad40f..8dded139e8 100644 --- a/packages/vchart/src/core/vchart.ts +++ b/packages/vchart/src/core/vchart.ts @@ -414,15 +414,14 @@ export class VChart implements IVChart { // 桑基图默认记载滚动条组件 pluginList.push('scrollbar'); } - // 额外补充部分钩子 + // hook增加图表实例参数 const performanceHook = { ...(restOptions.performanceHook || {}) }; - (['beforeDoRender'] as (keyof IPerformanceHook)[]).forEach(hookKey => { - performanceHook[hookKey] && + (Object.keys(performanceHook) as (keyof IPerformanceHook)[]).forEach(hookKey => { + // @ts-ignore + restOptions.performanceHook[hookKey] = (...args) => { // @ts-ignore - (restOptions.performanceHook[hookKey] = (...args) => { - // @ts-ignore - performanceHook[hookKey](...args, this as any); - }); + performanceHook[hookKey](...args, this as any); + }; }); this._compiler = new Compiler(