@antv/g2 5.1.16 → 5.1.18
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/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/animation/growInX.js +4 -2
- package/esm/animation/growInX.js.map +1 -1
- package/esm/animation/growInY.js +4 -2
- package/esm/animation/growInY.js.map +1 -1
- package/esm/animation/morphing.js +35 -18
- package/esm/animation/morphing.js.map +1 -1
- package/esm/animation/scaleInY.js +2 -5
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/animation/utils.d.ts +10 -1
- package/esm/animation/utils.js +29 -3
- package/esm/animation/utils.js.map +1 -1
- package/esm/animation/waveIn.js +3 -14
- package/esm/animation/waveIn.js.map +1 -1
- package/esm/component/title.js +2 -1
- package/esm/component/title.js.map +1 -1
- package/esm/exports.js +0 -2
- package/esm/exports.js.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/interaction/brushAxisHighlight.js +3 -3
- package/esm/interaction/brushAxisHighlight.js.map +1 -1
- package/esm/interaction/brushHighlight.js +4 -5
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/elementPointMove.d.ts +9 -0
- package/esm/interaction/elementPointMove.js +506 -0
- package/esm/interaction/elementPointMove.js.map +1 -0
- package/esm/interaction/event.js +1 -8
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/tooltip.js +15 -5
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/treemapDrillDown.js +1 -4
- package/esm/interaction/treemapDrillDown.js.map +1 -1
- package/esm/interaction/utils.d.ts +8 -2
- package/esm/interaction/utils.js +51 -8
- package/esm/interaction/utils.js.map +1 -1
- package/esm/lib/core.d.ts +2 -1
- package/esm/lib/core.js +2 -1
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/chord.js +0 -1
- package/esm/mark/chord.js.map +1 -1
- package/esm/mark/point.js +3 -1
- package/esm/mark/point.js.map +1 -1
- package/esm/mark/sankey.js +1 -1
- package/esm/mark/sankey.js.map +1 -1
- package/esm/runtime/plot.js +4 -7
- package/esm/runtime/plot.js.map +1 -1
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/gauge/round.js +1 -1
- package/esm/shape/gauge/round.js.map +1 -1
- package/esm/shape/image/image.js +1 -1
- package/esm/shape/index.d.ts +2 -0
- package/esm/shape/index.js +2 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.js +1 -1
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/interval/funnel.js +1 -1
- package/esm/shape/interval/funnel.js.map +1 -1
- package/esm/shape/label/position/default.js +9 -9
- package/esm/shape/label/position/default.js.map +1 -1
- package/esm/shape/lineXY/line.js +1 -1
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/liquid/liquid.js +4 -4
- package/esm/shape/liquid/liquid.js.map +1 -1
- package/esm/shape/liquid/wave.js +2 -2
- package/esm/shape/liquid/wave.js.map +1 -1
- package/esm/shape/point/circle.d.ts +16 -0
- package/esm/shape/point/circle.js +56 -0
- package/esm/shape/point/circle.js.map +1 -0
- package/esm/shape/point/color.d.ts +2 -0
- package/esm/shape/point/color.js +2 -1
- package/esm/shape/point/color.js.map +1 -1
- package/esm/shape/point/hollowCircle.d.ts +6 -0
- package/esm/shape/point/hollowCircle.js +9 -0
- package/esm/shape/point/hollowCircle.js.map +1 -0
- package/esm/shape/text/advance.js +2 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +2 -3
- package/esm/shape/text/badge.js.map +1 -1
- package/esm/theme/create.d.ts +4 -2
- package/esm/theme/create.js +4 -2
- package/esm/theme/create.js.map +1 -1
- package/esm/utils/helper.js +1 -8
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/marker.d.ts +1 -1
- package/esm/utils/marker.js +2 -2
- package/esm/utils/marker.js.map +1 -1
- package/lib/animation/growInX.js +4 -2
- package/lib/animation/growInX.js.map +1 -1
- package/lib/animation/growInY.js +4 -2
- package/lib/animation/growInY.js.map +1 -1
- package/lib/animation/morphing.js +33 -16
- package/lib/animation/morphing.js.map +1 -1
- package/lib/animation/scaleInY.js +2 -5
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/animation/utils.d.ts +10 -1
- package/lib/animation/utils.js +30 -4
- package/lib/animation/utils.js.map +1 -1
- package/lib/animation/waveIn.js +2 -13
- package/lib/animation/waveIn.js.map +1 -1
- package/lib/component/title.js +2 -1
- package/lib/component/title.js.map +1 -1
- package/lib/exports.js +0 -2
- package/lib/exports.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/interaction/brushAxisHighlight.js +3 -3
- package/lib/interaction/brushAxisHighlight.js.map +1 -1
- package/lib/interaction/brushHighlight.js +4 -5
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/elementPointMove.d.ts +9 -0
- package/lib/interaction/elementPointMove.js +510 -0
- package/lib/interaction/elementPointMove.js.map +1 -0
- package/lib/interaction/event.js +4 -11
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/tooltip.js +14 -4
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/treemapDrillDown.js +2 -5
- package/lib/interaction/treemapDrillDown.js.map +1 -1
- package/lib/interaction/utils.d.ts +8 -2
- package/lib/interaction/utils.js +56 -8
- package/lib/interaction/utils.js.map +1 -1
- package/lib/lib/core.d.ts +2 -1
- package/lib/lib/core.js +1 -0
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/chord.js +0 -1
- package/lib/mark/chord.js.map +1 -1
- package/lib/mark/point.js +2 -0
- package/lib/mark/point.js.map +1 -1
- package/lib/mark/sankey.js +1 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/runtime/plot.js +4 -7
- package/lib/runtime/plot.js.map +1 -1
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/gauge/round.js +1 -1
- package/lib/shape/gauge/round.js.map +1 -1
- package/lib/shape/image/image.js +1 -1
- package/lib/shape/index.d.ts +2 -0
- package/lib/shape/index.js +6 -2
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.js +1 -1
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/interval/funnel.js +1 -1
- package/lib/shape/interval/funnel.js.map +1 -1
- package/lib/shape/label/position/default.js +9 -9
- package/lib/shape/label/position/default.js.map +1 -1
- package/lib/shape/lineXY/line.js +1 -1
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/liquid/liquid.js +4 -4
- package/lib/shape/liquid/liquid.js.map +1 -1
- package/lib/shape/liquid/wave.js +2 -2
- package/lib/shape/liquid/wave.js.map +1 -1
- package/lib/shape/point/circle.d.ts +16 -0
- package/lib/shape/point/circle.js +61 -0
- package/lib/shape/point/circle.js.map +1 -0
- package/lib/shape/point/color.d.ts +2 -0
- package/lib/shape/point/color.js +3 -1
- package/lib/shape/point/color.js.map +1 -1
- package/lib/shape/point/hollowCircle.d.ts +6 -0
- package/lib/shape/point/hollowCircle.js +13 -0
- package/lib/shape/point/hollowCircle.js.map +1 -0
- package/lib/shape/text/advance.js +2 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +2 -3
- package/lib/shape/text/badge.js.map +1 -1
- package/lib/theme/create.d.ts +4 -2
- package/lib/theme/create.js +4 -2
- package/lib/theme/create.js.map +1 -1
- package/lib/utils/helper.js +1 -8
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/marker.d.ts +1 -1
- package/lib/utils/marker.js +2 -2
- package/lib/utils/marker.js.map +1 -1
- package/package.json +12 -13
- package/src/animation/growInX.ts +9 -2
- package/src/animation/growInY.ts +9 -2
- package/src/animation/morphing.ts +36 -24
- package/src/animation/scaleInY.ts +2 -5
- package/src/animation/utils.ts +34 -4
- package/src/animation/waveIn.ts +3 -20
- package/src/component/title.ts +4 -0
- package/src/exports.ts +0 -4
- package/src/interaction/brushAxisHighlight.ts +5 -4
- package/src/interaction/brushHighlight.ts +8 -5
- package/src/interaction/elementPointMove.ts +659 -0
- package/src/interaction/event.ts +1 -7
- package/src/interaction/index.ts +1 -0
- package/src/interaction/tooltip.ts +15 -4
- package/src/interaction/treemapDrillDown.ts +1 -5
- package/src/interaction/utils.ts +71 -7
- package/src/lib/core.ts +2 -0
- package/src/mark/chord.ts +0 -1
- package/src/mark/point.ts +4 -0
- package/src/mark/sankey.ts +1 -1
- package/src/runtime/plot.ts +12 -7
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/gauge/round.ts +1 -1
- package/src/shape/image/image.ts +1 -1
- package/src/shape/index.ts +2 -0
- package/src/shape/interval/color.ts +1 -1
- package/src/shape/interval/funnel.ts +1 -1
- package/src/shape/label/position/default.ts +9 -9
- package/src/shape/lineXY/line.ts +1 -2
- package/src/shape/liquid/liquid.ts +4 -4
- package/src/shape/liquid/wave.ts +2 -2
- package/src/shape/point/circle.ts +57 -0
- package/src/shape/point/color.ts +2 -1
- package/src/shape/point/hollowCircle.ts +16 -0
- package/src/shape/text/advance.ts +3 -1
- package/src/shape/text/badge.ts +2 -3
- package/src/theme/create.ts +4 -2
- package/src/utils/helper.ts +1 -7
- package/src/utils/marker.ts +2 -11
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { Text, Group, Circle, Path } from '@antv/g';
|
|
2
|
+
import { deepMix, isUndefined, find, get } from '@antv/util';
|
|
3
|
+
import type { CircleStyleProps, TextStyleProps, PathStyleProps } from '@antv/g';
|
|
4
|
+
import { subObject } from '../utils/helper';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
selectPlotArea,
|
|
8
|
+
getPointsR,
|
|
9
|
+
getPointsPath,
|
|
10
|
+
getElements,
|
|
11
|
+
getThetaPath,
|
|
12
|
+
} from './utils';
|
|
13
|
+
|
|
14
|
+
export type ElementPointMoveOptions = {
|
|
15
|
+
selection?: number[];
|
|
16
|
+
precision?: number;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const DEFAULT_STYLE = {
|
|
21
|
+
pointR: 6,
|
|
22
|
+
pointStrokeWidth: 1,
|
|
23
|
+
pointStroke: '#888',
|
|
24
|
+
pointActiveStroke: '#f5f5f5',
|
|
25
|
+
pathStroke: '#888',
|
|
26
|
+
pathLineDash: [3, 4],
|
|
27
|
+
labelFontSize: 12,
|
|
28
|
+
labelFill: '#888',
|
|
29
|
+
labelStroke: '#fff',
|
|
30
|
+
labelLineWidth: 1,
|
|
31
|
+
labelY: -6,
|
|
32
|
+
labelX: 2,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// point shape name.
|
|
36
|
+
const MOVE_POINT_NAME = 'movePoint';
|
|
37
|
+
|
|
38
|
+
// Element mouseenter change style.
|
|
39
|
+
const elementMouseenter = (e) => {
|
|
40
|
+
const element = e.target;
|
|
41
|
+
const { markType } = element;
|
|
42
|
+
// Mark line.
|
|
43
|
+
if (markType === 'line') {
|
|
44
|
+
element.attr('_lineWidth', element.attr('lineWidth') || 1);
|
|
45
|
+
element.attr('lineWidth', element.attr('_lineWidth') + 3);
|
|
46
|
+
}
|
|
47
|
+
// Mark interval.
|
|
48
|
+
if (markType === 'interval') {
|
|
49
|
+
element.attr('_opacity', element.attr('opacity') || 1);
|
|
50
|
+
element.attr('opacity', 0.7 * element.attr('_opacity'));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Element mouseleave change style.
|
|
55
|
+
const elementMouseleave = (e) => {
|
|
56
|
+
const element = e.target;
|
|
57
|
+
const { markType } = element;
|
|
58
|
+
// Mark line.
|
|
59
|
+
if (markType === 'line') {
|
|
60
|
+
element.attr('lineWidth', element.attr('_lineWidth'));
|
|
61
|
+
}
|
|
62
|
+
// Mark interval.
|
|
63
|
+
if (markType === 'interval') {
|
|
64
|
+
element.attr('opacity', element.attr('_opacity'));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Get the latest overall data based on the individual data changes.
|
|
69
|
+
const getNewData = (newChangeData, data, encode) => {
|
|
70
|
+
return data.map((d) => {
|
|
71
|
+
const isUpdate = ['x', 'color'].reduce((v, key) => {
|
|
72
|
+
const field = encode[key];
|
|
73
|
+
if (!field) return v;
|
|
74
|
+
|
|
75
|
+
if (d[field] !== newChangeData[field]) return false;
|
|
76
|
+
|
|
77
|
+
return v;
|
|
78
|
+
}, true);
|
|
79
|
+
|
|
80
|
+
return isUpdate ? { ...d, ...newChangeData } : d;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Find mark interval origin element data.
|
|
85
|
+
const getIntervalDataRatioTransformFn = (element) => {
|
|
86
|
+
const y = get(element, ['__data__', 'y']);
|
|
87
|
+
const y1 = get(element, ['__data__', 'y1']);
|
|
88
|
+
const v = y1 - y;
|
|
89
|
+
|
|
90
|
+
const {
|
|
91
|
+
__data__: { data, encode, transform },
|
|
92
|
+
childNodes,
|
|
93
|
+
} = element.parentNode;
|
|
94
|
+
const isNormalizeY = find(transform, ({ type }) => type === 'normalizeY');
|
|
95
|
+
const yField = get(encode, ['y', 'field']);
|
|
96
|
+
const value = data[childNodes.indexOf(element)][yField];
|
|
97
|
+
|
|
98
|
+
return (newValue, isTheta = false) => {
|
|
99
|
+
if (isNormalizeY || isTheta) {
|
|
100
|
+
return (newValue / (1 - newValue) / (v / (1 - v))) * value;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return newValue;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Find origin path data.
|
|
108
|
+
const getPathDataRatioTransformFn = (element, index) => {
|
|
109
|
+
const v = get(element, ['__data__', 'seriesItems', index, '0', 'value']);
|
|
110
|
+
const i = get(element, ['__data__', 'seriesIndex', index]);
|
|
111
|
+
|
|
112
|
+
const {
|
|
113
|
+
__data__: { data, encode, transform },
|
|
114
|
+
} = element.parentNode;
|
|
115
|
+
const isNormalizeY = find(transform, ({ type }) => type === 'normalizeY');
|
|
116
|
+
const yField = get(encode, ['y', 'field']);
|
|
117
|
+
const value = data[i][yField];
|
|
118
|
+
|
|
119
|
+
return (newValue) => {
|
|
120
|
+
if (isNormalizeY) {
|
|
121
|
+
if (v === 1) {
|
|
122
|
+
return newValue;
|
|
123
|
+
}
|
|
124
|
+
return (newValue / (1 - newValue) / (v / (1 - v))) * value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return newValue;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// Point shape select change style.
|
|
132
|
+
const selectedPointsStyle = (pointsShape, selection, defaultStyle) => {
|
|
133
|
+
pointsShape.forEach((shape, index) => {
|
|
134
|
+
shape.attr(
|
|
135
|
+
'stroke',
|
|
136
|
+
selection[1] === index
|
|
137
|
+
? defaultStyle['activeStroke']
|
|
138
|
+
: defaultStyle['stroke'],
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Create help show message shape.
|
|
144
|
+
const createHelpShape = (
|
|
145
|
+
group,
|
|
146
|
+
circle,
|
|
147
|
+
pathStyle,
|
|
148
|
+
labelStyle,
|
|
149
|
+
): [Path, Text] => {
|
|
150
|
+
const pathShape = new Path({
|
|
151
|
+
style: pathStyle,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const labelShape = new Text({
|
|
155
|
+
style: labelStyle,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
circle.appendChild(labelShape);
|
|
159
|
+
group.appendChild(pathShape);
|
|
160
|
+
return [pathShape, labelShape];
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Get color scale type.
|
|
164
|
+
const getColorType = (scaleColor, color) => {
|
|
165
|
+
const indexOf = get(scaleColor, ['options', 'range', 'indexOf']);
|
|
166
|
+
if (!indexOf) return;
|
|
167
|
+
const i = scaleColor.options.range.indexOf(color);
|
|
168
|
+
return scaleColor.sortedDomain[i];
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Get the same direction new point.
|
|
172
|
+
const getSamePointPosition = (center, point, target) => {
|
|
173
|
+
const oldR = getPointsR(center, point);
|
|
174
|
+
const newR = getPointsR(center, target);
|
|
175
|
+
const ratio = newR / oldR;
|
|
176
|
+
const newX = center[0] + (point[0] - center[0]) * ratio;
|
|
177
|
+
const newY = center[1] + (point[1] - center[1]) * ratio;
|
|
178
|
+
return [newX, newY];
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* ElementPointMove interaction.
|
|
183
|
+
*/
|
|
184
|
+
export function ElementPointMove(
|
|
185
|
+
elementPointMoveOptions: ElementPointMoveOptions = {},
|
|
186
|
+
) {
|
|
187
|
+
const { selection = [], precision = 2, ...style } = elementPointMoveOptions;
|
|
188
|
+
|
|
189
|
+
const defaultStyle = { ...DEFAULT_STYLE, ...(style || {}) };
|
|
190
|
+
|
|
191
|
+
// Shape default style.
|
|
192
|
+
const pathDefaultStyle = subObject(defaultStyle, 'path') as PathStyleProps;
|
|
193
|
+
const labelDefaultStyle = subObject(defaultStyle, 'label') as TextStyleProps;
|
|
194
|
+
const pointDefaultStyle = subObject(
|
|
195
|
+
defaultStyle,
|
|
196
|
+
'point',
|
|
197
|
+
) as CircleStyleProps;
|
|
198
|
+
|
|
199
|
+
return (context, _, emitter) => {
|
|
200
|
+
const {
|
|
201
|
+
update,
|
|
202
|
+
setState,
|
|
203
|
+
container,
|
|
204
|
+
view,
|
|
205
|
+
options: { marks, coordinate: coordinateOptions },
|
|
206
|
+
} = context;
|
|
207
|
+
const plotArea = selectPlotArea(container);
|
|
208
|
+
let elements = getElements(plotArea);
|
|
209
|
+
let newState;
|
|
210
|
+
let newSelection = selection;
|
|
211
|
+
|
|
212
|
+
const { transform = [], type: coordinateType } = coordinateOptions;
|
|
213
|
+
const isTranspose = !!find(transform, ({ type }) => type === 'transpose');
|
|
214
|
+
const isPolar = coordinateType === 'polar';
|
|
215
|
+
const isTheta = coordinateType === 'theta';
|
|
216
|
+
const isArea = !!find(elements, ({ markType }) => markType === 'area');
|
|
217
|
+
|
|
218
|
+
if (isArea) {
|
|
219
|
+
elements = elements.filter(({ markType }) => markType === 'area');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Create points
|
|
223
|
+
const pointsGroup = new Group({
|
|
224
|
+
style: {
|
|
225
|
+
// Tooltip point need down.
|
|
226
|
+
zIndex: 2,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
plotArea.appendChild(pointsGroup);
|
|
230
|
+
|
|
231
|
+
const selectedChange = () => {
|
|
232
|
+
emitter.emit('element-point:select', {
|
|
233
|
+
nativeEvent: true,
|
|
234
|
+
data: {
|
|
235
|
+
selection: newSelection,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const dataChange = (changeData, data) => {
|
|
241
|
+
emitter.emit('element-point:moved', {
|
|
242
|
+
nativeEvent: true,
|
|
243
|
+
data: {
|
|
244
|
+
changeData,
|
|
245
|
+
data,
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Element click change style.
|
|
251
|
+
const elementClick = (e) => {
|
|
252
|
+
const element = e.target;
|
|
253
|
+
newSelection = [element.parentNode.childNodes.indexOf(element)];
|
|
254
|
+
selectedChange();
|
|
255
|
+
createPoints(element);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const elementSelect = (d) => {
|
|
259
|
+
const {
|
|
260
|
+
data: { selection },
|
|
261
|
+
nativeEvent,
|
|
262
|
+
} = d;
|
|
263
|
+
if (nativeEvent) return;
|
|
264
|
+
newSelection = selection;
|
|
265
|
+
const element = get(elements, [newSelection?.[0]]);
|
|
266
|
+
if (element) {
|
|
267
|
+
createPoints(element);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// Create select element points.
|
|
272
|
+
const createPoints = (element) => {
|
|
273
|
+
const { attributes, markType, __data__: data } = element;
|
|
274
|
+
const { stroke: fill } = attributes;
|
|
275
|
+
const { points, seriesTitle, color, title, seriesX, y1 } = data;
|
|
276
|
+
// Transpose Currently only do mark interval;
|
|
277
|
+
if (isTranspose && markType !== 'interval') return;
|
|
278
|
+
|
|
279
|
+
const { scale, coordinate } = newState?.view || view;
|
|
280
|
+
const { color: scaleColor, y: scaleY, x: scaleX } = scale;
|
|
281
|
+
const center = coordinate.getCenter();
|
|
282
|
+
|
|
283
|
+
pointsGroup.removeChildren();
|
|
284
|
+
let downPoint;
|
|
285
|
+
|
|
286
|
+
const updateView = async (x, y, color, markTypes) => {
|
|
287
|
+
setState('elementPointMove', (viewOptions) => {
|
|
288
|
+
// Update marks.
|
|
289
|
+
const newMarks = (newState?.options?.marks || marks).map((mark) => {
|
|
290
|
+
if (!markTypes.includes(mark.type)) return mark;
|
|
291
|
+
const { data, encode } = mark;
|
|
292
|
+
const encodeKeys = Object.keys(encode);
|
|
293
|
+
|
|
294
|
+
// Get change new one element data.
|
|
295
|
+
const newChangeData = encodeKeys.reduce((value, key) => {
|
|
296
|
+
const dataKey = encode[key];
|
|
297
|
+
if (key === 'x') {
|
|
298
|
+
value[dataKey] = x;
|
|
299
|
+
}
|
|
300
|
+
if (key === 'y') {
|
|
301
|
+
value[dataKey] = y;
|
|
302
|
+
}
|
|
303
|
+
if (key === 'color') {
|
|
304
|
+
value[dataKey] = color;
|
|
305
|
+
}
|
|
306
|
+
return value;
|
|
307
|
+
}, {} as any);
|
|
308
|
+
// Get change new all data.
|
|
309
|
+
const newData = getNewData(newChangeData, data, encode);
|
|
310
|
+
dataChange(newChangeData, newData);
|
|
311
|
+
|
|
312
|
+
return deepMix({}, mark, {
|
|
313
|
+
data: newData,
|
|
314
|
+
// No need animate
|
|
315
|
+
animate: false,
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
return { ...viewOptions, marks: newMarks };
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return await update('elementPointMove');
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
if (['line', 'area'].includes(markType)) {
|
|
326
|
+
points.forEach((p, index) => {
|
|
327
|
+
const title = scaleX.invert(seriesX[index]);
|
|
328
|
+
|
|
329
|
+
// Area points have bottom point.
|
|
330
|
+
if (!title) return;
|
|
331
|
+
|
|
332
|
+
const circle = new Circle({
|
|
333
|
+
name: MOVE_POINT_NAME,
|
|
334
|
+
style: {
|
|
335
|
+
cx: p[0],
|
|
336
|
+
cy: p[1],
|
|
337
|
+
fill,
|
|
338
|
+
...pointDefaultStyle,
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const ratioTransform = getPathDataRatioTransformFn(element, index);
|
|
343
|
+
|
|
344
|
+
circle.addEventListener('mousedown', (e) => {
|
|
345
|
+
const oldPoint = coordinate.output([seriesX[index], 0]);
|
|
346
|
+
const pathLength = seriesTitle?.length;
|
|
347
|
+
|
|
348
|
+
container.attr('cursor', 'move');
|
|
349
|
+
|
|
350
|
+
if (newSelection[1] !== index) {
|
|
351
|
+
newSelection[1] = index;
|
|
352
|
+
selectedChange();
|
|
353
|
+
}
|
|
354
|
+
selectedPointsStyle(
|
|
355
|
+
pointsGroup.childNodes,
|
|
356
|
+
newSelection,
|
|
357
|
+
pointDefaultStyle,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const [pathShape, labelShape] = createHelpShape(
|
|
361
|
+
pointsGroup,
|
|
362
|
+
circle,
|
|
363
|
+
pathDefaultStyle,
|
|
364
|
+
labelDefaultStyle,
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
// Point move change text
|
|
368
|
+
const pointMousemove = (e) => {
|
|
369
|
+
const newCy = p[1] + e.clientY - downPoint[1];
|
|
370
|
+
// Area/Radar chart.
|
|
371
|
+
if (isArea) {
|
|
372
|
+
// Radar chart.
|
|
373
|
+
if (isPolar) {
|
|
374
|
+
const newCx = p[0] + e.clientX - downPoint[0];
|
|
375
|
+
|
|
376
|
+
const [newX, newY] = getSamePointPosition(center, oldPoint, [
|
|
377
|
+
newCx,
|
|
378
|
+
newCy,
|
|
379
|
+
]);
|
|
380
|
+
|
|
381
|
+
const [, initY] = coordinate.output([1, scaleY.output(0)]);
|
|
382
|
+
const [, y] = coordinate.invert([
|
|
383
|
+
newX,
|
|
384
|
+
initY - (points[index + pathLength][1] - newY),
|
|
385
|
+
]);
|
|
386
|
+
|
|
387
|
+
const nextIndex = (index + 1) % pathLength;
|
|
388
|
+
const lastIndex = (index - 1 + pathLength) % pathLength;
|
|
389
|
+
const newPath = getPointsPath([
|
|
390
|
+
points[lastIndex],
|
|
391
|
+
[newX, newY],
|
|
392
|
+
seriesTitle[nextIndex] && points[nextIndex],
|
|
393
|
+
]);
|
|
394
|
+
labelShape.attr(
|
|
395
|
+
'text',
|
|
396
|
+
ratioTransform(scaleY.invert(y)).toFixed(precision),
|
|
397
|
+
);
|
|
398
|
+
pathShape.attr('d', newPath);
|
|
399
|
+
circle.attr('cx', newX);
|
|
400
|
+
circle.attr('cy', newY);
|
|
401
|
+
} else {
|
|
402
|
+
// Area chart.
|
|
403
|
+
const [, initY] = coordinate.output([1, scaleY.output(0)]);
|
|
404
|
+
const [, y] = coordinate.invert([
|
|
405
|
+
p[0],
|
|
406
|
+
initY - (points[index + pathLength][1] - newCy),
|
|
407
|
+
]);
|
|
408
|
+
const newPath = getPointsPath([
|
|
409
|
+
points[index - 1],
|
|
410
|
+
[p[0], newCy],
|
|
411
|
+
seriesTitle[index + 1] && points[index + 1],
|
|
412
|
+
]);
|
|
413
|
+
labelShape.attr(
|
|
414
|
+
'text',
|
|
415
|
+
ratioTransform(scaleY.invert(y)).toFixed(precision),
|
|
416
|
+
);
|
|
417
|
+
pathShape.attr('d', newPath);
|
|
418
|
+
circle.attr('cy', newCy);
|
|
419
|
+
}
|
|
420
|
+
} else {
|
|
421
|
+
// Line chart.
|
|
422
|
+
const [, y] = coordinate.invert([p[0], newCy]);
|
|
423
|
+
const newPath = getPointsPath([
|
|
424
|
+
points[index - 1],
|
|
425
|
+
[p[0], newCy],
|
|
426
|
+
points[index + 1],
|
|
427
|
+
]);
|
|
428
|
+
labelShape.attr('text', scaleY.invert(y).toFixed(precision));
|
|
429
|
+
pathShape.attr('d', newPath);
|
|
430
|
+
circle.attr('cy', newCy);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
downPoint = [e.clientX, e.clientY];
|
|
435
|
+
window.addEventListener('mousemove', pointMousemove);
|
|
436
|
+
|
|
437
|
+
const mouseupFn = async () => {
|
|
438
|
+
container.attr('cursor', 'default');
|
|
439
|
+
window.removeEventListener('mousemove', pointMousemove);
|
|
440
|
+
container.removeEventListener('mouseup', mouseupFn);
|
|
441
|
+
|
|
442
|
+
if (isUndefined(labelShape.attr('text'))) return;
|
|
443
|
+
|
|
444
|
+
const y = Number(labelShape.attr('text'));
|
|
445
|
+
const colorType = getColorType(scaleColor, color);
|
|
446
|
+
newState = await updateView(title, y, colorType, [
|
|
447
|
+
'line',
|
|
448
|
+
'area',
|
|
449
|
+
]);
|
|
450
|
+
|
|
451
|
+
labelShape.remove();
|
|
452
|
+
pathShape.remove();
|
|
453
|
+
createPoints(element);
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
container.addEventListener('mouseup', mouseupFn);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
pointsGroup.appendChild(circle);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
selectedPointsStyle(
|
|
463
|
+
pointsGroup.childNodes,
|
|
464
|
+
newSelection,
|
|
465
|
+
pointDefaultStyle,
|
|
466
|
+
);
|
|
467
|
+
} else if (markType === 'interval') {
|
|
468
|
+
// Column chart point.
|
|
469
|
+
let circlePoint = [(points[0][0] + points[1][0]) / 2, points[0][1]];
|
|
470
|
+
// Bar chart point.
|
|
471
|
+
if (isTranspose) {
|
|
472
|
+
circlePoint = [points[0][0], (points[0][1] + points[1][1]) / 2];
|
|
473
|
+
} else if (isTheta) {
|
|
474
|
+
// Pie chart point.
|
|
475
|
+
circlePoint = points[0];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const ratioTransform = getIntervalDataRatioTransformFn(element);
|
|
479
|
+
|
|
480
|
+
const circle = new Circle({
|
|
481
|
+
name: MOVE_POINT_NAME,
|
|
482
|
+
style: {
|
|
483
|
+
cx: circlePoint[0],
|
|
484
|
+
cy: circlePoint[1],
|
|
485
|
+
fill,
|
|
486
|
+
...pointDefaultStyle,
|
|
487
|
+
stroke: pointDefaultStyle['activeStroke'],
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
circle.addEventListener('mousedown', (e) => {
|
|
492
|
+
container.attr('cursor', 'move');
|
|
493
|
+
|
|
494
|
+
const colorType = getColorType(scaleColor, color);
|
|
495
|
+
|
|
496
|
+
const [pathShape, labelShape] = createHelpShape(
|
|
497
|
+
pointsGroup,
|
|
498
|
+
circle,
|
|
499
|
+
pathDefaultStyle,
|
|
500
|
+
labelDefaultStyle,
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
// Point move change text
|
|
504
|
+
const pointMousemove = (e) => {
|
|
505
|
+
if (isTranspose) {
|
|
506
|
+
// Bar chart.
|
|
507
|
+
const newCx = circlePoint[0] + e.clientX - downPoint[0];
|
|
508
|
+
const [initX] = coordinate.output([
|
|
509
|
+
scaleY.output(0),
|
|
510
|
+
scaleY.output(0),
|
|
511
|
+
]);
|
|
512
|
+
|
|
513
|
+
const [, x] = coordinate.invert([
|
|
514
|
+
initX + (newCx - points[2][0]),
|
|
515
|
+
circlePoint[1],
|
|
516
|
+
]);
|
|
517
|
+
const newPath = getPointsPath(
|
|
518
|
+
[
|
|
519
|
+
[newCx, points[0][1]],
|
|
520
|
+
[newCx, points[1][1]],
|
|
521
|
+
points[2],
|
|
522
|
+
points[3],
|
|
523
|
+
],
|
|
524
|
+
true,
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
labelShape.attr(
|
|
528
|
+
'text',
|
|
529
|
+
ratioTransform(scaleY.invert(x)).toFixed(precision),
|
|
530
|
+
);
|
|
531
|
+
pathShape.attr('d', newPath);
|
|
532
|
+
circle.attr('cx', newCx);
|
|
533
|
+
} else if (isTheta) {
|
|
534
|
+
// Pie chart.
|
|
535
|
+
const newCy = circlePoint[1] + e.clientY - downPoint[1];
|
|
536
|
+
const newCx = circlePoint[0] + e.clientX - downPoint[0];
|
|
537
|
+
|
|
538
|
+
const [newXOut, newYOut] = getSamePointPosition(
|
|
539
|
+
center,
|
|
540
|
+
[newCx, newCy],
|
|
541
|
+
circlePoint,
|
|
542
|
+
);
|
|
543
|
+
const [newXIn, newYIn] = getSamePointPosition(
|
|
544
|
+
center,
|
|
545
|
+
[newCx, newCy],
|
|
546
|
+
points[1],
|
|
547
|
+
);
|
|
548
|
+
const lastPercent = coordinate.invert([newXOut, newYOut])[1];
|
|
549
|
+
const percent = y1 - lastPercent;
|
|
550
|
+
|
|
551
|
+
if (percent < 0) return;
|
|
552
|
+
const newPath = getThetaPath(
|
|
553
|
+
center,
|
|
554
|
+
[[newXOut, newYOut], [newXIn, newYIn], points[2], points[3]],
|
|
555
|
+
percent > 0.5 ? 1 : 0,
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
labelShape.attr(
|
|
559
|
+
'text',
|
|
560
|
+
ratioTransform(percent, true).toFixed(precision),
|
|
561
|
+
);
|
|
562
|
+
pathShape.attr('d', newPath);
|
|
563
|
+
circle.attr('cx', newXOut);
|
|
564
|
+
circle.attr('cy', newYOut);
|
|
565
|
+
} else {
|
|
566
|
+
// Column chart.
|
|
567
|
+
const newCy = circlePoint[1] + e.clientY - downPoint[1];
|
|
568
|
+
const [, initY] = coordinate.output([1, scaleY.output(0)]);
|
|
569
|
+
|
|
570
|
+
const [, y] = coordinate.invert([
|
|
571
|
+
circlePoint[0],
|
|
572
|
+
initY - (points[2][1] - newCy),
|
|
573
|
+
]);
|
|
574
|
+
const newPath = getPointsPath(
|
|
575
|
+
[
|
|
576
|
+
[points[0][0], newCy],
|
|
577
|
+
[points[1][0], newCy],
|
|
578
|
+
points[2],
|
|
579
|
+
points[3],
|
|
580
|
+
],
|
|
581
|
+
true,
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
labelShape.attr(
|
|
585
|
+
'text',
|
|
586
|
+
ratioTransform(scaleY.invert(y)).toFixed(precision),
|
|
587
|
+
);
|
|
588
|
+
pathShape.attr('d', newPath);
|
|
589
|
+
circle.attr('cy', newCy);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
downPoint = [e.clientX, e.clientY];
|
|
594
|
+
window.addEventListener('mousemove', pointMousemove);
|
|
595
|
+
|
|
596
|
+
// Change mosueup change data and update 、clear shape.
|
|
597
|
+
const mouseupFn = async () => {
|
|
598
|
+
container.attr('cursor', 'default');
|
|
599
|
+
container.removeEventListener('mouseup', mouseupFn);
|
|
600
|
+
window.removeEventListener('mousemove', pointMousemove);
|
|
601
|
+
|
|
602
|
+
if (isUndefined(labelShape.attr('text'))) return;
|
|
603
|
+
|
|
604
|
+
const y = Number(labelShape.attr('text'));
|
|
605
|
+
|
|
606
|
+
newState = await updateView(title, y, colorType, [markType]);
|
|
607
|
+
|
|
608
|
+
labelShape.remove();
|
|
609
|
+
pathShape.remove();
|
|
610
|
+
createPoints(element);
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
container.addEventListener('mouseup', mouseupFn);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
pointsGroup.appendChild(circle);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// Add EventListener.
|
|
621
|
+
elements.forEach((element, index) => {
|
|
622
|
+
if (newSelection[0] === index) {
|
|
623
|
+
createPoints(element);
|
|
624
|
+
}
|
|
625
|
+
element.addEventListener('click', elementClick);
|
|
626
|
+
element.addEventListener('mouseenter', elementMouseenter);
|
|
627
|
+
element.addEventListener('mouseleave', elementMouseleave);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
const rootClick = (e) => {
|
|
631
|
+
const element = e?.target;
|
|
632
|
+
if (
|
|
633
|
+
!element ||
|
|
634
|
+
(element.name !== MOVE_POINT_NAME && !elements.includes(element))
|
|
635
|
+
) {
|
|
636
|
+
newSelection = [];
|
|
637
|
+
selectedChange();
|
|
638
|
+
pointsGroup.removeChildren();
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
emitter.on('element-point:select', elementSelect);
|
|
643
|
+
emitter.on('element-point:unselect', rootClick);
|
|
644
|
+
container.addEventListener('mousedown', rootClick);
|
|
645
|
+
|
|
646
|
+
// Remove EventListener.
|
|
647
|
+
return () => {
|
|
648
|
+
pointsGroup.remove();
|
|
649
|
+
emitter.off('element-point:select', elementSelect);
|
|
650
|
+
emitter.off('element-point:unselect', rootClick);
|
|
651
|
+
container.removeEventListener('mousedown', rootClick);
|
|
652
|
+
elements.forEach((element) => {
|
|
653
|
+
element.removeEventListener('click', elementClick);
|
|
654
|
+
element.removeEventListener('mouseenter', elementMouseenter);
|
|
655
|
+
element.removeEventListener('mouseleave', elementMouseleave);
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
};
|
|
659
|
+
}
|
package/src/interaction/event.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ChartEvent } from '../utils/event';
|
|
2
|
+
import { maybeRoot } from './utils';
|
|
2
3
|
|
|
3
4
|
export function dataOf(element, view) {
|
|
4
5
|
const { __data__: datum } = element;
|
|
@@ -14,13 +15,6 @@ export function dataOf(element, view) {
|
|
|
14
15
|
return selectedMark.data[index];
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
function maybeRoot(node, rootOf) {
|
|
18
|
-
if (rootOf(node)) return node;
|
|
19
|
-
let root = node.parent;
|
|
20
|
-
while (root && !rootOf(root)) root = root.parent;
|
|
21
|
-
return root;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
18
|
// For extended component
|
|
25
19
|
function maybeComponentRoot(node) {
|
|
26
20
|
return maybeRoot(node, (node) => node.className === 'component');
|
package/src/interaction/index.ts
CHANGED