diff --git a/packages/vchart/src/component/axis/cartesian/axis.ts b/packages/vchart/src/component/axis/cartesian/axis.ts index b329b6dbb1..f09ce5ee8c 100644 --- a/packages/vchart/src/component/axis/cartesian/axis.ts +++ b/packages/vchart/src/component/axis/cartesian/axis.ts @@ -36,7 +36,7 @@ import type { IComponentOption } from '../../interface'; // eslint-disable-next-line no-duplicate-imports import { ComponentTypeEnum } from '../../interface/type'; import { HOOK_EVENT } from '@visactor/vgrammar-core'; -import type { AxisItem, LineAxisAttributes } from '@visactor/vrender-components'; +import { AXIS_ELEMENT_NAME, type AxisItem, type LineAxisAttributes } from '@visactor/vrender-components'; // eslint-disable-next-line no-duplicate-imports import { getAxisItem, isValidCartesianAxis, shouldUpdateAxis } from '../util'; import type { IAxis, ITick } from '../interface'; @@ -46,11 +46,10 @@ import type { ICartesianTickDataOpt } from '@visactor/vrender-components'; import type { DataSet } from '@visactor/vdataset'; // eslint-disable-next-line no-duplicate-imports import { AxisComponent } from '../base-axis'; -import type { IGraphic, IText } from '@visactor/vrender-core'; +import type { FederatedEvent, IGraphic, IText } from '@visactor/vrender-core'; // eslint-disable-next-line no-duplicate-imports import { createText } from '@visactor/vrender-core'; import type { ICartesianChartSpec } from '../../../chart/cartesian/interface'; -import { STACK_FIELD_END, STACK_FIELD_START } from '../../../constant/data'; const CartesianAxisPlugin = [AxisSyncPlugin]; @@ -975,6 +974,16 @@ export abstract class CartesianAxis extends La getBoundsInRect(rect: ILayoutRect, fullRect: ILayoutRect): IBoundsLike { return { x1: 0, x2: 0, y1: 0, y2: 0 }; } + + getDatum(graphic?: IGraphic>) { + // override + return; + } } diff --git a/packages/vchart/src/component/interface/common.ts b/packages/vchart/src/component/interface/common.ts index b4fa060513..670431a75a 100644 --- a/packages/vchart/src/component/interface/common.ts +++ b/packages/vchart/src/component/interface/common.ts @@ -45,6 +45,9 @@ export interface IComponent extends ILayoutModel { // 清空,用于更新等场景 clear: () => void; + + // 数据 + getDatum: (childGraphic?: IGraphic) => any | undefined; } export interface IComponentConstructor extends IModelConstructor { diff --git a/packages/vchart/src/event/event-dispatcher.ts b/packages/vchart/src/event/event-dispatcher.ts index ad89ac5dcf..124c071742 100644 --- a/packages/vchart/src/event/event-dispatcher.ts +++ b/packages/vchart/src/event/event-dispatcher.ts @@ -20,6 +20,7 @@ import type { CompilerListenerParameters } from '../compile/interface'; import type { Compiler } from '../compile/compiler'; import type { StringOrNumber } from '../typings'; import type { IElement } from '@visactor/vgrammar-core'; +import type { IComponent } from '../component/interface'; import { Factory as VGrammarFactory } from '@visactor/vgrammar-core'; const componentTypeMap: Record = { @@ -301,11 +302,18 @@ export class EventDispatcher implements IEventDispatcher { targetMark = targetMark.group; } + const node = get(listenerParams.event, 'target'); + + let datum = listenerParams.datum; + if (model && model.modelType === 'component') { + datum = (model as IComponent).getDatum(node) ?? datum; + } + const params: BaseEventParams = { event: listenerParams.event, item: listenerParams.item, - datum: listenerParams.datum, source: listenerParams.source, + datum, itemMap, chart, model, @@ -326,7 +334,6 @@ export class EventDispatcher implements IEventDispatcher { if ((event as any).elements) { items = (event as any).elements; } - const params: InteractionEventParam = { event: listenerParams.event, chart,