Socket
Socket
Sign inDemoInstall

victory-brush-line

Package Overview
Dependencies
28
Maintainers
16
Versions
136
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 36.9.2-next.0 to 36.9.2-next.1

7

CHANGELOG.md
# victory-brush-line
## 36.9.2-next.0
## 36.9.2-next.1

@@ -8,7 +8,10 @@ ### Patch Changes

- 6e34169a5: Replace lodash isFunction with native code
- Updated dependencies [7da790934]
- Updated dependencies [3f2da66e3]
- Updated dependencies [c13308624]
- Updated dependencies [7efd582cc]
- Updated dependencies [9cdaf2c08]
- Updated dependencies [f6f7cc515]
- Updated dependencies [6e34169a5]
- victory-core@36.9.2-next.0
- victory-core@36.9.2-next.1

@@ -15,0 +18,0 @@ ## 36.9.1

import _pick from "lodash/pick";
import _defaults from "lodash/defaults";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
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 _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 ? Object.setPrototypeOf.bind() : 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 _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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
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";
import { Selection, Helpers, Collection, LineSegment, Scale, Domain, Box } from "victory-core";
import isEqual from "react-fast-compare";
const SMALL_NUMBER = 1 / Number.MAX_SAFE_INTEGER;
const getScale = props => {
const {
scale = {},
dimension = "x"
} = props;
var SMALL_NUMBER = 1 / Number.MAX_SAFE_INTEGER;
var getScale = function (props) {
var _props$scale = props.scale,
scale = _props$scale === void 0 ? {} : _props$scale,
_props$dimension = props.dimension,
dimension = _props$dimension === void 0 ? "x" : _props$dimension;
if (scale[dimension]) {
return scale[dimension];
}
const fallbackScale = Scale.getBaseScale(props, dimension);
const range = Helpers.getRange(props, dimension);
const domain = Domain.getDomainFromProps(props, dimension) || [0, 1];
var fallbackScale = Scale.getBaseScale(props, dimension);
var range = Helpers.getRange(props, dimension);
var domain = Domain.getDomainFromProps(props, dimension) || [0, 1];
fallbackScale.range(range).domain(domain);
return fallbackScale;
};
const getDimension = props => {
const {
horizontal,
dimension = "x"
} = props;
var getDimension = function (props) {
var horizontal = props.horizontal,
_props$dimension2 = props.dimension,
dimension = _props$dimension2 === void 0 ? "x" : _props$dimension2;
if (!horizontal) {
return dimension;
}
return dimension === "x" ? "y" : "x";
};
const toRange = (props, domain) => {
const scale = getScale(props);
return [scale(Math.min(...domain)), scale(Math.max(...domain))];
var toRange = function (props, domain) {
var scale = getScale(props);
return [scale(Math.min.apply(Math, _toConsumableArray(domain))), scale(Math.max.apply(Math, _toConsumableArray(domain)))];
};
const toDomain = (props, range) => {
const scale = getScale(props);
return [scale.invert(Math.min(...range)), scale.invert(Math.max(...range))];
var toDomain = function (props, range) {
var scale = getScale(props);
return [scale.invert(Math.min.apply(Math, _toConsumableArray(range))), scale.invert(Math.max.apply(Math, _toConsumableArray(range)))];
};
const getFullRange = props => {
const scale = getScale(props);
var getFullRange = function (props) {
var scale = getScale(props);
return scale.range();
};
const getFullDomain = props => {
const scale = getScale(props);
var getFullDomain = function (props) {
var scale = getScale(props);
return scale.domain();
};
const withinBound = (value, bound) => {
var withinBound = function (value, bound) {
return value >= Collection.getMinValue(bound) && value <= Collection.getMaxValue(bound);
};
const getBrushDomain = (brushDomain, fullDomain) => {
var getBrushDomain = function (brushDomain, fullDomain) {
if (brushDomain) {
const brushMin = Collection.getMinValue(brushDomain);
const brushMax = Collection.getMaxValue(brushDomain);
const domainMin = Collection.getMinValue(fullDomain);
const domainMax = Collection.getMaxValue(fullDomain);
const defaultMin = brushMin < domainMin ? domainMin : Number(domainMax) - SMALL_NUMBER;
const defaultMax = brushMax > domainMax ? domainMax : Number(domainMin) + SMALL_NUMBER;
const min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
const max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
var brushMin = Collection.getMinValue(brushDomain);
var brushMax = Collection.getMaxValue(brushDomain);
var domainMin = Collection.getMinValue(fullDomain);
var domainMax = Collection.getMaxValue(fullDomain);
var defaultMin = brushMin < domainMin ? domainMin : Number(domainMax) - SMALL_NUMBER;
var defaultMax = brushMax > domainMax ? domainMax : Number(domainMin) + SMALL_NUMBER;
var min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
var max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
return [min, max];
}
return fullDomain;
};
const getActiveHandle = (props, position, range) => {
const width = props.handleWidth / 2;
const dimension = getDimension(props);
const getHandle = type => {
const base = {
min: dimension === "x" ? Math.min(...range) : Math.max(...range),
max: dimension === "x" ? Math.max(...range) : Math.min(...range)
var getActiveHandle = function (props, position, range) {
var width = props.handleWidth / 2;
var dimension = getDimension(props);
var getHandle = function (type) {
var base = {
min: dimension === "x" ? Math.min.apply(Math, _toConsumableArray(range)) : Math.max.apply(Math, _toConsumableArray(range)),
max: dimension === "x" ? Math.max.apply(Math, _toConsumableArray(range)) : Math.min.apply(Math, _toConsumableArray(range))
};
return [base[type] - width, base[type] + width];
};
const active = ["min", "max"].reduce((memo, type) => {
var active = ["min", "max"].reduce(function (memo, type) {
memo[type] = withinBound(position, getHandle(type)) ? type : undefined;

@@ -80,32 +128,32 @@ return memo;

};
const getMinimumDomain = () => {
var getMinimumDomain = function () {
return [0, SMALL_NUMBER];
};
const panBox = (props, position) => {
const {
brushDomain,
startPosition
} = props;
const range = toRange(props, brushDomain);
const fullRange = getFullRange(props);
const size = Math.abs(range[1] - range[0]);
const globalMin = Math.min(...fullRange);
const globalMax = Math.max(...fullRange);
const delta = startPosition ? startPosition - position : 0;
const min = Math.min(...range) - delta;
const max = Math.max(...range) - delta;
const constrainedMin = min > globalMax - size ? globalMax - size : Math.max(min, globalMin);
const constrainedMax = max < globalMin + size ? globalMin + size : Math.min(max, globalMax);
var panBox = function (props, position) {
var brushDomain = props.brushDomain,
startPosition = props.startPosition;
var range = toRange(props, brushDomain);
var fullRange = getFullRange(props);
var size = Math.abs(range[1] - range[0]);
var globalMin = Math.min.apply(Math, _toConsumableArray(fullRange));
var globalMax = Math.max.apply(Math, _toConsumableArray(fullRange));
var delta = startPosition ? startPosition - position : 0;
var min = Math.min.apply(Math, _toConsumableArray(range)) - delta;
var max = Math.max.apply(Math, _toConsumableArray(range)) - delta;
var constrainedMin = min > globalMax - size ? globalMax - size : Math.max(min, globalMin);
var constrainedMax = max < globalMin + size ? globalMin + size : Math.min(max, globalMax);
return [constrainedMin, constrainedMax];
};
const fallbackProps = {
var fallbackProps = {
brushAreaStyle: {
stroke: "none",
fill: "black",
opacity: _ref => {
let {
active
} = _ref;
opacity: function (_ref) {
var active = _ref.active;
return active ? 0.2 : 0.1;
} // eslint-disable-line no-magic-numbers
},

@@ -116,8 +164,7 @@ brushStyle: {

fill: "black",
opacity: _ref2 => {
let {
active
} = _ref2;
opacity: function (_ref2) {
var active = _ref2.active;
return active ? 0.4 : 0.3;
} // eslint-disable-line no-magic-numbers
},

@@ -130,226 +177,456 @@ handleStyle: {

};
export class VictoryBrushLine extends React.Component {
static 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
};
static defaultEvents = function (props) {
return props.disable ? undefined : [{
target: props.type,
eventHandlers: {
onMouseEnter: (evt, targetProps) => {
evt.preventDefault();
const {
allowResize,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
const position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const fullDomain = getFullDomain(targetProps);
const currentDomain = getBrushDomain(brushDomain, fullDomain);
const range = toRange(targetProps, currentDomain);
const activeHandle = allowResize && getActiveHandle(targetProps, position, range);
const activeBrushes = {
brushArea: !targetProps.brushDomain,
brush: withinBound(position, range) && !isEqual(fullDomain, currentDomain),
minHandle: activeHandle === "min" || activeHandle === "both",
maxHandle: activeHandle === "min" || activeHandle === "both"
};
return [{
mutation: () => ({
activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG
})
}];
export var VictoryBrushLine = /*#__PURE__*/function (_React$Component) {
_inherits(VictoryBrushLine, _React$Component);
var _super = _createSuper(VictoryBrushLine);
function VictoryBrushLine() {
_classCallCheck(this, VictoryBrushLine);
return _super.apply(this, arguments);
}
_createClass(VictoryBrushLine, [{
key: "getRectDimensions",
value: function getRectDimensions(props, brushWidth, domain) {
var brushDomain = props.brushDomain;
var dimension = getDimension(props);
var range = toRange(props, domain || getBrushDomain(brushDomain, getFullDomain(props)));
var coordinates = dimension === "x" ? {
y1: props.y1,
y2: props.y2,
x1: Math.min.apply(Math, _toConsumableArray(range)),
x2: Math.max.apply(Math, _toConsumableArray(range))
} : {
x1: props.x1,
x2: props.x2,
y1: Math.min.apply(Math, _toConsumableArray(range)),
y2: Math.max.apply(Math, _toConsumableArray(range))
};
var x1 = coordinates.x1,
x2 = coordinates.x2,
y1 = coordinates.y1,
y2 = coordinates.y2;
var offset = {
x: dimension === "x" ? 0 : brushWidth / 2,
y: dimension === "y" ? 0 : brushWidth / 2
};
var x = Math.min(x1, x2) - offset.x;
var y = Math.min(y1, y2) - offset.y;
var width = Math.max(x1, x2) + offset.x - x;
var height = Math.max(y1, y2) + offset.y - y;
return {
x: x,
y: y,
width: width,
height: height
};
}
}, {
key: "getHandleDimensions",
value: function getHandleDimensions(props) {
var handleWidth = props.handleWidth,
x1 = props.x1,
x2 = props.x2,
y1 = props.y1,
y2 = props.y2,
brushDomain = props.brushDomain;
var dimension = getDimension(props);
var brushWidth = props.brushWidth || props.width;
var domain = getBrushDomain(brushDomain, getFullDomain(props));
var range = toRange(props, domain);
var defaultX = Math.min(x1, x2) - brushWidth / 2;
var defaultY = Math.min(y1, y2) - brushWidth / 2;
var x = {
min: dimension === "x" ? Math.min.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultX,
max: dimension === "x" ? Math.max.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultX
};
var y = {
min: dimension === "y" ? Math.max.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultY,
max: dimension === "y" ? Math.min.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultY
};
var width = dimension === "x" ? handleWidth : brushWidth;
var height = dimension === "x" ? brushWidth : handleWidth;
return {
min: {
x: x.min,
y: y.min,
width: width,
height: height
},
onMouseDown: (evt, targetProps) => {
evt.preventDefault();
const {
allowResize,
allowDrag,
allowDraw,
activeBrushes,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
max: {
x: x.max,
y: y.max,
width: width,
height: height
}
};
}
}, {
key: "getCursor",
value: function getCursor(props) {
var _props$activeBrushes = props.activeBrushes,
activeBrushes = _props$activeBrushes === void 0 ? {} : _props$activeBrushes;
var dimension = getDimension(props);
// Don't trigger events for static brushes
if (!allowResize && !allowDrag) {
return [];
if (activeBrushes.minHandle || activeBrushes.maxHandle) {
return dimension === "x" ? "ew-resize" : "ns-resize";
} else if (activeBrushes.brush) {
return "move";
}
return "crosshair";
}
}, {
key: "renderHandles",
value: function renderHandles(props) {
var handleComponent = props.handleComponent,
handleStyle = props.handleStyle,
id = props.id,
brushDomain = props.brushDomain,
_props$datum = props.datum,
datum = _props$datum === void 0 ? {} : _props$datum,
_props$activeBrushes2 = props.activeBrushes,
activeBrushes = _props$activeBrushes2 === void 0 ? {} : _props$activeBrushes2;
if (!brushDomain) {
return null;
}
var handleDimensions = this.getHandleDimensions(props);
var style = Object.assign({}, fallbackProps.handleStyle, handleStyle);
var minDatum = Object.assign({
handleValue: Collection.getMinValue(brushDomain)
}, datum);
var maxDatum = Object.assign({
handleValue: Collection.getMaxValue(brushDomain)
}, datum);
var minHandleProps = Object.assign({
key: "".concat(id, "-min"),
style: Helpers.evaluateStyle(style, {
datum: minDatum,
active: activeBrushes.minHandle
})
}, handleDimensions.min);
var maxHandleProps = Object.assign({
key: "".concat(id, "-max"),
style: Helpers.evaluateStyle(style, {
datum: maxDatum,
active: activeBrushes.maxHandle
})
}, handleDimensions.max);
return [/*#__PURE__*/React.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/React.cloneElement(handleComponent, maxHandleProps)];
}
}, {
key: "renderBrush",
value: function renderBrush(props) {
var brushComponent = props.brushComponent,
brushStyle = props.brushStyle,
_props$activeBrushes3 = props.activeBrushes,
activeBrushes = _props$activeBrushes3 === void 0 ? {} : _props$activeBrushes3,
_props$datum2 = props.datum,
datum = _props$datum2 === void 0 ? {} : _props$datum2,
brushDomain = props.brushDomain;
if (!brushDomain) {
return null;
}
var brushWidth = props.brushWidth || props.width;
var rectDimensions = this.getRectDimensions(props, brushWidth);
var baseStyle = Object.assign({}, fallbackProps.brushStyle, brushStyle);
var style = Helpers.evaluateStyle(baseStyle, {
datum: datum,
active: activeBrushes.brush
});
var brushProps = Object.assign({
style: style
}, rectDimensions);
return /*#__PURE__*/React.cloneElement(brushComponent, brushProps);
}
}, {
key: "renderBrushArea",
value: function renderBrushArea(props) {
var brushAreaComponent = props.brushAreaComponent,
brushAreaStyle = props.brushAreaStyle,
_props$activeBrushes4 = props.activeBrushes,
activeBrushes = _props$activeBrushes4 === void 0 ? {} : _props$activeBrushes4,
_props$datum3 = props.datum,
datum = _props$datum3 === void 0 ? {} : _props$datum3;
var brushAreaWidth = props.brushAreaWidth || props.width;
var cursor = this.getCursor(props);
var rectDimensions = this.getRectDimensions(props, brushAreaWidth, getFullDomain(props));
var baseStyle = Object.assign({
cursor: cursor
}, fallbackProps.brushAreaStyle, brushAreaStyle);
var style = Helpers.evaluateStyle(baseStyle, {
datum: datum,
active: activeBrushes.brushArea
});
var brushAreaProps = Object.assign({
style: style
}, rectDimensions);
return /*#__PURE__*/React.cloneElement(brushAreaComponent, brushAreaProps);
}
}, {
key: "renderLine",
value: function renderLine(props) {
var filteredProps = _pick(props, ["x1", "x2", "y1", "y2", "datum", "scale", "active", "style"]);
return /*#__PURE__*/React.cloneElement(props.lineComponent, filteredProps);
}
}, {
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props));
}
}]);
return VictoryBrushLine;
}(React.Component);
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
};
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
};
}
const fullDomain = getFullDomain(targetProps);
const currentDomain = getBrushDomain(brushDomain, fullDomain);
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
const position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const range = toRange(targetProps, currentDomain);
const activeHandle = allowResize && getActiveHandle(targetProps, position, range);
// If the event occurs in any of the handle regions, start a resize
if (activeHandle) {
return [{
mutation: () => {
return {
parentSVG,
isSelecting: true,
activeHandle,
brushDomain: currentDomain,
startPosition: position,
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: () => ({
}];
},
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,
parentSVG
})
}];
}
// if the event occurs outside the region, or if the whole domain is selected,
// start a new selection
return allowDraw ? [{
mutation: () => ({
activeBrushes: activeBrushes,
parentSVG: parentSVG
};
}
}];
} // 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,
parentSVG
})
}] : [];
},
// eslint-disable-next-line max-statements, complexity
onMouseMove: (evt, targetProps) => {
const {
isPanning,
isSelecting,
allowResize,
allowDrag,
onBrushDomainChange,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
if (isPanning || isSelecting) {
evt.preventDefault();
evt.stopPropagation();
activeBrushes: activeBrushes,
parentSVG: parentSVG
};
}
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
const position = Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const fullDomain = getFullDomain(targetProps);
const domain = getBrushDomain(brushDomain, fullDomain);
const initialRange = toRange(targetProps, domain);
const activeHandle = getActiveHandle(targetProps, position, initialRange);
const activeBrushes = {
brushArea: !targetProps.brushDomain,
brush: withinBound(position, initialRange) && !isEqual(fullDomain, domain),
minHandle: activeHandle === "min" || activeHandle === "both",
maxHandle: activeHandle === "max" || activeHandle === "both"
}] : [];
},
// 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 (!targetProps.isPanning && !targetProps.isSelecting) {
return [{
mutation: function () {
return {
activeBrushes: activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG: parentSVG
};
}
}];
}
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: () => ({
activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG
})
}];
if (Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
}
if (allowDrag && isPanning) {
const fullRange = getFullRange(targetProps);
const range = panBox(targetProps, position);
const currentDomain = toDomain(targetProps, range);
const startPosition = Math.max(...range) >= Math.max(...fullRange) || Math.min(...range) <= Math.min(...fullRange) ? targetProps.startPosition : position;
const mutatedProps = {
startPosition,
isPanning: true,
brushDomain: currentDomain,
activeBrushes: {
brush: true
},
parentSVG
};
if (Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
return [{
mutation: function () {
return mutatedProps;
}
return [{
mutation: () => mutatedProps
}];
} else if (allowResize && isSelecting) {
let currentDomain = brushDomain || getMinimumDomain();
const range = toRange(targetProps, currentDomain);
const oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min";
const handle = targetProps.activeHandle && getActiveHandle(targetProps, position, range) === "both" ? oppositeHandle : targetProps.activeHandle;
if (!handle) {
currentDomain = toDomain(targetProps, [targetProps.startPosition, position]);
} else {
const rangeMax = dimension === "x" ? Math.max(...range) : Math.min(...range);
const rangeMin = dimension === "x" ? Math.min(...range) : Math.max(...range);
const min = handle === "max" ? rangeMin : position;
const max = handle === "min" ? rangeMax : position;
currentDomain = toDomain(targetProps, [min, max]);
}];
} else if (allowResize && isSelecting) {
var _currentDomain = brushDomain || getMinimumDomain();
var _range = toRange(targetProps, _currentDomain);
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]);
}
var _mutatedProps = {
brushDomain: _currentDomain,
startPosition: targetProps.startPosition,
isSelecting: isSelecting,
activeHandle: handle,
parentSVG: parentSVG,
activeBrushes: {
brush: true,
minHandle: activeHandle === "min",
maxHandle: activeHandle === "max"
}
const mutatedProps = {
brushDomain: currentDomain,
startPosition: targetProps.startPosition,
isSelecting,
activeHandle: handle,
parentSVG,
activeBrushes: {
brush: true,
minHandle: activeHandle === "min",
maxHandle: activeHandle === "max"
}
};
if (Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, _defaults({}, mutatedProps, targetProps));
}
return [{
mutation: () => mutatedProps
}];
}
return [];
},
onMouseUp: (evt, targetProps) => {
const {
onBrushDomainChange,
brushDomain,
allowResize,
activeBrushes
} = targetProps;
// if the mouse hasn't moved since a mouseDown event, select the whole domain region
const mutatedProps = {
isPanning: false,
isSelecting: false,
activeHandle: null,
startPosition: null,
brushDomain,
activeBrushes
};
if (allowResize && Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(brushDomain, _defaults({}, mutatedProps, targetProps));
if (Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(_currentDomain, _defaults({}, _mutatedProps, targetProps));
}
return [{
mutation: () => mutatedProps
mutation: function () {
return _mutatedProps;
}
}];
},
onMouseLeave: (evt, targetProps) => {
const {
brushDomain
} = targetProps;
return [{
mutation: () => ({
}
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 && Helpers.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,

@@ -359,188 +636,10 @@ isSelecting: false,

startPosition: null,
brushDomain,
brushDomain: brushDomain,
activeBrushes: {}
})
}];
}
};
}
}];
}
}];
};
getRectDimensions(props, brushWidth, domain) {
const {
brushDomain
} = props;
const dimension = getDimension(props);
const range = toRange(props, domain || getBrushDomain(brushDomain, getFullDomain(props)));
const coordinates = dimension === "x" ? {
y1: props.y1,
y2: props.y2,
x1: Math.min(...range),
x2: Math.max(...range)
} : {
x1: props.x1,
x2: props.x2,
y1: Math.min(...range),
y2: Math.max(...range)
};
const {
x1,
x2,
y1,
y2
} = coordinates;
const offset = {
x: dimension === "x" ? 0 : brushWidth / 2,
y: dimension === "y" ? 0 : brushWidth / 2
};
const x = Math.min(x1, x2) - offset.x;
const y = Math.min(y1, y2) - offset.y;
const width = Math.max(x1, x2) + offset.x - x;
const height = Math.max(y1, y2) + offset.y - y;
return {
x,
y,
width,
height
};
}
getHandleDimensions(props) {
const {
handleWidth,
x1,
x2,
y1,
y2,
brushDomain
} = props;
const dimension = getDimension(props);
const brushWidth = props.brushWidth || props.width;
const domain = getBrushDomain(brushDomain, getFullDomain(props));
const range = toRange(props, domain);
const defaultX = Math.min(x1, x2) - brushWidth / 2;
const defaultY = Math.min(y1, y2) - brushWidth / 2;
const x = {
min: dimension === "x" ? Math.min(...range) - handleWidth / 2 : defaultX,
max: dimension === "x" ? Math.max(...range) - handleWidth / 2 : defaultX
};
const y = {
min: dimension === "y" ? Math.max(...range) - handleWidth / 2 : defaultY,
max: dimension === "y" ? Math.min(...range) - handleWidth / 2 : defaultY
};
const width = dimension === "x" ? handleWidth : brushWidth;
const height = dimension === "x" ? brushWidth : handleWidth;
return {
min: {
x: x.min,
y: y.min,
width,
height
},
max: {
x: x.max,
y: y.max,
width,
height
}
};
}
getCursor(props) {
const {
activeBrushes = {}
} = props;
const dimension = getDimension(props);
if (activeBrushes.minHandle || activeBrushes.maxHandle) {
return dimension === "x" ? "ew-resize" : "ns-resize";
} else if (activeBrushes.brush) {
return "move";
}
return "crosshair";
}
renderHandles(props) {
const {
handleComponent,
handleStyle,
id,
brushDomain,
datum = {},
activeBrushes = {}
} = props;
if (!brushDomain) {
return null;
}
const handleDimensions = this.getHandleDimensions(props);
const style = Object.assign({}, fallbackProps.handleStyle, handleStyle);
const minDatum = Object.assign({
handleValue: Collection.getMinValue(brushDomain)
}, datum);
const maxDatum = Object.assign({
handleValue: Collection.getMaxValue(brushDomain)
}, datum);
const minHandleProps = Object.assign({
key: `${id}-min`,
style: Helpers.evaluateStyle(style, {
datum: minDatum,
active: activeBrushes.minHandle
})
}, handleDimensions.min);
const maxHandleProps = Object.assign({
key: `${id}-max`,
style: Helpers.evaluateStyle(style, {
datum: maxDatum,
active: activeBrushes.maxHandle
})
}, handleDimensions.max);
return [/*#__PURE__*/React.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/React.cloneElement(handleComponent, maxHandleProps)];
}
renderBrush(props) {
const {
brushComponent,
brushStyle,
activeBrushes = {},
datum = {},
brushDomain
} = props;
if (!brushDomain) {
return null;
}
const brushWidth = props.brushWidth || props.width;
const rectDimensions = this.getRectDimensions(props, brushWidth);
const baseStyle = Object.assign({}, fallbackProps.brushStyle, brushStyle);
const style = Helpers.evaluateStyle(baseStyle, {
datum,
active: activeBrushes.brush
});
const brushProps = Object.assign({
style
}, rectDimensions);
return /*#__PURE__*/React.cloneElement(brushComponent, brushProps);
}
renderBrushArea(props) {
const {
brushAreaComponent,
brushAreaStyle,
activeBrushes = {},
datum = {}
} = props;
const brushAreaWidth = props.brushAreaWidth || props.width;
const cursor = this.getCursor(props);
const rectDimensions = this.getRectDimensions(props, brushAreaWidth, getFullDomain(props));
const baseStyle = Object.assign({
cursor
}, fallbackProps.brushAreaStyle, brushAreaStyle);
const style = Helpers.evaluateStyle(baseStyle, {
datum,
active: activeBrushes.brushArea
});
const brushAreaProps = Object.assign({
style
}, rectDimensions);
return /*#__PURE__*/React.cloneElement(brushAreaComponent, brushAreaProps);
}
renderLine(props) {
const filteredProps = _pick(props, ["x1", "x2", "y1", "y2", "datum", "scale", "active", "style"]);
return /*#__PURE__*/React.cloneElement(props.lineComponent, filteredProps);
}
render() {
return /*#__PURE__*/React.createElement("g", this.props.events, this.renderLine(this.props), this.renderBrushArea(this.props), this.renderBrush(this.props), this.renderHandles(this.props));
}
}
}];
};

