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.
@@ -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
- var Helpers = {
25
- getDimension: function (props) {
26
- var horizontal = props.horizontal,
27
- brushDimension = props.brushDimension;
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: function (point, bounds, padding) {
36
- var _CoreHelpers$mapValue = CoreHelpers.mapValues(bounds, Number),
37
- x1 = _CoreHelpers$mapValue.x1,
38
- x2 = _CoreHelpers$mapValue.x2,
39
- y1 = _CoreHelpers$mapValue.y1,
40
- y2 = _CoreHelpers$mapValue.y2;
41
-
42
- var _CoreHelpers$mapValue2 = CoreHelpers.mapValues(point, Number),
43
- x = _CoreHelpers$mapValue2.x,
44
- y = _CoreHelpers$mapValue2.y;
45
-
46
- var paddingValue = padding ? padding / 2 : 0;
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: function (props, fullDomain, selectedDomain) {
50
- var brushDimension = this.getDimension(props);
51
-
52
- var fullDomainObject = _defaults({}, fullDomain, props.domain);
53
-
54
- var selectedDomainObject = _defaults({}, selectedDomain, fullDomainObject);
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.apply(Math, _toConsumableArray(selectedCoords.x)) : Math.min.apply(Math, _toConsumableArray(fullCoords.x)),
60
- x2: brushDimension !== "y" ? Math.max.apply(Math, _toConsumableArray(selectedCoords.x)) : Math.max.apply(Math, _toConsumableArray(fullCoords.x)),
61
- y1: brushDimension !== "x" ? Math.min.apply(Math, _toConsumableArray(selectedCoords.y)) : Math.min.apply(Math, _toConsumableArray(fullCoords.y)),
62
- y2: brushDimension !== "x" ? Math.max.apply(Math, _toConsumableArray(selectedCoords.y)) : Math.max.apply(Math, _toConsumableArray(fullCoords.y))
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: function (props, domainBox) {
66
- var brushDimension = this.getDimension(props);
67
- var x1 = domainBox.x1,
68
- x2 = domainBox.x2,
69
- y1 = domainBox.y1,
70
- y2 = domainBox.y2;
71
- var minX = Math.min(x1, x2);
72
- var maxX = Math.max(x1, x2);
73
- var minY = Math.min(y1, y2);
74
- var maxY = Math.max(y1, y2);
75
- var handleWidth = props.handleWidth / 2;
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: y1,
81
- y2: y2
60
+ y1,
61
+ y2
82
62
  },
83
63
  right: brushDimension !== "y" && {
84
64
  x1: maxX - handleWidth,
85
65
  x2: maxX + handleWidth,
86
- y1: y1,
87
- y2: y2
66
+ y1,
67
+ y2
88
68
  },
89
69
  top: brushDimension !== "x" && {
90
- x1: x1,
91
- x2: x2,
70
+ x1,
71
+ x2,
92
72
  y1: minY - handleWidth,
93
73
  y2: minY + handleWidth
94
74
  },
95
75
  bottom: brushDimension !== "x" && {
96
- x1: x1,
97
- x2: x2,
76
+ x1,
77
+ x2,
98
78
  y1: maxY - handleWidth,
99
79
  y2: maxY + handleWidth
100
80
  }
101
81
  };
102
82
  },
103
- getActiveHandles: function (point, props, domainBox) {
104
- var _this = this;
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: function (box, handles) {
113
- var x1 = box.x1,
114
- y1 = box.y1,
115
- x2 = box.x2,
116
- y2 = box.y2;
117
- var mutations = {
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: y1,
122
- y2: 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: y1,
128
- y2: 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: x1,
134
- x2: 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: x1,
140
- x2: x2
117
+ x1,
118
+ x2
141
119
  }
142
120
  };
143
- return handles.reduce(function (memo, current) {
121
+ return handles.reduce((memo, current) => {
144
122
  return Object.assign(memo, mutations[current]);
145
123
  }, {});
146
124
  },
147
- getMinimumDomain: function () {
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: function (targetProps, cachedDomain, evt) {
154
- var domain = targetProps.domain,
155
- fullDomain = targetProps.fullDomain,
156
- scale = targetProps.scale,
157
- horizontal = targetProps.horizontal,
158
- allowResize = targetProps.allowResize;
159
- var defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea;
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
- var brushBox = this.getDomainBox(targetProps, fullDomain, cachedDomain);
167
- var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
168
- var pannedBox = this.panBox(_objectSpread(_objectSpread(_objectSpread({}, targetProps), brushBox), {}, {
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
- }), Selection.getSVGEventCoordinates(evt, parentSVG));
173
- var fullDomainBox = targetProps.fullDomainBox || this.getDomainBox(targetProps, fullDomain);
174
- var constrainedBox = this.constrainBox(pannedBox, fullDomainBox);
175
- return Selection.getBounds(_objectSpread(_objectSpread({}, constrainedBox), {}, {
176
- scale: scale,
177
- horizontal: horizontal
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: function (point, box, brushDimension) {
184
- var x = point.x,
185
- y = point.y;
186
- var x1 = box.x1,
187
- x2 = box.x2,
188
- y1 = box.y1,
189
- y2 = box.y2;
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: function (props, point) {
198
- var domain = props.domain,
199
- startX = props.startX,
200
- startY = props.startY;
201
- var brushDimension = this.getDimension(props);
202
-
203
- var brushDomain = _defaults({}, props.brushDomain, domain);
204
-
205
- var fullDomain = _defaults({}, props.fullDomain, domain);
206
-
207
- var _ref = props.x1 ? props : this.getDomainBox(props, fullDomain, brushDomain),
208
- x1 = _ref.x1,
209
- x2 = _ref.x2,
210
- y1 = _ref.y1,
211
- y2 = _ref.y2;
212
-
213
- var x = point.x,
214
- y = point.y;
215
- var delta = {
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: function (box, fullDomainBox) {
227
- var _CoreHelpers$mapValue3 = CoreHelpers.mapValues(fullDomainBox, Number),
228
- x1 = _CoreHelpers$mapValue3.x1,
229
- y1 = _CoreHelpers$mapValue3.y1,
230
- x2 = _CoreHelpers$mapValue3.x2,
231
- y2 = _CoreHelpers$mapValue3.y2;
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: function (point, fullDomainBox) {
241
- var _CoreHelpers$mapValue4 = CoreHelpers.mapValues(fullDomainBox, Number),
242
- x1 = _CoreHelpers$mapValue4.x1,
243
- y1 = _CoreHelpers$mapValue4.y1,
244
- x2 = _CoreHelpers$mapValue4.x2,
245
- y2 = _CoreHelpers$mapValue4.y2;
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: function (props) {
253
- var x1 = props.x1,
254
- x2 = props.x2,
255
- y1 = props.y1,
256
- y2 = props.y2,
257
- mouseMoveThreshold = props.mouseMoveThreshold;
258
- var brushDimension = this.getDimension(props);
259
- var xMoved = Math.abs(x1 - x2) >= mouseMoveThreshold;
260
- var yMoved = Math.abs(y1 - y2) >= mouseMoveThreshold;
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: function (evt, targetProps) {
275
- var _this2 = this;
276
-
259
+ onMouseDown(evt, targetProps) {
277
260
  evt.preventDefault();
278
- var handleWidth = targetProps.handleWidth,
279
- cachedBrushDomain = targetProps.cachedBrushDomain,
280
- domain = targetProps.domain,
281
- allowResize = targetProps.allowResize,
282
- allowDrag = targetProps.allowDrag,
283
- allowDraw = targetProps.allowDraw;
284
- var brushDimension = this.getDimension(targetProps);
285
- var defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea; // Don't trigger events for static brushes
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
- var fullDomainBox = targetProps.fullDomainBox || this.getDomainBox(targetProps, domain);
292
- var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
293
-
294
- var _Selection$getSVGEven = Selection.getSVGEventCoordinates(evt, parentSVG),
295
- x = _Selection$getSVGEven.x,
296
- y = _Selection$getSVGEven.y; // Ignore events that occur outside of the maximum domain region
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: x,
301
- y: y
283
+ x,
284
+ y
302
285
  }, fullDomainBox, handleWidth)) {
303
286
  return {};
304
287
  }
305
-
306
- var brushDomain = _defaults({}, targetProps.brushDomain, domain);
307
-
308
- var currentDomain = isEqual(brushDomain, cachedBrushDomain) ? targetProps.currentDomain || brushDomain || domain : brushDomain || domain;
309
- var domainBox = this.getDomainBox(targetProps, domain, currentDomain);
310
- var activeHandles = allowResize && this.getActiveHandles({
311
- x: x,
312
- y: y
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: function () {
319
- return _objectSpread({
299
+ mutation: () => {
300
+ return {
320
301
  isSelecting: true,
321
- domainBox: domainBox,
322
- fullDomainBox: fullDomainBox,
302
+ domainBox,
303
+ fullDomainBox,
323
304
  cachedBrushDomain: brushDomain,
324
- currentDomain: currentDomain,
325
- parentSVG: parentSVG
326
- }, _this2.getResizeMutation(domainBox, activeHandles));
305
+ currentDomain,
306
+ parentSVG,
307
+ ...this.getResizeMutation(domainBox, activeHandles)
308
+ };
327
309
  }
328
310
  }];
329
311
  } else if (this.withinBounds({
330
- x: x,
331
- y: 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: function () {
338
- return _objectSpread({
339
- isPanning: allowDrag,
340
- startX: x,
341
- startY: y,
342
- domainBox: domainBox,
343
- fullDomainBox: fullDomainBox,
344
- currentDomain: currentDomain,
345
- cachedBrushDomain: brushDomain,
346
- parentSVG: parentSVG
347
- }, domainBox);
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
- } // if the event occurs outside the region, or if the whole domain is selected,
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: function () {
357
- return _objectSpread({
358
- isSelecting: allowResize || defaultBrushArea === "move",
359
- domainBox: domainBox,
360
- fullDomainBox: fullDomainBox,
361
- parentSVG: parentSVG,
362
- cachedBrushDomain: brushDomain,
363
- cachedCurrentDomain: currentDomain,
364
- currentDomain: _this2.getMinimumDomain()
365
- }, _this2.getSelectionMutation({
366
- x: x,
367
- y: y
368
- }, domainBox, brushDimension));
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: function (evt, targetProps) {
374
- var scale = targetProps.scale,
375
- isPanning = targetProps.isPanning,
376
- isSelecting = targetProps.isSelecting,
377
- fullDomainBox = targetProps.fullDomainBox,
378
- onBrushDomainChange = targetProps.onBrushDomainChange,
379
- allowResize = targetProps.allowResize,
380
- allowDrag = targetProps.allowDrag,
381
- horizontal = targetProps.horizontal,
382
- mouseMoveThreshold = targetProps.mouseMoveThreshold,
383
- parentSVG = targetProps.parentSVG;
384
- var brushDimension = this.getDimension(targetProps);
385
-
386
- var _Selection$getSVGEven2 = Selection.getSVGEventCoordinates(evt, parentSVG),
387
- x = _Selection$getSVGEven2.x,
388
- y = _Selection$getSVGEven2.y;
389
-
390
- if (!allowResize && !allowDrag || mouseMoveThreshold > 0 && !this.hasMoved(_objectSpread(_objectSpread({}, targetProps), {}, {
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
- var startX = targetProps.startX,
399
- startY = targetProps.startY;
400
- var pannedBox = this.panBox(targetProps, {
401
- x: x,
402
- y: y
378
+ const {
379
+ startX,
380
+ startY
381
+ } = targetProps;
382
+ const pannedBox = this.panBox(targetProps, {
383
+ x,
384
+ y
403
385
  });
404
- var constrainedBox = this.constrainBox(pannedBox, fullDomainBox);
405
- var currentDomain = Selection.getBounds(_objectSpread(_objectSpread({}, constrainedBox), {}, {
406
- scale: scale,
407
- horizontal: horizontal
408
- }));
409
-
410
- var mutatedProps = _objectSpread({
411
- currentDomain: currentDomain,
412
- parentSVG: 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
- }, constrainedBox);
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: function () {
424
- return mutatedProps;
425
- }
404
+ mutation: () => mutatedProps
426
405
  }];
427
406
  } else if (allowResize && isSelecting) {
428
- var _this$constrainPoint = this.constrainPoint({
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
- x2 = _this$constrainPoint.x,
433
- y2 = _this$constrainPoint.y;
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: scale,
441
- horizontal: horizontal
419
+ scale,
420
+ horizontal
442
421
  });
443
-
444
- var _mutatedProps = {
445
- x2: x2,
446
- y2: y2,
447
- currentDomain: _currentDomain,
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(_currentDomain, _defaults({}, _mutatedProps, targetProps));
429
+ onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
453
430
  }
454
-
455
431
  return [{
456
432
  target: "parent",
457
- mutation: function () {
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: function (evt, targetProps) {
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
- } // eslint-disable-line max-statements, complexity
471
-
472
-
473
- var x1 = targetProps.x1,
474
- y1 = targetProps.y1,
475
- x2 = targetProps.x2,
476
- y2 = targetProps.y2,
477
- isPanning = targetProps.isPanning,
478
- isSelecting = targetProps.isSelecting,
479
- onBrushDomainChange = targetProps.onBrushDomainChange,
480
- onBrushDomainChangeEnd = targetProps.onBrushDomainChangeEnd,
481
- onBrushCleared = targetProps.onBrushCleared,
482
- currentDomain = targetProps.currentDomain,
483
- allowResize = targetProps.allowResize,
484
- allowDrag = targetProps.allowDrag;
485
- var defaultBrushArea = !allowResize && !targetProps.defaultBrushArea ? "move" : targetProps.defaultBrushArea;
486
- var defaultBrushHasArea = defaultBrushArea !== undefined && defaultBrushArea !== "none";
487
- var mutatedProps = {
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
- }; // if the mouse hasn't moved since a mouseDown event, select the default brush area
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
- var cachedDomain = targetProps.cachedCurrentDomain || currentDomain;
494
- var defaultDomain = this.getDefaultBrushArea(targetProps, cachedDomain, evt);
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: function () {
517
- return mutatedProps;
518
- }
487
+ mutation: () => mutatedProps
519
488
  }];
520
489
  }
521
490
  };
522
- export var BrushHelpers = _objectSpread(_objectSpread({}, Helpers), {}, {
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, // eslint-disable-line no-magic-numbers
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
+ };