victory-pie
Advanced tools
Comparing version 36.9.2-next.0 to 36.9.2-next.1
# victory-pie | ||
## 36.9.2-next.0 | ||
## 36.9.2-next.1 | ||
@@ -9,8 +9,11 @@ ### Patch Changes | ||
- 6e34169a5: Replace lodash isFunction with native code | ||
- Updated dependencies [7da790934] | ||
- Updated dependencies [3f2da66e3] | ||
- Updated dependencies [c13308624] | ||
- Updated dependencies [7efd582cc] | ||
- Updated dependencies [9cdaf2c08] | ||
- Updated dependencies [f6f7cc515] | ||
- Updated dependencies [6e34169a5] | ||
- victory-core@36.9.2-next.0 | ||
- victory-vendor@36.9.2-next.0 | ||
- victory-core@36.9.2-next.1 | ||
- victory-vendor@36.9.2-next.1 | ||
@@ -17,0 +20,0 @@ ## 36.9.1 |
import _isPlainObject from "lodash/isPlainObject"; | ||
import _defaults from "lodash/defaults"; | ||
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 90, 135, 180, 225, 270, 315, 360] }]*/ | ||
import * as d3Shape from "victory-vendor/d3-shape"; | ||
import { Helpers, Data, Style } from "victory-core"; | ||
const checkForValidText = text => { | ||
var checkForValidText = function (text) { | ||
if (text === undefined || text === null || Helpers.isFunction(text)) { | ||
return text; | ||
} | ||
return `${text}`; | ||
return "".concat(text); | ||
}; | ||
const getColor = (style, colors, index) => { | ||
var getColor = function (style, colors, index) { | ||
if (style && style.data && style.data.fill) { | ||
return style.data.fill; | ||
} | ||
return colors && colors[index % colors.length]; | ||
}; | ||
const getRadius = (props, padding) => { | ||
var getRadius = function (props, padding) { | ||
if (typeof props.radius === "number") { | ||
return props.radius; | ||
} | ||
return Math.min(props.width - padding.left - padding.right, props.height - padding.top - padding.bottom) / 2; | ||
}; | ||
const getOrigin = (props, padding) => { | ||
const { | ||
width, | ||
height | ||
} = props; | ||
const origin = _isPlainObject(props.origin) ? props.origin : {}; | ||
var getOrigin = function (props, padding) { | ||
var width = props.width, | ||
height = props.height; | ||
var origin = _isPlainObject(props.origin) ? props.origin : {}; | ||
return { | ||
@@ -35,5 +39,6 @@ x: origin.x !== undefined ? origin.x : (padding.left - padding.right + width) / 2, | ||
}; | ||
const getSlices = (props, data) => { | ||
const padAngle = Helpers.isFunction(props.padAngle) ? 0 : props.padAngle; | ||
const layoutFunction = d3Shape.pie().sort(null).startAngle(Helpers.degreesToRadians(props.startAngle)).endAngle(Helpers.degreesToRadians(props.endAngle)).padAngle(Helpers.degreesToRadians(padAngle)).value(datum => { | ||
var getSlices = function (props, data) { | ||
var padAngle = Helpers.isFunction(props.padAngle) ? 0 : props.padAngle; | ||
var layoutFunction = d3Shape.pie().sort(null).startAngle(Helpers.degreesToRadians(props.startAngle)).endAngle(Helpers.degreesToRadians(props.endAngle)).padAngle(Helpers.degreesToRadians(padAngle)).value(function (datum) { | ||
return datum._y; | ||
@@ -43,36 +48,36 @@ }); | ||
}; | ||
const getCalculatedValues = props => { | ||
const { | ||
colorScale | ||
} = props; | ||
const styleObject = Helpers.getDefaultStyles(props, "pie"); | ||
const style = Helpers.getStyles(props.style, styleObject); | ||
const colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale); | ||
const padding = Helpers.getPadding(props); | ||
const defaultRadius = getRadius(props, padding); | ||
const origin = getOrigin(props, padding); | ||
const data = Data.getData(props); | ||
const slices = getSlices(props, data); | ||
var getCalculatedValues = function (props) { | ||
var colorScale = props.colorScale; | ||
var styleObject = Helpers.getDefaultStyles(props, "pie"); | ||
var style = Helpers.getStyles(props.style, styleObject); | ||
var colors = Array.isArray(colorScale) ? colorScale : Style.getColorScale(colorScale); | ||
var padding = Helpers.getPadding(props); | ||
var defaultRadius = getRadius(props, padding); | ||
var origin = getOrigin(props, padding); | ||
var data = Data.getData(props); | ||
var slices = getSlices(props, data); | ||
return Object.assign({}, props, { | ||
style, | ||
colors, | ||
padding, | ||
defaultRadius, | ||
data, | ||
slices, | ||
origin | ||
style: style, | ||
colors: colors, | ||
padding: padding, | ||
defaultRadius: defaultRadius, | ||
data: data, | ||
slices: slices, | ||
origin: origin | ||
}); | ||
}; | ||
const getSliceStyle = (index, calculatedValues) => { | ||
const { | ||
style, | ||
colors | ||
} = calculatedValues; | ||
const fill = getColor(style, colors, index); | ||
var getSliceStyle = function (index, calculatedValues) { | ||
var style = calculatedValues.style, | ||
colors = calculatedValues.colors; | ||
var fill = getColor(style, colors, index); | ||
return Object.assign({ | ||
fill | ||
fill: fill | ||
}, style.data); | ||
}; | ||
const getLabelText = (props, datum, index) => { | ||
let text; | ||
var getLabelText = function (props, datum, index) { | ||
var text; | ||
if (datum.label) { | ||
@@ -85,20 +90,25 @@ text = datum.label; | ||
} | ||
return checkForValidText(text); | ||
}; | ||
const getLabelArc = labelRadius => { | ||
var getLabelArc = function (labelRadius) { | ||
return d3Shape.arc().outerRadius(labelRadius).innerRadius(labelRadius); | ||
}; | ||
const getCalculatedLabelRadius = (radius, labelRadius, style) => { | ||
const padding = style && style.padding || 0; | ||
var getCalculatedLabelRadius = function (radius, labelRadius, style) { | ||
var padding = style && style.padding || 0; | ||
return labelRadius || radius + padding; | ||
}; | ||
const getLabelPosition = (arc, slice, position) => { | ||
const construct = { | ||
var getLabelPosition = function (arc, slice, position) { | ||
var construct = { | ||
startAngle: position === "startAngle" ? slice.startAngle : slice.endAngle, | ||
endAngle: position === "endAngle" ? slice.endAngle : slice.startAngle | ||
}; | ||
const clonedArc = Object.assign({}, slice, construct); | ||
var clonedArc = Object.assign({}, slice, construct); | ||
return arc.centroid(clonedArc); | ||
}; | ||
const getLabelOrientation = (degree, labelPlacement) => { | ||
var getLabelOrientation = function (degree, labelPlacement) { | ||
if (labelPlacement === "perpendicular") { | ||
@@ -109,2 +119,3 @@ return degree > 90 && degree < 270 ? "bottom" : "top"; | ||
} | ||
if (degree < 45 || degree > 315) { | ||
@@ -117,18 +128,25 @@ return "top"; | ||
} | ||
return "left"; | ||
}; | ||
const getTextAnchor = orientation => { | ||
var getTextAnchor = function (orientation) { | ||
if (orientation === "top" || orientation === "bottom") { | ||
return "middle"; | ||
} | ||
return orientation === "right" ? "start" : "end"; | ||
}; | ||
const getVerticalAnchor = orientation => { | ||
var getVerticalAnchor = function (orientation) { | ||
if (orientation === "left" || orientation === "right") { | ||
return "middle"; | ||
} | ||
return orientation === "bottom" ? "start" : "end"; | ||
}; | ||
const getBaseLabelAngle = (slice, labelPosition, labelStyle) => { | ||
let baseAngle = 0; | ||
var getBaseLabelAngle = function (slice, labelPosition, labelStyle) { | ||
var baseAngle = 0; | ||
if (labelPosition.angle !== undefined) { | ||
@@ -141,156 +159,163 @@ baseAngle = labelStyle.angle; | ||
} | ||
const positiveAngle = baseAngle < 0 ? 360 - baseAngle : baseAngle; | ||
var positiveAngle = baseAngle < 0 ? 360 - baseAngle : baseAngle; | ||
return positiveAngle % 360; | ||
}; | ||
const getLabelAngle = (baseAngle, labelPlacement) => { | ||
var getLabelAngle = function (baseAngle, labelPlacement) { | ||
if (labelPlacement === "vertical") { | ||
return 0; | ||
} | ||
if (labelPlacement === "parallel") { | ||
return baseAngle > 180 && baseAngle < 360 ? baseAngle + 90 : baseAngle - 90; | ||
} | ||
return baseAngle > 90 && baseAngle < 270 ? baseAngle - 180 : baseAngle; | ||
}; | ||
const getLabelProps = (text, dataProps, calculatedValues) => { | ||
const { | ||
index, | ||
datum, | ||
data, | ||
slice, | ||
labelComponent, | ||
theme | ||
} = dataProps; | ||
const { | ||
style, | ||
defaultRadius, | ||
origin, | ||
width, | ||
height | ||
} = calculatedValues; | ||
const labelRadius = Helpers.evaluateProp(calculatedValues.labelRadius, Object.assign({ | ||
text | ||
var getLabelProps = function (text, dataProps, calculatedValues) { | ||
var index = dataProps.index, | ||
datum = dataProps.datum, | ||
data = dataProps.data, | ||
slice = dataProps.slice, | ||
labelComponent = dataProps.labelComponent, | ||
theme = dataProps.theme; | ||
var style = calculatedValues.style, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
origin = calculatedValues.origin, | ||
width = calculatedValues.width, | ||
height = calculatedValues.height; | ||
var labelRadius = Helpers.evaluateProp(calculatedValues.labelRadius, Object.assign({ | ||
text: text | ||
}, dataProps)); | ||
const labelPosition = Helpers.evaluateProp(calculatedValues.labelPosition, Object.assign({ | ||
text | ||
var labelPosition = Helpers.evaluateProp(calculatedValues.labelPosition, Object.assign({ | ||
text: text | ||
}, dataProps)) || "centroid"; | ||
const labelPlacement = Helpers.evaluateProp(calculatedValues.labelPlacement, Object.assign({ | ||
text | ||
var labelPlacement = Helpers.evaluateProp(calculatedValues.labelPlacement, Object.assign({ | ||
text: text | ||
}, dataProps)) || "vertical"; | ||
const labelStyle = Object.assign({ | ||
var labelStyle = Object.assign({ | ||
padding: 0 | ||
}, style.labels); | ||
const evaluatedStyle = Helpers.evaluateStyle(labelStyle, Object.assign({ | ||
labelRadius, | ||
text | ||
var evaluatedStyle = Helpers.evaluateStyle(labelStyle, Object.assign({ | ||
labelRadius: labelRadius, | ||
text: text | ||
}, dataProps)); | ||
const calculatedLabelRadius = getCalculatedLabelRadius(defaultRadius, labelRadius, evaluatedStyle); | ||
const labelArc = getLabelArc(calculatedLabelRadius); | ||
const position = getLabelPosition(labelArc, slice, labelPosition); | ||
const baseAngle = getBaseLabelAngle(slice, labelPosition, labelStyle); | ||
const labelAngle = getLabelAngle(baseAngle, labelPlacement); | ||
const orientation = getLabelOrientation(baseAngle, labelPlacement); | ||
const textAnchor = labelStyle.textAnchor || getTextAnchor(orientation); | ||
const verticalAnchor = labelStyle.verticalAnchor || getVerticalAnchor(orientation); | ||
const labelProps = { | ||
width, | ||
height, | ||
index, | ||
datum, | ||
data, | ||
slice, | ||
orientation, | ||
text, | ||
var calculatedLabelRadius = getCalculatedLabelRadius(defaultRadius, labelRadius, evaluatedStyle); | ||
var labelArc = getLabelArc(calculatedLabelRadius); | ||
var position = getLabelPosition(labelArc, slice, labelPosition); | ||
var baseAngle = getBaseLabelAngle(slice, labelPosition, labelStyle); | ||
var labelAngle = getLabelAngle(baseAngle, labelPlacement); | ||
var orientation = getLabelOrientation(baseAngle, labelPlacement); | ||
var textAnchor = labelStyle.textAnchor || getTextAnchor(orientation); | ||
var verticalAnchor = labelStyle.verticalAnchor || getVerticalAnchor(orientation); | ||
var labelProps = { | ||
width: width, | ||
height: height, | ||
index: index, | ||
datum: datum, | ||
data: data, | ||
slice: slice, | ||
orientation: orientation, | ||
text: text, | ||
style: labelStyle, | ||
x: Math.round(position[0]) + origin.x, | ||
y: Math.round(position[1]) + origin.y, | ||
textAnchor, | ||
verticalAnchor, | ||
textAnchor: textAnchor, | ||
verticalAnchor: verticalAnchor, | ||
angle: labelAngle, | ||
calculatedLabelRadius | ||
calculatedLabelRadius: calculatedLabelRadius | ||
}; | ||
if (!Helpers.isTooltip(labelComponent)) { | ||
return labelProps; | ||
} | ||
const tooltipTheme = theme && theme.tooltip || {}; | ||
var tooltipTheme = theme && theme.tooltip || {}; | ||
return _defaults({}, labelProps, Helpers.omit(tooltipTheme, ["style"])); | ||
}; | ||
export const getXOffsetMultiplayerByAngle = angle => Math.cos(angle - Helpers.degreesToRadians(90)); | ||
export const getYOffsetMultiplayerByAngle = angle => Math.sin(angle - Helpers.degreesToRadians(90)); | ||
export const getXOffset = (offset, angle) => offset * getXOffsetMultiplayerByAngle(angle); | ||
export const getYOffset = (offset, angle) => offset * getYOffsetMultiplayerByAngle(angle); | ||
export const getAverage = array => array.reduce((acc, cur) => acc + cur, 0) / array.length; | ||
export const getLabelIndicatorPropsForLineSegment = (props, calculatedValues, labelProps) => { | ||
const { | ||
innerRadius, | ||
radius, | ||
slice: { | ||
startAngle, | ||
endAngle | ||
}, | ||
labelIndicatorInnerOffset, | ||
labelIndicatorOuterOffset, | ||
index | ||
} = props; | ||
const { | ||
height, | ||
width | ||
} = calculatedValues; | ||
const { | ||
calculatedLabelRadius | ||
} = labelProps; | ||
// calculation | ||
const middleRadius = getAverage([innerRadius, radius]); | ||
const midAngle = getAverage([endAngle, startAngle]); | ||
const centerX = width / 2; | ||
const centerY = height / 2; | ||
const innerOffset = middleRadius + labelIndicatorInnerOffset; | ||
const outerOffset = calculatedLabelRadius - labelIndicatorOuterOffset; | ||
const x1 = centerX + getXOffset(innerOffset, midAngle); | ||
const y1 = centerY + getYOffset(innerOffset, midAngle); | ||
const x2 = centerX + getXOffset(outerOffset, midAngle); | ||
const y2 = centerY + getYOffset(outerOffset, midAngle); | ||
const labelIndicatorProps = { | ||
x1, | ||
y1, | ||
x2, | ||
y2, | ||
index | ||
export var getXOffsetMultiplayerByAngle = function (angle) { | ||
return Math.cos(angle - Helpers.degreesToRadians(90)); | ||
}; | ||
export var getYOffsetMultiplayerByAngle = function (angle) { | ||
return Math.sin(angle - Helpers.degreesToRadians(90)); | ||
}; | ||
export var getXOffset = function (offset, angle) { | ||
return offset * getXOffsetMultiplayerByAngle(angle); | ||
}; | ||
export var getYOffset = function (offset, angle) { | ||
return offset * getYOffsetMultiplayerByAngle(angle); | ||
}; | ||
export var getAverage = function (array) { | ||
return array.reduce(function (acc, cur) { | ||
return acc + cur; | ||
}, 0) / array.length; | ||
}; | ||
export var getLabelIndicatorPropsForLineSegment = function (props, calculatedValues, labelProps) { | ||
var innerRadius = props.innerRadius, | ||
radius = props.radius, | ||
_props$slice = props.slice, | ||
startAngle = _props$slice.startAngle, | ||
endAngle = _props$slice.endAngle, | ||
labelIndicatorInnerOffset = props.labelIndicatorInnerOffset, | ||
labelIndicatorOuterOffset = props.labelIndicatorOuterOffset, | ||
index = props.index; | ||
var height = calculatedValues.height, | ||
width = calculatedValues.width; | ||
var calculatedLabelRadius = labelProps.calculatedLabelRadius; // calculation | ||
var middleRadius = getAverage([innerRadius, radius]); | ||
var midAngle = getAverage([endAngle, startAngle]); | ||
var centerX = width / 2; | ||
var centerY = height / 2; | ||
var innerOffset = middleRadius + labelIndicatorInnerOffset; | ||
var outerOffset = calculatedLabelRadius - labelIndicatorOuterOffset; | ||
var x1 = centerX + getXOffset(innerOffset, midAngle); | ||
var y1 = centerY + getYOffset(innerOffset, midAngle); | ||
var x2 = centerX + getXOffset(outerOffset, midAngle); | ||
var y2 = centerY + getYOffset(outerOffset, midAngle); | ||
var labelIndicatorProps = { | ||
x1: x1, | ||
y1: y1, | ||
x2: x2, | ||
y2: y2, | ||
index: index | ||
}; | ||
return _defaults({}, labelIndicatorProps); | ||
}; | ||
export const getBaseProps = (initialProps, fallbackProps) => { | ||
const props = Helpers.modifyProps(initialProps, fallbackProps, "pie"); | ||
const calculatedValues = getCalculatedValues(props); | ||
const { | ||
slices, | ||
style, | ||
data, | ||
origin, | ||
defaultRadius, | ||
labels, | ||
events, | ||
sharedEvents, | ||
height, | ||
width, | ||
standalone, | ||
name, | ||
innerRadius, | ||
cornerRadius, | ||
padAngle, | ||
disableInlineStyles, | ||
labelIndicator | ||
} = calculatedValues; | ||
const radius = props.radius || defaultRadius; | ||
const initialChildProps = { | ||
export var getBaseProps = function (initialProps, fallbackProps) { | ||
var props = Helpers.modifyProps(initialProps, fallbackProps, "pie"); | ||
var calculatedValues = getCalculatedValues(props); | ||
var slices = calculatedValues.slices, | ||
style = calculatedValues.style, | ||
data = calculatedValues.data, | ||
origin = calculatedValues.origin, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
labels = calculatedValues.labels, | ||
events = calculatedValues.events, | ||
sharedEvents = calculatedValues.sharedEvents, | ||
height = calculatedValues.height, | ||
width = calculatedValues.width, | ||
standalone = calculatedValues.standalone, | ||
name = calculatedValues.name, | ||
innerRadius = calculatedValues.innerRadius, | ||
cornerRadius = calculatedValues.cornerRadius, | ||
padAngle = calculatedValues.padAngle, | ||
disableInlineStyles = calculatedValues.disableInlineStyles, | ||
labelIndicator = calculatedValues.labelIndicator; | ||
var radius = props.radius || defaultRadius; | ||
var initialChildProps = { | ||
parent: { | ||
standalone, | ||
height, | ||
width, | ||
slices, | ||
name, | ||
standalone: standalone, | ||
height: height, | ||
width: width, | ||
slices: slices, | ||
name: name, | ||
style: style.parent | ||
} | ||
}; | ||
return slices.reduce((childProps, slice, index) => { | ||
const datum = _defaults({}, data[index], { | ||
return slices.reduce(function (childProps, slice, index) { | ||
var datum = _defaults({}, data[index], { | ||
startAngle: Helpers.radiansToDegrees(slice.startAngle), | ||
@@ -300,15 +325,16 @@ endAngle: Helpers.radiansToDegrees(slice.endAngle), | ||
}); | ||
const eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
const dataProps = { | ||
index, | ||
slice, | ||
datum, | ||
data, | ||
origin, | ||
innerRadius, | ||
radius, | ||
cornerRadius, | ||
padAngle, | ||
var eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
var dataProps = { | ||
index: index, | ||
slice: slice, | ||
datum: datum, | ||
data: data, | ||
origin: origin, | ||
innerRadius: innerRadius, | ||
radius: radius, | ||
cornerRadius: cornerRadius, | ||
padAngle: padAngle, | ||
style: disableInlineStyles ? {} : getSliceStyle(index, calculatedValues), | ||
disableInlineStyles | ||
disableInlineStyles: disableInlineStyles | ||
}; | ||
@@ -318,8 +344,11 @@ childProps[eventKey] = { | ||
}; | ||
const text = getLabelText(props, datum, index); | ||
var text = getLabelText(props, datum, index); | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
const evaluatedText = Helpers.evaluateProp(text, dataProps); | ||
var evaluatedText = Helpers.evaluateProp(text, dataProps); | ||
childProps[eventKey].labels = getLabelProps(evaluatedText, Object.assign({}, props, dataProps), calculatedValues); | ||
if (labelIndicator) { | ||
const labelProps = childProps[eventKey].labels; | ||
var labelProps = childProps[eventKey].labels; | ||
if (labelProps.calculatedLabelRadius > radius) { | ||
@@ -330,4 +359,5 @@ childProps[eventKey].labelIndicators = getLabelIndicatorPropsForLineSegment(Object.assign({}, props, dataProps), calculatedValues, labelProps); | ||
} | ||
return childProps; | ||
}, initialChildProps); | ||
}; |
102
es/slice.js
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"; | ||
import { Helpers, Path } from "victory-core"; | ||
import * as d3Shape from "victory-vendor/d3-shape"; | ||
const getPath = props => { | ||
const { | ||
slice, | ||
radius, | ||
innerRadius, | ||
cornerRadius | ||
} = props; | ||
var getPath = function (props) { | ||
var slice = props.slice, | ||
radius = props.radius, | ||
innerRadius = props.innerRadius, | ||
cornerRadius = props.cornerRadius; | ||
if (Helpers.isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
const padAngle = Helpers.degreesToRadians(props.padAngle); | ||
const startAngle = Helpers.degreesToRadians(props.sliceStartAngle); | ||
const endAngle = Helpers.degreesToRadians(props.sliceEndAngle); | ||
const pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0); | ||
var padAngle = Helpers.degreesToRadians(props.padAngle); | ||
var startAngle = Helpers.degreesToRadians(props.sliceStartAngle); | ||
var endAngle = Helpers.degreesToRadians(props.sliceEndAngle); | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0); | ||
return pathFunction(_defaults({ | ||
startAngle, | ||
endAngle, | ||
padAngle | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
}; | ||
const evaluateProps = props => { | ||
var evaluateProps = function (props) { | ||
/** | ||
@@ -41,31 +50,32 @@ * * Potential evaluated props of following must be evaluated in this order: | ||
*/ | ||
const style = Helpers.evaluateStyle(props.style, props); | ||
const radius = Helpers.evaluateProp(props.radius, Object.assign({}, props, { | ||
style | ||
var style = Helpers.evaluateStyle(props.style, props); | ||
var radius = Helpers.evaluateProp(props.radius, Object.assign({}, props, { | ||
style: style | ||
})); | ||
const innerRadius = Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, { | ||
style, | ||
radius | ||
var innerRadius = Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, { | ||
style: style, | ||
radius: radius | ||
})); | ||
const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props); | ||
const id = Helpers.evaluateProp(props.id, props); | ||
const cornerRadius = Helpers.evaluateProp(props.cornerRadius, props); | ||
const padAngle = Helpers.evaluateProp(props.padAngle, props); | ||
const sliceStartAngle = Helpers.evaluateProp(props.sliceStartAngle, props); | ||
const sliceEndAngle = Helpers.evaluateProp(props.sliceEndAngle, props); | ||
const tabIndex = Helpers.evaluateProp(props.tabIndex, props); | ||
var ariaLabel = Helpers.evaluateProp(props.ariaLabel, props); | ||
var id = Helpers.evaluateProp(props.id, props); | ||
var cornerRadius = Helpers.evaluateProp(props.cornerRadius, props); | ||
var padAngle = Helpers.evaluateProp(props.padAngle, props); | ||
var sliceStartAngle = Helpers.evaluateProp(props.sliceStartAngle, props); | ||
var sliceEndAngle = Helpers.evaluateProp(props.sliceEndAngle, props); | ||
var tabIndex = Helpers.evaluateProp(props.tabIndex, props); | ||
return Object.assign({}, props, { | ||
ariaLabel, | ||
style, | ||
radius, | ||
innerRadius, | ||
id, | ||
cornerRadius, | ||
padAngle, | ||
sliceStartAngle, | ||
sliceEndAngle, | ||
tabIndex | ||
ariaLabel: ariaLabel, | ||
style: style, | ||
radius: radius, | ||
innerRadius: innerRadius, | ||
id: id, | ||
cornerRadius: cornerRadius, | ||
padAngle: padAngle, | ||
sliceStartAngle: sliceStartAngle, | ||
sliceEndAngle: sliceEndAngle, | ||
tabIndex: tabIndex | ||
}); | ||
}; | ||
const defaultProps = { | ||
var defaultProps = { | ||
pathComponent: /*#__PURE__*/React.createElement(Path, null), | ||
@@ -75,10 +85,6 @@ role: "presentation", | ||
}; | ||
export const Slice = initialProps => { | ||
const props = evaluateProps({ | ||
...defaultProps, | ||
...initialProps | ||
}); | ||
const defaultTransform = props.origin ? `translate(${props.origin.x}, ${props.origin.y})` : undefined; | ||
return /*#__PURE__*/React.cloneElement(props.pathComponent, { | ||
...props.events, | ||
export var Slice = function (initialProps) { | ||
var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps)); | ||
var defaultTransform = props.origin ? "translate(".concat(props.origin.x, ", ").concat(props.origin.y, ")") : undefined; | ||
return /*#__PURE__*/React.cloneElement(props.pathComponent, _objectSpread(_objectSpread({}, props.events), {}, { | ||
"aria-label": props.ariaLabel, | ||
@@ -93,3 +99,3 @@ d: getPath(props), | ||
tabIndex: props.tabIndex | ||
}); | ||
})); | ||
}; |
@@ -0,1 +1,33 @@ | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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 _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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
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, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
import React from "react"; | ||
@@ -5,3 +37,3 @@ import { addEvents, Helpers, Data, LineSegment, VictoryContainer, VictoryLabel, VictoryTheme, UserProps } from "victory-core"; | ||
import { Slice } from "./slice"; | ||
const fallbackProps = { | ||
var fallbackProps = { | ||
endAngle: 360, | ||
@@ -20,129 +52,171 @@ height: 400, | ||
}; | ||
const datumHasXandY = datum => { | ||
var datumHasXandY = function (datum) { | ||
return !Helpers.isNil(datum._x) && !Helpers.isNil(datum._y); | ||
}; | ||
}; // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
class VictoryPieBase extends React.Component { | ||
static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
static displayName = "VictoryPie"; | ||
static role = "pie"; | ||
static defaultTransitions = { | ||
onExit: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
label: " " | ||
}) | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
label: " " | ||
}), | ||
after: datum => ({ | ||
y_: datum._y, | ||
label: datum.label | ||
}) | ||
} | ||
}; | ||
static defaultProps = { | ||
data: [{ | ||
x: "A", | ||
y: 1 | ||
}, { | ||
x: "B", | ||
y: 2 | ||
}, { | ||
x: "C", | ||
y: 3 | ||
}, { | ||
x: "D", | ||
y: 1 | ||
}, { | ||
x: "E", | ||
y: 2 | ||
}], | ||
standalone: true, | ||
dataComponent: /*#__PURE__*/React.createElement(Slice, null), | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null), | ||
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
groupComponent: /*#__PURE__*/React.createElement("g", null), | ||
sortOrder: "ascending", | ||
theme: VictoryTheme.grayscale | ||
}; | ||
static getBaseProps = props => getBaseProps(props, fallbackProps); | ||
static getData = Data.getData; | ||
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"]; | ||
var VictoryPieBase = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryPieBase, _React$Component); | ||
// Overridden in victory-native | ||
shouldAnimate() { | ||
return Boolean(this.props.animate); | ||
var _super = _createSuper(VictoryPieBase); | ||
function VictoryPieBase() { | ||
_classCallCheck(this, VictoryPieBase); | ||
return _super.apply(this, arguments); | ||
} | ||
renderComponents(props, shouldRenderDatum) { | ||
if (shouldRenderDatum === void 0) { | ||
shouldRenderDatum = datumHasXandY; | ||
_createClass(VictoryPieBase, [{ | ||
key: "shouldAnimate", | ||
value: // Overridden in victory-native | ||
function shouldAnimate() { | ||
return Boolean(this.props.animate); | ||
} | ||
const { | ||
dataComponent, | ||
labelComponent, | ||
groupComponent, | ||
labelIndicator, | ||
labelPosition | ||
} = props; | ||
if (!groupComponent) { | ||
throw new Error("VictoryPie expects a groupComponent prop"); | ||
} | ||
const showIndicator = labelIndicator && labelPosition === "centroid"; | ||
const children = []; | ||
if (dataComponent) { | ||
const dataComponents = this.dataKeys.reduce((validDataComponents, _dataKey, index) => { | ||
const dataProps = this.getComponentProps(dataComponent, "data", index); | ||
if (shouldRenderDatum(dataProps.datum)) { | ||
validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps)); | ||
}, { | ||
key: "renderComponents", | ||
value: function renderComponents(props) { | ||
var _this = this; | ||
var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY; | ||
var dataComponent = props.dataComponent, | ||
labelComponent = props.labelComponent, | ||
groupComponent = props.groupComponent, | ||
labelIndicator = props.labelIndicator, | ||
labelPosition = props.labelPosition; | ||
if (!groupComponent) { | ||
throw new Error("VictoryPie expects a groupComponent prop"); | ||
} | ||
var showIndicator = labelIndicator && labelPosition === "centroid"; | ||
var children = []; | ||
if (dataComponent) { | ||
var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) { | ||
var dataProps = _this.getComponentProps(dataComponent, "data", index); | ||
if (shouldRenderDatum(dataProps.datum)) { | ||
validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps)); | ||
} | ||
return validDataComponents; | ||
}, []); | ||
children.push.apply(children, _toConsumableArray(dataComponents)); | ||
} | ||
if (labelComponent) { | ||
var labelComponents = this.dataKeys.map(function (_dataKey, index) { | ||
var labelProps = _this.getComponentProps(labelComponent, "labels", index); | ||
if (labelProps.text !== undefined && labelProps.text !== null) { | ||
return /*#__PURE__*/React.cloneElement(labelComponent, labelProps); | ||
} | ||
return undefined; | ||
}).filter(function (comp) { | ||
return comp !== undefined; | ||
}); | ||
children.push.apply(children, _toConsumableArray(labelComponents)); | ||
} | ||
if (showIndicator && labelIndicator) { | ||
var labelIndicatorComponent = /*#__PURE__*/React.createElement(LineSegment, null); | ||
if (typeof labelIndicator === "object") { | ||
// pass user provided react component | ||
labelIndicatorComponent = labelIndicator; | ||
} | ||
return validDataComponents; | ||
}, []); | ||
children.push(...dataComponents); | ||
var labelIndicatorComponents = this.dataKeys.map(function (_dataKey, index) { | ||
var labelIndicatorProps = _this.getComponentProps(labelIndicatorComponent, "labelIndicators", index); | ||
return /*#__PURE__*/React.cloneElement(labelIndicatorComponent, labelIndicatorProps); | ||
}); | ||
children.push.apply(children, _toConsumableArray(labelIndicatorComponents)); | ||
} | ||
return this.renderContainer(groupComponent, children); | ||
} | ||
if (labelComponent) { | ||
const labelComponents = this.dataKeys.map((_dataKey, index) => { | ||
const labelProps = this.getComponentProps(labelComponent, "labels", index); | ||
if (labelProps.text !== undefined && labelProps.text !== null) { | ||
return /*#__PURE__*/React.cloneElement(labelComponent, labelProps); | ||
} | ||
return undefined; | ||
}).filter(comp => comp !== undefined); | ||
children.push(...labelComponents); | ||
} | ||
if (showIndicator && labelIndicator) { | ||
let labelIndicatorComponent = /*#__PURE__*/React.createElement(LineSegment, null); | ||
if (typeof labelIndicator === "object") { | ||
// pass user provided react component | ||
labelIndicatorComponent = labelIndicator; | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var animationWhitelist = VictoryPie.animationWhitelist, | ||
role = VictoryPie.role; | ||
var props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
const labelIndicatorComponents = this.dataKeys.map((_dataKey, index) => { | ||
const labelIndicatorProps = this.getComponentProps(labelIndicatorComponent, "labelIndicators", index); | ||
return /*#__PURE__*/React.cloneElement(labelIndicatorComponent, labelIndicatorProps); | ||
}); | ||
children.push(...labelIndicatorComponents); | ||
var children = this.renderComponents(props); | ||
var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return UserProps.withSafeUserProps(component, props); | ||
} | ||
return this.renderContainer(groupComponent, children); | ||
} | ||
render() { | ||
const { | ||
animationWhitelist, | ||
role | ||
} = VictoryPie; | ||
const props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
}]); | ||
return VictoryPieBase; | ||
}(React.Component); | ||
VictoryPieBase.animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
VictoryPieBase.displayName = "VictoryPie"; | ||
VictoryPieBase.role = "pie"; | ||
VictoryPieBase.defaultTransitions = { | ||
onExit: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
_y: 0, | ||
label: " " | ||
}; | ||
} | ||
const children = this.renderComponents(props); | ||
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return UserProps.withSafeUserProps(component, props); | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
_y: 0, | ||
label: " " | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
y_: datum._y, | ||
label: datum.label | ||
}; | ||
} | ||
} | ||
} | ||
export const VictoryPie = addEvents(VictoryPieBase); | ||
}; | ||
VictoryPieBase.defaultProps = { | ||
data: [{ | ||
x: "A", | ||
y: 1 | ||
}, { | ||
x: "B", | ||
y: 2 | ||
}, { | ||
x: "C", | ||
y: 3 | ||
}, { | ||
x: "D", | ||
y: 1 | ||
}, { | ||
x: "E", | ||
y: 2 | ||
}], | ||
standalone: true, | ||
dataComponent: /*#__PURE__*/React.createElement(Slice, null), | ||
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null), | ||
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null), | ||
groupComponent: /*#__PURE__*/React.createElement("g", null), | ||
sortOrder: "ascending", | ||
theme: VictoryTheme.grayscale | ||
}; | ||
VictoryPieBase.getBaseProps = function (props) { | ||
return getBaseProps(props, fallbackProps); | ||
}; | ||
VictoryPieBase.getData = Data.getData; | ||
VictoryPieBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"]; | ||
export var VictoryPie = addEvents(VictoryPieBase); |
@@ -7,35 +7,45 @@ "use strict"; | ||
exports.getYOffsetMultiplayerByAngle = exports.getYOffset = exports.getXOffsetMultiplayerByAngle = exports.getXOffset = exports.getLabelIndicatorPropsForLineSegment = exports.getBaseProps = exports.getAverage = void 0; | ||
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject")); | ||
var _defaults2 = _interopRequireDefault(require("lodash/defaults")); | ||
var d3Shape = _interopRequireWildcard(require("victory-vendor/d3-shape")); | ||
var _victoryCore = require("victory-core"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 90, 135, 180, 225, 270, 315, 360] }]*/ | ||
const checkForValidText = text => { | ||
var checkForValidText = function (text) { | ||
if (text === undefined || text === null || _victoryCore.Helpers.isFunction(text)) { | ||
return text; | ||
} | ||
return `${text}`; | ||
return "".concat(text); | ||
}; | ||
const getColor = (style, colors, index) => { | ||
var getColor = function (style, colors, index) { | ||
if (style && style.data && style.data.fill) { | ||
return style.data.fill; | ||
} | ||
return colors && colors[index % colors.length]; | ||
}; | ||
const getRadius = (props, padding) => { | ||
var getRadius = function (props, padding) { | ||
if (typeof props.radius === "number") { | ||
return props.radius; | ||
} | ||
return Math.min(props.width - padding.left - padding.right, props.height - padding.top - padding.bottom) / 2; | ||
}; | ||
const getOrigin = (props, padding) => { | ||
const { | ||
width, | ||
height | ||
} = props; | ||
const origin = (0, _isPlainObject2.default)(props.origin) ? props.origin : {}; | ||
var getOrigin = function (props, padding) { | ||
var width = props.width, | ||
height = props.height; | ||
var origin = (0, _isPlainObject2.default)(props.origin) ? props.origin : {}; | ||
return { | ||
@@ -46,5 +56,6 @@ x: origin.x !== undefined ? origin.x : (padding.left - padding.right + width) / 2, | ||
}; | ||
const getSlices = (props, data) => { | ||
const padAngle = _victoryCore.Helpers.isFunction(props.padAngle) ? 0 : props.padAngle; | ||
const layoutFunction = d3Shape.pie().sort(null).startAngle(_victoryCore.Helpers.degreesToRadians(props.startAngle)).endAngle(_victoryCore.Helpers.degreesToRadians(props.endAngle)).padAngle(_victoryCore.Helpers.degreesToRadians(padAngle)).value(datum => { | ||
var getSlices = function (props, data) { | ||
var padAngle = _victoryCore.Helpers.isFunction(props.padAngle) ? 0 : props.padAngle; | ||
var layoutFunction = d3Shape.pie().sort(null).startAngle(_victoryCore.Helpers.degreesToRadians(props.startAngle)).endAngle(_victoryCore.Helpers.degreesToRadians(props.endAngle)).padAngle(_victoryCore.Helpers.degreesToRadians(padAngle)).value(function (datum) { | ||
return datum._y; | ||
@@ -54,36 +65,43 @@ }); | ||
}; | ||
const getCalculatedValues = props => { | ||
const { | ||
colorScale | ||
} = props; | ||
const styleObject = _victoryCore.Helpers.getDefaultStyles(props, "pie"); | ||
const style = _victoryCore.Helpers.getStyles(props.style, styleObject); | ||
const colors = Array.isArray(colorScale) ? colorScale : _victoryCore.Style.getColorScale(colorScale); | ||
const padding = _victoryCore.Helpers.getPadding(props); | ||
const defaultRadius = getRadius(props, padding); | ||
const origin = getOrigin(props, padding); | ||
const data = _victoryCore.Data.getData(props); | ||
const slices = getSlices(props, data); | ||
var getCalculatedValues = function (props) { | ||
var colorScale = props.colorScale; | ||
var styleObject = _victoryCore.Helpers.getDefaultStyles(props, "pie"); | ||
var style = _victoryCore.Helpers.getStyles(props.style, styleObject); | ||
var colors = Array.isArray(colorScale) ? colorScale : _victoryCore.Style.getColorScale(colorScale); | ||
var padding = _victoryCore.Helpers.getPadding(props); | ||
var defaultRadius = getRadius(props, padding); | ||
var origin = getOrigin(props, padding); | ||
var data = _victoryCore.Data.getData(props); | ||
var slices = getSlices(props, data); | ||
return Object.assign({}, props, { | ||
style, | ||
colors, | ||
padding, | ||
defaultRadius, | ||
data, | ||
slices, | ||
origin | ||
style: style, | ||
colors: colors, | ||
padding: padding, | ||
defaultRadius: defaultRadius, | ||
data: data, | ||
slices: slices, | ||
origin: origin | ||
}); | ||
}; | ||
const getSliceStyle = (index, calculatedValues) => { | ||
const { | ||
style, | ||
colors | ||
} = calculatedValues; | ||
const fill = getColor(style, colors, index); | ||
var getSliceStyle = function (index, calculatedValues) { | ||
var style = calculatedValues.style, | ||
colors = calculatedValues.colors; | ||
var fill = getColor(style, colors, index); | ||
return Object.assign({ | ||
fill | ||
fill: fill | ||
}, style.data); | ||
}; | ||
const getLabelText = (props, datum, index) => { | ||
let text; | ||
var getLabelText = function (props, datum, index) { | ||
var text; | ||
if (datum.label) { | ||
@@ -96,20 +114,25 @@ text = datum.label; | ||
} | ||
return checkForValidText(text); | ||
}; | ||
const getLabelArc = labelRadius => { | ||
var getLabelArc = function (labelRadius) { | ||
return d3Shape.arc().outerRadius(labelRadius).innerRadius(labelRadius); | ||
}; | ||
const getCalculatedLabelRadius = (radius, labelRadius, style) => { | ||
const padding = style && style.padding || 0; | ||
var getCalculatedLabelRadius = function (radius, labelRadius, style) { | ||
var padding = style && style.padding || 0; | ||
return labelRadius || radius + padding; | ||
}; | ||
const getLabelPosition = (arc, slice, position) => { | ||
const construct = { | ||
var getLabelPosition = function (arc, slice, position) { | ||
var construct = { | ||
startAngle: position === "startAngle" ? slice.startAngle : slice.endAngle, | ||
endAngle: position === "endAngle" ? slice.endAngle : slice.startAngle | ||
}; | ||
const clonedArc = Object.assign({}, slice, construct); | ||
var clonedArc = Object.assign({}, slice, construct); | ||
return arc.centroid(clonedArc); | ||
}; | ||
const getLabelOrientation = (degree, labelPlacement) => { | ||
var getLabelOrientation = function (degree, labelPlacement) { | ||
if (labelPlacement === "perpendicular") { | ||
@@ -120,2 +143,3 @@ return degree > 90 && degree < 270 ? "bottom" : "top"; | ||
} | ||
if (degree < 45 || degree > 315) { | ||
@@ -128,18 +152,25 @@ return "top"; | ||
} | ||
return "left"; | ||
}; | ||
const getTextAnchor = orientation => { | ||
var getTextAnchor = function (orientation) { | ||
if (orientation === "top" || orientation === "bottom") { | ||
return "middle"; | ||
} | ||
return orientation === "right" ? "start" : "end"; | ||
}; | ||
const getVerticalAnchor = orientation => { | ||
var getVerticalAnchor = function (orientation) { | ||
if (orientation === "left" || orientation === "right") { | ||
return "middle"; | ||
} | ||
return orientation === "bottom" ? "start" : "end"; | ||
}; | ||
const getBaseLabelAngle = (slice, labelPosition, labelStyle) => { | ||
let baseAngle = 0; | ||
var getBaseLabelAngle = function (slice, labelPosition, labelStyle) { | ||
var baseAngle = 0; | ||
if (labelPosition.angle !== undefined) { | ||
@@ -152,162 +183,186 @@ baseAngle = labelStyle.angle; | ||
} | ||
const positiveAngle = baseAngle < 0 ? 360 - baseAngle : baseAngle; | ||
var positiveAngle = baseAngle < 0 ? 360 - baseAngle : baseAngle; | ||
return positiveAngle % 360; | ||
}; | ||
const getLabelAngle = (baseAngle, labelPlacement) => { | ||
var getLabelAngle = function (baseAngle, labelPlacement) { | ||
if (labelPlacement === "vertical") { | ||
return 0; | ||
} | ||
if (labelPlacement === "parallel") { | ||
return baseAngle > 180 && baseAngle < 360 ? baseAngle + 90 : baseAngle - 90; | ||
} | ||
return baseAngle > 90 && baseAngle < 270 ? baseAngle - 180 : baseAngle; | ||
}; | ||
const getLabelProps = (text, dataProps, calculatedValues) => { | ||
const { | ||
index, | ||
datum, | ||
data, | ||
slice, | ||
labelComponent, | ||
theme | ||
} = dataProps; | ||
const { | ||
style, | ||
defaultRadius, | ||
origin, | ||
width, | ||
height | ||
} = calculatedValues; | ||
const labelRadius = _victoryCore.Helpers.evaluateProp(calculatedValues.labelRadius, Object.assign({ | ||
text | ||
var getLabelProps = function (text, dataProps, calculatedValues) { | ||
var index = dataProps.index, | ||
datum = dataProps.datum, | ||
data = dataProps.data, | ||
slice = dataProps.slice, | ||
labelComponent = dataProps.labelComponent, | ||
theme = dataProps.theme; | ||
var style = calculatedValues.style, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
origin = calculatedValues.origin, | ||
width = calculatedValues.width, | ||
height = calculatedValues.height; | ||
var labelRadius = _victoryCore.Helpers.evaluateProp(calculatedValues.labelRadius, Object.assign({ | ||
text: text | ||
}, dataProps)); | ||
const labelPosition = _victoryCore.Helpers.evaluateProp(calculatedValues.labelPosition, Object.assign({ | ||
text | ||
var labelPosition = _victoryCore.Helpers.evaluateProp(calculatedValues.labelPosition, Object.assign({ | ||
text: text | ||
}, dataProps)) || "centroid"; | ||
const labelPlacement = _victoryCore.Helpers.evaluateProp(calculatedValues.labelPlacement, Object.assign({ | ||
text | ||
var labelPlacement = _victoryCore.Helpers.evaluateProp(calculatedValues.labelPlacement, Object.assign({ | ||
text: text | ||
}, dataProps)) || "vertical"; | ||
const labelStyle = Object.assign({ | ||
var labelStyle = Object.assign({ | ||
padding: 0 | ||
}, style.labels); | ||
const evaluatedStyle = _victoryCore.Helpers.evaluateStyle(labelStyle, Object.assign({ | ||
labelRadius, | ||
text | ||
var evaluatedStyle = _victoryCore.Helpers.evaluateStyle(labelStyle, Object.assign({ | ||
labelRadius: labelRadius, | ||
text: text | ||
}, dataProps)); | ||
const calculatedLabelRadius = getCalculatedLabelRadius(defaultRadius, labelRadius, evaluatedStyle); | ||
const labelArc = getLabelArc(calculatedLabelRadius); | ||
const position = getLabelPosition(labelArc, slice, labelPosition); | ||
const baseAngle = getBaseLabelAngle(slice, labelPosition, labelStyle); | ||
const labelAngle = getLabelAngle(baseAngle, labelPlacement); | ||
const orientation = getLabelOrientation(baseAngle, labelPlacement); | ||
const textAnchor = labelStyle.textAnchor || getTextAnchor(orientation); | ||
const verticalAnchor = labelStyle.verticalAnchor || getVerticalAnchor(orientation); | ||
const labelProps = { | ||
width, | ||
height, | ||
index, | ||
datum, | ||
data, | ||
slice, | ||
orientation, | ||
text, | ||
var calculatedLabelRadius = getCalculatedLabelRadius(defaultRadius, labelRadius, evaluatedStyle); | ||
var labelArc = getLabelArc(calculatedLabelRadius); | ||
var position = getLabelPosition(labelArc, slice, labelPosition); | ||
var baseAngle = getBaseLabelAngle(slice, labelPosition, labelStyle); | ||
var labelAngle = getLabelAngle(baseAngle, labelPlacement); | ||
var orientation = getLabelOrientation(baseAngle, labelPlacement); | ||
var textAnchor = labelStyle.textAnchor || getTextAnchor(orientation); | ||
var verticalAnchor = labelStyle.verticalAnchor || getVerticalAnchor(orientation); | ||
var labelProps = { | ||
width: width, | ||
height: height, | ||
index: index, | ||
datum: datum, | ||
data: data, | ||
slice: slice, | ||
orientation: orientation, | ||
text: text, | ||
style: labelStyle, | ||
x: Math.round(position[0]) + origin.x, | ||
y: Math.round(position[1]) + origin.y, | ||
textAnchor, | ||
verticalAnchor, | ||
textAnchor: textAnchor, | ||
verticalAnchor: verticalAnchor, | ||
angle: labelAngle, | ||
calculatedLabelRadius | ||
calculatedLabelRadius: calculatedLabelRadius | ||
}; | ||
if (!_victoryCore.Helpers.isTooltip(labelComponent)) { | ||
return labelProps; | ||
} | ||
const tooltipTheme = theme && theme.tooltip || {}; | ||
var tooltipTheme = theme && theme.tooltip || {}; | ||
return (0, _defaults2.default)({}, labelProps, _victoryCore.Helpers.omit(tooltipTheme, ["style"])); | ||
}; | ||
const getXOffsetMultiplayerByAngle = angle => Math.cos(angle - _victoryCore.Helpers.degreesToRadians(90)); | ||
var getXOffsetMultiplayerByAngle = function (angle) { | ||
return Math.cos(angle - _victoryCore.Helpers.degreesToRadians(90)); | ||
}; | ||
exports.getXOffsetMultiplayerByAngle = getXOffsetMultiplayerByAngle; | ||
const getYOffsetMultiplayerByAngle = angle => Math.sin(angle - _victoryCore.Helpers.degreesToRadians(90)); | ||
var getYOffsetMultiplayerByAngle = function (angle) { | ||
return Math.sin(angle - _victoryCore.Helpers.degreesToRadians(90)); | ||
}; | ||
exports.getYOffsetMultiplayerByAngle = getYOffsetMultiplayerByAngle; | ||
const getXOffset = (offset, angle) => offset * getXOffsetMultiplayerByAngle(angle); | ||
var getXOffset = function (offset, angle) { | ||
return offset * getXOffsetMultiplayerByAngle(angle); | ||
}; | ||
exports.getXOffset = getXOffset; | ||
const getYOffset = (offset, angle) => offset * getYOffsetMultiplayerByAngle(angle); | ||
var getYOffset = function (offset, angle) { | ||
return offset * getYOffsetMultiplayerByAngle(angle); | ||
}; | ||
exports.getYOffset = getYOffset; | ||
const getAverage = array => array.reduce((acc, cur) => acc + cur, 0) / array.length; | ||
var getAverage = function (array) { | ||
return array.reduce(function (acc, cur) { | ||
return acc + cur; | ||
}, 0) / array.length; | ||
}; | ||
exports.getAverage = getAverage; | ||
const getLabelIndicatorPropsForLineSegment = (props, calculatedValues, labelProps) => { | ||
const { | ||
innerRadius, | ||
radius, | ||
slice: { | ||
startAngle, | ||
endAngle | ||
}, | ||
labelIndicatorInnerOffset, | ||
labelIndicatorOuterOffset, | ||
index | ||
} = props; | ||
const { | ||
height, | ||
width | ||
} = calculatedValues; | ||
const { | ||
calculatedLabelRadius | ||
} = labelProps; | ||
// calculation | ||
const middleRadius = getAverage([innerRadius, radius]); | ||
const midAngle = getAverage([endAngle, startAngle]); | ||
const centerX = width / 2; | ||
const centerY = height / 2; | ||
const innerOffset = middleRadius + labelIndicatorInnerOffset; | ||
const outerOffset = calculatedLabelRadius - labelIndicatorOuterOffset; | ||
const x1 = centerX + getXOffset(innerOffset, midAngle); | ||
const y1 = centerY + getYOffset(innerOffset, midAngle); | ||
const x2 = centerX + getXOffset(outerOffset, midAngle); | ||
const y2 = centerY + getYOffset(outerOffset, midAngle); | ||
const labelIndicatorProps = { | ||
x1, | ||
y1, | ||
x2, | ||
y2, | ||
index | ||
var getLabelIndicatorPropsForLineSegment = function (props, calculatedValues, labelProps) { | ||
var innerRadius = props.innerRadius, | ||
radius = props.radius, | ||
_props$slice = props.slice, | ||
startAngle = _props$slice.startAngle, | ||
endAngle = _props$slice.endAngle, | ||
labelIndicatorInnerOffset = props.labelIndicatorInnerOffset, | ||
labelIndicatorOuterOffset = props.labelIndicatorOuterOffset, | ||
index = props.index; | ||
var height = calculatedValues.height, | ||
width = calculatedValues.width; | ||
var calculatedLabelRadius = labelProps.calculatedLabelRadius; // calculation | ||
var middleRadius = getAverage([innerRadius, radius]); | ||
var midAngle = getAverage([endAngle, startAngle]); | ||
var centerX = width / 2; | ||
var centerY = height / 2; | ||
var innerOffset = middleRadius + labelIndicatorInnerOffset; | ||
var outerOffset = calculatedLabelRadius - labelIndicatorOuterOffset; | ||
var x1 = centerX + getXOffset(innerOffset, midAngle); | ||
var y1 = centerY + getYOffset(innerOffset, midAngle); | ||
var x2 = centerX + getXOffset(outerOffset, midAngle); | ||
var y2 = centerY + getYOffset(outerOffset, midAngle); | ||
var labelIndicatorProps = { | ||
x1: x1, | ||
y1: y1, | ||
x2: x2, | ||
y2: y2, | ||
index: index | ||
}; | ||
return (0, _defaults2.default)({}, labelIndicatorProps); | ||
}; | ||
exports.getLabelIndicatorPropsForLineSegment = getLabelIndicatorPropsForLineSegment; | ||
const getBaseProps = (initialProps, fallbackProps) => { | ||
const props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "pie"); | ||
const calculatedValues = getCalculatedValues(props); | ||
const { | ||
slices, | ||
style, | ||
data, | ||
origin, | ||
defaultRadius, | ||
labels, | ||
events, | ||
sharedEvents, | ||
height, | ||
width, | ||
standalone, | ||
name, | ||
innerRadius, | ||
cornerRadius, | ||
padAngle, | ||
disableInlineStyles, | ||
labelIndicator | ||
} = calculatedValues; | ||
const radius = props.radius || defaultRadius; | ||
const initialChildProps = { | ||
var getBaseProps = function (initialProps, fallbackProps) { | ||
var props = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "pie"); | ||
var calculatedValues = getCalculatedValues(props); | ||
var slices = calculatedValues.slices, | ||
style = calculatedValues.style, | ||
data = calculatedValues.data, | ||
origin = calculatedValues.origin, | ||
defaultRadius = calculatedValues.defaultRadius, | ||
labels = calculatedValues.labels, | ||
events = calculatedValues.events, | ||
sharedEvents = calculatedValues.sharedEvents, | ||
height = calculatedValues.height, | ||
width = calculatedValues.width, | ||
standalone = calculatedValues.standalone, | ||
name = calculatedValues.name, | ||
innerRadius = calculatedValues.innerRadius, | ||
cornerRadius = calculatedValues.cornerRadius, | ||
padAngle = calculatedValues.padAngle, | ||
disableInlineStyles = calculatedValues.disableInlineStyles, | ||
labelIndicator = calculatedValues.labelIndicator; | ||
var radius = props.radius || defaultRadius; | ||
var initialChildProps = { | ||
parent: { | ||
standalone, | ||
height, | ||
width, | ||
slices, | ||
name, | ||
standalone: standalone, | ||
height: height, | ||
width: width, | ||
slices: slices, | ||
name: name, | ||
style: style.parent | ||
} | ||
}; | ||
return slices.reduce((childProps, slice, index) => { | ||
const datum = (0, _defaults2.default)({}, data[index], { | ||
return slices.reduce(function (childProps, slice, index) { | ||
var datum = (0, _defaults2.default)({}, data[index], { | ||
startAngle: _victoryCore.Helpers.radiansToDegrees(slice.startAngle), | ||
@@ -317,15 +372,15 @@ endAngle: _victoryCore.Helpers.radiansToDegrees(slice.endAngle), | ||
}); | ||
const eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
const dataProps = { | ||
index, | ||
slice, | ||
datum, | ||
data, | ||
origin, | ||
innerRadius, | ||
radius, | ||
cornerRadius, | ||
padAngle, | ||
var eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index; | ||
var dataProps = { | ||
index: index, | ||
slice: slice, | ||
datum: datum, | ||
data: data, | ||
origin: origin, | ||
innerRadius: innerRadius, | ||
radius: radius, | ||
cornerRadius: cornerRadius, | ||
padAngle: padAngle, | ||
style: disableInlineStyles ? {} : getSliceStyle(index, calculatedValues), | ||
disableInlineStyles | ||
disableInlineStyles: disableInlineStyles | ||
}; | ||
@@ -335,8 +390,12 @@ childProps[eventKey] = { | ||
}; | ||
const text = getLabelText(props, datum, index); | ||
var text = getLabelText(props, datum, index); | ||
if (text !== undefined && text !== null || labels && (events || sharedEvents)) { | ||
const evaluatedText = _victoryCore.Helpers.evaluateProp(text, dataProps); | ||
var evaluatedText = _victoryCore.Helpers.evaluateProp(text, dataProps); | ||
childProps[eventKey].labels = getLabelProps(evaluatedText, Object.assign({}, props, dataProps), calculatedValues); | ||
if (labelIndicator) { | ||
const labelProps = childProps[eventKey].labels; | ||
var labelProps = childProps[eventKey].labels; | ||
if (labelProps.calculatedLabelRadius > radius) { | ||
@@ -347,5 +406,7 @@ childProps[eventKey].labelIndicators = getLabelIndicatorPropsForLineSegment(Object.assign({}, props, dataProps), calculatedValues, labelProps); | ||
} | ||
return childProps; | ||
}, initialChildProps); | ||
}; | ||
exports.getBaseProps = getBaseProps; |
@@ -6,3 +6,5 @@ "use strict"; | ||
}); | ||
var _victoryPie = require("./victory-pie"); | ||
Object.keys(_victoryPie).forEach(function (key) { | ||
@@ -18,3 +20,5 @@ if (key === "default" || key === "__esModule") return; | ||
}); | ||
var _slice = require("./slice"); | ||
Object.keys(_slice).forEach(function (key) { | ||
@@ -21,0 +25,0 @@ if (key === "default" || key === "__esModule") return; |
127
lib/slice.js
@@ -7,30 +7,48 @@ "use strict"; | ||
exports.Slice = void 0; | ||
var _defaults2 = _interopRequireDefault(require("lodash/defaults")); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _victoryCore = require("victory-core"); | ||
var d3Shape = _interopRequireWildcard(require("victory-vendor/d3-shape")); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const getPath = props => { | ||
const { | ||
slice, | ||
radius, | ||
innerRadius, | ||
cornerRadius | ||
} = props; | ||
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 getPath = function (props) { | ||
var slice = props.slice, | ||
radius = props.radius, | ||
innerRadius = props.innerRadius, | ||
cornerRadius = props.cornerRadius; | ||
if (_victoryCore.Helpers.isFunction(props.pathFunction)) { | ||
return props.pathFunction(slice); | ||
} | ||
const padAngle = _victoryCore.Helpers.degreesToRadians(props.padAngle); | ||
const startAngle = _victoryCore.Helpers.degreesToRadians(props.sliceStartAngle); | ||
const endAngle = _victoryCore.Helpers.degreesToRadians(props.sliceEndAngle); | ||
const pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0); | ||
var padAngle = _victoryCore.Helpers.degreesToRadians(props.padAngle); | ||
var startAngle = _victoryCore.Helpers.degreesToRadians(props.sliceStartAngle); | ||
var endAngle = _victoryCore.Helpers.degreesToRadians(props.sliceEndAngle); | ||
var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0); | ||
return pathFunction((0, _defaults2.default)({ | ||
startAngle, | ||
endAngle, | ||
padAngle | ||
startAngle: startAngle, | ||
endAngle: endAngle, | ||
padAngle: padAngle | ||
}, slice)); | ||
}; | ||
const evaluateProps = props => { | ||
var evaluateProps = function (props) { | ||
/** | ||
@@ -51,31 +69,42 @@ * * Potential evaluated props of following must be evaluated in this order: | ||
*/ | ||
const style = _victoryCore.Helpers.evaluateStyle(props.style, props); | ||
const radius = _victoryCore.Helpers.evaluateProp(props.radius, Object.assign({}, props, { | ||
style | ||
var style = _victoryCore.Helpers.evaluateStyle(props.style, props); | ||
var radius = _victoryCore.Helpers.evaluateProp(props.radius, Object.assign({}, props, { | ||
style: style | ||
})); | ||
const innerRadius = _victoryCore.Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, { | ||
style, | ||
radius | ||
var innerRadius = _victoryCore.Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, { | ||
style: style, | ||
radius: radius | ||
})); | ||
const ariaLabel = _victoryCore.Helpers.evaluateProp(props.ariaLabel, props); | ||
const id = _victoryCore.Helpers.evaluateProp(props.id, props); | ||
const cornerRadius = _victoryCore.Helpers.evaluateProp(props.cornerRadius, props); | ||
const padAngle = _victoryCore.Helpers.evaluateProp(props.padAngle, props); | ||
const sliceStartAngle = _victoryCore.Helpers.evaluateProp(props.sliceStartAngle, props); | ||
const sliceEndAngle = _victoryCore.Helpers.evaluateProp(props.sliceEndAngle, props); | ||
const tabIndex = _victoryCore.Helpers.evaluateProp(props.tabIndex, props); | ||
var ariaLabel = _victoryCore.Helpers.evaluateProp(props.ariaLabel, props); | ||
var id = _victoryCore.Helpers.evaluateProp(props.id, props); | ||
var cornerRadius = _victoryCore.Helpers.evaluateProp(props.cornerRadius, props); | ||
var padAngle = _victoryCore.Helpers.evaluateProp(props.padAngle, props); | ||
var sliceStartAngle = _victoryCore.Helpers.evaluateProp(props.sliceStartAngle, props); | ||
var sliceEndAngle = _victoryCore.Helpers.evaluateProp(props.sliceEndAngle, props); | ||
var tabIndex = _victoryCore.Helpers.evaluateProp(props.tabIndex, props); | ||
return Object.assign({}, props, { | ||
ariaLabel, | ||
style, | ||
radius, | ||
innerRadius, | ||
id, | ||
cornerRadius, | ||
padAngle, | ||
sliceStartAngle, | ||
sliceEndAngle, | ||
tabIndex | ||
ariaLabel: ariaLabel, | ||
style: style, | ||
radius: radius, | ||
innerRadius: innerRadius, | ||
id: id, | ||
cornerRadius: cornerRadius, | ||
padAngle: padAngle, | ||
sliceStartAngle: sliceStartAngle, | ||
sliceEndAngle: sliceEndAngle, | ||
tabIndex: tabIndex | ||
}); | ||
}; | ||
const defaultProps = { | ||
var defaultProps = { | ||
pathComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.Path, null), | ||
@@ -85,10 +114,7 @@ role: "presentation", | ||
}; | ||
const Slice = initialProps => { | ||
const props = evaluateProps({ | ||
...defaultProps, | ||
...initialProps | ||
}); | ||
const defaultTransform = props.origin ? `translate(${props.origin.x}, ${props.origin.y})` : undefined; | ||
return /*#__PURE__*/_react.default.cloneElement(props.pathComponent, { | ||
...props.events, | ||
var Slice = function (initialProps) { | ||
var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps)); | ||
var defaultTransform = props.origin ? "translate(".concat(props.origin.x, ", ").concat(props.origin.y, ")") : undefined; | ||
return /*#__PURE__*/_react.default.cloneElement(props.pathComponent, _objectSpread(_objectSpread({}, props.events), {}, { | ||
"aria-label": props.ariaLabel, | ||
@@ -103,4 +129,5 @@ d: getPath(props), | ||
tabIndex: props.tabIndex | ||
}); | ||
})); | ||
}; | ||
exports.Slice = Slice; |
@@ -7,8 +7,46 @@ "use strict"; | ||
exports.VictoryPie = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _victoryCore = require("victory-core"); | ||
var _helperMethods = require("./helper-methods"); | ||
var _slice = require("./slice"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const fallbackProps = { | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
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 _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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
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, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var fallbackProps = { | ||
endAngle: 360, | ||
@@ -27,129 +65,173 @@ height: 400, | ||
}; | ||
const datumHasXandY = datum => { | ||
var datumHasXandY = function (datum) { | ||
return !_victoryCore.Helpers.isNil(datum._x) && !_victoryCore.Helpers.isNil(datum._y); | ||
}; | ||
}; // eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
class VictoryPieBase extends _react.default.Component { | ||
static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
static displayName = "VictoryPie"; | ||
static role = "pie"; | ||
static defaultTransitions = { | ||
onExit: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
label: " " | ||
}) | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: () => ({ | ||
_y: 0, | ||
label: " " | ||
}), | ||
after: datum => ({ | ||
y_: datum._y, | ||
label: datum.label | ||
}) | ||
} | ||
}; | ||
static defaultProps = { | ||
data: [{ | ||
x: "A", | ||
y: 1 | ||
}, { | ||
x: "B", | ||
y: 2 | ||
}, { | ||
x: "C", | ||
y: 3 | ||
}, { | ||
x: "D", | ||
y: 1 | ||
}, { | ||
x: "E", | ||
y: 2 | ||
}], | ||
standalone: true, | ||
dataComponent: /*#__PURE__*/_react.default.createElement(_slice.Slice, null), | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null), | ||
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
groupComponent: /*#__PURE__*/_react.default.createElement("g", null), | ||
sortOrder: "ascending", | ||
theme: _victoryCore.VictoryTheme.grayscale | ||
}; | ||
static getBaseProps = props => (0, _helperMethods.getBaseProps)(props, fallbackProps); | ||
static getData = _victoryCore.Data.getData; | ||
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"]; | ||
var VictoryPieBase = /*#__PURE__*/function (_React$Component) { | ||
_inherits(VictoryPieBase, _React$Component); | ||
// Overridden in victory-native | ||
shouldAnimate() { | ||
return Boolean(this.props.animate); | ||
var _super = _createSuper(VictoryPieBase); | ||
function VictoryPieBase() { | ||
_classCallCheck(this, VictoryPieBase); | ||
return _super.apply(this, arguments); | ||
} | ||
renderComponents(props, shouldRenderDatum) { | ||
if (shouldRenderDatum === void 0) { | ||
shouldRenderDatum = datumHasXandY; | ||
_createClass(VictoryPieBase, [{ | ||
key: "shouldAnimate", | ||
value: // Overridden in victory-native | ||
function shouldAnimate() { | ||
return Boolean(this.props.animate); | ||
} | ||
const { | ||
dataComponent, | ||
labelComponent, | ||
groupComponent, | ||
labelIndicator, | ||
labelPosition | ||
} = props; | ||
if (!groupComponent) { | ||
throw new Error("VictoryPie expects a groupComponent prop"); | ||
} | ||
const showIndicator = labelIndicator && labelPosition === "centroid"; | ||
const children = []; | ||
if (dataComponent) { | ||
const dataComponents = this.dataKeys.reduce((validDataComponents, _dataKey, index) => { | ||
const dataProps = this.getComponentProps(dataComponent, "data", index); | ||
if (shouldRenderDatum(dataProps.datum)) { | ||
validDataComponents.push( /*#__PURE__*/_react.default.cloneElement(dataComponent, dataProps)); | ||
}, { | ||
key: "renderComponents", | ||
value: function renderComponents(props) { | ||
var _this = this; | ||
var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY; | ||
var dataComponent = props.dataComponent, | ||
labelComponent = props.labelComponent, | ||
groupComponent = props.groupComponent, | ||
labelIndicator = props.labelIndicator, | ||
labelPosition = props.labelPosition; | ||
if (!groupComponent) { | ||
throw new Error("VictoryPie expects a groupComponent prop"); | ||
} | ||
var showIndicator = labelIndicator && labelPosition === "centroid"; | ||
var children = []; | ||
if (dataComponent) { | ||
var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) { | ||
var dataProps = _this.getComponentProps(dataComponent, "data", index); | ||
if (shouldRenderDatum(dataProps.datum)) { | ||
validDataComponents.push( /*#__PURE__*/_react.default.cloneElement(dataComponent, dataProps)); | ||
} | ||
return validDataComponents; | ||
}, []); | ||
children.push.apply(children, _toConsumableArray(dataComponents)); | ||
} | ||
if (labelComponent) { | ||
var labelComponents = this.dataKeys.map(function (_dataKey, index) { | ||
var labelProps = _this.getComponentProps(labelComponent, "labels", index); | ||
if (labelProps.text !== undefined && labelProps.text !== null) { | ||
return /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps); | ||
} | ||
return undefined; | ||
}).filter(function (comp) { | ||
return comp !== undefined; | ||
}); | ||
children.push.apply(children, _toConsumableArray(labelComponents)); | ||
} | ||
if (showIndicator && labelIndicator) { | ||
var labelIndicatorComponent = /*#__PURE__*/_react.default.createElement(_victoryCore.LineSegment, null); | ||
if (typeof labelIndicator === "object") { | ||
// pass user provided react component | ||
labelIndicatorComponent = labelIndicator; | ||
} | ||
return validDataComponents; | ||
}, []); | ||
children.push(...dataComponents); | ||
var labelIndicatorComponents = this.dataKeys.map(function (_dataKey, index) { | ||
var labelIndicatorProps = _this.getComponentProps(labelIndicatorComponent, "labelIndicators", index); | ||
return /*#__PURE__*/_react.default.cloneElement(labelIndicatorComponent, labelIndicatorProps); | ||
}); | ||
children.push.apply(children, _toConsumableArray(labelIndicatorComponents)); | ||
} | ||
return this.renderContainer(groupComponent, children); | ||
} | ||
if (labelComponent) { | ||
const labelComponents = this.dataKeys.map((_dataKey, index) => { | ||
const labelProps = this.getComponentProps(labelComponent, "labels", index); | ||
if (labelProps.text !== undefined && labelProps.text !== null) { | ||
return /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps); | ||
} | ||
return undefined; | ||
}).filter(comp => comp !== undefined); | ||
children.push(...labelComponents); | ||
} | ||
if (showIndicator && labelIndicator) { | ||
let labelIndicatorComponent = /*#__PURE__*/_react.default.createElement(_victoryCore.LineSegment, null); | ||
if (typeof labelIndicator === "object") { | ||
// pass user provided react component | ||
labelIndicatorComponent = labelIndicator; | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var animationWhitelist = VictoryPie.animationWhitelist, | ||
role = VictoryPie.role; | ||
var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
} | ||
const labelIndicatorComponents = this.dataKeys.map((_dataKey, index) => { | ||
const labelIndicatorProps = this.getComponentProps(labelIndicatorComponent, "labelIndicators", index); | ||
return /*#__PURE__*/_react.default.cloneElement(labelIndicatorComponent, labelIndicatorProps); | ||
}); | ||
children.push(...labelIndicatorComponents); | ||
var children = this.renderComponents(props); | ||
var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return _victoryCore.UserProps.withSafeUserProps(component, props); | ||
} | ||
return this.renderContainer(groupComponent, children); | ||
} | ||
render() { | ||
const { | ||
animationWhitelist, | ||
role | ||
} = VictoryPie; | ||
const props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
return this.animateComponent(props, animationWhitelist); | ||
}]); | ||
return VictoryPieBase; | ||
}(_react.default.Component); | ||
VictoryPieBase.animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
VictoryPieBase.displayName = "VictoryPie"; | ||
VictoryPieBase.role = "pie"; | ||
VictoryPieBase.defaultTransitions = { | ||
onExit: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
_y: 0, | ||
label: " " | ||
}; | ||
} | ||
const children = this.renderComponents(props); | ||
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children; | ||
return _victoryCore.UserProps.withSafeUserProps(component, props); | ||
}, | ||
onEnter: { | ||
duration: 500, | ||
before: function () { | ||
return { | ||
_y: 0, | ||
label: " " | ||
}; | ||
}, | ||
after: function (datum) { | ||
return { | ||
y_: datum._y, | ||
label: datum.label | ||
}; | ||
} | ||
} | ||
} | ||
const VictoryPie = exports.VictoryPie = (0, _victoryCore.addEvents)(VictoryPieBase); | ||
}; | ||
VictoryPieBase.defaultProps = { | ||
data: [{ | ||
x: "A", | ||
y: 1 | ||
}, { | ||
x: "B", | ||
y: 2 | ||
}, { | ||
x: "C", | ||
y: 3 | ||
}, { | ||
x: "D", | ||
y: 1 | ||
}, { | ||
x: "E", | ||
y: 2 | ||
}], | ||
standalone: true, | ||
dataComponent: /*#__PURE__*/_react.default.createElement(_slice.Slice, null), | ||
labelComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryLabel, null), | ||
containerComponent: /*#__PURE__*/_react.default.createElement(_victoryCore.VictoryContainer, null), | ||
groupComponent: /*#__PURE__*/_react.default.createElement("g", null), | ||
sortOrder: "ascending", | ||
theme: _victoryCore.VictoryTheme.grayscale | ||
}; | ||
VictoryPieBase.getBaseProps = function (props) { | ||
return (0, _helperMethods.getBaseProps)(props, fallbackProps); | ||
}; | ||
VictoryPieBase.getData = _victoryCore.Data.getData; | ||
VictoryPieBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"]; | ||
var VictoryPie = (0, _victoryCore.addEvents)(VictoryPieBase); | ||
exports.VictoryPie = VictoryPie; |
{ | ||
"name": "victory-pie", | ||
"version": "36.9.2-next.0", | ||
"version": "36.9.2-next.1", | ||
"description": "Pie Component for Victory", | ||
@@ -24,4 +24,4 @@ "keywords": [ | ||
"lodash": "^4.17.19", | ||
"victory-core": "^36.9.2-next.0", | ||
"victory-vendor": "^36.9.2-next.0" | ||
"victory-core": "^36.9.2-next.1", | ||
"victory-vendor": "^36.9.2-next.1" | ||
}, | ||
@@ -28,0 +28,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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
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
2427773
47093
2
1
80
1
Updatedvictory-core@^36.9.2-next.1