@@ -6,3 +6,5 @@ "use strict";

});
var _victoryBrushLine = require("./victory-brush-line");
Object.keys(_victoryBrushLine).forEach(function (key) {

@@ -9,0 +11,0 @@ if (key === "default" || key === "__esModule") return;

@@ -7,77 +7,137 @@ "use strict";

exports.VictoryBrushLine = void 0;
var _pick2 = _interopRequireDefault(require("lodash/pick"));
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
var _react = _interopRequireDefault(require("react"));
var _victoryCore = require("victory-core");
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const SMALL_NUMBER = 1 / Number.MAX_SAFE_INTEGER;
const getScale = props => {
const {
scale = {},
dimension = "x"
} = props;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
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 _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 ? Object.setPrototypeOf.bind() : 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 _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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
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;
var getScale = function (props) {
var _props$scale = props.scale,
scale = _props$scale === void 0 ? {} : _props$scale,
_props$dimension = props.dimension,
dimension = _props$dimension === void 0 ? "x" : _props$dimension;
if (scale[dimension]) {
return scale[dimension];
}
const fallbackScale = _victoryCore.Scale.getBaseScale(props, dimension);
const range = _victoryCore.Helpers.getRange(props, dimension);
const domain = _victoryCore.Domain.getDomainFromProps(props, dimension) || [0, 1];
var fallbackScale = _victoryCore.Scale.getBaseScale(props, dimension);
var range = _victoryCore.Helpers.getRange(props, dimension);
var domain = _victoryCore.Domain.getDomainFromProps(props, dimension) || [0, 1];
fallbackScale.range(range).domain(domain);
return fallbackScale;
};
const getDimension = props => {
const {
horizontal,
dimension = "x"
} = props;
var getDimension = function (props) {
var horizontal = props.horizontal,
_props$dimension2 = props.dimension,
dimension = _props$dimension2 === void 0 ? "x" : _props$dimension2;
if (!horizontal) {
return dimension;
}
return dimension === "x" ? "y" : "x";
};
const toRange = (props, domain) => {
const scale = getScale(props);
return [scale(Math.min(...domain)), scale(Math.max(...domain))];
var toRange = function (props, domain) {
var scale = getScale(props);
return [scale(Math.min.apply(Math, _toConsumableArray(domain))), scale(Math.max.apply(Math, _toConsumableArray(domain)))];
};
const toDomain = (props, range) => {
const scale = getScale(props);
return [scale.invert(Math.min(...range)), scale.invert(Math.max(...range))];
var toDomain = function (props, range) {
var scale = getScale(props);
return [scale.invert(Math.min.apply(Math, _toConsumableArray(range))), scale.invert(Math.max.apply(Math, _toConsumableArray(range)))];
};
const getFullRange = props => {
const scale = getScale(props);
var getFullRange = function (props) {
var scale = getScale(props);
return scale.range();
};
const getFullDomain = props => {
const scale = getScale(props);
var getFullDomain = function (props) {
var scale = getScale(props);
return scale.domain();
};
const withinBound = (value, bound) => {
var withinBound = function (value, bound) {
return value >= _victoryCore.Collection.getMinValue(bound) && value <= _victoryCore.Collection.getMaxValue(bound);
};
const getBrushDomain = (brushDomain, fullDomain) => {
var getBrushDomain = function (brushDomain, fullDomain) {
if (brushDomain) {
const brushMin = _victoryCore.Collection.getMinValue(brushDomain);
const brushMax = _victoryCore.Collection.getMaxValue(brushDomain);
const domainMin = _victoryCore.Collection.getMinValue(fullDomain);
const domainMax = _victoryCore.Collection.getMaxValue(fullDomain);
const defaultMin = brushMin < domainMin ? domainMin : Number(domainMax) - SMALL_NUMBER;
const defaultMax = brushMax > domainMax ? domainMax : Number(domainMin) + SMALL_NUMBER;
const min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
const max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
var brushMin = _victoryCore.Collection.getMinValue(brushDomain);
var brushMax = _victoryCore.Collection.getMaxValue(brushDomain);
var domainMin = _victoryCore.Collection.getMinValue(fullDomain);
var domainMax = _victoryCore.Collection.getMaxValue(fullDomain);
var defaultMin = brushMin < domainMin ? domainMin : Number(domainMax) - SMALL_NUMBER;
var defaultMax = brushMax > domainMax ? domainMax : Number(domainMin) + SMALL_NUMBER;
var min = withinBound(brushMin, fullDomain) ? brushMin : defaultMin;
var max = withinBound(brushMax, fullDomain) ? brushMax : defaultMax;
return [min, max];
}
return fullDomain;
};
const getActiveHandle = (props, position, range) => {
const width = props.handleWidth / 2;
const dimension = getDimension(props);
const getHandle = type => {
const base = {
min: dimension === "x" ? Math.min(...range) : Math.max(...range),
max: dimension === "x" ? Math.max(...range) : Math.min(...range)
var getActiveHandle = function (props, position, range) {
var width = props.handleWidth / 2;
var dimension = getDimension(props);
var getHandle = function (type) {
var base = {
min: dimension === "x" ? Math.min.apply(Math, _toConsumableArray(range)) : Math.max.apply(Math, _toConsumableArray(range)),
max: dimension === "x" ? Math.max.apply(Math, _toConsumableArray(range)) : Math.min.apply(Math, _toConsumableArray(range))
};
return [base[type] - width, base[type] + width];
};
const active = ["min", "max"].reduce((memo, type) => {
var active = ["min", "max"].reduce(function (memo, type) {
memo[type] = withinBound(position, getHandle(type)) ? type : undefined;

@@ -88,32 +148,32 @@ return memo;

};
const getMinimumDomain = () => {
var getMinimumDomain = function () {
return [0, SMALL_NUMBER];
};
const panBox = (props, position) => {
const {
brushDomain,
startPosition
} = props;
const range = toRange(props, brushDomain);
const fullRange = getFullRange(props);
const size = Math.abs(range[1] - range[0]);
const globalMin = Math.min(...fullRange);
const globalMax = Math.max(...fullRange);
const delta = startPosition ? startPosition - position : 0;
const min = Math.min(...range) - delta;
const max = Math.max(...range) - delta;
const constrainedMin = min > globalMax - size ? globalMax - size : Math.max(min, globalMin);
const constrainedMax = max < globalMin + size ? globalMin + size : Math.min(max, globalMax);
var panBox = function (props, position) {
var brushDomain = props.brushDomain,
startPosition = props.startPosition;
var range = toRange(props, brushDomain);
var fullRange = getFullRange(props);
var size = Math.abs(range[1] - range[0]);
var globalMin = Math.min.apply(Math, _toConsumableArray(fullRange));
var globalMax = Math.max.apply(Math, _toConsumableArray(fullRange));
var delta = startPosition ? startPosition - position : 0;
var min = Math.min.apply(Math, _toConsumableArray(range)) - delta;
var max = Math.max.apply(Math, _toConsumableArray(range)) - delta;
var constrainedMin = min > globalMax - size ? globalMax - size : Math.max(min, globalMin);
var constrainedMax = max < globalMin + size ? globalMin + size : Math.min(max, globalMax);
return [constrainedMin, constrainedMax];
};
const fallbackProps = {
var fallbackProps = {
brushAreaStyle: {
stroke: "none",
fill: "black",
opacity: _ref => {
let {
active
} = _ref;
opacity: function (_ref) {
var active = _ref.active;
return active ? 0.2 : 0.1;
} // eslint-disable-line no-magic-numbers
},

@@ -124,8 +184,7 @@ brushStyle: {

fill: "black",
opacity: _ref2 => {
let {
active
} = _ref2;
opacity: function (_ref2) {
var active = _ref2.active;
return active ? 0.4 : 0.3;
} // eslint-disable-line no-magic-numbers
},

@@ -138,226 +197,470 @@ handleStyle: {

};
class VictoryBrushLine extends _react.default.Component {
static 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
};
static defaultEvents = function (props) {
return props.disable ? undefined : [{
target: props.type,
eventHandlers: {
onMouseEnter: (evt, targetProps) => {
evt.preventDefault();
const {
allowResize,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
const parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
const position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const fullDomain = getFullDomain(targetProps);
const currentDomain = getBrushDomain(brushDomain, fullDomain);
const range = toRange(targetProps, currentDomain);
const activeHandle = allowResize && getActiveHandle(targetProps, position, range);
const 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: () => ({
activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG
})
}];
var VictoryBrushLine = /*#__PURE__*/function (_React$Component) {
_inherits(VictoryBrushLine, _React$Component);
var _super = _createSuper(VictoryBrushLine);
function VictoryBrushLine() {
_classCallCheck(this, VictoryBrushLine);
return _super.apply(this, arguments);
}
_createClass(VictoryBrushLine, [{
key: "getRectDimensions",
value: function getRectDimensions(props, brushWidth, domain) {
var brushDomain = props.brushDomain;
var dimension = getDimension(props);
var range = toRange(props, domain || getBrushDomain(brushDomain, getFullDomain(props)));
var coordinates = dimension === "x" ? {
y1: props.y1,
y2: props.y2,
x1: Math.min.apply(Math, _toConsumableArray(range)),
x2: Math.max.apply(Math, _toConsumableArray(range))
} : {
x1: props.x1,
x2: props.x2,
y1: Math.min.apply(Math, _toConsumableArray(range)),
y2: Math.max.apply(Math, _toConsumableArray(range))
};
var x1 = coordinates.x1,
x2 = coordinates.x2,
y1 = coordinates.y1,
y2 = coordinates.y2;
var offset = {
x: dimension === "x" ? 0 : brushWidth / 2,
y: dimension === "y" ? 0 : brushWidth / 2
};
var x = Math.min(x1, x2) - offset.x;
var y = Math.min(y1, y2) - offset.y;
var width = Math.max(x1, x2) + offset.x - x;
var height = Math.max(y1, y2) + offset.y - y;
return {
x: x,
y: y,
width: width,
height: height
};
}
}, {
key: "getHandleDimensions",
value: function getHandleDimensions(props) {
var handleWidth = props.handleWidth,
x1 = props.x1,
x2 = props.x2,
y1 = props.y1,
y2 = props.y2,
brushDomain = props.brushDomain;
var dimension = getDimension(props);
var brushWidth = props.brushWidth || props.width;
var domain = getBrushDomain(brushDomain, getFullDomain(props));
var range = toRange(props, domain);
var defaultX = Math.min(x1, x2) - brushWidth / 2;
var defaultY = Math.min(y1, y2) - brushWidth / 2;
var x = {
min: dimension === "x" ? Math.min.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultX,
max: dimension === "x" ? Math.max.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultX
};
var y = {
min: dimension === "y" ? Math.max.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultY,
max: dimension === "y" ? Math.min.apply(Math, _toConsumableArray(range)) - handleWidth / 2 : defaultY
};
var width = dimension === "x" ? handleWidth : brushWidth;
var height = dimension === "x" ? brushWidth : handleWidth;
return {
min: {
x: x.min,
y: y.min,
width: width,
height: height
},
onMouseDown: (evt, targetProps) => {
evt.preventDefault();
const {
allowResize,
allowDrag,
allowDraw,
activeBrushes,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
max: {
x: x.max,
y: y.max,
width: width,
height: height
}
};
}
}, {
key: "getCursor",
value: function getCursor(props) {
var _props$activeBrushes = props.activeBrushes,
activeBrushes = _props$activeBrushes === void 0 ? {} : _props$activeBrushes;
var dimension = getDimension(props);
// Don't trigger events for static brushes
if (!allowResize && !allowDrag) {
return [];
if (activeBrushes.minHandle || activeBrushes.maxHandle) {
return dimension === "x" ? "ew-resize" : "ns-resize";
} else if (activeBrushes.brush) {
return "move";
}
return "crosshair";
}
}, {
key: "renderHandles",
value: function renderHandles(props) {
var handleComponent = props.handleComponent,
handleStyle = props.handleStyle,
id = props.id,
brushDomain = props.brushDomain,
_props$datum = props.datum,
datum = _props$datum === void 0 ? {} : _props$datum,
_props$activeBrushes2 = props.activeBrushes,
activeBrushes = _props$activeBrushes2 === void 0 ? {} : _props$activeBrushes2;
if (!brushDomain) {
return null;
}
var handleDimensions = this.getHandleDimensions(props);
var style = Object.assign({}, fallbackProps.handleStyle, handleStyle);
var minDatum = Object.assign({
handleValue: _victoryCore.Collection.getMinValue(brushDomain)
}, datum);
var maxDatum = Object.assign({
handleValue: _victoryCore.Collection.getMaxValue(brushDomain)
}, datum);
var minHandleProps = Object.assign({
key: "".concat(id, "-min"),
style: _victoryCore.Helpers.evaluateStyle(style, {
datum: minDatum,
active: activeBrushes.minHandle
})
}, handleDimensions.min);
var maxHandleProps = Object.assign({
key: "".concat(id, "-max"),
style: _victoryCore.Helpers.evaluateStyle(style, {
datum: maxDatum,
active: activeBrushes.maxHandle
})
}, handleDimensions.max);
return [/*#__PURE__*/_react.default.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/_react.default.cloneElement(handleComponent, maxHandleProps)];
}
}, {
key: "renderBrush",
value: function renderBrush(props) {
var brushComponent = props.brushComponent,
brushStyle = props.brushStyle,
_props$activeBrushes3 = props.activeBrushes,
activeBrushes = _props$activeBrushes3 === void 0 ? {} : _props$activeBrushes3,
_props$datum2 = props.datum,
datum = _props$datum2 === void 0 ? {} : _props$datum2,
brushDomain = props.brushDomain;
if (!brushDomain) {
return null;
}
var brushWidth = props.brushWidth || props.width;
var rectDimensions = this.getRectDimensions(props, brushWidth);
var baseStyle = Object.assign({}, fallbackProps.brushStyle, brushStyle);
var style = _victoryCore.Helpers.evaluateStyle(baseStyle, {
datum: datum,
active: activeBrushes.brush
});
var brushProps = Object.assign({
style: style
}, rectDimensions);
return /*#__PURE__*/_react.default.cloneElement(brushComponent, brushProps);
}
}, {
key: "renderBrushArea",
value: function renderBrushArea(props) {
var brushAreaComponent = props.brushAreaComponent,
brushAreaStyle = props.brushAreaStyle,
_props$activeBrushes4 = props.activeBrushes,
activeBrushes = _props$activeBrushes4 === void 0 ? {} : _props$activeBrushes4,
_props$datum3 = props.datum,
datum = _props$datum3 === void 0 ? {} : _props$datum3;
var brushAreaWidth = props.brushAreaWidth || props.width;
var cursor = this.getCursor(props);
var rectDimensions = this.getRectDimensions(props, brushAreaWidth, getFullDomain(props));
var baseStyle = Object.assign({
cursor: cursor
}, fallbackProps.brushAreaStyle, brushAreaStyle);
var style = _victoryCore.Helpers.evaluateStyle(baseStyle, {
datum: datum,
active: activeBrushes.brushArea
});
var brushAreaProps = Object.assign({
style: style
}, rectDimensions);
return /*#__PURE__*/_react.default.cloneElement(brushAreaComponent, brushAreaProps);
}
}, {
key: "renderLine",
value: function renderLine(props) {
var filteredProps = (0, _pick2.default)(props, ["x1", "x2", "y1", "y2", "datum", "scale", "active", "style"]);
return /*#__PURE__*/_react.default.cloneElement(props.lineComponent, filteredProps);
}
}, {
key: "render",
value: function render() {
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));
}
}]);
return VictoryBrushLine;
}(_react.default.Component);
exports.VictoryBrushLine = VictoryBrushLine;
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
};
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 || _victoryCore.Selection.getParentSVG(evt);
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
};
}
const fullDomain = getFullDomain(targetProps);
const currentDomain = getBrushDomain(brushDomain, fullDomain);
const parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
const position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const range = toRange(targetProps, currentDomain);
const activeHandle = allowResize && getActiveHandle(targetProps, position, range);
// If the event occurs in any of the handle regions, start a resize
if (activeHandle) {
return [{
mutation: () => {
return {
parentSVG,
isSelecting: true,
activeHandle,
brushDomain: currentDomain,
startPosition: position,
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: () => ({
}];
},
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,
parentSVG
})
}];
}
// if the event occurs outside the region, or if the whole domain is selected,
// start a new selection
return allowDraw ? [{
mutation: () => ({
activeBrushes: activeBrushes,
parentSVG: parentSVG
};
}
}];
} // 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,
parentSVG
})
}] : [];
},
// eslint-disable-next-line max-statements, complexity
onMouseMove: (evt, targetProps) => {
const {
isPanning,
isSelecting,
allowResize,
allowDrag,
onBrushDomainChange,
brushDomain
} = targetProps;
const dimension = getDimension(targetProps);
if (isPanning || isSelecting) {
evt.preventDefault();
evt.stopPropagation();
activeBrushes: activeBrushes,
parentSVG: parentSVG
};
}
const parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
const position = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG)[dimension];
const fullDomain = getFullDomain(targetProps);
const domain = getBrushDomain(brushDomain, fullDomain);
const initialRange = toRange(targetProps, domain);
const activeHandle = getActiveHandle(targetProps, position, initialRange);
const activeBrushes = {
brushArea: !targetProps.brushDomain,
brush: withinBound(position, initialRange) && !(0, _reactFastCompare.default)(fullDomain, domain),
minHandle: activeHandle === "min" || activeHandle === "both",
maxHandle: activeHandle === "max" || activeHandle === "both"
}] : [];
},
// 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 (!targetProps.isPanning && !targetProps.isSelecting) {
return [{
mutation: function () {
return {
activeBrushes: activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG: parentSVG
};
}
}];
}
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: () => ({
activeBrushes,
brushDomain: targetProps.brushDomain,
parentSVG
})
}];
if (_victoryCore.Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, (0, _defaults2.default)({}, mutatedProps, targetProps));
}
if (allowDrag && isPanning) {
const fullRange = getFullRange(targetProps);
const range = panBox(targetProps, position);
const currentDomain = toDomain(targetProps, range);
const startPosition = Math.max(...range) >= Math.max(...fullRange) || Math.min(...range) <= Math.min(...fullRange) ? targetProps.startPosition : position;
const mutatedProps = {
startPosition,
isPanning: true,
brushDomain: currentDomain,
activeBrushes: {
brush: true
},
parentSVG
};
if (_victoryCore.Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, (0, _defaults2.default)({}, mutatedProps, targetProps));
return [{
mutation: function () {
return mutatedProps;
}
return [{
mutation: () => mutatedProps
}];
} else if (allowResize && isSelecting) {
let currentDomain = brushDomain || getMinimumDomain();
const range = toRange(targetProps, currentDomain);
const oppositeHandle = targetProps.activeHandle === "min" ? "max" : "min";
const handle = targetProps.activeHandle && getActiveHandle(targetProps, position, range) === "both" ? oppositeHandle : targetProps.activeHandle;
if (!handle) {
currentDomain = toDomain(targetProps, [targetProps.startPosition, position]);
} else {
const rangeMax = dimension === "x" ? Math.max(...range) : Math.min(...range);
const rangeMin = dimension === "x" ? Math.min(...range) : Math.max(...range);
const min = handle === "max" ? rangeMin : position;
const max = handle === "min" ? rangeMax : position;
currentDomain = toDomain(targetProps, [min, max]);
}];
} else if (allowResize && isSelecting) {
var _currentDomain = brushDomain || getMinimumDomain();
var _range = toRange(targetProps, _currentDomain);
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]);
}
var _mutatedProps = {
brushDomain: _currentDomain,
startPosition: targetProps.startPosition,
isSelecting: isSelecting,
activeHandle: handle,
parentSVG: parentSVG,
activeBrushes: {
brush: true,
minHandle: activeHandle === "min",
maxHandle: activeHandle === "max"
}
const mutatedProps = {
brushDomain: currentDomain,
startPosition: targetProps.startPosition,
isSelecting,
activeHandle: handle,
parentSVG,
activeBrushes: {
brush: true,
minHandle: activeHandle === "min",
maxHandle: activeHandle === "max"
}
};
if (_victoryCore.Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(currentDomain, (0, _defaults2.default)({}, mutatedProps, targetProps));
}
return [{
mutation: () => mutatedProps
}];
}
return [];
},
onMouseUp: (evt, targetProps) => {
const {
onBrushDomainChange,
brushDomain,
allowResize,
activeBrushes
} = targetProps;
// if the mouse hasn't moved since a mouseDown event, select the whole domain region
const mutatedProps = {
isPanning: false,
isSelecting: false,
activeHandle: null,
startPosition: null,
brushDomain,
activeBrushes
};
if (allowResize && _victoryCore.Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(brushDomain, (0, _defaults2.default)({}, mutatedProps, targetProps));
if (_victoryCore.Helpers.isFunction(onBrushDomainChange)) {
onBrushDomainChange(_currentDomain, (0, _defaults2.default)({}, _mutatedProps, targetProps));
}
return [{
mutation: () => mutatedProps
mutation: function () {
return _mutatedProps;
}
}];
},
onMouseLeave: (evt, targetProps) => {
const {
brushDomain
} = targetProps;
return [{
mutation: () => ({
}
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 && _victoryCore.Helpers.isFunction(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,

@@ -367,189 +670,10 @@ isSelecting: false,

startPosition: null,
brushDomain,
brushDomain: brushDomain,
activeBrushes: {}
})
}];
}
};
}
}];
}
}];
};
getRectDimensions(props, brushWidth, domain) {
const {
brushDomain
} = props;
const dimension = getDimension(props);
const range = toRange(props, domain || getBrushDomain(brushDomain, getFullDomain(props)));
const coordinates = dimension === "x" ? {
y1: props.y1,
y2: props.y2,
x1: Math.min(...range),
x2: Math.max(...range)
} : {
x1: props.x1,
x2: props.x2,
y1: Math.min(...range),
y2: Math.max(...range)
};
const {
x1,
x2,
y1,
y2
} = coordinates;
const offset = {
x: dimension === "x" ? 0 : brushWidth / 2,
y: dimension === "y" ? 0 : brushWidth / 2
};
const x = Math.min(x1, x2) - offset.x;
const y = Math.min(y1, y2) - offset.y;
const width = Math.max(x1, x2) + offset.x - x;
const height = Math.max(y1, y2) + offset.y - y;
return {
x,
y,
width,
height
};
}
getHandleDimensions(props) {
const {
handleWidth,
x1,
x2,
y1,
y2,
brushDomain
} = props;
const dimension = getDimension(props);
const brushWidth = props.brushWidth || props.width;
const domain = getBrushDomain(brushDomain, getFullDomain(props));
const range = toRange(props, domain);
const defaultX = Math.min(x1, x2) - brushWidth / 2;
const defaultY = Math.min(y1, y2) - brushWidth / 2;
const x = {
min: dimension === "x" ? Math.min(...range) - handleWidth / 2 : defaultX,
max: dimension === "x" ? Math.max(...range) - handleWidth / 2 : defaultX
};
const y = {
min: dimension === "y" ? Math.max(...range) - handleWidth / 2 : defaultY,
max: dimension === "y" ? Math.min(...range) - handleWidth / 2 : defaultY
};
const width = dimension === "x" ? handleWidth : brushWidth;
const height = dimension === "x" ? brushWidth : handleWidth;
return {
min: {
x: x.min,
y: y.min,
width,
height
},
max: {
x: x.max,
y: y.max,
width,
height
}
};
}
getCursor(props) {
const {
activeBrushes = {}
} = props;
const dimension = getDimension(props);
if (activeBrushes.minHandle || activeBrushes.maxHandle) {
return dimension === "x" ? "ew-resize" : "ns-resize";
} else if (activeBrushes.brush) {
return "move";
}
return "crosshair";
}
renderHandles(props) {
const {
handleComponent,
handleStyle,
id,
brushDomain,
datum = {},
activeBrushes = {}
} = props;
if (!brushDomain) {
return null;
}
const handleDimensions = this.getHandleDimensions(props);
const style = Object.assign({}, fallbackProps.handleStyle, handleStyle);
const minDatum = Object.assign({
handleValue: _victoryCore.Collection.getMinValue(brushDomain)
}, datum);
const maxDatum = Object.assign({
handleValue: _victoryCore.Collection.getMaxValue(brushDomain)
}, datum);
const minHandleProps = Object.assign({
key: `${id}-min`,
style: _victoryCore.Helpers.evaluateStyle(style, {
datum: minDatum,
active: activeBrushes.minHandle
})
}, handleDimensions.min);
const maxHandleProps = Object.assign({
key: `${id}-max`,
style: _victoryCore.Helpers.evaluateStyle(style, {
datum: maxDatum,
active: activeBrushes.maxHandle
})
}, handleDimensions.max);
return [/*#__PURE__*/_react.default.cloneElement(handleComponent, minHandleProps), /*#__PURE__*/_react.default.cloneElement(handleComponent, maxHandleProps)];
}
renderBrush(props) {
const {
brushComponent,
brushStyle,
activeBrushes = {},
datum = {},
brushDomain
} = props;
if (!brushDomain) {
return null;
}
const brushWidth = props.brushWidth || props.width;
const rectDimensions = this.getRectDimensions(props, brushWidth);
const baseStyle = Object.assign({}, fallbackProps.brushStyle, brushStyle);
const style = _victoryCore.Helpers.evaluateStyle(baseStyle, {
datum,
active: activeBrushes.brush
});
const brushProps = Object.assign({
style
}, rectDimensions);
return /*#__PURE__*/_react.default.cloneElement(brushComponent, brushProps);
}
renderBrushArea(props) {
const {
brushAreaComponent,
brushAreaStyle,
activeBrushes = {},
datum = {}
} = props;
const brushAreaWidth = props.brushAreaWidth || props.width;
const cursor = this.getCursor(props);
const rectDimensions = this.getRectDimensions(props, brushAreaWidth, getFullDomain(props));
const baseStyle = Object.assign({
cursor
}, fallbackProps.brushAreaStyle, brushAreaStyle);
const style = _victoryCore.Helpers.evaluateStyle(baseStyle, {
datum,
active: activeBrushes.brushArea
});
const brushAreaProps = Object.assign({
style
}, rectDimensions);
return /*#__PURE__*/_react.default.cloneElement(brushAreaComponent, brushAreaProps);
}
renderLine(props) {
const filteredProps = (0, _pick2.default)(props, ["x1", "x2", "y1", "y2", "datum", "scale", "active", "style"]);
return /*#__PURE__*/_react.default.cloneElement(props.lineComponent, filteredProps);
}
render() {
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));
}
}
exports.VictoryBrushLine = VictoryBrushLine;
}];
};
{
"name": "victory-brush-line",
"version": "36.9.2-next.0",
"version": "36.9.2-next.1",
"description": "Interactive Brush Line Component for Victory",

@@ -25,3 +25,3 @@ "keywords": [

"react-fast-compare": "^3.2.0",
"victory-core": "^36.9.2-next.0"
"victory-core": "^36.9.2-next.1"
},

@@ -28,0 +28,0 @@ "peerDependencies": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc