victory-brush-container 36.9.2 → 37.0.0
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 +6 -0
- package/dist/victory-brush-container.js +1101 -1427
- package/dist/victory-brush-container.min.js +1 -1
- package/es/brush-helpers.js +301 -330
- package/es/victory-brush-container.js +160 -218
- package/lib/brush-helpers.js +301 -339
- package/lib/index.js +0 -4
- package/lib/victory-brush-container.js +160 -226
- package/package.json +2 -2
package/es/brush-helpers.js
CHANGED
|
@@ -1,192 +1,177 @@
|
|
|
1
1
|
import _defaults from "lodash/defaults";
|
|
2
2
|
import _throttle from "lodash/throttle";
|
|
3
|
-
|
|
4
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
-
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
-
|
|
8
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
|
|
10
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
-
|
|
12
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
17
|
-
|
|
18
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
-
|
|
20
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
|
-
|
|
22
3
|
import { Helpers as CoreHelpers, Selection } from "victory-core";
|
|
23
4
|
import isEqual from "react-fast-compare";
|
|
24
|
-
|
|
25
|
-
getDimension
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const Helpers = {
|
|
6
|
+
getDimension(props) {
|
|
7
|
+
const {
|
|
8
|
+
horizontal,
|
|
9
|
+
brushDimension
|
|
10
|
+
} = props;
|
|
29
11
|
if (!horizontal || !brushDimension) {
|
|
30
12
|
return brushDimension;
|
|
31
13
|
}
|
|
32
|
-
|
|
33
14
|
return brushDimension === "x" ? "y" : "x";
|
|
34
15
|
},
|
|
35
|
-
withinBounds
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
16
|
+
withinBounds(point, bounds, padding) {
|
|
17
|
+
const {
|
|
18
|
+
x1,
|
|
19
|
+
x2,
|
|
20
|
+
y1,
|
|
21
|
+
y2
|
|
22
|
+
} = CoreHelpers.mapValues(bounds, Number);
|
|
23
|
+
const {
|
|
24
|
+
x,
|
|
25
|
+
y
|
|
26
|
+
} = CoreHelpers.mapValues(point, Number);
|
|
27
|
+
const paddingValue = padding ? padding / 2 : 0;
|
|
47
28
|
return x + paddingValue >= Math.min(x1, x2) && x - paddingValue <= Math.max(x1, x2) && y + paddingValue >= Math.min(y1, y2) && y - paddingValue <= Math.max(y1, y2);
|
|
48
29
|
},
|
|
49
|
-
getDomainBox
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var fullCoords = Selection.getDomainCoordinates(props, fullDomainObject);
|
|
57
|
-
var selectedCoords = Selection.getDomainCoordinates(props, selectedDomainObject);
|
|
30
|
+
getDomainBox(props, fullDomain, selectedDomain) {
|
|
31
|
+
const brushDimension = this.getDimension(props);
|
|
32
|
+
const fullDomainObject = _defaults({}, fullDomain, props.domain);
|
|
33
|
+
const selectedDomainObject = _defaults({}, selectedDomain, fullDomainObject);
|
|
34
|
+
const fullCoords = Selection.getDomainCoordinates(props, fullDomainObject);
|
|
35
|
+
const selectedCoords = Selection.getDomainCoordinates(props, selectedDomainObject);
|
|
58
36
|
return {
|
|
59
|
-
x1: brushDimension !== "y" ? Math.min
|
|
60
|
-
x2: brushDimension !== "y" ? Math.max
|
|
61
|
-
y1: brushDimension !== "x" ? Math.min
|
|
62
|
-
y2: brushDimension !== "x" ? Math.max
|
|
37
|
+
x1: brushDimension !== "y" ? Math.min(...selectedCoords.x) : Math.min(...fullCoords.x),
|
|
38
|
+
x2: brushDimension !== "y" ? Math.max(...selectedCoords.x) : Math.max(...fullCoords.x),
|
|
39
|
+
y1: brushDimension !== "x" ? Math.min(...selectedCoords.y) : Math.min(...fullCoords.y),
|
|
40
|
+
y2: brushDimension !== "x" ? Math.max(...selectedCoords.y) : Math.max(...fullCoords.y)
|
|
63
41
|
};
|
|
64
42
|
},
|
|
65
|
-
getHandles
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
43
|
+
getHandles(props, domainBox) {
|
|
44
|
+
const brushDimension = this.getDimension(props);
|
|
45
|
+
const {
|
|
46
|
+
x1,
|
|
47
|
+
x2,
|
|
48
|
+
y1,
|
|
49
|
+
y2
|
|
50
|
+
} = domainBox;
|
|
51
|
+
const minX = Math.min(x1, x2);
|
|
52
|
+
const maxX = Math.max(x1, x2);
|
|
53
|
+
const minY = Math.min(y1, y2);
|
|
54
|
+
const maxY = Math.max(y1, y2);
|
|
55
|
+
const handleWidth = props.handleWidth / 2;
|
|
76
56
|
return {
|
|
77
57
|
left: brushDimension !== "y" && {
|
|
78
58
|
x1: minX - handleWidth,
|
|
79
59
|
x2: minX + handleWidth,
|
|
80
|
-
y1
|
|
81
|
-
y2
|
|
60
|
+
y1,
|
|
61
|
+
y2
|
|
82
62
|
},
|
|
83
63
|
right: brushDimension !== "y" && {
|
|
84
64
|
x1: maxX - handleWidth,
|
|
85
65
|
x2: maxX + handleWidth,
|
|
86
|
-
y1
|
|
87
|
-
y2
|
|
66
|
+
y1,
|
|
67
|
+
y2
|
|
88
68
|
},
|
|
89
69
|
top: brushDimension !== "x" && {
|
|
90
|
-
x1
|
|
91
|
-
x2
|
|
70
|
+
x1,
|
|
71
|
+
x2,
|
|
92
72
|
y1: minY - handleWidth,
|
|
93
73
|
y2: minY + handleWidth
|
|
94
74
|
},
|
|
95
75
|
bottom: brushDimension !== "x" && {
|
|
96
|
-
x1
|
|
97
|
-
x2
|
|
76
|
+
x1,
|
|
77
|
+
x2,
|
|
98
78
|
y1: maxY - handleWidth,
|
|
99
79
|
y2: maxY + handleWidth
|
|
100
80
|
}
|
|
101
81
|
};
|
|
102
82
|
},
|
|
103
|
-
getActiveHandles
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var handles = this.getHandles(props, domainBox);
|
|
107
|
-
var activeHandles = ["top", "bottom", "left", "right"].reduce(function (memo, opt) {
|
|
108
|
-
return handles[opt] && _this.withinBounds(point, handles[opt]) ? memo.concat(opt) : memo;
|
|
109
|
-
}, []);
|
|
83
|
+
getActiveHandles(point, props, domainBox) {
|
|
84
|
+
const handles = this.getHandles(props, domainBox);
|
|
85
|
+
const activeHandles = ["top", "bottom", "left", "right"].reduce((memo, opt) => handles[opt] && this.withinBounds(point, handles[opt]) ? memo.concat(opt) : memo, []);
|
|
110
86
|
return activeHandles.length && activeHandles;
|
|
111
87
|
},
|
|
112
|
-
getResizeMutation
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
88
|
+
getResizeMutation(box, handles) {
|
|
89
|
+
const {
|
|
90
|
+
x1,
|
|
91
|
+
y1,
|
|
92
|
+
x2,
|
|
93
|
+
y2
|
|
94
|
+
} = box;
|
|
95
|
+
const mutations = {
|
|
118
96
|
left: {
|
|
119
97
|
x1: Math.max(x1, x2),
|
|
120
98
|
x2: Math.min(x1, x2),
|
|
121
|
-
y1
|
|
122
|
-
y2
|
|
99
|
+
y1,
|
|
100
|
+
y2
|
|
123
101
|
},
|
|
124
102
|
right: {
|
|
125
103
|
x1: Math.min(x1, x2),
|
|
126
104
|
x2: Math.max(x1, x2),
|
|
127
|
-
y1
|
|
128
|
-
y2
|
|
105
|
+
y1,
|
|
106
|
+
y2
|
|
129
107
|
},
|
|
130
108
|
top: {
|
|
131
109
|
y1: Math.max(y1, y2),
|
|
132
110
|
y2: Math.min(y1, y2),
|
|
133
|
-
x1
|
|
134
|
-
x2
|
|
111
|
+
x1,
|
|
112
|
+
x2
|
|
135
113
|
},
|
|
136
114
|
bottom: {
|
|
137
115
|
y1: Math.min(y1, y2),
|
|
138
116
|
y2: Math.max(y1, y2),
|
|
139
|
-
x1
|
|
140
|
-
x2
|
|
117
|
+
x1,
|
|
118
|
+
x2
|
|
141
119
|
}
|
|
142
120
|
};
|
|
143
|
-
return handles.reduce(
|
|
121
|
+
return handles.reduce((memo, current) => {
|
|
144
122
|
return Object.assign(memo, mutations[current]);
|
|
145
123
|
}, {});
|
|
146
124
|
},
|
|
147
|
-
getMinimumDomain
|
|
125
|
+
getMinimumDomain() {
|
|
148
126
|
return {
|
|
149
127
|
x: [0, 1 / Number.MAX_SAFE_INTEGER],
|
|
150
128
|
y: [0, 1 / Number.MAX_SAFE_INTEGER]
|
|
151
129
|
};
|
|
152
130
|
},
|
|
153
|
-
getDefaultBrushArea
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
131
|
+
getDefaultBrushArea(targetProps, cachedDomain, evt) {
|
|
132
|
+
const {
|
|
133
|
+
domain,
|
|
134
|
+
fullDomain,
|
|
135
|
+
scale,
|
|
136
|
+
horizontal,
|
|
137
|
+
allowResize
|
|
138
|
+
} = targetProps;
|
|
139
|
+
const defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea;
|
|
161
140
|
if (defaultBrushArea === "none") {
|
|
162
141
|
return this.getMinimumDomain();
|
|
163
142
|
} else if (defaultBrushArea === "disable") {
|
|
164
143
|
return cachedDomain;
|
|
165
144
|
} else if (defaultBrushArea === "move") {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
145
|
+
const brushBox = this.getDomainBox(targetProps, fullDomain, cachedDomain);
|
|
146
|
+
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
|
|
147
|
+
const pannedBox = this.panBox({
|
|
148
|
+
...targetProps,
|
|
149
|
+
...brushBox,
|
|
169
150
|
brushDomain: cachedDomain,
|
|
170
151
|
startX: (brushBox.x1 + brushBox.x2) / 2,
|
|
171
152
|
startY: (brushBox.y1 + brushBox.y2) / 2
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return Selection.getBounds(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
153
|
+
}, Selection.getSVGEventCoordinates(evt, parentSVG));
|
|
154
|
+
const fullDomainBox = targetProps.fullDomainBox || this.getDomainBox(targetProps, fullDomain);
|
|
155
|
+
const constrainedBox = this.constrainBox(pannedBox, fullDomainBox);
|
|
156
|
+
return Selection.getBounds({
|
|
157
|
+
...constrainedBox,
|
|
158
|
+
scale,
|
|
159
|
+
horizontal
|
|
160
|
+
});
|
|
179
161
|
}
|
|
180
|
-
|
|
181
162
|
return domain;
|
|
182
163
|
},
|
|
183
|
-
getSelectionMutation
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
164
|
+
getSelectionMutation(point, box, brushDimension) {
|
|
165
|
+
const {
|
|
166
|
+
x,
|
|
167
|
+
y
|
|
168
|
+
} = point;
|
|
169
|
+
const {
|
|
170
|
+
x1,
|
|
171
|
+
x2,
|
|
172
|
+
y1,
|
|
173
|
+
y2
|
|
174
|
+
} = box;
|
|
190
175
|
return {
|
|
191
176
|
x1: brushDimension !== "y" ? x : x1,
|
|
192
177
|
y1: brushDimension !== "x" ? y : y1,
|
|
@@ -194,25 +179,26 @@ var Helpers = {
|
|
|
194
179
|
y2: brushDimension !== "x" ? y : y2
|
|
195
180
|
};
|
|
196
181
|
},
|
|
197
|
-
panBox
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
182
|
+
panBox(props, point) {
|
|
183
|
+
const {
|
|
184
|
+
domain,
|
|
185
|
+
startX,
|
|
186
|
+
startY
|
|
187
|
+
} = props;
|
|
188
|
+
const brushDimension = this.getDimension(props);
|
|
189
|
+
const brushDomain = _defaults({}, props.brushDomain, domain);
|
|
190
|
+
const fullDomain = _defaults({}, props.fullDomain, domain);
|
|
191
|
+
const {
|
|
192
|
+
x1,
|
|
193
|
+
x2,
|
|
194
|
+
y1,
|
|
195
|
+
y2
|
|
196
|
+
} = props.x1 ? props : this.getDomainBox(props, fullDomain, brushDomain);
|
|
197
|
+
const {
|
|
198
|
+
x,
|
|
199
|
+
y
|
|
200
|
+
} = point;
|
|
201
|
+
const delta = {
|
|
216
202
|
x: startX ? startX - x : 0,
|
|
217
203
|
y: startY ? startY - y : 0
|
|
218
204
|
};
|
|
@@ -223,13 +209,13 @@ var Helpers = {
|
|
|
223
209
|
y2: brushDimension !== "x" ? Math.max(y1, y2) - delta.y : Math.max(y1, y2)
|
|
224
210
|
};
|
|
225
211
|
},
|
|
226
|
-
constrainBox
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
212
|
+
constrainBox(box, fullDomainBox) {
|
|
213
|
+
const {
|
|
214
|
+
x1,
|
|
215
|
+
y1,
|
|
216
|
+
x2,
|
|
217
|
+
y2
|
|
218
|
+
} = CoreHelpers.mapValues(fullDomainBox, Number);
|
|
233
219
|
return {
|
|
234
220
|
x1: box.x2 > x2 ? x2 - Math.abs(box.x2 - box.x1) : Math.max(box.x1, x1),
|
|
235
221
|
y1: box.y2 > y2 ? y2 - Math.abs(box.y2 - box.y1) : Math.max(box.y1, y1),
|
|
@@ -237,271 +223,257 @@ var Helpers = {
|
|
|
237
223
|
y2: box.y1 < y1 ? y1 + Math.abs(box.y2 - box.y1) : Math.min(box.y2, y2)
|
|
238
224
|
};
|
|
239
225
|
},
|
|
240
|
-
constrainPoint
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
226
|
+
constrainPoint(point, fullDomainBox) {
|
|
227
|
+
const {
|
|
228
|
+
x1,
|
|
229
|
+
y1,
|
|
230
|
+
x2,
|
|
231
|
+
y2
|
|
232
|
+
} = CoreHelpers.mapValues(fullDomainBox, Number);
|
|
247
233
|
return {
|
|
248
234
|
x: Math.min(Math.max(point.x, x1), x2),
|
|
249
235
|
y: Math.min(Math.max(point.y, y1), y2)
|
|
250
236
|
};
|
|
251
237
|
},
|
|
252
|
-
hasMoved
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
238
|
+
hasMoved(props) {
|
|
239
|
+
const {
|
|
240
|
+
x1,
|
|
241
|
+
x2,
|
|
242
|
+
y1,
|
|
243
|
+
y2,
|
|
244
|
+
mouseMoveThreshold
|
|
245
|
+
} = props;
|
|
246
|
+
const brushDimension = this.getDimension(props);
|
|
247
|
+
const xMoved = Math.abs(x1 - x2) >= mouseMoveThreshold;
|
|
248
|
+
const yMoved = Math.abs(y1 - y2) >= mouseMoveThreshold;
|
|
262
249
|
switch (brushDimension) {
|
|
263
250
|
case "x":
|
|
264
251
|
return xMoved;
|
|
265
|
-
|
|
266
252
|
case "y":
|
|
267
253
|
return yMoved;
|
|
268
|
-
|
|
269
254
|
default:
|
|
270
255
|
return xMoved || yMoved;
|
|
271
256
|
}
|
|
272
257
|
},
|
|
273
258
|
// eslint-disable-next-line max-statements, complexity
|
|
274
|
-
onMouseDown
|
|
275
|
-
var _this2 = this;
|
|
276
|
-
|
|
259
|
+
onMouseDown(evt, targetProps) {
|
|
277
260
|
evt.preventDefault();
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
261
|
+
const {
|
|
262
|
+
handleWidth,
|
|
263
|
+
cachedBrushDomain,
|
|
264
|
+
domain,
|
|
265
|
+
allowResize,
|
|
266
|
+
allowDrag,
|
|
267
|
+
allowDraw
|
|
268
|
+
} = targetProps;
|
|
269
|
+
const brushDimension = this.getDimension(targetProps);
|
|
270
|
+
const defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea;
|
|
271
|
+
// Don't trigger events for static brushes
|
|
287
272
|
if (!allowResize && !allowDrag) {
|
|
288
273
|
return {};
|
|
289
274
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
275
|
+
const fullDomainBox = targetProps.fullDomainBox || this.getDomainBox(targetProps, domain);
|
|
276
|
+
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
|
|
277
|
+
const {
|
|
278
|
+
x,
|
|
279
|
+
y
|
|
280
|
+
} = Selection.getSVGEventCoordinates(evt, parentSVG);
|
|
281
|
+
// Ignore events that occur outside of the maximum domain region
|
|
299
282
|
if (!this.withinBounds({
|
|
300
|
-
x
|
|
301
|
-
y
|
|
283
|
+
x,
|
|
284
|
+
y
|
|
302
285
|
}, fullDomainBox, handleWidth)) {
|
|
303
286
|
return {};
|
|
304
287
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}, targetProps, domainBox); // If the event occurs in any of the handle regions, start a resize
|
|
314
|
-
|
|
288
|
+
const brushDomain = _defaults({}, targetProps.brushDomain, domain);
|
|
289
|
+
const currentDomain = isEqual(brushDomain, cachedBrushDomain) ? targetProps.currentDomain || brushDomain || domain : brushDomain || domain;
|
|
290
|
+
const domainBox = this.getDomainBox(targetProps, domain, currentDomain);
|
|
291
|
+
const activeHandles = allowResize && this.getActiveHandles({
|
|
292
|
+
x,
|
|
293
|
+
y
|
|
294
|
+
}, targetProps, domainBox);
|
|
295
|
+
// If the event occurs in any of the handle regions, start a resize
|
|
315
296
|
if (activeHandles) {
|
|
316
297
|
return [{
|
|
317
298
|
target: "parent",
|
|
318
|
-
mutation:
|
|
319
|
-
return
|
|
299
|
+
mutation: () => {
|
|
300
|
+
return {
|
|
320
301
|
isSelecting: true,
|
|
321
|
-
domainBox
|
|
322
|
-
fullDomainBox
|
|
302
|
+
domainBox,
|
|
303
|
+
fullDomainBox,
|
|
323
304
|
cachedBrushDomain: brushDomain,
|
|
324
|
-
currentDomain
|
|
325
|
-
parentSVG
|
|
326
|
-
|
|
305
|
+
currentDomain,
|
|
306
|
+
parentSVG,
|
|
307
|
+
...this.getResizeMutation(domainBox, activeHandles)
|
|
308
|
+
};
|
|
327
309
|
}
|
|
328
310
|
}];
|
|
329
311
|
} else if (this.withinBounds({
|
|
330
|
-
x
|
|
331
|
-
y
|
|
312
|
+
x,
|
|
313
|
+
y
|
|
332
314
|
}, domainBox) && !isEqual(domain, currentDomain)) {
|
|
333
315
|
// if the event occurs within a selected region start a panning event, unless the whole
|
|
334
316
|
// domain is selected
|
|
335
317
|
return [{
|
|
336
318
|
target: "parent",
|
|
337
|
-
mutation:
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
319
|
+
mutation: () => ({
|
|
320
|
+
isPanning: allowDrag,
|
|
321
|
+
startX: x,
|
|
322
|
+
startY: y,
|
|
323
|
+
domainBox,
|
|
324
|
+
fullDomainBox,
|
|
325
|
+
currentDomain,
|
|
326
|
+
cachedBrushDomain: brushDomain,
|
|
327
|
+
parentSVG,
|
|
328
|
+
...domainBox // set x1, x2, y1, y2
|
|
329
|
+
})
|
|
349
330
|
}];
|
|
350
|
-
}
|
|
331
|
+
}
|
|
332
|
+
// if the event occurs outside the region, or if the whole domain is selected,
|
|
351
333
|
// start a new selection
|
|
352
|
-
|
|
353
|
-
|
|
354
334
|
return allowDraw ? [{
|
|
355
335
|
target: "parent",
|
|
356
|
-
mutation:
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
336
|
+
mutation: () => ({
|
|
337
|
+
isSelecting: allowResize || defaultBrushArea === "move",
|
|
338
|
+
domainBox,
|
|
339
|
+
fullDomainBox,
|
|
340
|
+
parentSVG,
|
|
341
|
+
cachedBrushDomain: brushDomain,
|
|
342
|
+
cachedCurrentDomain: currentDomain,
|
|
343
|
+
currentDomain: this.getMinimumDomain(),
|
|
344
|
+
...this.getSelectionMutation({
|
|
345
|
+
x,
|
|
346
|
+
y
|
|
347
|
+
}, domainBox, brushDimension)
|
|
348
|
+
})
|
|
370
349
|
}] : {};
|
|
371
350
|
},
|
|
372
351
|
// eslint-disable-next-line max-statements, complexity
|
|
373
|
-
onGlobalMouseMove
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
352
|
+
onGlobalMouseMove(evt, targetProps) {
|
|
353
|
+
const {
|
|
354
|
+
scale,
|
|
355
|
+
isPanning,
|
|
356
|
+
isSelecting,
|
|
357
|
+
fullDomainBox,
|
|
358
|
+
onBrushDomainChange,
|
|
359
|
+
allowResize,
|
|
360
|
+
allowDrag,
|
|
361
|
+
horizontal,
|
|
362
|
+
mouseMoveThreshold,
|
|
363
|
+
parentSVG
|
|
364
|
+
} = targetProps;
|
|
365
|
+
const brushDimension = this.getDimension(targetProps);
|
|
366
|
+
const {
|
|
367
|
+
x,
|
|
368
|
+
y
|
|
369
|
+
} = Selection.getSVGEventCoordinates(evt, parentSVG);
|
|
370
|
+
if (!allowResize && !allowDrag || mouseMoveThreshold > 0 && !this.hasMoved({
|
|
371
|
+
...targetProps,
|
|
391
372
|
x2: x,
|
|
392
373
|
y2: y
|
|
393
|
-
}))
|
|
374
|
+
})) {
|
|
394
375
|
return {};
|
|
395
376
|
}
|
|
396
|
-
|
|
397
377
|
if (allowDrag && isPanning) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
378
|
+
const {
|
|
379
|
+
startX,
|
|
380
|
+
startY
|
|
381
|
+
} = targetProps;
|
|
382
|
+
const pannedBox = this.panBox(targetProps, {
|
|
383
|
+
x,
|
|
384
|
+
y
|
|
403
385
|
});
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
currentDomain
|
|
412
|
-
parentSVG
|
|
386
|
+
const constrainedBox = this.constrainBox(pannedBox, fullDomainBox);
|
|
387
|
+
const currentDomain = Selection.getBounds({
|
|
388
|
+
...constrainedBox,
|
|
389
|
+
scale,
|
|
390
|
+
horizontal
|
|
391
|
+
});
|
|
392
|
+
const mutatedProps = {
|
|
393
|
+
currentDomain,
|
|
394
|
+
parentSVG,
|
|
413
395
|
startX: pannedBox.x2 >= fullDomainBox.x2 || pannedBox.x1 <= fullDomainBox.x1 ? startX : x,
|
|
414
|
-
startY: pannedBox.y2 >= fullDomainBox.y2 || pannedBox.y1 <= fullDomainBox.y1 ? startY : y
|
|
415
|
-
|
|
416
|
-
|
|
396
|
+
startY: pannedBox.y2 >= fullDomainBox.y2 || pannedBox.y1 <= fullDomainBox.y1 ? startY : y,
|
|
397
|
+
...constrainedBox
|
|
398
|
+
};
|
|
417
399
|
if (CoreHelpers.isFunction(onBrushDomainChange)) {
|
|
418
400
|
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
|
|
419
401
|
}
|
|
420
|
-
|
|
421
402
|
return [{
|
|
422
403
|
target: "parent",
|
|
423
|
-
mutation:
|
|
424
|
-
return mutatedProps;
|
|
425
|
-
}
|
|
404
|
+
mutation: () => mutatedProps
|
|
426
405
|
}];
|
|
427
406
|
} else if (allowResize && isSelecting) {
|
|
428
|
-
|
|
407
|
+
const {
|
|
408
|
+
x: x2,
|
|
409
|
+
y: y2
|
|
410
|
+
} = this.constrainPoint({
|
|
429
411
|
x: brushDimension !== "y" ? x : targetProps.x2,
|
|
430
412
|
y: brushDimension !== "x" ? y : targetProps.y2
|
|
431
|
-
}, fullDomainBox)
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
var _currentDomain = Selection.getBounds({
|
|
436
|
-
x2: x2,
|
|
437
|
-
y2: y2,
|
|
413
|
+
}, fullDomainBox);
|
|
414
|
+
const currentDomain = Selection.getBounds({
|
|
415
|
+
x2,
|
|
416
|
+
y2,
|
|
438
417
|
x1: targetProps.x1,
|
|
439
418
|
y1: targetProps.y1,
|
|
440
|
-
scale
|
|
441
|
-
horizontal
|
|
419
|
+
scale,
|
|
420
|
+
horizontal
|
|
442
421
|
});
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
parentSVG: parentSVG
|
|
422
|
+
const mutatedProps = {
|
|
423
|
+
x2,
|
|
424
|
+
y2,
|
|
425
|
+
currentDomain,
|
|
426
|
+
parentSVG
|
|
449
427
|
};
|
|
450
|
-
|
|
451
428
|
if (CoreHelpers.isFunction(onBrushDomainChange)) {
|
|
452
|
-
onBrushDomainChange(
|
|
429
|
+
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
|
|
453
430
|
}
|
|
454
|
-
|
|
455
431
|
return [{
|
|
456
432
|
target: "parent",
|
|
457
|
-
mutation:
|
|
458
|
-
return _mutatedProps;
|
|
459
|
-
}
|
|
433
|
+
mutation: () => mutatedProps
|
|
460
434
|
}];
|
|
461
435
|
}
|
|
462
|
-
|
|
463
436
|
return {};
|
|
464
437
|
},
|
|
465
438
|
// eslint-disable-next-line complexity
|
|
466
|
-
onGlobalMouseUp
|
|
439
|
+
onGlobalMouseUp(evt, targetProps) {
|
|
467
440
|
// if a panning or selection has not been started, ignore the event
|
|
468
441
|
if (!targetProps.isPanning && !targetProps.isSelecting) {
|
|
469
442
|
return {};
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
443
|
+
}
|
|
444
|
+
// eslint-disable-line max-statements, complexity
|
|
445
|
+
const {
|
|
446
|
+
x1,
|
|
447
|
+
y1,
|
|
448
|
+
x2,
|
|
449
|
+
y2,
|
|
450
|
+
isPanning,
|
|
451
|
+
isSelecting,
|
|
452
|
+
onBrushDomainChange,
|
|
453
|
+
onBrushDomainChangeEnd,
|
|
454
|
+
onBrushCleared,
|
|
455
|
+
currentDomain,
|
|
456
|
+
allowResize,
|
|
457
|
+
allowDrag
|
|
458
|
+
} = targetProps;
|
|
459
|
+
const defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea;
|
|
460
|
+
const defaultBrushHasArea = defaultBrushArea !== undefined && defaultBrushArea !== "none";
|
|
461
|
+
const mutatedProps = {
|
|
488
462
|
isPanning: false,
|
|
489
463
|
isSelecting: false
|
|
490
|
-
};
|
|
464
|
+
};
|
|
491
465
|
|
|
466
|
+
// if the mouse hasn't moved since a mouseDown event, select the default brush area
|
|
492
467
|
if ((allowResize || defaultBrushHasArea) && (x1 === x2 || y1 === y2)) {
|
|
493
|
-
|
|
494
|
-
|
|
468
|
+
const cachedDomain = targetProps.cachedCurrentDomain || currentDomain;
|
|
469
|
+
const defaultDomain = this.getDefaultBrushArea(targetProps, cachedDomain, evt);
|
|
495
470
|
mutatedProps.currentDomain = defaultDomain;
|
|
496
|
-
|
|
497
471
|
if (CoreHelpers.isFunction(onBrushDomainChange)) {
|
|
498
472
|
onBrushDomainChange(defaultDomain, _defaults({}, mutatedProps, targetProps));
|
|
499
473
|
}
|
|
500
|
-
|
|
501
474
|
if (CoreHelpers.isFunction(onBrushDomainChangeEnd)) {
|
|
502
475
|
onBrushDomainChangeEnd(defaultDomain, _defaults({}, mutatedProps, targetProps));
|
|
503
476
|
}
|
|
504
|
-
|
|
505
477
|
if (CoreHelpers.isFunction(onBrushCleared)) {
|
|
506
478
|
onBrushCleared(defaultDomain, _defaults({}, mutatedProps, targetProps));
|
|
507
479
|
}
|
|
@@ -510,21 +482,20 @@ var Helpers = {
|
|
|
510
482
|
onBrushDomainChangeEnd(currentDomain, _defaults({}, mutatedProps, targetProps));
|
|
511
483
|
}
|
|
512
484
|
}
|
|
513
|
-
|
|
514
485
|
return [{
|
|
515
486
|
target: "parent",
|
|
516
|
-
mutation:
|
|
517
|
-
return mutatedProps;
|
|
518
|
-
}
|
|
487
|
+
mutation: () => mutatedProps
|
|
519
488
|
}];
|
|
520
489
|
}
|
|
521
490
|
};
|
|
522
|
-
export
|
|
491
|
+
export const BrushHelpers = {
|
|
492
|
+
...Helpers,
|
|
523
493
|
onMouseDown: Helpers.onMouseDown.bind(Helpers),
|
|
524
494
|
onGlobalMouseUp: Helpers.onGlobalMouseUp.bind(Helpers),
|
|
525
|
-
onGlobalMouseMove: _throttle(Helpers.onGlobalMouseMove.bind(Helpers), 16,
|
|
495
|
+
onGlobalMouseMove: _throttle(Helpers.onGlobalMouseMove.bind(Helpers), 16,
|
|
496
|
+
// eslint-disable-line no-magic-numbers
|
|
526
497
|
{
|
|
527
498
|
leading: true,
|
|
528
499
|
trailing: false
|
|
529
500
|
})
|
|
530
|
-
}
|
|
501
|
+
};
|