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

victory-stack

Package Overview
Dependencies
Maintainers
16
Versions
148
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

victory-stack - npm Package Compare versions

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

10

CHANGELOG.md
# victory-stack
## 36.9.2-next.0
## 36.9.2-next.1
### Patch Changes
- 7da790934: Replace lodash keys with native code
- Updated dependencies [7da790934]
- Updated dependencies [3f2da66e3]
- Updated dependencies [c13308624]
- Updated dependencies [7efd582cc]
- Updated dependencies [9cdaf2c08]
- Updated dependencies [f6f7cc515]
- Updated dependencies [6e34169a5]
- victory-core@36.9.2-next.0
- victory-shared-events@36.9.2-next.0
- victory-core@36.9.2-next.1
- victory-shared-events@36.9.2-next.1

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

import _orderBy from "lodash/orderBy";
import _keys from "lodash/keys";
/* eslint-disable no-use-before-define */
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }
import React from "react";
import { Helpers, Scale, Wrapper } from "victory-core";
import isEqual from "react-fast-compare";
const fallbackProps = {
var fallbackProps = {
width: 450,
height: 300,
padding: 50
};
}; // Assumes data in `datasets` is sorted by `Data.getData`.
// Assumes data in `datasets` is sorted by `Data.getData`.
function fillData(props, datasets) {
const {
fillInMissingData
} = props;
const xMap = datasets.reduce((prev, dataset) => {
dataset.forEach(datum => {
var fillInMissingData = props.fillInMissingData;
var xMap = datasets.reduce(function (prev, dataset) {
dataset.forEach(function (datum) {
prev[datum._x instanceof Date ? datum._x.getTime() : datum._x] = true;

@@ -24,30 +38,40 @@ });

}, {});
const xKeys = _keys(xMap).map(k => Number(k));
const xArr = _orderBy(xKeys);
return datasets.map(dataset => {
let indexOffset = 0;
const isDate = dataset[0] && dataset[0]._x instanceof Date;
const filledInData = xArr.map((x, index) => {
let parsedX = Number(x);
const datum = dataset[index - indexOffset];
var xKeys = Object.keys(xMap).map(function (k) {
return Number(k);
});
var xArr = _orderBy(xKeys);
return datasets.map(function (dataset) {
var indexOffset = 0;
var isDate = dataset[0] && dataset[0]._x instanceof Date;
var filledInData = xArr.map(function (x, index) {
var parsedX = Number(x);
var datum = dataset[index - indexOffset];
if (datum) {
const x1 = isDate ? datum._x.getTime() : datum._x;
var x1 = isDate ? datum._x.getTime() : datum._x;
if (x1 === parsedX) {
return datum;
}
indexOffset++;
const y = fillInMissingData ? 0 : null;
var _y = fillInMissingData ? 0 : null;
parsedX = isDate ? new Date(parsedX) : parsedX;
return {
x: parsedX,
y,
y: _y,
_x: parsedX,
_y: y
_y: _y
};
}
const y = fillInMissingData ? 0 : null;
var y = fillInMissingData ? 0 : null;
parsedX = isDate ? new Date(parsedX) : parsedX;
return {
x: parsedX,
y,
y: y,
_x: parsedX,

@@ -60,2 +84,3 @@ _y: y

}
function getY0(datum, index, datasets) {

@@ -65,21 +90,31 @@ if (datum.y0) {

}
const y = datum._y;
const group = datum._group;
const firstDatasetBaseline = datasets[0].map(d => d.y0);
const previousDatasets = datasets.slice(0, index);
const previousPoints = previousDatasets.reduce((prev, dataset) => {
return prev.concat(dataset.filter(previousDatum => datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x).map(previousDatum => previousDatum._y || 0));
var y = datum._y;
var group = datum._group;
var firstDatasetBaseline = datasets[0].map(function (d) {
return d.y0;
});
var previousDatasets = datasets.slice(0, index);
var previousPoints = previousDatasets.reduce(function (prev, dataset) {
return prev.concat(dataset.filter(function (previousDatum) {
return datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x;
}).map(function (previousDatum) {
return previousDatum._y || 0;
}));
}, []);
const y0 = previousPoints.length && previousPoints.reduce((memo, value) => {
const sameSign = y < 0 && value < 0 || y >= 0 && value >= 0;
var y0 = previousPoints.length && previousPoints.reduce(function (memo, value) {
var sameSign = y < 0 && value < 0 || y >= 0 && value >= 0;
return sameSign ? Number(value) + memo : memo;
}, firstDatasetBaseline[group] || 0);
return previousPoints.some(point => point instanceof Date) ? new Date(y0) : y0;
return previousPoints.some(function (point) {
return point instanceof Date;
}) ? new Date(y0) : y0;
}
/* eslint-disable no-nested-ternary */
/* eslint-disable no-nested-ternary */
function addLayoutData(props, datasets, index) {
const xOffset = props.xOffset || 0;
return datasets[index].map(datum => {
const yOffset = getY0(datum, index, datasets) || 0;
var xOffset = props.xOffset || 0;
return datasets[index].map(function (datum) {
var yOffset = getY0(datum, index, datasets) || 0;
return Object.assign({}, datum, {

@@ -94,16 +129,24 @@ _y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y,

function stackData(props, childComponents) {
const dataFromChildren = Wrapper.getDataFromChildren(props, childComponents);
const filterNullChildData = dataFromChildren.map(dataset => dataset.filter(datum => datum._x !== null && datum._y !== null));
const datasets = fillData(props, filterNullChildData);
return datasets.map((d, i) => addLayoutData(props, datasets, i));
var dataFromChildren = Wrapper.getDataFromChildren(props, childComponents);
var filterNullChildData = dataFromChildren.map(function (dataset) {
return dataset.filter(function (datum) {
return datum._x !== null && datum._y !== null;
});
});
var datasets = fillData(props, filterNullChildData);
return datasets.map(function (d, i) {
return addLayoutData(props, datasets, i);
});
}
export function getCalculatedProps(initialProps, childComponents) {
const children = childComponents || React.Children.toArray(initialProps.children);
const role = "stack";
const props = Helpers.modifyProps(initialProps, fallbackProps, role);
const style = Wrapper.getStyle(props.theme, props.style, role);
const categories = props.categories || Wrapper.getCategories(props, children);
const datasets = props.datasets || stackData(props, children);
const clonedChildren = children.map((c, i) => {
var children = childComponents || React.Children.toArray(initialProps.children);
var role = "stack";
var props = Helpers.modifyProps(initialProps, fallbackProps, role);
var style = Wrapper.getStyle(props.theme, props.style, role);
var categories = props.categories || Wrapper.getCategories(props, children);
var datasets = props.datasets || stackData(props, children);
var clonedChildren = children.map(function (c, i) {
return /*#__PURE__*/React.cloneElement(c, {

@@ -113,51 +156,45 @@ data: datasets[i]

});
const domain = {
var domain = {
x: Wrapper.getDomain(Object.assign({}, props, {
categories
categories: categories
}), "x", clonedChildren),
y: Wrapper.getDomain(Object.assign({}, props, {
categories
categories: categories
}), "y", clonedChildren)
};
const range = props.range || {
var range = props.range || {
x: Helpers.getRange(props, "x"),
y: Helpers.getRange(props, "y")
};
const baseScale = {
var baseScale = {
x: Scale.getScaleFromProps(props, "x") || Wrapper.getScale(props, "x"),
y: Scale.getScaleFromProps(props, "y") || Wrapper.getScale(props, "y")
};
const scale = {
var scale = {
x: baseScale.x.domain(domain.x).range(props.horizontal ? range.y : range.x),
y: baseScale.y.domain(domain.y).range(props.horizontal ? range.x : range.y)
};
const {
colorScale,
horizontal
} = props;
var colorScale = props.colorScale,
horizontal = props.horizontal;
return {
datasets,
categories,
range,
domain,
horizontal,
scale,
style,
colorScale,
role
datasets: datasets,
categories: categories,
range: range,
domain: domain,
horizontal: horizontal,
scale: scale,
style: style,
colorScale: colorScale,
role: role
};
}
} // We need to remove sharedEvents in order to memoize the calculated data
// With shared events, the props change on every event, and every value is re-calculated
// We need to remove sharedEvents in order to memoize the calculated data
// With shared events, the props change on every event, and every value is re-calculated
const withoutSharedEvents = props => {
const {
children
} = props;
const modifiedChildren = React.Children.toArray(children).map(_child => {
const child = _child;
return {
...child,
var withoutSharedEvents = function (props) {
var children = props.children;
var modifiedChildren = React.Children.toArray(children).map(function (_child) {
var child = _child;
return _objectSpread(_objectSpread({}, child), {}, {
props: Helpers.omit(child.props, ["sharedEvents"])
};
});
});

@@ -167,9 +204,14 @@ props.children = modifiedChildren;

};
export function useMemoizedProps(initialProps) {
const modifiedProps = withoutSharedEvents(initialProps);
const [props, setProps] = React.useState(modifiedProps);
var modifiedProps = withoutSharedEvents(initialProps);
// React.memo uses shallow equality to compare objects. This way props
var _React$useState = React.useState(modifiedProps),
_React$useState2 = _slicedToArray(_React$useState, 2),
props = _React$useState2[0],
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
// will only be re-calculated when they change.
React.useEffect(() => {
React.useEffect(function () {
if (!isEqual(modifiedProps, props)) {

@@ -179,6 +221,7 @@ setProps(modifiedProps);

}, [props, setProps, modifiedProps]);
return React.useMemo(() => {
return React.useMemo(function () {
return getCalculatedProps(props, props.children);
}, [props]);
}
function getLabels(props, datasets, index) {

@@ -188,12 +231,12 @@ if (!props.labels) {

}
return datasets.length === index + 1 ? props.labels : undefined;
}
export function getChildProps(props, calculatedProps) {
const {
categories,
domain,
range,
scale,
horizontal
} = calculatedProps;
var categories = calculatedProps.categories,
domain = calculatedProps.domain,
range = calculatedProps.range,
scale = calculatedProps.scale,
horizontal = calculatedProps.horizontal;
return {

@@ -205,42 +248,44 @@ height: props.height,

theme: props.theme,
categories,
domain,
range,
scale,
horizontal
categories: categories,
domain: domain,
range: range,
scale: scale,
horizontal: horizontal
};
}
function getColorScale(props, child) {
const role = child.type && child.type.role;
const colorScaleOptions = child.props.colorScale || props.colorScale;
var role = child.type && child.type.role;
var colorScaleOptions = child.props.colorScale || props.colorScale;
if (role !== "group" && role !== "stack") {
return undefined;
}
return props.theme ? colorScaleOptions || props.theme.props.colorScale : colorScaleOptions;
}
export function getChildren(initialProps, childComponents, calculatedProps) {
const props = Helpers.modifyProps(initialProps, fallbackProps, "stack");
const children = childComponents || React.Children.toArray(props.children);
const newCalculatedProps = calculatedProps || getCalculatedProps(props, children);
const {
datasets
} = newCalculatedProps;
const childProps = getChildProps(props, newCalculatedProps);
const parentName = props.name || "stack";
return children.map((child, index) => {
const role = child.type && child.type.role;
const data = datasets[index];
const style = Wrapper.getChildStyle(child, index, newCalculatedProps);
const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
const name = child.props.name || `${parentName}-${role}-${index}`;
var props = Helpers.modifyProps(initialProps, fallbackProps, "stack");
var children = childComponents || React.Children.toArray(props.children);
var newCalculatedProps = calculatedProps || getCalculatedProps(props, children);
var datasets = newCalculatedProps.datasets;
var childProps = getChildProps(props, newCalculatedProps);
var parentName = props.name || "stack";
return children.map(function (child, index) {
var role = child.type && child.type.role;
var data = datasets[index];
var style = Wrapper.getChildStyle(child, index, newCalculatedProps);
var labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
var name = child.props.name || "".concat(parentName, "-").concat(role, "-").concat(index);
return /*#__PURE__*/React.cloneElement(child, Object.assign({
key: `${name}-key-${index}`,
labels,
name,
key: "".concat(name, "-key-").concat(index),
labels: labels,
name: name,
domainPadding: child.props.domainPadding || props.domainPadding,
theme: props.theme,
labelComponent: props.labelComponent || child.props.labelComponent,
style,
style: style,
colorScale: getColorScale(props, child),
data,
data: data,
polar: props.polar

@@ -247,0 +292,0 @@ }, childProps));

import _isEmpty from "lodash/isEmpty";
import _defaults from "lodash/defaults";
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; }
import React from "react";

@@ -8,3 +15,3 @@ import { Helpers, Hooks, UserProps, VictoryContainer, VictoryTheme, Wrapper } from "victory-core";

import isEqual from "react-fast-compare";
const fallbackProps = {
var fallbackProps = {
width: 450,

@@ -14,3 +21,3 @@ height: 300,

};
const defaultProps = {
var defaultProps = {
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),

@@ -22,41 +29,36 @@ groupComponent: /*#__PURE__*/React.createElement("g", null),

};
const VictoryStackBase = initialProps => {
const {
role
} = VictoryStack;
const propsWithDefaults = React.useMemo(() => ({
...defaultProps,
...initialProps
}), [initialProps]);
const {
setAnimationState,
getAnimationProps,
getProps
} = Hooks.useAnimationState();
const props = getProps(propsWithDefaults);
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
const {
eventKey,
containerComponent,
standalone,
groupComponent,
externalEventMutations,
width,
height,
theme,
polar,
horizontal,
name
} = modifiedProps;
const childComponents = React.Children.toArray(modifiedProps.children);
const calculatedProps = useMemoizedProps(modifiedProps);
const {
domain,
scale,
style
} = calculatedProps;
const newChildren = React.useMemo(() => {
const children = getChildren(props, childComponents, calculatedProps);
const orderedChildren = children.map((child, index) => {
const childProps = Object.assign({
var VictoryStackBase = function (initialProps) {
var role = VictoryStack.role;
var propsWithDefaults = React.useMemo(function () {
return _objectSpread(_objectSpread({}, defaultProps), initialProps);
}, [initialProps]);
var _Hooks$useAnimationSt = Hooks.useAnimationState(),
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
getProps = _Hooks$useAnimationSt.getProps;
var props = getProps(propsWithDefaults);
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
var eventKey = modifiedProps.eventKey,
containerComponent = modifiedProps.containerComponent,
standalone = modifiedProps.standalone,
groupComponent = modifiedProps.groupComponent,
externalEventMutations = modifiedProps.externalEventMutations,
width = modifiedProps.width,
height = modifiedProps.height,
theme = modifiedProps.theme,
polar = modifiedProps.polar,
horizontal = modifiedProps.horizontal,
name = modifiedProps.name;
var childComponents = React.Children.toArray(modifiedProps.children);
var calculatedProps = useMemoizedProps(modifiedProps);
var domain = calculatedProps.domain,
scale = calculatedProps.scale,
style = calculatedProps.style;
var newChildren = React.useMemo(function () {
var children = getChildren(props, childComponents, calculatedProps);
var orderedChildren = children.map(function (child, index) {
var childProps = Object.assign({
animate: getAnimationProps(props, child, index)

@@ -71,36 +73,42 @@ }, child.props);

*/
return orderedChildren.reverse();
}, [props, childComponents, calculatedProps, getAnimationProps]);
const containerProps = React.useMemo(() => {
var containerProps = React.useMemo(function () {
if (standalone) {
return {
domain,
scale,
width,
height,
standalone,
theme,
domain: domain,
scale: scale,
width: width,
height: height,
standalone: standalone,
theme: theme,
style: style.parent,
horizontal,
polar,
name
horizontal: horizontal,
polar: polar,
name: name
};
}
return {};
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, name]);
const userProps = React.useMemo(() => UserProps.getSafeUserProps(propsWithDefaults), [propsWithDefaults]);
const container = React.useMemo(() => {
var userProps = React.useMemo(function () {
return UserProps.getSafeUserProps(propsWithDefaults);
}, [propsWithDefaults]);
var container = React.useMemo(function () {
if (standalone) {
const defaultContainerProps = _defaults({}, containerComponent.props, containerProps, userProps);
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps, userProps);
return /*#__PURE__*/React.cloneElement(containerComponent, defaultContainerProps);
}
return /*#__PURE__*/React.cloneElement(groupComponent, userProps);
}, [groupComponent, standalone, containerComponent, containerProps, userProps]);
const events = React.useMemo(() => {
var events = React.useMemo(function () {
return Wrapper.getAllEvents(props);
}, [props]);
const previousProps = Hooks.usePreviousProps(propsWithDefaults);
React.useEffect(() => {
var previousProps = Hooks.usePreviousProps(propsWithDefaults);
React.useEffect(function () {
// This is called before dismount to keep state in sync
return () => {
return function () {
if (propsWithDefaults.animate) {

@@ -111,2 +119,3 @@ setAnimationState(previousProps, propsWithDefaults);

}, [setAnimationState, previousProps, propsWithDefaults]);
if (!_isEmpty(events)) {

@@ -120,10 +129,12 @@ return /*#__PURE__*/React.createElement(VictorySharedEvents, {

}
return /*#__PURE__*/React.cloneElement(container, container.props, newChildren);
};
const componentConfig = {
var componentConfig = {
role: "stack",
expectedComponents: ["groupComponent", "containerComponent", "labelComponent"],
getChildren
getChildren: getChildren
};
export const VictoryStack = Object.assign( /*#__PURE__*/React.memo(VictoryStackBase, isEqual), componentConfig);
export var VictoryStack = Object.assign( /*#__PURE__*/React.memo(VictoryStackBase, isEqual), componentConfig);
VictoryStack.displayName = "VictoryStack";

@@ -10,23 +10,41 @@ "use strict";

exports.useMemoizedProps = useMemoizedProps;
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
var _keys2 = _interopRequireDefault(require("lodash/keys"));
var _react = _interopRequireDefault(require("react"));
var _victoryCore = require("victory-core");
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable no-use-before-define */
const fallbackProps = {
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }
var fallbackProps = {
width: 450,
height: 300,
padding: 50
};
}; // Assumes data in `datasets` is sorted by `Data.getData`.
// Assumes data in `datasets` is sorted by `Data.getData`.
function fillData(props, datasets) {
const {
fillInMissingData
} = props;
const xMap = datasets.reduce((prev, dataset) => {
dataset.forEach(datum => {
var fillInMissingData = props.fillInMissingData;
var xMap = datasets.reduce(function (prev, dataset) {
dataset.forEach(function (datum) {
prev[datum._x instanceof Date ? datum._x.getTime() : datum._x] = true;

@@ -36,30 +54,38 @@ });

}, {});
const xKeys = (0, _keys2.default)(xMap).map(k => Number(k));
const xArr = (0, _orderBy2.default)(xKeys);
return datasets.map(dataset => {
let indexOffset = 0;
const isDate = dataset[0] && dataset[0]._x instanceof Date;
const filledInData = xArr.map((x, index) => {
let parsedX = Number(x);
const datum = dataset[index - indexOffset];
var xKeys = Object.keys(xMap).map(function (k) {
return Number(k);
});
var xArr = (0, _orderBy2.default)(xKeys);
return datasets.map(function (dataset) {
var indexOffset = 0;
var isDate = dataset[0] && dataset[0]._x instanceof Date;
var filledInData = xArr.map(function (x, index) {
var parsedX = Number(x);
var datum = dataset[index - indexOffset];
if (datum) {
const x1 = isDate ? datum._x.getTime() : datum._x;
var x1 = isDate ? datum._x.getTime() : datum._x;
if (x1 === parsedX) {
return datum;
}
indexOffset++;
const y = fillInMissingData ? 0 : null;
var _y = fillInMissingData ? 0 : null;
parsedX = isDate ? new Date(parsedX) : parsedX;
return {
x: parsedX,
y,
y: _y,
_x: parsedX,
_y: y
_y: _y
};
}
const y = fillInMissingData ? 0 : null;
var y = fillInMissingData ? 0 : null;
parsedX = isDate ? new Date(parsedX) : parsedX;
return {
x: parsedX,
y,
y: y,
_x: parsedX,

@@ -72,2 +98,3 @@ _y: y

}
function getY0(datum, index, datasets) {

@@ -77,21 +104,31 @@ if (datum.y0) {

}
const y = datum._y;
const group = datum._group;
const firstDatasetBaseline = datasets[0].map(d => d.y0);
const previousDatasets = datasets.slice(0, index);
const previousPoints = previousDatasets.reduce((prev, dataset) => {
return prev.concat(dataset.filter(previousDatum => datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x).map(previousDatum => previousDatum._y || 0));
var y = datum._y;
var group = datum._group;
var firstDatasetBaseline = datasets[0].map(function (d) {
return d.y0;
});
var previousDatasets = datasets.slice(0, index);
var previousPoints = previousDatasets.reduce(function (prev, dataset) {
return prev.concat(dataset.filter(function (previousDatum) {
return datum._x instanceof Date ? previousDatum._x.getTime() === datum._x.getTime() : previousDatum._x === datum._x;
}).map(function (previousDatum) {
return previousDatum._y || 0;
}));
}, []);
const y0 = previousPoints.length && previousPoints.reduce((memo, value) => {
const sameSign = y < 0 && value < 0 || y >= 0 && value >= 0;
var y0 = previousPoints.length && previousPoints.reduce(function (memo, value) {
var sameSign = y < 0 && value < 0 || y >= 0 && value >= 0;
return sameSign ? Number(value) + memo : memo;
}, firstDatasetBaseline[group] || 0);
return previousPoints.some(point => point instanceof Date) ? new Date(y0) : y0;
return previousPoints.some(function (point) {
return point instanceof Date;
}) ? new Date(y0) : y0;
}
/* eslint-disable no-nested-ternary */
/* eslint-disable no-nested-ternary */
function addLayoutData(props, datasets, index) {
const xOffset = props.xOffset || 0;
return datasets[index].map(datum => {
const yOffset = getY0(datum, index, datasets) || 0;
var xOffset = props.xOffset || 0;
return datasets[index].map(function (datum) {
var yOffset = getY0(datum, index, datasets) || 0;
return Object.assign({}, datum, {

@@ -106,16 +143,30 @@ _y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y,

function stackData(props, childComponents) {
const dataFromChildren = _victoryCore.Wrapper.getDataFromChildren(props, childComponents);
const filterNullChildData = dataFromChildren.map(dataset => dataset.filter(datum => datum._x !== null && datum._y !== null));
const datasets = fillData(props, filterNullChildData);
return datasets.map((d, i) => addLayoutData(props, datasets, i));
var dataFromChildren = _victoryCore.Wrapper.getDataFromChildren(props, childComponents);
var filterNullChildData = dataFromChildren.map(function (dataset) {
return dataset.filter(function (datum) {
return datum._x !== null && datum._y !== null;
});
});
var datasets = fillData(props, filterNullChildData);
return datasets.map(function (d, i) {
return addLayoutData(props, datasets, i);
});
}
function getCalculatedProps(initialProps, childComponents) {
const children = childComponents || _react.default.Children.toArray(initialProps.children);
const role = "stack";
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, role);
const style = _victoryCore.Wrapper.getStyle(props.theme, props.style, role);
const categories = props.categories || _victoryCore.Wrapper.getCategories(props, children);
const datasets = props.datasets || stackData(props, children);
const clonedChildren = children.map((c, i) => {
var children = childComponents || _react.default.Children.toArray(initialProps.children);
var role = "stack";
var props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, role);
var style = _victoryCore.Wrapper.getStyle(props.theme, props.style, role);
var categories = props.categories || _victoryCore.Wrapper.getCategories(props, children);
var datasets = props.datasets || stackData(props, children);
var clonedChildren = children.map(function (c, i) {
return /*#__PURE__*/_react.default.cloneElement(c, {

@@ -125,62 +176,64 @@ data: datasets[i]

});
const domain = {
var domain = {
x: _victoryCore.Wrapper.getDomain(Object.assign({}, props, {
categories
categories: categories
}), "x", clonedChildren),
y: _victoryCore.Wrapper.getDomain(Object.assign({}, props, {
categories
categories: categories
}), "y", clonedChildren)
};
const range = props.range || {
var range = props.range || {
x: _victoryCore.Helpers.getRange(props, "x"),
y: _victoryCore.Helpers.getRange(props, "y")
};
const baseScale = {
var baseScale = {
x: _victoryCore.Scale.getScaleFromProps(props, "x") || _victoryCore.Wrapper.getScale(props, "x"),
y: _victoryCore.Scale.getScaleFromProps(props, "y") || _victoryCore.Wrapper.getScale(props, "y")
};
const scale = {
var scale = {
x: baseScale.x.domain(domain.x).range(props.horizontal ? range.y : range.x),
y: baseScale.y.domain(domain.y).range(props.horizontal ? range.x : range.y)
};
const {
colorScale,
horizontal
} = props;
var colorScale = props.colorScale,
horizontal = props.horizontal;
return {
datasets,
categories,
range,
domain,
horizontal,
scale,
style,
colorScale,
role
datasets: datasets,
categories: categories,
range: range,
domain: domain,
horizontal: horizontal,
scale: scale,
style: style,
colorScale: colorScale,
role: role
};
}
} // We need to remove sharedEvents in order to memoize the calculated data
// With shared events, the props change on every event, and every value is re-calculated
// We need to remove sharedEvents in order to memoize the calculated data
// With shared events, the props change on every event, and every value is re-calculated
const withoutSharedEvents = props => {
const {
children
} = props;
const modifiedChildren = _react.default.Children.toArray(children).map(_child => {
const child = _child;
return {
...child,
var withoutSharedEvents = function (props) {
var children = props.children;
var modifiedChildren = _react.default.Children.toArray(children).map(function (_child) {
var child = _child;
return _objectSpread(_objectSpread({}, child), {}, {
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"])
};
});
});
props.children = modifiedChildren;
return props;
};
function useMemoizedProps(initialProps) {
const modifiedProps = withoutSharedEvents(initialProps);
const [props, setProps] = _react.default.useState(modifiedProps);
var modifiedProps = withoutSharedEvents(initialProps);
// React.memo uses shallow equality to compare objects. This way props
var _React$useState = _react.default.useState(modifiedProps),
_React$useState2 = _slicedToArray(_React$useState, 2),
props = _React$useState2[0],
setProps = _React$useState2[1]; // React.memo uses shallow equality to compare objects. This way props
// will only be re-calculated when they change.
_react.default.useEffect(() => {
_react.default.useEffect(function () {
if (!(0, _reactFastCompare.default)(modifiedProps, props)) {

@@ -190,6 +243,8 @@ setProps(modifiedProps);

}, [props, setProps, modifiedProps]);
return _react.default.useMemo(() => {
return _react.default.useMemo(function () {
return getCalculatedProps(props, props.children);
}, [props]);
}
function getLabels(props, datasets, index) {

@@ -199,12 +254,12 @@ if (!props.labels) {

}
return datasets.length === index + 1 ? props.labels : undefined;
}
function getChildProps(props, calculatedProps) {
const {
categories,
domain,
range,
scale,
horizontal
} = calculatedProps;
var categories = calculatedProps.categories,
domain = calculatedProps.domain,
range = calculatedProps.range,
scale = calculatedProps.scale,
horizontal = calculatedProps.horizontal;
return {

@@ -216,42 +271,48 @@ height: props.height,

theme: props.theme,
categories,
domain,
range,
scale,
horizontal
categories: categories,
domain: domain,
range: range,
scale: scale,
horizontal: horizontal
};
}
function getColorScale(props, child) {
const role = child.type && child.type.role;
const colorScaleOptions = child.props.colorScale || props.colorScale;
var role = child.type && child.type.role;
var colorScaleOptions = child.props.colorScale || props.colorScale;
if (role !== "group" && role !== "stack") {
return undefined;
}
return props.theme ? colorScaleOptions || props.theme.props.colorScale : colorScaleOptions;
}
function getChildren(initialProps, childComponents, calculatedProps) {
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "stack");
const children = childComponents || _react.default.Children.toArray(props.children);
const newCalculatedProps = calculatedProps || getCalculatedProps(props, children);
const {
datasets
} = newCalculatedProps;
const childProps = getChildProps(props, newCalculatedProps);
const parentName = props.name || "stack";
return children.map((child, index) => {
const role = child.type && child.type.role;
const data = datasets[index];
const style = _victoryCore.Wrapper.getChildStyle(child, index, newCalculatedProps);
const labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
const name = child.props.name || `${parentName}-${role}-${index}`;
var props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "stack");
var children = childComponents || _react.default.Children.toArray(props.children);
var newCalculatedProps = calculatedProps || getCalculatedProps(props, children);
var datasets = newCalculatedProps.datasets;
var childProps = getChildProps(props, newCalculatedProps);
var parentName = props.name || "stack";
return children.map(function (child, index) {
var role = child.type && child.type.role;
var data = datasets[index];
var style = _victoryCore.Wrapper.getChildStyle(child, index, newCalculatedProps);
var labels = props.labels ? getLabels(props, datasets, index) : child.props.labels;
var name = child.props.name || "".concat(parentName, "-").concat(role, "-").concat(index);
return /*#__PURE__*/_react.default.cloneElement(child, Object.assign({
key: `${name}-key-${index}`,
labels,
name,
key: "".concat(name, "-key-").concat(index),
labels: labels,
name: name,
domainPadding: child.props.domainPadding || props.domainPadding,
theme: props.theme,
labelComponent: props.labelComponent || child.props.labelComponent,
style,
style: style,
colorScale: getColorScale(props, child),
data,
data: data,
polar: props.polar

@@ -258,0 +319,0 @@ }, childProps));

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

});
var _victoryStack = require("./victory-stack");
Object.keys(_victoryStack).forEach(function (key) {

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

@@ -7,11 +7,26 @@ "use strict";

exports.VictoryStack = void 0;
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
var _react = _interopRequireDefault(require("react"));
var _victoryCore = require("victory-core");
var _victorySharedEvents = require("victory-shared-events");
var _helperMethods = require("./helper-methods");
var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const fallbackProps = {
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; }
var fallbackProps = {
width: 450,

@@ -21,3 +36,3 @@ height: 300,

};
const defaultProps = {
var defaultProps = {
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null),

@@ -29,41 +44,42 @@ groupComponent: /*#__PURE__*/_react.default.createElement("g", null),

};
const VictoryStackBase = initialProps => {
const {
role
} = VictoryStack;
const propsWithDefaults = _react.default.useMemo(() => ({
...defaultProps,
...initialProps
}), [initialProps]);
const {
setAnimationState,
getAnimationProps,
getProps
} = _victoryCore.Hooks.useAnimationState();
const props = getProps(propsWithDefaults);
const modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
const {
eventKey,
containerComponent,
standalone,
groupComponent,
externalEventMutations,
width,
height,
theme,
polar,
horizontal,
name
} = modifiedProps;
const childComponents = _react.default.Children.toArray(modifiedProps.children);
const calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
const {
domain,
scale,
style
} = calculatedProps;
const newChildren = _react.default.useMemo(() => {
const children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
const orderedChildren = children.map((child, index) => {
const childProps = Object.assign({
var VictoryStackBase = function (initialProps) {
var role = VictoryStack.role;
var propsWithDefaults = _react.default.useMemo(function () {
return _objectSpread(_objectSpread({}, defaultProps), initialProps);
}, [initialProps]);
var _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(),
setAnimationState = _Hooks$useAnimationSt.setAnimationState,
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps,
getProps = _Hooks$useAnimationSt.getProps;
var props = getProps(propsWithDefaults);
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role);
var eventKey = modifiedProps.eventKey,
containerComponent = modifiedProps.containerComponent,
standalone = modifiedProps.standalone,
groupComponent = modifiedProps.groupComponent,
externalEventMutations = modifiedProps.externalEventMutations,
width = modifiedProps.width,
height = modifiedProps.height,
theme = modifiedProps.theme,
polar = modifiedProps.polar,
horizontal = modifiedProps.horizontal,
name = modifiedProps.name;
var childComponents = _react.default.Children.toArray(modifiedProps.children);
var calculatedProps = (0, _helperMethods.useMemoizedProps)(modifiedProps);
var domain = calculatedProps.domain,
scale = calculatedProps.scale,
style = calculatedProps.style;
var newChildren = _react.default.useMemo(function () {
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps);
var orderedChildren = children.map(function (child, index) {
var childProps = Object.assign({
animate: getAnimationProps(props, child, index)

@@ -78,36 +94,47 @@ }, child.props);

*/
return orderedChildren.reverse();
}, [props, childComponents, calculatedProps, getAnimationProps]);
const containerProps = _react.default.useMemo(() => {
var containerProps = _react.default.useMemo(function () {
if (standalone) {
return {
domain,
scale,
width,
height,
standalone,
theme,
domain: domain,
scale: scale,
width: width,
height: height,
standalone: standalone,
theme: theme,
style: style.parent,
horizontal,
polar,
name
horizontal: horizontal,
polar: polar,
name: name
};
}
return {};
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, name]);
const userProps = _react.default.useMemo(() => _victoryCore.UserProps.getSafeUserProps(propsWithDefaults), [propsWithDefaults]);
const container = _react.default.useMemo(() => {
var userProps = _react.default.useMemo(function () {
return _victoryCore.UserProps.getSafeUserProps(propsWithDefaults);
}, [propsWithDefaults]);
var container = _react.default.useMemo(function () {
if (standalone) {
const defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, userProps);
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, userProps);
return /*#__PURE__*/_react.default.cloneElement(containerComponent, defaultContainerProps);
}
return /*#__PURE__*/_react.default.cloneElement(groupComponent, userProps);
}, [groupComponent, standalone, containerComponent, containerProps, userProps]);
const events = _react.default.useMemo(() => {
var events = _react.default.useMemo(function () {
return _victoryCore.Wrapper.getAllEvents(props);
}, [props]);
const previousProps = _victoryCore.Hooks.usePreviousProps(propsWithDefaults);
_react.default.useEffect(() => {
var previousProps = _victoryCore.Hooks.usePreviousProps(propsWithDefaults);
_react.default.useEffect(function () {
// This is called before dismount to keep state in sync
return () => {
return function () {
if (propsWithDefaults.animate) {

@@ -118,2 +145,3 @@ setAnimationState(previousProps, propsWithDefaults);

}, [setAnimationState, previousProps, propsWithDefaults]);
if (!(0, _isEmpty2.default)(events)) {

@@ -127,5 +155,7 @@ return /*#__PURE__*/_react.default.createElement(_victorySharedEvents.VictorySharedEvents, {

}
return /*#__PURE__*/_react.default.cloneElement(container, container.props, newChildren);
};
const componentConfig = {
var componentConfig = {
role: "stack",

@@ -135,3 +165,4 @@ expectedComponents: ["groupComponent", "containerComponent", "labelComponent"],

};
const VictoryStack = exports.VictoryStack = Object.assign( /*#__PURE__*/_react.default.memo(VictoryStackBase, _reactFastCompare.default), componentConfig);
var VictoryStack = Object.assign( /*#__PURE__*/_react.default.memo(VictoryStackBase, _reactFastCompare.default), componentConfig);
exports.VictoryStack = VictoryStack;
VictoryStack.displayName = "VictoryStack";
{
"name": "victory-stack",
"version": "36.9.2-next.0",
"version": "36.9.2-next.1",
"description": "Stack Layout Component for Victory",

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

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

@@ -33,4 +33,4 @@ "peerDependencies": {

"devDependencies": {
"victory-bar": "36.9.2-next.0",
"victory-histogram": "36.9.2-next.0"
"victory-bar": "36.9.2-next.1",
"victory-histogram": "36.9.2-next.1"
},

@@ -37,0 +37,0 @@ "wireit": {

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc