Socket
Socket
Sign inDemoInstall

victory-voronoi-container

Package Overview
Dependencies
31
Maintainers
16
Versions
148
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 36.9.1 to 36.9.2-next.0

12

CHANGELOG.md
# victory-voronoi-container
## 36.9.2-next.0
### Patch Changes
- 6e34169a5: Replace lodash isFunction with native code
- Updated dependencies [3f2da66e3]
- Updated dependencies [c13308624]
- Updated dependencies [f6f7cc515]
- Updated dependencies [6e34169a5]
- victory-core@36.9.2-next.0
- victory-tooltip@36.9.2-next.0
## 36.9.1

@@ -4,0 +16,0 @@

0

es/index.d.ts
export * from "./victory-voronoi-container";
export * from "./voronoi-helpers";
//# sourceMappingURL=index.d.ts.map

@@ -0,0 +0,0 @@ import React from "react";

444

es/victory-voronoi-container.js
import _pick from "lodash/pick";
import _isFunction from "lodash/isFunction";
import _defaults from "lodash/defaults";
var _excluded = ["childName", "eventKey", "style", "continuous"];
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; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 _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); }
/* eslint-disable react/no-multi-comp */

@@ -54,229 +9,198 @@ import React from "react";

export function voronoiContainerMixin(Base) {
var _class;
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
return _class = /*#__PURE__*/function (_Base) {
_inherits(VictoryVoronoiContainer, _Base);
var _super = _createSuper(VictoryVoronoiContainer);
function VictoryVoronoiContainer() {
_classCallCheck(this, VictoryVoronoiContainer);
return _super.apply(this, arguments);
}
_createClass(VictoryVoronoiContainer, [{
key: "getDimension",
value: function getDimension(props) {
var horizontal = props.horizontal,
voronoiDimension = props.voronoiDimension;
if (!horizontal || !voronoiDimension) {
return voronoiDimension;
return class VictoryVoronoiContainer extends Base {
static displayName = "VictoryVoronoiContainer";
static defaultProps = {
...VictoryContainer.defaultProps,
activateData: true,
activateLabels: true,
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null),
voronoiPadding: 5
};
static defaultEvents = props => {
return [{
target: "parent",
eventHandlers: {
onMouseLeave: (evt, targetProps) => {
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onTouchCancel: (evt, targetProps) => {
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onMouseMove: (evt, targetProps) => {
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps);
},
onTouchMove: (evt, targetProps) => {
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps);
}
}
return voronoiDimension === "x" ? "y" : "x";
}, {
target: "data",
eventHandlers: props.disable ? {} : {
onMouseOver: () => null,
onMouseOut: () => null,
onMouseMove: () => null
}
}];
};
getDimension(props) {
const {
horizontal,
voronoiDimension
} = props;
if (!horizontal || !voronoiDimension) {
return voronoiDimension;
}
}, {
key: "getPoint",
value: function getPoint(point) {
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"];
return _pick(point, whitelist);
}
}, {
key: "getLabelPosition",
value: function getLabelPosition(props, labelProps, points) {
var mousePosition = props.mousePosition,
mouseFollowTooltips = props.mouseFollowTooltips;
var voronoiDimension = this.getDimension(props);
var point = this.getPoint(points[0]);
var basePosition = Helpers.scalePoint(props, point);
var center = mouseFollowTooltips ? mousePosition : undefined;
if (!voronoiDimension || points.length < 2) {
return _objectSpread(_objectSpread({}, basePosition), {}, {
center: _defaults({}, labelProps.center, center)
});
}
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x;
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y;
center = mouseFollowTooltips ? mousePosition : {
x: x,
y: y
};
return voronoiDimension === "x" ? "y" : "x";
}
getPoint(point) {
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"];
return _pick(point, whitelist);
}
getLabelPosition(props, labelProps, points) {
const {
mousePosition,
mouseFollowTooltips
} = props;
const voronoiDimension = this.getDimension(props);
const point = this.getPoint(points[0]);
const basePosition = Helpers.scalePoint(props, point);
let center = mouseFollowTooltips ? mousePosition : undefined;
if (!voronoiDimension || points.length < 2) {
return {
x: x,
y: y,
...basePosition,
center: _defaults({}, labelProps.center, center)
};
}
}, {
key: "getStyle",
value: function getStyle(props, points, type) {
var labels = props.labels,
labelComponent = props.labelComponent,
theme = props.theme;
var componentProps = labelComponent.props || {};
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {};
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style;
return points.reduce(function (memo, datum, index) {
var labelProps = _defaults({}, componentProps, {
datum: datum,
active: true
});
var text = _isFunction(labels) ? labels(labelProps) : undefined;
var textArray = text !== undefined ? "".concat(text).split("\n") : [];
var baseStyle = datum.style && datum.style[type] || {};
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray;
var style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps);
var styleArray = textArray.length ? textArray.map(function () {
return style;
}) : [style];
return memo.concat(styleArray);
}, []);
}
}, {
key: "getDefaultLabelProps",
value: function getDefaultLabelProps(props, points) {
var voronoiDimension = props.voronoiDimension,
horizontal = props.horizontal,
mouseFollowTooltips = props.mouseFollowTooltips;
var point = this.getPoint(points[0]);
var multiPoint = voronoiDimension && points.length > 1;
var y = point._y1 !== undefined ? point._y1 : point._y;
var defaultHorizontalOrientation = y < 0 ? "left" : "right";
var defaultOrientation = y < 0 ? "bottom" : "top";
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation;
var orientation = mouseFollowTooltips ? undefined : labelOrientation;
return {
orientation: orientation,
pointerLength: multiPoint ? 0 : undefined,
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined
};
}
}, {
key: "getLabelProps",
value: function getLabelProps(props, points) {
var labels = props.labels,
scale = props.scale,
labelComponent = props.labelComponent,
theme = props.theme,
width = props.width,
height = props.height;
var componentProps = labelComponent.props || {};
var text = points.reduce(function (memo, datum) {
var labelProps = _defaults({}, componentProps, {
datum: datum,
active: true
});
var t = _isFunction(labels) ? labels(labelProps) : null;
if (t === null || t === undefined) {
return memo;
}
return memo.concat("".concat(t).split("\n"));
}, []); // remove properties from first point to make datum
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var _points$ = points[0],
childName = _points$.childName,
eventKey = _points$.eventKey,
style = _points$.style,
continuous = _points$.continuous,
datum = _objectWithoutProperties(_points$, _excluded);
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName);
var labelProps = _defaults({
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"),
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"),
active: true,
renderInPortal: false,
activePoints: points,
datum: datum,
scale: scale,
theme: theme
}, componentProps, {
text: text,
width: width,
height: height,
style: this.getStyle(props, points, "labels"),
flyoutStyle: this.getStyle(props, points, "flyout")[0]
}, this.getDefaultLabelProps(props, points));
var labelPosition = this.getLabelPosition(props, labelProps, points);
return _defaults({}, labelPosition, labelProps);
}
}, {
key: "getTooltip",
value: function getTooltip(props) {
var labels = props.labels,
activePoints = props.activePoints,
labelComponent = props.labelComponent;
if (!labels) {
return null;
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x;
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y;
center = mouseFollowTooltips ? mousePosition : {
x,
y
};
return {
x,
y,
center: _defaults({}, labelProps.center, center)
};
}
getStyle(props, points, type) {
const {
labels,
labelComponent,
theme
} = props;
const componentProps = labelComponent.props || {};
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {};
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style;
return points.reduce((memo, datum, index) => {
const labelProps = _defaults({}, componentProps, {
datum,
active: true
});
const text = Helpers.isFunction(labels) ? labels(labelProps) : undefined;
const textArray = text !== undefined ? `${text}`.split("\n") : [];
const baseStyle = datum.style && datum.style[type] || {};
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray;
const style = Helpers.evaluateStyle(_defaults({}, componentStyle, baseStyle, themeStyles[type]), labelProps);
const styleArray = textArray.length ? textArray.map(() => style) : [style];
return memo.concat(styleArray);
}, []);
}
getDefaultLabelProps(props, points) {
const {
voronoiDimension,
horizontal,
mouseFollowTooltips
} = props;
const point = this.getPoint(points[0]);
const multiPoint = voronoiDimension && points.length > 1;
const y = point._y1 !== undefined ? point._y1 : point._y;
const defaultHorizontalOrientation = y < 0 ? "left" : "right";
const defaultOrientation = y < 0 ? "bottom" : "top";
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation;
const orientation = mouseFollowTooltips ? undefined : labelOrientation;
return {
orientation,
pointerLength: multiPoint ? 0 : undefined,
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined
};
}
getLabelProps(props, points) {
const {
labels,
scale,
labelComponent,
theme,
width,
height
} = props;
const componentProps = labelComponent.props || {};
const text = points.reduce((memo, datum) => {
const labelProps = _defaults({}, componentProps, {
datum,
active: true
});
const t = Helpers.isFunction(labels) ? labels(labelProps) : null;
if (t === null || t === undefined) {
return memo;
}
return memo.concat(`${t}`.split("\n"));
}, []);
if (Array.isArray(activePoints) && activePoints.length) {
var labelProps = this.getLabelProps(props, activePoints);
var text = labelProps.text;
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text;
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null;
}
// remove properties from first point to make datum
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {
childName,
eventKey,
style,
continuous,
...datum
} = points[0];
const name = props.name === childName ? childName : `${props.name}-${childName}`;
const labelProps = _defaults({
key: `${name}-${eventKey}-voronoi-tooltip`,
id: `${name}-${eventKey}-voronoi-tooltip`,
active: true,
renderInPortal: false,
activePoints: points,
datum,
scale,
theme
}, componentProps, {
text,
width,
height,
style: this.getStyle(props, points, "labels"),
flyoutStyle: this.getStyle(props, points, "flyout")[0]
}, this.getDefaultLabelProps(props, points));
const labelPosition = this.getLabelPosition(props, labelProps, points);
return _defaults({}, labelPosition, labelProps);
}
getTooltip(props) {
const {
labels,
activePoints,
labelComponent
} = props;
if (!labels) {
return null;
} // Overrides method in VictoryContainer
}, {
key: "getChildren",
value: function getChildren(props) {
return [].concat(_toConsumableArray(React.Children.toArray(props.children)), [this.getTooltip(props)]);
}
}]);
if (Array.isArray(activePoints) && activePoints.length) {
const labelProps = this.getLabelProps(props, activePoints);
const {
text
} = labelProps;
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text;
return showLabel ? /*#__PURE__*/React.cloneElement(labelComponent, labelProps) : null;
}
return null;
}
return VictoryVoronoiContainer;
}(Base), _class.displayName = "VictoryVoronoiContainer", _class.defaultProps = _objectSpread(_objectSpread({}, VictoryContainer.defaultProps), {}, {
activateData: true,
activateLabels: true,
labelComponent: /*#__PURE__*/React.createElement(VictoryTooltip, null),
voronoiPadding: 5
}), _class.defaultEvents = function (props) {
return [{
target: "parent",
eventHandlers: {
onMouseLeave: function (evt, targetProps) {
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onTouchCancel: function (evt, targetProps) {
return props.disable ? {} : VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onMouseMove: function (evt, targetProps) {
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps);
},
onTouchMove: function (evt, targetProps) {
return props.disable ? {} : VoronoiHelpers.onMouseMove(evt, targetProps);
}
}
}, {
target: "data",
eventHandlers: props.disable ? {} : {
onMouseOver: function () {
return null;
},
onMouseOut: function () {
return null;
},
onMouseMove: function () {
return null;
}
}
}];
}, _class;
// Overrides method in VictoryContainer
getChildren(props) {
return [...React.Children.toArray(props.children), this.getTooltip(props)];
}
};
}
export var VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer);
export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer);

@@ -0,0 +0,0 @@ /// <reference types="lodash" />

@@ -6,22 +6,2 @@ import _throttle from "lodash/throttle";

import _isEmpty from "lodash/isEmpty";
import _isFunction from "lodash/isFunction";
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; }
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; }
import { Collection, Selection, Data, Helpers } from "victory-core";

