Skip to content

Commit

Permalink
Merge pull request #3582 from VisActor/chore/spec-types
Browse files Browse the repository at this point in the history
Chore/spec types
  • Loading branch information
xile611 authored Dec 19, 2024
2 parents e28928f + 274cdb9 commit 27f2a90
Show file tree
Hide file tree
Showing 172 changed files with 816 additions and 756 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ packages/vchart/mark.d.ts
packages/vchart/mark.js
packages/vchart/series.d.ts
packages/vchart/series.js
packages/vchart/spec-types/

packages/taro-vchart/lib/
packages/lark-vchart/index.js
Expand All @@ -130,3 +131,5 @@ docs/public/vchart/preview/failedPreviewLists.json
packages/vchart/__tests__/runtime/node/**.png
# env files
.env.local

*.tsbuildinfo
3 changes: 2 additions & 1 deletion packages/vchart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"build:es5": "rimraf lib && rollup -c --bundleConfigAsCjs",
"build:schema": "schema src/typings/spec/chart.ts ISpec --useTypeOfKeyword --ignoreErrors --required > ../vchart-schema/vchart.json",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir ../vchart-types/types",
"build:spec-types": "rimraf ./spec-types && tsc -p ./tsconfig.spec.json --declaration --emitDeclarationOnly --outDir ./spec-types",
"build:umd": "cross-env DEBUG='Bundler*' bundle -f umd",
"build:cjs": "cross-env DEBUG='Bundler*' bundle --clean -f cjs --ignorePostTasks --ignoreUmdEntries",
"build:es": "cross-env DEBUG='Bundler*' bundle --clean -f es --ignorePostTasks",
Expand Down Expand Up @@ -137,4 +138,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
2 changes: 1 addition & 1 deletion packages/vchart/src/animation/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-duplicate-imports */
import { TagPointsUpdate, ClipDirectionAnimate } from '@visactor/vrender-core';
import type { IElement } from '@visactor/vgrammar-core';
import type { ILineAnimationParams, LineAppearPreset } from '../series/line/animation';
import type { ILineAnimationParams, LineAppearPreset } from '../series/line/interface';
import { linePresetAnimation } from '../series/line/animation';
import type { MarkAnimationSpec, ICartesianGroupAnimationParams } from './interface';
import { Factory } from '../core/factory';
Expand Down
9 changes: 5 additions & 4 deletions packages/vchart/src/chart/common/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { ILineSeriesSpec } from '../../series/line/interface';
import type { IAreaSeriesSpec } from '../../series/area/interface';
import type { IChartSpec } from '../../typings/spec/common';
import type { IBar3dSeriesSpec, IBarSeriesSpec } from '../../series/bar/interface';
import type { IRangeColumnChartSpec } from '../range-column';
import type { IRangeAreaChartSpec } from '../range-area';
import type { IRangeColumnChartSpec } from '../range-column/interface';
import type { IRangeAreaChartSpec } from '../range-area/interface';
import type { IDotSeriesSpec } from '../../series/dot/interface';
import type { IMapSeriesSpec } from '../../series/map/interface';
import type { IPie3dSeriesSpec, IPieSeriesSpec } from '../../series/pie/interface';
Expand All @@ -12,7 +12,7 @@ import type { IRadarSeriesSpec } from '../../series/radar/interface';
import type { IRoseSeriesSpec } from '../../series/rose/interface';
import type { IScatterSeriesSpec } from '../../series/scatter/interface';
import type { IWordCloud3dSeriesSpec, IWordCloudSeriesSpec } from '../../series/word-cloud/interface';
import type { IGaugePointerSeriesSpec, IGaugeSeriesSpec } from '../../series/gauge';
import type { IGaugePointerSeriesSpec, IGaugeSeriesSpec } from '../../series/gauge/interface';
import type { IBoxPlotSeriesSpec } from '../../series/box-plot/interface';
import type { ICirclePackingSeriesSpec } from '../../series/circle-packing/interface';
import type { IFunnelSeriesSpec, IFunnel3dSeriesSpec } from '../../series/funnel/interface';
Expand All @@ -24,7 +24,8 @@ import type { ISunburstSeriesSpec } from '../../series/sunburst/interface';
import type { ITreemapSeriesSpec } from '../../series/treemap/interface';
import type { IWaterfallSeriesSpec } from '../../series/waterfall/interface';
import type { ICorrelationSeriesSpec } from '../../series/correlation/interface';
import type { ICartesianAxisSpec, IPolarAxisSpec } from '../../component';
import type { ICartesianAxisSpec } from '../../component/axis/cartesian/interface';
import type { IPolarAxisSpec } from '../../component/axis/polar/interface';
import type { ICartesianCrosshairSpec, IPolarCrosshairSpec } from '../../component/crosshair/interface';
import type { IMarkLineSpec } from '../../component/marker/mark-line/interface';
import type { IMarkAreaSpec } from '../../component/marker/mark-area/interface';
Expand Down
4 changes: 2 additions & 2 deletions packages/vchart/src/chart/gauge/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IPolarAxisSpec } from '../../component/axis/polar/interface';
import type { IGaugePointerSeriesSpec, IGaugeSeriesSpec } from '../../series/gauge';
import type { IGaugePointerSeriesSpec, IGaugeSeriesSpec } from '../../series/gauge/interface';
import type { ILinearAxisSpec } from '../../component/axis/interface';
import type { ICircularProgressSeriesSpec } from '../../series/progress/circular/interface';
import type { IPolarChartSpec } from '../polar';
import type { IPolarChartSpec } from '../polar/interface';

export interface IGaugeChartSpec
extends Omit<IPolarChartSpec, 'axes'>,
Expand Down
4 changes: 2 additions & 2 deletions packages/vchart/src/chart/interface/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { IRenderOption } from '../../compile/interface';
import type { IModelOption, IModelSpecInfo } from '../../model/interface';
import type { IView } from '@visactor/vgrammar-core';
import type { IBoundsLike } from '@visactor/vutils';
import type { ISeriesSpecInfo } from '../../series';
import type { IRegionSpecInfo } from '../../region';
import type { ISeriesSpecInfo } from '../../series/interface';
import type { IRegionSpecInfo } from '../../region/interface';

export interface ILayoutParams {
srView?: IView;
Expand Down
2 changes: 1 addition & 1 deletion packages/vchart/src/chart/polar/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IPointLike } from '@visactor/vutils';
import type { IPolarAxisSpec } from '../../component/axis/polar/interface';
import type { IPolarCrosshairSpec } from '../../component/crosshair/interface';
import type { IChartSpec, ILayoutRect } from '../../typings';
import type { IIndicatorSpec } from '../../component';
import type { IIndicatorSpec } from '../../component/indicator/interface';

export interface IPolarChartSpec extends IChartSpec {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/vchart/src/chart/sequence/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IChartSpec, ISeriesSpec } from '../../typings/spec/common';
import type { ICartesianAxisSpec } from '../../component/axis/cartesian/interface';
import type { IDataZoomSpec, IScrollBarSpec } from '../../component/data-zoom';
import type { IDataZoomSpec } from '../../component/data-zoom/data-zoom/interface';
import type { IScrollBarSpec } from '../../component/data-zoom/scroll-bar/interface';
import type { ICartesianCrosshairSpec } from '../../component/crosshair/interface';
import type { ILayoutSpec } from '../../layout/interface';
import type { RegionSpec } from '../../region/interface';
Expand Down
17 changes: 9 additions & 8 deletions packages/vchart/src/compile/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { IElement, InteractionSpec, IView } from '@visactor/vgrammar-core';
import { View } from '@visactor/vgrammar-core';
import type {
CompilerListenerParameters,
CompilerModel,
ICompiler,
ICompilerModel,
IGrammarItem,
IProductMap,
IRenderContainer,
Expand All @@ -21,7 +22,7 @@ import { isNil, isValid, Logger, LoggerLevel } from '@visactor/vutils';
import type { EventSourceType } from '../event/interface';
import type { IChart } from '../chart/interface';
import { vglobal } from '@visactor/vrender-core';
import type { IColor, Stage } from '@visactor/vrender-core';
import type { IColor, IStage } from '@visactor/vrender-core';
import type { IMorphConfig } from '../animation/spec';
import type { IVChart } from '../core/interface';

Expand All @@ -30,7 +31,7 @@ type EventListener = {
callback: (...args: any[]) => void;
};

export class Compiler {
export class Compiler implements ICompiler {
protected _view: IView;
/**
* 获取 VGrammar View 实例
Expand All @@ -54,7 +55,7 @@ export class Compiler {
// 已释放标记
private _released: boolean = false;

protected _model: CompilerModel = {
protected _model: ICompilerModel = {
[GrammarType.signal]: {},
[GrammarType.data]: {},
[GrammarType.mark]: {}
Expand Down Expand Up @@ -87,8 +88,8 @@ export class Compiler {
/**
* 获取 渲染引擎
*/
getStage(): Stage | undefined {
return this._view?.renderer.stage();
getStage(): IStage | undefined {
return this._view?.renderer.stage() as unknown as IStage;
}

initView() {
Expand Down Expand Up @@ -141,7 +142,7 @@ export class Compiler {
}
}

handleStageRender = () => {
protected handleStageRender = () => {
this._compileChart?.getEvent()?.emit(ChartEvent.afterRender, { chart: this._compileChart });
};

Expand All @@ -159,7 +160,7 @@ export class Compiler {
}
}

compileInteractions() {
protected compileInteractions() {
this._view.removeAllInteractions();
if (this._interactions?.length) {
const regionCombindInteractions = {};
Expand Down
74 changes: 69 additions & 5 deletions packages/vchart/src/compile/interface/compilable-item.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,74 @@
import type { IGroupMark, IGrammarBase, IView } from '@visactor/vgrammar-core';
import type { Compiler } from '../compiler';
import type { Maybe, IPerformanceHook } from '../../typings';
import type { IGroupMark, IGrammarBase, IView, IRenderer, InteractionSpec } from '@visactor/vgrammar-core';
import type { Maybe, IPerformanceHook, StringOrNumber } from '../../typings';
import type { IColor, IStage } from '@visactor/vrender-core';
import type { IChart } from '../../chart/interface/chart';
import type { IVChart } from '../../core/interface';
import type { IMorphConfig } from '../../animation/spec';
import type { IBoundsLike } from '@visactor/vutils';
import type { EventSourceType, EventType } from '../../event/interface';

export type CompilerListenerParameters = {
type: EventType;
event: Event;
source: EventSourceType;
// FIXME: 这里 item 应当为场景树的 Item 类型
item: any | null;
datum: any | null;
markId: number | null;
modelId: number | null;
markUserId: StringOrNumber | null;
modelUserId: StringOrNumber | null;
};

export interface IProductMap<T extends IGrammarItem> {
/** 编译产物 id 和对应的在 vchart 中的 GrammarItem */
[productId: string]: IGrammarItemMap<T>;
}

export interface IGrammarItemMap<T extends IGrammarItem> {
/** GrammarItem id 和 对应的引用 */
[id: number]: T;
}

export type ICompilerModel = Record<GrammarType, IProductMap<IGrammarItem>>;

export interface ICompiler {
getVGrammarView: () => IView;
getModel: () => ICompilerModel;
getRenderer: () => IRenderer;
getCanvas: () => HTMLCanvasElement | undefined;
getStage: () => IStage | undefined;
compile: (ctx: { chart: IChart; vChart: IVChart }, option: any) => void;
clear: (ctx: { chart: IChart; vChart: IVChart }, removeGraphicItems?: boolean) => void;
renderNextTick: (morphConfig?: IMorphConfig) => void;
render: (morphConfig?: IMorphConfig) => void;
updateViewBox: (viewBox: IBoundsLike, reRender?: boolean) => void;
resize: (width: number, height: number, reRender?: boolean) => void;
setBackground: (color: IColor) => void;
setSize: (width: number, height: number) => void;
setViewBox: (viewBox: IBoundsLike, reRender?: boolean) => void;
addEventListener: (
source: EventSourceType,
type: string,
callback: (params: CompilerListenerParameters) => void
) => void;
removeEventListener: (
source: EventSourceType,
type: string,
callback: (params: CompilerListenerParameters) => void
) => void;
release: () => void;
releaseGrammar: (removeGraphicItems: boolean) => void;
addGrammarItem: (grammarItem: IGrammarItem) => void;
removeGrammarItem: (grammarItem: IGrammarItem, reserveVGrammarModel?: boolean) => void;
addInteraction: (interaction: InteractionSpec & { seriesId?: number; regionId?: number }) => void;
removeInteraction: (seriesId: number) => void;
updateDepend: (items?: IGrammarItem[]) => boolean;
}

export interface ICompilable {
/** 获取 compile 对象 */
getCompiler: () => Compiler;
getCompiler: () => ICompiler;
/** 获取 vgrammar view */
getVGrammarView: () => IView;

Expand All @@ -29,7 +93,7 @@ export interface ICompilable {

export interface ICompilableInitOption {
/** 编译对象 应当由外部提供 */
getCompiler: () => Compiler;
getCompiler: () => ICompiler;
/** 性能测试钩子 */
performanceHook?: IPerformanceHook;
}
Expand Down
27 changes: 0 additions & 27 deletions packages/vchart/src/compile/interface/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { IColor, IStageParams, IStage, ILayer } from '@visactor/vrender-core';
import type { EventSourceType, EventType } from '../../event/interface';
import type { RenderMode } from '../../typings/spec/common';
import type { IBoundsLike } from '@visactor/vutils';
import type { GrammarType, IGrammarItem } from './compilable-item';
import type { StringOrNumber } from '../../typings';

export interface IRenderContainer {
Expand Down Expand Up @@ -173,28 +171,3 @@ export interface IRenderOption {
*/
ReactDOM?: any;
}

export type CompilerListenerParameters = {
type: EventType;
event: Event;
source: EventSourceType;
// FIXME: 这里 item 应当为场景树的 Item 类型
item: any | null;
datum: any | null;
markId: number | null;
modelId: number | null;
markUserId: StringOrNumber | null;
modelUserId: StringOrNumber | null;
};

export type CompilerModel = Record<GrammarType, IProductMap<IGrammarItem>>;

export interface IProductMap<T extends IGrammarItem> {
/** 编译产物 id 和对应的在 vchart 中的 GrammarItem */
[productId: string]: IGrammarItemMap<T>;
}

export interface IGrammarItemMap<T extends IGrammarItem> {
/** GrammarItem id 和 对应的引用 */
[id: number]: T;
}
7 changes: 4 additions & 3 deletions packages/vchart/src/compile/mark/compilable-mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import type {
ICompilableMarkOption,
StateValueType,
IMarkCompileOption,
IAttributeOpt
IAttributeOpt,
IMarkData
} from './interface';
// eslint-disable-next-line no-duplicate-imports
import { STATE_VALUE_ENUM } from './interface';
Expand Down Expand Up @@ -94,7 +95,7 @@ export abstract class CompilableMark extends GrammarItem implements ICompilableM
readonly model: IModel;

/** 数据(可以没有) */
protected _data: Maybe<MarkData>;
protected _data: IMarkData;
getDataView(): DataView | undefined {
return this._data?.getDataView();
}
Expand All @@ -113,7 +114,7 @@ export abstract class CompilableMark extends GrammarItem implements ICompilableM
getData() {
return this._data;
}
setData(d?: MarkData) {
setData(d?: IMarkData) {
this._data = d;
}

Expand Down
33 changes: 25 additions & 8 deletions packages/vchart/src/compile/mark/interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { IMarkStateStyle, MarkType } from '../../mark/interface';
import type { IModel } from '../../model/interface';
import type { GrammarItemCompileOption, GrammarItemInitOption } from '../interface';
// eslint-disable-next-line no-duplicate-imports
import type { IGrammarItem } from '../interface';
import type { MarkStateManager } from './mark-state-manager';
import type { GrammarItemCompileOption, GrammarItemInitOption, IGrammarItem } from '../interface';
import type { DataView } from '@visactor/vdataset';
import type {
IAnimate,
Expand All @@ -17,8 +14,28 @@ import type {
TransformSpec
} from '@visactor/vgrammar-core';
import type { Maybe, Datum, StringOrNumber } from '../../typings';
import type { MarkData } from './mark-data';
import type { IRegion } from '../../region/interface';
import type { ICompilableData } from '../data/interface';

export interface IMarkStateManager {
getStateInfoList: () => IStateInfo[];
getStateInfo: (stateValue: StateValue) => IStateInfo;
addStateInfo: (stateInfo: IStateInfo) => void;
changeStateInfo: (stateInfo: Partial<IStateInfo>) => void;
clearStateInfo: (stateValues: StateValue[]) => void;
checkOneState: (
renderNode: IElement,
datum: Datum | Datum[],
state: IStateInfo,
isMultiMark?: boolean
) => 'in' | 'out' | 'skip';
checkState: (renderNode: IElement, datum: Datum | Datum[]) => StateValue[];
}

export interface IMarkData extends ICompilableData {
setCompiledProductId: (name: string) => any;
generateProductId: () => string;
}

export interface ICompilableMarkOption extends GrammarItemInitOption {
key?: string | ((datum: Datum) => string);
Expand Down Expand Up @@ -46,13 +63,13 @@ export interface ICompilableMark extends IGrammarItem {
readonly model: IModel;

// 数据 可以没有
getData: () => MarkData | undefined;
setData: (d: MarkData) => void;
getData: () => IMarkData | undefined;
setData: (d: IMarkData) => void;
getDataView: () => DataView | undefined;
setDataView: (d?: DataView, productId?: string) => void;

// 状态
state: MarkStateManager;
state: IMarkStateManager;
readonly stateStyle: IMarkStateStyle<any>;
hasState: (state: string) => boolean;
getState: (state: string) => any;
Expand Down
4 changes: 2 additions & 2 deletions packages/vchart/src/compile/mark/mark-data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CompilableData } from '../data/compilable-data';
import { PREFIX } from '../../constant/base';
import { isNil, isValid } from '@visactor/vutils';
import type { ICompilableMark, IMarkDataInitOption } from './interface';
import type { ICompilableMark, IMarkData, IMarkDataInitOption } from './interface';

export class MarkData extends CompilableData {
export class MarkData extends CompilableData implements IMarkData {
protected _mark: ICompilableMark;

constructor(option: IMarkDataInitOption) {
Expand Down
Loading

0 comments on commit 27f2a90

Please sign in to comment.