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

victory-box-plot

Package Overview
Dependencies
Maintainers
2
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

victory-box-plot - npm Package Compare versions

Comparing version 31.3.0 to 32.0.0

100

es/helper-methods.js

@@ -12,7 +12,7 @@ import _isNil from "lodash/isNil";

import { Helpers, Scale, Domain, Data, Collection } from "victory-core";
import { Helpers, Scale, Domain, Data } from "victory-core";
import { min as d3Min, max as d3Max, quantile as d3Quantile } from "d3-array";
var TYPES = ["max", "min", "median", "q1", "q3"];
var checkProcessedData = function (props, data) {
var checkProcessedData = function (data) {
/* check if the data is pre-processed. start by checking that it has

@@ -27,11 +27,9 @@ all required quartile attributes. */

if (hasQuartileAttributes) {
// check that the indepedent variable is distinct
var values = data.map(function (_ref) {
var _x = _ref._x,
_y = _ref._y;
return props.horizontal ? _y : _x;
// check that the independent variable is distinct
var values = data.map(function (d) {
return d._x;
});
if (!_uniq(values).length === values.length) {
throw new Error("\n data prop may only take an array of objects with a unique\n independent variable. Make sure your x or y values are distinct.\n ");
throw new Error("\n data prop may only take an array of objects with a unique\n independent variable. Make sure your x values are distinct.\n ");
}

@@ -49,5 +47,5 @@

var getSummaryStatistics = function (data, horizontal) {
var getSummaryStatistics = function (data) {
var dependentVars = data.map(function (datum) {
return horizontal ? datum._x : datum._y;
return datum._y;
});

@@ -63,20 +61,11 @@ var quartiles = {

};
return horizontal ? _assign({}, quartiles, {
return _assign({}, data[0], quartiles, {
_y: data[0]._y
}) : _assign({}, quartiles, {
_x: data[0]._x
});
};
var isHorizontal = function (props, data) {
var arrayX = data.every(function (datum) {
return Array.isArray(datum._x);
});
return arrayX || props.horizontal;
};
var processData = function (props, data) {
var processData = function (data) {
/* check if the data is coming in a pre-processed form,
i.e. { x || y, min, max, q1, q3, median }. if not, process it. */
var isProcessed = checkProcessedData(props, data);
var isProcessed = checkProcessedData(data);

@@ -91,9 +80,8 @@ if (!isProcessed) {

});
var horizontal = arrayX || props.horizontal;
var sortKey = horizontal ? "_x" : "_y";
var groupKey = horizontal ? "_y" : "_x";
var sortKey = "_y";
var groupKey = "_x";
if (arrayX && arrayY) {
throw new Error("\n data may not be given with array values for both x and y\n ");
} else if (arrayX || arrayY) {
if (arrayX) {
throw new Error("\n data should not be given as in array for x\n ");
} else if (arrayY) {
/* generate summary statistics for each datum. to do this, flatten

@@ -108,3 +96,3 @@ the depedentVarArray and process each datum separately */

return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -120,3 +108,3 @@ } else {

return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -132,3 +120,3 @@ }

var formattedData = Data.formatData(props.data, props, accessorTypes);
return formattedData.length ? processData(props, formattedData) : [];
return formattedData.length ? processData(formattedData) : [];
};

@@ -166,9 +154,6 @@

if (dataset.length < 1) {
var scaleDomain = Scale.getBaseScale(props, axis).domain();
var min = minDomain !== undefined ? minDomain : Collection.getMinValue(scaleDomain);
var max = maxDomain !== undefined ? maxDomain : Collection.getMaxValue(scaleDomain);
return Domain.getDomainFromMinMax(min, max);
return minDomain !== undefined && maxDomain !== undefined ? Domain.getDomainFromMinMax(minDomain, maxDomain) : undefined;
}
return props.horizontal && axis === "x" || !props.horizontal && axis === "y" ? getDomainFromMinMaxValues(dataset, props, axis) : reduceDataset(dataset, props, axis);
return axis === "y" ? getDomainFromMinMaxValues(dataset, props, axis) : reduceDataset(dataset, props, axis);
};

@@ -213,5 +198,5 @@

var getCalculatedValues = function (props) {
var theme = props.theme;
var theme = props.theme,
horizontal = props.horizontal;
var data = getData(props);
var horizontal = isHorizontal(props, data);
var range = {

@@ -226,9 +211,9 @@ x: Helpers.getRange(props, "x"),

var scale = {
x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
x: Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
y: Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
};
var defaultStyles = theme && theme.boxplot && theme.boxplot.style ? theme.boxplot.style : {};
var style = getStyles(props, defaultStyles);
var defaultLabelOrientation = horizontal ? "top" : "right";
var labelOrientation = props.labelOrientation || defaultLabelOrientation;
var defaultOrientation = props.horizontal ? "top" : "right";
var labelOrientation = props.labelOrientation || defaultOrientation;
var boxWidth = props.boxWidth || 1;

@@ -369,4 +354,14 @@ return {

var labelStyle = style[namespace] || style.labels;
var defaultVerticalAnchor = horizontal ? "end" : "middle";
var defaultTextAnchor = horizontal ? "middle" : "start";
var defaultVerticalAnchors = {
top: "end",
bottom: "start",
left: "middle",
right: "middle"
};
var defaultTextAnchors = {
left: "end",
right: "start",
top: "middle",
bottom: "middle"
};
var whiskerWidth = typeof props.whiskerWidth === "number" ? props.whiskerWidth : boxWidth;

@@ -387,8 +382,10 @@ var width = type === "min" || type === "max" ? whiskerWidth : boxWidth;

index: index,
orientation: labelOrientation,
style: labelStyle,
y: horizontal ? getDefaultPosition("y") : positions[type],
x: horizontal ? positions[type] : getDefaultPosition("x"),
textAnchor: labelStyle.textAnchor || defaultTextAnchor,
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchor,
angle: labelStyle.angle
textAnchor: labelStyle.textAnchor || defaultTextAnchors[labelOrientation],
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchors[labelOrientation],
angle: labelStyle.angle,
horizontal: horizontal
};

@@ -437,11 +434,12 @@ };

padding: padding,
groupComponent: groupComponent
groupComponent: groupComponent,
horizontal: horizontal
}
};
var boxScale = horizontal ? scale.x : scale.y;
var boxScale = scale.y;
return data.reduce(function (acc, datum, index) {
var eventKey = !_isNil(datum.eventKey) ? datum.eventKey : index;
var positions = {
x: scale.x(datum._x),
y: scale.y(datum._y),
x: horizontal ? scale.y(datum._y) : scale.x(datum._x),
y: horizontal ? scale.x(datum._x) : scale.y(datum._y),
min: boxScale(datum._min),

@@ -448,0 +446,0 @@ max: boxScale(datum._max),

@@ -275,3 +275,2 @@ import _isNil from "lodash/isNil";

samples: 50,
scale: "linear",
sortKey: "x",

@@ -278,0 +277,0 @@ sortOrder: "ascending",

@@ -34,3 +34,3 @@ "use strict";

var checkProcessedData = function (props, data) {
var checkProcessedData = function (data) {
/* check if the data is pre-processed. start by checking that it has

@@ -45,11 +45,9 @@ all required quartile attributes. */

if (hasQuartileAttributes) {
// check that the indepedent variable is distinct
var values = data.map(function (_ref) {
var _x = _ref._x,
_y = _ref._y;
return props.horizontal ? _y : _x;
// check that the independent variable is distinct
var values = data.map(function (d) {
return d._x;
});
if (!(0, _uniq2.default)(values).length === values.length) {
throw new Error("\n data prop may only take an array of objects with a unique\n independent variable. Make sure your x or y values are distinct.\n ");
throw new Error("\n data prop may only take an array of objects with a unique\n independent variable. Make sure your x values are distinct.\n ");
}

@@ -67,5 +65,5 @@

var getSummaryStatistics = function (data, horizontal) {
var getSummaryStatistics = function (data) {
var dependentVars = data.map(function (datum) {
return horizontal ? datum._x : datum._y;
return datum._y;
});

@@ -81,20 +79,11 @@ var quartiles = {

};
return horizontal ? (0, _assign3.default)({}, quartiles, {
return (0, _assign3.default)({}, data[0], quartiles, {
_y: data[0]._y
}) : (0, _assign3.default)({}, quartiles, {
_x: data[0]._x
});
};
var isHorizontal = function (props, data) {
var arrayX = data.every(function (datum) {
return Array.isArray(datum._x);
});
return arrayX || props.horizontal;
};
var processData = function (props, data) {
var processData = function (data) {
/* check if the data is coming in a pre-processed form,
i.e. { x || y, min, max, q1, q3, median }. if not, process it. */
var isProcessed = checkProcessedData(props, data);
var isProcessed = checkProcessedData(data);

@@ -109,9 +98,8 @@ if (!isProcessed) {

});
var horizontal = arrayX || props.horizontal;
var sortKey = horizontal ? "_x" : "_y";
var groupKey = horizontal ? "_y" : "_x";
var sortKey = "_y";
var groupKey = "_x";
if (arrayX && arrayY) {
throw new Error("\n data may not be given with array values for both x and y\n ");
} else if (arrayX || arrayY) {
if (arrayX) {
throw new Error("\n data should not be given as in array for x\n ");
} else if (arrayY) {
/* generate summary statistics for each datum. to do this, flatten

@@ -124,3 +112,3 @@ the depedentVarArray and process each datum separately */

var sortedData = (0, _orderBy2.default)(dataArray, sortKey);
return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -133,3 +121,3 @@ } else {

var sortedData = (0, _orderBy2.default)(datum, sortKey);
return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -147,3 +135,3 @@ }

return formattedData.length ? processData(props, formattedData) : [];
return formattedData.length ? processData(formattedData) : [];
};

@@ -189,10 +177,6 @@

if (dataset.length < 1) {
var scaleDomain = _victoryCore.Scale.getBaseScale(props, axis).domain();
var min = minDomain !== undefined ? minDomain : _victoryCore.Collection.getMinValue(scaleDomain);
var max = maxDomain !== undefined ? maxDomain : _victoryCore.Collection.getMaxValue(scaleDomain);
return _victoryCore.Domain.getDomainFromMinMax(min, max);
return minDomain !== undefined && maxDomain !== undefined ? _victoryCore.Domain.getDomainFromMinMax(minDomain, maxDomain) : undefined;
}
return props.horizontal && axis === "x" || !props.horizontal && axis === "y" ? getDomainFromMinMaxValues(dataset, props, axis) : reduceDataset(dataset, props, axis);
return axis === "y" ? getDomainFromMinMaxValues(dataset, props, axis) : reduceDataset(dataset, props, axis);
};

@@ -235,5 +219,5 @@

var getCalculatedValues = function (props) {
var theme = props.theme;
var theme = props.theme,
horizontal = props.horizontal;
var data = getData(props);
var horizontal = isHorizontal(props, data);
var range = {

@@ -248,9 +232,9 @@ x: _victoryCore.Helpers.getRange(props, "x"),

var scale = {
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
};
var defaultStyles = theme && theme.boxplot && theme.boxplot.style ? theme.boxplot.style : {};
var style = getStyles(props, defaultStyles);
var defaultLabelOrientation = horizontal ? "top" : "right";
var labelOrientation = props.labelOrientation || defaultLabelOrientation;
var defaultOrientation = props.horizontal ? "top" : "right";
var labelOrientation = props.labelOrientation || defaultOrientation;
var boxWidth = props.boxWidth || 1;

@@ -391,4 +375,14 @@ return {

var labelStyle = style[namespace] || style.labels;
var defaultVerticalAnchor = horizontal ? "end" : "middle";
var defaultTextAnchor = horizontal ? "middle" : "start";
var defaultVerticalAnchors = {
top: "end",
bottom: "start",
left: "middle",
right: "middle"
};
var defaultTextAnchors = {
left: "end",
right: "start",
top: "middle",
bottom: "middle"
};
var whiskerWidth = typeof props.whiskerWidth === "number" ? props.whiskerWidth : boxWidth;

@@ -409,8 +403,10 @@ var width = type === "min" || type === "max" ? whiskerWidth : boxWidth;

index: index,
orientation: labelOrientation,
style: labelStyle,
y: horizontal ? getDefaultPosition("y") : positions[type],
x: horizontal ? positions[type] : getDefaultPosition("x"),
textAnchor: labelStyle.textAnchor || defaultTextAnchor,
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchor,
angle: labelStyle.angle
textAnchor: labelStyle.textAnchor || defaultTextAnchors[labelOrientation],
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchors[labelOrientation],
angle: labelStyle.angle,
horizontal: horizontal
};

@@ -460,11 +456,12 @@ };

padding: padding,
groupComponent: groupComponent
groupComponent: groupComponent,
horizontal: horizontal
}
};
var boxScale = horizontal ? scale.x : scale.y;
var boxScale = scale.y;
return data.reduce(function (acc, datum, index) {
var eventKey = !(0, _isNil2.default)(datum.eventKey) ? datum.eventKey : index;
var positions = {
x: scale.x(datum._x),
y: scale.y(datum._y),
x: horizontal ? scale.y(datum._y) : scale.x(datum._x),
y: horizontal ? scale.x(datum._x) : scale.y(datum._y),
min: boxScale(datum._min),

@@ -471,0 +468,0 @@ max: boxScale(datum._max),

@@ -288,3 +288,2 @@ "use strict";

samples: 50,
scale: "linear",
sortKey: "x",

@@ -291,0 +290,0 @@ sortOrder: "ascending",

{
"name": "victory-box-plot",
"version": "31.3.0",
"version": "32.0.0",
"description": "Box Plot Component for Victory",

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

"prop-types": "^15.5.8",
"victory-core": "^31.2.0"
"victory-core": "^32.0.0"
},

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

import { orderBy, defaults, assign, uniq, groupBy, keys, isNaN, isNil } from "lodash";
import { Helpers, Scale, Domain, Data, Collection } from "victory-core";
import { Helpers, Scale, Domain, Data } from "victory-core";
import { min as d3Min, max as d3Max, quantile as d3Quantile } from "d3-array";

@@ -7,3 +7,3 @@

const checkProcessedData = (props, data) => {
const checkProcessedData = (data) => {
/* check if the data is pre-processed. start by checking that it has

@@ -16,8 +16,8 @@ all required quartile attributes. */

if (hasQuartileAttributes) {
// check that the indepedent variable is distinct
const values = data.map(({ _x, _y }) => (props.horizontal ? _y : _x));
// check that the independent variable is distinct
const values = data.map((d) => d._x);
if (!uniq(values).length === values.length) {
throw new Error(`
data prop may only take an array of objects with a unique
independent variable. Make sure your x or y values are distinct.
independent variable. Make sure your x values are distinct.
`);

@@ -32,4 +32,4 @@ }

const getSummaryStatistics = (data, horizontal) => {
const dependentVars = data.map((datum) => (horizontal ? datum._x : datum._y));
const getSummaryStatistics = (data) => {
const dependentVars = data.map((datum) => datum._y);
const quartiles = {

@@ -43,17 +43,9 @@ _q1: nanToNull(d3Quantile(dependentVars, 0.25)), // eslint-disable-line no-magic-numbers

return horizontal
? assign({}, quartiles, { _y: data[0]._y })
: assign({}, quartiles, { _x: data[0]._x });
return assign({}, data[0], quartiles, { _y: data[0]._y });
};
const isHorizontal = (props, data) => {
const arrayX = data.every((datum) => Array.isArray(datum._x));
return arrayX || props.horizontal;
};
const processData = (props, data) => {
const processData = (data) => {
/* check if the data is coming in a pre-processed form,
i.e. { x || y, min, max, q1, q3, median }. if not, process it. */
const isProcessed = checkProcessedData(props, data);
const isProcessed = checkProcessedData(data);
if (!isProcessed) {

@@ -63,10 +55,9 @@ // check if the data is coming with x or y values as an array

const arrayY = data.every((datum) => Array.isArray(datum._y));
const horizontal = arrayX || props.horizontal;
const sortKey = horizontal ? "_x" : "_y";
const groupKey = horizontal ? "_y" : "_x";
if (arrayX && arrayY) {
const sortKey = "_y";
const groupKey = "_x";
if (arrayX) {
throw new Error(`
data may not be given with array values for both x and y
data should not be given as in array for x
`);
} else if (arrayX || arrayY) {
} else if (arrayY) {
/* generate summary statistics for each datum. to do this, flatten

@@ -77,3 +68,3 @@ the depedentVarArray and process each datum separately */

const sortedData = orderBy(dataArray, sortKey);
return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -86,3 +77,3 @@ } else {

const sortedData = orderBy(datum, sortKey);
return getSummaryStatistics(sortedData, horizontal);
return getSummaryStatistics(sortedData);
});

@@ -98,3 +89,3 @@ }

const formattedData = Data.formatData(props.data, props, accessorTypes);
return formattedData.length ? processData(props, formattedData) : [];
return formattedData.length ? processData(formattedData) : [];
};

@@ -144,8 +135,7 @@

if (dataset.length < 1) {
const scaleDomain = Scale.getBaseScale(props, axis).domain();
const min = minDomain !== undefined ? minDomain : Collection.getMinValue(scaleDomain);
const max = maxDomain !== undefined ? maxDomain : Collection.getMaxValue(scaleDomain);
return Domain.getDomainFromMinMax(min, max);
return minDomain !== undefined && maxDomain !== undefined
? Domain.getDomainFromMinMax(minDomain, maxDomain)
: undefined;
}
return (props.horizontal && axis === "x") || (!props.horizontal && axis === "y")
return axis === "y"
? getDomainFromMinMaxValues(dataset, props, axis)

@@ -185,5 +175,4 @@ : reduceDataset(dataset, props, axis);

const getCalculatedValues = (props) => {
const { theme } = props;
const { theme, horizontal } = props;
const data = getData(props);
const horizontal = isHorizontal(props, data);
const range = {

@@ -200,11 +189,11 @@ x: Helpers.getRange(props, "x"),

.domain(domain.x)
.range(range.x),
.range(props.horizontal ? range.y : range.x),
y: Scale.getBaseScale(props, "y")
.domain(domain.y)
.range(range.y)
.range(props.horizontal ? range.x : range.y)
};
const defaultStyles = theme && theme.boxplot && theme.boxplot.style ? theme.boxplot.style : {};
const style = getStyles(props, defaultStyles);
const defaultLabelOrientation = horizontal ? "top" : "right";
const labelOrientation = props.labelOrientation || defaultLabelOrientation;
const defaultOrientation = props.horizontal ? "top" : "right";
const labelOrientation = props.labelOrientation || defaultOrientation;
const boxWidth = props.boxWidth || 1;

@@ -296,4 +285,4 @@ return { data, horizontal, domain, scale, style, labelOrientation, boxWidth };

const labelStyle = style[namespace] || style.labels;
const defaultVerticalAnchor = horizontal ? "end" : "middle";
const defaultTextAnchor = horizontal ? "middle" : "start";
const defaultVerticalAnchors = { top: "end", bottom: "start", left: "middle", right: "middle" };
const defaultTextAnchors = { left: "end", right: "start", top: "middle", bottom: "middle" };
const whiskerWidth = typeof props.whiskerWidth === "number" ? props.whiskerWidth : boxWidth;

@@ -314,8 +303,10 @@ const width = type === "min" || type === "max" ? whiskerWidth : boxWidth;

index,
orientation: labelOrientation,
style: labelStyle,
y: horizontal ? getDefaultPosition("y") : positions[type],
x: horizontal ? positions[type] : getDefaultPosition("x"),
textAnchor: labelStyle.textAnchor || defaultTextAnchor,
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchor,
angle: labelStyle.angle
textAnchor: labelStyle.textAnchor || defaultTextAnchors[labelOrientation],
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchors[labelOrientation],
angle: labelStyle.angle,
horizontal
};

@@ -364,12 +355,12 @@ };

padding,
groupComponent
groupComponent,
horizontal
}
};
const boxScale = horizontal ? scale.x : scale.y;
const boxScale = scale.y;
return data.reduce((acc, datum, index) => {
const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
const positions = {
x: scale.x(datum._x),
y: scale.y(datum._y),
x: horizontal ? scale.y(datum._y) : scale.x(datum._x),
y: horizontal ? scale.x(datum._x) : scale.y(datum._y),
min: boxScale(datum._min),

@@ -376,0 +367,0 @@ max: boxScale(datum._max),

@@ -176,3 +176,2 @@ import React from "react";

samples: 50,
scale: "linear",
sortKey: "x",

@@ -179,0 +178,0 @@ sortOrder: "ascending",

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