@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":"types.js","sourceRoot":"","sources":["../../../src/plots/column/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ShapeAttrs } from '@antv/g2';\nimport { BrushCfg, Options, StyleAttr } from '../../types';\nimport { OptionWithConversionTag } from '../../adaptor/conversion-tag';\nimport { OptionWithConnectedArea } from '../../adaptor/connected-area';\nimport { IntervalGeometryOptions } from '../../adaptor/geometries/interval';\n\ntype PartialIntervalGeometryOptions = Pick<IntervalGeometryOptions, 'dodgePadding' | 'intervalPadding'>;\n\nexport interface ColumnOptions\n extends Options,\n OptionWithConversionTag,\n OptionWithConnectedArea,\n PartialIntervalGeometryOptions {\n /**\n * @title x轴字段\n */\n readonly xField: string;\n /**\n * @title y轴字段\n */\n readonly yField: string;\n /**\n * @title 拆分字段\n */\n readonly seriesField?: string;\n /**\n * @title 是否分组柱形图\n * @default false\n */\n readonly isGroup?: boolean;\n /**\n * @title 是否是区间柱状图\n * @default false\n */\n readonly isRange?: boolean;\n /**\n * @title 是否是百分比柱状图\n * @default false\n */\n readonly isPercent?: boolean;\n /**\n * @title 是否堆积柱状图\n * @default false\n */\n readonly isStack?: boolean;\n /**\n * @title 柱状图宽度占比\n * @description 范围[0-1]\n */\n readonly columnWidthRatio?: number;\n /**\n * @title 分组中柱子之间的间距\n * @description 范围[0-1],仅对分组柱状图适用\n */\n readonly marginRatio?: number;\n /**\n * @title 柱状图最小宽度(像素)\n */\n readonly minColumnWidth?: number;\n /**\n * @title 柱状图最大宽度(像素)\n */\n readonly maxColumnWidth?: number;\n /**\n * @title 柱状图柱子的背景\n */\n readonly columnBackground?: { style?: ShapeAttrs };\n /**\n * @title 柱子样式\n */\n readonly columnStyle?: StyleAttr;\n /**\n * @title 分组字段\n * @description 优先级高于 seriesField , isGroup: true 时会根据 groupField 进行分组\n */\n readonly groupField?: string;\n /**\n * @title 自定义柱状图\n * @description interval 图形元素展示形状\n */\n readonly shape?: string;\n /**\n * @title 图表交互\n * @description 开启下钻交互,以及进行下钻交互的配置\n */\n readonly brush?: BrushCfg;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/column/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ShapeAttrs } from '@antv/g2';\nimport { BrushCfg, Options, StyleAttr } from '../../types';\nimport { OptionWithConversionTag } from '../../adaptor/conversion-tag';\nimport { OptionWithConnectedArea } from '../../adaptor/connected-area';\nimport { IntervalGeometryOptions } from '../../adaptor/geometries/interval';\nimport { Transformations } from '../../types/coordinate';\n\ntype PartialIntervalGeometryOptions = Pick<IntervalGeometryOptions, 'dodgePadding' | 'intervalPadding'>;\n\nexport interface ColumnOptions\n extends Options,\n OptionWithConversionTag,\n OptionWithConnectedArea,\n PartialIntervalGeometryOptions {\n /**\n * @title x轴字段\n */\n readonly xField: string;\n /**\n * @title y轴字段\n */\n readonly yField: string;\n /**\n * @title 拆分字段\n */\n readonly seriesField?: string;\n /**\n * @title 是否分组柱形图\n * @default false\n */\n readonly isGroup?: boolean;\n /**\n * @title 是否是区间柱状图\n * @default false\n */\n readonly isRange?: boolean;\n /**\n * @title 是否是百分比柱状图\n * @default false\n */\n readonly isPercent?: boolean;\n /**\n * @title 是否堆积柱状图\n * @default false\n */\n readonly isStack?: boolean;\n /**\n * @title 柱状图宽度占比\n * @description 范围[0-1]\n */\n readonly columnWidthRatio?: number;\n /**\n * @title 分组中柱子之间的间距\n * @description 范围[0-1],仅对分组柱状图适用\n */\n readonly marginRatio?: number;\n /**\n * @title 柱状图最小宽度(像素)\n */\n readonly minColumnWidth?: number;\n /**\n * @title 柱状图最大宽度(像素)\n */\n readonly maxColumnWidth?: number;\n /**\n * @title 柱状图柱子的背景\n */\n readonly columnBackground?: { style?: ShapeAttrs };\n /**\n * @title 柱子样式\n */\n readonly columnStyle?: StyleAttr;\n /**\n * @title 分组字段\n * @description 优先级高于 seriesField , isGroup: true 时会根据 groupField 进行分组\n */\n readonly groupField?: string;\n /**\n * @title 自定义柱状图\n * @description interval 图形元素展示形状\n */\n readonly shape?: string;\n /**\n * @title 图表交互\n * @description 开启下钻交互,以及进行下钻交互的配置\n */\n readonly brush?: BrushCfg;\n\n /**\n * @title 坐标转换\n * @description 可以对坐标系进行转换,如: reflectX, reflectY, transpose 等\n */\n readonly coordinate?: Transformations;\n}\n"]}
|
package/esm/plots/mix/adaptor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
import { each } from '@antv/util';
|
|
3
3
|
import { geometry as geometryAdaptor } from '../../adaptor/geometries/base';
|
|
4
|
-
import { interaction, animation, theme, tooltip } from '../../adaptor/common';
|
|
4
|
+
import { interaction, animation, theme, tooltip, annotation } from '../../adaptor/common';
|
|
5
5
|
import { PLOT_CONTAINER_OPTIONS } from '../../core/plot';
|
|
6
6
|
import { AXIS_META_CONFIG_KEYS } from '../../constant';
|
|
7
7
|
import { deepAssign, flow, pick } from '../../utils';
|
|
@@ -102,19 +102,32 @@ function multiView(params) {
|
|
|
102
102
|
*/
|
|
103
103
|
function multiPlot(params) {
|
|
104
104
|
var chart = params.chart, options = params.options;
|
|
105
|
-
var plots = options.plots;
|
|
105
|
+
var plots = options.plots, _a = options.data, data = _a === void 0 ? [] : _a;
|
|
106
106
|
each(plots, function (plot) {
|
|
107
|
-
var type = plot.type, region = plot.region, _a = plot.options, options = _a === void 0 ? {} : _a;
|
|
107
|
+
var type = plot.type, region = plot.region, _a = plot.options, options = _a === void 0 ? {} : _a, top = plot.top;
|
|
108
108
|
var tooltip = options.tooltip;
|
|
109
|
+
if (top) {
|
|
110
|
+
execPlotAdaptor(type, chart, __assign(__assign({}, options), { data: data }));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
109
113
|
var viewOfG2 = chart.createView(__assign({ region: region }, pick(options, PLOT_CONTAINER_OPTIONS)));
|
|
110
114
|
if (tooltip) {
|
|
111
115
|
// 配置 tooltip 交互
|
|
112
116
|
viewOfG2.interaction('tooltip');
|
|
113
117
|
}
|
|
114
|
-
execPlotAdaptor(type, viewOfG2, options);
|
|
118
|
+
execPlotAdaptor(type, viewOfG2, __assign({ data: data }, options));
|
|
115
119
|
});
|
|
116
120
|
return params;
|
|
117
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 处理缩略轴的 adaptor (mix)
|
|
124
|
+
* @param params
|
|
125
|
+
*/
|
|
126
|
+
export function slider(params) {
|
|
127
|
+
var chart = params.chart, options = params.options;
|
|
128
|
+
chart.option('slider', options.slider);
|
|
129
|
+
return params;
|
|
130
|
+
}
|
|
118
131
|
/**
|
|
119
132
|
* 图适配器
|
|
120
133
|
* @param chart
|
|
@@ -122,7 +135,7 @@ function multiPlot(params) {
|
|
|
122
135
|
*/
|
|
123
136
|
export function adaptor(params) {
|
|
124
137
|
return flow(animation, // 多 view 的图,动画配置放到最前面
|
|
125
|
-
multiView, multiPlot, interaction, animation, theme, tooltip
|
|
138
|
+
multiView, multiPlot, interaction, animation, theme, tooltip, slider, annotation()
|
|
126
139
|
// ... 其他的 adaptor flow
|
|
127
140
|
)(params);
|
|
128
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/mix/adaptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3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Z,CAAC","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/esm/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/esm/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/esm/plots/mix/utils.js
CHANGED
|
@@ -8,12 +8,13 @@ import { adaptor as areaAdaptor } from '../area/adaptor';
|
|
|
8
8
|
import { adaptor as gaugeAdaptor } from '../gauge/adaptor';
|
|
9
9
|
import { adaptor as tinyLineAdaptor } from '../tiny-line/adaptor';
|
|
10
10
|
import { adaptor as tinyColumnAdaptor } from '../tiny-column/adaptor';
|
|
11
|
-
import { adaptor as
|
|
11
|
+
import { adaptor as tinyAreaAdaptor } from '../tiny-area/adaptor';
|
|
12
12
|
import { adaptor as ringProgressAdaptor } from '../ring-progress/adaptor';
|
|
13
13
|
import { adaptor as progressAdaptor } from '../progress/adaptor';
|
|
14
14
|
import { adaptor as scatterAdaptor } from '../scatter/adaptor';
|
|
15
15
|
import { adaptor as histogramAdaptor } from '../histogram/adaptor';
|
|
16
16
|
import { adaptor as funnelAdaptor } from '../funnel/adaptor';
|
|
17
|
+
import { adaptor as stockAdaptor } from '../stock/adaptor';
|
|
17
18
|
import { Line } from '../line';
|
|
18
19
|
import { Pie } from '../pie';
|
|
19
20
|
import { Bar } from '../bar';
|
|
@@ -28,6 +29,7 @@ import { Progress } from '../progress';
|
|
|
28
29
|
import { Scatter } from '../scatter';
|
|
29
30
|
import { Histogram } from '../histogram';
|
|
30
31
|
import { Funnel } from '../funnel';
|
|
32
|
+
import { Stock } from '../stock';
|
|
31
33
|
/**
|
|
32
34
|
* 可在 multi-view 中使用的 plots
|
|
33
35
|
*/
|
|
@@ -40,12 +42,13 @@ var PLOT_ADAPTORS = {
|
|
|
40
42
|
gauge: gaugeAdaptor,
|
|
41
43
|
'tiny-line': tinyLineAdaptor,
|
|
42
44
|
'tiny-column': tinyColumnAdaptor,
|
|
43
|
-
'tiny-area':
|
|
45
|
+
'tiny-area': tinyAreaAdaptor,
|
|
44
46
|
'ring-progress': ringProgressAdaptor,
|
|
45
47
|
progress: progressAdaptor,
|
|
46
48
|
scatter: scatterAdaptor,
|
|
47
49
|
histogram: histogramAdaptor,
|
|
48
50
|
funnel: funnelAdaptor,
|
|
51
|
+
stock: stockAdaptor,
|
|
49
52
|
};
|
|
50
53
|
/**
|
|
51
54
|
* 获取指定 plot 的 class contructor
|
|
@@ -66,6 +69,7 @@ var PLOT_CONSTRUCTOR = {
|
|
|
66
69
|
scatter: Scatter,
|
|
67
70
|
histogram: Histogram,
|
|
68
71
|
funnel: Funnel,
|
|
72
|
+
stock: Stock,
|
|
69
73
|
};
|
|
70
74
|
/**
|
|
71
75
|
* 在 mix 图表以及 facet 图表中,defaultOptions 进行复写简化
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/mix/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/plots/mix/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,WAAW,E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AAK,EAAE,EAAE;CACzC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,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,UAAU,CAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC;KAC9F,CAAC,CAAC;AACL,CAAC","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/esm/plots/pie/adaptor.js
CHANGED
|
@@ -124,7 +124,7 @@ function label(params) {
|
|
|
124
124
|
var angleScale = chart.getScaleByField(angleField);
|
|
125
125
|
var percent = angleScale === null || angleScale === void 0 ? void 0 : angleScale.scale(value);
|
|
126
126
|
return isFunction(content_1)
|
|
127
|
-
? // append
|
|
127
|
+
? // append percent (number) to data, users can get origin data from `dataum._origin`
|
|
128
128
|
content_1(__assign(__assign({}, data), { percent: percent }), dataum, index)
|
|
129
129
|
: isString(content_1)
|
|
130
130
|
? template(content_1, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/pie/adaptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1G,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9G,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAA0B;IAClC,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,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,EACL,KAAK;IACL,mBAAmB;IACnB,aAAa,EACb,WAAW,EACX,SAAS,CACV,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC","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}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,CAAC,GAAG,0CAAE,KAAK,CAAA,EAAE;gBACjB,aAAW,GAAG;oBACZ;wBACE,OAAO,EAAE,oBAAoB;wBAC7B,MAAM,EAAK,aAAa,YAAS;wBACjC,GAAG,EAAE,EAAE,SAAS,WAAA,EAAE,WAAW,aAAA,EAAE;qBAChC;iBACF,CAAC;aACH;YACD,IAAI,OAAC,CAAC,CAAC,GAAG,0CAAE,KAAK,EAAE,UAAC,KAAK;gBACvB,aAAW,CAAC,IAAI,uBAAM,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,UAAU,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;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,MAA0B;IAChD,0BAA0B;IAC1B,OAAO,IAAI,CACT,OAAO,CAAC,UAAU,CAAC,EACnB,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,UAAU,EACV,MAAM,EACN,OAAO,EACP,KAAK,EACL,KAAK;IACL,mBAAmB;IACnB,aAAa,EACb,WAAW,EACX,SAAS,CACV,CAAC,MAAM,CAAC,CAAC;AACZ,CAAC","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
|
+
//# sourceMappingURL=coordinate.js.map
|
|
@@ -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>[];
|
|
@@ -58,7 +58,7 @@ export function getDeepPercent(data, measure, fields, percent) {
|
|
|
58
58
|
* 获取数据,如果是百分比,进行数据转换 (适用于面积图、柱状图、条形图)
|
|
59
59
|
* @param isPercent 是否百分比
|
|
60
60
|
*/
|
|
61
|
-
export function
|
|
61
|
+
export function getDataWhetherPercentage(data, yField, groupField, asField, isPercent) {
|
|
62
62
|
return !isPercent ? data : percent(data, yField, groupField, asField);
|
|
63
63
|
}
|
|
64
64
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.js","sourceRoot":"","sources":["../../../src/utils/transform/percent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,IAAU,EAAE,OAAe,EAAE,UAAkB,EAAE,EAAU;IACj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AAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpG,6BACK,KAAK,gBACP,OAAO,IAAG,UAAU,OACrB;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,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","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/lib/adaptor/common.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Types } from '@antv/g2';
|
|
1
2
|
import { Params } from '../core/adaptor';
|
|
2
3
|
import { Options } from '../types';
|
|
4
|
+
import { Transformations } from '../types/coordinate';
|
|
3
5
|
import { Axis } from '../types/axis';
|
|
4
6
|
/**
|
|
5
7
|
* 通用 legend 配置, 适用于带 colorField 或 seriesField 的图表
|
|
@@ -59,4 +61,12 @@ export declare function annotation(annotationOptions?: Options['annotations']):
|
|
|
59
61
|
* @param params
|
|
60
62
|
*/
|
|
61
63
|
export declare function limitInPlot(params: Params<Options>): Params<Options>;
|
|
64
|
+
/**
|
|
65
|
+
* 坐标系转换
|
|
66
|
+
*/
|
|
67
|
+
export declare function transformations(coordinateType?: Types.CoordinateOption['type']): (params: Params<Options & {
|
|
68
|
+
coordinate: Transformations;
|
|
69
|
+
}>) => Params<Options & {
|
|
70
|
+
coordinate: Transformations;
|
|
71
|
+
}>;
|
|
62
72
|
export { pattern } from './pattern';
|
package/lib/adaptor/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.limitInPlot = exports.annotation = exports.scale = exports.scrollbar = exports.slider = exports.state = exports.theme = exports.animation = exports.interaction = exports.tooltip = exports.legend = void 0;
|
|
3
|
+
exports.transformations = exports.limitInPlot = exports.annotation = exports.scale = exports.scrollbar = exports.slider = exports.state = exports.theme = exports.animation = exports.interaction = exports.tooltip = exports.legend = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var util_1 = require("@antv/util");
|
|
6
6
|
var constant_1 = require("../constant");
|
|
@@ -181,6 +181,32 @@ function limitInPlot(params) {
|
|
|
181
181
|
return params;
|
|
182
182
|
}
|
|
183
183
|
exports.limitInPlot = limitInPlot;
|
|
184
|
+
/**
|
|
185
|
+
* 坐标系转换
|
|
186
|
+
*/
|
|
187
|
+
function transformations(coordinateType) {
|
|
188
|
+
if (coordinateType === void 0) { coordinateType = 'rect'; }
|
|
189
|
+
return function (params) {
|
|
190
|
+
var chart = params.chart, options = params.options;
|
|
191
|
+
var coordinate = options.coordinate;
|
|
192
|
+
var actions = Array.from(coordinate || [])
|
|
193
|
+
.map(function (cfg) {
|
|
194
|
+
if (cfg.type === 'reflectX')
|
|
195
|
+
return ['reflect', 'x'];
|
|
196
|
+
if (cfg.type === 'reflectY')
|
|
197
|
+
return ['reflect', 'y'];
|
|
198
|
+
if (cfg.type === 'transpose')
|
|
199
|
+
return ['transpose'];
|
|
200
|
+
return null;
|
|
201
|
+
})
|
|
202
|
+
.filter(function (d) { return !!d; });
|
|
203
|
+
if (actions.length !== 0) {
|
|
204
|
+
chart.coordinate({ type: coordinateType, actions: actions });
|
|
205
|
+
}
|
|
206
|
+
return params;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
exports.transformations = transformations;
|
|
184
210
|
var pattern_1 = require("./pattern");
|
|
185
211
|
Object.defineProperty(exports, "pattern", { enumerable: true, get: function () { return pattern_1.pattern; } });
|
|
186
212
|
//# sourceMappingURL=common.js.map
|