victory-brush-line
Advanced tools
Comparing version 36.3.2 to 36.4.0
@@ -10,18 +10,32 @@ import _pick from "lodash/pick"; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
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; } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
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."); } | ||
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); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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; } | ||
import React from "react"; | ||
@@ -168,11 +182,11 @@ import PropTypes from "prop-types"; | ||
var VictoryBrushLine = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var VictoryBrushLine = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryBrushLine, _React$Component); | ||
var _super = _createSuper(VictoryBrushLine); | ||
function VictoryBrushLine() { | ||
_classCallCheck(this, VictoryBrushLine); | ||
return _possibleConstructorReturn(this, (VictoryBrushLine.__proto__ || Object.getPrototypeOf(VictoryBrushLine)).apply(this, arguments)); | ||
return _super.apply(this, arguments); | ||
} | ||
@@ -316,3 +330,3 @@ | ||
return [React.cloneElement(handleComponent, minHandleProps), React.cloneElement(handleComponent, maxHandleProps)]; | ||
return [/*#__PURE__*/React.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/React.cloneElement(handleComponent, maxHandleProps)]; | ||
} | ||
@@ -348,3 +362,3 @@ }, { | ||
return React.cloneElement(brushComponent, brushProps); | ||
return /*#__PURE__*/React.cloneElement(brushComponent, brushProps); | ||
} | ||
@@ -377,3 +391,3 @@ }, { | ||
return React.cloneElement(brushAreaComponent, brushAreaProps); | ||
return /*#__PURE__*/React.cloneElement(brushAreaComponent, brushAreaProps); | ||
} | ||
@@ -385,3 +399,3 @@ }, { | ||
return React.cloneElement(props.lineComponent, filteredProps); | ||
return /*#__PURE__*/React.cloneElement(props.lineComponent, filteredProps); | ||
} | ||
@@ -391,3 +405,3 @@ }, { | ||
value: function render() { | ||
return React.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props)); | ||
return /*#__PURE__*/React.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props)); | ||
} | ||
@@ -399,83 +413,119 @@ }]); | ||
Object.defineProperty(VictoryBrushLine, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
allowDrag: PropTypes.bool, | ||
allowDraw: PropTypes.bool, | ||
allowResize: PropTypes.bool, | ||
brushAreaComponent: PropTypes.element, | ||
brushAreaStyle: PropTypes.object, | ||
brushAreaWidth: PropTypes.number, | ||
brushComponent: PropTypes.element, | ||
brushDimension: PropTypes.oneOf(["x", "y"]), | ||
brushDomain: PropTypes.array, | ||
brushStyle: PropTypes.object, | ||
brushWidth: PropTypes.number, | ||
className: PropTypes.string, | ||
dimension: PropTypes.oneOf(["x", "y"]), | ||
disable: PropTypes.bool, | ||
events: PropTypes.object, | ||
groupComponent: PropTypes.element, | ||
handleComponent: PropTypes.element, | ||
handleStyle: PropTypes.object, | ||
handleWidth: PropTypes.number, | ||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
lineComponent: PropTypes.element, | ||
name: PropTypes.string, | ||
onBrushDomainChange: PropTypes.func, | ||
scale: PropTypes.object, | ||
style: PropTypes.object, | ||
type: PropTypes.string, | ||
width: PropTypes.number | ||
} | ||
_defineProperty(VictoryBrushLine, "propTypes", { | ||
allowDrag: PropTypes.bool, | ||
allowDraw: PropTypes.bool, | ||
allowResize: PropTypes.bool, | ||
brushAreaComponent: PropTypes.element, | ||
brushAreaStyle: PropTypes.object, | ||
brushAreaWidth: PropTypes.number, | ||
brushComponent: PropTypes.element, | ||
brushDimension: PropTypes.oneOf(["x", "y"]), | ||
brushDomain: PropTypes.array, | ||
brushStyle: PropTypes.object, | ||
brushWidth: PropTypes.number, | ||
className: PropTypes.string, | ||
dimension: PropTypes.oneOf(["x", "y"]), | ||
disable: PropTypes.bool, | ||
events: PropTypes.object, | ||
groupComponent: PropTypes.element, | ||
handleComponent: PropTypes.element, | ||
handleStyle: PropTypes.object, | ||
handleWidth: PropTypes.number, | ||
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
lineComponent: PropTypes.element, | ||
name: PropTypes.string, | ||
onBrushDomainChange: PropTypes.func, | ||
scale: PropTypes.object, | ||
style: PropTypes.object, | ||
type: PropTypes.string, | ||
width: PropTypes.number | ||
}); | ||
Object.defineProperty(VictoryBrushLine, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
allowDrag: true, | ||
allowDraw: true, | ||
allowResize: true, | ||
brushAreaComponent: React.createElement(Box, null), | ||
brushComponent: React.createElement(Box, null), | ||
groupComponent: React.createElement("g", null), | ||
handleComponent: React.createElement(Box, null), | ||
handleWidth: 10, | ||
lineComponent: React.createElement(LineSegment, null), | ||
width: 10 | ||
} | ||
_defineProperty(VictoryBrushLine, "defaultProps", { | ||
allowDrag: true, | ||
allowDraw: true, | ||
allowResize: true, | ||
brushAreaComponent: /*#__PURE__*/React.createElement(Box, null), | ||
brushComponent: /*#__PURE__*/React.createElement(Box, null), | ||
groupComponent: /*#__PURE__*/React.createElement("g", null), | ||
handleComponent: /*#__PURE__*/React.createElement(Box, null), | ||
handleWidth: 10, | ||
lineComponent: /*#__PURE__*/React.createElement(LineSegment, null), | ||
width: 10 | ||
}); | ||
Object.defineProperty(VictoryBrushLine, "defaultEvents", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function (props) { | ||
return props.disable ? undefined : [{ | ||
target: props.type, | ||
eventHandlers: { | ||
onMouseEnter: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, range) && !isEqual(fullDomain, currentDomain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "min" || activeHandle === "both" | ||
}; | ||
_defineProperty(VictoryBrushLine, "defaultEvents", function (props) { | ||
return props.disable ? undefined : [{ | ||
target: props.type, | ||
eventHandlers: { | ||
onMouseEnter: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, range) && !isEqual(fullDomain, currentDomain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "min" || activeHandle === "both" | ||
}; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
}, | ||
onMouseDown: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
allowDraw = targetProps.allowDraw, | ||
activeBrushes = targetProps.activeBrushes, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); // Don't trigger events for static brushes | ||
if (!allowResize && !allowDrag) { | ||
return []; | ||
} | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); // If the event occurs in any of the handle regions, start a resize | ||
if (activeHandle) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
parentSVG: parentSVG, | ||
isSelecting: true, | ||
activeHandle: activeHandle, | ||
brushDomain: currentDomain, | ||
startPosition: position, | ||
activeBrushes: activeBrushes | ||
}; | ||
} | ||
}]; | ||
} else if (withinBound(position, range) && !isEqual(fullDomain, currentDomain)) { | ||
// if the event occurs within a selected region start a panning event, unless the whole | ||
// domain is selected | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: allowDrag, | ||
startPosition: position, | ||
brushDomain: currentDomain, | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
@@ -485,191 +535,115 @@ }; | ||
}]; | ||
}, | ||
onMouseDown: function (evt, targetProps) { | ||
} else { | ||
// if the event occurs outside the region, or if the whole domain is selected, | ||
// start a new selection | ||
return allowDraw ? [{ | ||
mutation: function () { | ||
return { | ||
isSelecting: allowResize, | ||
brushDomain: null, | ||
startPosition: position, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}] : []; | ||
} | ||
}, | ||
// eslint-disable-next-line max-statements, complexity | ||
onMouseMove: function (evt, targetProps) { | ||
var isPanning = targetProps.isPanning, | ||
isSelecting = targetProps.isSelecting, | ||
allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
if (isPanning || isSelecting) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
allowDraw = targetProps.allowDraw, | ||
activeBrushes = targetProps.activeBrushes, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); // Don't trigger events for static brushes | ||
evt.stopPropagation(); | ||
} | ||
if (!allowResize && !allowDrag) { | ||
return []; | ||
} | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var domain = getBrushDomain(brushDomain, fullDomain); | ||
var initialRange = toRange(targetProps, domain); | ||
var activeHandle = getActiveHandle(targetProps, position, initialRange); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, initialRange) && !isEqual(fullDomain, domain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "max" || activeHandle === "both" | ||
}; | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); // If the event occurs in any of the handle regions, start a resize | ||
if (!targetProps.isPanning && !targetProps.isSelecting) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
} | ||
if (activeHandle) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
parentSVG: parentSVG, | ||
isSelecting: true, | ||
activeHandle: activeHandle, | ||
brushDomain: currentDomain, | ||
startPosition: position, | ||
activeBrushes: activeBrushes | ||
}; | ||
} | ||
}]; | ||
} else if (withinBound(position, range) && !isEqual(fullDomain, currentDomain)) { | ||
// if the event occurs within a selected region start a panning event, unless the whole | ||
// domain is selected | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: allowDrag, | ||
startPosition: position, | ||
brushDomain: currentDomain, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
} else { | ||
// if the event occurs outside the region, or if the whole domain is selected, | ||
// start a new selection | ||
return allowDraw ? [{ | ||
mutation: function () { | ||
return { | ||
isSelecting: allowResize, | ||
brushDomain: null, | ||
startPosition: position, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}] : []; | ||
} | ||
}, | ||
// eslint-disable-next-line max-statements, complexity | ||
onMouseMove: function (evt, targetProps) { | ||
var isPanning = targetProps.isPanning, | ||
isSelecting = targetProps.isSelecting, | ||
allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
if (isPanning || isSelecting) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt); | ||
var position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var domain = getBrushDomain(brushDomain, fullDomain); | ||
var initialRange = toRange(targetProps, domain); | ||
var activeHandle = getActiveHandle(targetProps, position, initialRange); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, initialRange) && !isEqual(fullDomain, domain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "max" || activeHandle === "both" | ||
if (allowDrag && isPanning) { | ||
var fullRange = getFullRange(targetProps); | ||
var range = panBox(targetProps, position); | ||
var currentDomain = toDomain(targetProps, range); | ||
var startPosition = Math.max.apply(Math, _toConsumableArray(range)) >= Math.max.apply(Math, _toConsumableArray(fullRange)) || Math.min.apply(Math, _toConsumableArray(range)) <= Math.min.apply(Math, _toConsumableArray(fullRange)) ? targetProps.startPosition : position; | ||
var mutatedProps = { | ||
startPosition: startPosition, | ||
isPanning: true, | ||
brushDomain: currentDomain, | ||
activeBrushes: { | ||
brush: true | ||
}, | ||
parentSVG: parentSVG | ||
}; | ||
if (!targetProps.isPanning && !targetProps.isSelecting) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
if (_isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps)); | ||
} | ||
if (allowDrag && isPanning) { | ||
var fullRange = getFullRange(targetProps); | ||
var range = panBox(targetProps, position); | ||
var currentDomain = toDomain(targetProps, range); | ||
var startPosition = Math.max.apply(Math, _toConsumableArray(range)) >= Math.max.apply(Math, _toConsumableArray(fullRange)) || Math.min.apply(Math, _toConsumableArray(range)) <= Math.min.apply(Math, _toConsumableArray(fullRange)) ? targetProps.startPosition : position; | ||
var mutatedProps = { | ||
startPosition: startPosition, | ||
isPanning: true, | ||
brushDomain: currentDomain, | ||
activeBrushes: { | ||
brush: true | ||
}, | ||
parentSVG: parentSVG | ||
}; | ||
if (_isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps)); | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
} else if (allowResize && isSelecting) { | ||
var _currentDomain = brushDomain || getMinimumDomain(); | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
} else if (allowResize && isSelecting) { | ||
var _currentDomain = brushDomain || getMinimumDomain(); | ||
var _range = toRange(targetProps, _currentDomain); | ||
var _range = toRange(targetProps, _currentDomain); | ||
var oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min"; | ||
var handle = targetProps.activeHandle && getActiveHandle(targetProps, position, _range) === "both" ? oppositeHandle : targetProps.activeHandle; | ||
var oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min"; | ||
var handle = targetProps.activeHandle && getActiveHandle(targetProps, position, _range) === "both" ? oppositeHandle : targetProps.activeHandle; | ||
if (!handle) { | ||
_currentDomain = toDomain(targetProps, [targetProps.startPosition, position]); | ||
} else { | ||
var rangeMax = dimension === "x" ? Math.max.apply(Math, _toConsumableArray(_range)) : Math.min.apply(Math, _toConsumableArray(_range)); | ||
var rangeMin = dimension === "x" ? Math.min.apply(Math, _toConsumableArray(_range)) : Math.max.apply(Math, _toConsumableArray(_range)); | ||
var min = handle === "max" ? rangeMin : position; | ||
var max = handle === "min" ? rangeMax : position; | ||
_currentDomain = toDomain(targetProps, [min, max]); | ||
} | ||
if (!handle) { | ||
_currentDomain = toDomain(targetProps, [targetProps.startPosition, position]); | ||
} else { | ||
var rangeMax = dimension === "x" ? Math.max.apply(Math, _toConsumableArray(_range)) : Math.min.apply(Math, _toConsumableArray(_range)); | ||
var rangeMin = dimension === "x" ? Math.min.apply(Math, _toConsumableArray(_range)) : Math.max.apply(Math, _toConsumableArray(_range)); | ||
var min = handle === "max" ? rangeMin : position; | ||
var max = handle === "min" ? rangeMax : position; | ||
_currentDomain = toDomain(targetProps, [min, max]); | ||
var _mutatedProps = { | ||
brushDomain: _currentDomain, | ||
startPosition: targetProps.startPosition, | ||
isSelecting: isSelecting, | ||
activeHandle: handle, | ||
parentSVG: parentSVG, | ||
activeBrushes: { | ||
brush: true, | ||
minHandle: activeHandle === "min", | ||
maxHandle: activeHandle === "max" | ||
} | ||
var _mutatedProps = { | ||
brushDomain: _currentDomain, | ||
startPosition: targetProps.startPosition, | ||
isSelecting: isSelecting, | ||
activeHandle: handle, | ||
parentSVG: parentSVG, | ||
activeBrushes: { | ||
brush: true, | ||
minHandle: activeHandle === "min", | ||
maxHandle: activeHandle === "max" | ||
} | ||
}; | ||
if (_isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(_currentDomain, _defaults({}, _mutatedProps, targetProps)); | ||
} | ||
return [{ | ||
mutation: function () { | ||
return _mutatedProps; | ||
} | ||
}]; | ||
} | ||
return []; | ||
}, | ||
onMouseUp: function (evt, targetProps) { | ||
var onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain, | ||
allowResize = targetProps.allowResize, | ||
activeBrushes = targetProps.activeBrushes; // if the mouse hasn't moved since a mouseDown event, select the whole domain region | ||
var mutatedProps = { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: activeBrushes | ||
}; | ||
if (allowResize && _isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(brushDomain, _defaults({}, mutatedProps, targetProps)); | ||
if (_isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(_currentDomain, _defaults({}, _mutatedProps, targetProps)); | ||
} | ||
@@ -679,25 +653,53 @@ | ||
mutation: function () { | ||
return mutatedProps; | ||
return _mutatedProps; | ||
} | ||
}]; | ||
}, | ||
onMouseLeave: function (evt, targetProps) { | ||
var brushDomain = targetProps.brushDomain; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: {} | ||
}; | ||
} | ||
}]; | ||
} | ||
return []; | ||
}, | ||
onMouseUp: function (evt, targetProps) { | ||
var onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain, | ||
allowResize = targetProps.allowResize, | ||
activeBrushes = targetProps.activeBrushes; // if the mouse hasn't moved since a mouseDown event, select the whole domain region | ||
var mutatedProps = { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: activeBrushes | ||
}; | ||
if (allowResize && _isFunction(onBrushDomainChange)) { | ||
onBrushDomainChange(brushDomain, _defaults({}, mutatedProps, targetProps)); | ||
} | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
}, | ||
onMouseLeave: function (evt, targetProps) { | ||
var brushDomain = targetProps.brushDomain; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: {} | ||
}; | ||
} | ||
}]; | ||
} | ||
}]; | ||
} | ||
} | ||
}]; | ||
}); | ||
export { VictoryBrushLine as default }; |
@@ -30,18 +30,32 @@ "use strict"; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
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; } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
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."); } | ||
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); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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; } | ||
var SMALL_NUMBER = 1 / Number.MAX_SAFE_INTEGER; | ||
@@ -190,11 +204,11 @@ | ||
var VictoryBrushLine = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var VictoryBrushLine = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryBrushLine, _React$Component); | ||
var _super = _createSuper(VictoryBrushLine); | ||
function VictoryBrushLine() { | ||
_classCallCheck(this, VictoryBrushLine); | ||
return _possibleConstructorReturn(this, (VictoryBrushLine.__proto__ || Object.getPrototypeOf(VictoryBrushLine)).apply(this, arguments)); | ||
return _super.apply(this, arguments); | ||
} | ||
@@ -332,3 +346,3 @@ | ||
}, handleDimensions.max); | ||
return [_react.default.cloneElement(handleComponent, minHandleProps), _react.default.cloneElement(handleComponent, maxHandleProps)]; | ||
return [/*#__PURE__*/_react.default.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/_react.default.cloneElement(handleComponent, maxHandleProps)]; | ||
} | ||
@@ -362,3 +376,3 @@ }, { | ||
}, rectDimensions); | ||
return _react.default.cloneElement(brushComponent, brushProps); | ||
return /*#__PURE__*/_react.default.cloneElement(brushComponent, brushProps); | ||
} | ||
@@ -389,3 +403,3 @@ }, { | ||
}, rectDimensions); | ||
return _react.default.cloneElement(brushAreaComponent, brushAreaProps); | ||
return /*#__PURE__*/_react.default.cloneElement(brushAreaComponent, brushAreaProps); | ||
} | ||
@@ -396,3 +410,3 @@ }, { | ||
var filteredProps = (0, _pick2.default)(props, ["x1", "x2", "y1", "y2", "datum", "scale", "active", "style"]); | ||
return _react.default.cloneElement(props.lineComponent, filteredProps); | ||
return /*#__PURE__*/_react.default.cloneElement(props.lineComponent, filteredProps); | ||
} | ||
@@ -402,3 +416,3 @@ }, { | ||
value: function render() { | ||
return _react.default.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props)); | ||
return /*#__PURE__*/_react.default.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props)); | ||
} | ||
@@ -411,86 +425,126 @@ }]); | ||
exports.default = VictoryBrushLine; | ||
Object.defineProperty(VictoryBrushLine, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
allowDrag: _propTypes.default.bool, | ||
allowDraw: _propTypes.default.bool, | ||
allowResize: _propTypes.default.bool, | ||
brushAreaComponent: _propTypes.default.element, | ||
brushAreaStyle: _propTypes.default.object, | ||
brushAreaWidth: _propTypes.default.number, | ||
brushComponent: _propTypes.default.element, | ||
brushDimension: _propTypes.default.oneOf(["x", "y"]), | ||
brushDomain: _propTypes.default.array, | ||
brushStyle: _propTypes.default.object, | ||
brushWidth: _propTypes.default.number, | ||
className: _propTypes.default.string, | ||
dimension: _propTypes.default.oneOf(["x", "y"]), | ||
disable: _propTypes.default.bool, | ||
events: _propTypes.default.object, | ||
groupComponent: _propTypes.default.element, | ||
handleComponent: _propTypes.default.element, | ||
handleStyle: _propTypes.default.object, | ||
handleWidth: _propTypes.default.number, | ||
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), | ||
lineComponent: _propTypes.default.element, | ||
name: _propTypes.default.string, | ||
onBrushDomainChange: _propTypes.default.func, | ||
scale: _propTypes.default.object, | ||
style: _propTypes.default.object, | ||
type: _propTypes.default.string, | ||
width: _propTypes.default.number | ||
} | ||
_defineProperty(VictoryBrushLine, "propTypes", { | ||
allowDrag: _propTypes.default.bool, | ||
allowDraw: _propTypes.default.bool, | ||
allowResize: _propTypes.default.bool, | ||
brushAreaComponent: _propTypes.default.element, | ||
brushAreaStyle: _propTypes.default.object, | ||
brushAreaWidth: _propTypes.default.number, | ||
brushComponent: _propTypes.default.element, | ||
brushDimension: _propTypes.default.oneOf(["x", "y"]), | ||
brushDomain: _propTypes.default.array, | ||
brushStyle: _propTypes.default.object, | ||
brushWidth: _propTypes.default.number, | ||
className: _propTypes.default.string, | ||
dimension: _propTypes.default.oneOf(["x", "y"]), | ||
disable: _propTypes.default.bool, | ||
events: _propTypes.default.object, | ||
groupComponent: _propTypes.default.element, | ||
handleComponent: _propTypes.default.element, | ||
handleStyle: _propTypes.default.object, | ||
handleWidth: _propTypes.default.number, | ||
id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]), | ||
lineComponent: _propTypes.default.element, | ||
name: _propTypes.default.string, | ||
onBrushDomainChange: _propTypes.default.func, | ||
scale: _propTypes.default.object, | ||
style: _propTypes.default.object, | ||
type: _propTypes.default.string, | ||
width: _propTypes.default.number | ||
}); | ||
Object.defineProperty(VictoryBrushLine, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
allowDrag: true, | ||
allowDraw: true, | ||
allowResize: true, | ||
brushAreaComponent: _react.default.createElement(_victoryCore.Box, null), | ||
brushComponent: _react.default.createElement(_victoryCore.Box, null), | ||
groupComponent: _react.default.createElement("g", null), | ||
handleComponent: _react.default.createElement(_victoryCore.Box, null), | ||
handleWidth: 10, | ||
lineComponent: _react.default.createElement(_victoryCore.LineSegment, null), | ||
width: 10 | ||
} | ||
_defineProperty(VictoryBrushLine, "defaultProps", { | ||
allowDrag: true, | ||
allowDraw: true, | ||
allowResize: true, | ||
brushAreaComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Box, null), | ||
brushComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Box, null), | ||
groupComponent: /*#__PURE__*/_react.default.createElement("g", null), | ||
handleComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Box, null), | ||
handleWidth: 10, | ||
lineComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.LineSegment, null), | ||
width: 10 | ||
}); | ||
Object.defineProperty(VictoryBrushLine, "defaultEvents", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function (props) { | ||
return props.disable ? undefined : [{ | ||
target: props.type, | ||
eventHandlers: { | ||
onMouseEnter: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
_defineProperty(VictoryBrushLine, "defaultEvents", function (props) { | ||
return props.disable ? undefined : [{ | ||
target: props.type, | ||
eventHandlers: { | ||
onMouseEnter: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, range) && !(0, _reactFastCompare.default)(fullDomain, currentDomain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "min" || activeHandle === "both" | ||
}; | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, range) && !(0, _reactFastCompare.default)(fullDomain, currentDomain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "min" || activeHandle === "both" | ||
}; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
}, | ||
onMouseDown: function (evt, targetProps) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
allowDraw = targetProps.allowDraw, | ||
activeBrushes = targetProps.activeBrushes, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); // Don't trigger events for static brushes | ||
if (!allowResize && !allowDrag) { | ||
return []; | ||
} | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); // If the event occurs in any of the handle regions, start a resize | ||
if (activeHandle) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
parentSVG: parentSVG, | ||
isSelecting: true, | ||
activeHandle: activeHandle, | ||
brushDomain: currentDomain, | ||
startPosition: position, | ||
activeBrushes: activeBrushes | ||
}; | ||
} | ||
}]; | ||
} else if (withinBound(position, range) && !(0, _reactFastCompare.default)(fullDomain, currentDomain)) { | ||
// if the event occurs within a selected region start a panning event, unless the whole | ||
// domain is selected | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: allowDrag, | ||
startPosition: position, | ||
brushDomain: currentDomain, | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
@@ -500,196 +554,117 @@ }; | ||
}]; | ||
}, | ||
onMouseDown: function (evt, targetProps) { | ||
} else { | ||
// if the event occurs outside the region, or if the whole domain is selected, | ||
// start a new selection | ||
return allowDraw ? [{ | ||
mutation: function () { | ||
return { | ||
isSelecting: allowResize, | ||
brushDomain: null, | ||
startPosition: position, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}] : []; | ||
} | ||
}, | ||
// eslint-disable-next-line max-statements, complexity | ||
onMouseMove: function (evt, targetProps) { | ||
var isPanning = targetProps.isPanning, | ||
isSelecting = targetProps.isSelecting, | ||
allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
if (isPanning || isSelecting) { | ||
evt.preventDefault(); | ||
var allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
allowDraw = targetProps.allowDraw, | ||
activeBrushes = targetProps.activeBrushes, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); // Don't trigger events for static brushes | ||
evt.stopPropagation(); | ||
} | ||
if (!allowResize && !allowDrag) { | ||
return []; | ||
} | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
var fullDomain = getFullDomain(targetProps); | ||
var currentDomain = getBrushDomain(brushDomain, fullDomain); | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
var fullDomain = getFullDomain(targetProps); | ||
var domain = getBrushDomain(brushDomain, fullDomain); | ||
var initialRange = toRange(targetProps, domain); | ||
var activeHandle = getActiveHandle(targetProps, position, initialRange); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, initialRange) && !(0, _reactFastCompare.default)(fullDomain, domain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "max" || activeHandle === "both" | ||
}; | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
if (!targetProps.isPanning && !targetProps.isSelecting) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
} | ||
var range = toRange(targetProps, currentDomain); | ||
var activeHandle = allowResize && getActiveHandle(targetProps, position, range); // If the event occurs in any of the handle regions, start a resize | ||
if (activeHandle) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
parentSVG: parentSVG, | ||
isSelecting: true, | ||
activeHandle: activeHandle, | ||
brushDomain: currentDomain, | ||
startPosition: position, | ||
activeBrushes: activeBrushes | ||
}; | ||
} | ||
}]; | ||
} else if (withinBound(position, range) && !(0, _reactFastCompare.default)(fullDomain, currentDomain)) { | ||
// if the event occurs within a selected region start a panning event, unless the whole | ||
// domain is selected | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: allowDrag, | ||
startPosition: position, | ||
brushDomain: currentDomain, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
} else { | ||
// if the event occurs outside the region, or if the whole domain is selected, | ||
// start a new selection | ||
return allowDraw ? [{ | ||
mutation: function () { | ||
return { | ||
isSelecting: allowResize, | ||
brushDomain: null, | ||
startPosition: position, | ||
activeBrushes: activeBrushes, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}] : []; | ||
} | ||
}, | ||
// eslint-disable-next-line max-statements, complexity | ||
onMouseMove: function (evt, targetProps) { | ||
var isPanning = targetProps.isPanning, | ||
isSelecting = targetProps.isSelecting, | ||
allowResize = targetProps.allowResize, | ||
allowDrag = targetProps.allowDrag, | ||
onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain; | ||
var dimension = getDimension(targetProps); | ||
if (isPanning || isSelecting) { | ||
evt.preventDefault(); | ||
evt.stopPropagation(); | ||
} | ||
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt); | ||
var position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension]; | ||
var fullDomain = getFullDomain(targetProps); | ||
var domain = getBrushDomain(brushDomain, fullDomain); | ||
var initialRange = toRange(targetProps, domain); | ||
var activeHandle = getActiveHandle(targetProps, position, initialRange); | ||
var activeBrushes = { | ||
brushArea: !targetProps.brushDomain, | ||
brush: withinBound(position, initialRange) && !(0, _reactFastCompare.default)(fullDomain, domain), | ||
minHandle: activeHandle === "min" || activeHandle === "both", | ||
maxHandle: activeHandle === "max" || activeHandle === "both" | ||
if (allowDrag && isPanning) { | ||
var fullRange = getFullRange(targetProps); | ||
var range = panBox(targetProps, position); | ||
var currentDomain = toDomain(targetProps, range); | ||
var startPosition = Math.max.apply(Math, _toConsumableArray(range)) >= Math.max.apply(Math, _toConsumableArray(fullRange)) || Math.min.apply(Math, _toConsumableArray(range)) <= Math.min.apply(Math, _toConsumableArray(fullRange)) ? targetProps.startPosition : position; | ||
var mutatedProps = { | ||
startPosition: startPosition, | ||
isPanning: true, | ||
brushDomain: currentDomain, | ||
activeBrushes: { | ||
brush: true | ||
}, | ||
parentSVG: parentSVG | ||
}; | ||
if (!targetProps.isPanning && !targetProps.isSelecting) { | ||
return [{ | ||
mutation: function () { | ||
return { | ||
activeBrushes: activeBrushes, | ||
brushDomain: targetProps.brushDomain, | ||
parentSVG: parentSVG | ||
}; | ||
} | ||
}]; | ||
if ((0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(currentDomain, (0, _defaults2.default)({}, mutatedProps, targetProps)); | ||
} | ||
if (allowDrag && isPanning) { | ||
var fullRange = getFullRange(targetProps); | ||
var range = panBox(targetProps, position); | ||
var currentDomain = toDomain(targetProps, range); | ||
var startPosition = Math.max.apply(Math, _toConsumableArray(range)) >= Math.max.apply(Math, _toConsumableArray(fullRange)) || Math.min.apply(Math, _toConsumableArray(range)) <= Math.min.apply(Math, _toConsumableArray(fullRange)) ? targetProps.startPosition : position; | ||
var mutatedProps = { | ||
startPosition: startPosition, | ||
isPanning: true, | ||
brushDomain: currentDomain, | ||
activeBrushes: { | ||
brush: true | ||
}, | ||
parentSVG: parentSVG | ||
}; | ||
if ((0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(currentDomain, (0, _defaults2.default)({}, mutatedProps, targetProps)); | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
} else if (allowResize && isSelecting) { | ||
var _currentDomain = brushDomain || getMinimumDomain(); | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
} else if (allowResize && isSelecting) { | ||
var _currentDomain = brushDomain || getMinimumDomain(); | ||
var _range = toRange(targetProps, _currentDomain); | ||
var _range = toRange(targetProps, _currentDomain); | ||
var oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min"; | ||
var handle = targetProps.activeHandle && getActiveHandle(targetProps, position, _range) === "both" ? oppositeHandle : targetProps.activeHandle; | ||
var oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min"; | ||
var handle = targetProps.activeHandle && getActiveHandle(targetProps, position, _range) === "both" ? oppositeHandle : targetProps.activeHandle; | ||
if (!handle) { | ||
_currentDomain = toDomain(targetProps, [targetProps.startPosition, position]); | ||
} else { | ||
var rangeMax = dimension === "x" ? Math.max.apply(Math, _toConsumableArray(_range)) : Math.min.apply(Math, _toConsumableArray(_range)); | ||
var rangeMin = dimension === "x" ? Math.min.apply(Math, _toConsumableArray(_range)) : Math.max.apply(Math, _toConsumableArray(_range)); | ||
var min = handle === "max" ? rangeMin : position; | ||
var max = handle === "min" ? rangeMax : position; | ||
_currentDomain = toDomain(targetProps, [min, max]); | ||
} | ||
if (!handle) { | ||
_currentDomain = toDomain(targetProps, [targetProps.startPosition, position]); | ||
} else { | ||
var rangeMax = dimension === "x" ? Math.max.apply(Math, _toConsumableArray(_range)) : Math.min.apply(Math, _toConsumableArray(_range)); | ||
var rangeMin = dimension === "x" ? Math.min.apply(Math, _toConsumableArray(_range)) : Math.max.apply(Math, _toConsumableArray(_range)); | ||
var min = handle === "max" ? rangeMin : position; | ||
var max = handle === "min" ? rangeMax : position; | ||
_currentDomain = toDomain(targetProps, [min, max]); | ||
var _mutatedProps = { | ||
brushDomain: _currentDomain, | ||
startPosition: targetProps.startPosition, | ||
isSelecting: isSelecting, | ||
activeHandle: handle, | ||
parentSVG: parentSVG, | ||
activeBrushes: { | ||
brush: true, | ||
minHandle: activeHandle === "min", | ||
maxHandle: activeHandle === "max" | ||
} | ||
var _mutatedProps = { | ||
brushDomain: _currentDomain, | ||
startPosition: targetProps.startPosition, | ||
isSelecting: isSelecting, | ||
activeHandle: handle, | ||
parentSVG: parentSVG, | ||
activeBrushes: { | ||
brush: true, | ||
minHandle: activeHandle === "min", | ||
maxHandle: activeHandle === "max" | ||
} | ||
}; | ||
if ((0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(_currentDomain, (0, _defaults2.default)({}, _mutatedProps, targetProps)); | ||
} | ||
return [{ | ||
mutation: function () { | ||
return _mutatedProps; | ||
} | ||
}]; | ||
} | ||
return []; | ||
}, | ||
onMouseUp: function (evt, targetProps) { | ||
var onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain, | ||
allowResize = targetProps.allowResize, | ||
activeBrushes = targetProps.activeBrushes; // if the mouse hasn't moved since a mouseDown event, select the whole domain region | ||
var mutatedProps = { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: activeBrushes | ||
}; | ||
if (allowResize && (0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(brushDomain, (0, _defaults2.default)({}, mutatedProps, targetProps)); | ||
if ((0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(_currentDomain, (0, _defaults2.default)({}, _mutatedProps, targetProps)); | ||
} | ||
@@ -699,24 +674,51 @@ | ||
mutation: function () { | ||
return mutatedProps; | ||
return _mutatedProps; | ||
} | ||
}]; | ||
}, | ||
onMouseLeave: function (evt, targetProps) { | ||
var brushDomain = targetProps.brushDomain; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: {} | ||
}; | ||
} | ||
}]; | ||
} | ||
return []; | ||
}, | ||
onMouseUp: function (evt, targetProps) { | ||
var onBrushDomainChange = targetProps.onBrushDomainChange, | ||
brushDomain = targetProps.brushDomain, | ||
allowResize = targetProps.allowResize, | ||
activeBrushes = targetProps.activeBrushes; // if the mouse hasn't moved since a mouseDown event, select the whole domain region | ||
var mutatedProps = { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: activeBrushes | ||
}; | ||
if (allowResize && (0, _isFunction2.default)(onBrushDomainChange)) { | ||
onBrushDomainChange(brushDomain, (0, _defaults2.default)({}, mutatedProps, targetProps)); | ||
} | ||
return [{ | ||
mutation: function () { | ||
return mutatedProps; | ||
} | ||
}]; | ||
}, | ||
onMouseLeave: function (evt, targetProps) { | ||
var brushDomain = targetProps.brushDomain; | ||
return [{ | ||
mutation: function () { | ||
return { | ||
isPanning: false, | ||
isSelecting: false, | ||
activeHandle: null, | ||
startPosition: null, | ||
brushDomain: brushDomain, | ||
activeBrushes: {} | ||
}; | ||
} | ||
}]; | ||
} | ||
}]; | ||
} | ||
} | ||
}]; | ||
}); |
{ | ||
"name": "victory-brush-line", | ||
"version": "36.3.2", | ||
"version": "36.4.0", | ||
"description": "Interactive Brush Line Component for Victory", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"react-fast-compare": "^2.0.0", | ||
"victory-core": "^36.3.2" | ||
"victory-core": "^36.4.0" | ||
}, | ||
@@ -35,3 +35,3 @@ "peerDependencies": { | ||
"sideEffects": false, | ||
"gitHead": "18895d1290245732d14332bbbda10336032c9aab" | ||
"gitHead": "2e05481eeb34f9801a90023a131a21aa7deff082" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
0
740178
14691
Updatedvictory-core@^36.4.0