victory-stack
Advanced tools
Comparing version 35.10.1 to 35.11.0
@@ -9,17 +9,5 @@ import _isEmpty from "lodash/isEmpty"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes } from "victory-core"; | ||
import { Helpers, VictoryContainer, VictoryTheme, CommonProps, Wrapper, PropTypes as CustomPropTypes, useAnimationState, usePreviousProps } from "victory-core"; | ||
import { VictorySharedEvents } from "victory-shared-events"; | ||
@@ -34,79 +22,49 @@ import { getChildren, getCalculatedProps } from "./helper-methods"; | ||
var VictoryStack = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(VictoryStack, _React$Component); | ||
var VictoryStack = function (initialProps) { | ||
// eslint-disable-next-line no-use-before-define | ||
var role = VictoryStackMemo.role; | ||
function VictoryStack(props) { | ||
var _this; | ||
var _useAnimationState = useAnimationState(), | ||
setAnimationState = _useAnimationState.setAnimationState, | ||
getAnimationProps = _useAnimationState.getAnimationProps, | ||
getProps = _useAnimationState.getProps; | ||
_classCallCheck(this, VictoryStack); | ||
var props = getProps(initialProps); | ||
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 = getCalculatedProps(modifiedProps, childComponents); | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin; | ||
var newChildren = React.useMemo(function () { | ||
var children = getChildren(props, childComponents, calculatedProps); | ||
var orderedChildren = children.map(function (child, index) { | ||
var childProps = _assign({ | ||
animate: getAnimationProps(props, child, index, "victory-stack") | ||
}, child.props); | ||
_this = _possibleConstructorReturn(this, (VictoryStack.__proto__ || Object.getPrototypeOf(VictoryStack)).call(this, props)); | ||
return React.cloneElement(child, childProps); | ||
}); | ||
/* | ||
reverse render order for children of `VictoryStack` so that higher children in the stack | ||
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and | ||
areas with strokes | ||
*/ | ||
if (props.animate) { | ||
_this.state = { | ||
nodesShouldLoad: false, | ||
nodesDoneLoad: false, | ||
animating: true | ||
}; | ||
_this.setAnimationState = Wrapper.setAnimationState.bind(_assertThisInitialized(_this)); | ||
} | ||
return _this; | ||
} | ||
_createClass(VictoryStack, [{ | ||
key: "shouldComponentUpdate", | ||
value: function shouldComponentUpdate(nextProps) { | ||
if (this.props.animate) { | ||
if (!isEqual(this.props, nextProps)) { | ||
this.setAnimationState(this.props, nextProps); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
}, { | ||
key: "getNewChildren", | ||
value: function getNewChildren(props, childComponents, calculatedProps) { | ||
var children = getChildren(props, childComponents, calculatedProps); | ||
var getAnimationProps = Wrapper.getAnimationProps.bind(this); | ||
var newChildren = children.map(function (child, index) { | ||
var childProps = _assign({ | ||
animate: getAnimationProps(props, child, index) | ||
}, child.props); | ||
return React.cloneElement(child, childProps); | ||
}); | ||
/* | ||
reverse render order for children of `VictoryStack` so that higher children in the stack | ||
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and | ||
areas with strokes | ||
*/ | ||
return newChildren.reverse(); | ||
} | ||
}, { | ||
key: "renderContainer", | ||
value: function renderContainer(containerComponent, props) { | ||
var containerProps = _defaults({}, containerComponent.props, props); | ||
return React.cloneElement(containerComponent, containerProps); | ||
} | ||
}, { | ||
key: "getContainerProps", | ||
value: function getContainerProps(props, calculatedProps) { | ||
var width = props.width, | ||
height = props.height, | ||
standalone = props.standalone, | ||
theme = props.theme, | ||
polar = props.polar, | ||
horizontal = props.horizontal, | ||
name = props.name; | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin; | ||
return orderedChildren.reverse(); | ||
}, [props, childComponents, calculatedProps, getAnimationProps]); | ||
var containerProps = React.useMemo(function () { | ||
if (standalone) { | ||
return { | ||
@@ -126,96 +84,70 @@ domain: domain, | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var role = this.constructor.role; | ||
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props; | ||
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role); | ||
var eventKey = modifiedProps.eventKey, | ||
containerComponent = modifiedProps.containerComponent, | ||
standalone = modifiedProps.standalone, | ||
groupComponent = modifiedProps.groupComponent, | ||
externalEventMutations = modifiedProps.externalEventMutations; | ||
var childComponents = React.Children.toArray(modifiedProps.children); | ||
var calculatedProps = getCalculatedProps(modifiedProps, childComponents); | ||
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps); | ||
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {}; | ||
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent; | ||
var events = Wrapper.getAllEvents(props); | ||
if (!_isEmpty(events)) { | ||
return React.createElement(VictorySharedEvents, { | ||
container: container, | ||
eventKey: eventKey, | ||
events: events, | ||
externalEventMutations: externalEventMutations | ||
}, newChildren); | ||
} | ||
return {}; | ||
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]); | ||
var container = React.useMemo(function () { | ||
if (standalone) { | ||
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps); | ||
return React.cloneElement(container, container.props, newChildren); | ||
return React.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
}]); | ||
return VictoryStack; | ||
}(React.Component); | ||
return groupComponent; | ||
}, [groupComponent, standalone, containerComponent, containerProps]); | ||
var events = React.useMemo(function () { | ||
return Wrapper.getAllEvents(props); | ||
}, [props]); | ||
var previousProps = usePreviousProps(initialProps); | ||
React.useEffect(function () { | ||
// This is called before dismount to keep state in sync | ||
return function () { | ||
if (initialProps.animate) { | ||
setAnimationState(previousProps, initialProps); | ||
} | ||
}; | ||
}, [setAnimationState, previousProps, initialProps]); | ||
Object.defineProperty(VictoryStack, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: "VictoryStack" | ||
}); | ||
Object.defineProperty(VictoryStack, "role", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: "stack" | ||
}); | ||
Object.defineProperty(VictoryStack, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: _objectSpread({}, CommonProps.baseProps, { | ||
bins: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.instanceOf(Date)])), CustomPropTypes.nonNegative]), | ||
categories: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.shape({ | ||
x: PropTypes.arrayOf(PropTypes.string), | ||
y: PropTypes.arrayOf(PropTypes.string) | ||
})]), | ||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]), | ||
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]), | ||
fillInMissingData: PropTypes.bool, | ||
horizontal: PropTypes.bool, | ||
labelComponent: PropTypes.element, | ||
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), | ||
style: PropTypes.shape({ | ||
parent: PropTypes.object, | ||
data: PropTypes.object, | ||
labels: PropTypes.object | ||
}), | ||
xOffset: PropTypes.number | ||
}) | ||
}); | ||
Object.defineProperty(VictoryStack, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
containerComponent: React.createElement(VictoryContainer, null), | ||
groupComponent: React.createElement("g", null), | ||
standalone: true, | ||
theme: VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
if (!_isEmpty(events)) { | ||
return React.createElement(VictorySharedEvents, { | ||
container: container, | ||
eventKey: eventKey, | ||
events: events, | ||
externalEventMutations: externalEventMutations | ||
}, newChildren); | ||
} | ||
return React.cloneElement(container, container.props, newChildren); | ||
}; | ||
VictoryStack.propTypes = _objectSpread({}, CommonProps.baseProps, { | ||
bins: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.instanceOf(Date)])), CustomPropTypes.nonNegative]), | ||
categories: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.shape({ | ||
x: PropTypes.arrayOf(PropTypes.string), | ||
y: PropTypes.arrayOf(PropTypes.string) | ||
})]), | ||
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]), | ||
colorScale: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]), | ||
fillInMissingData: PropTypes.bool, | ||
horizontal: PropTypes.bool, | ||
labelComponent: PropTypes.element, | ||
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), | ||
style: PropTypes.shape({ | ||
parent: PropTypes.object, | ||
data: PropTypes.object, | ||
labels: PropTypes.object | ||
}), | ||
xOffset: PropTypes.number | ||
}); | ||
Object.defineProperty(VictoryStack, "expectedComponents", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: ["groupComponent", "containerComponent", "labelComponent"] | ||
}); | ||
Object.defineProperty(VictoryStack, "getChildren", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: getChildren | ||
}); | ||
export { VictoryStack as default }; | ||
VictoryStack.defaultProps = { | ||
containerComponent: React.createElement(VictoryContainer, null), | ||
groupComponent: React.createElement("g", null), | ||
standalone: true, | ||
theme: VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
}; | ||
var VictoryStackMemo = React.memo(VictoryStack, isEqual); | ||
VictoryStackMemo.displayName = "VictoryStack"; | ||
VictoryStackMemo.role = "stack"; | ||
VictoryStackMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"]; | ||
VictoryStackMemo.getChildren = getChildren; | ||
export default VictoryStackMemo; |
@@ -32,14 +32,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
var fallbackProps = { | ||
@@ -51,79 +39,54 @@ width: 450, | ||
var VictoryStack = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(VictoryStack, _React$Component); | ||
var VictoryStack = function (initialProps) { | ||
// eslint-disable-next-line no-use-before-define | ||
var role = VictoryStackMemo.role; | ||
function VictoryStack(props) { | ||
var _this; | ||
var _useAnimationState = (0, _victoryCore.useAnimationState)(), | ||
setAnimationState = _useAnimationState.setAnimationState, | ||
getAnimationProps = _useAnimationState.getAnimationProps, | ||
getProps = _useAnimationState.getProps; | ||
_classCallCheck(this, VictoryStack); | ||
var props = getProps(initialProps); | ||
_this = _possibleConstructorReturn(this, (VictoryStack.__proto__ || Object.getPrototypeOf(VictoryStack)).call(this, props)); | ||
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role); | ||
if (props.animate) { | ||
_this.state = { | ||
nodesShouldLoad: false, | ||
nodesDoneLoad: false, | ||
animating: true | ||
}; | ||
_this.setAnimationState = _victoryCore.Wrapper.setAnimationState.bind(_assertThisInitialized(_this)); | ||
} | ||
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; | ||
return _this; | ||
} | ||
var childComponents = _react.default.Children.toArray(modifiedProps.children); | ||
_createClass(VictoryStack, [{ | ||
key: "shouldComponentUpdate", | ||
value: function shouldComponentUpdate(nextProps) { | ||
if (this.props.animate) { | ||
if (!(0, _reactFastCompare.default)(this.props, nextProps)) { | ||
this.setAnimationState(this.props, nextProps); | ||
return false; | ||
} | ||
} | ||
var calculatedProps = (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents); | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin; | ||
return true; | ||
} | ||
}, { | ||
key: "getNewChildren", | ||
value: function getNewChildren(props, childComponents, calculatedProps) { | ||
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps); | ||
var newChildren = _react.default.useMemo(function () { | ||
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps); | ||
var orderedChildren = children.map(function (child, index) { | ||
var childProps = (0, _assign2.default)({ | ||
animate: getAnimationProps(props, child, index, "victory-stack") | ||
}, child.props); | ||
return _react.default.cloneElement(child, childProps); | ||
}); | ||
/* | ||
reverse render order for children of `VictoryStack` so that higher children in the stack | ||
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and | ||
areas with strokes | ||
*/ | ||
var getAnimationProps = _victoryCore.Wrapper.getAnimationProps.bind(this); | ||
return orderedChildren.reverse(); | ||
}, [props, childComponents, calculatedProps, getAnimationProps]); | ||
var newChildren = children.map(function (child, index) { | ||
var childProps = (0, _assign2.default)({ | ||
animate: getAnimationProps(props, child, index) | ||
}, child.props); | ||
return _react.default.cloneElement(child, childProps); | ||
}); | ||
/* | ||
reverse render order for children of `VictoryStack` so that higher children in the stack | ||
are rendered behind lower children. This looks nicer for stacked bars with cornerRadius, and | ||
areas with strokes | ||
*/ | ||
return newChildren.reverse(); | ||
} | ||
}, { | ||
key: "renderContainer", | ||
value: function renderContainer(containerComponent, props) { | ||
var containerProps = (0, _defaults2.default)({}, containerComponent.props, props); | ||
return _react.default.cloneElement(containerComponent, containerProps); | ||
} | ||
}, { | ||
key: "getContainerProps", | ||
value: function getContainerProps(props, calculatedProps) { | ||
var width = props.width, | ||
height = props.height, | ||
standalone = props.standalone, | ||
theme = props.theme, | ||
polar = props.polar, | ||
horizontal = props.horizontal, | ||
name = props.name; | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin; | ||
var containerProps = _react.default.useMemo(function () { | ||
if (standalone) { | ||
return { | ||
@@ -143,101 +106,76 @@ domain: domain, | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var role = this.constructor.role; | ||
var props = this.state && this.state.nodesWillExit ? this.state.oldProps || this.props : this.props; | ||
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role); | ||
return {}; | ||
}, [standalone, domain, scale, width, height, theme, style, horizontal, polar, origin, name]); | ||
var eventKey = modifiedProps.eventKey, | ||
containerComponent = modifiedProps.containerComponent, | ||
standalone = modifiedProps.standalone, | ||
groupComponent = modifiedProps.groupComponent, | ||
externalEventMutations = modifiedProps.externalEventMutations; | ||
var container = _react.default.useMemo(function () { | ||
if (standalone) { | ||
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps); | ||
return _react.default.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
var childComponents = _react.default.Children.toArray(modifiedProps.children); | ||
return groupComponent; | ||
}, [groupComponent, standalone, containerComponent, containerProps]); | ||
var calculatedProps = (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents); | ||
var newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps); | ||
var containerProps = standalone ? this.getContainerProps(modifiedProps, calculatedProps) : {}; | ||
var container = standalone ? this.renderContainer(containerComponent, containerProps) : groupComponent; | ||
var events = _react.default.useMemo(function () { | ||
return _victoryCore.Wrapper.getAllEvents(props); | ||
}, [props]); | ||
var events = _victoryCore.Wrapper.getAllEvents(props); | ||
var previousProps = (0, _victoryCore.usePreviousProps)(initialProps); | ||
if (!(0, _isEmpty2.default)(events)) { | ||
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, { | ||
container: container, | ||
eventKey: eventKey, | ||
events: events, | ||
externalEventMutations: externalEventMutations | ||
}, newChildren); | ||
_react.default.useEffect(function () { | ||
// This is called before dismount to keep state in sync | ||
return function () { | ||
if (initialProps.animate) { | ||
setAnimationState(previousProps, initialProps); | ||
} | ||
}; | ||
}, [setAnimationState, previousProps, initialProps]); | ||
return _react.default.cloneElement(container, container.props, newChildren); | ||
} | ||
}]); | ||
if (!(0, _isEmpty2.default)(events)) { | ||
return _react.default.createElement(_victorySharedEvents.VictorySharedEvents, { | ||
container: container, | ||
eventKey: eventKey, | ||
events: events, | ||
externalEventMutations: externalEventMutations | ||
}, newChildren); | ||
} | ||
return VictoryStack; | ||
}(_react.default.Component); | ||
return _react.default.cloneElement(container, container.props, newChildren); | ||
}; | ||
exports.default = VictoryStack; | ||
Object.defineProperty(VictoryStack, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: "VictoryStack" | ||
VictoryStack.propTypes = _objectSpread({}, _victoryCore.CommonProps.baseProps, { | ||
bins: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_victoryCore.PropTypes.nonNegative, _propTypes.default.instanceOf(Date)])), _victoryCore.PropTypes.nonNegative]), | ||
categories: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.shape({ | ||
x: _propTypes.default.arrayOf(_propTypes.default.string), | ||
y: _propTypes.default.arrayOf(_propTypes.default.string) | ||
})]), | ||
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]), | ||
colorScale: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]), | ||
fillInMissingData: _propTypes.default.bool, | ||
horizontal: _propTypes.default.bool, | ||
labelComponent: _propTypes.default.element, | ||
labels: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.array]), | ||
style: _propTypes.default.shape({ | ||
parent: _propTypes.default.object, | ||
data: _propTypes.default.object, | ||
labels: _propTypes.default.object | ||
}), | ||
xOffset: _propTypes.default.number | ||
}); | ||
Object.defineProperty(VictoryStack, "role", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: "stack" | ||
}); | ||
Object.defineProperty(VictoryStack, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: _objectSpread({}, _victoryCore.CommonProps.baseProps, { | ||
bins: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_victoryCore.PropTypes.nonNegative, _propTypes.default.instanceOf(Date)])), _victoryCore.PropTypes.nonNegative]), | ||
categories: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.shape({ | ||
x: _propTypes.default.arrayOf(_propTypes.default.string), | ||
y: _propTypes.default.arrayOf(_propTypes.default.string) | ||
})]), | ||
children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]), | ||
colorScale: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.oneOf(["grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"])]), | ||
fillInMissingData: _propTypes.default.bool, | ||
horizontal: _propTypes.default.bool, | ||
labelComponent: _propTypes.default.element, | ||
labels: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.array]), | ||
style: _propTypes.default.shape({ | ||
parent: _propTypes.default.object, | ||
data: _propTypes.default.object, | ||
labels: _propTypes.default.object | ||
}), | ||
xOffset: _propTypes.default.number | ||
}) | ||
}); | ||
Object.defineProperty(VictoryStack, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: { | ||
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null), | ||
groupComponent: _react.default.createElement("g", null), | ||
standalone: true, | ||
theme: _victoryCore.VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
} | ||
}); | ||
Object.defineProperty(VictoryStack, "expectedComponents", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: ["groupComponent", "containerComponent", "labelComponent"] | ||
}); | ||
Object.defineProperty(VictoryStack, "getChildren", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: _helperMethods.getChildren | ||
}); | ||
VictoryStack.defaultProps = { | ||
containerComponent: _react.default.createElement(_victoryCore.VictoryContainer, null), | ||
groupComponent: _react.default.createElement("g", null), | ||
standalone: true, | ||
theme: _victoryCore.VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
}; | ||
var VictoryStackMemo = _react.default.memo(VictoryStack, _reactFastCompare.default); | ||
VictoryStackMemo.displayName = "VictoryStack"; | ||
VictoryStackMemo.role = "stack"; | ||
VictoryStackMemo.expectedComponents = ["groupComponent", "containerComponent", "labelComponent"]; | ||
VictoryStackMemo.getChildren = _helperMethods.getChildren; | ||
var _default = VictoryStackMemo; | ||
exports.default = _default; |
{ | ||
"name": "victory-stack", | ||
"version": "35.10.1", | ||
"version": "35.11.0", | ||
"description": "Stack Layout Component for Victory", | ||
@@ -25,4 +25,4 @@ "keywords": [ | ||
"react-fast-compare": "^2.0.0", | ||
"victory-core": "^35.10.1", | ||
"victory-shared-events": "^35.10.1" | ||
"victory-core": "^35.11.0", | ||
"victory-shared-events": "^35.11.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "peerDependencies": { |
@@ -10,3 +10,5 @@ import { assign, defaults, isEmpty } from "lodash"; | ||
Wrapper, | ||
PropTypes as CustomPropTypes | ||
PropTypes as CustomPropTypes, | ||
useAnimationState, | ||
usePreviousProps | ||
} from "victory-core"; | ||
@@ -23,98 +25,34 @@ import { VictorySharedEvents } from "victory-shared-events"; | ||
export default class VictoryStack extends React.Component { | ||
static displayName = "VictoryStack"; | ||
const VictoryStack = (initialProps) => { | ||
// eslint-disable-next-line no-use-before-define | ||
const { role } = VictoryStackMemo; | ||
const { setAnimationState, getAnimationProps, getProps } = | ||
useAnimationState(); | ||
static role = "stack"; | ||
const props = getProps(initialProps); | ||
static propTypes = { | ||
...CommonProps.baseProps, | ||
bins: PropTypes.oneOfType([ | ||
PropTypes.arrayOf( | ||
PropTypes.oneOfType([ | ||
CustomPropTypes.nonNegative, | ||
PropTypes.instanceOf(Date) | ||
]) | ||
), | ||
CustomPropTypes.nonNegative | ||
]), | ||
categories: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.shape({ | ||
x: PropTypes.arrayOf(PropTypes.string), | ||
y: PropTypes.arrayOf(PropTypes.string) | ||
}) | ||
]), | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.node), | ||
PropTypes.node | ||
]), | ||
colorScale: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.oneOf([ | ||
"grayscale", | ||
"qualitative", | ||
"heatmap", | ||
"warm", | ||
"cool", | ||
"red", | ||
"green", | ||
"blue" | ||
]) | ||
]), | ||
fillInMissingData: PropTypes.bool, | ||
horizontal: PropTypes.bool, | ||
labelComponent: PropTypes.element, | ||
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), | ||
style: PropTypes.shape({ | ||
parent: PropTypes.object, | ||
data: PropTypes.object, | ||
labels: PropTypes.object | ||
}), | ||
xOffset: PropTypes.number | ||
}; | ||
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); | ||
const { | ||
eventKey, | ||
containerComponent, | ||
standalone, | ||
groupComponent, | ||
externalEventMutations, | ||
width, | ||
height, | ||
theme, | ||
polar, | ||
horizontal, | ||
name | ||
} = modifiedProps; | ||
static defaultProps = { | ||
containerComponent: <VictoryContainer />, | ||
groupComponent: <g />, | ||
standalone: true, | ||
theme: VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
}; | ||
const childComponents = React.Children.toArray(modifiedProps.children); | ||
const calculatedProps = getCalculatedProps(modifiedProps, childComponents); | ||
const { domain, scale, style, origin } = calculatedProps; | ||
static expectedComponents = [ | ||
"groupComponent", | ||
"containerComponent", | ||
"labelComponent" | ||
]; | ||
static getChildren = getChildren; | ||
constructor(props) { | ||
super(props); | ||
if (props.animate) { | ||
this.state = { | ||
nodesShouldLoad: false, | ||
nodesDoneLoad: false, | ||
animating: true | ||
}; | ||
this.setAnimationState = Wrapper.setAnimationState.bind(this); | ||
} | ||
} | ||
shouldComponentUpdate(nextProps) { | ||
if (this.props.animate) { | ||
if (!isEqual(this.props, nextProps)) { | ||
this.setAnimationState(this.props, nextProps); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
getNewChildren(props, childComponents, calculatedProps) { | ||
const newChildren = React.useMemo(() => { | ||
const children = getChildren(props, childComponents, calculatedProps); | ||
const getAnimationProps = Wrapper.getAnimationProps.bind(this); | ||
const newChildren = children.map((child, index) => { | ||
const orderedChildren = children.map((child, index) => { | ||
const childProps = assign( | ||
{ animate: getAnimationProps(props, child, index) }, | ||
{ animate: getAnimationProps(props, child, index, "victory-stack") }, | ||
child.props | ||
@@ -129,71 +67,147 @@ ); | ||
*/ | ||
return newChildren.reverse(); | ||
} | ||
return orderedChildren.reverse(); | ||
}, [props, childComponents, calculatedProps, getAnimationProps]); | ||
renderContainer(containerComponent, props) { | ||
const containerProps = defaults({}, containerComponent.props, props); | ||
return React.cloneElement(containerComponent, containerProps); | ||
} | ||
const containerProps = React.useMemo(() => { | ||
if (standalone) { | ||
return { | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
standalone, | ||
theme, | ||
style: style.parent, | ||
horizontal, | ||
polar, | ||
origin, | ||
name | ||
}; | ||
} | ||
return {}; | ||
}, [ | ||
standalone, | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
theme, | ||
style, | ||
horizontal, | ||
polar, | ||
origin, | ||
name | ||
]); | ||
getContainerProps(props, calculatedProps) { | ||
const { width, height, standalone, theme, polar, horizontal, name } = props; | ||
const { domain, scale, style, origin } = calculatedProps; | ||
return { | ||
domain, | ||
scale, | ||
width, | ||
height, | ||
standalone, | ||
theme, | ||
style: style.parent, | ||
horizontal, | ||
polar, | ||
origin, | ||
name | ||
const container = React.useMemo(() => { | ||
if (standalone) { | ||
const defaultContainerProps = defaults( | ||
{}, | ||
containerComponent.props, | ||
containerProps | ||
); | ||
return React.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
return groupComponent; | ||
}, [groupComponent, standalone, containerComponent, containerProps]); | ||
const events = React.useMemo(() => { | ||
return Wrapper.getAllEvents(props); | ||
}, [props]); | ||
const previousProps = usePreviousProps(initialProps); | ||
React.useEffect(() => { | ||
// This is called before dismount to keep state in sync | ||
return () => { | ||
if (initialProps.animate) { | ||
setAnimationState(previousProps, initialProps); | ||
} | ||
}; | ||
} | ||
}, [setAnimationState, previousProps, initialProps]); | ||
render() { | ||
const { role } = this.constructor; | ||
const props = | ||
this.state && this.state.nodesWillExit | ||
? this.state.oldProps || this.props | ||
: this.props; | ||
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); | ||
const { | ||
eventKey, | ||
containerComponent, | ||
standalone, | ||
groupComponent, | ||
externalEventMutations | ||
} = modifiedProps; | ||
const childComponents = React.Children.toArray(modifiedProps.children); | ||
const calculatedProps = getCalculatedProps(modifiedProps, childComponents); | ||
const newChildren = this.getNewChildren( | ||
modifiedProps, | ||
childComponents, | ||
calculatedProps | ||
if (!isEmpty(events)) { | ||
return ( | ||
<VictorySharedEvents | ||
container={container} | ||
eventKey={eventKey} | ||
events={events} | ||
externalEventMutations={externalEventMutations} | ||
> | ||
{newChildren} | ||
</VictorySharedEvents> | ||
); | ||
const containerProps = standalone | ||
? this.getContainerProps(modifiedProps, calculatedProps) | ||
: {}; | ||
const container = standalone | ||
? this.renderContainer(containerComponent, containerProps) | ||
: groupComponent; | ||
const events = Wrapper.getAllEvents(props); | ||
if (!isEmpty(events)) { | ||
return ( | ||
<VictorySharedEvents | ||
container={container} | ||
eventKey={eventKey} | ||
events={events} | ||
externalEventMutations={externalEventMutations} | ||
> | ||
{newChildren} | ||
</VictorySharedEvents> | ||
); | ||
} | ||
} | ||
return React.cloneElement(container, container.props, newChildren); | ||
} | ||
} | ||
return React.cloneElement(container, container.props, newChildren); | ||
}; | ||
VictoryStack.propTypes = { | ||
...CommonProps.baseProps, | ||
bins: PropTypes.oneOfType([ | ||
PropTypes.arrayOf( | ||
PropTypes.oneOfType([ | ||
CustomPropTypes.nonNegative, | ||
PropTypes.instanceOf(Date) | ||
]) | ||
), | ||
CustomPropTypes.nonNegative | ||
]), | ||
categories: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.shape({ | ||
x: PropTypes.arrayOf(PropTypes.string), | ||
y: PropTypes.arrayOf(PropTypes.string) | ||
}) | ||
]), | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.node), | ||
PropTypes.node | ||
]), | ||
colorScale: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.oneOf([ | ||
"grayscale", | ||
"qualitative", | ||
"heatmap", | ||
"warm", | ||
"cool", | ||
"red", | ||
"green", | ||
"blue" | ||
]) | ||
]), | ||
fillInMissingData: PropTypes.bool, | ||
horizontal: PropTypes.bool, | ||
labelComponent: PropTypes.element, | ||
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), | ||
style: PropTypes.shape({ | ||
parent: PropTypes.object, | ||
data: PropTypes.object, | ||
labels: PropTypes.object | ||
}), | ||
xOffset: PropTypes.number | ||
}; | ||
VictoryStack.defaultProps = { | ||
containerComponent: <VictoryContainer />, | ||
groupComponent: <g />, | ||
standalone: true, | ||
theme: VictoryTheme.grayscale, | ||
fillInMissingData: true | ||
}; | ||
const VictoryStackMemo = React.memo(VictoryStack, isEqual); | ||
VictoryStackMemo.displayName = "VictoryStack"; | ||
VictoryStackMemo.role = "stack"; | ||
VictoryStackMemo.expectedComponents = [ | ||
"groupComponent", | ||
"containerComponent", | ||
"labelComponent" | ||
]; | ||
VictoryStackMemo.getChildren = getChildren; | ||
export default VictoryStackMemo; |
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
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
932072
18038
Updatedvictory-core@^35.11.0