@@ -31,298 +11,229 @@ import isEqual from "react-fast-compare";

import React from "react";
var ON_MOUSE_MOVE_THROTTLE_MS = 32;
var VoronoiHelpersClass = /*#__PURE__*/function () {
function VoronoiHelpersClass() {
var _this = this;
_classCallCheck(this, VoronoiHelpersClass);
this.onMouseLeave = function (evt, targetProps) {
var _this$getParentMutati;
var activePoints = targetProps.activePoints || [];
_this.onDeactivated(targetProps, activePoints);
var inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return (_this$getParentMutati = _this.getParentMutation([])).concat.apply(_this$getParentMutati, _toConsumableArray(inactiveMutations));
const ON_MOUSE_MOVE_THROTTLE_MS = 32;
class VoronoiHelpersClass {
withinBounds(props, point) {
const {
width,
height,
polar,
origin,
scale
} = props;
const padding = Helpers.getPadding(props, "voronoiPadding");
const {
x,
y
} = point;
if (polar) {
const distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
const radius = Math.max(...scale.y.range());
return distanceSquared < Math.pow(radius, 2);
}
return x >= padding.left && x <= width - padding.right && y >= padding.top && y <= height - padding.bottom;
}
getDatasets(props) {
const minDomain = {
x: Collection.getMinValue(props.domain.x),
y: Collection.getMinValue(props.domain.y)
};
this.handleMouseMove = function (evt, targetProps) {
// eslint-disable-line max-statements
var activePoints = targetProps.activePoints || [];
var parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
var mousePosition = Selection.getSVGEventCoordinates(evt, parentSVG);
if (!_this.withinBounds(targetProps, mousePosition)) {
var _this$getParentMutati2;
_this.onDeactivated(targetProps, activePoints);
var _inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return (_this$getParentMutati2 = _this.getParentMutation([], mousePosition, parentSVG)).concat.apply(_this$getParentMutati2, _toConsumableArray(_inactiveMutations));
const children = React.Children.toArray(props.children);
const addMeta = (data, name, child) => {
const continuous = child && child.type && child.type.continuous;
const style = child ? child.props && child.props.style : props.style;
return data.map((datum, index) => {
const {
x,
y,
y0,
x0
} = Helpers.getPoint(datum);
const voronoiX = (Number(x) + Number(x0)) / 2;
const voronoiY = (Number(y) + Number(y0)) / 2;
return Object.assign({
_voronoiX: props.voronoiDimension === "y" ? minDomain.x : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? minDomain.y : voronoiY,
eventKey: index,
childName: name,
continuous,
style
}, datum);
});
};
if (props.data) {
return addMeta(props.data);
}
const getData = childProps => {
const data = Data.getData(childProps);
return Array.isArray(data) && data.length > 0 ? data : undefined;
};
const iteratee = (child, childName) => {
const childProps = child.props || {};
const name = childProps.name || childName;
const blacklist = props.voronoiBlacklist || [];
const blacklistStr = blacklist.filter(_isString);
const blacklistRegExp = blacklist.filter(_isRegExp);
const isRegExpMatch = blacklistRegExp.some(regExp => regExp.test(name));
if (!Data.isDataComponent(child) || _includes(blacklistStr, name) || isRegExpMatch) {
return null;
}
var _this$getVoronoiPoint = _this.getVoronoiPoints(targetProps, mousePosition),
_this$getVoronoiPoint2 = _this$getVoronoiPoint.points,
points = _this$getVoronoiPoint2 === void 0 ? [] : _this$getVoronoiPoint2,
index = _this$getVoronoiPoint.index;
var parentMutations = _this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && isEqual(points, activePoints)) {
return parentMutations;
}
_this.onActivated(targetProps, points);
_this.onDeactivated(targetProps, activePoints);
var activeMutations = points.length ? points.map(function (point) {
return _this.getActiveMutations(targetProps, point);
}) : [];
var inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return parentMutations.concat.apply(parentMutations, _toConsumableArray(inactiveMutations).concat(_toConsumableArray(activeMutations)));
const getChildData = child.type && Helpers.isFunction(child.type.getData) ? child.type.getData : getData;
const childData = getChildData(child.props);
return childData ? addMeta(childData, name, child) : null;
};
this.onMouseMove = _throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false
return Helpers.reduceChildren(children, iteratee, props);
}
findPoints(datasets, point) {
return datasets.filter(d => {
return point._voronoiX === d._voronoiX && point._voronoiY === d._voronoiY;
});
}
_createClass(VoronoiHelpersClass, [{
key: "withinBounds",
value: function withinBounds(props, point) {
var width = props.width,
height = props.height,
polar = props.polar,
origin = props.origin,
scale = props.scale;
var padding = Helpers.getPadding(props, "voronoiPadding");
var x = point.x,
y = point.y;
if (polar) {
var distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
var radius = Math.max.apply(Math, _toConsumableArray(scale.y.range()));
return distanceSquared < Math.pow(radius, 2);
}
return x >= padding.left && x <= width - padding.right && y >= padding.top && y <= height - padding.bottom;
withinRadius(point, mousePosition, radius) {
if (!point) {
return false;
}
}, {
key: "getDatasets",
value: function getDatasets(props) {
var minDomain = {
x: Collection.getMinValue(props.domain.x),
y: Collection.getMinValue(props.domain.y)
};
var children = React.Children.toArray(props.children);
var addMeta = function (data, name, child) {
var continuous = child && child.type && child.type.continuous;
var style = child ? child.props && child.props.style : props.style;
return data.map(function (datum, index) {
var _Helpers$getPoint = Helpers.getPoint(datum),
x = _Helpers$getPoint.x,
y = _Helpers$getPoint.y,
y0 = _Helpers$getPoint.y0,
x0 = _Helpers$getPoint.x0;
var voronoiX = (Number(x) + Number(x0)) / 2;
var voronoiY = (Number(y) + Number(y0)) / 2;
return Object.assign({
_voronoiX: props.voronoiDimension === "y" ? minDomain.x : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? minDomain.y : voronoiY,
eventKey: index,
childName: name,
continuous: continuous,
style: style
}, datum);
});
};
if (props.data) {
return addMeta(props.data);
}
var getData = function (childProps) {
var data = Data.getData(childProps);
return Array.isArray(data) && data.length > 0 ? data : undefined;
};
var iteratee = function (child, childName) {
var childProps = child.props || {};
var name = childProps.name || childName;
var blacklist = props.voronoiBlacklist || [];
var blacklistStr = blacklist.filter(_isString);
var blacklistRegExp = blacklist.filter(_isRegExp);
var isRegExpMatch = blacklistRegExp.some(function (regExp) {
return regExp.test(name);
});
if (!Data.isDataComponent(child) || _includes(blacklistStr, name) || isRegExpMatch) {
return null;
}
var getChildData = child.type && _isFunction(child.type.getData) ? child.type.getData : getData;
var childData = getChildData(child.props);
return childData ? addMeta(childData, name, child) : null;
};
return Helpers.reduceChildren(children, iteratee, props);
if (!radius) {
return true;
}
}, {
key: "findPoints",
value: function findPoints(datasets, point) {
return datasets.filter(function (d) {
return point._voronoiX === d._voronoiX && point._voronoiY === d._voronoiY;
});
const {
x,
y
} = mousePosition;
const distanceSquared = Math.pow(x - point[0], 2) + Math.pow(y - point[1], 2);
return distanceSquared < Math.pow(radius, 2);
}
getVoronoiPoints(props, mousePosition) {
const datasets = this.getDatasets(props);
const scaledData = datasets.map(d => {
const {
x,
y
} = Helpers.scalePoint(props, d);
return [x, y];
});
const delaunay = Delaunay.from(scaledData);
const index = delaunay.find(mousePosition.x, mousePosition.y);
const withinRadius = this.withinRadius(scaledData[index], mousePosition, props.radius);
const points = withinRadius ? this.findPoints(datasets, datasets[index]) : [];
return {
points,
index
};
}
getActiveMutations(props, point) {
const {
childName,
continuous
} = point;
const {
activateData,
activateLabels,
labels
} = props;
if (!activateData && !activateLabels) {
return [];
}
}, {
key: "withinRadius",
value: function withinRadius(point, mousePosition, radius) {
if (!point) {
return false;
}
if (!radius) {
return true;
}
var x = mousePosition.x,
y = mousePosition.y;
var distanceSquared = Math.pow(x - point[0], 2) + Math.pow(y - point[1], 2);
return distanceSquared < Math.pow(radius, 2);
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (_isEmpty(targets)) {
return [];
}
}, {
key: "getVoronoiPoints",
value: function getVoronoiPoints(props, mousePosition) {
var datasets = this.getDatasets(props);
var scaledData = datasets.map(function (d) {
var _Helpers$scalePoint = Helpers.scalePoint(props, d),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
return [x, y];
});
var delaunay = Delaunay.from(scaledData);
var index = delaunay.find(mousePosition.x, mousePosition.y);
var withinRadius = this.withinRadius(scaledData[index], mousePosition, props.radius);
var points = withinRadius ? this.findPoints(datasets, datasets[index]) : [];
return targets.map(target => {
const eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
return {
points: points,
index: index
childName,
eventKey,
target,
mutation: () => ({
active: true
})
};
});
}
getInactiveMutations(props, point) {
const {
childName,
continuous
} = point;
const {
activateData,
activateLabels,
labels
} = props;
if (!activateData && !activateLabels) {
return [];
}
}, {
key: "getActiveMutations",
value: function getActiveMutations(props, point) {
var childName = point.childName,
continuous = point.continuous;
var activateData = props.activateData,
activateLabels = props.activateLabels,
labels = props.labels;
if (!activateData && !activateLabels) {
return [];
}
var defaultTarget = activateData ? ["data"] : [];
var targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (_isEmpty(targets)) {
return [];
}
return targets.map(function (target) {
var eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
return {
childName: childName,
eventKey: eventKey,
target: target,
mutation: function () {
return {
active: true
};
}
};
});
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (_isEmpty(targets)) {
return [];
}
}, {
key: "getInactiveMutations",
value: function getInactiveMutations(props, point) {
var childName = point.childName,
continuous = point.continuous;
var activateData = props.activateData,
activateLabels = props.activateLabels,
labels = props.labels;
return targets.map(target => {
const eventKey = continuous && target === "data" ? "all" : point.eventKey;
return {
childName,
eventKey,
target,
mutation: () => null
};
});
}
if (!activateData && !activateLabels) {
return [];
}
var defaultTarget = activateData ? ["data"] : [];
var targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if (_isEmpty(targets)) {
return [];
}
return targets.map(function (target) {
var eventKey = continuous && target === "data" ? "all" : point.eventKey;
return {
childName: childName,
eventKey: eventKey,
target: target,
mutation: function () {
return null;
}
};
});
} // eslint-disable-next-line max-params
}, {
key: "getParentMutation",
value: function getParentMutation(activePoints, mousePosition, parentSVG, vIndex) {
return [{
target: "parent",
eventKey: "parent",
mutation: function () {
return {
activePoints: activePoints,
mousePosition: mousePosition,
parentSVG: parentSVG,
vIndex: vIndex
};
}
}];
// eslint-disable-next-line max-params
getParentMutation(activePoints, mousePosition, parentSVG, vIndex) {
return [{
target: "parent",
eventKey: "parent",
mutation: () => ({
activePoints,
mousePosition,
parentSVG,
vIndex
})
}];
}
onActivated(props, points) {
if (Helpers.isFunction(props.onActivated)) {
props.onActivated(points, props);
}
}, {
key: "onActivated",
value: function onActivated(props, points) {
if (_isFunction(props.onActivated)) {
props.onActivated(points, props);
}
}
onDeactivated(props, points) {
if (Helpers.isFunction(props.onDeactivated)) {
props.onDeactivated(points, props);
}
}, {
key: "onDeactivated",
value: function onDeactivated(props, points) {
if (_isFunction(props.onDeactivated)) {
props.onDeactivated(points, props);
}
}
onMouseLeave = (evt, targetProps) => {
const activePoints = targetProps.activePoints || [];
this.onDeactivated(targetProps, activePoints);
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return this.getParentMutation([]).concat(...inactiveMutations);
};
handleMouseMove = (evt, targetProps) => {
// eslint-disable-line max-statements
const activePoints = targetProps.activePoints || [];
const parentSVG = targetProps.parentSVG || Selection.getParentSVG(evt);
const mousePosition = Selection.getSVGEventCoordinates(evt, parentSVG);
if (!this.withinBounds(targetProps, mousePosition)) {
this.onDeactivated(targetProps, activePoints);
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return this.getParentMutation([], mousePosition, parentSVG).concat(...inactiveMutations);
}
}]);
return VoronoiHelpersClass;
}();
export var VoronoiHelpers = new VoronoiHelpersClass();
const {
points = [],
index
} = this.getVoronoiPoints(targetProps, mousePosition);
const parentMutations = this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && isEqual(points, activePoints)) {
return parentMutations;
}
this.onActivated(targetProps, points);
this.onDeactivated(targetProps, activePoints);
const activeMutations = points.length ? points.map(point => this.getActiveMutations(targetProps, point)) : [];
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return parentMutations.concat(...inactiveMutations, ...activeMutations);
};
onMouseMove = _throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false
});
}
export const VoronoiHelpers = new VoronoiHelpersClass();
export * from "./victory-voronoi-container";
export * from "./voronoi-helpers";
//# sourceMappingURL=index.d.ts.map

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

});
var _victoryVoronoiContainer = require("./victory-voronoi-container");
Object.keys(_victoryVoronoiContainer).forEach(function (key) {

@@ -20,5 +18,3 @@ if (key === "default" || key === "__esModule") return;

});
var _voronoiHelpers = require("./voronoi-helpers");
Object.keys(_voronoiHelpers).forEach(function (key) {

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

@@ -0,0 +0,0 @@ import React from "react";

@@ -8,293 +8,208 @@ "use strict";

exports.voronoiContainerMixin = voronoiContainerMixin;
var _pick2 = _interopRequireDefault(require("lodash/pick"));
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
var _react = _interopRequireDefault(require("react"));
var _victoryTooltip = require("victory-tooltip");
var _victoryCore = require("victory-core");
var _voronoiHelpers = require("./voronoi-helpers");
var _excluded = ["childName", "eventKey", "style", "continuous"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable react/no-multi-comp */
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; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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 _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 voronoiContainerMixin(Base) {
var _class;
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
return _class = /*#__PURE__*/function (_Base) {
_inherits(VictoryVoronoiContainer, _Base);
var _super = _createSuper(VictoryVoronoiContainer);
function VictoryVoronoiContainer() {
_classCallCheck(this, VictoryVoronoiContainer);
return _super.apply(this, arguments);
}
_createClass(VictoryVoronoiContainer, [{
key: "getDimension",
value: function getDimension(props) {
var horizontal = props.horizontal,
voronoiDimension = props.voronoiDimension;
if (!horizontal || !voronoiDimension) {
return voronoiDimension;
return class VictoryVoronoiContainer extends Base {
static displayName = "VictoryVoronoiContainer";
static defaultProps = {
..._victoryCore.VictoryContainer.defaultProps,
activateData: true,
activateLabels: true,
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null),
voronoiPadding: 5
};
static defaultEvents = props => {
return [{
target: "parent",
eventHandlers: {
onMouseLeave: (evt, targetProps) => {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onTouchCancel: (evt, targetProps) => {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onMouseMove: (evt, targetProps) => {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps);
},
onTouchMove: (evt, targetProps) => {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps);
}
}
return voronoiDimension === "x" ? "y" : "x";
}, {
target: "data",
eventHandlers: props.disable ? {} : {
onMouseOver: () => null,
onMouseOut: () => null,
onMouseMove: () => null
}
}];
};
getDimension(props) {
const {
horizontal,
voronoiDimension
} = props;
if (!horizontal || !voronoiDimension) {
return voronoiDimension;
}
}, {
key: "getPoint",
value: function getPoint(point) {
var whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"];
return (0, _pick2.default)(point, whitelist);
}
}, {
key: "getLabelPosition",
value: function getLabelPosition(props, labelProps, points) {
var mousePosition = props.mousePosition,
mouseFollowTooltips = props.mouseFollowTooltips;
var voronoiDimension = this.getDimension(props);
var point = this.getPoint(points[0]);
var basePosition = _victoryCore.Helpers.scalePoint(props, point);
var center = mouseFollowTooltips ? mousePosition : undefined;
if (!voronoiDimension || points.length < 2) {
return _objectSpread(_objectSpread({}, basePosition), {}, {
center: (0, _defaults2.default)({}, labelProps.center, center)
});
}
var x = voronoiDimension === "y" ? mousePosition.x : basePosition.x;
var y = voronoiDimension === "x" ? mousePosition.y : basePosition.y;
center = mouseFollowTooltips ? mousePosition : {
x: x,
y: y
};
return voronoiDimension === "x" ? "y" : "x";
}
getPoint(point) {
const whitelist = ["_x", "_x1", "_x0", "_y", "_y1", "_y0"];
return (0, _pick2.default)(point, whitelist);
}
getLabelPosition(props, labelProps, points) {
const {
mousePosition,
mouseFollowTooltips
} = props;
const voronoiDimension = this.getDimension(props);
const point = this.getPoint(points[0]);
const basePosition = _victoryCore.Helpers.scalePoint(props, point);
let center = mouseFollowTooltips ? mousePosition : undefined;
if (!voronoiDimension || points.length < 2) {
return {
x: x,
y: y,
...basePosition,
center: (0, _defaults2.default)({}, labelProps.center, center)
};
}
}, {
key: "getStyle",
value: function getStyle(props, points, type) {
var labels = props.labels,
labelComponent = props.labelComponent,
theme = props.theme;
var componentProps = labelComponent.props || {};
var themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {};
var componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style;
return points.reduce(function (memo, datum, index) {
var labelProps = (0, _defaults2.default)({}, componentProps, {
datum: datum,
active: true
});
var text = (0, _isFunction2.default)(labels) ? labels(labelProps) : undefined;
var textArray = text !== undefined ? "".concat(text).split("\n") : [];
var baseStyle = datum.style && datum.style[type] || {};
var componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray;
var style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps);
var styleArray = textArray.length ? textArray.map(function () {
return style;
}) : [style];
return memo.concat(styleArray);
}, []);
}
}, {
key: "getDefaultLabelProps",
value: function getDefaultLabelProps(props, points) {
var voronoiDimension = props.voronoiDimension,
horizontal = props.horizontal,
mouseFollowTooltips = props.mouseFollowTooltips;
var point = this.getPoint(points[0]);
var multiPoint = voronoiDimension && points.length > 1;
var y = point._y1 !== undefined ? point._y1 : point._y;
var defaultHorizontalOrientation = y < 0 ? "left" : "right";
var defaultOrientation = y < 0 ? "bottom" : "top";
var labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation;
var orientation = mouseFollowTooltips ? undefined : labelOrientation;
return {
orientation: orientation,
pointerLength: multiPoint ? 0 : undefined,
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined
};
}
}, {
key: "getLabelProps",
value: function getLabelProps(props, points) {
var labels = props.labels,
scale = props.scale,
labelComponent = props.labelComponent,
theme = props.theme,
width = props.width,
height = props.height;
var componentProps = labelComponent.props || {};
var text = points.reduce(function (memo, datum) {
var labelProps = (0, _defaults2.default)({}, componentProps, {
datum: datum,
active: true
});
var t = (0, _isFunction2.default)(labels) ? labels(labelProps) : null;
if (t === null || t === undefined) {
return memo;
}
return memo.concat("".concat(t).split("\n"));
}, []); // remove properties from first point to make datum
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var _points$ = points[0],
childName = _points$.childName,
eventKey = _points$.eventKey,
style = _points$.style,
continuous = _points$.continuous,
datum = _objectWithoutProperties(_points$, _excluded);
var name = props.name === childName ? childName : "".concat(props.name, "-").concat(childName);
var labelProps = (0, _defaults2.default)({
key: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"),
id: "".concat(name, "-").concat(eventKey, "-voronoi-tooltip"),
active: true,
renderInPortal: false,
activePoints: points,
datum: datum,
scale: scale,
theme: theme
}, componentProps, {
text: text,
width: width,
height: height,
style: this.getStyle(props, points, "labels"),
flyoutStyle: this.getStyle(props, points, "flyout")[0]
}, this.getDefaultLabelProps(props, points));
var labelPosition = this.getLabelPosition(props, labelProps, points);
return (0, _defaults2.default)({}, labelPosition, labelProps);
}
}, {
key: "getTooltip",
value: function getTooltip(props) {
var labels = props.labels,
activePoints = props.activePoints,
labelComponent = props.labelComponent;
if (!labels) {
return null;
const x = voronoiDimension === "y" ? mousePosition.x : basePosition.x;
const y = voronoiDimension === "x" ? mousePosition.y : basePosition.y;
center = mouseFollowTooltips ? mousePosition : {
x,
y
};
return {
x,
y,
center: (0, _defaults2.default)({}, labelProps.center, center)
};
}
getStyle(props, points, type) {
const {
labels,
labelComponent,
theme
} = props;
const componentProps = labelComponent.props || {};
const themeStyles = theme && theme.voronoi && theme.voronoi.style ? theme.voronoi.style : {};
const componentStyleArray = type === "flyout" ? componentProps.flyoutStyle : componentProps.style;
return points.reduce((memo, datum, index) => {
const labelProps = (0, _defaults2.default)({}, componentProps, {
datum,
active: true
});
const text = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : undefined;
const textArray = text !== undefined ? `${text}`.split("\n") : [];
const baseStyle = datum.style && datum.style[type] || {};
const componentStyle = Array.isArray(componentStyleArray) ? componentStyleArray[index] : componentStyleArray;
const style = _victoryCore.Helpers.evaluateStyle((0, _defaults2.default)({}, componentStyle, baseStyle, themeStyles[type]), labelProps);
const styleArray = textArray.length ? textArray.map(() => style) : [style];
return memo.concat(styleArray);
}, []);
}
getDefaultLabelProps(props, points) {
const {
voronoiDimension,
horizontal,
mouseFollowTooltips
} = props;
const point = this.getPoint(points[0]);
const multiPoint = voronoiDimension && points.length > 1;
const y = point._y1 !== undefined ? point._y1 : point._y;
const defaultHorizontalOrientation = y < 0 ? "left" : "right";
const defaultOrientation = y < 0 ? "bottom" : "top";
const labelOrientation = horizontal ? defaultHorizontalOrientation : defaultOrientation;
const orientation = mouseFollowTooltips ? undefined : labelOrientation;
return {
orientation,
pointerLength: multiPoint ? 0 : undefined,
constrainToVisibleArea: multiPoint || mouseFollowTooltips ? true : undefined
};
}
getLabelProps(props, points) {
const {
labels,
scale,
labelComponent,
theme,
width,
height
} = props;
const componentProps = labelComponent.props || {};
const text = points.reduce((memo, datum) => {
const labelProps = (0, _defaults2.default)({}, componentProps, {
datum,
active: true
});
const t = _victoryCore.Helpers.isFunction(labels) ? labels(labelProps) : null;
if (t === null || t === undefined) {
return memo;
}
return memo.concat(`${t}`.split("\n"));
}, []);
if (Array.isArray(activePoints) && activePoints.length) {
var labelProps = this.getLabelProps(props, activePoints);
var text = labelProps.text;
var showLabel = Array.isArray(text) ? text.filter(Boolean).length : text;
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null;
}
// remove properties from first point to make datum
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {
childName,
eventKey,
style,
continuous,
...datum
} = points[0];
const name = props.name === childName ? childName : `${props.name}-${childName}`;
const labelProps = (0, _defaults2.default)({
key: `${name}-${eventKey}-voronoi-tooltip`,
id: `${name}-${eventKey}-voronoi-tooltip`,
active: true,
renderInPortal: false,
activePoints: points,
datum,
scale,
theme
}, componentProps, {
text,
width,
height,
style: this.getStyle(props, points, "labels"),
flyoutStyle: this.getStyle(props, points, "flyout")[0]
}, this.getDefaultLabelProps(props, points));
const labelPosition = this.getLabelPosition(props, labelProps, points);
return (0, _defaults2.default)({}, labelPosition, labelProps);
}
getTooltip(props) {
const {
labels,
activePoints,
labelComponent
} = props;
if (!labels) {
return null;
} // Overrides method in VictoryContainer
}, {
key: "getChildren",
value: function getChildren(props) {
return [].concat(_toConsumableArray(_react.default.Children.toArray(props.children)), [this.getTooltip(props)]);
}
}]);
if (Array.isArray(activePoints) && activePoints.length) {
const labelProps = this.getLabelProps(props, activePoints);
const {
text
} = labelProps;
const showLabel = Array.isArray(text) ? text.filter(Boolean).length : text;
return showLabel ? /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps) : null;
}
return null;
}
return VictoryVoronoiContainer;
}(Base), _class.displayName = "VictoryVoronoiContainer", _class.defaultProps = _objectSpread(_objectSpread({}, _victoryCore.VictoryContainer.defaultProps), {}, {
activateData: true,
activateLabels: true,
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryTooltip.VictoryTooltip, null),
voronoiPadding: 5
}), _class.defaultEvents = function (props) {
return [{
target: "parent",
eventHandlers: {
onMouseLeave: function (evt, targetProps) {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onTouchCancel: function (evt, targetProps) {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseLeave(evt, targetProps);
},
onMouseMove: function (evt, targetProps) {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps);
},
onTouchMove: function (evt, targetProps) {
return props.disable ? {} : _voronoiHelpers.VoronoiHelpers.onMouseMove(evt, targetProps);
}
}
}, {
target: "data",
eventHandlers: props.disable ? {} : {
onMouseOver: function () {
return null;
},
onMouseOut: function () {
return null;
},
onMouseMove: function () {
return null;
}
}
}];
}, _class;
// Overrides method in VictoryContainer
getChildren(props) {
return [..._react.default.Children.toArray(props.children), this.getTooltip(props)];
}
};
}
var VictoryVoronoiContainer = voronoiContainerMixin(_victoryCore.VictoryContainer);
exports.VictoryVoronoiContainer = VictoryVoronoiContainer;
const VictoryVoronoiContainer = exports.VictoryVoronoiContainer = voronoiContainerMixin(_victoryCore.VictoryContainer);

@@ -0,0 +0,0 @@ /// <reference types="lodash" />

@@ -7,348 +7,239 @@ "use strict";

exports.VoronoiHelpers = void 0;
var _throttle2 = _interopRequireDefault(require("lodash/throttle"));
var _isRegExp2 = _interopRequireDefault(require("lodash/isRegExp"));
var _isString2 = _interopRequireDefault(require("lodash/isString"));
var _includes2 = _interopRequireDefault(require("lodash/includes"));
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
var _isFunction2 = _interopRequireDefault(require("lodash/isFunction"));
var _victoryCore = require("victory-core");
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
var _index = _interopRequireDefault(require("delaunay-find/lib/index.js"));
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
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; }
var ON_MOUSE_MOVE_THROTTLE_MS = 32;
var VoronoiHelpersClass = /*#__PURE__*/function () {
function VoronoiHelpersClass() {
var _this = this;
_classCallCheck(this, VoronoiHelpersClass);
this.onMouseLeave = function (evt, targetProps) {
var _this$getParentMutati;
var activePoints = targetProps.activePoints || [];
_this.onDeactivated(targetProps, activePoints);
var inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return (_this$getParentMutati = _this.getParentMutation([])).concat.apply(_this$getParentMutati, _toConsumableArray(inactiveMutations));
const ON_MOUSE_MOVE_THROTTLE_MS = 32;
class VoronoiHelpersClass {
withinBounds(props, point) {
const {
width,
height,
polar,
origin,
scale
} = props;
const padding = _victoryCore.Helpers.getPadding(props, "voronoiPadding");
const {
x,
y
} = point;
if (polar) {
const distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
const radius = Math.max(...scale.y.range());
return distanceSquared < Math.pow(radius, 2);
}
return x >= padding.left && x <= width - padding.right && y >= padding.top && y <= height - padding.bottom;
}
getDatasets(props) {
const minDomain = {
x: _victoryCore.Collection.getMinValue(props.domain.x),
y: _victoryCore.Collection.getMinValue(props.domain.y)
};
this.handleMouseMove = function (evt, targetProps) {
// eslint-disable-line max-statements
var activePoints = targetProps.activePoints || [];
var parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
var mousePosition = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG);
if (!_this.withinBounds(targetProps, mousePosition)) {
var _this$getParentMutati2;
_this.onDeactivated(targetProps, activePoints);
var _inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return (_this$getParentMutati2 = _this.getParentMutation([], mousePosition, parentSVG)).concat.apply(_this$getParentMutati2, _toConsumableArray(_inactiveMutations));
const children = _react.default.Children.toArray(props.children);
const addMeta = (data, name, child) => {
const continuous = child && child.type && child.type.continuous;
const style = child ? child.props && child.props.style : props.style;
return data.map((datum, index) => {
const {
x,
y,
y0,
x0
} = _victoryCore.Helpers.getPoint(datum);
const voronoiX = (Number(x) + Number(x0)) / 2;
const voronoiY = (Number(y) + Number(y0)) / 2;
return Object.assign({
_voronoiX: props.voronoiDimension === "y" ? minDomain.x : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? minDomain.y : voronoiY,
eventKey: index,
childName: name,
continuous,
style
}, datum);
});
};
if (props.data) {
return addMeta(props.data);
}
const getData = childProps => {
const data = _victoryCore.Data.getData(childProps);
return Array.isArray(data) && data.length > 0 ? data : undefined;
};
const iteratee = (child, childName) => {
const childProps = child.props || {};
const name = childProps.name || childName;
const blacklist = props.voronoiBlacklist || [];
const blacklistStr = blacklist.filter(_isString2.default);
const blacklistRegExp = blacklist.filter(_isRegExp2.default);
const isRegExpMatch = blacklistRegExp.some(regExp => regExp.test(name));
if (!_victoryCore.Data.isDataComponent(child) || (0, _includes2.default)(blacklistStr, name) || isRegExpMatch) {
return null;
}
var _this$getVoronoiPoint = _this.getVoronoiPoints(targetProps, mousePosition),
_this$getVoronoiPoint2 = _this$getVoronoiPoint.points,
points = _this$getVoronoiPoint2 === void 0 ? [] : _this$getVoronoiPoint2,
index = _this$getVoronoiPoint.index;
var parentMutations = _this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && (0, _reactFastCompare.default)(points, activePoints)) {
return parentMutations;
}
_this.onActivated(targetProps, points);
_this.onDeactivated(targetProps, activePoints);
var activeMutations = points.length ? points.map(function (point) {
return _this.getActiveMutations(targetProps, point);
}) : [];
var inactiveMutations = activePoints.length ? activePoints.map(function (point) {
return _this.getInactiveMutations(targetProps, point);
}) : [];
return parentMutations.concat.apply(parentMutations, _toConsumableArray(inactiveMutations).concat(_toConsumableArray(activeMutations)));
const getChildData = child.type && _victoryCore.Helpers.isFunction(child.type.getData) ? child.type.getData : getData;
const childData = getChildData(child.props);
return childData ? addMeta(childData, name, child) : null;
};
this.onMouseMove = (0, _throttle2.default)(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false
return _victoryCore.Helpers.reduceChildren(children, iteratee, props);
}
findPoints(datasets, point) {
return datasets.filter(d => {
return point._voronoiX === d._voronoiX && point._voronoiY === d._voronoiY;
});
}
_createClass(VoronoiHelpersClass, [{
key: "withinBounds",
value: function withinBounds(props, point) {
var width = props.width,
height = props.height,
polar = props.polar,
origin = props.origin,
scale = props.scale;
var padding = _victoryCore.Helpers.getPadding(props, "voronoiPadding");
var x = point.x,
y = point.y;
if (polar) {
var distanceSquared = Math.pow(x - origin.x, 2) + Math.pow(y - origin.y, 2);
var radius = Math.max.apply(Math, _toConsumableArray(scale.y.range()));
return distanceSquared < Math.pow(radius, 2);
}
return x >= padding.left && x <= width - padding.right && y >= padding.top && y <= height - padding.bottom;
withinRadius(point, mousePosition, radius) {
if (!point) {
return false;
}
}, {
key: "getDatasets",
value: function getDatasets(props) {
var minDomain = {
x: _victoryCore.Collection.getMinValue(props.domain.x),
y: _victoryCore.Collection.getMinValue(props.domain.y)
};
var children = _react.default.Children.toArray(props.children);
var addMeta = function (data, name, child) {
var continuous = child && child.type && child.type.continuous;
var style = child ? child.props && child.props.style : props.style;
return data.map(function (datum, index) {
var _Helpers$getPoint = _victoryCore.Helpers.getPoint(datum),
x = _Helpers$getPoint.x,
y = _Helpers$getPoint.y,
y0 = _Helpers$getPoint.y0,
x0 = _Helpers$getPoint.x0;
var voronoiX = (Number(x) + Number(x0)) / 2;
var voronoiY = (Number(y) + Number(y0)) / 2;
return Object.assign({
_voronoiX: props.voronoiDimension === "y" ? minDomain.x : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? minDomain.y : voronoiY,
eventKey: index,
childName: name,
continuous: continuous,
style: style
}, datum);
});
};
if (props.data) {
return addMeta(props.data);
}
var getData = function (childProps) {
var data = _victoryCore.Data.getData(childProps);
return Array.isArray(data) && data.length > 0 ? data : undefined;
};
var iteratee = function (child, childName) {
var childProps = child.props || {};
var name = childProps.name || childName;
var blacklist = props.voronoiBlacklist || [];
var blacklistStr = blacklist.filter(_isString2.default);
var blacklistRegExp = blacklist.filter(_isRegExp2.default);
var isRegExpMatch = blacklistRegExp.some(function (regExp) {
return regExp.test(name);
});
if (!_victoryCore.Data.isDataComponent(child) || (0, _includes2.default)(blacklistStr, name) || isRegExpMatch) {
return null;
}
var getChildData = child.type && (0, _isFunction2.default)(child.type.getData) ? child.type.getData : getData;
var childData = getChildData(child.props);
return childData ? addMeta(childData, name, child) : null;
};
return _victoryCore.Helpers.reduceChildren(children, iteratee, props);
if (!radius) {
return true;
}
}, {
key: "findPoints",
value: function findPoints(datasets, point) {
return datasets.filter(function (d) {
return point._voronoiX === d._voronoiX && point._voronoiY === d._voronoiY;
});
const {
x,
y
} = mousePosition;
const distanceSquared = Math.pow(x - point[0], 2) + Math.pow(y - point[1], 2);
return distanceSquared < Math.pow(radius, 2);
}
getVoronoiPoints(props, mousePosition) {
const datasets = this.getDatasets(props);
const scaledData = datasets.map(d => {
const {
x,
y
} = _victoryCore.Helpers.scalePoint(props, d);
return [x, y];
});
const delaunay = _index.default.from(scaledData);
const index = delaunay.find(mousePosition.x, mousePosition.y);
const withinRadius = this.withinRadius(scaledData[index], mousePosition, props.radius);
const points = withinRadius ? this.findPoints(datasets, datasets[index]) : [];
return {
points,
index
};
}
getActiveMutations(props, point) {
const {
childName,
continuous
} = point;
const {
activateData,
activateLabels,
labels
} = props;
if (!activateData && !activateLabels) {
return [];
}
}, {
key: "withinRadius",
value: function withinRadius(point, mousePosition, radius) {
if (!point) {
return false;
}
if (!radius) {
return true;
}
var x = mousePosition.x,
y = mousePosition.y;
var distanceSquared = Math.pow(x - point[0], 2) + Math.pow(y - point[1], 2);
return distanceSquared < Math.pow(radius, 2);
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if ((0, _isEmpty2.default)(targets)) {
return [];
}
}, {
key: "getVoronoiPoints",
value: function getVoronoiPoints(props, mousePosition) {
var datasets = this.getDatasets(props);
var scaledData = datasets.map(function (d) {
var _Helpers$scalePoint = _victoryCore.Helpers.scalePoint(props, d),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
return [x, y];
});
var delaunay = _index.default.from(scaledData);
var index = delaunay.find(mousePosition.x, mousePosition.y);
var withinRadius = this.withinRadius(scaledData[index], mousePosition, props.radius);
var points = withinRadius ? this.findPoints(datasets, datasets[index]) : [];
return targets.map(target => {
const eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
return {
points: points,
index: index
childName,
eventKey,
target,
mutation: () => ({
active: true
})
};
});
}
getInactiveMutations(props, point) {
const {
childName,
continuous
} = point;
const {
activateData,
activateLabels,
labels
} = props;
if (!activateData && !activateLabels) {
return [];
}
}, {
key: "getActiveMutations",
value: function getActiveMutations(props, point) {
var childName = point.childName,
continuous = point.continuous;
var activateData = props.activateData,
activateLabels = props.activateLabels,
labels = props.labels;
if (!activateData && !activateLabels) {
return [];
}
var defaultTarget = activateData ? ["data"] : [];
var targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if ((0, _isEmpty2.default)(targets)) {
return [];
}
return targets.map(function (target) {
var eventKey = continuous === true && target === "data" ? "all" : point.eventKey;
return {
childName: childName,
eventKey: eventKey,
target: target,
mutation: function () {
return {
active: true
};
}
};
});
const defaultTarget = activateData ? ["data"] : [];
const targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if ((0, _isEmpty2.default)(targets)) {
return [];
}
}, {
key: "getInactiveMutations",
value: function getInactiveMutations(props, point) {
var childName = point.childName,
continuous = point.continuous;
var activateData = props.activateData,
activateLabels = props.activateLabels,
labels = props.labels;
return targets.map(target => {
const eventKey = continuous && target === "data" ? "all" : point.eventKey;
return {
childName,
eventKey,
target,
mutation: () => null
};
});
}
if (!activateData && !activateLabels) {
return [];
}
var defaultTarget = activateData ? ["data"] : [];
var targets = labels && !activateLabels ? defaultTarget : defaultTarget.concat("labels");
if ((0, _isEmpty2.default)(targets)) {
return [];
}
return targets.map(function (target) {
var eventKey = continuous && target === "data" ? "all" : point.eventKey;
return {
childName: childName,
eventKey: eventKey,
target: target,
mutation: function () {
return null;
}
};
});
} // eslint-disable-next-line max-params
}, {
key: "getParentMutation",
value: function getParentMutation(activePoints, mousePosition, parentSVG, vIndex) {
return [{
target: "parent",
eventKey: "parent",
mutation: function () {
return {
activePoints: activePoints,
mousePosition: mousePosition,
parentSVG: parentSVG,
vIndex: vIndex
};
}
}];
// eslint-disable-next-line max-params
getParentMutation(activePoints, mousePosition, parentSVG, vIndex) {
return [{
target: "parent",
eventKey: "parent",
mutation: () => ({
activePoints,
mousePosition,
parentSVG,
vIndex
})
}];
}
onActivated(props, points) {
if (_victoryCore.Helpers.isFunction(props.onActivated)) {
props.onActivated(points, props);
}
}, {
key: "onActivated",
value: function onActivated(props, points) {
if ((0, _isFunction2.default)(props.onActivated)) {
props.onActivated(points, props);
}
}
onDeactivated(props, points) {
if (_victoryCore.Helpers.isFunction(props.onDeactivated)) {
props.onDeactivated(points, props);
}
}, {
key: "onDeactivated",
value: function onDeactivated(props, points) {
if ((0, _isFunction2.default)(props.onDeactivated)) {
props.onDeactivated(points, props);
}
}
onMouseLeave = (evt, targetProps) => {
const activePoints = targetProps.activePoints || [];
this.onDeactivated(targetProps, activePoints);
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return this.getParentMutation([]).concat(...inactiveMutations);
};
handleMouseMove = (evt, targetProps) => {
// eslint-disable-line max-statements
const activePoints = targetProps.activePoints || [];
const parentSVG = targetProps.parentSVG || _victoryCore.Selection.getParentSVG(evt);
const mousePosition = _victoryCore.Selection.getSVGEventCoordinates(evt, parentSVG);
if (!this.withinBounds(targetProps, mousePosition)) {
this.onDeactivated(targetProps, activePoints);
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return this.getParentMutation([], mousePosition, parentSVG).concat(...inactiveMutations);
}
}]);
return VoronoiHelpersClass;
}();
var VoronoiHelpers = new VoronoiHelpersClass();
exports.VoronoiHelpers = VoronoiHelpers;
const {
points = [],
index
} = this.getVoronoiPoints(targetProps, mousePosition);
const parentMutations = this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && (0, _reactFastCompare.default)(points, activePoints)) {
return parentMutations;
}
this.onActivated(targetProps, points);
this.onDeactivated(targetProps, activePoints);
const activeMutations = points.length ? points.map(point => this.getActiveMutations(targetProps, point)) : [];
const inactiveMutations = activePoints.length ? activePoints.map(point => this.getInactiveMutations(targetProps, point)) : [];
return parentMutations.concat(...inactiveMutations, ...activeMutations);
};
onMouseMove = (0, _throttle2.default)(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false
});
}
const VoronoiHelpers = exports.VoronoiHelpers = new VoronoiHelpersClass();
{
"name": "victory-voronoi-container",
"version": "36.9.1",
"version": "36.9.2-next.0",
"description": "Interactive Voronoi Mouseover Component for Victory",

@@ -26,4 +26,4 @@ "keywords": [

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

@@ -33,5 +33,2 @@ "peerDependencies": {

},
"publishConfig": {
"provenance": true
},
"wireit": {

@@ -257,3 +254,3 @@ "### THESE WIREIT CONFIGS ARE GENERATED ####": {},

"jest": {
"command": "nps jest:pkg",
"command": "jest --passWithNoTests",
"files": [

@@ -267,5 +264,6 @@ "src/**/*.test.*",

"dependencies": [
"build:lib:cjs",
"../victory-vendor:build:lib:cjs",
"../victory-voronoi:build:lib:cjs"
"../victory-core:build",
"../victory-tooltip:build",
"../victory-vendor:build",
"../victory-voronoi:build"
],

@@ -272,0 +270,0 @@ "packageLocks": [

import { Collection, Selection, Data, Helpers } from "victory-core";
import {
isFunction,
isEmpty,
includes,
isString,
isRegExp,
throttle,
} from "lodash";
import { isEmpty, includes, isString, isRegExp, throttle } from "lodash";
import isEqual from "react-fast-compare";

@@ -87,3 +80,3 @@ import Delaunay from "delaunay-find/lib/index.js";

const getChildData =
child.type && isFunction(child.type.getData)
child.type && Helpers.isFunction(child.type.getData)
? child.type.getData

@@ -199,3 +192,3 @@ : getData;

onActivated(props, points) {
if (isFunction(props.onActivated)) {
if (Helpers.isFunction(props.onActivated)) {
props.onActivated(points, props);

@@ -206,3 +199,3 @@ }

onDeactivated(props, points) {
if (isFunction(props.onDeactivated)) {
if (Helpers.isFunction(props.onDeactivated)) {
props.onDeactivated(points, props);

@@ -209,0 +202,0 @@ }

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

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

Sorry, the diff of this file is not supported yet

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