Skip to content

Commit d207469

Browse files
committed
feat(multi-view): add types define for multi-view plot
1 parent 8bb9c00 commit d207469

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

src/adaptor/geometries/base.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export type MappingOptions = {
1818
readonly tooltip?: TooltipAttr;
1919
};
2020

21-
export interface GeometryOptions extends Options {
21+
/**
22+
* 一个图形映射的逻辑,纯粹的图形语法
23+
*/
24+
export type Geometry = {
2225
/** geometry 类型 */
2326
readonly type: string;
2427
/** x 轴字段 */
@@ -41,7 +44,12 @@ export interface GeometryOptions extends Options {
4144
readonly mapping: MappingOptions;
4245
/** geometry params */
4346
readonly args?: any;
44-
}
47+
};
48+
49+
/**
50+
* geometry options
51+
*/
52+
export type GeometryOptions = Geometry & Options;
4553

4654
/**
4755
* 获得映射的字段列表

src/lab.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MultiLayer } from './plots/multi-layer';
1+
import { MultiView } from './plots/multi-layer';
22

33
/** 实验室图表所处的阶段 */
44
export enum Stage {
@@ -28,7 +28,7 @@ export function notice(stage: Stage, plotType: string) {
2828
*/
2929
export class Lab {
3030
get MultiLayer() {
31-
notice(Stage.DEV, 'multi-layer');
32-
return MultiLayer;
31+
notice(Stage.DEV, 'multi-view');
32+
return MultiView;
3333
}
3434
}

src/plots/multi-layer/adaptor.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
import { interaction, animation, theme, scale } from '../../adaptor/common';
22
import { Params } from '../../core/adaptor';
33
import { flow } from '../../utils';
4-
import { MultiLayerOptions } from './types';
4+
import { MultiViewOptions } from './types';
55

66
/**
77
* geometry 处理
88
* @param params
99
*/
10-
function geometry(params: Params<MultiLayerOptions>): Params<MultiLayerOptions> {
10+
function geometry(params: Params<MultiViewOptions>): Params<MultiViewOptions> {
1111
const { chart, options } = params;
1212

1313
return params;
1414
}
1515

16-
/**
17-
* meta 配置
18-
* @param params
19-
*/
20-
export function meta(params: Params<MultiLayerOptions>): Params<MultiLayerOptions> {
21-
const { options } = params;
22-
23-
return flow(scale({}))(params);
24-
}
2516
/**
2617
* 图适配器
2718
* @param chart
2819
* @param options
2920
*/
30-
export function adaptor(params: Params<MultiLayerOptions>) {
21+
export function adaptor(params: Params<MultiViewOptions>) {
3122
return flow(
32-
animation,
23+
animation, // 多 view 的图,动画配置放到最前面
3324
geometry,
34-
meta,
3525
interaction,
3626
animation,
3727
theme

src/plots/multi-layer/index.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import { Plot } from '../../core/plot';
22
import { Adaptor } from '../../core/adaptor';
3-
import { MultiLayerOptions } from './types';
3+
import { MultiViewOptions } from './types';
44
import { adaptor } from './adaptor';
55

6-
export { MultiLayerOptions };
6+
export { MultiViewOptions };
77

88
/**
9-
* 多图层图形,释放 G2 80% 的功能
9+
* 多图层图形,释放 G2 80% 的功能,可以用来做:
10+
* 1. 图层叠加的图:
11+
* - 折线 + 置信度区间迭代
12+
* - 嵌套饼图
13+
* - ...
14+
* 2. 图层划分的图
15+
* - 多维图
16+
* - 柱饼组合图
17+
* - ...
1018
*/
11-
export class MultiLayer extends Plot<MultiLayerOptions> {
19+
export class MultiView extends Plot<MultiViewOptions> {
1220
/** 图表类型 */
13-
public type: string = 'multi-layer';
21+
public type: string = 'multi-view';
1422

1523
/**
1624
* 获取适配器
1725
*/
18-
protected getSchemaAdaptor(): Adaptor<MultiLayerOptions> {
26+
protected getSchemaAdaptor(): Adaptor<MultiViewOptions> {
1927
return adaptor;
2028
}
2129
}

src/plots/multi-layer/types.ts

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,63 @@
1-
import { Options } from '../../types';
1+
import { Data, Meta, Options, Region, Tooltip } from '../../types';
2+
import { Axis } from '../../types/axis';
3+
import { Legend } from '../../types/legend';
4+
import { Geometry } from '../../adaptor/geometries/base';
5+
6+
/**
7+
* 子 view 的配置。暂时不开嵌套 view 的情况
8+
*/
9+
type View = {
10+
/**
11+
* view 的布局范围,默认是占满全部
12+
*/
13+
readonly region?: Region;
14+
15+
/**
16+
* view 的中数据
17+
*/
18+
readonly data: Data;
19+
20+
/**
21+
* view 中对应的 meta 字段配置
22+
*/
23+
readonly meta?: Record<string, Meta>;
24+
25+
/**
26+
* 图形 geometry 及映射配置
27+
*/
28+
readonly geometries: Geometry[];
29+
30+
/**
31+
* x 轴配置
32+
*/
33+
readonly xAxis?: Axis;
34+
35+
/**
36+
* y 轴配置
37+
*/
38+
readonly yAxis?: Axis;
39+
40+
/**
41+
* legend 配置
42+
*/
43+
readonly legend?: Legend;
44+
};
245

346
/** 配置类型定义 */
4-
export interface MultiLayerOptions extends Options {}
47+
export interface MultiViewOptions extends Omit<Options, 'data' | 'legend' | 'xAxis' | 'yAxis' | 'legend' | 'tooltip'> {
48+
/**
49+
* 是否同步子 view 的配置
50+
* 目前仅仅支持 true / false,后续需要增加 function 的方式进行自定义 view 之前的布局同步
51+
*/
52+
readonly syncViewPadding?: boolean;
53+
/**
54+
* 没一个图层的配置。
55+
* 每个图层包括有自己的:数据、图形、图形映射。
56+
*/
57+
readonly views: View[];
58+
59+
/**
60+
* tooltip 配置在 chart 层配置
61+
*/
62+
readonly tooltip?: Tooltip;
63+
}

0 commit comments

Comments
 (0)