@antv/g2plot 2.4.19 → 2.4.22
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 +1626 -0
- package/README.en-US.md +2 -2
- package/README.md +2 -2
- package/dist/g2plot.min.js +2 -2
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/brush.js +2 -3
- package/esm/adaptor/brush.js.map +1 -1
- package/esm/adaptor/common.js +2 -11
- package/esm/adaptor/common.js.map +1 -1
- package/esm/adaptor/geometries/base.d.ts +2 -2
- package/esm/adaptor/geometries/base.js +3 -1
- package/esm/adaptor/geometries/base.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interactions/brush.d.ts +18 -6
- package/esm/interactions/brush.js +35 -25
- package/esm/interactions/brush.js.map +1 -1
- package/esm/plots/box/adaptor.js +2 -2
- package/esm/plots/box/adaptor.js.map +1 -1
- package/esm/plots/chord/adaptor.js +2 -13
- package/esm/plots/chord/adaptor.js.map +1 -1
- package/esm/plots/chord/constant.d.ts +4 -4
- package/esm/plots/chord/constant.js +4 -4
- package/esm/plots/chord/constant.js.map +1 -1
- package/esm/plots/column/adaptor.js +3 -1
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/facet/types.d.ts +1 -2
- package/esm/plots/facet/types.js.map +1 -1
- package/esm/plots/facet/utils.js +2 -11
- package/esm/plots/facet/utils.js.map +1 -1
- package/esm/plots/funnel/adaptor.d.ts +5 -0
- package/esm/plots/funnel/adaptor.js +31 -2
- package/esm/plots/funnel/adaptor.js.map +1 -1
- package/esm/plots/funnel/geometries/basic.d.ts +5 -0
- package/esm/plots/funnel/geometries/basic.js +8 -4
- package/esm/plots/funnel/geometries/basic.js.map +1 -1
- package/esm/plots/funnel/geometries/common.d.ts +1 -0
- package/esm/plots/funnel/geometries/common.js +5 -2
- package/esm/plots/funnel/geometries/common.js.map +1 -1
- package/esm/plots/funnel/geometries/compare.d.ts +1 -0
- package/esm/plots/funnel/geometries/compare.js +37 -30
- package/esm/plots/funnel/geometries/compare.js.map +1 -1
- package/esm/plots/funnel/index.d.ts +1 -0
- package/esm/plots/funnel/index.js +1 -0
- package/esm/plots/funnel/index.js.map +1 -1
- package/esm/plots/funnel/interactions/funnel-conversion-tag.d.ts +9 -0
- package/esm/plots/funnel/interactions/funnel-conversion-tag.js +57 -0
- package/esm/plots/funnel/interactions/funnel-conversion-tag.js.map +1 -0
- package/esm/plots/funnel/interactions/index.d.ts +5 -0
- package/esm/plots/funnel/interactions/index.js +10 -0
- package/esm/plots/funnel/interactions/index.js.map +1 -0
- package/esm/plots/funnel/types.d.ts +1 -0
- package/esm/plots/funnel/types.js.map +1 -1
- package/esm/plots/gauge/utils.js +6 -5
- package/esm/plots/gauge/utils.js.map +1 -1
- package/esm/plots/heatmap/adaptor.js +9 -11
- package/esm/plots/heatmap/adaptor.js.map +1 -1
- package/esm/plots/histogram/adaptor.js +3 -0
- package/esm/plots/histogram/adaptor.js.map +1 -1
- package/esm/plots/pie/adaptor.js +3 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/plots/pie/types.d.ts +6 -1
- package/esm/plots/pie/types.js.map +1 -1
- package/esm/plots/progress/adaptor.js +1 -2
- package/esm/plots/progress/adaptor.js.map +1 -1
- package/esm/plots/progress/utils.d.ts +1 -0
- package/esm/plots/progress/utils.js +4 -1
- package/esm/plots/progress/utils.js.map +1 -1
- package/esm/plots/sankey/adaptor.js +2 -11
- package/esm/plots/sankey/adaptor.js.map +1 -1
- package/esm/plots/stock/utils.d.ts +3 -1
- package/esm/plots/stock/utils.js +4 -2
- package/esm/plots/stock/utils.js.map +1 -1
- package/esm/plots/violin/adaptor.js +2 -10
- package/esm/plots/violin/adaptor.js.map +1 -1
- package/esm/types/common.d.ts +4 -3
- package/esm/types/common.js.map +1 -1
- package/esm/types/interaction.d.ts +5 -0
- package/esm/types/interaction.js.map +1 -1
- package/esm/utils/conversion.js +4 -3
- package/esm/utils/conversion.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/view.d.ts +8 -1
- package/esm/utils/view.js +27 -0
- package/esm/utils/view.js.map +1 -1
- package/lib/adaptor/brush.js +2 -3
- package/lib/adaptor/brush.js.map +1 -1
- package/lib/adaptor/common.js +1 -10
- package/lib/adaptor/common.js.map +1 -1
- package/lib/adaptor/geometries/base.d.ts +2 -2
- package/lib/adaptor/geometries/base.js +3 -1
- package/lib/adaptor/geometries/base.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interactions/brush.d.ts +18 -6
- package/lib/interactions/brush.js +35 -25
- package/lib/interactions/brush.js.map +1 -1
- package/lib/plots/box/adaptor.js +1 -1
- package/lib/plots/box/adaptor.js.map +1 -1
- package/lib/plots/chord/adaptor.js +1 -12
- package/lib/plots/chord/adaptor.js.map +1 -1
- package/lib/plots/chord/constant.d.ts +4 -4
- package/lib/plots/chord/constant.js +4 -4
- package/lib/plots/chord/constant.js.map +1 -1
- package/lib/plots/column/adaptor.js +3 -1
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/facet/types.d.ts +1 -2
- package/lib/plots/facet/types.js.map +1 -1
- package/lib/plots/facet/utils.js +1 -10
- package/lib/plots/facet/utils.js.map +1 -1
- package/lib/plots/funnel/adaptor.d.ts +5 -0
- package/lib/plots/funnel/adaptor.js +32 -2
- package/lib/plots/funnel/adaptor.js.map +1 -1
- package/lib/plots/funnel/geometries/basic.d.ts +5 -0
- package/lib/plots/funnel/geometries/basic.js +8 -3
- package/lib/plots/funnel/geometries/basic.js.map +1 -1
- package/lib/plots/funnel/geometries/common.d.ts +1 -0
- package/lib/plots/funnel/geometries/common.js +6 -3
- package/lib/plots/funnel/geometries/common.js.map +1 -1
- package/lib/plots/funnel/geometries/compare.d.ts +1 -0
- package/lib/plots/funnel/geometries/compare.js +38 -30
- package/lib/plots/funnel/geometries/compare.js.map +1 -1
- package/lib/plots/funnel/index.d.ts +1 -0
- package/lib/plots/funnel/index.js +1 -0
- package/lib/plots/funnel/index.js.map +1 -1
- package/lib/plots/funnel/interactions/funnel-conversion-tag.d.ts +9 -0
- package/lib/plots/funnel/interactions/funnel-conversion-tag.js +60 -0
- package/lib/plots/funnel/interactions/funnel-conversion-tag.js.map +1 -0
- package/lib/plots/funnel/interactions/index.d.ts +5 -0
- package/lib/plots/funnel/interactions/index.js +13 -0
- package/lib/plots/funnel/interactions/index.js.map +1 -0
- package/lib/plots/funnel/types.d.ts +1 -0
- package/lib/plots/funnel/types.js.map +1 -1
- package/lib/plots/gauge/utils.js +5 -4
- package/lib/plots/gauge/utils.js.map +1 -1
- package/lib/plots/heatmap/adaptor.js +8 -10
- package/lib/plots/heatmap/adaptor.js.map +1 -1
- package/lib/plots/histogram/adaptor.js +3 -0
- package/lib/plots/histogram/adaptor.js.map +1 -1
- package/lib/plots/pie/adaptor.js +3 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/plots/pie/types.d.ts +6 -1
- package/lib/plots/pie/types.js.map +1 -1
- package/lib/plots/progress/adaptor.js +1 -2
- package/lib/plots/progress/adaptor.js.map +1 -1
- package/lib/plots/progress/utils.d.ts +1 -0
- package/lib/plots/progress/utils.js +4 -1
- package/lib/plots/progress/utils.js.map +1 -1
- package/lib/plots/sankey/adaptor.js +2 -11
- package/lib/plots/sankey/adaptor.js.map +1 -1
- package/lib/plots/stock/utils.d.ts +3 -1
- package/lib/plots/stock/utils.js +4 -2
- package/lib/plots/stock/utils.js.map +1 -1
- package/lib/plots/violin/adaptor.js +2 -10
- package/lib/plots/violin/adaptor.js.map +1 -1
- package/lib/types/common.d.ts +4 -3
- package/lib/types/common.js.map +1 -1
- package/lib/types/interaction.d.ts +5 -0
- package/lib/types/interaction.js.map +1 -1
- package/lib/utils/conversion.js +4 -3
- package/lib/utils/conversion.js.map +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/view.d.ts +8 -1
- package/lib/utils/view.js +29 -1
- package/lib/utils/view.js.map +1 -1
- package/package.json +4 -2
- package/src/adaptor/brush.ts +2 -2
- package/src/adaptor/common.ts +2 -11
- package/src/adaptor/geometries/base.ts +5 -3
- package/src/index.ts +1 -1
- package/src/interactions/brush.ts +38 -25
- package/src/plots/box/adaptor.ts +2 -2
- package/src/plots/chord/adaptor.ts +2 -14
- package/src/plots/chord/constant.ts +4 -4
- package/src/plots/column/adaptor.ts +3 -1
- package/src/plots/facet/types.ts +1 -1
- package/src/plots/facet/utils.ts +4 -12
- package/src/plots/funnel/adaptor.ts +32 -2
- package/src/plots/funnel/geometries/basic.ts +10 -5
- package/src/plots/funnel/geometries/common.ts +6 -3
- package/src/plots/funnel/geometries/compare.ts +50 -41
- package/src/plots/funnel/index.ts +1 -0
- package/src/plots/funnel/interactions/funnel-conversion-tag.ts +57 -0
- package/src/plots/funnel/interactions/index.ts +11 -0
- package/src/plots/funnel/types.ts +1 -0
- package/src/plots/gauge/utils.ts +5 -4
- package/src/plots/heatmap/adaptor.ts +10 -11
- package/src/plots/histogram/adaptor.ts +2 -0
- package/src/plots/pie/adaptor.ts +3 -1
- package/src/plots/pie/types.ts +6 -1
- package/src/plots/progress/adaptor.ts +1 -2
- package/src/plots/progress/utils.ts +4 -1
- package/src/plots/sankey/adaptor.ts +2 -11
- package/src/plots/stock/utils.ts +4 -3
- package/src/plots/violin/adaptor.ts +2 -11
- package/src/types/common.ts +5 -3
- package/src/types/interaction.ts +6 -0
- package/src/utils/conversion.ts +6 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/view.ts +34 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Types } from '@antv/g2';
|
|
2
|
-
import { isArray } from '@antv/util';
|
|
2
|
+
import { isArray, isNumber, get, map } from '@antv/util';
|
|
3
3
|
import { flow, deepAssign } from '../../../utils';
|
|
4
4
|
import { Params } from '../../../core/adaptor';
|
|
5
5
|
import { Datum, Data } from '../../../types/common';
|
|
@@ -114,52 +114,61 @@ function geometry(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
|
114
114
|
return params;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
export function compareConversionTag(params: Params<FunnelOptions>) {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
const { chart, index, options } = params;
|
|
120
|
+
const { conversionTag, isTransposed } = options;
|
|
121
|
+
(isNumber(index) ? [chart] : chart.views).forEach((view, viewIndex) => {
|
|
122
|
+
// 获取形状位置,再转化为需要的转化率位置
|
|
123
|
+
const dataArray = get(view, ['geometries', '0', 'dataArray'], []);
|
|
124
|
+
const size = get(view, ['options', 'data', 'length']);
|
|
125
|
+
const x = map(dataArray, (item) => get(item, ['0', 'nextPoints', '0', 'x']) * size - 0.5);
|
|
126
|
+
|
|
127
|
+
const getLineCoordinate = (
|
|
128
|
+
datum: Datum,
|
|
129
|
+
datumIndex: number,
|
|
130
|
+
data: Data,
|
|
131
|
+
initLineOption: Record<string, any>
|
|
132
|
+
): Types.LineOption => {
|
|
133
|
+
const ratio = (index || viewIndex) === 0 ? -1 : 1;
|
|
134
|
+
return deepAssign({}, initLineOption, {
|
|
135
|
+
start: [x[datumIndex - 1] || datumIndex - 0.5, datum[FUNNEL_MAPPING_VALUE]],
|
|
136
|
+
end: [x[datumIndex - 1] || datumIndex - 0.5, datum[FUNNEL_MAPPING_VALUE] + 0.05],
|
|
137
|
+
text: isTransposed
|
|
138
|
+
? {
|
|
139
|
+
style: {
|
|
140
|
+
textAlign: 'start',
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
: {
|
|
144
|
+
offsetX: conversionTag !== false ? ratio * conversionTag.offsetX : 0,
|
|
145
|
+
style: {
|
|
146
|
+
textAlign: (index || viewIndex) === 0 ? 'end' : 'start',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
conversionTagComponent(getLineCoordinate)(
|
|
153
|
+
deepAssign(
|
|
154
|
+
{},
|
|
155
|
+
{
|
|
156
|
+
chart: view,
|
|
157
|
+
options,
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
117
164
|
/**
|
|
118
165
|
* 转化率组件
|
|
119
166
|
* @param params
|
|
120
167
|
*/
|
|
121
168
|
function conversionTag(params: Params<FunnelOptions>): Params<FunnelOptions> {
|
|
122
|
-
const { chart
|
|
123
|
-
const { conversionTag, isTransposed } = options;
|
|
169
|
+
const { chart } = params;
|
|
124
170
|
// @ts-ignore
|
|
125
|
-
chart.once('beforepaint', () =>
|
|
126
|
-
chart.views.forEach((view, viewIndex) => {
|
|
127
|
-
const getLineCoordinate = (
|
|
128
|
-
datum: Datum,
|
|
129
|
-
datumIndex: number,
|
|
130
|
-
data: Data,
|
|
131
|
-
initLineOption: Record<string, any>
|
|
132
|
-
): Types.LineOption => {
|
|
133
|
-
const ratio = viewIndex === 0 ? -1 : 1;
|
|
134
|
-
return deepAssign({}, initLineOption, {
|
|
135
|
-
start: [datumIndex - 0.5, datum[FUNNEL_MAPPING_VALUE]],
|
|
136
|
-
end: [datumIndex - 0.5, datum[FUNNEL_MAPPING_VALUE] + 0.05],
|
|
137
|
-
text: isTransposed
|
|
138
|
-
? {
|
|
139
|
-
style: {
|
|
140
|
-
textAlign: 'start',
|
|
141
|
-
},
|
|
142
|
-
}
|
|
143
|
-
: {
|
|
144
|
-
offsetX: conversionTag !== false ? ratio * conversionTag.offsetX : 0,
|
|
145
|
-
style: {
|
|
146
|
-
textAlign: viewIndex === 0 ? 'end' : 'start',
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
conversionTagComponent(getLineCoordinate)(
|
|
153
|
-
deepAssign(
|
|
154
|
-
{},
|
|
155
|
-
{
|
|
156
|
-
chart: view,
|
|
157
|
-
options,
|
|
158
|
-
}
|
|
159
|
-
)
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
171
|
+
chart.once('beforepaint', () => compareConversionTag(params));
|
|
163
172
|
return params;
|
|
164
173
|
}
|
|
165
174
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { get, map, filter, each } from '@antv/util';
|
|
2
|
+
import { Action } from '@antv/g2';
|
|
3
|
+
import { conversionTag as basicConversionTag } from '../geometries/basic';
|
|
4
|
+
import { compareConversionTag } from '../geometries/compare';
|
|
5
|
+
import { transformData, CONVERSION_TAG_NAME } from '../geometries/common';
|
|
6
|
+
import { FunnelOptions } from '../types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Funnel 转化率跟随 legend 变化事件
|
|
10
|
+
*/
|
|
11
|
+
export class ConversionTagAction extends Action {
|
|
12
|
+
private rendering = false;
|
|
13
|
+
public change(options: FunnelOptions) {
|
|
14
|
+
// 防止多次重复渲染
|
|
15
|
+
if (!this.rendering) {
|
|
16
|
+
const { seriesField, compareField } = options;
|
|
17
|
+
const conversionTag = compareField ? compareConversionTag : basicConversionTag;
|
|
18
|
+
const { view } = this.context;
|
|
19
|
+
// 兼容分面漏斗图
|
|
20
|
+
const views = seriesField || compareField ? view.views : [view];
|
|
21
|
+
map(views, (v, index) => {
|
|
22
|
+
// 防止影响其他 annotations 被去除
|
|
23
|
+
const annotationController = v.getController('annotation');
|
|
24
|
+
|
|
25
|
+
const annotations = filter(
|
|
26
|
+
get(annotationController, ['option'], []),
|
|
27
|
+
({ name }) => name !== CONVERSION_TAG_NAME
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
annotationController.clear(true);
|
|
31
|
+
|
|
32
|
+
each(annotations, (annotation) => {
|
|
33
|
+
if (typeof annotation === 'object') {
|
|
34
|
+
v.annotation()[annotation.type](annotation);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const data = get(v, ['filteredData'], v.getOptions().data);
|
|
39
|
+
|
|
40
|
+
conversionTag({
|
|
41
|
+
chart: v,
|
|
42
|
+
index,
|
|
43
|
+
options: {
|
|
44
|
+
...options,
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
filteredData: transformData(data, data, options),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
v.filterData(data);
|
|
51
|
+
this.rendering = true;
|
|
52
|
+
v.render(true);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
this.rendering = false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { registerAction, registerInteraction } from '@antv/g2';
|
|
2
|
+
import { ConversionTagAction } from './funnel-conversion-tag';
|
|
3
|
+
|
|
4
|
+
const FUNNEL_CONVERSION_TAG = 'funnel-conversion-tag';
|
|
5
|
+
export const FUNNEL_LEGEND_FILTER = 'funnel-afterrender';
|
|
6
|
+
export const interactionStart = { trigger: 'afterrender', action: `${FUNNEL_CONVERSION_TAG}:change` };
|
|
7
|
+
|
|
8
|
+
registerAction(FUNNEL_CONVERSION_TAG, ConversionTagAction);
|
|
9
|
+
registerInteraction(FUNNEL_LEGEND_FILTER, {
|
|
10
|
+
start: [interactionStart],
|
|
11
|
+
});
|
package/src/plots/gauge/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clamp, get, size } from '@antv/util';
|
|
1
|
+
import { clamp, get, size, uniq } from '@antv/util';
|
|
2
2
|
import { Data, Datum } from '../../types';
|
|
3
3
|
import { RANGE_VALUE, RANGE_TYPE, PERCENT } from './constants';
|
|
4
4
|
import { GaugeOptions, GaugeRangeData } from './types';
|
|
@@ -16,8 +16,6 @@ export function processRangeData(range: number[], percent: GaugeOptions['percent
|
|
|
16
16
|
.map((r: number, idx: number) => {
|
|
17
17
|
return { [RANGE_VALUE]: r - (range[idx - 1] || 0), [RANGE_TYPE]: `${idx}`, [PERCENT]: percent };
|
|
18
18
|
})
|
|
19
|
-
// 去掉 0 的数据
|
|
20
|
-
.filter((d: Datum) => !!d[RANGE_VALUE])
|
|
21
19
|
);
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -37,6 +35,9 @@ export function getIndicatorData(percent: GaugeOptions['percent']): Data {
|
|
|
37
35
|
export function getRangeData(percent: GaugeOptions['percent'], range?: GaugeOptions['range']): GaugeRangeData {
|
|
38
36
|
const ticks = get(range, ['ticks'], []);
|
|
39
37
|
|
|
40
|
-
const clampTicks = size(ticks) ? ticks : [0, clamp(percent, 0, 1), 1];
|
|
38
|
+
const clampTicks = size(ticks) ? uniq(ticks) : [0, clamp(percent, 0, 1), 1];
|
|
39
|
+
if (!clampTicks[0]) {
|
|
40
|
+
clampTicks.shift();
|
|
41
|
+
}
|
|
41
42
|
return processRangeData(clampTicks as number[], percent);
|
|
42
43
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { get } from '@antv/util';
|
|
1
|
+
import { get, isNumber } from '@antv/util';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { deepAssign, findGeometry } from '../../utils';
|
|
4
4
|
import { flow, transformLabel } from '../../utils';
|
|
@@ -9,7 +9,8 @@ import { HeatmapOptions } from './types';
|
|
|
9
9
|
|
|
10
10
|
function geometry(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
|
|
11
11
|
const { chart, options } = params;
|
|
12
|
-
const { data, type, xField, yField, colorField, sizeField, sizeRatio, shape, color, tooltip, heatmapStyle } =
|
|
12
|
+
const { data, type, xField, yField, colorField, sizeField, sizeRatio, shape, color, tooltip, heatmapStyle, meta } =
|
|
13
|
+
options;
|
|
13
14
|
|
|
14
15
|
chart.data(data);
|
|
15
16
|
let geometryType = 'polygon';
|
|
@@ -51,8 +52,9 @@ function geometry(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
|
|
|
51
52
|
(sizeField
|
|
52
53
|
? (dautm) => {
|
|
53
54
|
const field = data.map((row) => row[sizeField]);
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
let { min, max } = meta?.[sizeField] || {};
|
|
56
|
+
min = isNumber(min) ? min : Math.min(...field);
|
|
57
|
+
max = isNumber(max) ? max : Math.max(...field);
|
|
56
58
|
return [shape, (get(dautm, sizeField) - min) / (max - min), checkedSizeRatio];
|
|
57
59
|
}
|
|
58
60
|
: () => [shape, 1, checkedSizeRatio]),
|
|
@@ -167,17 +169,14 @@ function coordinate(params: Params<HeatmapOptions>): Params<HeatmapOptions> {
|
|
|
167
169
|
const { chart, options } = params;
|
|
168
170
|
const { coordinate, reflect } = options;
|
|
169
171
|
|
|
170
|
-
|
|
171
|
-
chart.coordinate({
|
|
172
|
-
type: coordinate.type || 'rect',
|
|
173
|
-
cfg: coordinate.cfg,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
172
|
+
const coordinateOption = deepAssign({ actions: [] }, coordinate ?? { type: 'rect' });
|
|
176
173
|
|
|
177
174
|
if (reflect) {
|
|
178
|
-
|
|
175
|
+
coordinateOption.actions?.push?.(['reflect', reflect]);
|
|
179
176
|
}
|
|
180
177
|
|
|
178
|
+
chart.coordinate(coordinateOption);
|
|
179
|
+
|
|
181
180
|
return params;
|
|
182
181
|
}
|
|
183
182
|
|
package/src/plots/pie/adaptor.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { PieOptions } from './types';
|
|
|
19
19
|
*/
|
|
20
20
|
function geometry(params: Params<PieOptions>): Params<PieOptions> {
|
|
21
21
|
const { chart, options } = params;
|
|
22
|
-
const { data, angleField, colorField, color, pieStyle } = options;
|
|
22
|
+
const { data, angleField, colorField, color, pieStyle, shape } = options;
|
|
23
23
|
|
|
24
24
|
// 处理不合法的数据
|
|
25
25
|
let processData = processIllegalData(data, angleField);
|
|
@@ -38,6 +38,7 @@ function geometry(params: Params<PieOptions>): Params<PieOptions> {
|
|
|
38
38
|
isStack: true,
|
|
39
39
|
interval: {
|
|
40
40
|
color,
|
|
41
|
+
shape,
|
|
41
42
|
style: pieStyle,
|
|
42
43
|
},
|
|
43
44
|
args: {
|
|
@@ -59,6 +60,7 @@ function geometry(params: Params<PieOptions>): Params<PieOptions> {
|
|
|
59
60
|
isStack: true,
|
|
60
61
|
interval: {
|
|
61
62
|
color,
|
|
63
|
+
shape,
|
|
62
64
|
style: pieStyle,
|
|
63
65
|
},
|
|
64
66
|
args: {
|
package/src/plots/pie/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Options, Statistic, StyleAttr } from '../../types';
|
|
1
|
+
import { Options, Statistic, StyleAttr, ShapeAttr } from '../../types';
|
|
2
2
|
import { Label } from '../../types/label';
|
|
3
3
|
|
|
4
4
|
export type StatisticData = {
|
|
@@ -46,4 +46,9 @@ export interface PieOptions extends Options {
|
|
|
46
46
|
* @description 显示在环图中心,可以代替tooltip,显示环图数据的总计值和各项数据,启用 statistic 组件的同时将自动关闭tooltip
|
|
47
47
|
*/
|
|
48
48
|
readonly statistic?: Statistic;
|
|
49
|
+
/**
|
|
50
|
+
* @title 饼图形状映射
|
|
51
|
+
* @descriptio 自定义饼图形状
|
|
52
|
+
*/
|
|
53
|
+
readonly shape?: ShapeAttr;
|
|
49
54
|
}
|
|
@@ -19,10 +19,9 @@ export function geometry(params: Params<ProgressOptions>): Params<ProgressOption
|
|
|
19
19
|
|
|
20
20
|
const p = deepAssign({}, params, {
|
|
21
21
|
options: {
|
|
22
|
-
xField: '
|
|
22
|
+
xField: 'current',
|
|
23
23
|
yField: 'percent',
|
|
24
24
|
seriesField: 'type',
|
|
25
|
-
isStack: true,
|
|
26
25
|
widthRatio: barWidthRatio,
|
|
27
26
|
interval: {
|
|
28
27
|
style: progressStyle,
|
|
@@ -8,12 +8,15 @@ export function getProgressData(percent: number) {
|
|
|
8
8
|
const clampPercent = clamp(isRealNumber(percent) ? percent : 0, 0, 1);
|
|
9
9
|
return [
|
|
10
10
|
{
|
|
11
|
+
// 用于 progressStyle 的回调方法
|
|
12
|
+
current: `${clampPercent}`,
|
|
11
13
|
type: 'current',
|
|
12
14
|
percent: clampPercent,
|
|
13
15
|
},
|
|
14
16
|
{
|
|
17
|
+
current: `${clampPercent}`,
|
|
15
18
|
type: 'target',
|
|
16
|
-
percent: 1
|
|
19
|
+
percent: 1,
|
|
17
20
|
},
|
|
18
21
|
];
|
|
19
22
|
}
|
|
@@ -2,6 +2,7 @@ import { uniq } from '@antv/util';
|
|
|
2
2
|
import { theme } from '../../adaptor/common';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
4
|
import { deepAssign, findViewById, flow } from '../../utils';
|
|
5
|
+
import { addViewAnimation } from '../../utils/view';
|
|
5
6
|
import { polygon, edge } from '../../adaptor/geometries';
|
|
6
7
|
import { transformToViewsData } from './helper';
|
|
7
8
|
import { SankeyOptions } from './types';
|
|
@@ -110,19 +111,9 @@ export function animation(params: Params<SankeyOptions>): Params<SankeyOptions>
|
|
|
110
111
|
const { chart, options } = params;
|
|
111
112
|
const { animation } = options;
|
|
112
113
|
|
|
113
|
-
// 同时设置整个 view 动画选项
|
|
114
|
-
if (typeof animation === 'boolean') {
|
|
115
|
-
chart.animate(animation);
|
|
116
|
-
} else {
|
|
117
|
-
chart.animate(true);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
114
|
const geometries = [...chart.views[0].geometries, ...chart.views[1].geometries];
|
|
121
115
|
|
|
122
|
-
|
|
123
|
-
geometries.forEach((g) => {
|
|
124
|
-
g.animate(animation);
|
|
125
|
-
});
|
|
116
|
+
addViewAnimation(chart, animation, geometries);
|
|
126
117
|
|
|
127
118
|
return params;
|
|
128
119
|
}
|
package/src/plots/stock/utils.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { TREND_FIELD, TREND_DOWN, TREND_UP, Y_FIELD } from './constant';
|
|
|
6
6
|
* @param data
|
|
7
7
|
* @param yField
|
|
8
8
|
*/
|
|
9
|
-
export function getStockData(data, yField) {
|
|
10
|
-
return map(data, (
|
|
11
|
-
|
|
9
|
+
export function getStockData(data: Record<string, any>[], yField: [string, string, string, string]) {
|
|
10
|
+
return map(data, (item) => {
|
|
11
|
+
const obj = item && { ...item };
|
|
12
|
+
if (isArray(yField) && obj) {
|
|
12
13
|
const [open, close, high, low] = yField;
|
|
13
14
|
obj[TREND_FIELD] = obj[open] <= obj[close] ? TREND_UP : TREND_DOWN;
|
|
14
15
|
obj[Y_FIELD] = [obj[open], obj[close], obj[high], obj[low]];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Geometry } from '@antv/g2';
|
|
2
1
|
import { get, set, omit, each } from '@antv/util';
|
|
3
2
|
import { Params } from '../../core/adaptor';
|
|
4
3
|
import { interaction, theme, tooltip, annotation as baseAnnotation } from '../../adaptor/common';
|
|
5
4
|
import { interval, point, violin } from '../../adaptor/geometries';
|
|
6
5
|
import { flow, pick, deepAssign, findViewById } from '../../utils';
|
|
6
|
+
import { addViewAnimation } from '../../utils/view';
|
|
7
7
|
import { AXIS_META_CONFIG_KEYS } from '../../constant';
|
|
8
8
|
import { ViolinOptions } from './types';
|
|
9
9
|
import { transformViolinData } from './utils';
|
|
@@ -281,16 +281,7 @@ export function animation(params: Params<ViolinOptions>): Params<ViolinOptions>
|
|
|
281
281
|
|
|
282
282
|
// 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
|
|
283
283
|
each(chart.views, (view) => {
|
|
284
|
-
|
|
285
|
-
if (typeof animation === 'boolean') {
|
|
286
|
-
view.animate(animation);
|
|
287
|
-
} else {
|
|
288
|
-
view.animate(true);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
each(view.geometries, (g: Geometry) => {
|
|
292
|
-
g.animate(animation);
|
|
293
|
-
});
|
|
284
|
+
addViewAnimation(view, animation);
|
|
294
285
|
});
|
|
295
286
|
|
|
296
287
|
return params;
|
package/src/types/common.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Types } from '@antv/g2';
|
|
1
|
+
import { Geometry, Types } from '@antv/g2';
|
|
2
2
|
import { Axis } from './axis';
|
|
3
3
|
import { Label } from './label';
|
|
4
4
|
import { Tooltip } from './tooltip';
|
|
@@ -109,7 +109,7 @@ export type Options = {
|
|
|
109
109
|
readonly padding?: number[] | number | 'auto';
|
|
110
110
|
/**
|
|
111
111
|
* @title 画布宽度
|
|
112
|
-
* @description
|
|
112
|
+
* @description 额外增加的 padding 值
|
|
113
113
|
*/
|
|
114
114
|
readonly appendPadding?: number[] | number;
|
|
115
115
|
/**
|
|
@@ -221,7 +221,7 @@ export type Options = {
|
|
|
221
221
|
* @title 动画
|
|
222
222
|
* @description 设置图表动画
|
|
223
223
|
*/
|
|
224
|
-
readonly animation?: Animation;
|
|
224
|
+
readonly animation?: Animation | ((type: string, g: Geometry) => Animation) | boolean;
|
|
225
225
|
/**
|
|
226
226
|
* @title 交互
|
|
227
227
|
* @description 设置画布交互行为
|
|
@@ -249,3 +249,5 @@ export type Options = {
|
|
|
249
249
|
*/
|
|
250
250
|
readonly defaultInteractions?: string[];
|
|
251
251
|
};
|
|
252
|
+
|
|
253
|
+
export type RawFields = string[] | ((type: string, field: 'color' | 'shape' | 'size' | 'style') => string[] | never);
|
package/src/types/interaction.ts
CHANGED
|
@@ -43,4 +43,10 @@ export type BrushCfg = {
|
|
|
43
43
|
* @description brush button 的配置, 只在 action: 'filter' 的情况下适用
|
|
44
44
|
*/
|
|
45
45
|
readonly button?: ButtonCfg;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @title 是否允许 brush 交互开始的回调
|
|
49
|
+
* @description 是否允许 brush 交互开始的回调
|
|
50
|
+
*/
|
|
51
|
+
readonly isStartEnable?: (context: any) => boolean;
|
|
46
52
|
};
|
package/src/utils/conversion.ts
CHANGED
|
@@ -9,15 +9,18 @@ export function conversionTagFormatter(prev: number, next: number): string {
|
|
|
9
9
|
return '-';
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// 0 / 0 没有意义
|
|
13
|
+
if (prev === 0 && next === 0) {
|
|
14
|
+
return '-';
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
if (prev === next) {
|
|
13
18
|
return '100%';
|
|
14
19
|
}
|
|
20
|
+
|
|
15
21
|
if (prev === 0) {
|
|
16
22
|
return '∞';
|
|
17
23
|
}
|
|
18
|
-
if (next === 0) {
|
|
19
|
-
return '-∞';
|
|
20
|
-
}
|
|
21
24
|
|
|
22
25
|
return `${((100 * next) / prev).toFixed(2)}%`;
|
|
23
26
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -12,5 +12,6 @@ export { kebabCase } from './kebab-case';
|
|
|
12
12
|
export { renderStatistic, renderGaugeStatistic } from './statistic';
|
|
13
13
|
export { measureTextWidth } from './measure-text';
|
|
14
14
|
export { isBetween, isRealNumber } from './number';
|
|
15
|
+
export { addViewAnimation } from './view';
|
|
15
16
|
export * from './data';
|
|
16
17
|
export * from './padding';
|
package/src/utils/view.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { View } from '@antv/g2';
|
|
1
|
+
import { Geometry, View, Types } from '@antv/g2';
|
|
2
|
+
import { each, isFunction } from '@antv/util';
|
|
3
|
+
import { Options } from '../types';
|
|
4
|
+
import { Animation } from '../types/animation';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* 在 Chart 中查找特定 id 的子 View
|
|
@@ -29,3 +32,33 @@ export function getViews(view: View): View[] {
|
|
|
29
32
|
export function getSiblingViews(view: View): View[] {
|
|
30
33
|
return getViews(view).filter((sub) => sub !== view);
|
|
31
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 所有的 Geometries 都使用同一动画(各个图形如有区别,自行覆盖)并添加处理动画回调
|
|
38
|
+
* @param view View
|
|
39
|
+
* @param animation 动画配置
|
|
40
|
+
*/
|
|
41
|
+
export function addViewAnimation(
|
|
42
|
+
view: View,
|
|
43
|
+
animation: Options['animation'],
|
|
44
|
+
geometries: Geometry<Types.ShapePoint>[] = view.geometries
|
|
45
|
+
) {
|
|
46
|
+
// 同时设置整个 view 动画选项
|
|
47
|
+
if (typeof animation === 'boolean') {
|
|
48
|
+
view.animate(animation);
|
|
49
|
+
} else {
|
|
50
|
+
view.animate(true);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 所有的 Geometry 都使用同一动画(各个图形如有区别,自行覆盖)
|
|
54
|
+
each(geometries, (g: Geometry) => {
|
|
55
|
+
let animationCfg;
|
|
56
|
+
if (isFunction(animation)) {
|
|
57
|
+
animationCfg = animation(g.type || g.shapeType, g) || true;
|
|
58
|
+
} else {
|
|
59
|
+
animationCfg = animation;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
g.animate(animationCfg as Animation);
|
|
63
|
+
});
|
|
64
|
+
}
|