Comparing version 0.0.179 to 0.0.181
@@ -9,4 +9,2 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.default = BoxPlot; | ||
@@ -22,7 +20,7 @@ | ||
var _group = require('@vx/group'); | ||
var _propTypes = require('prop-types'); | ||
var _additionalProps = require('../util/additionalProps'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _additionalProps2 = _interopRequireDefault(_additionalProps); | ||
var _group = require('@vx/group'); | ||
@@ -33,113 +31,152 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function verticalToHorizontal(_ref) { | ||
var _ref2 = _slicedToArray(_ref, 4), | ||
x1 = _ref2[0], | ||
y1 = _ref2[1], | ||
x2 = _ref2[2], | ||
y2 = _ref2[3]; | ||
var x1 = _ref.x1, | ||
x2 = _ref.x2, | ||
y1 = _ref.y1, | ||
y2 = _ref.y2; | ||
return [y1, x1, y2, x2]; | ||
return { | ||
x1: y1, | ||
x2: y2, | ||
y1: x1, | ||
y2: x2 | ||
}; | ||
} | ||
function BoxPlot(_ref3) { | ||
var _ref3$left = _ref3.left, | ||
left = _ref3$left === undefined ? 0 : _ref3$left, | ||
_ref3$top = _ref3.top, | ||
top = _ref3$top === undefined ? 0 : _ref3$top, | ||
className = _ref3.className, | ||
data = _ref3.data, | ||
max = _ref3.max, | ||
min = _ref3.min, | ||
firstQuartile = _ref3.firstQuartile, | ||
thirdQuartile = _ref3.thirdQuartile, | ||
median = _ref3.median, | ||
boxWidth = _ref3.boxWidth, | ||
fill = _ref3.fill, | ||
fillOpacity = _ref3.fillOpacity, | ||
stroke = _ref3.stroke, | ||
strokeWidth = _ref3.strokeWidth, | ||
_ref3$rx = _ref3.rx, | ||
rx = _ref3$rx === undefined ? 2 : _ref3$rx, | ||
_ref3$ry = _ref3.ry, | ||
ry = _ref3$ry === undefined ? 2 : _ref3$ry, | ||
valueScale = _ref3.valueScale, | ||
outliers = _ref3.outliers, | ||
horizontal = _ref3.horizontal, | ||
_ref3$medianProps = _ref3.medianProps, | ||
medianProps = _ref3$medianProps === undefined ? {} : _ref3$medianProps, | ||
_ref3$maxProps = _ref3.maxProps, | ||
maxProps = _ref3$maxProps === undefined ? {} : _ref3$maxProps, | ||
_ref3$minProps = _ref3.minProps, | ||
minProps = _ref3$minProps === undefined ? {} : _ref3$minProps, | ||
_ref3$boxProps = _ref3.boxProps, | ||
boxProps = _ref3$boxProps === undefined ? {} : _ref3$boxProps, | ||
_ref3$outlierProps = _ref3.outlierProps, | ||
outlierProps = _ref3$outlierProps === undefined ? {} : _ref3$outlierProps, | ||
_ref3$container = _ref3.container, | ||
container = _ref3$container === undefined ? false : _ref3$container, | ||
_ref3$containerProps = _ref3.containerProps, | ||
containerProps = _ref3$containerProps === undefined ? {} : _ref3$containerProps, | ||
restProps = _objectWithoutProperties(_ref3, ['left', 'top', 'className', 'data', 'max', 'min', 'firstQuartile', 'thirdQuartile', 'median', 'boxWidth', 'fill', 'fillOpacity', 'stroke', 'strokeWidth', 'rx', 'ry', 'valueScale', 'outliers', 'horizontal', 'medianProps', 'maxProps', 'minProps', 'boxProps', 'outlierProps', 'container', 'containerProps']); | ||
BoxPlot.propTypes = { | ||
left: _propTypes2.default.number, | ||
top: _propTypes2.default.number, | ||
className: _propTypes2.default.string, | ||
max: _propTypes2.default.number, | ||
min: _propTypes2.default.number, | ||
firstQuartile: _propTypes2.default.number, | ||
thirdQuartile: _propTypes2.default.number, | ||
median: _propTypes2.default.number, | ||
boxWidth: _propTypes2.default.number, | ||
fill: _propTypes2.default.string, | ||
fillOpacity: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]), | ||
stroke: _propTypes2.default.string, | ||
strokeWidth: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]), | ||
rx: _propTypes2.default.number, | ||
ry: _propTypes2.default.number, | ||
valueScale: _propTypes2.default.func, | ||
outliers: _propTypes2.default.array, | ||
horizontal: _propTypes2.default.bool, | ||
medianProps: _propTypes2.default.object, | ||
maxProps: _propTypes2.default.object, | ||
minProps: _propTypes2.default.object, | ||
boxProps: _propTypes2.default.object, | ||
outlierProps: _propTypes2.default.object, | ||
container: _propTypes2.default.bool, | ||
containerProps: _propTypes2.default.object, | ||
children: _propTypes2.default.func | ||
}; | ||
function BoxPlot(_ref2) { | ||
var _ref2$left = _ref2.left, | ||
left = _ref2$left === undefined ? 0 : _ref2$left, | ||
_ref2$top = _ref2.top, | ||
top = _ref2$top === undefined ? 0 : _ref2$top, | ||
className = _ref2.className, | ||
max = _ref2.max, | ||
min = _ref2.min, | ||
firstQuartile = _ref2.firstQuartile, | ||
thirdQuartile = _ref2.thirdQuartile, | ||
median = _ref2.median, | ||
boxWidth = _ref2.boxWidth, | ||
fill = _ref2.fill, | ||
fillOpacity = _ref2.fillOpacity, | ||
stroke = _ref2.stroke, | ||
strokeWidth = _ref2.strokeWidth, | ||
_ref2$rx = _ref2.rx, | ||
rx = _ref2$rx === undefined ? 2 : _ref2$rx, | ||
_ref2$ry = _ref2.ry, | ||
ry = _ref2$ry === undefined ? 2 : _ref2$ry, | ||
valueScale = _ref2.valueScale, | ||
_ref2$outliers = _ref2.outliers, | ||
outliers = _ref2$outliers === undefined ? [] : _ref2$outliers, | ||
horizontal = _ref2.horizontal, | ||
_ref2$medianProps = _ref2.medianProps, | ||
medianProps = _ref2$medianProps === undefined ? {} : _ref2$medianProps, | ||
_ref2$maxProps = _ref2.maxProps, | ||
maxProps = _ref2$maxProps === undefined ? {} : _ref2$maxProps, | ||
_ref2$minProps = _ref2.minProps, | ||
minProps = _ref2$minProps === undefined ? {} : _ref2$minProps, | ||
_ref2$boxProps = _ref2.boxProps, | ||
boxProps = _ref2$boxProps === undefined ? {} : _ref2$boxProps, | ||
_ref2$outlierProps = _ref2.outlierProps, | ||
outlierProps = _ref2$outlierProps === undefined ? {} : _ref2$outlierProps, | ||
_ref2$container = _ref2.container, | ||
container = _ref2$container === undefined ? false : _ref2$container, | ||
_ref2$containerProps = _ref2.containerProps, | ||
containerProps = _ref2$containerProps === undefined ? {} : _ref2$containerProps, | ||
children = _ref2.children; | ||
var offset = horizontal ? top : left; | ||
var center = offset + boxWidth / 2; | ||
var valueRange = valueScale.range(); | ||
var maxLinePos = Array(4).fill(0); | ||
var maxToBoxLinePos = Array(4).fill(0); | ||
var boxPos = Array(4).fill(0); | ||
var medianLinePos = Array(4).fill(0); | ||
var minToBoxLinePos = Array(4).fill(0); | ||
var minLinePos = Array(4).fill(0); | ||
var containerPos = Array(4).fill(0); | ||
var boxplot = { | ||
valueRange: valueRange, | ||
center: center, | ||
offset: offset, | ||
boxWidth: boxWidth, | ||
max: { | ||
x1: center - boxWidth / 4, | ||
x2: center + boxWidth / 4, | ||
y1: valueScale(max), | ||
y2: valueScale(max) | ||
}, | ||
maxToThird: { | ||
x1: center, | ||
x2: center, | ||
y1: valueScale(max), | ||
y2: valueScale(thirdQuartile) | ||
}, | ||
median: { | ||
x1: offset, | ||
x2: offset + boxWidth, | ||
y1: valueScale(median), | ||
y2: valueScale(median) | ||
}, | ||
minToFirst: { | ||
x1: center, | ||
x2: center, | ||
y1: valueScale(firstQuartile), | ||
y2: valueScale(min) | ||
}, | ||
min: { | ||
x1: center - boxWidth / 4, | ||
x2: center + boxWidth / 4, | ||
y1: valueScale(min), | ||
y2: valueScale(min) | ||
}, | ||
box: { | ||
x1: offset, | ||
x2: boxWidth, | ||
y1: valueScale(thirdQuartile), | ||
y2: Math.abs(valueScale(thirdQuartile) - valueScale(firstQuartile)) | ||
}, | ||
container: { | ||
x1: offset, | ||
x2: boxWidth, | ||
y1: Math.min.apply(Math, _toConsumableArray(valueRange)), | ||
y2: Math.abs(valueRange[0] - valueRange[1]) | ||
} | ||
}; | ||
// all of these are [x0, y0, x1, y1] | ||
maxLinePos[0] = center - boxWidth / 4; | ||
maxLinePos[1] = valueScale(max); | ||
maxLinePos[2] = center + boxWidth / 4; | ||
maxLinePos[3] = valueScale(max); | ||
if (horizontal) { | ||
boxplot.max = verticalToHorizontal(boxplot.max); | ||
boxplot.maxToThird = verticalToHorizontal(boxplot.maxToThird); | ||
boxplot.box = verticalToHorizontal(boxplot.box); | ||
boxplot.box.y1 = valueScale(firstQuartile); | ||
boxplot.median = verticalToHorizontal(boxplot.median); | ||
boxplot.minToFirst = verticalToHorizontal(boxplot.minToFirst); | ||
boxplot.min = verticalToHorizontal(boxplot.min); | ||
boxplot.container = verticalToHorizontal(boxplot.container); | ||
boxplot.container.y1 = Math.min.apply(Math, _toConsumableArray(valueRange)); | ||
} | ||
maxToBoxLinePos[0] = center; | ||
maxToBoxLinePos[1] = valueScale(max); | ||
maxToBoxLinePos[2] = center; | ||
maxToBoxLinePos[3] = valueScale(thirdQuartile); | ||
if (children) return children(boxplot); | ||
boxPos[0] = offset; | ||
boxPos[1] = valueScale(thirdQuartile); | ||
boxPos[2] = boxWidth; | ||
boxPos[3] = Math.abs(valueScale(thirdQuartile) - valueScale(firstQuartile)); | ||
medianLinePos[0] = offset; | ||
medianLinePos[1] = valueScale(median); | ||
medianLinePos[2] = offset + boxWidth; | ||
medianLinePos[3] = valueScale(median); | ||
minToBoxLinePos[0] = center; | ||
minToBoxLinePos[1] = valueScale(firstQuartile); | ||
minToBoxLinePos[2] = center; | ||
minToBoxLinePos[3] = valueScale(min); | ||
minLinePos[0] = center - boxWidth / 4; | ||
minLinePos[1] = valueScale(min); | ||
minLinePos[2] = center + boxWidth / 4; | ||
minLinePos[3] = valueScale(min); | ||
var valueRange = valueScale.range(); | ||
containerPos[0] = boxPos[0]; | ||
containerPos[1] = Math.min.apply(Math, _toConsumableArray(valueRange)); | ||
containerPos[2] = boxPos[2]; | ||
containerPos[3] = Math.abs(valueRange[0] - valueRange[1]); | ||
if (horizontal) { | ||
maxLinePos = verticalToHorizontal(maxLinePos); | ||
maxToBoxLinePos = verticalToHorizontal(maxToBoxLinePos); | ||
boxPos = verticalToHorizontal(boxPos); | ||
boxPos[0] = valueScale(firstQuartile); | ||
medianLinePos = verticalToHorizontal(medianLinePos); | ||
minToBoxLinePos = verticalToHorizontal(minToBoxLinePos); | ||
minLinePos = verticalToHorizontal(minLinePos); | ||
containerPos = verticalToHorizontal(containerPos); | ||
containerPos[0] = Math.min.apply(Math, _toConsumableArray(valueRange)); | ||
} | ||
return _react2.default.createElement( | ||
@@ -152,38 +189,28 @@ _group.Group, | ||
return _react2.default.createElement('circle', _extends({ | ||
key: i, | ||
key: 'vx-boxplot-outlier-' + i, | ||
className: 'vx-boxplot-outlier', | ||
cx: cx, | ||
cy: cy, | ||
r: 4, | ||
stroke: stroke, | ||
strokeWidth: 1, | ||
strokeWidth: strokeWidth, | ||
fill: fill, | ||
fillOpacity: fillOpacity, | ||
r: '4' | ||
}, (0, _additionalProps2.default)(outlierProps, { | ||
data: d, | ||
cx: cx, | ||
cy: cy | ||
}))); | ||
fillOpacity: fillOpacity | ||
}, outlierProps)); | ||
}), | ||
_react2.default.createElement('line', _extends({ | ||
className: 'vx-boxplot-max', | ||
x1: maxLinePos[0], | ||
y1: maxLinePos[1], | ||
x2: maxLinePos[2], | ||
y2: maxLinePos[3], | ||
x1: boxplot.max.x1, | ||
y1: boxplot.max.y1, | ||
x2: boxplot.max.x2, | ||
y2: boxplot.max.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, (0, _additionalProps2.default)(maxProps, { | ||
data: data, | ||
max: max, | ||
x1: maxLinePos[0], | ||
x2: maxLinePos[2], | ||
y1: maxLinePos[1], | ||
y2: maxLinePos[3] | ||
}))), | ||
}, maxProps)), | ||
_react2.default.createElement('line', { | ||
x1: maxToBoxLinePos[0], | ||
y1: maxToBoxLinePos[1], | ||
x2: maxToBoxLinePos[2], | ||
y2: maxToBoxLinePos[3], | ||
className: 'vx-boxplot-max-to-third', | ||
x1: boxplot.maxToThird.x1, | ||
y1: boxplot.maxToThird.y1, | ||
x2: boxplot.maxToThird.x2, | ||
y2: boxplot.maxToThird.y2, | ||
stroke: stroke, | ||
@@ -194,6 +221,6 @@ strokeWidth: strokeWidth | ||
className: 'vx-boxplot-box', | ||
x: boxPos[0], | ||
y: boxPos[1], | ||
width: boxPos[2], | ||
height: boxPos[3], | ||
x: boxplot.box.x1, | ||
y: boxplot.box.y1, | ||
width: boxplot.box.x2, | ||
height: boxplot.box.y2, | ||
stroke: stroke, | ||
@@ -205,36 +232,18 @@ strokeWidth: strokeWidth, | ||
ry: ry | ||
}, (0, _additionalProps2.default)(boxProps, { | ||
data: data, | ||
height: boxPos[3], | ||
median: median, | ||
firstQuartile: firstQuartile, | ||
thirdQuartile: thirdQuartile, | ||
min: min, | ||
max: max, | ||
x1: boxPos[0], | ||
x2: boxPos[0] + boxPos[2], | ||
y1: boxPos[1], | ||
y2: boxPos[1] + boxPos[3] | ||
}))), | ||
}, boxProps)), | ||
_react2.default.createElement('line', _extends({ | ||
className: 'vx-boxplot-median', | ||
x1: medianLinePos[0], | ||
y1: medianLinePos[1], | ||
x2: medianLinePos[2], | ||
y2: medianLinePos[3], | ||
x1: boxplot.median.x1, | ||
y1: boxplot.median.y1, | ||
x2: boxplot.median.x2, | ||
y2: boxplot.median.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, (0, _additionalProps2.default)(medianProps, { | ||
data: data, | ||
median: median, | ||
x1: medianLinePos[0], | ||
x2: medianLinePos[2], | ||
y1: medianLinePos[1], | ||
y2: medianLinePos[3] | ||
}))), | ||
}, medianProps)), | ||
_react2.default.createElement('line', { | ||
x1: minToBoxLinePos[0], | ||
y1: minToBoxLinePos[1], | ||
x2: minToBoxLinePos[2], | ||
y2: minToBoxLinePos[3], | ||
className: 'vx-boxplot-min-to-first', | ||
x1: boxplot.minToFirst.x1, | ||
y1: boxplot.minToFirst.y1, | ||
x2: boxplot.minToFirst.x2, | ||
y2: boxplot.minToFirst.y2, | ||
stroke: stroke, | ||
@@ -245,35 +254,17 @@ strokeWidth: strokeWidth | ||
className: 'vx-boxplot-min', | ||
x1: minLinePos[0], | ||
y1: minLinePos[1], | ||
x2: minLinePos[2], | ||
y2: minLinePos[3], | ||
x1: boxplot.min.x1, | ||
y1: boxplot.min.y1, | ||
x2: boxplot.min.x2, | ||
y2: boxplot.min.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, (0, _additionalProps2.default)(minProps, { | ||
data: data, | ||
min: min, | ||
x1: minLinePos[0], | ||
x2: minLinePos[2], | ||
y1: minLinePos[1], | ||
y2: minLinePos[3] | ||
}))), | ||
}, minProps)), | ||
container && _react2.default.createElement('rect', _extends({ | ||
x: containerPos[0], | ||
y: containerPos[1], | ||
width: containerPos[2], | ||
height: containerPos[3], | ||
x: boxplot.container.x1, | ||
y: boxplot.container.y1, | ||
width: boxplot.container.x2, | ||
height: boxplot.container.y2, | ||
fillOpacity: '0' | ||
}, (0, _additionalProps2.default)(containerProps, { | ||
data: data, | ||
x1: containerPos[0], | ||
x2: containerPos[0] + containerPos[2], | ||
y1: containerPos[1], | ||
y2: containerPos[1] + containerPos[3], | ||
median: median, | ||
max: max, | ||
min: min, | ||
thirdQuartile: thirdQuartile, | ||
firstQuartile: firstQuartile | ||
}))) | ||
}, containerProps)) | ||
); | ||
} |
@@ -19,4 +19,6 @@ 'use strict'; | ||
var _group = require('@vx/group'); | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _scale = require('@vx/scale'); | ||
@@ -26,6 +28,2 @@ | ||
var _additionalProps = require('../util/additionalProps'); | ||
var _additionalProps2 = _interopRequireDefault(_additionalProps); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -37,2 +35,15 @@ | ||
ViolinPlot.propTypes = { | ||
left: _propTypes2.default.number, | ||
top: _propTypes2.default.number, | ||
className: _propTypes2.default.string, | ||
data: _propTypes2.default.array.isRequired, | ||
width: _propTypes2.default.number, | ||
count: _propTypes2.default.func, | ||
value: _propTypes2.default.func, | ||
valueScale: _propTypes2.default.func, | ||
horizontal: _propTypes2.default.bool, | ||
children: _propTypes2.default.func | ||
}; | ||
function ViolinPlot(_ref) { | ||
@@ -44,17 +55,19 @@ var _ref$left = _ref.left, | ||
className = _ref.className, | ||
binData = _ref.binData, | ||
_ref$stroke = _ref.stroke, | ||
stroke = _ref$stroke === undefined ? 'black' : _ref$stroke, | ||
_ref$fill = _ref.fill, | ||
fill = _ref$fill === undefined ? 'rgba(0,0,0,0.3)' : _ref$fill, | ||
opacity = _ref.opacity, | ||
strokeWidth = _ref.strokeWidth, | ||
data = _ref.data, | ||
width = _ref.width, | ||
_ref$count = _ref.count, | ||
count = _ref$count === undefined ? function (d) { | ||
return d.count; | ||
} : _ref$count, | ||
_ref$value = _ref.value, | ||
value = _ref$value === undefined ? function (d) { | ||
return d.value; | ||
} : _ref$value, | ||
valueScale = _ref.valueScale, | ||
strokeDasharray = _ref.strokeDasharray, | ||
horizontal = _ref.horizontal, | ||
restProps = _objectWithoutProperties(_ref, ['left', 'top', 'className', 'binData', 'stroke', 'fill', 'opacity', 'strokeWidth', 'width', 'valueScale', 'strokeDasharray', 'horizontal']); | ||
children = _ref.children, | ||
restProps = _objectWithoutProperties(_ref, ['left', 'top', 'className', 'data', 'width', 'count', 'value', 'valueScale', 'horizontal', 'children']); | ||
var center = (horizontal ? top : left) + width / 2; | ||
var binCounts = binData.map(function (bin) { | ||
var binCounts = data.map(function (bin) { | ||
return bin.count; | ||
@@ -68,47 +81,38 @@ }); | ||
var path = ''; | ||
if (horizontal) { | ||
var topCurve = (0, _d3Shape.line)().x(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).y(function (d) { | ||
return center - widthScale(d.count); | ||
return center - widthScale(count(d)); | ||
}).curve(_d3Shape.curveCardinal); | ||
var bottomCurve = (0, _d3Shape.line)().x(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).y(function (d) { | ||
return center + widthScale(d.count); | ||
return center + widthScale(count(d)); | ||
}).curve(_d3Shape.curveCardinal); | ||
var topCurvePath = topCurve(binData); | ||
var bottomCurvePath = bottomCurve([].concat(_toConsumableArray(binData)).reverse()); | ||
var topCurvePath = topCurve(data); | ||
var bottomCurvePath = bottomCurve([].concat(_toConsumableArray(data)).reverse()); | ||
path = topCurvePath + ' ' + bottomCurvePath.replace('M', 'L') + ' Z'; | ||
} else { | ||
var rightCurve = (0, _d3Shape.line)().x(function (d) { | ||
return center + widthScale(d.count); | ||
return center + widthScale(count(d)); | ||
}).y(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).curve(_d3Shape.curveCardinal); | ||
var leftCurve = (0, _d3Shape.line)().x(function (d) { | ||
return center - widthScale(d.count); | ||
return center - widthScale(count(d)); | ||
}).y(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).curve(_d3Shape.curveCardinal); | ||
var rightCurvePath = rightCurve(binData); | ||
var leftCurvePath = leftCurve([].concat(_toConsumableArray(binData)).reverse()); | ||
var rightCurvePath = rightCurve(data); | ||
var leftCurvePath = leftCurve([].concat(_toConsumableArray(data)).reverse()); | ||
path = rightCurvePath + ' ' + leftCurvePath.replace('M', 'L') + ' Z'; | ||
} | ||
return _react2.default.createElement( | ||
_group.Group, | ||
{ className: (0, _classnames2.default)('vx-violin', className) }, | ||
_react2.default.createElement('path', _extends({ | ||
d: path, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth, | ||
strokeDasharray: strokeDasharray, | ||
fill: fill, | ||
fillOpacity: opacity | ||
}, (0, _additionalProps2.default)(restProps, binData))) | ||
); | ||
if (children) return children({ path: path }); | ||
return _react2.default.createElement('path', _extends({ className: (0, _classnames2.default)('vx-violin', className), d: path }, restProps)); | ||
} |
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import { Group } from '@vx/group'; | ||
@@ -7,16 +8,2 @@ import { scaleLinear } from '@vx/scale'; | ||
function callOrValue(maybeFn, data) { | ||
if (typeof maybeFn === 'function') { | ||
return maybeFn(data); | ||
} | ||
return maybeFn; | ||
} | ||
function additionalProps(restProps, data) { | ||
return Object.keys(restProps).reduce(function (ret, cur) { | ||
ret[cur] = callOrValue(restProps[cur], data); | ||
return ret; | ||
}, {}); | ||
} | ||
var _extends = Object.assign || function (target) { | ||
@@ -48,40 +35,2 @@ for (var i = 1; i < arguments.length; i++) { | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
@@ -98,110 +47,151 @@ if (Array.isArray(arr)) { | ||
function verticalToHorizontal(_ref) { | ||
var _ref2 = slicedToArray(_ref, 4), | ||
x1 = _ref2[0], | ||
y1 = _ref2[1], | ||
x2 = _ref2[2], | ||
y2 = _ref2[3]; | ||
var x1 = _ref.x1, | ||
x2 = _ref.x2, | ||
y1 = _ref.y1, | ||
y2 = _ref.y2; | ||
return [y1, x1, y2, x2]; | ||
return { | ||
x1: y1, | ||
x2: y2, | ||
y1: x1, | ||
y2: x2 | ||
}; | ||
} | ||
function BoxPlot(_ref3) { | ||
var _ref3$left = _ref3.left, | ||
left = _ref3$left === undefined ? 0 : _ref3$left, | ||
_ref3$top = _ref3.top, | ||
top = _ref3$top === undefined ? 0 : _ref3$top, | ||
className = _ref3.className, | ||
data = _ref3.data, | ||
max = _ref3.max, | ||
min = _ref3.min, | ||
firstQuartile = _ref3.firstQuartile, | ||
thirdQuartile = _ref3.thirdQuartile, | ||
median = _ref3.median, | ||
boxWidth = _ref3.boxWidth, | ||
fill = _ref3.fill, | ||
fillOpacity = _ref3.fillOpacity, | ||
stroke = _ref3.stroke, | ||
strokeWidth = _ref3.strokeWidth, | ||
_ref3$rx = _ref3.rx, | ||
rx = _ref3$rx === undefined ? 2 : _ref3$rx, | ||
_ref3$ry = _ref3.ry, | ||
ry = _ref3$ry === undefined ? 2 : _ref3$ry, | ||
valueScale = _ref3.valueScale, | ||
outliers = _ref3.outliers, | ||
horizontal = _ref3.horizontal, | ||
_ref3$medianProps = _ref3.medianProps, | ||
medianProps = _ref3$medianProps === undefined ? {} : _ref3$medianProps, | ||
_ref3$maxProps = _ref3.maxProps, | ||
maxProps = _ref3$maxProps === undefined ? {} : _ref3$maxProps, | ||
_ref3$minProps = _ref3.minProps, | ||
minProps = _ref3$minProps === undefined ? {} : _ref3$minProps, | ||
_ref3$boxProps = _ref3.boxProps, | ||
boxProps = _ref3$boxProps === undefined ? {} : _ref3$boxProps, | ||
_ref3$outlierProps = _ref3.outlierProps, | ||
outlierProps = _ref3$outlierProps === undefined ? {} : _ref3$outlierProps, | ||
_ref3$container = _ref3.container, | ||
container = _ref3$container === undefined ? false : _ref3$container, | ||
_ref3$containerProps = _ref3.containerProps, | ||
containerProps = _ref3$containerProps === undefined ? {} : _ref3$containerProps, | ||
restProps = objectWithoutProperties(_ref3, ['left', 'top', 'className', 'data', 'max', 'min', 'firstQuartile', 'thirdQuartile', 'median', 'boxWidth', 'fill', 'fillOpacity', 'stroke', 'strokeWidth', 'rx', 'ry', 'valueScale', 'outliers', 'horizontal', 'medianProps', 'maxProps', 'minProps', 'boxProps', 'outlierProps', 'container', 'containerProps']); | ||
BoxPlot.propTypes = { | ||
left: PropTypes.number, | ||
top: PropTypes.number, | ||
className: PropTypes.string, | ||
max: PropTypes.number, | ||
min: PropTypes.number, | ||
firstQuartile: PropTypes.number, | ||
thirdQuartile: PropTypes.number, | ||
median: PropTypes.number, | ||
boxWidth: PropTypes.number, | ||
fill: PropTypes.string, | ||
fillOpacity: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
stroke: PropTypes.string, | ||
strokeWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
rx: PropTypes.number, | ||
ry: PropTypes.number, | ||
valueScale: PropTypes.func, | ||
outliers: PropTypes.array, | ||
horizontal: PropTypes.bool, | ||
medianProps: PropTypes.object, | ||
maxProps: PropTypes.object, | ||
minProps: PropTypes.object, | ||
boxProps: PropTypes.object, | ||
outlierProps: PropTypes.object, | ||
container: PropTypes.bool, | ||
containerProps: PropTypes.object, | ||
children: PropTypes.func | ||
}; | ||
function BoxPlot(_ref2) { | ||
var _ref2$left = _ref2.left, | ||
left = _ref2$left === undefined ? 0 : _ref2$left, | ||
_ref2$top = _ref2.top, | ||
top = _ref2$top === undefined ? 0 : _ref2$top, | ||
className = _ref2.className, | ||
max = _ref2.max, | ||
min = _ref2.min, | ||
firstQuartile = _ref2.firstQuartile, | ||
thirdQuartile = _ref2.thirdQuartile, | ||
median = _ref2.median, | ||
boxWidth = _ref2.boxWidth, | ||
fill = _ref2.fill, | ||
fillOpacity = _ref2.fillOpacity, | ||
stroke = _ref2.stroke, | ||
strokeWidth = _ref2.strokeWidth, | ||
_ref2$rx = _ref2.rx, | ||
rx = _ref2$rx === undefined ? 2 : _ref2$rx, | ||
_ref2$ry = _ref2.ry, | ||
ry = _ref2$ry === undefined ? 2 : _ref2$ry, | ||
valueScale = _ref2.valueScale, | ||
_ref2$outliers = _ref2.outliers, | ||
outliers = _ref2$outliers === undefined ? [] : _ref2$outliers, | ||
horizontal = _ref2.horizontal, | ||
_ref2$medianProps = _ref2.medianProps, | ||
medianProps = _ref2$medianProps === undefined ? {} : _ref2$medianProps, | ||
_ref2$maxProps = _ref2.maxProps, | ||
maxProps = _ref2$maxProps === undefined ? {} : _ref2$maxProps, | ||
_ref2$minProps = _ref2.minProps, | ||
minProps = _ref2$minProps === undefined ? {} : _ref2$minProps, | ||
_ref2$boxProps = _ref2.boxProps, | ||
boxProps = _ref2$boxProps === undefined ? {} : _ref2$boxProps, | ||
_ref2$outlierProps = _ref2.outlierProps, | ||
outlierProps = _ref2$outlierProps === undefined ? {} : _ref2$outlierProps, | ||
_ref2$container = _ref2.container, | ||
container = _ref2$container === undefined ? false : _ref2$container, | ||
_ref2$containerProps = _ref2.containerProps, | ||
containerProps = _ref2$containerProps === undefined ? {} : _ref2$containerProps, | ||
children = _ref2.children; | ||
var offset = horizontal ? top : left; | ||
var center = offset + boxWidth / 2; | ||
var valueRange = valueScale.range(); | ||
var maxLinePos = Array(4).fill(0); | ||
var maxToBoxLinePos = Array(4).fill(0); | ||
var boxPos = Array(4).fill(0); | ||
var medianLinePos = Array(4).fill(0); | ||
var minToBoxLinePos = Array(4).fill(0); | ||
var minLinePos = Array(4).fill(0); | ||
var containerPos = Array(4).fill(0); | ||
var boxplot = { | ||
valueRange: valueRange, | ||
center: center, | ||
offset: offset, | ||
boxWidth: boxWidth, | ||
max: { | ||
x1: center - boxWidth / 4, | ||
x2: center + boxWidth / 4, | ||
y1: valueScale(max), | ||
y2: valueScale(max) | ||
}, | ||
maxToThird: { | ||
x1: center, | ||
x2: center, | ||
y1: valueScale(max), | ||
y2: valueScale(thirdQuartile) | ||
}, | ||
median: { | ||
x1: offset, | ||
x2: offset + boxWidth, | ||
y1: valueScale(median), | ||
y2: valueScale(median) | ||
}, | ||
minToFirst: { | ||
x1: center, | ||
x2: center, | ||
y1: valueScale(firstQuartile), | ||
y2: valueScale(min) | ||
}, | ||
min: { | ||
x1: center - boxWidth / 4, | ||
x2: center + boxWidth / 4, | ||
y1: valueScale(min), | ||
y2: valueScale(min) | ||
}, | ||
box: { | ||
x1: offset, | ||
x2: boxWidth, | ||
y1: valueScale(thirdQuartile), | ||
y2: Math.abs(valueScale(thirdQuartile) - valueScale(firstQuartile)) | ||
}, | ||
container: { | ||
x1: offset, | ||
x2: boxWidth, | ||
y1: Math.min.apply(Math, toConsumableArray(valueRange)), | ||
y2: Math.abs(valueRange[0] - valueRange[1]) | ||
} | ||
}; | ||
// all of these are [x0, y0, x1, y1] | ||
maxLinePos[0] = center - boxWidth / 4; | ||
maxLinePos[1] = valueScale(max); | ||
maxLinePos[2] = center + boxWidth / 4; | ||
maxLinePos[3] = valueScale(max); | ||
if (horizontal) { | ||
boxplot.max = verticalToHorizontal(boxplot.max); | ||
boxplot.maxToThird = verticalToHorizontal(boxplot.maxToThird); | ||
boxplot.box = verticalToHorizontal(boxplot.box); | ||
boxplot.box.y1 = valueScale(firstQuartile); | ||
boxplot.median = verticalToHorizontal(boxplot.median); | ||
boxplot.minToFirst = verticalToHorizontal(boxplot.minToFirst); | ||
boxplot.min = verticalToHorizontal(boxplot.min); | ||
boxplot.container = verticalToHorizontal(boxplot.container); | ||
boxplot.container.y1 = Math.min.apply(Math, toConsumableArray(valueRange)); | ||
} | ||
maxToBoxLinePos[0] = center; | ||
maxToBoxLinePos[1] = valueScale(max); | ||
maxToBoxLinePos[2] = center; | ||
maxToBoxLinePos[3] = valueScale(thirdQuartile); | ||
if (children) return children(boxplot); | ||
boxPos[0] = offset; | ||
boxPos[1] = valueScale(thirdQuartile); | ||
boxPos[2] = boxWidth; | ||
boxPos[3] = Math.abs(valueScale(thirdQuartile) - valueScale(firstQuartile)); | ||
medianLinePos[0] = offset; | ||
medianLinePos[1] = valueScale(median); | ||
medianLinePos[2] = offset + boxWidth; | ||
medianLinePos[3] = valueScale(median); | ||
minToBoxLinePos[0] = center; | ||
minToBoxLinePos[1] = valueScale(firstQuartile); | ||
minToBoxLinePos[2] = center; | ||
minToBoxLinePos[3] = valueScale(min); | ||
minLinePos[0] = center - boxWidth / 4; | ||
minLinePos[1] = valueScale(min); | ||
minLinePos[2] = center + boxWidth / 4; | ||
minLinePos[3] = valueScale(min); | ||
var valueRange = valueScale.range(); | ||
containerPos[0] = boxPos[0]; | ||
containerPos[1] = Math.min.apply(Math, toConsumableArray(valueRange)); | ||
containerPos[2] = boxPos[2]; | ||
containerPos[3] = Math.abs(valueRange[0] - valueRange[1]); | ||
if (horizontal) { | ||
maxLinePos = verticalToHorizontal(maxLinePos); | ||
maxToBoxLinePos = verticalToHorizontal(maxToBoxLinePos); | ||
boxPos = verticalToHorizontal(boxPos); | ||
boxPos[0] = valueScale(firstQuartile); | ||
medianLinePos = verticalToHorizontal(medianLinePos); | ||
minToBoxLinePos = verticalToHorizontal(minToBoxLinePos); | ||
minLinePos = verticalToHorizontal(minLinePos); | ||
containerPos = verticalToHorizontal(containerPos); | ||
containerPos[0] = Math.min.apply(Math, toConsumableArray(valueRange)); | ||
} | ||
return React.createElement( | ||
@@ -214,38 +204,28 @@ Group, | ||
return React.createElement('circle', _extends({ | ||
key: i, | ||
key: 'vx-boxplot-outlier-' + i, | ||
className: 'vx-boxplot-outlier', | ||
cx: cx, | ||
cy: cy, | ||
r: 4, | ||
stroke: stroke, | ||
strokeWidth: 1, | ||
strokeWidth: strokeWidth, | ||
fill: fill, | ||
fillOpacity: fillOpacity, | ||
r: '4' | ||
}, additionalProps(outlierProps, { | ||
data: d, | ||
cx: cx, | ||
cy: cy | ||
}))); | ||
fillOpacity: fillOpacity | ||
}, outlierProps)); | ||
}), | ||
React.createElement('line', _extends({ | ||
className: 'vx-boxplot-max', | ||
x1: maxLinePos[0], | ||
y1: maxLinePos[1], | ||
x2: maxLinePos[2], | ||
y2: maxLinePos[3], | ||
x1: boxplot.max.x1, | ||
y1: boxplot.max.y1, | ||
x2: boxplot.max.x2, | ||
y2: boxplot.max.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, additionalProps(maxProps, { | ||
data: data, | ||
max: max, | ||
x1: maxLinePos[0], | ||
x2: maxLinePos[2], | ||
y1: maxLinePos[1], | ||
y2: maxLinePos[3] | ||
}))), | ||
}, maxProps)), | ||
React.createElement('line', { | ||
x1: maxToBoxLinePos[0], | ||
y1: maxToBoxLinePos[1], | ||
x2: maxToBoxLinePos[2], | ||
y2: maxToBoxLinePos[3], | ||
className: 'vx-boxplot-max-to-third', | ||
x1: boxplot.maxToThird.x1, | ||
y1: boxplot.maxToThird.y1, | ||
x2: boxplot.maxToThird.x2, | ||
y2: boxplot.maxToThird.y2, | ||
stroke: stroke, | ||
@@ -256,6 +236,6 @@ strokeWidth: strokeWidth | ||
className: 'vx-boxplot-box', | ||
x: boxPos[0], | ||
y: boxPos[1], | ||
width: boxPos[2], | ||
height: boxPos[3], | ||
x: boxplot.box.x1, | ||
y: boxplot.box.y1, | ||
width: boxplot.box.x2, | ||
height: boxplot.box.y2, | ||
stroke: stroke, | ||
@@ -267,36 +247,18 @@ strokeWidth: strokeWidth, | ||
ry: ry | ||
}, additionalProps(boxProps, { | ||
data: data, | ||
height: boxPos[3], | ||
median: median, | ||
firstQuartile: firstQuartile, | ||
thirdQuartile: thirdQuartile, | ||
min: min, | ||
max: max, | ||
x1: boxPos[0], | ||
x2: boxPos[0] + boxPos[2], | ||
y1: boxPos[1], | ||
y2: boxPos[1] + boxPos[3] | ||
}))), | ||
}, boxProps)), | ||
React.createElement('line', _extends({ | ||
className: 'vx-boxplot-median', | ||
x1: medianLinePos[0], | ||
y1: medianLinePos[1], | ||
x2: medianLinePos[2], | ||
y2: medianLinePos[3], | ||
x1: boxplot.median.x1, | ||
y1: boxplot.median.y1, | ||
x2: boxplot.median.x2, | ||
y2: boxplot.median.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, additionalProps(medianProps, { | ||
data: data, | ||
median: median, | ||
x1: medianLinePos[0], | ||
x2: medianLinePos[2], | ||
y1: medianLinePos[1], | ||
y2: medianLinePos[3] | ||
}))), | ||
}, medianProps)), | ||
React.createElement('line', { | ||
x1: minToBoxLinePos[0], | ||
y1: minToBoxLinePos[1], | ||
x2: minToBoxLinePos[2], | ||
y2: minToBoxLinePos[3], | ||
className: 'vx-boxplot-min-to-first', | ||
x1: boxplot.minToFirst.x1, | ||
y1: boxplot.minToFirst.y1, | ||
x2: boxplot.minToFirst.x2, | ||
y2: boxplot.minToFirst.y2, | ||
stroke: stroke, | ||
@@ -307,37 +269,32 @@ strokeWidth: strokeWidth | ||
className: 'vx-boxplot-min', | ||
x1: minLinePos[0], | ||
y1: minLinePos[1], | ||
x2: minLinePos[2], | ||
y2: minLinePos[3], | ||
x1: boxplot.min.x1, | ||
y1: boxplot.min.y1, | ||
x2: boxplot.min.x2, | ||
y2: boxplot.min.y2, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth | ||
}, additionalProps(minProps, { | ||
data: data, | ||
min: min, | ||
x1: minLinePos[0], | ||
x2: minLinePos[2], | ||
y1: minLinePos[1], | ||
y2: minLinePos[3] | ||
}))), | ||
}, minProps)), | ||
container && React.createElement('rect', _extends({ | ||
x: containerPos[0], | ||
y: containerPos[1], | ||
width: containerPos[2], | ||
height: containerPos[3], | ||
x: boxplot.container.x1, | ||
y: boxplot.container.y1, | ||
width: boxplot.container.x2, | ||
height: boxplot.container.y2, | ||
fillOpacity: '0' | ||
}, additionalProps(containerProps, { | ||
data: data, | ||
x1: containerPos[0], | ||
x2: containerPos[0] + containerPos[2], | ||
y1: containerPos[1], | ||
y2: containerPos[1] + containerPos[3], | ||
median: median, | ||
max: max, | ||
min: min, | ||
thirdQuartile: thirdQuartile, | ||
firstQuartile: firstQuartile | ||
}))) | ||
}, containerProps)) | ||
); | ||
} | ||
ViolinPlot.propTypes = { | ||
left: PropTypes.number, | ||
top: PropTypes.number, | ||
className: PropTypes.string, | ||
data: PropTypes.array.isRequired, | ||
width: PropTypes.number, | ||
count: PropTypes.func, | ||
value: PropTypes.func, | ||
valueScale: PropTypes.func, | ||
horizontal: PropTypes.bool, | ||
children: PropTypes.func | ||
}; | ||
function ViolinPlot(_ref) { | ||
@@ -349,17 +306,19 @@ var _ref$left = _ref.left, | ||
className = _ref.className, | ||
binData = _ref.binData, | ||
_ref$stroke = _ref.stroke, | ||
stroke = _ref$stroke === undefined ? 'black' : _ref$stroke, | ||
_ref$fill = _ref.fill, | ||
fill = _ref$fill === undefined ? 'rgba(0,0,0,0.3)' : _ref$fill, | ||
opacity = _ref.opacity, | ||
strokeWidth = _ref.strokeWidth, | ||
data = _ref.data, | ||
width = _ref.width, | ||
_ref$count = _ref.count, | ||
count = _ref$count === undefined ? function (d) { | ||
return d.count; | ||
} : _ref$count, | ||
_ref$value = _ref.value, | ||
value = _ref$value === undefined ? function (d) { | ||
return d.value; | ||
} : _ref$value, | ||
valueScale = _ref.valueScale, | ||
strokeDasharray = _ref.strokeDasharray, | ||
horizontal = _ref.horizontal, | ||
restProps = objectWithoutProperties(_ref, ['left', 'top', 'className', 'binData', 'stroke', 'fill', 'opacity', 'strokeWidth', 'width', 'valueScale', 'strokeDasharray', 'horizontal']); | ||
children = _ref.children, | ||
restProps = objectWithoutProperties(_ref, ['left', 'top', 'className', 'data', 'width', 'count', 'value', 'valueScale', 'horizontal', 'children']); | ||
var center = (horizontal ? top : left) + width / 2; | ||
var binCounts = binData.map(function (bin) { | ||
var binCounts = data.map(function (bin) { | ||
return bin.count; | ||
@@ -373,47 +332,38 @@ }); | ||
var path = ''; | ||
if (horizontal) { | ||
var topCurve = line().x(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).y(function (d) { | ||
return center - widthScale(d.count); | ||
return center - widthScale(count(d)); | ||
}).curve(curveCardinal); | ||
var bottomCurve = line().x(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).y(function (d) { | ||
return center + widthScale(d.count); | ||
return center + widthScale(count(d)); | ||
}).curve(curveCardinal); | ||
var topCurvePath = topCurve(binData); | ||
var bottomCurvePath = bottomCurve([].concat(toConsumableArray(binData)).reverse()); | ||
var topCurvePath = topCurve(data); | ||
var bottomCurvePath = bottomCurve([].concat(toConsumableArray(data)).reverse()); | ||
path = topCurvePath + ' ' + bottomCurvePath.replace('M', 'L') + ' Z'; | ||
} else { | ||
var rightCurve = line().x(function (d) { | ||
return center + widthScale(d.count); | ||
return center + widthScale(count(d)); | ||
}).y(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).curve(curveCardinal); | ||
var leftCurve = line().x(function (d) { | ||
return center - widthScale(d.count); | ||
return center - widthScale(count(d)); | ||
}).y(function (d) { | ||
return valueScale(d.value); | ||
return valueScale(value(d)); | ||
}).curve(curveCardinal); | ||
var rightCurvePath = rightCurve(binData); | ||
var leftCurvePath = leftCurve([].concat(toConsumableArray(binData)).reverse()); | ||
var rightCurvePath = rightCurve(data); | ||
var leftCurvePath = leftCurve([].concat(toConsumableArray(data)).reverse()); | ||
path = rightCurvePath + ' ' + leftCurvePath.replace('M', 'L') + ' Z'; | ||
} | ||
return React.createElement( | ||
Group, | ||
{ className: classnames('vx-violin', className) }, | ||
React.createElement('path', _extends({ | ||
d: path, | ||
stroke: stroke, | ||
strokeWidth: strokeWidth, | ||
strokeDasharray: strokeDasharray, | ||
fill: fill, | ||
fillOpacity: opacity | ||
}, additionalProps(restProps, binData))) | ||
); | ||
if (children) return children({ path: path }); | ||
return React.createElement('path', _extends({ className: classnames('vx-violin', className), d: path }, restProps)); | ||
} | ||
@@ -420,0 +370,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("classnames"),require("@vx/group"),require("@vx/scale"),require("d3-shape")):"function"==typeof define&&define.amd?define(["exports","react","classnames","@vx/group","@vx/scale","d3-shape"],t):t(r.vx=r.vx||{},r.React,r.classNames,r.vx,r.vx,r.d3)}(this,function(r,J,K,U,W,E){"use strict";function X(i,n){return Object.keys(i).reduce(function(r,t){var e,a;return r[t]=(e=i[t],a=n,"function"==typeof e?e(a):e),r},{})}J=J&&J.hasOwnProperty("default")?J.default:J,K=K&&K.hasOwnProperty("default")?K.default:K;var Y=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(r[a]=e[a])}return r},$=function(r,t){var e={};for(var a in r)0<=t.indexOf(a)||Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},n=function(r,t){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return function(r,t){var e=[],a=!0,i=!1,n=void 0;try{for(var o,l=r[Symbol.iterator]();!(a=(o=l.next()).done)&&(e.push(o.value),!t||e.length!==t);a=!0);}catch(r){i=!0,n=r}finally{try{!a&&l.return&&l.return()}finally{if(i)throw n}}return e}(r,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},rr=function(r){if(Array.isArray(r)){for(var t=0,e=Array(r.length);t<r.length;t++)e[t]=r[t];return e}return Array.from(r)};function tr(r){var t=n(r,4),e=t[0],a=t[1],i=t[2];return[a,e,t[3],i]}r.BoxPlot=function(r){var t=r.left,e=void 0===t?0:t,a=r.top,i=void 0===a?0:a,n=r.className,o=r.data,l=r.max,u=r.min,c=r.firstQuartile,s=r.thirdQuartile,f=r.median,d=r.boxWidth,y=r.fill,x=r.fillOpacity,v=r.stroke,h=r.strokeWidth,p=r.rx,m=void 0===p?2:p,k=r.ry,b=void 0===k?2:k,P=r.valueScale,M=r.outliers,O=r.horizontal,g=r.medianProps,A=void 0===g?{}:g,W=r.maxProps,E=void 0===W?{}:W,w=r.minProps,N=void 0===w?{}:w,Q=r.boxProps,j=void 0===Q?{}:Q,S=r.outlierProps,D=void 0===S?{}:S,q=r.container,z=void 0!==q&&q,C=r.containerProps,L=void 0===C?{}:C,G=($(r,["left","top","className","data","max","min","firstQuartile","thirdQuartile","median","boxWidth","fill","fillOpacity","stroke","strokeWidth","rx","ry","valueScale","outliers","horizontal","medianProps","maxProps","minProps","boxProps","outlierProps","container","containerProps"]),O?i:e),R=G+d/2,Z=Array(4).fill(0),_=Array(4).fill(0),B=Array(4).fill(0),I=Array(4).fill(0),T=Array(4).fill(0),V=Array(4).fill(0),F=Array(4).fill(0);Z[0]=R-d/4,Z[1]=P(l),Z[2]=R+d/4,Z[3]=P(l),_[0]=R,_[1]=P(l),_[2]=R,_[3]=P(s),B[0]=G,B[1]=P(s),B[2]=d,B[3]=Math.abs(P(s)-P(c)),I[0]=G,I[1]=P(f),I[2]=G+d,I[3]=P(f),T[0]=R,T[1]=P(c),T[2]=R,T[3]=P(u),V[0]=R-d/4,V[1]=P(u),V[2]=R+d/4,V[3]=P(u);var H=P.range();return F[0]=B[0],F[1]=Math.min.apply(Math,rr(H)),F[2]=B[2],F[3]=Math.abs(H[0]-H[1]),O&&(Z=tr(Z),_=tr(_),(B=tr(B))[0]=P(c),I=tr(I),T=tr(T),V=tr(V),(F=tr(F))[0]=Math.min.apply(Math,rr(H))),J.createElement(U.Group,{className:K("vx-boxplot",n)},M.map(function(r,t){var e=O?P(r):R,a=O?R:P(r);return J.createElement("circle",Y({key:t,className:"vx-boxplot-outlier",cx:e,cy:a,stroke:v,strokeWidth:1,fill:y,fillOpacity:x,r:"4"},X(D,{data:r,cx:e,cy:a})))}),J.createElement("line",Y({className:"vx-boxplot-max",x1:Z[0],y1:Z[1],x2:Z[2],y2:Z[3],stroke:v,strokeWidth:h},X(E,{data:o,max:l,x1:Z[0],x2:Z[2],y1:Z[1],y2:Z[3]}))),J.createElement("line",{x1:_[0],y1:_[1],x2:_[2],y2:_[3],stroke:v,strokeWidth:h}),J.createElement("rect",Y({className:"vx-boxplot-box",x:B[0],y:B[1],width:B[2],height:B[3],stroke:v,strokeWidth:h,fill:y,fillOpacity:x,rx:m,ry:b},X(j,{data:o,height:B[3],median:f,firstQuartile:c,thirdQuartile:s,min:u,max:l,x1:B[0],x2:B[0]+B[2],y1:B[1],y2:B[1]+B[3]}))),J.createElement("line",Y({className:"vx-boxplot-median",x1:I[0],y1:I[1],x2:I[2],y2:I[3],stroke:v,strokeWidth:h},X(A,{data:o,median:f,x1:I[0],x2:I[2],y1:I[1],y2:I[3]}))),J.createElement("line",{x1:T[0],y1:T[1],x2:T[2],y2:T[3],stroke:v,strokeWidth:h}),J.createElement("line",Y({className:"vx-boxplot-min",x1:V[0],y1:V[1],x2:V[2],y2:V[3],stroke:v,strokeWidth:h},X(N,{data:o,min:u,x1:V[0],x2:V[2],y1:V[1],y2:V[3]}))),z&&J.createElement("rect",Y({x:F[0],y:F[1],width:F[2],height:F[3],fillOpacity:"0"},X(L,{data:o,x1:F[0],x2:F[0]+F[2],y1:F[1],y2:F[1]+F[3],median:f,max:l,min:u,thirdQuartile:s,firstQuartile:c}))))},r.ViolinPlot=function(r){var t=r.left,e=void 0===t?0:t,a=r.top,i=void 0===a?0:a,n=r.className,o=r.binData,l=r.stroke,u=void 0===l?"black":l,c=r.fill,s=void 0===c?"rgba(0,0,0,0.3)":c,f=r.opacity,d=r.strokeWidth,y=r.width,x=r.valueScale,v=r.strokeDasharray,h=r.horizontal,p=$(r,["left","top","className","binData","stroke","fill","opacity","strokeWidth","width","valueScale","strokeDasharray","horizontal"]),m=(h?i:e)+y/2,k=o.map(function(r){return r.count}),b=W.scaleLinear({rangeRound:[0,y/2],domain:[0,Math.max.apply(Math,rr(k))]}),P="";if(h){var M=E.line().x(function(r){return x(r.value)}).y(function(r){return m-b(r.count)}).curve(E.curveCardinal),O=E.line().x(function(r){return x(r.value)}).y(function(r){return m+b(r.count)}).curve(E.curveCardinal);P=M(o)+" "+O([].concat(rr(o)).reverse()).replace("M","L")+" Z"}else{var g=E.line().x(function(r){return m+b(r.count)}).y(function(r){return x(r.value)}).curve(E.curveCardinal),A=E.line().x(function(r){return m-b(r.count)}).y(function(r){return x(r.value)}).curve(E.curveCardinal);P=g(o)+" "+A([].concat(rr(o)).reverse()).replace("M","L")+" Z"}return J.createElement(U.Group,{className:K("vx-violin",n)},J.createElement("path",Y({d:P,stroke:u,strokeWidth:d,strokeDasharray:v,fill:s,fillOpacity:f},X(p,o))))},r.computeStats=function(r){for(var t=[].concat(rr(r)).sort(function(r,t){return r-t}),e=t.length,a=t[Math.round(e/4)],i=t[Math.round(3*e/4)],n=i-a,o=a-1.5*n,l=i+1.5*n,u=t.filter(function(r){return r<o||l<r}),c=2*n*Math.pow(e-u.length,-1/3),s=Math.round((l-o)/c),f=(l-o)/s,d=Array(s+2).fill(0),y=Array(s+2).fill(o),x=1;x<=s;x+=1)y[x]+=f*(x-.5);y[y.length-1]=l,t.filter(function(r){return o<=r&&r<=l}).forEach(function(r){d[Math.floor((r-o)/f)+1]+=1});var v=y.map(function(r,t){return{value:r,count:d[t]}});return{boxPlot:{min:o,firstQuartile:a,median:t[Math.round(e/2)],thirdQuartile:i,max:l,outliers:u},binData:v}},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("classnames"),require("prop-types"),require("@vx/group"),require("@vx/scale"),require("d3-shape")):"function"==typeof define&&define.amd?define(["exports","react","classnames","prop-types","@vx/group","@vx/scale","d3-shape"],r):r(e.vx=e.vx||{},e.React,e.classNames,e.PropTypes,e.vx,e.vx,e.d3)}(this,function(e,D,G,r,V,M,O){"use strict";D=D&&D.hasOwnProperty("default")?D.default:D,G=G&&G.hasOwnProperty("default")?G.default:G,r=r&&r.hasOwnProperty("default")?r.default:r;var H=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},I=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)};function J(e){var r=e.x1,t=e.x2;return{x1:e.y1,x2:e.y2,y1:r,y2:t}}function t(e){var r=e.left,t=void 0===r?0:r,n=e.top,o=void 0===n?0:n,a=e.className,i=e.max,l=e.min,c=e.firstQuartile,u=e.thirdQuartile,s=e.median,x=e.boxWidth,m=e.fill,d=e.fillOpacity,y=e.stroke,f=e.strokeWidth,p=e.rx,h=void 0===p?2:p,v=e.ry,b=void 0===v?2:v,T=e.valueScale,P=e.outliers,g=void 0===P?[]:P,k=e.horizontal,M=e.medianProps,O=void 0===M?{}:M,N=e.maxProps,W=void 0===N?{}:N,j=e.minProps,w=void 0===j?{}:j,E=e.boxProps,q=void 0===E?{}:E,F=e.outlierProps,A=void 0===F?{}:F,Q=e.container,S=void 0!==Q&&Q,z=e.containerProps,C=void 0===z?{}:z,R=e.children,L=k?o:t,Z=L+x/2,_=T.range(),B={valueRange:_,center:Z,offset:L,boxWidth:x,max:{x1:Z-x/4,x2:Z+x/4,y1:T(i),y2:T(i)},maxToThird:{x1:Z,x2:Z,y1:T(i),y2:T(u)},median:{x1:L,x2:L+x,y1:T(s),y2:T(s)},minToFirst:{x1:Z,x2:Z,y1:T(c),y2:T(l)},min:{x1:Z-x/4,x2:Z+x/4,y1:T(l),y2:T(l)},box:{x1:L,x2:x,y1:T(u),y2:Math.abs(T(u)-T(c))},container:{x1:L,x2:x,y1:Math.min.apply(Math,I(_)),y2:Math.abs(_[0]-_[1])}};return k&&(B.max=J(B.max),B.maxToThird=J(B.maxToThird),B.box=J(B.box),B.box.y1=T(c),B.median=J(B.median),B.minToFirst=J(B.minToFirst),B.min=J(B.min),B.container=J(B.container),B.container.y1=Math.min.apply(Math,I(_))),R?R(B):D.createElement(V.Group,{className:G("vx-boxplot",a)},g.map(function(e,r){var t=k?T(e):Z,n=k?Z:T(e);return D.createElement("circle",H({key:"vx-boxplot-outlier-"+r,className:"vx-boxplot-outlier",cx:t,cy:n,r:4,stroke:y,strokeWidth:f,fill:m,fillOpacity:d},A))}),D.createElement("line",H({className:"vx-boxplot-max",x1:B.max.x1,y1:B.max.y1,x2:B.max.x2,y2:B.max.y2,stroke:y,strokeWidth:f},W)),D.createElement("line",{className:"vx-boxplot-max-to-third",x1:B.maxToThird.x1,y1:B.maxToThird.y1,x2:B.maxToThird.x2,y2:B.maxToThird.y2,stroke:y,strokeWidth:f}),D.createElement("rect",H({className:"vx-boxplot-box",x:B.box.x1,y:B.box.y1,width:B.box.x2,height:B.box.y2,stroke:y,strokeWidth:f,fill:m,fillOpacity:d,rx:h,ry:b},q)),D.createElement("line",H({className:"vx-boxplot-median",x1:B.median.x1,y1:B.median.y1,x2:B.median.x2,y2:B.median.y2,stroke:y,strokeWidth:f},O)),D.createElement("line",{className:"vx-boxplot-min-to-first",x1:B.minToFirst.x1,y1:B.minToFirst.y1,x2:B.minToFirst.x2,y2:B.minToFirst.y2,stroke:y,strokeWidth:f}),D.createElement("line",H({className:"vx-boxplot-min",x1:B.min.x1,y1:B.min.y1,x2:B.min.x2,y2:B.min.y2,stroke:y,strokeWidth:f},w)),S&&D.createElement("rect",H({x:B.container.x1,y:B.container.y1,width:B.container.x2,height:B.container.y2,fillOpacity:"0"},C)))}function n(e){var r=e.left,t=void 0===r?0:r,n=e.top,o=void 0===n?0:n,a=e.className,i=e.data,l=e.width,c=e.count,u=void 0===c?function(e){return e.count}:c,s=e.value,x=void 0===s?function(e){return e.value}:s,m=e.valueScale,d=e.horizontal,y=e.children,f=function(e,r){var t={};for(var n in e)0<=r.indexOf(n)||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}(e,["left","top","className","data","width","count","value","valueScale","horizontal","children"]),p=(d?o:t)+l/2,h=i.map(function(e){return e.count}),v=M.scaleLinear({rangeRound:[0,l/2],domain:[0,Math.max.apply(Math,I(h))]}),b="";if(d){var T=O.line().x(function(e){return m(x(e))}).y(function(e){return p-v(u(e))}).curve(O.curveCardinal),P=O.line().x(function(e){return m(x(e))}).y(function(e){return p+v(u(e))}).curve(O.curveCardinal);b=T(i)+" "+P([].concat(I(i)).reverse()).replace("M","L")+" Z"}else{var g=O.line().x(function(e){return p+v(u(e))}).y(function(e){return m(x(e))}).curve(O.curveCardinal),k=O.line().x(function(e){return p-v(u(e))}).y(function(e){return m(x(e))}).curve(O.curveCardinal);b=g(i)+" "+k([].concat(I(i)).reverse()).replace("M","L")+" Z"}return y?y({path:b}):D.createElement("path",H({className:G("vx-violin",a),d:b},f))}t.propTypes={left:r.number,top:r.number,className:r.string,max:r.number,min:r.number,firstQuartile:r.number,thirdQuartile:r.number,median:r.number,boxWidth:r.number,fill:r.string,fillOpacity:r.oneOfType([r.number,r.string]),stroke:r.string,strokeWidth:r.oneOfType([r.number,r.string]),rx:r.number,ry:r.number,valueScale:r.func,outliers:r.array,horizontal:r.bool,medianProps:r.object,maxProps:r.object,minProps:r.object,boxProps:r.object,outlierProps:r.object,container:r.bool,containerProps:r.object,children:r.func},n.propTypes={left:r.number,top:r.number,className:r.string,data:r.array.isRequired,width:r.number,count:r.func,value:r.func,valueScale:r.func,horizontal:r.bool,children:r.func},e.BoxPlot=t,e.ViolinPlot=n,e.computeStats=function(e){for(var r=[].concat(I(e)).sort(function(e,r){return e-r}),t=r.length,n=r[Math.round(t/4)],o=r[Math.round(3*t/4)],a=o-n,i=n-1.5*a,l=o+1.5*a,c=r.filter(function(e){return e<i||l<e}),u=2*a*Math.pow(t-c.length,-1/3),s=Math.round((l-i)/u),x=(l-i)/s,m=Array(s+2).fill(0),d=Array(s+2).fill(i),y=1;y<=s;y+=1)d[y]+=x*(y-.5);d[d.length-1]=l,r.filter(function(e){return i<=e&&e<=l}).forEach(function(e){m[Math.floor((e-i)/x)+1]+=1});var f=d.map(function(e,r){return{value:e,count:m[r]}});return{boxPlot:{min:i,firstQuartile:n,median:r[Math.round(t/2)],thirdQuartile:o,max:l,outliers:c},binData:f}},Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@vx/stats", | ||
"version": "0.0.179", | ||
"version": "0.0.181", | ||
"description": "vx stats box violin", | ||
@@ -40,3 +40,4 @@ "sideEffects": false, | ||
"classnames": "^2.2.5", | ||
"d3-shape": "^1.2.0" | ||
"d3-shape": "^1.2.0", | ||
"prop-types": "^15.5.10" | ||
}, | ||
@@ -43,0 +44,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37886
6
8
811
1
+ Addedprop-types@^15.5.10