victory-stack
Advanced tools
Comparing version 36.9.2 to 37.0.0
# victory-stack | ||
## 37.0.0 | ||
### Major Changes | ||
- Upgrade babel dependencies and build target to modern browsers ([#2804](https://github.com/FormidableLabs/victory/pull/2804)) | ||
## 36.9.2 | ||
@@ -4,0 +10,0 @@ |
import _orderBy from "lodash/orderBy"; | ||
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; } | ||
/* eslint-disable no-use-before-define */ | ||
import React from "react"; | ||
import { Helpers, Scale, Wrapper } from "victory-core"; | ||
import isEqual from "react-fast-compare"; | ||
var fallbackProps = { | ||
const 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) { | ||
var fillInMissingData = props.fillInMissingData; | ||
var xMap = datasets.reduce(function (prev, dataset) { | ||
dataset.forEach(function (datum) { | ||
const { | ||
fillInMissingData | ||
} = props; | ||
const xMap = datasets.reduce((prev, dataset) => { | ||
dataset.forEach(datum => { | ||
prev[datum._x instanceof Date ? datum._x.getTime() : datum._x] = true; | ||
@@ -38,40 +23,30 @@ }); | ||
}, {}); | ||
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]; | ||
const xKeys = Object.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]; | ||
if (datum) { | ||
var x1 = isDate ? datum._x.getTime() : datum._x; | ||
const x1 = isDate ? datum._x.getTime() : datum._x; | ||
if (x1 === parsedX) { | ||
return datum; | ||
} | ||
indexOffset++; | ||
var _y = fillInMissingData ? 0 : null; | ||
const y = fillInMissingData ? 0 : null; | ||
parsedX = isDate ? new Date(parsedX) : parsedX; | ||
return { | ||
x: parsedX, | ||
y: _y, | ||
y, | ||
_x: parsedX, | ||
_y: _y | ||
_y: y | ||
}; | ||
} | ||
var y = fillInMissingData ? 0 : null; | ||
const y = fillInMissingData ? 0 : null; | ||
parsedX = isDate ? new Date(parsedX) : parsedX; | ||
return { | ||
x: parsedX, | ||
y: y, | ||
y, | ||
_x: parsedX, | ||
@@ -84,3 +59,2 @@ _y: y | ||
} | ||
function getY0(datum, index, datasets) { | ||
@@ -90,31 +64,21 @@ if (datum.y0) { | ||
} | ||
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 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 y0 = previousPoints.length && previousPoints.reduce(function (memo, value) { | ||
var sameSign = y < 0 && value < 0 || y >= 0 && value >= 0; | ||
const y0 = previousPoints.length && previousPoints.reduce((memo, value) => { | ||
const sameSign = y < 0 && value < 0 || y >= 0 && value >= 0; | ||
return sameSign ? Number(value) + memo : memo; | ||
}, firstDatasetBaseline[group] || 0); | ||
return previousPoints.some(function (point) { | ||
return point instanceof Date; | ||
}) ? new Date(y0) : y0; | ||
return previousPoints.some(point => point instanceof Date) ? new Date(y0) : y0; | ||
} | ||
/* eslint-disable no-nested-ternary */ | ||
function addLayoutData(props, datasets, index) { | ||
var xOffset = props.xOffset || 0; | ||
return datasets[index].map(function (datum) { | ||
var yOffset = getY0(datum, index, datasets) || 0; | ||
const xOffset = props.xOffset || 0; | ||
return datasets[index].map(datum => { | ||
const yOffset = getY0(datum, index, datasets) || 0; | ||
return Object.assign({}, datum, { | ||
@@ -129,24 +93,16 @@ _y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y, | ||
function stackData(props, childComponents) { | ||
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); | ||
}); | ||
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)); | ||
} | ||
export function getCalculatedProps(initialProps, childComponents) { | ||
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) { | ||
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) => { | ||
return /*#__PURE__*/React.cloneElement(c, { | ||
@@ -156,45 +112,51 @@ data: datasets[i] | ||
}); | ||
var domain = { | ||
const domain = { | ||
x: Wrapper.getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "x", clonedChildren), | ||
y: Wrapper.getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "y", clonedChildren) | ||
}; | ||
var range = props.range || { | ||
const range = props.range || { | ||
x: Helpers.getRange(props, "x"), | ||
y: Helpers.getRange(props, "y") | ||
}; | ||
var baseScale = { | ||
const baseScale = { | ||
x: Scale.getScaleFromProps(props, "x") || Wrapper.getScale(props, "x"), | ||
y: Scale.getScaleFromProps(props, "y") || Wrapper.getScale(props, "y") | ||
}; | ||
var scale = { | ||
const 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) | ||
}; | ||
var colorScale = props.colorScale, | ||
horizontal = props.horizontal; | ||
const { | ||
colorScale, | ||
horizontal | ||
} = props; | ||
return { | ||
datasets: datasets, | ||
categories: categories, | ||
range: range, | ||
domain: domain, | ||
horizontal: horizontal, | ||
scale: scale, | ||
style: style, | ||
colorScale: colorScale, | ||
role: role | ||
datasets, | ||
categories, | ||
range, | ||
domain, | ||
horizontal, | ||
scale, | ||
style, | ||
colorScale, | ||
role | ||
}; | ||
} // We need to remove sharedEvents in order to memoize the calculated data | ||
} | ||
// 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 | ||
var withoutSharedEvents = function (props) { | ||
var children = props.children; | ||
var modifiedChildren = React.Children.toArray(children).map(function (_child) { | ||
var child = _child; | ||
return _objectSpread(_objectSpread({}, child), {}, { | ||
const withoutSharedEvents = props => { | ||
const { | ||
children | ||
} = props; | ||
const modifiedChildren = React.Children.toArray(children).map(_child => { | ||
const child = _child; | ||
return { | ||
...child, | ||
props: Helpers.omit(child.props, ["sharedEvents"]) | ||
}); | ||
}; | ||
}); | ||
@@ -204,14 +166,9 @@ props.children = modifiedChildren; | ||
}; | ||
export function useMemoizedProps(initialProps) { | ||
var modifiedProps = withoutSharedEvents(initialProps); | ||
const modifiedProps = withoutSharedEvents(initialProps); | ||
const [props, setProps] = React.useState(modifiedProps); | ||
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 | ||
// React.memo uses shallow equality to compare objects. This way props | ||
// will only be re-calculated when they change. | ||
React.useEffect(function () { | ||
React.useEffect(() => { | ||
if (!isEqual(modifiedProps, props)) { | ||
@@ -221,7 +178,6 @@ setProps(modifiedProps); | ||
}, [props, setProps, modifiedProps]); | ||
return React.useMemo(function () { | ||
return React.useMemo(() => { | ||
return getCalculatedProps(props, props.children); | ||
}, [props]); | ||
} | ||
function getLabels(props, datasets, index) { | ||
@@ -231,12 +187,12 @@ if (!props.labels) { | ||
} | ||
return datasets.length === index + 1 ? props.labels : undefined; | ||
} | ||
export function getChildProps(props, calculatedProps) { | ||
var categories = calculatedProps.categories, | ||
domain = calculatedProps.domain, | ||
range = calculatedProps.range, | ||
scale = calculatedProps.scale, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
@@ -248,44 +204,42 @@ height: props.height, | ||
theme: props.theme, | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
scale: scale, | ||
horizontal: horizontal | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
horizontal | ||
}; | ||
} | ||
function getColorScale(props, child) { | ||
var role = child.type && child.type.role; | ||
var colorScaleOptions = child.props.colorScale || props.colorScale; | ||
const role = child.type && child.type.role; | ||
const 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) { | ||
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); | ||
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}`; | ||
return /*#__PURE__*/React.cloneElement(child, Object.assign({ | ||
key: "".concat(name, "-key-").concat(index), | ||
labels: labels, | ||
name: name, | ||
key: `${name}-key-${index}`, | ||
labels, | ||
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 | ||
@@ -292,0 +246,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"; | ||
@@ -15,3 +8,3 @@ import { Helpers, Hooks, UserProps, VictoryContainer, VictoryTheme, Wrapper } from "victory-core"; | ||
import isEqual from "react-fast-compare"; | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -21,3 +14,3 @@ height: 300, | ||
}; | ||
var defaultProps = { | ||
const defaultProps = { | ||
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
@@ -29,36 +22,41 @@ groupComponent: /*#__PURE__*/React.createElement("g", null), | ||
}; | ||
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({ | ||
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({ | ||
animate: getAnimationProps(props, child, index) | ||
@@ -73,42 +71,36 @@ }, child.props); | ||
*/ | ||
return orderedChildren.reverse(); | ||
}, [props, childComponents, calculatedProps, getAnimationProps]); | ||
var containerProps = React.useMemo(function () { | ||
const containerProps = React.useMemo(() => { | ||
if (standalone) { | ||
return { | ||
domain: domain, | ||
scale: scale, | ||
width: width, | ||
height: height, | ||
standalone: standalone, | ||
theme: theme, | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
standalone, | ||
theme, | ||
style: style.parent, | ||
horizontal: horizontal, | ||
polar: polar, | ||
name: name | ||
horizontal, | ||
polar, | ||
name | ||
}; | ||
} | ||
return {}; | ||
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, name]); | ||
var userProps = React.useMemo(function () { | ||
return UserProps.getSafeUserProps(propsWithDefaults); | ||
}, [propsWithDefaults]); | ||
var container = React.useMemo(function () { | ||
const userProps = React.useMemo(() => UserProps.getSafeUserProps(propsWithDefaults), [propsWithDefaults]); | ||
const container = React.useMemo(() => { | ||
if (standalone) { | ||
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps, userProps); | ||
const defaultContainerProps = _defaults({}, containerComponent.props, containerProps, userProps); | ||
return /*#__PURE__*/React.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
return /*#__PURE__*/React.cloneElement(groupComponent, userProps); | ||
}, [groupComponent, standalone, containerComponent, containerProps, userProps]); | ||
var events = React.useMemo(function () { | ||
const events = React.useMemo(() => { | ||
return Wrapper.getAllEvents(props); | ||
}, [props]); | ||
var previousProps = Hooks.usePreviousProps(propsWithDefaults); | ||
React.useEffect(function () { | ||
const previousProps = Hooks.usePreviousProps(propsWithDefaults); | ||
React.useEffect(() => { | ||
// This is called before dismount to keep state in sync | ||
return function () { | ||
return () => { | ||
if (propsWithDefaults.animate) { | ||
@@ -119,3 +111,2 @@ setAnimationState(previousProps, propsWithDefaults); | ||
}, [setAnimationState, previousProps, propsWithDefaults]); | ||
if (!_isEmpty(events)) { | ||
@@ -129,12 +120,10 @@ return /*#__PURE__*/React.createElement(VictorySharedEvents, { | ||
} | ||
return /*#__PURE__*/React.cloneElement(container, container.props, newChildren); | ||
}; | ||
var componentConfig = { | ||
const componentConfig = { | ||
role: "stack", | ||
expectedComponents: ["groupComponent", "containerComponent", "labelComponent"], | ||
getChildren: getChildren | ||
getChildren | ||
}; | ||
export var VictoryStack = Object.assign( /*#__PURE__*/React.memo(VictoryStackBase, isEqual), componentConfig); | ||
export const VictoryStack = Object.assign( /*#__PURE__*/React.memo(VictoryStackBase, isEqual), componentConfig); | ||
VictoryStack.displayName = "VictoryStack"; |
@@ -10,41 +10,22 @@ "use strict"; | ||
exports.useMemoizedProps = useMemoizedProps; | ||
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy")); | ||
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 */ | ||
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 = { | ||
const 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) { | ||
var fillInMissingData = props.fillInMissingData; | ||
var xMap = datasets.reduce(function (prev, dataset) { | ||
dataset.forEach(function (datum) { | ||
const { | ||
fillInMissingData | ||
} = props; | ||
const xMap = datasets.reduce((prev, dataset) => { | ||
dataset.forEach(datum => { | ||
prev[datum._x instanceof Date ? datum._x.getTime() : datum._x] = true; | ||
@@ -54,38 +35,30 @@ }); | ||
}, {}); | ||
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]; | ||
const xKeys = Object.keys(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]; | ||
if (datum) { | ||
var x1 = isDate ? datum._x.getTime() : datum._x; | ||
const x1 = isDate ? datum._x.getTime() : datum._x; | ||
if (x1 === parsedX) { | ||
return datum; | ||
} | ||
indexOffset++; | ||
var _y = fillInMissingData ? 0 : null; | ||
const y = fillInMissingData ? 0 : null; | ||
parsedX = isDate ? new Date(parsedX) : parsedX; | ||
return { | ||
x: parsedX, | ||
y: _y, | ||
y, | ||
_x: parsedX, | ||
_y: _y | ||
_y: y | ||
}; | ||
} | ||
var y = fillInMissingData ? 0 : null; | ||
const y = fillInMissingData ? 0 : null; | ||
parsedX = isDate ? new Date(parsedX) : parsedX; | ||
return { | ||
x: parsedX, | ||
y: y, | ||
y, | ||
_x: parsedX, | ||
@@ -98,3 +71,2 @@ _y: y | ||
} | ||
function getY0(datum, index, datasets) { | ||
@@ -104,31 +76,21 @@ if (datum.y0) { | ||
} | ||
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 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 y0 = previousPoints.length && previousPoints.reduce(function (memo, value) { | ||
var sameSign = y < 0 && value < 0 || y >= 0 && value >= 0; | ||
const y0 = previousPoints.length && previousPoints.reduce((memo, value) => { | ||
const sameSign = y < 0 && value < 0 || y >= 0 && value >= 0; | ||
return sameSign ? Number(value) + memo : memo; | ||
}, firstDatasetBaseline[group] || 0); | ||
return previousPoints.some(function (point) { | ||
return point instanceof Date; | ||
}) ? new Date(y0) : y0; | ||
return previousPoints.some(point => point instanceof Date) ? new Date(y0) : y0; | ||
} | ||
/* eslint-disable no-nested-ternary */ | ||
function addLayoutData(props, datasets, index) { | ||
var xOffset = props.xOffset || 0; | ||
return datasets[index].map(function (datum) { | ||
var yOffset = getY0(datum, index, datasets) || 0; | ||
const xOffset = props.xOffset || 0; | ||
return datasets[index].map(datum => { | ||
const yOffset = getY0(datum, index, datasets) || 0; | ||
return Object.assign({}, datum, { | ||
@@ -143,30 +105,16 @@ _y0: !(datum._y instanceof Date) ? yOffset : yOffset ? new Date(yOffset) : datum._y, | ||
function stackData(props, childComponents) { | ||
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); | ||
}); | ||
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)); | ||
} | ||
function getCalculatedProps(initialProps, childComponents) { | ||
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) { | ||
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) => { | ||
return /*#__PURE__*/_react.default.cloneElement(c, { | ||
@@ -176,64 +124,62 @@ data: datasets[i] | ||
}); | ||
var domain = { | ||
const 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) | ||
}; | ||
var range = props.range || { | ||
const range = props.range || { | ||
x: _victoryCore.Helpers.getRange(props, "x"), | ||
y: _victoryCore.Helpers.getRange(props, "y") | ||
}; | ||
var baseScale = { | ||
const baseScale = { | ||
x: _victoryCore.Scale.getScaleFromProps(props, "x") || _victoryCore.Wrapper.getScale(props, "x"), | ||
y: _victoryCore.Scale.getScaleFromProps(props, "y") || _victoryCore.Wrapper.getScale(props, "y") | ||
}; | ||
var scale = { | ||
const 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) | ||
}; | ||
var colorScale = props.colorScale, | ||
horizontal = props.horizontal; | ||
const { | ||
colorScale, | ||
horizontal | ||
} = props; | ||
return { | ||
datasets: datasets, | ||
categories: categories, | ||
range: range, | ||
domain: domain, | ||
horizontal: horizontal, | ||
scale: scale, | ||
style: style, | ||
colorScale: colorScale, | ||
role: role | ||
datasets, | ||
categories, | ||
range, | ||
domain, | ||
horizontal, | ||
scale, | ||
style, | ||
colorScale, | ||
role | ||
}; | ||
} // We need to remove sharedEvents in order to memoize the calculated data | ||
} | ||
// 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 | ||
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), {}, { | ||
const withoutSharedEvents = props => { | ||
const { | ||
children | ||
} = props; | ||
const modifiedChildren = _react.default.Children.toArray(children).map(_child => { | ||
const child = _child; | ||
return { | ||
...child, | ||
props: _victoryCore.Helpers.omit(child.props, ["sharedEvents"]) | ||
}); | ||
}; | ||
}); | ||
props.children = modifiedChildren; | ||
return props; | ||
}; | ||
function useMemoizedProps(initialProps) { | ||
var modifiedProps = withoutSharedEvents(initialProps); | ||
const modifiedProps = withoutSharedEvents(initialProps); | ||
const [props, setProps] = _react.default.useState(modifiedProps); | ||
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 | ||
// React.memo uses shallow equality to compare objects. This way props | ||
// will only be re-calculated when they change. | ||
_react.default.useEffect(function () { | ||
_react.default.useEffect(() => { | ||
if (!(0, _reactFastCompare.default)(modifiedProps, props)) { | ||
@@ -243,8 +189,6 @@ setProps(modifiedProps); | ||
}, [props, setProps, modifiedProps]); | ||
return _react.default.useMemo(function () { | ||
return _react.default.useMemo(() => { | ||
return getCalculatedProps(props, props.children); | ||
}, [props]); | ||
} | ||
function getLabels(props, datasets, index) { | ||
@@ -254,12 +198,12 @@ if (!props.labels) { | ||
} | ||
return datasets.length === index + 1 ? props.labels : undefined; | ||
} | ||
function getChildProps(props, calculatedProps) { | ||
var categories = calculatedProps.categories, | ||
domain = calculatedProps.domain, | ||
range = calculatedProps.range, | ||
scale = calculatedProps.scale, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
@@ -271,48 +215,42 @@ height: props.height, | ||
theme: props.theme, | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
scale: scale, | ||
horizontal: horizontal | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
horizontal | ||
}; | ||
} | ||
function getColorScale(props, child) { | ||
var role = child.type && child.type.role; | ||
var colorScaleOptions = child.props.colorScale || props.colorScale; | ||
const role = child.type && child.type.role; | ||
const 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) { | ||
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); | ||
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}`; | ||
return /*#__PURE__*/_react.default.cloneElement(child, Object.assign({ | ||
key: "".concat(name, "-key-").concat(index), | ||
labels: labels, | ||
name: name, | ||
key: `${name}-key-${index}`, | ||
labels, | ||
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 | ||
@@ -319,0 +257,0 @@ }, childProps)); |
@@ -6,5 +6,3 @@ "use strict"; | ||
}); | ||
var _victoryStack = require("./victory-stack"); | ||
Object.keys(_victoryStack).forEach(function (key) { | ||
@@ -11,0 +9,0 @@ if (key === "default" || key === "__esModule") return; |
@@ -7,26 +7,11 @@ "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 }; } | ||
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 = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -36,3 +21,3 @@ height: 300, | ||
}; | ||
var defaultProps = { | ||
const defaultProps = { | ||
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
@@ -44,42 +29,41 @@ groupComponent: /*#__PURE__*/_react.default.createElement("g", null), | ||
}; | ||
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({ | ||
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({ | ||
animate: getAnimationProps(props, child, index) | ||
@@ -94,47 +78,36 @@ }, child.props); | ||
*/ | ||
return orderedChildren.reverse(); | ||
}, [props, childComponents, calculatedProps, getAnimationProps]); | ||
var containerProps = _react.default.useMemo(function () { | ||
const containerProps = _react.default.useMemo(() => { | ||
if (standalone) { | ||
return { | ||
domain: domain, | ||
scale: scale, | ||
width: width, | ||
height: height, | ||
standalone: standalone, | ||
theme: theme, | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
standalone, | ||
theme, | ||
style: style.parent, | ||
horizontal: horizontal, | ||
polar: polar, | ||
name: name | ||
horizontal, | ||
polar, | ||
name | ||
}; | ||
} | ||
return {}; | ||
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, name]); | ||
var userProps = _react.default.useMemo(function () { | ||
return _victoryCore.UserProps.getSafeUserProps(propsWithDefaults); | ||
}, [propsWithDefaults]); | ||
var container = _react.default.useMemo(function () { | ||
const userProps = _react.default.useMemo(() => _victoryCore.UserProps.getSafeUserProps(propsWithDefaults), [propsWithDefaults]); | ||
const container = _react.default.useMemo(() => { | ||
if (standalone) { | ||
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, userProps); | ||
const 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]); | ||
var events = _react.default.useMemo(function () { | ||
const events = _react.default.useMemo(() => { | ||
return _victoryCore.Wrapper.getAllEvents(props); | ||
}, [props]); | ||
var previousProps = _victoryCore.Hooks.usePreviousProps(propsWithDefaults); | ||
_react.default.useEffect(function () { | ||
const previousProps = _victoryCore.Hooks.usePreviousProps(propsWithDefaults); | ||
_react.default.useEffect(() => { | ||
// This is called before dismount to keep state in sync | ||
return function () { | ||
return () => { | ||
if (propsWithDefaults.animate) { | ||
@@ -145,3 +118,2 @@ setAnimationState(previousProps, propsWithDefaults); | ||
}, [setAnimationState, previousProps, propsWithDefaults]); | ||
if (!(0, _isEmpty2.default)(events)) { | ||
@@ -155,7 +127,5 @@ return /*#__PURE__*/_react.default.createElement(_victorySharedEvents.VictorySharedEvents, { | ||
} | ||
return /*#__PURE__*/_react.default.cloneElement(container, container.props, newChildren); | ||
}; | ||
var componentConfig = { | ||
const componentConfig = { | ||
role: "stack", | ||
@@ -165,4 +135,3 @@ expectedComponents: ["groupComponent", "containerComponent", "labelComponent"], | ||
}; | ||
var VictoryStack = Object.assign( /*#__PURE__*/_react.default.memo(VictoryStackBase, _reactFastCompare.default), componentConfig); | ||
exports.VictoryStack = VictoryStack; | ||
const VictoryStack = exports.VictoryStack = Object.assign( /*#__PURE__*/_react.default.memo(VictoryStackBase, _reactFastCompare.default), componentConfig); | ||
VictoryStack.displayName = "VictoryStack"; |
{ | ||
"name": "victory-stack", | ||
"version": "36.9.2", | ||
"version": "37.0.0", | ||
"description": "Stack Layout Component for Victory", | ||
@@ -25,4 +25,4 @@ "keywords": [ | ||
"react-fast-compare": "^3.2.0", | ||
"victory-core": "^36.9.2", | ||
"victory-shared-events": "^36.9.2" | ||
"victory-core": "^37.0.0", | ||
"victory-shared-events": "^37.0.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
800915
15068
4
+ Addedvictory-core@37.3.4(transitive)
+ Addedvictory-shared-events@37.3.4(transitive)
+ Addedvictory-vendor@37.3.4(transitive)
- Removedvictory-core@36.9.2(transitive)
- Removedvictory-shared-events@36.9.2(transitive)
- Removedvictory-vendor@36.9.2(transitive)
Updatedvictory-core@^37.0.0