Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

victory-voronoi-container

Package Overview
Dependencies
Maintainers
2
Versions
155
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

victory-voronoi-container - npm Package Compare versions

Comparing version 32.3.1 to 32.3.2

88

es/voronoi-helpers.js
import _isRegExp from "lodash/isRegExp";
import _isString from "lodash/isString";
import _includes from "lodash/includes";
import _keys from "lodash/keys";
import _groupBy from "lodash/groupBy";
import _isEmpty from "lodash/isEmpty";

@@ -21,3 +19,3 @@ import _isFunction from "lodash/isFunction";

import isEqual from "react-fast-compare";
import { voronoi as d3Voronoi } from "d3-voronoi";
import Delaunay from "delaunay-find/lib/index.js";
import React from "react";

@@ -60,4 +58,4 @@ var VoronoiHelpers = {

return _assign({
_voronoiX: props.voronoiDimension === "y" ? 0 : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? 0 : voronoiY,
_voronoiX: props.voronoiDimension === "y" ? undefined : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? undefined : voronoiY,
eventKey: index,

@@ -101,36 +99,43 @@ childName: name,

},
// returns an array of objects with point and data where point is an x, y coordinate, and data is
// an array of points belonging to that coordinate
mergeDatasets: function (props, datasets) {
var points = _groupBy(datasets, function (datum) {
var _Helpers$scalePoint = Helpers.scalePoint(props, datum),
x = _Helpers$scalePoint.x,
y = _Helpers$scalePoint.y;
findPoints: function (datasets, point) {
var x = point._voronoiX;
var y = point._voronoiY;
return "".concat(x, ",").concat(y);
});
if (x !== undefined && y !== undefined) {
return [point];
}
return _keys(points).map(function (key) {
var point = key.split(",");
return {
x: +point[0],
y: +point[1],
points: points[key]
};
return datasets.filter(function (d) {
var matchesX = x === undefined || x === d._voronoiX;
var matchesY = y === undefined || y === d._voronoiY;
return matchesX && matchesY;
});
},
getVoronoi: function (props, mousePosition) {
var width = props.width,
height = props.height,
voronoiPadding = props.voronoiPadding;
var padding = voronoiPadding || 0;
var voronoiFunction = d3Voronoi().x(function (d) {
return d.x;
}).y(function (d) {
return d.y;
}).extent([[padding, padding], [width - padding, height - padding]]);
withinRadius: function (point, mousePosition, radius) {
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);
},
getVoronoiPoints: function (props, mousePosition) {
var datasets = this.getDatasets(props);
var voronoi = voronoiFunction(this.mergeDatasets(props, datasets));
var size = props.voronoiDimension ? undefined : props.radius;
return voronoi.find(mousePosition.x, mousePosition.y, size);
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 {
points: points,
index: index
};
},

@@ -199,3 +204,4 @@ getActiveMutations: function (props, point) {

},
getParentMutation: function (activePoints, mousePosition, parentSVG) {
// eslint-disable-next-line max-params
getParentMutation: function (activePoints, mousePosition, parentSVG, vIndex) {
return [{

@@ -208,3 +214,4 @@ target: "parent",

mousePosition: mousePosition,
parentSVG: parentSVG
parentSVG: parentSVG,
vIndex: vIndex
};

@@ -253,6 +260,9 @@ }

var nearestVoronoi = this.getVoronoi(targetProps, mousePosition);
var points = nearestVoronoi ? nearestVoronoi.data.points : [];
var parentMutations = this.getParentMutation(points, mousePosition, parentSVG);
var _getVoronoiPoints = this.getVoronoiPoints(targetProps, mousePosition),
_getVoronoiPoints$poi = _getVoronoiPoints.points,
points = _getVoronoiPoints$poi === void 0 ? [] : _getVoronoiPoints$poi,
index = _getVoronoiPoints.index;
var parentMutations = this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && isEqual(points, activePoints)) {

@@ -259,0 +269,0 @@ return parentMutations;

@@ -14,6 +14,2 @@ "use strict";

var _keys2 = _interopRequireDefault(require("lodash/keys"));
var _groupBy2 = _interopRequireDefault(require("lodash/groupBy"));
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));

@@ -31,3 +27,3 @@

var _d3Voronoi = require("d3-voronoi");
var _index = _interopRequireDefault(require("delaunay-find/lib/index.js"));

@@ -82,4 +78,4 @@ var _react = _interopRequireDefault(require("react"));

return (0, _assign2.default)({
_voronoiX: props.voronoiDimension === "y" ? 0 : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? 0 : voronoiY,
_voronoiX: props.voronoiDimension === "y" ? undefined : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? undefined : voronoiY,
eventKey: index,

@@ -124,36 +120,46 @@ childName: name,

},
// returns an array of objects with point and data where point is an x, y coordinate, and data is
// an array of points belonging to that coordinate
mergeDatasets: function (props, datasets) {
var points = (0, _groupBy2.default)(datasets, function (datum) {
var _Helpers$scalePoint = _victoryCore.Helpers.scalePoint(props, datum),
findPoints: function (datasets, point) {
var x = point._voronoiX;
var y = point._voronoiY;
if (x !== undefined && y !== undefined) {
return [point];
}
return datasets.filter(function (d) {
var matchesX = x === undefined || x === d._voronoiX;
var matchesY = y === undefined || y === d._voronoiY;
return matchesX && matchesY;
});
},
withinRadius: function (point, mousePosition, radius) {
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);
},
getVoronoiPoints: function (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 "".concat(x, ",").concat(y);
return [x, y];
});
return (0, _keys2.default)(points).map(function (key) {
var point = key.split(",");
return {
x: +point[0],
y: +point[1],
points: points[key]
};
});
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 {
points: points,
index: index
};
},
getVoronoi: function (props, mousePosition) {
var width = props.width,
height = props.height,
voronoiPadding = props.voronoiPadding;
var padding = voronoiPadding || 0;
var voronoiFunction = (0, _d3Voronoi.voronoi)().x(function (d) {
return d.x;
}).y(function (d) {
return d.y;
}).extent([[padding, padding], [width - padding, height - padding]]);
var datasets = this.getDatasets(props);
var voronoi = voronoiFunction(this.mergeDatasets(props, datasets));
var size = props.voronoiDimension ? undefined : props.radius;
return voronoi.find(mousePosition.x, mousePosition.y, size);
},
getActiveMutations: function (props, point) {

@@ -221,3 +227,4 @@ var childName = point.childName,

},
getParentMutation: function (activePoints, mousePosition, parentSVG) {
// eslint-disable-next-line max-params
getParentMutation: function (activePoints, mousePosition, parentSVG, vIndex) {
return [{

@@ -230,3 +237,4 @@ target: "parent",

mousePosition: mousePosition,
parentSVG: parentSVG
parentSVG: parentSVG,
vIndex: vIndex
};

@@ -277,6 +285,9 @@ }

var nearestVoronoi = this.getVoronoi(targetProps, mousePosition);
var points = nearestVoronoi ? nearestVoronoi.data.points : [];
var parentMutations = this.getParentMutation(points, mousePosition, parentSVG);
var _getVoronoiPoints = this.getVoronoiPoints(targetProps, mousePosition),
_getVoronoiPoints$poi = _getVoronoiPoints.points,
points = _getVoronoiPoints$poi === void 0 ? [] : _getVoronoiPoints$poi,
index = _getVoronoiPoints.index;
var parentMutations = this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && (0, _reactFastCompare.default)(points, activePoints)) {

@@ -283,0 +294,0 @@ return parentMutations;

{
"name": "victory-voronoi-container",
"version": "32.3.1",
"version": "32.3.2",
"description": "Interactive Voronoi Mouseover Component for Victory",

@@ -22,7 +22,7 @@ "keywords": [

"dependencies": {
"d3-voronoi": "^1.1.2",
"delaunay-find": "0.0.3",
"lodash": "^4.17.11",
"prop-types": "^15.5.8",
"victory-core": "^32.3.1",
"victory-tooltip": "^32.3.1"
"victory-core": "^32.3.2",
"victory-tooltip": "^32.3.2"
},

@@ -29,0 +29,0 @@ "scripts": {

import { Selection, Data, Helpers } from "victory-core";
import {
assign,
throttle,
isFunction,
isEmpty,
groupBy,
keys,
includes,
isString,
isRegExp
} from "lodash";
import { assign, throttle, isFunction, isEmpty, includes, isString, isRegExp } from "lodash";
import isEqual from "react-fast-compare";
import { voronoi as d3Voronoi } from "d3-voronoi";
import Delaunay from "delaunay-find/lib/index.js";
import React from "react";

@@ -42,4 +32,4 @@

{
_voronoiX: props.voronoiDimension === "y" ? 0 : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? 0 : voronoiY,
_voronoiX: props.voronoiDimension === "y" ? undefined : voronoiX,
_voronoiY: props.voronoiDimension === "x" ? undefined : voronoiY,
eventKey: index,

@@ -83,30 +73,35 @@ childName: name,

// returns an array of objects with point and data where point is an x, y coordinate, and data is
// an array of points belonging to that coordinate
mergeDatasets(props, datasets) {
const points = groupBy(datasets, (datum) => {
const { x, y } = Helpers.scalePoint(props, datum);
return `${x},${y}`;
findPoints(datasets, point) {
const x = point._voronoiX;
const y = point._voronoiY;
if (x !== undefined && y !== undefined) {
return [point];
}
return datasets.filter((d) => {
const matchesX = x === undefined || x === d._voronoiX;
const matchesY = y === undefined || y === d._voronoiY;
return matchesX && matchesY;
});
return keys(points).map((key) => {
const point = key.split(",");
return {
x: +point[0],
y: +point[1],
points: points[key]
};
});
},
getVoronoi(props, mousePosition) {
const { width, height, voronoiPadding } = props;
const padding = voronoiPadding || 0;
const voronoiFunction = d3Voronoi()
.x((d) => d.x)
.y((d) => d.y)
.extent([[padding, padding], [width - padding, height - padding]]);
withinRadius(point, mousePosition, radius) {
if (!radius) {
return true;
}
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 voronoi = voronoiFunction(this.mergeDatasets(props, datasets));
const size = props.voronoiDimension ? undefined : props.radius;
return voronoi.find(mousePosition.x, mousePosition.y, size);
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 };
},

@@ -158,3 +153,4 @@

getParentMutation(activePoints, mousePosition, parentSVG) {
// eslint-disable-next-line max-params
getParentMutation(activePoints, mousePosition, parentSVG, vIndex) {
return [

@@ -164,3 +160,3 @@ {

eventKey: "parent",
mutation: () => ({ activePoints, mousePosition, parentSVG })
mutation: () => ({ activePoints, mousePosition, parentSVG, vIndex })
}

@@ -203,5 +199,4 @@ ];

}
const nearestVoronoi = this.getVoronoi(targetProps, mousePosition);
const points = nearestVoronoi ? nearestVoronoi.data.points : [];
const parentMutations = this.getParentMutation(points, mousePosition, parentSVG);
const { points = [], index } = this.getVoronoiPoints(targetProps, mousePosition);
const parentMutations = this.getParentMutation(points, mousePosition, parentSVG, index);
if (activePoints.length && isEqual(points, activePoints)) {

@@ -208,0 +203,0 @@ return parentMutations;

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc