@antv/g2plot 2.4.12 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/g2plot.min.js +4 -4
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/common.d.ts +10 -0
- package/esm/adaptor/common.js +25 -0
- package/esm/adaptor/common.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +4 -4
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/area/index.js +2 -2
- package/esm/plots/area/index.js.map +1 -1
- package/esm/plots/area/types.d.ts +6 -0
- package/esm/plots/area/types.js.map +1 -1
- package/esm/plots/bar/adaptor.js +3 -3
- package/esm/plots/bar/adaptor.js.map +1 -1
- package/esm/plots/bar/index.js +2 -2
- package/esm/plots/bar/index.js.map +1 -1
- package/esm/plots/column/adaptor.js +4 -4
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/column/index.js +2 -2
- package/esm/plots/column/index.js.map +1 -1
- package/esm/plots/column/types.d.ts +6 -0
- package/esm/plots/column/types.js.map +1 -1
- package/esm/plots/mix/adaptor.d.ts +5 -0
- package/esm/plots/mix/adaptor.js +18 -5
- package/esm/plots/mix/adaptor.js.map +1 -1
- package/esm/plots/mix/types.d.ts +24 -2
- package/esm/plots/mix/types.js.map +1 -1
- package/esm/plots/mix/utils.d.ts +21 -16
- package/esm/plots/mix/utils.js +6 -2
- package/esm/plots/mix/utils.js.map +1 -1
- package/esm/plots/pie/adaptor.js +1 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/types/coordinate.d.ts +13 -0
- package/esm/types/coordinate.js +1 -0
- package/esm/types/coordinate.js.map +1 -0
- package/esm/utils/transform/percent.d.ts +1 -1
- package/esm/utils/transform/percent.js +1 -1
- package/esm/utils/transform/percent.js.map +1 -1
- package/lib/adaptor/common.d.ts +10 -0
- package/lib/adaptor/common.js +27 -1
- package/lib/adaptor/common.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +2 -2
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/area/index.js +1 -1
- package/lib/plots/area/index.js.map +1 -1
- package/lib/plots/area/types.d.ts +6 -0
- package/lib/plots/area/types.js.map +1 -1
- package/lib/plots/bar/adaptor.js +3 -3
- package/lib/plots/bar/adaptor.js.map +1 -1
- package/lib/plots/bar/index.js +1 -1
- package/lib/plots/bar/index.js.map +1 -1
- package/lib/plots/column/adaptor.js +2 -2
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/column/index.js +1 -1
- package/lib/plots/column/index.js.map +1 -1
- package/lib/plots/column/types.d.ts +6 -0
- package/lib/plots/column/types.js.map +1 -1
- package/lib/plots/mix/adaptor.d.ts +5 -0
- package/lib/plots/mix/adaptor.js +19 -5
- package/lib/plots/mix/adaptor.js.map +1 -1
- package/lib/plots/mix/types.d.ts +24 -2
- package/lib/plots/mix/types.js.map +1 -1
- package/lib/plots/mix/utils.d.ts +21 -16
- package/lib/plots/mix/utils.js +4 -0
- package/lib/plots/mix/utils.js.map +1 -1
- package/lib/plots/pie/adaptor.js +1 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/types/coordinate.d.ts +13 -0
- package/lib/types/coordinate.js +3 -0
- package/lib/types/coordinate.js.map +1 -0
- package/lib/utils/transform/percent.d.ts +1 -1
- package/lib/utils/transform/percent.js +3 -3
- package/lib/utils/transform/percent.js.map +1 -1
- package/package.json +1 -1
- package/src/adaptor/common.ts +28 -1
- package/src/index.ts +1 -1
- package/src/plots/area/adaptor.ts +14 -3
- package/src/plots/area/index.ts +2 -2
- package/src/plots/area/types.ts +7 -0
- package/src/plots/bar/adaptor.ts +3 -3
- package/src/plots/bar/index.ts +2 -2
- package/src/plots/column/adaptor.ts +4 -2
- package/src/plots/column/index.ts +2 -2
- package/src/plots/column/types.ts +7 -0
- package/src/plots/mix/adaptor.ts +24 -5
- package/src/plots/mix/types.ts +24 -2
- package/src/plots/mix/utils.ts +27 -18
- package/src/plots/pie/adaptor.ts +1 -1
- package/src/types/coordinate.ts +17 -0
- package/src/utils/transform/percent.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/mix/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAAkC;AAElC,sDAA4E;AAC5E,+
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/mix/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAAkC;AAElC,sDAA4E;AAC5E,+CAA0F;AAE1F,wCAAyD;AACzD,2CAAuD;AACvD,qCAAqD;AAKrD,iCAA0C;AAE1C;;;GAGG;AACH,SAAS,SAAS,CAAC,MAA0B;IACnC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAC1B,IAAA,KAAK,GAAa,OAAO,MAApB,EAAE,MAAM,GAAK,OAAO,OAAZ,CAAa;IAElC,WAAI,CAAC,KAAK,EAAE,UAAC,CAAQ;QACX,IAAA,MAAM,GAAmF,CAAC,OAApF,EAAE,IAAI,GAA6E,CAAC,KAA9E,EAAE,IAAI,GAAuE,CAAC,KAAxE,EAAE,IAAI,GAAiE,CAAC,KAAlE,EAAE,UAAU,GAAqD,CAAC,WAAtD,EAAE,YAAY,GAAuC,CAAC,aAAxC,EAAE,WAAW,GAA0B,CAAC,YAA3B,EAAE,OAAO,GAAiB,CAAC,QAAlB,EAAE,UAAU,GAAK,CAAC,WAAN,CAAO;QAEnG,aAAa;QACb,IAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC;YAChC,MAAM,QAAA;SACP,CAAC,CAAC;QAEH,UAAU;QACV,QAAQ,CAAC,IAAI,CAAC,IAAI,C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BAAU,EAAE;IACZ,uBAAuB;KACxB,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAbD,0BAaC","sourcesContent":["import { each } from '@antv/util';\nimport { Geometry } from '@antv/g2';\nimport { geometry as geometryAdaptor } from '../../adaptor/geometries/base';\nimport { interaction, animation, theme, tooltip, annotation } from '../../adaptor/common';\nimport { Params } from '../../core/adaptor';\nimport { PLOT_CONTAINER_OPTIONS } from '../../core/plot';\nimport { AXIS_META_CONFIG_KEYS } from '../../constant';\nimport { deepAssign, flow, pick } from '../../utils';\nimport { Axis } from '../../types/axis';\nimport { Legend } from '../../types/legend';\nimport { Interaction } from '../../types/interaction';\nimport { MixOptions, IView, IGeometry } from './types';\nimport { execPlotAdaptor } from './utils';\n\n/**\n * geometry 处理\n * @param params\n */\nfunction multiView(params: Params<MixOptions>): Params<MixOptions> {\n const { chart, options } = params;\n const { views, legend } = options;\n\n each(views, (v: IView) => {\n const { region, data, meta, axes, coordinate, interactions, annotations, tooltip, geometries } = v;\n\n // 1. 创建 view\n const viewOfG2 = chart.createView({\n region,\n });\n\n // 2. data\n viewOfG2.data(data);\n\n // 3. meta\n let scales: Record<string, any> = {};\n if (axes) {\n each(axes, (axis: Axis, field: string) => {\n scales[field] = pick(axis, AXIS_META_CONFIG_KEYS);\n });\n }\n\n scales = deepAssign({}, meta, scales);\n viewOfG2.scale(scales);\n\n // 4. x y axis\n if (!axes) {\n viewOfG2.axis(false);\n } else {\n each(axes, (axis: Axis, field: string) => {\n viewOfG2.axis(field, axis);\n });\n }\n\n // 5. coordinate\n viewOfG2.coordinate(coordinate);\n\n // 6. geometry\n each(geometries, (geometry: IGeometry) => {\n const { ext } = geometryAdaptor({\n chart: viewOfG2,\n options: geometry,\n });\n\n // adjust\n const { adjust } = geometry;\n if (adjust) {\n ext.geometry.adjust(adjust);\n }\n });\n\n // 7. interactions\n each(interactions, (interaction: Interaction) => {\n if (interaction.enable === false) {\n viewOfG2.removeInteraction(interaction.type);\n } else {\n viewOfG2.interaction(interaction.type, interaction.cfg);\n }\n });\n\n // 8. annotations\n each(annotations, (annotation) => {\n viewOfG2.annotation()[annotation.type]({\n ...annotation,\n });\n });\n\n // 9. animation (先做动画)\n if (typeof v.animation === 'boolean') {\n viewOfG2.animate(false);\n } else {\n viewOfG2.animate(true);\n // 9.1 所有的 Geometry 都使用同一动画(各个图形如有区别,todo 自行覆盖)\n each(viewOfG2.geometries, (g: Geometry) => {\n g.animate(v.animation);\n });\n }\n\n if (tooltip) {\n // 10. tooltip\n viewOfG2.interaction('tooltip');\n viewOfG2.tooltip(tooltip);\n }\n });\n\n // legend\n if (!legend) {\n chart.legend(false);\n } else {\n each(legend, (l: Legend, field: string) => {\n chart.legend(field, l);\n });\n }\n\n // tooltip\n chart.tooltip(options.tooltip);\n return params;\n}\n\n/**\n * 支持嵌套使用 g2plot 内置图表\n * @param params\n */\nfunction multiPlot(params: Params<MixOptions>): Params<MixOptions> {\n const { chart, options } = params;\n const { plots, data = [] } = options;\n\n each(plots, (plot) => {\n const { type, region, options = {}, top } = plot;\n const { tooltip } = options;\n\n if (top) {\n execPlotAdaptor(type, chart, { ...options, data });\n return;\n }\n\n const viewOfG2 = chart.createView({ region, ...pick(options, PLOT_CONTAINER_OPTIONS) });\n if (tooltip) {\n // 配置 tooltip 交互\n viewOfG2.interaction('tooltip');\n }\n\n execPlotAdaptor(type, viewOfG2, { data, ...options });\n });\n\n return params;\n}\n\n/**\n * 处理缩略轴的 adaptor (mix)\n * @param params\n */\nexport function slider(params: Params<MixOptions>): Params<MixOptions> {\n const { chart, options } = params;\n\n chart.option('slider', options.slider);\n\n return params;\n}\n\n/**\n * 图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<MixOptions>) {\n return flow(\n animation, // 多 view 的图,动画配置放到最前面\n multiView,\n multiPlot,\n interaction,\n animation,\n theme,\n tooltip,\n slider,\n annotation()\n // ... 其他的 adaptor flow\n )(params);\n}\n"]}
|
package/lib/plots/mix/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Geometry } from '../../adaptor/geometries/base';
|
|
|
6
6
|
import { Animation } from '../../types/animation';
|
|
7
7
|
import { Annotation } from '../../types/annotation';
|
|
8
8
|
import { Interaction } from '../../types/interaction';
|
|
9
|
+
import { Slider } from '../../types/slider';
|
|
9
10
|
import { IPlotTypes } from './utils';
|
|
10
11
|
/**
|
|
11
12
|
* @title geometry 映射信息
|
|
@@ -65,16 +66,31 @@ export declare type IView = {
|
|
|
65
66
|
* @title 子 plot 的配置
|
|
66
67
|
*/
|
|
67
68
|
export declare type IPlot = IPlotTypes & {
|
|
69
|
+
/**
|
|
70
|
+
* @title 数据
|
|
71
|
+
* @description 设置画布具体的数据. 默认基础顶层 data
|
|
72
|
+
*/
|
|
73
|
+
readonly data?: Record<string, any>[];
|
|
68
74
|
/**
|
|
69
75
|
* @title plot view 的布局范围
|
|
70
76
|
* @default "占满全部"
|
|
71
77
|
*/
|
|
72
78
|
readonly region?: Region;
|
|
79
|
+
/**
|
|
80
|
+
* @title 是否为顶层
|
|
81
|
+
* @description 设置为 true 时,几何图形挂在顶层 chart 对象上,而不是子 view 下。此时 region 设置无效,data 继承顶层 data 配置。
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
readonly top?: boolean;
|
|
73
85
|
};
|
|
74
86
|
/**
|
|
75
87
|
* @title 类型定义
|
|
76
88
|
*/
|
|
77
89
|
export interface MixOptions extends Omit<Options, 'data' | 'legend' | 'xAxis' | 'yAxis' | 'legend' | 'tooltip' | 'slider' | 'scrollbar'> {
|
|
90
|
+
/**
|
|
91
|
+
* @title 顶层数据配置
|
|
92
|
+
*/
|
|
93
|
+
readonly data?: Options['data'];
|
|
78
94
|
/**
|
|
79
95
|
* @title 是否同步子 view 的配置
|
|
80
96
|
* @description 目前仅仅支持 true / false,后续需要增加 function 的方式进行自定义 view 之前的布局同步
|
|
@@ -92,12 +108,18 @@ export interface MixOptions extends Omit<Options, 'data' | 'legend' | 'xAxis' |
|
|
|
92
108
|
readonly plots?: IPlot[];
|
|
93
109
|
/**
|
|
94
110
|
* @title tooltip 配置
|
|
95
|
-
* @description tooltip
|
|
111
|
+
* @description Mix tooltip 组件配置,统一顶层配置
|
|
112
|
+
* TODO 字段映射
|
|
96
113
|
*/
|
|
97
114
|
readonly tooltip?: Tooltip;
|
|
98
115
|
/**
|
|
99
116
|
* @title legend 配置
|
|
100
|
-
* @description
|
|
117
|
+
* @description Mix 图例配置,统一顶层配置
|
|
101
118
|
*/
|
|
102
119
|
readonly legend?: false | Record<string, Legend>;
|
|
120
|
+
/**
|
|
121
|
+
* @title slider 配置
|
|
122
|
+
* @description Mix 缩略轴配置,统一顶层配置
|
|
123
|
+
*/
|
|
124
|
+
readonly slider?: Slider;
|
|
103
125
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/mix/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Types } from '@antv/g2';\nimport { Data, Meta, Options, Region, Tooltip } from '../../types';\nimport { Axis } from '../../types/axis';\nimport { Legend } from '../../types/legend';\nimport { Geometry } from '../../adaptor/geometries/base';\nimport { Animation } from '../../types/animation';\nimport { Annotation } from '../../types/annotation';\nimport { Interaction } from '../../types/interaction';\nimport { IPlotTypes } from './utils';\n\n/**\n * @title geometry 映射信息\n */\nexport type IGeometry = Geometry & {\n adjust?: Types.AdjustOption;\n};\n/**\n * @title 子 view 的配置\n * @description 暂时不开嵌套 view 的情况\n */\nexport type IView = {\n /**\n * @title view 的布局范围\n * @default \"占满全部\"\n */\n readonly region?: Region;\n /**\n * @title view 中的数据\n */\n readonly data: Data;\n /**\n * @title view 中对应的 meta 字段配置\n */\n readonly meta?: Record<string, Meta>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 图形 geometry 及映射配置\n */\n readonly geometries: IGeometry[];\n /**\n * @title x,y 轴\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title interactions\n */\n readonly interactions?: Interaction[];\n /**\n * @title annotation\n */\n readonly annotations?: Annotation[];\n /**\n * @title annotation\n */\n readonly animation?: Animation;\n /**\n * @title tooltip\n */\n readonly tooltip?: Tooltip;\n};\n\n/**\n * @title 子 plot 的配置\n */\nexport type IPlot = IPlotTypes & {\n /**\n * @title plot view 的布局范围\n * @default \"占满全部\"\n */\n readonly region?: Region;\n};\n\n/**\n * @title 类型定义\n */\nexport interface MixOptions\n extends Omit<Options, 'data' | 'legend' | 'xAxis' | 'yAxis' | 'legend' | 'tooltip' | 'slider' | 'scrollbar'> {\n /**\n * @title 是否同步子 view 的配置\n * @description 目前仅仅支持 true / false,后续需要增加 function 的方式进行自定义 view 之前的布局同步\n */\n readonly syncViewPadding?: boolean;\n /**\n * @title 每一个图层的配置\n * @description 每个图层包括有自己的:数据、图形、图形映射\n */\n readonly views?: IView[];\n /**\n * @title 限定与指定 plot 类型\n * @description 支持使用已有的 plot,限定与指定 plot 类型\n */\n readonly plots?: IPlot[];\n /**\n * @title tooltip 配置\n * @description tooltip
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/mix/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Types } from '@antv/g2';\nimport { Data, Meta, Options, Region, Tooltip } from '../../types';\nimport { Axis } from '../../types/axis';\nimport { Legend } from '../../types/legend';\nimport { Geometry } from '../../adaptor/geometries/base';\nimport { Animation } from '../../types/animation';\nimport { Annotation } from '../../types/annotation';\nimport { Interaction } from '../../types/interaction';\nimport { Slider } from '../../types/slider';\nimport { IPlotTypes } from './utils';\n\n/**\n * @title geometry 映射信息\n */\nexport type IGeometry = Geometry & {\n adjust?: Types.AdjustOption;\n};\n/**\n * @title 子 view 的配置\n * @description 暂时不开嵌套 view 的情况\n */\nexport type IView = {\n /**\n * @title view 的布局范围\n * @default \"占满全部\"\n */\n readonly region?: Region;\n /**\n * @title view 中的数据\n */\n readonly data: Data;\n /**\n * @title view 中对应的 meta 字段配置\n */\n readonly meta?: Record<string, Meta>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 图形 geometry 及映射配置\n */\n readonly geometries: IGeometry[];\n /**\n * @title x,y 轴\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title interactions\n */\n readonly interactions?: Interaction[];\n /**\n * @title annotation\n */\n readonly annotations?: Annotation[];\n /**\n * @title annotation\n */\n readonly animation?: Animation;\n /**\n * @title tooltip\n */\n readonly tooltip?: Tooltip;\n};\n\n/**\n * @title 子 plot 的配置\n */\nexport type IPlot = IPlotTypes & {\n /**\n * @title 数据\n * @description 设置画布具体的数据. 默认基础顶层 data\n */\n readonly data?: Record<string, any>[];\n /**\n * @title plot view 的布局范围\n * @default \"占满全部\"\n */\n readonly region?: Region;\n /**\n * @title 是否为顶层\n * @description 设置为 true 时,几何图形挂在顶层 chart 对象上,而不是子 view 下。此时 region 设置无效,data 继承顶层 data 配置。\n * @default false\n */\n readonly top?: boolean;\n};\n\n/**\n * @title 类型定义\n */\nexport interface MixOptions\n extends Omit<Options, 'data' | 'legend' | 'xAxis' | 'yAxis' | 'legend' | 'tooltip' | 'slider' | 'scrollbar'> {\n /**\n * @title 顶层数据配置\n */\n readonly data?: Options['data'];\n /**\n * @title 是否同步子 view 的配置\n * @description 目前仅仅支持 true / false,后续需要增加 function 的方式进行自定义 view 之前的布局同步\n */\n readonly syncViewPadding?: boolean;\n /**\n * @title 每一个图层的配置\n * @description 每个图层包括有自己的:数据、图形、图形映射\n */\n readonly views?: IView[];\n /**\n * @title 限定与指定 plot 类型\n * @description 支持使用已有的 plot,限定与指定 plot 类型\n */\n readonly plots?: IPlot[];\n /**\n * @title tooltip 配置\n * @description Mix tooltip 组件配置,统一顶层配置\n * TODO 字段映射\n */\n readonly tooltip?: Tooltip;\n /**\n * @title legend 配置\n * @description Mix 图例配置,统一顶层配置\n */\n readonly legend?: false | Record<string, Legend>;\n /**\n * @title slider 配置\n * @description Mix 缩略轴配置,统一顶层配置\n */\n readonly slider?: Slider;\n}\n"]}
|
package/lib/plots/mix/utils.d.ts
CHANGED
|
@@ -13,10 +13,12 @@ import { ProgressOptions } from '../progress';
|
|
|
13
13
|
import { ScatterOptions } from '../scatter';
|
|
14
14
|
import { HistogramOptions } from '../histogram';
|
|
15
15
|
import { FunnelOptions } from '../funnel';
|
|
16
|
+
import { StockOptions } from '../stock';
|
|
17
|
+
import { Options } from '../../types';
|
|
16
18
|
/**
|
|
17
|
-
* 移除 options 中的 width、height
|
|
19
|
+
* 移除 options 中的 width、height 设置, 将 options 的 data 设置为可选
|
|
18
20
|
*/
|
|
19
|
-
declare type
|
|
21
|
+
declare type PlotOptions<T> = Omit<T, 'width' | 'height' | 'data'> & Partial<Pick<T extends Options ? T : never, 'data'>>;
|
|
20
22
|
/**
|
|
21
23
|
* multi-view 中的支持的 plots 类型(带 options 定义)
|
|
22
24
|
*/
|
|
@@ -28,46 +30,49 @@ export declare type IPlotTypes = {
|
|
|
28
30
|
/**
|
|
29
31
|
* plot 配置
|
|
30
32
|
*/
|
|
31
|
-
readonly options:
|
|
33
|
+
readonly options: PlotOptions<LineOptions>;
|
|
32
34
|
} | {
|
|
33
35
|
readonly type: 'pie';
|
|
34
|
-
readonly options:
|
|
36
|
+
readonly options: PlotOptions<PieOptions>;
|
|
35
37
|
} | {
|
|
36
38
|
readonly type: 'bar';
|
|
37
|
-
readonly options:
|
|
39
|
+
readonly options: PlotOptions<BarOptions>;
|
|
38
40
|
} | {
|
|
39
41
|
readonly type: 'column';
|
|
40
|
-
readonly options:
|
|
42
|
+
readonly options: PlotOptions<ColumnOptions>;
|
|
41
43
|
} | {
|
|
42
44
|
readonly type: 'area';
|
|
43
|
-
readonly options:
|
|
45
|
+
readonly options: PlotOptions<AreaOptions>;
|
|
44
46
|
} | {
|
|
45
47
|
readonly type: 'gauge';
|
|
46
|
-
readonly options:
|
|
48
|
+
readonly options: PlotOptions<GaugeOptions>;
|
|
47
49
|
} | {
|
|
48
50
|
readonly type: 'tiny-line';
|
|
49
|
-
readonly options:
|
|
51
|
+
readonly options: PlotOptions<TinyLineOptions>;
|
|
50
52
|
} | {
|
|
51
53
|
readonly type: 'tiny-area';
|
|
52
|
-
readonly options:
|
|
54
|
+
readonly options: PlotOptions<TinyAreaOptions>;
|
|
53
55
|
} | {
|
|
54
56
|
readonly type: 'tiny-column';
|
|
55
|
-
readonly options:
|
|
57
|
+
readonly options: PlotOptions<TinyColumnOptions>;
|
|
56
58
|
} | {
|
|
57
59
|
readonly type: 'ring-progress';
|
|
58
|
-
readonly options:
|
|
60
|
+
readonly options: PlotOptions<RingProgressOptions>;
|
|
59
61
|
} | {
|
|
60
62
|
readonly type: 'progress';
|
|
61
|
-
readonly options:
|
|
63
|
+
readonly options: PlotOptions<ProgressOptions>;
|
|
62
64
|
} | {
|
|
63
65
|
readonly type: 'histogram';
|
|
64
|
-
readonly options:
|
|
66
|
+
readonly options: PlotOptions<HistogramOptions>;
|
|
65
67
|
} | {
|
|
66
68
|
readonly type: 'scatter';
|
|
67
|
-
readonly options:
|
|
69
|
+
readonly options: PlotOptions<ScatterOptions>;
|
|
68
70
|
} | {
|
|
69
71
|
readonly type: 'funnel';
|
|
70
|
-
readonly options:
|
|
72
|
+
readonly options: PlotOptions<FunnelOptions>;
|
|
73
|
+
} | {
|
|
74
|
+
readonly type: 'stock';
|
|
75
|
+
readonly options: PlotOptions<StockOptions>;
|
|
71
76
|
};
|
|
72
77
|
/**
|
|
73
78
|
* 执行 plot 的 adaptor, 默认都带上 defaultOptions
|
package/lib/plots/mix/utils.js
CHANGED
|
@@ -17,6 +17,7 @@ var adaptor_11 = require("../progress/adaptor");
|
|
|
17
17
|
var adaptor_12 = require("../scatter/adaptor");
|
|
18
18
|
var adaptor_13 = require("../histogram/adaptor");
|
|
19
19
|
var adaptor_14 = require("../funnel/adaptor");
|
|
20
|
+
var adaptor_15 = require("../stock/adaptor");
|
|
20
21
|
var line_1 = require("../line");
|
|
21
22
|
var pie_1 = require("../pie");
|
|
22
23
|
var bar_1 = require("../bar");
|
|
@@ -31,6 +32,7 @@ var progress_1 = require("../progress");
|
|
|
31
32
|
var scatter_1 = require("../scatter");
|
|
32
33
|
var histogram_1 = require("../histogram");
|
|
33
34
|
var funnel_1 = require("../funnel");
|
|
35
|
+
var stock_1 = require("../stock");
|
|
34
36
|
/**
|
|
35
37
|
* 可在 multi-view 中使用的 plots
|
|
36
38
|
*/
|
|
@@ -49,6 +51,7 @@ var PLOT_ADAPTORS = {
|
|
|
49
51
|
scatter: adaptor_12.adaptor,
|
|
50
52
|
histogram: adaptor_13.adaptor,
|
|
51
53
|
funnel: adaptor_14.adaptor,
|
|
54
|
+
stock: adaptor_15.adaptor,
|
|
52
55
|
};
|
|
53
56
|
/**
|
|
54
57
|
* 获取指定 plot 的 class contructor
|
|
@@ -69,6 +72,7 @@ var PLOT_CONSTRUCTOR = {
|
|
|
69
72
|
scatter: scatter_1.Scatter,
|
|
70
73
|
histogram: histogram_1.Histogram,
|
|
71
74
|
funnel: funnel_1.Funnel,
|
|
75
|
+
stock: stock_1.Stock,
|
|
72
76
|
};
|
|
73
77
|
/**
|
|
74
78
|
* 在 mix 图表以及 facet 图表中,defaultOptions 进行复写简化
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/mix/utils.ts"],"names":[],"mappings":";;;AACA,mCAAiC;AACjC,qCAAyC;AACzC,2CAAyD;AACzD,0CAAuD;AACvD,6CAA6D;AAC7D,0CAAuD;AACvD,2CAAyD;AACzD,4CAA2D;AAC3D,gDAAkE;AAClE,kDAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/mix/utils.ts"],"names":[],"mappings":";;;AACA,mCAAiC;AACjC,qCAAyC;AACzC,2CAAyD;AACzD,0CAAuD;AACvD,6CAA6D;AAC7D,0CAA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K;CACb,CAAC;AAEF;;GAEG;AACH,IAAM,mBAAmB,GAAG;IAC1B,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;IACrB,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;IAC3C,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE;CACzC,CAAC;AAEF;;;GAGG;AACH,SAAgB,eAAe,CAC7B,IAAO,EACP,IAAU,EACV,OAA8B;IAE9B,IAAM,GAAG,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,CAAC,KAAK,CAAC,oBAAkB,IAAI,UAAO,CAAC,CAAC;QAC7C,OAAO;KACR;IACD,IAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC;QACL,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,kBAAU,CAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAAE,EAAE,UAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC;KAC9F,CAAC,CAAC;AACL,CAAC;AAfD,0CAeC","sourcesContent":["import { View } from '@antv/g2';\nimport { get } from '@antv/util';\nimport { deepAssign } from '../../utils';\nimport { adaptor as lineAdaptor } from '../line/adaptor';\nimport { adaptor as pieAdaptor } from '../pie/adaptor';\nimport { adaptor as columnAdaptor } from '../column/adaptor';\nimport { adaptor as barAdaptor } from '../bar/adaptor';\nimport { adaptor as areaAdaptor } from '../area/adaptor';\nimport { adaptor as gaugeAdaptor } from '../gauge/adaptor';\nimport { adaptor as tinyLineAdaptor } from '../tiny-line/adaptor';\nimport { adaptor as tinyColumnAdaptor } from '../tiny-column/adaptor';\nimport { adaptor as tinyAreaAdaptor } from '../tiny-area/adaptor';\nimport { adaptor as ringProgressAdaptor } from '../ring-progress/adaptor';\nimport { adaptor as progressAdaptor } from '../progress/adaptor';\nimport { adaptor as scatterAdaptor } from '../scatter/adaptor';\nimport { adaptor as histogramAdaptor } from '../histogram/adaptor';\nimport { adaptor as funnelAdaptor } from '../funnel/adaptor';\nimport { adaptor as stockAdaptor } from '../stock/adaptor';\nimport { Line, LineOptions } from '../line';\nimport { Pie, PieOptions } from '../pie';\nimport { Bar, BarOptions } from '../bar';\nimport { Column, ColumnOptions } from '../column';\nimport { Area, AreaOptions } from '../area';\nimport { Gauge, GaugeOptions } from '../gauge';\nimport { TinyLine, TinyLineOptions } from '../tiny-line';\nimport { TinyArea, TinyAreaOptions } from '../tiny-area';\nimport { TinyColumn, TinyColumnOptions } from '../tiny-column';\nimport { RingProgress, RingProgressOptions } from '../ring-progress';\nimport { Progress, ProgressOptions } from '../progress';\nimport { Scatter, ScatterOptions } from '../scatter';\nimport { Histogram, HistogramOptions } from '../histogram';\nimport { Funnel, FunnelOptions } from '../funnel';\nimport { Stock, StockOptions } from '../stock';\nimport { Options } from '../../types';\n\n/**\n * 移除 options 中的 width、height 设置, 将 options 的 data 设置为可选\n */\ntype PlotOptions<T> = Omit<T, 'width' | 'height' | 'data'> & Partial<Pick<T extends Options ? T : never, 'data'>>;\n\n/**\n * multi-view 中的支持的 plots 类型(带 options 定义)\n */\nexport type IPlotTypes =\n | {\n /**\n * plot 类型\n */\n readonly type: 'line';\n /**\n * plot 配置\n */\n readonly options: PlotOptions<LineOptions>;\n }\n | {\n readonly type: 'pie';\n readonly options: PlotOptions<PieOptions>;\n }\n | {\n readonly type: 'bar';\n readonly options: PlotOptions<BarOptions>;\n }\n | {\n readonly type: 'column';\n readonly options: PlotOptions<ColumnOptions>;\n }\n | {\n readonly type: 'area';\n readonly options: PlotOptions<AreaOptions>;\n }\n | {\n readonly type: 'gauge';\n readonly options: PlotOptions<GaugeOptions>;\n }\n | {\n readonly type: 'tiny-line';\n readonly options: PlotOptions<TinyLineOptions>;\n }\n | {\n readonly type: 'tiny-area';\n readonly options: PlotOptions<TinyAreaOptions>;\n }\n | {\n readonly type: 'tiny-column';\n readonly options: PlotOptions<TinyColumnOptions>;\n }\n | {\n readonly type: 'ring-progress';\n readonly options: PlotOptions<RingProgressOptions>;\n }\n | {\n readonly type: 'progress';\n readonly options: PlotOptions<ProgressOptions>;\n }\n | {\n readonly type: 'histogram';\n readonly options: PlotOptions<HistogramOptions>;\n }\n | {\n readonly type: 'scatter';\n readonly options: PlotOptions<ScatterOptions>;\n }\n | {\n readonly type: 'funnel';\n readonly options: PlotOptions<FunnelOptions>;\n }\n | {\n readonly type: 'stock';\n readonly options: PlotOptions<StockOptions>;\n };\n\n/**\n * 可在 multi-view 中使用的 plots\n */\nconst PLOT_ADAPTORS = {\n line: lineAdaptor,\n pie: pieAdaptor,\n column: columnAdaptor,\n bar: barAdaptor,\n area: areaAdaptor,\n gauge: gaugeAdaptor,\n 'tiny-line': tinyLineAdaptor,\n 'tiny-column': tinyColumnAdaptor,\n 'tiny-area': tinyAreaAdaptor,\n 'ring-progress': ringProgressAdaptor,\n progress: progressAdaptor,\n scatter: scatterAdaptor,\n histogram: histogramAdaptor,\n funnel: funnelAdaptor,\n stock: stockAdaptor,\n};\n\n/**\n * 获取指定 plot 的 class contructor\n * @param {string} plot\n */\nconst PLOT_CONSTRUCTOR = {\n line: Line,\n pie: Pie,\n column: Column,\n bar: Bar,\n area: Area,\n gauge: Gauge,\n 'tiny-line': TinyLine,\n 'tiny-column': TinyColumn,\n 'tiny-area': TinyArea,\n 'ring-progress': RingProgress,\n progress: Progress,\n scatter: Scatter,\n histogram: Histogram,\n funnel: Funnel,\n stock: Stock,\n};\n\n/**\n * 在 mix 图表以及 facet 图表中,defaultOptions 进行复写简化\n */\nconst DEFAULT_OPTIONS_MAP = {\n pie: { label: false },\n column: { tooltip: { showMarkers: false } },\n bar: { tooltip: { showMarkers: false } },\n};\n\n/**\n * 执行 plot 的 adaptor, 默认都带上 defaultOptions\n * @param {string} plot\n */\nexport function execPlotAdaptor<T extends IPlotTypes['type']>(\n plot: T,\n view: View,\n options: IPlotTypes['options']\n): void {\n const cls = PLOT_CONSTRUCTOR[plot];\n if (!cls) {\n console.error(`could not find ${plot} plot`);\n return;\n }\n const module = PLOT_ADAPTORS[plot];\n module({\n chart: view,\n options: deepAssign({}, cls.getDefaultOptions(), get(DEFAULT_OPTIONS_MAP, plot, {}), options),\n });\n}\n"]}
|
package/lib/plots/pie/adaptor.js
CHANGED
|
@@ -127,7 +127,7 @@ function label(params) {
|
|
|
127
127
|
var angleScale = chart.getScaleByField(angleField);
|
|
128
128
|
var percent = angleScale === null || angleScale === void 0 ? void 0 : angleScale.scale(value);
|
|
129
129
|
return util_1.isFunction(content_1)
|
|
130
|
-
? // append
|
|
130
|
+
? // append percent (number) to data, users can get origin data from `dataum._origin`
|
|
131
131
|
content_1(tslib_1.__assign(tslib_1.__assign({}, data), { percent: percent }), dataum, index)
|
|
132
132
|
: util_1.isString(content_1)
|
|
133
133
|
? utils_1.template(content_1, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/pie/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAA0G;AAE1G,+CAAmF;AACnF,sDAAmE;AACnE,uDAAoD;AACpD,iDAAgD;AAChD,4CAA8C;AAE9C,qCAA8G;AAE9G,uCAA6C;AAC7C,iCAAgE;AAChE,+CAA+C;AAG/C;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAA0B;IAClC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAC1B,IAAA,IAAI,GAA8C,OAAO,KAArD,EAAE,UAAU,GAAkC,OAAO,WAAzC,EAAE,UAAU,GAAsB,OAAO,WAA7B,EAAE,KAAK,GAAe,OAAO,MAAtB,EAAE,QAAQ,GAAK,OAAO,SAAZ,CAAa;IAElE,WAAW;IACX,IAAI,WAAW,GAAG,0BAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC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,2BAA2B;YAC3B,IAAI,aAAW,GAAG,EAAE,CAAC;YACrB,IAAI,QAAC,CAAC,CAAC,GAAG,0CAAE,KAAK,CAAA,EAAE;gBACjB,aAAW,GAAG;oBACZ;wBACE,OAAO,EAAE,oBAAoB;wBAC7B,MAAM,EAAK,4BAAa,YAAS;wBACjC,GAAG,EAAE,EAAE,SAAS,WAAA,EAAE,WAAW,aAAA,EAAE;qBAChC;iBACF,CAAC;aACH;YACD,WAAI,OAAC,CAAC,CAAC,GAAG,0CAAE,KAAK,EAAE,UAAC,KAAK;gBACvB,aAAW,CAAC,IAAI,uCAAM,KAAK,KAAE,GAAG,EAAE,EAAE,SAAS,WAAA,EAAE,WAAW,aAAA,EAAE,IAAG,CAAC;YAClE,CAAC,CAAC,CAAC;YACH,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,kBAAU,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,aAAW,EAAE,CAAC,CAAC,CAAC;SAC1E;aAAM;YACL,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AA7BD,kCA6BC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAA0B;IAChD,0BAA0B;IAC1B,OAAO,YAAI,CACT,iBAAO,CAAC,UAAU,CAAC,EACnB,QAAQ,EACR,IAAI,EACJ,cAAK,EACL,UAAU,EACV,eAAM,EACN,OAAO,EACP,KAAK,EACL,cAAK;IACL,mBAAmB;IACnB,aAAa,EACb,WAAW,EACX,kBAAS,CACV,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAjBD,0BAiBC","sourcesContent":["import { isFunction, isString, isNil, get, isArray, isNumber, each, toString, isEmpty } from '@antv/util';\nimport { Params } from '../../core/adaptor';\nimport { legend, animation, theme, state, annotation } from '../../adaptor/common';\nimport { getMappingFunction } from '../../adaptor/geometries/base';\nimport { interval } from '../../adaptor/geometries';\nimport { pattern } from '../../adaptor/pattern';\nimport { getLocale } from '../../core/locale';\nimport { Interaction } from '../../types/interaction';\nimport { flow, template, transformLabel, deepAssign, renderStatistic, processIllegalData } from '../../utils';\nimport { Data, Datum } from '../../types';\nimport { DEFAULT_OPTIONS } from './contants';\nimport { adaptOffset, getTotalValue, isAllZero } from './utils';\nimport { PIE_STATISTIC } from './interactions';\nimport { PieOptions } from './types';\n\n/**\n * 字段\n * @param params\n */\nfunction geometry(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { data, angleField, colorField, color, pieStyle } = options;\n\n // 处理不合法的数据\n let processData = processIllegalData(data, angleField);\n\n if (isAllZero(processData, angleField)) {\n // 数据全 0 处理,调整 position 映射\n const percentageField = '$$percentage$$';\n processData = processData.map((d) => ({ ...d, [percentageField]: 1 / processData.length }));\n chart.data(processData);\n\n const p = deepAssign({}, params, {\n options: {\n xField: '1',\n yField: percentageField,\n seriesField: colorField,\n isStack: true,\n interval: {\n color,\n style: pieStyle,\n },\n args: {\n zIndexReversed: true,\n sortZIndex: true,\n },\n },\n });\n\n interval(p);\n } else {\n chart.data(processData);\n\n const p = deepAssign({}, params, {\n options: {\n xField: '1',\n yField: angleField,\n seriesField: colorField,\n isStack: true,\n interval: {\n color,\n style: pieStyle,\n },\n args: {\n zIndexReversed: true,\n sortZIndex: true,\n },\n },\n });\n\n interval(p);\n }\n\n return params;\n}\n\n/**\n * meta 配置\n * @param params\n */\nfunction meta(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { meta, colorField } = options;\n\n // meta 直接是 scale 的信息\n const scales = deepAssign({}, meta);\n chart.scale(scales, {\n [colorField]: { type: 'cat' },\n });\n\n return params;\n}\n\n/**\n * coord 配置\n * @param params\n */\nfunction coordinate(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { radius, innerRadius, startAngle, endAngle } = options;\n\n chart.coordinate({\n type: 'theta',\n cfg: {\n radius,\n innerRadius,\n startAngle,\n endAngle,\n },\n });\n\n return params;\n}\n\n/**\n * label 配置\n * @param params\n */\nfunction label(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { label, colorField, angleField } = options;\n\n const geometry = chart.geometries[0];\n // label 为 false, 空 则不显示 label\n if (!label) {\n geometry.label(false);\n } else {\n const { callback, ...cfg } = label;\n const labelCfg = transformLabel(cfg);\n\n // ① 提供模板字符串的 label content 配置\n if (labelCfg.content) {\n const { content } = labelCfg;\n labelCfg.content = (data: object, dataum: any, index: number) => {\n const name = data[colorField];\n const value = data[angleField];\n // dymatic get scale, scale is ready this time\n const angleScale = chart.getScaleByField(angleField);\n const percent = angleScale?.scale(value);\n return isFunction(content)\n ? // append pecent (number) to data, users can get origin data from `dataum._origin`\n content({ ...data, percent }, dataum, index)\n : isString(content)\n ? template(content as string, {\n value,\n name,\n // percentage (string), default keep 2\n percentage: isNumber(percent) && !isNil(value) ? `${(percent * 100).toFixed(2)}%` : null,\n })\n : content;\n };\n }\n\n const LABEL_LAYOUT_TYPE_MAP = {\n inner: '',\n outer: 'pie-outer',\n spider: 'pie-spider',\n };\n const labelLayoutType = labelCfg.type ? LABEL_LAYOUT_TYPE_MAP[labelCfg.type] : 'pie-outer';\n const labelLayoutCfg = labelCfg.layout ? (!isArray(labelCfg.layout) ? [labelCfg.layout] : labelCfg.layout) : [];\n labelCfg.layout = (labelLayoutType ? [{ type: labelLayoutType }] : []).concat(labelLayoutCfg);\n\n geometry.label({\n // fix: could not create scale, when field is undefined(attributes 中的 fields 定义都会被用来创建 scale)\n fields: colorField ? [angleField, colorField] : [angleField],\n callback,\n cfg: {\n ...labelCfg,\n offset: adaptOffset(labelCfg.type, labelCfg.offset),\n type: 'pie',\n },\n });\n }\n return params;\n}\n\n/**\n * statistic options 处理\n * 1. 默认继承 default options 的样式\n * 2. 默认使用 meta 的 formatter\n */\nexport function transformStatisticOptions(options: PieOptions): PieOptions {\n const { innerRadius, statistic, angleField, colorField, meta, locale } = options;\n\n const i18n = getLocale(locale);\n\n if (innerRadius && statistic) {\n let { title: titleOpt, content: contentOpt } = deepAssign({}, DEFAULT_OPTIONS.statistic, statistic);\n if (titleOpt !== false) {\n titleOpt = deepAssign(\n {},\n {\n formatter: (datum: Datum) => {\n // 交互中\n if (datum) {\n return datum[colorField];\n }\n return !isNil(titleOpt.content) ? titleOpt.content : i18n.get(['statistic', 'total']);\n },\n },\n titleOpt\n );\n }\n if (contentOpt !== false) {\n contentOpt = deepAssign(\n {},\n {\n formatter: (datum: Datum, data: Data) => {\n const dataValue = datum ? datum[angleField] : getTotalValue(data, angleField);\n const metaFormatter = get(meta, [angleField, 'formatter']) || ((v) => v);\n // 交互中\n if (datum) {\n return metaFormatter(dataValue);\n }\n return !isNil(contentOpt.content) ? contentOpt.content : metaFormatter(dataValue);\n },\n },\n contentOpt\n );\n }\n\n return deepAssign({}, { statistic: { title: titleOpt, content: contentOpt } }, options);\n }\n return options;\n}\n\n/**\n * statistic 中心文本配置\n * @param params\n */\nexport function pieAnnotation(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { innerRadius, statistic } = transformStatisticOptions(options);\n // 先清空标注,再重新渲染\n chart.getController('annotation').clear(true);\n\n // 先进行其他 annotations,再去渲染统计文本\n flow(annotation())(params);\n\n /** 中心文本 指标卡 */\n if (innerRadius && statistic) {\n renderStatistic(chart, { statistic, plotType: 'pie' });\n }\n\n return params;\n}\n\n/**\n * 饼图 tooltip 配置\n * 1. 强制 tooltip.shared 为 false\n * @param params\n */\nfunction tooltip(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { tooltip, colorField, angleField, data } = options;\n\n if (tooltip === false) {\n chart.tooltip(tooltip);\n } else {\n chart.tooltip(deepAssign({}, tooltip, { shared: false }));\n\n // 主要解决 all zero, 对于非 all zero 不再适用\n if (isAllZero(data, angleField)) {\n let fields = get(tooltip, 'fields');\n let formatter = get(tooltip, 'formatter');\n\n if (isEmpty(get(tooltip, 'fields'))) {\n fields = [colorField, angleField];\n formatter = formatter || ((datum) => ({ name: datum[colorField], value: toString(datum[angleField]) }));\n }\n chart.geometries[0].tooltip(fields.join('*'), getMappingFunction(fields, formatter));\n }\n }\n\n return params;\n}\n\n/**\n * Interaction 配置 (饼图特殊的 interaction, 中心文本变更的时候,需要将一些配置参数传进去)\n * @param params\n */\nexport function interaction(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { interactions, statistic, annotations } = transformStatisticOptions(options);\n\n each(interactions, (i: Interaction) => {\n if (i.enable === false) {\n chart.removeInteraction(i.type);\n } else if (i.type === 'pie-statistic-active') {\n // 只针对 start 阶段的配置,进行添加参数信息\n let startStages = [];\n if (!i.cfg?.start) {\n startStages = [\n {\n trigger: 'element:mouseenter',\n action: `${PIE_STATISTIC}:change`,\n arg: { statistic, annotations },\n },\n ];\n }\n each(i.cfg?.start, (stage) => {\n startStages.push({ ...stage, arg: { statistic, annotations } });\n });\n chart.interaction(i.type, deepAssign({}, i.cfg, { start: startStages }));\n } else {\n chart.interaction(i.type, i.cfg || {});\n }\n });\n\n return params;\n}\n\n/**\n * 饼图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<PieOptions>) {\n // flow 的方式处理所有的配置到 G2 API\n return flow<Params<PieOptions>>(\n pattern('pieStyle'),\n geometry,\n meta,\n theme,\n coordinate,\n legend,\n tooltip,\n label,\n state,\n /** 指标卡中心文本 放在下层 */\n pieAnnotation,\n interaction,\n animation\n )(params);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/pie/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAA0G;AAE1G,+CAAmF;AACnF,sDAAmE;AACnE,uDAAoD;AACpD,iDAAgD;AAChD,4CAA8C;AAE9C,qCAA8G;AAE9G,uCAA6C;AAC7C,iCAAgE;AAChE,+CAA+C;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A0B;IAChD,0BAA0B;IAC1B,OAAO,YAAI,CACT,iBAAO,CAAC,UAAU,CAAC,EACnB,QAAQ,EACR,IAAI,EACJ,cAAK,EACL,UAAU,EACV,eAAM,EACN,OAAO,EACP,KAAK,EACL,cAAK;IACL,mBAAmB;IACnB,aAAa,EACb,WAAW,EACX,kBAAS,CACV,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC;AAjBD,0BAiBC","sourcesContent":["import { isFunction, isString, isNil, get, isArray, isNumber, each, toString, isEmpty } from '@antv/util';\nimport { Params } from '../../core/adaptor';\nimport { legend, animation, theme, state, annotation } from '../../adaptor/common';\nimport { getMappingFunction } from '../../adaptor/geometries/base';\nimport { interval } from '../../adaptor/geometries';\nimport { pattern } from '../../adaptor/pattern';\nimport { getLocale } from '../../core/locale';\nimport { Interaction } from '../../types/interaction';\nimport { flow, template, transformLabel, deepAssign, renderStatistic, processIllegalData } from '../../utils';\nimport { Data, Datum } from '../../types';\nimport { DEFAULT_OPTIONS } from './contants';\nimport { adaptOffset, getTotalValue, isAllZero } from './utils';\nimport { PIE_STATISTIC } from './interactions';\nimport { PieOptions } from './types';\n\n/**\n * 字段\n * @param params\n */\nfunction geometry(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { data, angleField, colorField, color, pieStyle } = options;\n\n // 处理不合法的数据\n let processData = processIllegalData(data, angleField);\n\n if (isAllZero(processData, angleField)) {\n // 数据全 0 处理,调整 position 映射\n const percentageField = '$$percentage$$';\n processData = processData.map((d) => ({ ...d, [percentageField]: 1 / processData.length }));\n chart.data(processData);\n\n const p = deepAssign({}, params, {\n options: {\n xField: '1',\n yField: percentageField,\n seriesField: colorField,\n isStack: true,\n interval: {\n color,\n style: pieStyle,\n },\n args: {\n zIndexReversed: true,\n sortZIndex: true,\n },\n },\n });\n\n interval(p);\n } else {\n chart.data(processData);\n\n const p = deepAssign({}, params, {\n options: {\n xField: '1',\n yField: angleField,\n seriesField: colorField,\n isStack: true,\n interval: {\n color,\n style: pieStyle,\n },\n args: {\n zIndexReversed: true,\n sortZIndex: true,\n },\n },\n });\n\n interval(p);\n }\n\n return params;\n}\n\n/**\n * meta 配置\n * @param params\n */\nfunction meta(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { meta, colorField } = options;\n\n // meta 直接是 scale 的信息\n const scales = deepAssign({}, meta);\n chart.scale(scales, {\n [colorField]: { type: 'cat' },\n });\n\n return params;\n}\n\n/**\n * coord 配置\n * @param params\n */\nfunction coordinate(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { radius, innerRadius, startAngle, endAngle } = options;\n\n chart.coordinate({\n type: 'theta',\n cfg: {\n radius,\n innerRadius,\n startAngle,\n endAngle,\n },\n });\n\n return params;\n}\n\n/**\n * label 配置\n * @param params\n */\nfunction label(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { label, colorField, angleField } = options;\n\n const geometry = chart.geometries[0];\n // label 为 false, 空 则不显示 label\n if (!label) {\n geometry.label(false);\n } else {\n const { callback, ...cfg } = label;\n const labelCfg = transformLabel(cfg);\n\n // ① 提供模板字符串的 label content 配置\n if (labelCfg.content) {\n const { content } = labelCfg;\n labelCfg.content = (data: object, dataum: any, index: number) => {\n const name = data[colorField];\n const value = data[angleField];\n // dymatic get scale, scale is ready this time\n const angleScale = chart.getScaleByField(angleField);\n const percent = angleScale?.scale(value);\n return isFunction(content)\n ? // append percent (number) to data, users can get origin data from `dataum._origin`\n content({ ...data, percent }, dataum, index)\n : isString(content)\n ? template(content as string, {\n value,\n name,\n // percentage (string), default keep 2\n percentage: isNumber(percent) && !isNil(value) ? `${(percent * 100).toFixed(2)}%` : null,\n })\n : content;\n };\n }\n\n const LABEL_LAYOUT_TYPE_MAP = {\n inner: '',\n outer: 'pie-outer',\n spider: 'pie-spider',\n };\n const labelLayoutType = labelCfg.type ? LABEL_LAYOUT_TYPE_MAP[labelCfg.type] : 'pie-outer';\n const labelLayoutCfg = labelCfg.layout ? (!isArray(labelCfg.layout) ? [labelCfg.layout] : labelCfg.layout) : [];\n labelCfg.layout = (labelLayoutType ? [{ type: labelLayoutType }] : []).concat(labelLayoutCfg);\n\n geometry.label({\n // fix: could not create scale, when field is undefined(attributes 中的 fields 定义都会被用来创建 scale)\n fields: colorField ? [angleField, colorField] : [angleField],\n callback,\n cfg: {\n ...labelCfg,\n offset: adaptOffset(labelCfg.type, labelCfg.offset),\n type: 'pie',\n },\n });\n }\n return params;\n}\n\n/**\n * statistic options 处理\n * 1. 默认继承 default options 的样式\n * 2. 默认使用 meta 的 formatter\n */\nexport function transformStatisticOptions(options: PieOptions): PieOptions {\n const { innerRadius, statistic, angleField, colorField, meta, locale } = options;\n\n const i18n = getLocale(locale);\n\n if (innerRadius && statistic) {\n let { title: titleOpt, content: contentOpt } = deepAssign({}, DEFAULT_OPTIONS.statistic, statistic);\n if (titleOpt !== false) {\n titleOpt = deepAssign(\n {},\n {\n formatter: (datum: Datum) => {\n // 交互中\n if (datum) {\n return datum[colorField];\n }\n return !isNil(titleOpt.content) ? titleOpt.content : i18n.get(['statistic', 'total']);\n },\n },\n titleOpt\n );\n }\n if (contentOpt !== false) {\n contentOpt = deepAssign(\n {},\n {\n formatter: (datum: Datum, data: Data) => {\n const dataValue = datum ? datum[angleField] : getTotalValue(data, angleField);\n const metaFormatter = get(meta, [angleField, 'formatter']) || ((v) => v);\n // 交互中\n if (datum) {\n return metaFormatter(dataValue);\n }\n return !isNil(contentOpt.content) ? contentOpt.content : metaFormatter(dataValue);\n },\n },\n contentOpt\n );\n }\n\n return deepAssign({}, { statistic: { title: titleOpt, content: contentOpt } }, options);\n }\n return options;\n}\n\n/**\n * statistic 中心文本配置\n * @param params\n */\nexport function pieAnnotation(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { innerRadius, statistic } = transformStatisticOptions(options);\n // 先清空标注,再重新渲染\n chart.getController('annotation').clear(true);\n\n // 先进行其他 annotations,再去渲染统计文本\n flow(annotation())(params);\n\n /** 中心文本 指标卡 */\n if (innerRadius && statistic) {\n renderStatistic(chart, { statistic, plotType: 'pie' });\n }\n\n return params;\n}\n\n/**\n * 饼图 tooltip 配置\n * 1. 强制 tooltip.shared 为 false\n * @param params\n */\nfunction tooltip(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { tooltip, colorField, angleField, data } = options;\n\n if (tooltip === false) {\n chart.tooltip(tooltip);\n } else {\n chart.tooltip(deepAssign({}, tooltip, { shared: false }));\n\n // 主要解决 all zero, 对于非 all zero 不再适用\n if (isAllZero(data, angleField)) {\n let fields = get(tooltip, 'fields');\n let formatter = get(tooltip, 'formatter');\n\n if (isEmpty(get(tooltip, 'fields'))) {\n fields = [colorField, angleField];\n formatter = formatter || ((datum) => ({ name: datum[colorField], value: toString(datum[angleField]) }));\n }\n chart.geometries[0].tooltip(fields.join('*'), getMappingFunction(fields, formatter));\n }\n }\n\n return params;\n}\n\n/**\n * Interaction 配置 (饼图特殊的 interaction, 中心文本变更的时候,需要将一些配置参数传进去)\n * @param params\n */\nexport function interaction(params: Params<PieOptions>): Params<PieOptions> {\n const { chart, options } = params;\n const { interactions, statistic, annotations } = transformStatisticOptions(options);\n\n each(interactions, (i: Interaction) => {\n if (i.enable === false) {\n chart.removeInteraction(i.type);\n } else if (i.type === 'pie-statistic-active') {\n // 只针对 start 阶段的配置,进行添加参数信息\n let startStages = [];\n if (!i.cfg?.start) {\n startStages = [\n {\n trigger: 'element:mouseenter',\n action: `${PIE_STATISTIC}:change`,\n arg: { statistic, annotations },\n },\n ];\n }\n each(i.cfg?.start, (stage) => {\n startStages.push({ ...stage, arg: { statistic, annotations } });\n });\n chart.interaction(i.type, deepAssign({}, i.cfg, { start: startStages }));\n } else {\n chart.interaction(i.type, i.cfg || {});\n }\n });\n\n return params;\n}\n\n/**\n * 饼图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<PieOptions>) {\n // flow 的方式处理所有的配置到 G2 API\n return flow<Params<PieOptions>>(\n pattern('pieStyle'),\n geometry,\n meta,\n theme,\n coordinate,\n legend,\n tooltip,\n label,\n state,\n /** 指标卡中心文本 放在下层 */\n pieAnnotation,\n interaction,\n animation\n )(params);\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transformations of coordinate
|
|
3
|
+
*/
|
|
4
|
+
export declare type Transformations = Array<{
|
|
5
|
+
/** send (x, y) to (-x, y) */
|
|
6
|
+
type: 'reflectX';
|
|
7
|
+
} | {
|
|
8
|
+
/** send (x, y) to (x, -y) */
|
|
9
|
+
type: 'reflectY';
|
|
10
|
+
} | {
|
|
11
|
+
/** send (x, y) to (y, x) */
|
|
12
|
+
type: 'transpose';
|
|
13
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinate.js","sourceRoot":"","sources":["../../src/types/coordinate.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Transformations of coordinate\n */\nexport type Transformations = Array<\n | {\n /** send (x, y) to (-x, y) */\n type: 'reflectX';\n }\n | {\n /** send (x, y) to (x, -y) */\n type: 'reflectY';\n }\n | {\n /** send (x, y) to (y, x) */\n type: 'transpose';\n }\n>;\n"]}
|
|
@@ -23,4 +23,4 @@ export declare function getDeepPercent(data: Record<string, any>[], measure: str
|
|
|
23
23
|
* 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)
|
|
24
24
|
* @param isPercent 是否百分比
|
|
25
25
|
*/
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function getDataWhetherPercentage(data: Record<string, any>[], yField: string, groupField: string, asField: string, isPercent?: boolean): Record<string, any>[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDataWhetherPercentage = exports.getDeepPercent = exports.percent = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var util_1 = require("@antv/util");
|
|
6
6
|
var number_1 = require("../number");
|
|
@@ -63,8 +63,8 @@ exports.getDeepPercent = getDeepPercent;
|
|
|
63
63
|
* 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)
|
|
64
64
|
* @param isPercent 是否百分比
|
|
65
65
|
*/
|
|
66
|
-
function
|
|
66
|
+
function getDataWhetherPercentage(data, yField, groupField, asField, isPercent) {
|
|
67
67
|
return !isPercent ? data : percent(data, yField, groupField, asField);
|
|
68
68
|
}
|
|
69
|
-
exports.
|
|
69
|
+
exports.getDataWhetherPercentage = getDataWhetherPercentage;
|
|
70
70
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.js","sourceRoot":"","sources":["../../../src/utils/transform/percent.ts"],"names":[],"mappings":";;;;AAAA,mCAAyC;AAEzC,oCAAyC;AAEzC;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,IAAU,EAAE,OAAe,EAAE,UAAkB,EAAE,EAAU;IACjF,qBAAqB;IACrB,IAAM,MAAM,GAAG,aAAM,CACnB,IAAI,EACJ,UAAC,GAAG,EAAE,KAAY;QAChB,IAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAExD,IAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QAEzB,GAAG,GAAG,qBAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACtC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAEzB,OAAO,GAAG,CAAC;IACb,CAAC,EACD,IAAI,GAAG,EAAkB,CAC1B,CAAC;IAEF,eAAe;IACf,O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,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACtC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAEzB,OAAO,GAAG,CAAC;IACb,CAAC,EACD,IAAI,GAAG,EAAkB,CAC1B,CAAC;IAEF,eAAe;IACf,OAAO,UAAG,CAAC,IAAI,EAAE,UAAC,KAAY;;QAC5B,IAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACzB,gBAAgB;QAChB,IAAM,UAAU,GAAG,aAAM,CAAC,MAAM,EAAE,UAAC,KAAK,EAAE,KAAK,IAAK,OAAA,KAAG,KAAK,GAAG,KAAK,CAAC,KAAK,CAAG,EAAzB,CAAyB,EAAE,EAAE,CAAC,CAAC;QAEnF,IAAM,UAAU,GAAG,qBAAY,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpG,6CACK,KAAK,gBACP,OAAO,IAAG,UAAU,OACrB;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAhCD,wCAgCC;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CACtC,IAA2B,EAC3B,MAAc,EACd,UAAkB,EAClB,OAAe,EACf,SAAmB;IAEnB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AARD,4DAQC","sourcesContent":["import { map, reduce } from '@antv/util';\nimport { Data, Datum } from '../../types';\nimport { isRealNumber } from '../number';\n\n/**\n * 对数据进行百分比化\n * @param data\n * @param measure\n * @param groupField\n * @param as\n */\nexport function percent(data: Data, measure: string, groupField: string, as: string) {\n // 1. 先计算每一个分组的 max 值\n const sumMap = reduce(\n data,\n (map, datum: Datum) => {\n const groupValue = datum[groupField];\n let sum = map.has(groupValue) ? map.get(groupValue) : 0;\n\n const v = datum[measure];\n\n sum = isRealNumber(v) ? sum + v : sum;\n map.set(groupValue, sum);\n\n return map;\n },\n new Map<string, number>()\n );\n\n // 2. 循环数组,计算占比\n return map(data, (datum: Datum) => {\n const v = datum[measure];\n const groupValue = datum[groupField];\n const percentage = isRealNumber(v) && sumMap.get(groupValue) !== 0 ? v / sumMap.get(groupValue) : 0;\n\n return {\n ...datum,\n [as]: percentage,\n };\n });\n}\n\n/**\n * 对数据进行深层百分比化\n * @param data\n * @param measure // 数值\n * @param fields // 需要分组的 field值\n * @param as // 存储percent 百分比的值\n */\nexport function getDeepPercent(data: Record<string, any>[], measure: string, fields: string[], percent: string) {\n const sumMap = reduce(\n data,\n (map, datum: Datum) => {\n // 获取分组得到的枚举key值\n const groupValue = reduce(fields, (value, field) => `${value}${datum[field]}`, '');\n\n let sum = map.has(groupValue) ? map.get(groupValue) : 0;\n\n const v = datum[measure];\n\n sum = isRealNumber(v) ? sum + v : sum;\n map.set(groupValue, sum);\n\n return map;\n },\n new Map<string, number>()\n );\n\n // 2. 循环数组,计算占比\n return map(data, (datum: Datum) => {\n const v = datum[measure];\n // 获取分组得到的枚举key值\n const groupValue = reduce(fields, (value, field) => `${value}${datum[field]}`, '');\n\n const percentage = isRealNumber(v) && sumMap.get(groupValue) !== 0 ? v / sumMap.get(groupValue) : 0;\n\n return {\n ...datum,\n [percent]: percentage,\n };\n });\n}\n\n/**\n * 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)\n * @param isPercent 是否百分比\n */\nexport function getDataWhetherPercentage(\n data: Record<string, any>[],\n yField: string,\n groupField: string,\n asField: string,\n isPercent?: boolean\n) {\n return !isPercent ? data : percent(data, yField, groupField, asField);\n}\n"]}
|
package/package.json
CHANGED
package/src/adaptor/common.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Geometry } from '@antv/g2';
|
|
1
|
+
import { Geometry, Types } from '@antv/g2';
|
|
2
2
|
import { each, isNil, isObject } from '@antv/util';
|
|
3
3
|
import { Params } from '../core/adaptor';
|
|
4
4
|
import { Options } from '../types';
|
|
5
5
|
import { Interaction } from '../types/interaction';
|
|
6
|
+
import { Transformations } from '../types/coordinate';
|
|
6
7
|
import { Axis } from '../types/axis';
|
|
7
8
|
import { AXIS_META_CONFIG_KEYS } from '../constant';
|
|
8
9
|
import { pick, deepAssign } from '../utils';
|
|
@@ -207,4 +208,30 @@ export function limitInPlot(params: Params<Options>): Params<Options> {
|
|
|
207
208
|
return params;
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
/**
|
|
212
|
+
* 坐标系转换
|
|
213
|
+
*/
|
|
214
|
+
export function transformations(coordinateType: Types.CoordinateOption['type'] = 'rect') {
|
|
215
|
+
return (params: Params<Options & { coordinate: Transformations }>) => {
|
|
216
|
+
const { chart, options } = params;
|
|
217
|
+
const { coordinate } = options;
|
|
218
|
+
|
|
219
|
+
const actions: Types.CoordinateActions[] = Array.from(coordinate || [])
|
|
220
|
+
.map((cfg) => {
|
|
221
|
+
if (cfg.type === 'reflectX') return ['reflect', 'x'] as Types.CoordinateActions;
|
|
222
|
+
if (cfg.type === 'reflectY') return ['reflect', 'y'] as Types.CoordinateActions;
|
|
223
|
+
if (cfg.type === 'transpose') return ['transpose'] as Types.CoordinateActions;
|
|
224
|
+
|
|
225
|
+
return null;
|
|
226
|
+
})
|
|
227
|
+
.filter((d) => !!d);
|
|
228
|
+
|
|
229
|
+
if (actions.length !== 0) {
|
|
230
|
+
chart.coordinate({ type: coordinateType, actions });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return params;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
210
237
|
export { pattern } from './pattern';
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { Geometry } from '@antv/g2';
|
|
2
2
|
import { each, omit } from '@antv/util';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
tooltip,
|
|
5
|
+
slider,
|
|
6
|
+
interaction,
|
|
7
|
+
animation,
|
|
8
|
+
theme,
|
|
9
|
+
annotation,
|
|
10
|
+
limitInPlot,
|
|
11
|
+
pattern,
|
|
12
|
+
transformations,
|
|
13
|
+
} from '../../adaptor/common';
|
|
4
14
|
import { findGeometry } from '../../utils';
|
|
5
15
|
import { Params } from '../../core/adaptor';
|
|
6
16
|
import { area, point, line } from '../../adaptor/geometries';
|
|
7
17
|
import { flow, transformLabel, deepAssign } from '../../utils';
|
|
8
|
-
import {
|
|
18
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
9
19
|
import { Datum } from '../../types';
|
|
10
20
|
import { meta, legend, axis } from '../line/adaptor';
|
|
11
21
|
import { AreaOptions } from './types';
|
|
@@ -33,7 +43,7 @@ function geometry(params: Params<AreaOptions>): Params<AreaOptions> {
|
|
|
33
43
|
} = options;
|
|
34
44
|
const pointState = pointMapping?.state;
|
|
35
45
|
|
|
36
|
-
const chartData =
|
|
46
|
+
const chartData = getDataWhetherPercentage(data, yField, xField, yField, isPercent);
|
|
37
47
|
chart.data(chartData);
|
|
38
48
|
// 百分比堆积图,默认会给一个 % 格式化逻辑, 用户可自定义
|
|
39
49
|
const tooltipOptions = isPercent
|
|
@@ -149,6 +159,7 @@ export function adaptor(params: Params<AreaOptions>) {
|
|
|
149
159
|
return flow(
|
|
150
160
|
theme,
|
|
151
161
|
pattern('areaStyle'),
|
|
162
|
+
transformations('rect'),
|
|
152
163
|
geometry,
|
|
153
164
|
meta,
|
|
154
165
|
adjust,
|
package/src/plots/area/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plot } from '../../core/plot';
|
|
2
2
|
import { Adaptor } from '../../core/adaptor';
|
|
3
|
-
import {
|
|
3
|
+
import { getDataWhetherPercentage } from '../../utils/transform/percent';
|
|
4
4
|
import { AreaOptions } from './types';
|
|
5
5
|
import { adaptor, meta } from './adaptor';
|
|
6
6
|
import { DEFAULT_OPTIONS } from './constants';
|
|
@@ -35,7 +35,7 @@ export class Area extends Plot<AreaOptions> {
|
|
|
35
35
|
const { isPercent, xField, yField } = this.options;
|
|
36
36
|
const { chart, options } = this;
|
|
37
37
|
meta({ chart, options });
|
|
38
|
-
this.chart.changeData(
|
|
38
|
+
this.chart.changeData(getDataWhetherPercentage(data, yField, xField, yField, isPercent));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
package/src/plots/area/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GeometryOptions, LineGeometryOptions, PointGeometryOptions } from '../../adaptor/geometries';
|
|
2
2
|
import { Options, StyleAttr } from '../../types';
|
|
3
|
+
import { Transformations } from '../../types/coordinate';
|
|
3
4
|
|
|
4
5
|
/** 面积图的配置类型定义 */
|
|
5
6
|
export interface AreaOptions extends Options, Pick<GeometryOptions, 'customInfo'> {
|
|
@@ -48,4 +49,10 @@ export interface AreaOptions extends Options, Pick<GeometryOptions, 'customInfo'
|
|
|
48
49
|
* @default false
|
|
49
50
|
*/
|
|
50
51
|
readonly startOnZero?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @title 坐标转换
|
|
55
|
+
* @description 可以对坐标系进行转换,如: reflectX, reflectY, transpose 等
|
|
56
|
+
*/
|
|
57
|
+
readonly coordinate?: Transformations;
|
|
51
58
|
}
|
package/src/plots/bar/adaptor.ts
CHANGED
|
@@ -103,10 +103,10 @@ function legend(params: Params<BarOptions>): Params<BarOptions> {
|
|
|
103
103
|
* @param params
|
|
104
104
|
*/
|
|
105
105
|
function coordinate(params: Params<BarOptions>): Params<BarOptions> {
|
|
106
|
-
const { chart } = params;
|
|
107
106
|
// transpose column to bar 对角变换 & y 方向镜像变换
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
const { options } = params;
|
|
108
|
+
const coordinateOptions = [{ type: 'transpose' }, { type: 'reflectY' }].concat(options.coordinate || []);
|
|
109
|
+
return deepAssign({}, params, { options: { coordinate: coordinateOptions } });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|