victory-chart
Advanced tools
Comparing version 36.9.2 to 37.0.0
# victory-chart | ||
## 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 _defaults from "lodash/defaults"; | ||
/* eslint-disable no-use-before-define */ | ||
/* eslint-disable no-use-before-define */ | ||
import React from "react"; | ||
import { Helpers, Scale, Axis, Wrapper } from "victory-core"; | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -11,32 +11,32 @@ height: 300, | ||
}; | ||
function getAxisProps(child, props, calculatedProps) { | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
stringMap = calculatedProps.stringMap, | ||
categories = calculatedProps.categories, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
domain, | ||
scale, | ||
stringMap, | ||
categories, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
stringMap: stringMap, | ||
horizontal: horizontal, | ||
categories: categories, | ||
stringMap, | ||
horizontal, | ||
categories, | ||
startAngle: props.startAngle, | ||
endAngle: props.endAngle, | ||
innerRadius: props.innerRadius, | ||
domain: domain, | ||
scale: scale | ||
domain, | ||
scale | ||
}; | ||
} | ||
export function getBackgroundWithProps(props, calculatedProps) { | ||
var backgroundElement = props.backgroundComponent; | ||
var height = props.polar ? calculatedProps.range.y[1] : calculatedProps.range.y[0] - calculatedProps.range.y[1]; | ||
var width = calculatedProps.range.x[1] - calculatedProps.range.x[0]; | ||
var xScale = props.horizontal ? calculatedProps.scale.y.range()[0] : calculatedProps.scale.x.range()[0]; | ||
var yScale = props.horizontal ? calculatedProps.scale.x.range()[1] : calculatedProps.scale.y.range()[1]; | ||
var xCoordinate = props.polar ? calculatedProps.origin.x : xScale; | ||
var yCoordinate = props.polar ? calculatedProps.origin.y : yScale; | ||
var parentName = props.name || "chart"; | ||
var backgroundProps = { | ||
height: height, | ||
const backgroundElement = props.backgroundComponent; | ||
const height = props.polar ? calculatedProps.range.y[1] : calculatedProps.range.y[0] - calculatedProps.range.y[1]; | ||
const width = calculatedProps.range.x[1] - calculatedProps.range.x[0]; | ||
const xScale = props.horizontal ? calculatedProps.scale.y.range()[0] : calculatedProps.scale.x.range()[0]; | ||
const yScale = props.horizontal ? calculatedProps.scale.x.range()[1] : calculatedProps.scale.y.range()[1]; | ||
const xCoordinate = props.polar ? calculatedProps.origin.x : xScale; | ||
const yCoordinate = props.polar ? calculatedProps.origin.y : yScale; | ||
const parentName = props.name || "chart"; | ||
const backgroundProps = { | ||
height, | ||
polar: props.polar, | ||
@@ -47,33 +47,31 @@ scale: calculatedProps.scale, | ||
y: yCoordinate, | ||
key: "".concat(parentName, "-background"), | ||
width: width | ||
key: `${parentName}-background`, | ||
width | ||
}; | ||
return /*#__PURE__*/React.cloneElement(backgroundElement, _defaults({}, backgroundElement.props, backgroundProps)); | ||
} | ||
function getChildProps(child, props, calculatedProps) { | ||
var axisChild = Axis.findAxisComponents([child]); | ||
const axisChild = Axis.findAxisComponents([child]); | ||
if (axisChild.length > 0) { | ||
return getAxisProps(axisChild[0], props, calculatedProps); | ||
} | ||
var categories = calculatedProps.categories, | ||
domain = calculatedProps.domain, | ||
range = calculatedProps.range, | ||
scale = calculatedProps.scale, | ||
stringMap = calculatedProps.stringMap, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
stringMap, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
scale: scale, | ||
stringMap: stringMap, | ||
horizontal: horizontal | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
stringMap, | ||
horizontal | ||
}; | ||
} | ||
function getStyles(props) { | ||
var styleProps = props.style && props.style.parent; | ||
const styleProps = props.style && props.style.parent; | ||
return { | ||
@@ -87,92 +85,93 @@ parent: _defaults({}, styleProps, { | ||
} | ||
export function getCalculatedProps(initialProps, childComponents) { | ||
var style = getStyles(initialProps); | ||
var props = Helpers.modifyProps(initialProps, fallbackProps, "chart"); | ||
var horizontal = props.horizontal, | ||
polar = props.polar; | ||
var allStrings = Wrapper.getStringsFromChildren(props, childComponents); | ||
var categories = Wrapper.getCategories(props, childComponents, allStrings); | ||
var stringMap = createStringMap(props, childComponents, allStrings); | ||
var domain = { | ||
const style = getStyles(initialProps); | ||
const props = Helpers.modifyProps(initialProps, fallbackProps, "chart"); | ||
const { | ||
horizontal, | ||
polar | ||
} = props; | ||
const allStrings = Wrapper.getStringsFromChildren(props, childComponents); | ||
const categories = Wrapper.getCategories(props, childComponents, allStrings); | ||
const stringMap = createStringMap(props, childComponents, allStrings); | ||
const domain = { | ||
x: getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "x", childComponents), | ||
y: getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "y", childComponents) | ||
}; | ||
var range = { | ||
const 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(horizontal ? range.y : range.x), | ||
y: baseScale.y.domain(domain.y).range(horizontal ? range.x : range.y) | ||
}; | ||
var origin = polar ? Helpers.getPolarOrigin(props) : Axis.getOrigin(domain); | ||
var padding = Helpers.getPadding(props); | ||
const origin = polar ? Helpers.getPolarOrigin(props) : Axis.getOrigin(domain); | ||
const padding = Helpers.getPadding(props); | ||
return { | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
horizontal: horizontal, | ||
scale: scale, | ||
stringMap: stringMap, | ||
style: style, | ||
origin: origin, | ||
padding: padding | ||
categories, | ||
domain, | ||
range, | ||
horizontal, | ||
scale, | ||
stringMap, | ||
style, | ||
origin, | ||
padding | ||
}; | ||
} | ||
export function getChildren(props, childComponents, calculatedProps) { | ||
var children = childComponents || getChildComponents(props); | ||
var newCalculatedProps = calculatedProps || getCalculatedProps(props, children); | ||
var baseStyle = newCalculatedProps.style.parent; | ||
var height = props.height, | ||
polar = props.polar, | ||
theme = props.theme, | ||
width = props.width; | ||
var origin = newCalculatedProps.origin, | ||
horizontal = newCalculatedProps.horizontal; | ||
var parentName = props.name || "chart"; | ||
return children.filter(React.isValidElement).map(function (child, index) { | ||
var role = child.type && child.type.role; | ||
var style = Array.isArray(child.props.style) ? child.props.style : _defaults({}, child.props.style, { | ||
const children = childComponents || getChildComponents(props); | ||
const newCalculatedProps = calculatedProps || getCalculatedProps(props, children); | ||
const baseStyle = newCalculatedProps.style.parent; | ||
const { | ||
height, | ||
polar, | ||
theme, | ||
width | ||
} = props; | ||
const { | ||
origin, | ||
horizontal | ||
} = newCalculatedProps; | ||
const parentName = props.name || "chart"; | ||
return children.filter(React.isValidElement).map((child, index) => { | ||
const role = child.type && child.type.role; | ||
const style = Array.isArray(child.props.style) ? child.props.style : _defaults({}, child.props.style, { | ||
parent: baseStyle | ||
}); | ||
var childProps = getChildProps(child, props, newCalculatedProps); | ||
var name = child.props.name || "".concat(parentName, "-").concat(role, "-").concat(index); | ||
var newProps = _defaults({ | ||
horizontal: horizontal, | ||
height: height, | ||
polar: polar, | ||
theme: theme, | ||
width: width, | ||
style: style, | ||
name: name, | ||
const childProps = getChildProps(child, props, newCalculatedProps); | ||
const name = child.props.name || `${parentName}-${role}-${index}`; | ||
const newProps = _defaults({ | ||
horizontal, | ||
height, | ||
polar, | ||
theme, | ||
width, | ||
style, | ||
name, | ||
origin: polar ? origin : undefined, | ||
padding: newCalculatedProps.padding, | ||
key: "".concat(name, "-key-").concat(index), | ||
key: `${name}-key-${index}`, | ||
standalone: false | ||
}, childProps); | ||
return /*#__PURE__*/React.cloneElement(child, newProps); | ||
}); | ||
} | ||
export var getChildComponents = function (props, defaultAxes) { | ||
var childComponents = React.Children.toArray(props.children); | ||
export const getChildComponents = (props, defaultAxes) => { | ||
let childComponents = React.Children.toArray(props.children); | ||
if (childComponents.length === 0) { | ||
childComponents.push(defaultAxes.independent, defaultAxes.dependent); | ||
} else { | ||
var axisComponents = { | ||
const axisComponents = { | ||
dependent: Axis.getAxisComponentsWithParent(childComponents, "dependent"), | ||
independent: Axis.getAxisComponentsWithParent(childComponents, "independent") | ||
}; | ||
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) { | ||
@@ -182,20 +181,17 @@ childComponents = props.prependDefaultAxes ? [defaultAxes.independent, defaultAxes.dependent].concat(childComponents) : childComponents.concat([defaultAxes.independent, defaultAxes.dependent]); | ||
} | ||
return childComponents; | ||
}; | ||
var getDomain = function (props, axis, childComponents) { | ||
var children = childComponents || React.Children.toArray(props.children); | ||
var domain = Wrapper.getDomain(props, axis, children); | ||
var axisComponent = Axis.getAxisComponent(children, axis); | ||
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis; | ||
const getDomain = (props, axis, childComponents) => { | ||
const children = childComponents || React.Children.toArray(props.children); | ||
const domain = Wrapper.getDomain(props, axis, children); | ||
const axisComponent = Axis.getAxisComponent(children, axis); | ||
const invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis; | ||
return invertDomain ? domain.concat().reverse() : domain; | ||
}; | ||
var createStringMap = function (props, childComponents, allStrings) { | ||
var x = !allStrings.x || allStrings.x.length === 0 ? null : allStrings.x.reduce(function (memo, string, index) { | ||
const createStringMap = (props, childComponents, allStrings) => { | ||
const x = !allStrings.x || allStrings.x.length === 0 ? null : allStrings.x.reduce((memo, string, index) => { | ||
memo[string] = index + 1; | ||
return memo; | ||
}, {}); | ||
var y = !allStrings.y || allStrings.y.length === 0 ? null : allStrings.y.reduce(function (memo, string, index) { | ||
const y = !allStrings.y || allStrings.y.length === 0 ? null : allStrings.y.reduce((memo, string, index) => { | ||
memo[string] = index + 1; | ||
@@ -205,5 +201,5 @@ return memo; | ||
return { | ||
x: x, | ||
y: y | ||
x, | ||
y | ||
}; | ||
}; |
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"; | ||
@@ -17,3 +10,3 @@ import { Background, Helpers, Hooks, UserProps, VictoryContainer, VictoryTheme, Wrapper } from "victory-core"; | ||
import isEqual from "react-fast-compare"; | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -23,3 +16,3 @@ height: 300, | ||
}; | ||
var defaultProps = { | ||
const defaultProps = { | ||
backgroundComponent: /*#__PURE__*/React.createElement(Background, null), | ||
@@ -43,44 +36,43 @@ containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
}; | ||
var VictoryChartImpl = function (initialProps) { | ||
var propsWithDefaults = React.useMemo(function () { | ||
return _objectSpread(_objectSpread({}, defaultProps), initialProps); | ||
}, [initialProps]); | ||
var role = "chart"; | ||
var _Hooks$useAnimationSt = Hooks.useAnimationState(), | ||
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps, | ||
setAnimationState = _Hooks$useAnimationSt.setAnimationState, | ||
getProps = _Hooks$useAnimationSt.getProps; | ||
var props = getProps(propsWithDefaults); | ||
var modifiedProps = Helpers.modifyProps(props, fallbackProps, role); | ||
var desc = modifiedProps.desc, | ||
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, | ||
name = modifiedProps.name, | ||
title = modifiedProps.title; | ||
var axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes; | ||
var childComponents = React.useMemo(function () { | ||
return getChildComponents(modifiedProps, axes); | ||
}, [modifiedProps, axes]); | ||
var calculatedProps = React.useMemo(function () { | ||
return getCalculatedProps(modifiedProps, childComponents); | ||
}, [modifiedProps, childComponents]); | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin, | ||
horizontal = calculatedProps.horizontal; | ||
var newChildren = React.useMemo(function () { | ||
var children = getChildren(props, childComponents, calculatedProps); | ||
var mappedChildren = children.map(function (child, index) { | ||
var childProps = Object.assign({ | ||
const VictoryChartImpl = initialProps => { | ||
const propsWithDefaults = React.useMemo(() => ({ | ||
...defaultProps, | ||
...initialProps | ||
}), [initialProps]); | ||
const role = "chart"; | ||
const { | ||
getAnimationProps, | ||
setAnimationState, | ||
getProps | ||
} = Hooks.useAnimationState(); | ||
const props = getProps(propsWithDefaults); | ||
const modifiedProps = Helpers.modifyProps(props, fallbackProps, role); | ||
const { | ||
desc, | ||
eventKey, | ||
containerComponent, | ||
standalone, | ||
groupComponent, | ||
externalEventMutations, | ||
width, | ||
height, | ||
theme, | ||
polar, | ||
name, | ||
title | ||
} = modifiedProps; | ||
const axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes; | ||
const childComponents = React.useMemo(() => getChildComponents(modifiedProps, axes), [modifiedProps, axes]); | ||
const calculatedProps = React.useMemo(() => getCalculatedProps(modifiedProps, childComponents), [modifiedProps, childComponents]); | ||
const { | ||
domain, | ||
scale, | ||
style, | ||
origin, | ||
horizontal | ||
} = calculatedProps; | ||
const newChildren = React.useMemo(() => { | ||
const children = getChildren(props, childComponents, calculatedProps); | ||
const mappedChildren = children.map((child, index) => { | ||
const childProps = Object.assign({ | ||
animate: getAnimationProps(props, child, index) | ||
@@ -90,47 +82,42 @@ }, child.props); | ||
}); | ||
if (props.style && props.style.background) { | ||
var backgroundComponent = getBackgroundWithProps(props, calculatedProps); | ||
const backgroundComponent = getBackgroundWithProps(props, calculatedProps); | ||
mappedChildren.unshift(backgroundComponent); | ||
} | ||
return mappedChildren; | ||
}, [getAnimationProps, childComponents, props, calculatedProps]); | ||
var containerProps = React.useMemo(function () { | ||
const containerProps = React.useMemo(() => { | ||
if (standalone) { | ||
return { | ||
desc: desc, | ||
domain: domain, | ||
width: width, | ||
height: height, | ||
horizontal: horizontal, | ||
name: name, | ||
desc, | ||
domain, | ||
width, | ||
height, | ||
horizontal, | ||
name, | ||
origin: polar ? origin : undefined, | ||
polar: polar, | ||
theme: theme, | ||
title: title, | ||
scale: scale, | ||
standalone: standalone, | ||
polar, | ||
theme, | ||
title, | ||
scale, | ||
standalone, | ||
style: style.parent | ||
}; | ||
} | ||
return {}; | ||
}, [desc, domain, height, horizontal, name, origin, polar, scale, standalone, style, title, theme, width]); | ||
var container = React.useMemo(function () { | ||
const container = React.useMemo(() => { | ||
if (standalone) { | ||
var defaultContainerProps = _defaults({}, containerComponent.props, containerProps, UserProps.getSafeUserProps(propsWithDefaults)); | ||
const defaultContainerProps = _defaults({}, containerComponent.props, containerProps, UserProps.getSafeUserProps(propsWithDefaults)); | ||
return /*#__PURE__*/React.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
return groupComponent; | ||
}, [groupComponent, standalone, containerComponent, containerProps, propsWithDefaults]); | ||
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) { | ||
@@ -141,3 +128,2 @@ setAnimationState(previousProps, propsWithDefaults); | ||
}, [setAnimationState, previousProps, propsWithDefaults]); | ||
if (!_isEmpty(events)) { | ||
@@ -151,9 +137,7 @@ return /*#__PURE__*/React.createElement(VictorySharedEvents, { | ||
} | ||
return /*#__PURE__*/React.cloneElement(container, container.props, newChildren); | ||
}; | ||
export var VictoryChart = /*#__PURE__*/React.memo(VictoryChartImpl, isEqual); | ||
VictoryChart.displayName = "VictoryChart"; // @ts-expect-error FIXME: Does this "expectedComponents" do anything? | ||
export const VictoryChart = /*#__PURE__*/React.memo(VictoryChartImpl, isEqual); | ||
VictoryChart.displayName = "VictoryChart"; | ||
// @ts-expect-error FIXME: Does this "expectedComponents" do anything? | ||
VictoryChart.expectedComponents = ["groupComponent", "containerComponent"]; |
@@ -10,13 +10,9 @@ "use strict"; | ||
exports.getChildren = getChildren; | ||
var _defaults2 = _interopRequireDefault(require("lodash/defaults")); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _victoryCore = require("victory-core"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-disable no-use-before-define */ | ||
/* eslint-disable no-use-before-define */ | ||
var fallbackProps = { | ||
const fallbackProps = { | ||
width: 450, | ||
@@ -26,32 +22,32 @@ height: 300, | ||
}; | ||
function getAxisProps(child, props, calculatedProps) { | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
stringMap = calculatedProps.stringMap, | ||
categories = calculatedProps.categories, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
domain, | ||
scale, | ||
stringMap, | ||
categories, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
stringMap: stringMap, | ||
horizontal: horizontal, | ||
categories: categories, | ||
stringMap, | ||
horizontal, | ||
categories, | ||
startAngle: props.startAngle, | ||
endAngle: props.endAngle, | ||
innerRadius: props.innerRadius, | ||
domain: domain, | ||
scale: scale | ||
domain, | ||
scale | ||
}; | ||
} | ||
function getBackgroundWithProps(props, calculatedProps) { | ||
var backgroundElement = props.backgroundComponent; | ||
var height = props.polar ? calculatedProps.range.y[1] : calculatedProps.range.y[0] - calculatedProps.range.y[1]; | ||
var width = calculatedProps.range.x[1] - calculatedProps.range.x[0]; | ||
var xScale = props.horizontal ? calculatedProps.scale.y.range()[0] : calculatedProps.scale.x.range()[0]; | ||
var yScale = props.horizontal ? calculatedProps.scale.x.range()[1] : calculatedProps.scale.y.range()[1]; | ||
var xCoordinate = props.polar ? calculatedProps.origin.x : xScale; | ||
var yCoordinate = props.polar ? calculatedProps.origin.y : yScale; | ||
var parentName = props.name || "chart"; | ||
var backgroundProps = { | ||
height: height, | ||
const backgroundElement = props.backgroundComponent; | ||
const height = props.polar ? calculatedProps.range.y[1] : calculatedProps.range.y[0] - calculatedProps.range.y[1]; | ||
const width = calculatedProps.range.x[1] - calculatedProps.range.x[0]; | ||
const xScale = props.horizontal ? calculatedProps.scale.y.range()[0] : calculatedProps.scale.x.range()[0]; | ||
const yScale = props.horizontal ? calculatedProps.scale.x.range()[1] : calculatedProps.scale.y.range()[1]; | ||
const xCoordinate = props.polar ? calculatedProps.origin.x : xScale; | ||
const yCoordinate = props.polar ? calculatedProps.origin.y : yScale; | ||
const parentName = props.name || "chart"; | ||
const backgroundProps = { | ||
height, | ||
polar: props.polar, | ||
@@ -62,33 +58,31 @@ scale: calculatedProps.scale, | ||
y: yCoordinate, | ||
key: "".concat(parentName, "-background"), | ||
width: width | ||
key: `${parentName}-background`, | ||
width | ||
}; | ||
return /*#__PURE__*/_react.default.cloneElement(backgroundElement, (0, _defaults2.default)({}, backgroundElement.props, backgroundProps)); | ||
} | ||
function getChildProps(child, props, calculatedProps) { | ||
var axisChild = _victoryCore.Axis.findAxisComponents([child]); | ||
const axisChild = _victoryCore.Axis.findAxisComponents([child]); | ||
if (axisChild.length > 0) { | ||
return getAxisProps(axisChild[0], props, calculatedProps); | ||
} | ||
var categories = calculatedProps.categories, | ||
domain = calculatedProps.domain, | ||
range = calculatedProps.range, | ||
scale = calculatedProps.scale, | ||
stringMap = calculatedProps.stringMap, | ||
horizontal = calculatedProps.horizontal; | ||
const { | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
stringMap, | ||
horizontal | ||
} = calculatedProps; | ||
return { | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
scale: scale, | ||
stringMap: stringMap, | ||
horizontal: horizontal | ||
categories, | ||
domain, | ||
range, | ||
scale, | ||
stringMap, | ||
horizontal | ||
}; | ||
} | ||
function getStyles(props) { | ||
var styleProps = props.style && props.style.parent; | ||
const styleProps = props.style && props.style.parent; | ||
return { | ||
@@ -102,82 +96,79 @@ parent: (0, _defaults2.default)({}, styleProps, { | ||
} | ||
function getCalculatedProps(initialProps, childComponents) { | ||
var style = getStyles(initialProps); | ||
var props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "chart"); | ||
var horizontal = props.horizontal, | ||
polar = props.polar; | ||
var allStrings = _victoryCore.Wrapper.getStringsFromChildren(props, childComponents); | ||
var categories = _victoryCore.Wrapper.getCategories(props, childComponents, allStrings); | ||
var stringMap = createStringMap(props, childComponents, allStrings); | ||
var domain = { | ||
const style = getStyles(initialProps); | ||
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "chart"); | ||
const { | ||
horizontal, | ||
polar | ||
} = props; | ||
const allStrings = _victoryCore.Wrapper.getStringsFromChildren(props, childComponents); | ||
const categories = _victoryCore.Wrapper.getCategories(props, childComponents, allStrings); | ||
const stringMap = createStringMap(props, childComponents, allStrings); | ||
const domain = { | ||
x: getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "x", childComponents), | ||
y: getDomain(Object.assign({}, props, { | ||
categories: categories | ||
categories | ||
}), "y", childComponents) | ||
}; | ||
var range = { | ||
const 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(horizontal ? range.y : range.x), | ||
y: baseScale.y.domain(domain.y).range(horizontal ? range.x : range.y) | ||
}; | ||
var origin = polar ? _victoryCore.Helpers.getPolarOrigin(props) : _victoryCore.Axis.getOrigin(domain); | ||
var padding = _victoryCore.Helpers.getPadding(props); | ||
const origin = polar ? _victoryCore.Helpers.getPolarOrigin(props) : _victoryCore.Axis.getOrigin(domain); | ||
const padding = _victoryCore.Helpers.getPadding(props); | ||
return { | ||
categories: categories, | ||
domain: domain, | ||
range: range, | ||
horizontal: horizontal, | ||
scale: scale, | ||
stringMap: stringMap, | ||
style: style, | ||
origin: origin, | ||
padding: padding | ||
categories, | ||
domain, | ||
range, | ||
horizontal, | ||
scale, | ||
stringMap, | ||
style, | ||
origin, | ||
padding | ||
}; | ||
} | ||
function getChildren(props, childComponents, calculatedProps) { | ||
var children = childComponents || getChildComponents(props); | ||
var newCalculatedProps = calculatedProps || getCalculatedProps(props, children); | ||
var baseStyle = newCalculatedProps.style.parent; | ||
var height = props.height, | ||
polar = props.polar, | ||
theme = props.theme, | ||
width = props.width; | ||
var origin = newCalculatedProps.origin, | ||
horizontal = newCalculatedProps.horizontal; | ||
var parentName = props.name || "chart"; | ||
return children.filter(_react.default.isValidElement).map(function (child, index) { | ||
var role = child.type && child.type.role; | ||
var style = Array.isArray(child.props.style) ? child.props.style : (0, _defaults2.default)({}, child.props.style, { | ||
const children = childComponents || getChildComponents(props); | ||
const newCalculatedProps = calculatedProps || getCalculatedProps(props, children); | ||
const baseStyle = newCalculatedProps.style.parent; | ||
const { | ||
height, | ||
polar, | ||
theme, | ||
width | ||
} = props; | ||
const { | ||
origin, | ||
horizontal | ||
} = newCalculatedProps; | ||
const parentName = props.name || "chart"; | ||
return children.filter(_react.default.isValidElement).map((child, index) => { | ||
const role = child.type && child.type.role; | ||
const style = Array.isArray(child.props.style) ? child.props.style : (0, _defaults2.default)({}, child.props.style, { | ||
parent: baseStyle | ||
}); | ||
var childProps = getChildProps(child, props, newCalculatedProps); | ||
var name = child.props.name || "".concat(parentName, "-").concat(role, "-").concat(index); | ||
var newProps = (0, _defaults2.default)({ | ||
horizontal: horizontal, | ||
height: height, | ||
polar: polar, | ||
theme: theme, | ||
width: width, | ||
style: style, | ||
name: name, | ||
const childProps = getChildProps(child, props, newCalculatedProps); | ||
const name = child.props.name || `${parentName}-${role}-${index}`; | ||
const newProps = (0, _defaults2.default)({ | ||
horizontal, | ||
height, | ||
polar, | ||
theme, | ||
width, | ||
style, | ||
name, | ||
origin: polar ? origin : undefined, | ||
padding: newCalculatedProps.padding, | ||
key: "".concat(name, "-key-").concat(index), | ||
key: `${name}-key-${index}`, | ||
standalone: false | ||
@@ -188,14 +179,11 @@ }, childProps); | ||
} | ||
var getChildComponents = function (props, defaultAxes) { | ||
var childComponents = _react.default.Children.toArray(props.children); | ||
const getChildComponents = (props, defaultAxes) => { | ||
let childComponents = _react.default.Children.toArray(props.children); | ||
if (childComponents.length === 0) { | ||
childComponents.push(defaultAxes.independent, defaultAxes.dependent); | ||
} else { | ||
var axisComponents = { | ||
const axisComponents = { | ||
dependent: _victoryCore.Axis.getAxisComponentsWithParent(childComponents, "dependent"), | ||
independent: _victoryCore.Axis.getAxisComponentsWithParent(childComponents, "independent") | ||
}; | ||
if (axisComponents.dependent.length === 0 && axisComponents.independent.length === 0) { | ||
@@ -205,25 +193,18 @@ childComponents = props.prependDefaultAxes ? [defaultAxes.independent, defaultAxes.dependent].concat(childComponents) : childComponents.concat([defaultAxes.independent, defaultAxes.dependent]); | ||
} | ||
return childComponents; | ||
}; | ||
exports.getChildComponents = getChildComponents; | ||
var getDomain = function (props, axis, childComponents) { | ||
var children = childComponents || _react.default.Children.toArray(props.children); | ||
var domain = _victoryCore.Wrapper.getDomain(props, axis, children); | ||
var axisComponent = _victoryCore.Axis.getAxisComponent(children, axis); | ||
var invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis; | ||
const getDomain = (props, axis, childComponents) => { | ||
const children = childComponents || _react.default.Children.toArray(props.children); | ||
const domain = _victoryCore.Wrapper.getDomain(props, axis, children); | ||
const axisComponent = _victoryCore.Axis.getAxisComponent(children, axis); | ||
const invertDomain = axisComponent && axisComponent.props && axisComponent.props.invertAxis; | ||
return invertDomain ? domain.concat().reverse() : domain; | ||
}; | ||
var createStringMap = function (props, childComponents, allStrings) { | ||
var x = !allStrings.x || allStrings.x.length === 0 ? null : allStrings.x.reduce(function (memo, string, index) { | ||
const createStringMap = (props, childComponents, allStrings) => { | ||
const x = !allStrings.x || allStrings.x.length === 0 ? null : allStrings.x.reduce((memo, string, index) => { | ||
memo[string] = index + 1; | ||
return memo; | ||
}, {}); | ||
var y = !allStrings.y || allStrings.y.length === 0 ? null : allStrings.y.reduce(function (memo, string, index) { | ||
const y = !allStrings.y || allStrings.y.length === 0 ? null : allStrings.y.reduce((memo, string, index) => { | ||
memo[string] = index + 1; | ||
@@ -233,5 +214,5 @@ return memo; | ||
return { | ||
x: x, | ||
y: y | ||
x, | ||
y | ||
}; | ||
}; |
@@ -6,5 +6,3 @@ "use strict"; | ||
}); | ||
var _victoryChart = require("./victory-chart"); | ||
Object.keys(_victoryChart).forEach(function (key) { | ||
@@ -11,0 +9,0 @@ if (key === "default" || key === "__esModule") return; |
@@ -7,30 +7,13 @@ "use strict"; | ||
exports.VictoryChart = 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 _victoryAxis = require("victory-axis"); | ||
var _victoryPolarAxis = require("victory-polar-axis"); | ||
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, | ||
@@ -40,3 +23,3 @@ height: 300, | ||
}; | ||
var defaultProps = { | ||
const defaultProps = { | ||
backgroundComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Background, null), | ||
@@ -60,51 +43,43 @@ containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
}; | ||
var VictoryChartImpl = function (initialProps) { | ||
var propsWithDefaults = _react.default.useMemo(function () { | ||
return _objectSpread(_objectSpread({}, defaultProps), initialProps); | ||
}, [initialProps]); | ||
var role = "chart"; | ||
var _Hooks$useAnimationSt = _victoryCore.Hooks.useAnimationState(), | ||
getAnimationProps = _Hooks$useAnimationSt.getAnimationProps, | ||
setAnimationState = _Hooks$useAnimationSt.setAnimationState, | ||
getProps = _Hooks$useAnimationSt.getProps; | ||
var props = getProps(propsWithDefaults); | ||
var modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role); | ||
var desc = modifiedProps.desc, | ||
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, | ||
name = modifiedProps.name, | ||
title = modifiedProps.title; | ||
var axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes; | ||
var childComponents = _react.default.useMemo(function () { | ||
return (0, _helperMethods.getChildComponents)(modifiedProps, axes); | ||
}, [modifiedProps, axes]); | ||
var calculatedProps = _react.default.useMemo(function () { | ||
return (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents); | ||
}, [modifiedProps, childComponents]); | ||
var domain = calculatedProps.domain, | ||
scale = calculatedProps.scale, | ||
style = calculatedProps.style, | ||
origin = calculatedProps.origin, | ||
horizontal = calculatedProps.horizontal; | ||
var newChildren = _react.default.useMemo(function () { | ||
var children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps); | ||
var mappedChildren = children.map(function (child, index) { | ||
var childProps = Object.assign({ | ||
const VictoryChartImpl = initialProps => { | ||
const propsWithDefaults = _react.default.useMemo(() => ({ | ||
...defaultProps, | ||
...initialProps | ||
}), [initialProps]); | ||
const role = "chart"; | ||
const { | ||
getAnimationProps, | ||
setAnimationState, | ||
getProps | ||
} = _victoryCore.Hooks.useAnimationState(); | ||
const props = getProps(propsWithDefaults); | ||
const modifiedProps = _victoryCore.Helpers.modifyProps(props, fallbackProps, role); | ||
const { | ||
desc, | ||
eventKey, | ||
containerComponent, | ||
standalone, | ||
groupComponent, | ||
externalEventMutations, | ||
width, | ||
height, | ||
theme, | ||
polar, | ||
name, | ||
title | ||
} = modifiedProps; | ||
const axes = props.polar ? modifiedProps.defaultPolarAxes : modifiedProps.defaultAxes; | ||
const childComponents = _react.default.useMemo(() => (0, _helperMethods.getChildComponents)(modifiedProps, axes), [modifiedProps, axes]); | ||
const calculatedProps = _react.default.useMemo(() => (0, _helperMethods.getCalculatedProps)(modifiedProps, childComponents), [modifiedProps, childComponents]); | ||
const { | ||
domain, | ||
scale, | ||
style, | ||
origin, | ||
horizontal | ||
} = calculatedProps; | ||
const newChildren = _react.default.useMemo(() => { | ||
const children = (0, _helperMethods.getChildren)(props, childComponents, calculatedProps); | ||
const mappedChildren = children.map((child, index) => { | ||
const childProps = Object.assign({ | ||
animate: getAnimationProps(props, child, index) | ||
@@ -114,51 +89,42 @@ }, child.props); | ||
}); | ||
if (props.style && props.style.background) { | ||
var backgroundComponent = (0, _helperMethods.getBackgroundWithProps)(props, calculatedProps); | ||
const backgroundComponent = (0, _helperMethods.getBackgroundWithProps)(props, calculatedProps); | ||
mappedChildren.unshift(backgroundComponent); | ||
} | ||
return mappedChildren; | ||
}, [getAnimationProps, childComponents, props, calculatedProps]); | ||
var containerProps = _react.default.useMemo(function () { | ||
const containerProps = _react.default.useMemo(() => { | ||
if (standalone) { | ||
return { | ||
desc: desc, | ||
domain: domain, | ||
width: width, | ||
height: height, | ||
horizontal: horizontal, | ||
name: name, | ||
desc, | ||
domain, | ||
width, | ||
height, | ||
horizontal, | ||
name, | ||
origin: polar ? origin : undefined, | ||
polar: polar, | ||
theme: theme, | ||
title: title, | ||
scale: scale, | ||
standalone: standalone, | ||
polar, | ||
theme, | ||
title, | ||
scale, | ||
standalone, | ||
style: style.parent | ||
}; | ||
} | ||
return {}; | ||
}, [desc, domain, height, horizontal, name, origin, polar, scale, standalone, style, title, theme, width]); | ||
var container = _react.default.useMemo(function () { | ||
const container = _react.default.useMemo(() => { | ||
if (standalone) { | ||
var defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, _victoryCore.UserProps.getSafeUserProps(propsWithDefaults)); | ||
const defaultContainerProps = (0, _defaults2.default)({}, containerComponent.props, containerProps, _victoryCore.UserProps.getSafeUserProps(propsWithDefaults)); | ||
return /*#__PURE__*/_react.default.cloneElement(containerComponent, defaultContainerProps); | ||
} | ||
return groupComponent; | ||
}, [groupComponent, standalone, containerComponent, containerProps, propsWithDefaults]); | ||
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) { | ||
@@ -169,3 +135,2 @@ setAnimationState(previousProps, propsWithDefaults); | ||
}, [setAnimationState, previousProps, propsWithDefaults]); | ||
if (!(0, _isEmpty2.default)(events)) { | ||
@@ -179,11 +144,7 @@ return /*#__PURE__*/_react.default.createElement(_victorySharedEvents.VictorySharedEvents, { | ||
} | ||
return /*#__PURE__*/_react.default.cloneElement(container, container.props, newChildren); | ||
}; | ||
var VictoryChart = /*#__PURE__*/_react.default.memo(VictoryChartImpl, _reactFastCompare.default); | ||
exports.VictoryChart = VictoryChart; | ||
VictoryChart.displayName = "VictoryChart"; // @ts-expect-error FIXME: Does this "expectedComponents" do anything? | ||
const VictoryChart = exports.VictoryChart = /*#__PURE__*/_react.default.memo(VictoryChartImpl, _reactFastCompare.default); | ||
VictoryChart.displayName = "VictoryChart"; | ||
// @ts-expect-error FIXME: Does this "expectedComponents" do anything? | ||
VictoryChart.expectedComponents = ["groupComponent", "containerComponent"]; |
{ | ||
"name": "victory-chart", | ||
"version": "36.9.2", | ||
"version": "37.0.0", | ||
"description": "Chart Component for Victory", | ||
@@ -25,6 +25,6 @@ "keywords": [ | ||
"react-fast-compare": "^3.2.0", | ||
"victory-axis": "^36.9.2", | ||
"victory-core": "^36.9.2", | ||
"victory-polar-axis": "^36.9.2", | ||
"victory-shared-events": "^36.9.2" | ||
"victory-axis": "^37.0.0", | ||
"victory-core": "^37.0.0", | ||
"victory-polar-axis": "^37.0.0", | ||
"victory-shared-events": "^37.0.0" | ||
}, | ||
@@ -31,0 +31,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
1139506
20305
4
+ Addedvictory-axis@37.3.2(transitive)
+ Addedvictory-core@37.3.2(transitive)
+ Addedvictory-polar-axis@37.3.2(transitive)
+ Addedvictory-shared-events@37.3.2(transitive)
+ Addedvictory-vendor@37.3.2(transitive)
- Removedvictory-axis@36.9.2(transitive)
- Removedvictory-core@36.9.2(transitive)
- Removedvictory-polar-axis@36.9.2(transitive)
- Removedvictory-shared-events@36.9.2(transitive)
- Removedvictory-vendor@36.9.2(transitive)
Updatedvictory-axis@^37.0.0
Updatedvictory-core@^37.0.0
Updatedvictory-polar-axis@^37.0.0