cx 24.7.1 → 24.7.2
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/manifest.js +799 -799
- package/dist/ui.js +3 -3
- package/package.json +1 -1
- package/src/charts/Legend.js +151 -151
- package/src/charts/Marker.d.ts +96 -96
- package/src/charts/Marker.js +299 -299
- package/src/charts/PieLabel.js +71 -71
- package/src/charts/axis/Axis.d.ts +96 -96
- package/src/charts/axis/NumericAxis.js +347 -347
- package/src/charts/axis/Stack.js +55 -55
- package/src/data/Binding.spec.js +69 -69
- package/src/data/StringTemplate.spec.js +105 -105
- package/src/data/getAccessor.spec.js +11 -11
- package/src/svg/Text.d.ts +40 -40
- package/src/ui/Controller.d.ts +182 -182
- package/src/ui/Culture.js +129 -129
- package/src/ui/Cx.js +313 -313
- package/src/ui/FocusManager.js +171 -171
- package/src/ui/Instance.d.ts +72 -72
- package/src/ui/VDOM.d.ts +12 -12
- package/src/ui/app/startAppLoop.js +58 -58
- package/src/ui/index.d.ts +42 -42
- package/src/util/Console.d.ts +4 -4
- package/src/widgets/drag-drop/DropZone.js +214 -214
- package/src/widgets/form/TextField.js +289 -289
- package/src/widgets/form/UploadButton.d.ts +34 -34
- package/src/widgets/grid/variables.scss +88 -88
- package/src/widgets/overlay/Dropdown.js +612 -612
- package/src/widgets/overlay/Window.js +196 -196
- package/src/widgets/overlay/variables.scss +83 -83
package/src/charts/Marker.js
CHANGED
|
@@ -1,299 +1,299 @@
|
|
|
1
|
-
import { Widget, VDOM } from "../ui/Widget";
|
|
2
|
-
import { BoundedObject } from "../svg/BoundedObject";
|
|
3
|
-
import { Rect } from "../svg/util/Rect";
|
|
4
|
-
import {
|
|
5
|
-
tooltipMouseMove,
|
|
6
|
-
tooltipMouseLeave,
|
|
7
|
-
tooltipParentWillUnmount,
|
|
8
|
-
tooltipParentWillReceiveProps,
|
|
9
|
-
tooltipParentDidMount,
|
|
10
|
-
} from "../widgets/overlay/tooltip-ops";
|
|
11
|
-
import { captureMouseOrTouch, getCursorPos } from "../widgets/overlay/captureMouse";
|
|
12
|
-
import { closest } from "../util/DOM";
|
|
13
|
-
import { Selection } from "../ui/selection/Selection";
|
|
14
|
-
import { getShape } from "./shapes";
|
|
15
|
-
import { getTopLevelBoundingClientRect } from "../util/getTopLevelBoundingClientRect";
|
|
16
|
-
|
|
17
|
-
export class Marker extends BoundedObject {
|
|
18
|
-
init() {
|
|
19
|
-
this.selection = Selection.create(this.selection);
|
|
20
|
-
|
|
21
|
-
if (this.draggable) {
|
|
22
|
-
this.draggableX = true;
|
|
23
|
-
this.draggableY = true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (this.constrain) {
|
|
27
|
-
this.constrainX = true;
|
|
28
|
-
this.constrainY = true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
super.init();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declareData() {
|
|
35
|
-
var selection = this.selection.configureWidget(this);
|
|
36
|
-
|
|
37
|
-
return super.declareData(...arguments, selection, {
|
|
38
|
-
x: undefined,
|
|
39
|
-
y: undefined,
|
|
40
|
-
size: undefined,
|
|
41
|
-
shape: undefined,
|
|
42
|
-
disabled: undefined,
|
|
43
|
-
colorMap: undefined,
|
|
44
|
-
colorIndex: undefined,
|
|
45
|
-
colorName: undefined,
|
|
46
|
-
legendColorIndex: undefined,
|
|
47
|
-
name: undefined,
|
|
48
|
-
active: true,
|
|
49
|
-
stack: undefined,
|
|
50
|
-
stackedX: undefined,
|
|
51
|
-
stackedY: undefined,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
prepareData(context, instance) {
|
|
56
|
-
instance.axes = context.axes;
|
|
57
|
-
instance.xAxis = context.axes[this.xAxis];
|
|
58
|
-
instance.yAxis = context.axes[this.yAxis];
|
|
59
|
-
let { data } = instance;
|
|
60
|
-
data.selected = this.selection.isInstanceSelected(instance);
|
|
61
|
-
data.stateMods = {
|
|
62
|
-
selected: data.selected,
|
|
63
|
-
disabled: data.disabled,
|
|
64
|
-
selectable: !this.selection.isDummy,
|
|
65
|
-
"draggable-x": this.draggableX && !this.draggableY,
|
|
66
|
-
"draggable-y": this.draggableY && !this.draggableX,
|
|
67
|
-
"draggable-xy": this.draggableY && this.draggableX,
|
|
68
|
-
};
|
|
69
|
-
if (data.name && !data.colorName) data.colorName = data.name;
|
|
70
|
-
super.prepareData(context, instance);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
calculateBounds(context, instance) {
|
|
74
|
-
let { data, xAxis, yAxis } = instance;
|
|
75
|
-
|
|
76
|
-
let x, y;
|
|
77
|
-
|
|
78
|
-
if (data.x == null || data.y == null) {
|
|
79
|
-
let bounds = super.calculateBounds(context, instance);
|
|
80
|
-
x = (bounds.l + bounds.r) / 2;
|
|
81
|
-
y = (bounds.t + bounds.b) / 2;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (data.x != null) x = data.stackedX ? xAxis.stack(data.stack, data.y, data.x) : xAxis.map(data.x);
|
|
85
|
-
|
|
86
|
-
if (data.y != null) y = data.stackedY ? yAxis.stack(data.stack, data.x, data.y) : yAxis.map(data.y);
|
|
87
|
-
|
|
88
|
-
return new Rect({
|
|
89
|
-
l: x - data.size / 2,
|
|
90
|
-
r: x + data.size / 2,
|
|
91
|
-
t: y - data.size / 2,
|
|
92
|
-
b: y + data.size / 2,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
explore(context, instance) {
|
|
97
|
-
let { data, xAxis, yAxis } = instance;
|
|
98
|
-
|
|
99
|
-
instance.colorMap = data.colorMap && context.getColorMap && context.getColorMap(data.colorMap);
|
|
100
|
-
if (instance.colorMap && data.colorName) instance.colorMap.acknowledge(data.colorName);
|
|
101
|
-
|
|
102
|
-
if (data.active) {
|
|
103
|
-
if (this.affectsAxes) {
|
|
104
|
-
if (xAxis && data.x != null) {
|
|
105
|
-
if (data.stackedX) xAxis.stacknowledge(data.stack, data.y, data.x);
|
|
106
|
-
else xAxis.acknowledge(data.x, 0, this.xOffset);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (yAxis && data.y != null) {
|
|
110
|
-
if (data.stackedY) yAxis.stacknowledge(data.stack, data.x, data.y);
|
|
111
|
-
else yAxis.acknowledge(data.y, 0, this.yOffset);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (context.pointReducer) context.pointReducer(data.x, data.y, data.name, data);
|
|
116
|
-
|
|
117
|
-
super.explore(context, instance);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
prepare(context, instance) {
|
|
122
|
-
let { data, xAxis, yAxis, colorMap } = instance;
|
|
123
|
-
|
|
124
|
-
if (colorMap && data.colorName) {
|
|
125
|
-
data.colorIndex = colorMap.map(data.colorName);
|
|
126
|
-
if (instance.cache("colorIndex", data.colorIndex)) instance.markShouldUpdate(context);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (data.active) {
|
|
130
|
-
if (xAxis && xAxis.shouldUpdate) instance.markShouldUpdate(context);
|
|
131
|
-
|
|
132
|
-
if (yAxis && yAxis.shouldUpdate) instance.markShouldUpdate(context);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
super.prepare(context, instance);
|
|
136
|
-
|
|
137
|
-
if (data.name && context.addLegendEntry)
|
|
138
|
-
context.addLegendEntry(this.legend, {
|
|
139
|
-
name: data.name,
|
|
140
|
-
active: data.active,
|
|
141
|
-
colorIndex: data.legendColorIndex || data.colorIndex,
|
|
142
|
-
disabled: data.disabled,
|
|
143
|
-
selected: data.selected,
|
|
144
|
-
style: data.style,
|
|
145
|
-
shape: data.shape,
|
|
146
|
-
onClick: (e) => {
|
|
147
|
-
this.onLegendClick(e, instance);
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
onLegendClick(e, instance) {
|
|
153
|
-
let allActions = this.legendAction == "auto";
|
|
154
|
-
let { data } = instance;
|
|
155
|
-
if (allActions || this.legendAction == "toggle") if (instance.set("active", !data.active)) return;
|
|
156
|
-
|
|
157
|
-
if (allActions || this.legendAction == "select") this.handleClick(e, instance);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
render(context, instance, key) {
|
|
161
|
-
let { data } = instance;
|
|
162
|
-
|
|
163
|
-
if (!data.active || data.x === null || data.y === null) return null;
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<MarkerComponent key={key} instance={instance} data={instance.data} shouldUpdate={instance.shouldUpdate}>
|
|
167
|
-
{this.renderChildren(context, instance)}
|
|
168
|
-
</MarkerComponent>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
handleMouseDown(e, instance) {
|
|
173
|
-
if (this.draggableX || this.draggableY) {
|
|
174
|
-
let svgEl = closest(e.target, (el) => el.tagName == "svg");
|
|
175
|
-
if (svgEl)
|
|
176
|
-
captureMouseOrTouch(
|
|
177
|
-
e,
|
|
178
|
-
(e, captureData) => {
|
|
179
|
-
this.handleDragMove(e, instance, captureData);
|
|
180
|
-
},
|
|
181
|
-
null,
|
|
182
|
-
{ svgEl, el: e.target },
|
|
183
|
-
e.target.style.cursor,
|
|
184
|
-
);
|
|
185
|
-
} else {
|
|
186
|
-
if (!this.selection.isDummy) this.selection.selectInstance(instance);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
handleClick(e, instance) {
|
|
191
|
-
if (this.onClick) instance.invoke("onClick", e, instance);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
handleDragMove(e, instance, captureData) {
|
|
195
|
-
let cursor = getCursorPos(e);
|
|
196
|
-
let svgBounds = getTopLevelBoundingClientRect(captureData.svgEl);
|
|
197
|
-
let { xAxis, yAxis } = instance;
|
|
198
|
-
if (this.draggableX && xAxis) {
|
|
199
|
-
let x = xAxis.trackValue(cursor.clientX - svgBounds.left, this.xOffset);
|
|
200
|
-
if (this.constrainX) x = xAxis.constrainValue(x);
|
|
201
|
-
instance.set("x", xAxis.encodeValue(x));
|
|
202
|
-
}
|
|
203
|
-
if (this.draggableY && yAxis) {
|
|
204
|
-
let y = yAxis.trackValue(cursor.clientY - svgBounds.top, this.yOffset);
|
|
205
|
-
if (this.constrainY) y = yAxis.constrainValue(y);
|
|
206
|
-
instance.set("y", yAxis.encodeValue(y));
|
|
207
|
-
}
|
|
208
|
-
tooltipMouseMove(e, instance, this.tooltip, { target: captureData.el });
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
Marker.prototype.xOffset = 0;
|
|
213
|
-
Marker.prototype.yOffset = 0;
|
|
214
|
-
Marker.prototype.size = 5;
|
|
215
|
-
Marker.prototype.anchors = "0.5 0.5 0.5 0.5";
|
|
216
|
-
|
|
217
|
-
Marker.prototype.xAxis = "x";
|
|
218
|
-
Marker.prototype.yAxis = "y";
|
|
219
|
-
|
|
220
|
-
Marker.prototype.baseClass = "marker";
|
|
221
|
-
Marker.prototype.draggableX = false;
|
|
222
|
-
Marker.prototype.draggableY = false;
|
|
223
|
-
Marker.prototype.draggable = false;
|
|
224
|
-
Marker.prototype.constrainX = false;
|
|
225
|
-
Marker.prototype.constrainY = false;
|
|
226
|
-
Marker.prototype.constrain = false;
|
|
227
|
-
Marker.prototype.legend = "legend";
|
|
228
|
-
Marker.prototype.legendAction = "auto";
|
|
229
|
-
Marker.prototype.shape = "circle";
|
|
230
|
-
Marker.prototype.styled = true;
|
|
231
|
-
Marker.prototype.hidden = false;
|
|
232
|
-
Marker.prototype.affectsAxes = true;
|
|
233
|
-
Marker.prototype.stackedY = false;
|
|
234
|
-
Marker.prototype.stackedX = false;
|
|
235
|
-
Marker.prototype.stack = "stack";
|
|
236
|
-
|
|
237
|
-
BoundedObject.alias("marker", Marker);
|
|
238
|
-
|
|
239
|
-
class MarkerComponent extends VDOM.Component {
|
|
240
|
-
shouldComponentUpdate(props) {
|
|
241
|
-
return props.shouldUpdate;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
render() {
|
|
245
|
-
let { instance, children, data } = this.props;
|
|
246
|
-
let { widget } = instance;
|
|
247
|
-
let { CSS, baseClass } = widget;
|
|
248
|
-
let { bounds, shape } = data;
|
|
249
|
-
let shapeRenderer = getShape(shape);
|
|
250
|
-
let shapeProps = {
|
|
251
|
-
className: CSS.element(baseClass, "shape", {
|
|
252
|
-
["color-" + data.colorIndex]: data.colorIndex != null,
|
|
253
|
-
selected: data.selected,
|
|
254
|
-
}),
|
|
255
|
-
style: data.style,
|
|
256
|
-
cx: (bounds.l + bounds.r) / 2,
|
|
257
|
-
cy: (bounds.t + bounds.b) / 2,
|
|
258
|
-
r: data.size / 2,
|
|
259
|
-
onMouseMove: (e) => {
|
|
260
|
-
tooltipMouseMove(e, instance, widget.tooltip);
|
|
261
|
-
},
|
|
262
|
-
onMouseLeave: (e) => {
|
|
263
|
-
tooltipMouseLeave(e, instance, widget.tooltip);
|
|
264
|
-
},
|
|
265
|
-
onMouseDown: (e) => {
|
|
266
|
-
widget.handleMouseDown(e, instance);
|
|
267
|
-
},
|
|
268
|
-
onTouchStart: (e) => {
|
|
269
|
-
widget.handleMouseDown(e, instance);
|
|
270
|
-
},
|
|
271
|
-
onClick: (e) => {
|
|
272
|
-
widget.handleClick(e, instance);
|
|
273
|
-
},
|
|
274
|
-
};
|
|
275
|
-
if (widget.tooltip) {
|
|
276
|
-
shapeProps.ref = (c) => {
|
|
277
|
-
this.el = c;
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return (
|
|
282
|
-
<g className={data.classNames}>
|
|
283
|
-
{!widget.hidden &&
|
|
284
|
-
shapeRenderer((bounds.l + bounds.r) / 2, (bounds.t + bounds.b) / 2, data.size, shapeProps)}
|
|
285
|
-
{children}
|
|
286
|
-
</g>
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
componentWillUnmount() {
|
|
291
|
-
tooltipParentWillUnmount(this.props.instance);
|
|
292
|
-
}
|
|
293
|
-
UNSAFE_componentWillReceiveProps(props) {
|
|
294
|
-
tooltipParentWillReceiveProps(this.el, props.instance, props.instance.widget.tooltip);
|
|
295
|
-
}
|
|
296
|
-
componentDidMount() {
|
|
297
|
-
tooltipParentDidMount(this.el, this.props.instance, this.props.instance.widget.tooltip);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
1
|
+
import { Widget, VDOM } from "../ui/Widget";
|
|
2
|
+
import { BoundedObject } from "../svg/BoundedObject";
|
|
3
|
+
import { Rect } from "../svg/util/Rect";
|
|
4
|
+
import {
|
|
5
|
+
tooltipMouseMove,
|
|
6
|
+
tooltipMouseLeave,
|
|
7
|
+
tooltipParentWillUnmount,
|
|
8
|
+
tooltipParentWillReceiveProps,
|
|
9
|
+
tooltipParentDidMount,
|
|
10
|
+
} from "../widgets/overlay/tooltip-ops";
|
|
11
|
+
import { captureMouseOrTouch, getCursorPos } from "../widgets/overlay/captureMouse";
|
|
12
|
+
import { closest } from "../util/DOM";
|
|
13
|
+
import { Selection } from "../ui/selection/Selection";
|
|
14
|
+
import { getShape } from "./shapes";
|
|
15
|
+
import { getTopLevelBoundingClientRect } from "../util/getTopLevelBoundingClientRect";
|
|
16
|
+
|
|
17
|
+
export class Marker extends BoundedObject {
|
|
18
|
+
init() {
|
|
19
|
+
this.selection = Selection.create(this.selection);
|
|
20
|
+
|
|
21
|
+
if (this.draggable) {
|
|
22
|
+
this.draggableX = true;
|
|
23
|
+
this.draggableY = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (this.constrain) {
|
|
27
|
+
this.constrainX = true;
|
|
28
|
+
this.constrainY = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
super.init();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declareData() {
|
|
35
|
+
var selection = this.selection.configureWidget(this);
|
|
36
|
+
|
|
37
|
+
return super.declareData(...arguments, selection, {
|
|
38
|
+
x: undefined,
|
|
39
|
+
y: undefined,
|
|
40
|
+
size: undefined,
|
|
41
|
+
shape: undefined,
|
|
42
|
+
disabled: undefined,
|
|
43
|
+
colorMap: undefined,
|
|
44
|
+
colorIndex: undefined,
|
|
45
|
+
colorName: undefined,
|
|
46
|
+
legendColorIndex: undefined,
|
|
47
|
+
name: undefined,
|
|
48
|
+
active: true,
|
|
49
|
+
stack: undefined,
|
|
50
|
+
stackedX: undefined,
|
|
51
|
+
stackedY: undefined,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
prepareData(context, instance) {
|
|
56
|
+
instance.axes = context.axes;
|
|
57
|
+
instance.xAxis = context.axes[this.xAxis];
|
|
58
|
+
instance.yAxis = context.axes[this.yAxis];
|
|
59
|
+
let { data } = instance;
|
|
60
|
+
data.selected = this.selection.isInstanceSelected(instance);
|
|
61
|
+
data.stateMods = {
|
|
62
|
+
selected: data.selected,
|
|
63
|
+
disabled: data.disabled,
|
|
64
|
+
selectable: !this.selection.isDummy,
|
|
65
|
+
"draggable-x": this.draggableX && !this.draggableY,
|
|
66
|
+
"draggable-y": this.draggableY && !this.draggableX,
|
|
67
|
+
"draggable-xy": this.draggableY && this.draggableX,
|
|
68
|
+
};
|
|
69
|
+
if (data.name && !data.colorName) data.colorName = data.name;
|
|
70
|
+
super.prepareData(context, instance);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
calculateBounds(context, instance) {
|
|
74
|
+
let { data, xAxis, yAxis } = instance;
|
|
75
|
+
|
|
76
|
+
let x, y;
|
|
77
|
+
|
|
78
|
+
if (data.x == null || data.y == null) {
|
|
79
|
+
let bounds = super.calculateBounds(context, instance);
|
|
80
|
+
x = (bounds.l + bounds.r) / 2;
|
|
81
|
+
y = (bounds.t + bounds.b) / 2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (data.x != null) x = data.stackedX ? xAxis.stack(data.stack, data.y, data.x) : xAxis.map(data.x);
|
|
85
|
+
|
|
86
|
+
if (data.y != null) y = data.stackedY ? yAxis.stack(data.stack, data.x, data.y) : yAxis.map(data.y);
|
|
87
|
+
|
|
88
|
+
return new Rect({
|
|
89
|
+
l: x - data.size / 2,
|
|
90
|
+
r: x + data.size / 2,
|
|
91
|
+
t: y - data.size / 2,
|
|
92
|
+
b: y + data.size / 2,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
explore(context, instance) {
|
|
97
|
+
let { data, xAxis, yAxis } = instance;
|
|
98
|
+
|
|
99
|
+
instance.colorMap = data.colorMap && context.getColorMap && context.getColorMap(data.colorMap);
|
|
100
|
+
if (instance.colorMap && data.colorName) instance.colorMap.acknowledge(data.colorName);
|
|
101
|
+
|
|
102
|
+
if (data.active) {
|
|
103
|
+
if (this.affectsAxes) {
|
|
104
|
+
if (xAxis && data.x != null) {
|
|
105
|
+
if (data.stackedX) xAxis.stacknowledge(data.stack, data.y, data.x);
|
|
106
|
+
else xAxis.acknowledge(data.x, 0, this.xOffset);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (yAxis && data.y != null) {
|
|
110
|
+
if (data.stackedY) yAxis.stacknowledge(data.stack, data.x, data.y);
|
|
111
|
+
else yAxis.acknowledge(data.y, 0, this.yOffset);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (context.pointReducer) context.pointReducer(data.x, data.y, data.name, data);
|
|
116
|
+
|
|
117
|
+
super.explore(context, instance);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
prepare(context, instance) {
|
|
122
|
+
let { data, xAxis, yAxis, colorMap } = instance;
|
|
123
|
+
|
|
124
|
+
if (colorMap && data.colorName) {
|
|
125
|
+
data.colorIndex = colorMap.map(data.colorName);
|
|
126
|
+
if (instance.cache("colorIndex", data.colorIndex)) instance.markShouldUpdate(context);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (data.active) {
|
|
130
|
+
if (xAxis && xAxis.shouldUpdate) instance.markShouldUpdate(context);
|
|
131
|
+
|
|
132
|
+
if (yAxis && yAxis.shouldUpdate) instance.markShouldUpdate(context);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
super.prepare(context, instance);
|
|
136
|
+
|
|
137
|
+
if (data.name && context.addLegendEntry)
|
|
138
|
+
context.addLegendEntry(this.legend, {
|
|
139
|
+
name: data.name,
|
|
140
|
+
active: data.active,
|
|
141
|
+
colorIndex: data.legendColorIndex || data.colorIndex,
|
|
142
|
+
disabled: data.disabled,
|
|
143
|
+
selected: data.selected,
|
|
144
|
+
style: data.style,
|
|
145
|
+
shape: data.shape,
|
|
146
|
+
onClick: (e) => {
|
|
147
|
+
this.onLegendClick(e, instance);
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
onLegendClick(e, instance) {
|
|
153
|
+
let allActions = this.legendAction == "auto";
|
|
154
|
+
let { data } = instance;
|
|
155
|
+
if (allActions || this.legendAction == "toggle") if (instance.set("active", !data.active)) return;
|
|
156
|
+
|
|
157
|
+
if (allActions || this.legendAction == "select") this.handleClick(e, instance);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
render(context, instance, key) {
|
|
161
|
+
let { data } = instance;
|
|
162
|
+
|
|
163
|
+
if (!data.active || data.x === null || data.y === null) return null;
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<MarkerComponent key={key} instance={instance} data={instance.data} shouldUpdate={instance.shouldUpdate}>
|
|
167
|
+
{this.renderChildren(context, instance)}
|
|
168
|
+
</MarkerComponent>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
handleMouseDown(e, instance) {
|
|
173
|
+
if (this.draggableX || this.draggableY) {
|
|
174
|
+
let svgEl = closest(e.target, (el) => el.tagName == "svg");
|
|
175
|
+
if (svgEl)
|
|
176
|
+
captureMouseOrTouch(
|
|
177
|
+
e,
|
|
178
|
+
(e, captureData) => {
|
|
179
|
+
this.handleDragMove(e, instance, captureData);
|
|
180
|
+
},
|
|
181
|
+
null,
|
|
182
|
+
{ svgEl, el: e.target },
|
|
183
|
+
e.target.style.cursor,
|
|
184
|
+
);
|
|
185
|
+
} else {
|
|
186
|
+
if (!this.selection.isDummy) this.selection.selectInstance(instance);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
handleClick(e, instance) {
|
|
191
|
+
if (this.onClick) instance.invoke("onClick", e, instance);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
handleDragMove(e, instance, captureData) {
|
|
195
|
+
let cursor = getCursorPos(e);
|
|
196
|
+
let svgBounds = getTopLevelBoundingClientRect(captureData.svgEl);
|
|
197
|
+
let { xAxis, yAxis } = instance;
|
|
198
|
+
if (this.draggableX && xAxis) {
|
|
199
|
+
let x = xAxis.trackValue(cursor.clientX - svgBounds.left, this.xOffset);
|
|
200
|
+
if (this.constrainX) x = xAxis.constrainValue(x);
|
|
201
|
+
instance.set("x", xAxis.encodeValue(x));
|
|
202
|
+
}
|
|
203
|
+
if (this.draggableY && yAxis) {
|
|
204
|
+
let y = yAxis.trackValue(cursor.clientY - svgBounds.top, this.yOffset);
|
|
205
|
+
if (this.constrainY) y = yAxis.constrainValue(y);
|
|
206
|
+
instance.set("y", yAxis.encodeValue(y));
|
|
207
|
+
}
|
|
208
|
+
tooltipMouseMove(e, instance, this.tooltip, { target: captureData.el });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
Marker.prototype.xOffset = 0;
|
|
213
|
+
Marker.prototype.yOffset = 0;
|
|
214
|
+
Marker.prototype.size = 5;
|
|
215
|
+
Marker.prototype.anchors = "0.5 0.5 0.5 0.5";
|
|
216
|
+
|
|
217
|
+
Marker.prototype.xAxis = "x";
|
|
218
|
+
Marker.prototype.yAxis = "y";
|
|
219
|
+
|
|
220
|
+
Marker.prototype.baseClass = "marker";
|
|
221
|
+
Marker.prototype.draggableX = false;
|
|
222
|
+
Marker.prototype.draggableY = false;
|
|
223
|
+
Marker.prototype.draggable = false;
|
|
224
|
+
Marker.prototype.constrainX = false;
|
|
225
|
+
Marker.prototype.constrainY = false;
|
|
226
|
+
Marker.prototype.constrain = false;
|
|
227
|
+
Marker.prototype.legend = "legend";
|
|
228
|
+
Marker.prototype.legendAction = "auto";
|
|
229
|
+
Marker.prototype.shape = "circle";
|
|
230
|
+
Marker.prototype.styled = true;
|
|
231
|
+
Marker.prototype.hidden = false;
|
|
232
|
+
Marker.prototype.affectsAxes = true;
|
|
233
|
+
Marker.prototype.stackedY = false;
|
|
234
|
+
Marker.prototype.stackedX = false;
|
|
235
|
+
Marker.prototype.stack = "stack";
|
|
236
|
+
|
|
237
|
+
BoundedObject.alias("marker", Marker);
|
|
238
|
+
|
|
239
|
+
class MarkerComponent extends VDOM.Component {
|
|
240
|
+
shouldComponentUpdate(props) {
|
|
241
|
+
return props.shouldUpdate;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
render() {
|
|
245
|
+
let { instance, children, data } = this.props;
|
|
246
|
+
let { widget } = instance;
|
|
247
|
+
let { CSS, baseClass } = widget;
|
|
248
|
+
let { bounds, shape } = data;
|
|
249
|
+
let shapeRenderer = getShape(shape);
|
|
250
|
+
let shapeProps = {
|
|
251
|
+
className: CSS.element(baseClass, "shape", {
|
|
252
|
+
["color-" + data.colorIndex]: data.colorIndex != null,
|
|
253
|
+
selected: data.selected,
|
|
254
|
+
}),
|
|
255
|
+
style: data.style,
|
|
256
|
+
cx: (bounds.l + bounds.r) / 2,
|
|
257
|
+
cy: (bounds.t + bounds.b) / 2,
|
|
258
|
+
r: data.size / 2,
|
|
259
|
+
onMouseMove: (e) => {
|
|
260
|
+
tooltipMouseMove(e, instance, widget.tooltip);
|
|
261
|
+
},
|
|
262
|
+
onMouseLeave: (e) => {
|
|
263
|
+
tooltipMouseLeave(e, instance, widget.tooltip);
|
|
264
|
+
},
|
|
265
|
+
onMouseDown: (e) => {
|
|
266
|
+
widget.handleMouseDown(e, instance);
|
|
267
|
+
},
|
|
268
|
+
onTouchStart: (e) => {
|
|
269
|
+
widget.handleMouseDown(e, instance);
|
|
270
|
+
},
|
|
271
|
+
onClick: (e) => {
|
|
272
|
+
widget.handleClick(e, instance);
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
if (widget.tooltip) {
|
|
276
|
+
shapeProps.ref = (c) => {
|
|
277
|
+
this.el = c;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<g className={data.classNames}>
|
|
283
|
+
{!widget.hidden &&
|
|
284
|
+
shapeRenderer((bounds.l + bounds.r) / 2, (bounds.t + bounds.b) / 2, data.size, shapeProps)}
|
|
285
|
+
{children}
|
|
286
|
+
</g>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
componentWillUnmount() {
|
|
291
|
+
tooltipParentWillUnmount(this.props.instance);
|
|
292
|
+
}
|
|
293
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
294
|
+
tooltipParentWillReceiveProps(this.el, props.instance, props.instance.widget.tooltip);
|
|
295
|
+
}
|
|
296
|
+
componentDidMount() {
|
|
297
|
+
tooltipParentDidMount(this.el, this.props.instance, this.props.instance.widget.tooltip);
|
|
298
|
+
}
|
|
299
|
+
}
|