Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vchart/src/chart/base/base-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ export class BaseChart<T extends IChartSpec> extends CompilableBase implements I
this._layoutRect.y = this.padding.top;

this._event.emit(ChartEvent.layoutRectUpdate, { chart: this });
this._option?.chartPluginApply?.('onLayoutRectUpdate', { chart: this });
}

/** 设置当前全局主题 */
Expand Down
6 changes: 6 additions & 0 deletions packages/vchart/src/chart/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { IView } from '@visactor/vgrammar-core';
import type { IBoundsLike } from '@visactor/vutils';
import type { ISeriesSpecInfo } from '../../series/interface';
import type { IRegionSpecInfo } from '../../region/interface';
import type { IChartPluginService } from '../../plugin/chart/interface';

export interface ILayoutParams {
srView?: IView;
Expand Down Expand Up @@ -36,6 +37,11 @@ export interface IChartOption
* 是否关闭交互效果
*/
disableTriggerEvent?: boolean;

/**
* 图表插件应用方法
*/
chartPluginApply?: (funcName: keyof IChartPluginService, ...args: any[]) => any;
}

export interface IChartSpecTransformerOption extends Partial<IChartOption> {
Expand Down
3 changes: 2 additions & 1 deletion packages/vchart/src/chart/sankey/sankey-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class SankeyChartSpecTransformer<
'link',
'emphasis',
'inverse',
'overflow'
'overflow',
'customLayout'
]);

return series;
Expand Down
8 changes: 7 additions & 1 deletion packages/vchart/src/core/vchart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ export class VChart implements IVChart {
private _isReleased: boolean;

private _chartPlugin?: IChartPluginService;
get chartPlugin() {
return this._chartPlugin;
}
private _onResize?: () => void;

constructor(spec: ISpec, options: IInitOption) {
Expand Down Expand Up @@ -783,6 +786,7 @@ export class VChart implements IVChart {
return false;
}
this._updateAnimateState();
this._chartPluginApply('onAfterRender', this._spec);
this._event.emit(ChartEvent.rendered, {
chart: this._chart,
vchart: this
Expand Down Expand Up @@ -2189,7 +2193,9 @@ export class VChart implements IVChart {

layout: this._option.layout,
onError: this._onError,
disableTriggerEvent: this._option.disableTriggerEvent === true
disableTriggerEvent: this._option.disableTriggerEvent === true,
chartPluginApply: (funcName: keyof IChartPluginService, ...args: any[]) =>
this._chartPluginApply(funcName, ...args)
};
}
}
Expand Down
12 changes: 11 additions & 1 deletion packages/vchart/src/data/transforms/sankey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export interface ISankeyOpt extends SankeyOptions {
sourceField: string;
valueField: string;
view: () => { x0: number; x1: number; y0: number; y1: number };
customLayout?: (
layout: SankeyLayout,
originalData: SankeyData,
view: ReturnType<ISankeyOpt['view']>,
option: ISankeyOpt
) => ReturnType<SankeyLayout['layout']>;
}

export const collectHierarchyField = (set: Set<any>, data: any[], field: string) => {
Expand Down Expand Up @@ -99,7 +105,11 @@ export const sankeyLayout = (data: SankeyData[], op: ISankeyOpt) => {

const result = [];

result.push(layout.layout(originalData, view));
if (op.customLayout) {
result.push(op.customLayout(layout, originalData, view, op));
} else {
result.push(layout.layout(originalData, view));
}

return result;
};
4 changes: 4 additions & 0 deletions packages/vchart/src/plugin/chart/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface IChartPlugin<T extends IChartPluginService = any> extends IBase
actionSource: VChartRenderActionSource
) => MaybePromise<void>;
onBeforeInitChart?: (service: T, chartSpec: any, actionSource: VChartRenderActionSource) => MaybePromise<void>;
onLayoutRectUpdate?: (service: T) => void;
onAfterRender?: (service: T) => void;
}

export interface IChartPluginConstructor {
Expand All @@ -38,4 +40,6 @@ export interface IChartPluginService<T extends IChartPlugin = any> extends IBase
actionSource: VChartRenderActionSource
) => MaybePromise<void>;
onBeforeInitChart?: (chartSpec: any, actionSource: VChartRenderActionSource) => MaybePromise<void>;
onLayoutRectUpdate?: () => void;
onAfterRender?: () => void;
}
16 changes: 16 additions & 0 deletions packages/vchart/src/plugin/chart/plugin-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class ChartPluginService<T extends IChartPlugin = IChartPlugin>
this.globalInstance = globalInstance;
}

getPlugin(name: string): T | undefined {
return this._plugins.find(plugin => plugin.name === name);
}

onInit(chartSpec: any) {
this._plugins.forEach(plugin => {
plugin.onInit && plugin.onInit(this, chartSpec);
Expand Down Expand Up @@ -46,6 +50,18 @@ export class ChartPluginService<T extends IChartPlugin = IChartPlugin>
});
}

onLayoutRectUpdate() {
this._plugins.forEach(plugin => {
plugin.onLayoutRectUpdate && plugin.onLayoutRectUpdate(this);
});
}

onAfterRender() {
this._plugins.forEach(plugin => {
plugin.onAfterRender && plugin.onAfterRender(this);
});
}

releaseAll(): void {
super.releaseAll();
this.globalInstance = null;
Expand Down
6 changes: 6 additions & 0 deletions packages/vchart/src/plugin/chart/scroll/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @description export all modules of scroll plugin
* @since 1.0.0
*/
export * from './scroll';
export * from './interface';
24 changes: 24 additions & 0 deletions packages/vchart/src/plugin/chart/scroll/interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { ScrollBarAttributes } from '@visactor/vrender-components';
import type { IChartPlugin } from '../interface';

/**
* IScrollPlugin 接口定义
* @since 1.0.0
*/
export type IScrollPlugin = IChartPlugin;

export interface IScrollPluginSpec {
x?: {
/**
* 是否支持水平滚动
*/
enable: boolean;
} & Omit<ScrollBarAttributes, 'direction' | 'range'>;

y?: {
/**
* 是否支持垂直滚动
*/
enable: boolean;
} & Omit<ScrollBarAttributes, 'direction' | 'range'>;
}
Loading
Loading