victory-pie
Advanced tools
Comparing version 31.0.2 to 31.1.0
@@ -31,3 +31,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
}; | ||
var animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
@@ -54,3 +53,4 @@ var VictoryPie = | ||
value: function render() { | ||
var role = this.constructor.role; | ||
var animationWhitelist = VictoryPie.animationWhitelist, | ||
role = VictoryPie.role; | ||
var props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
@@ -70,2 +70,8 @@ | ||
Object.defineProperty(VictoryPie, "animationWhitelist", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"] | ||
}); | ||
Object.defineProperty(VictoryPie, "displayName", { | ||
@@ -72,0 +78,0 @@ configurable: true, |
@@ -44,3 +44,2 @@ "use strict"; | ||
}; | ||
var animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"]; | ||
@@ -67,3 +66,4 @@ var VictoryPie = | ||
value: function render() { | ||
var role = this.constructor.role; | ||
var animationWhitelist = VictoryPie.animationWhitelist, | ||
role = VictoryPie.role; | ||
@@ -84,2 +84,8 @@ var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role); | ||
Object.defineProperty(VictoryPie, "animationWhitelist", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"] | ||
}); | ||
Object.defineProperty(VictoryPie, "displayName", { | ||
@@ -86,0 +92,0 @@ configurable: true, |
{ | ||
"name": "victory-pie", | ||
"version": "31.0.2", | ||
"version": "31.1.0", | ||
"description": "Pie Component for Victory", | ||
@@ -25,3 +25,3 @@ "keywords": [ | ||
"prop-types": "^15.5.8", | ||
"victory-core": "^31.0.2" | ||
"victory-core": "^31.1.0" | ||
}, | ||
@@ -28,0 +28,0 @@ "scripts": { |
@@ -51,3 +51,3 @@ # VictoryPie | ||
*default (provided by default theme):* `colorScale="grayscale"` | ||
_default (provided by default theme):_ `colorScale="grayscale"` | ||
@@ -69,3 +69,3 @@ ```playground | ||
*default:* `containerComponent={<VictoryContainer/>}` | ||
_default:_ `containerComponent={<VictoryContainer/>}` | ||
@@ -97,3 +97,2 @@ ```jsx | ||
```playground | ||
@@ -119,3 +118,3 @@ <VictoryPie | ||
*default:* `<Slice/>` | ||
_default:_ `<Slice/>` | ||
@@ -132,5 +131,4 @@ ```jsx | ||
*default:* `endAngle={360}` | ||
_default:_ `endAngle={360}` | ||
```playground | ||
@@ -158,3 +156,3 @@ <div> | ||
```jsx | ||
eventKey="x" | ||
eventKey = "x"; | ||
``` | ||
@@ -212,3 +210,3 @@ | ||
*default:* `<g/>` | ||
_default:_ `<g/>` | ||
@@ -225,3 +223,3 @@ ```jsx | ||
*default (provided by default theme):* `height={400}` | ||
_default (provided by default theme):_ `height={400}` | ||
@@ -251,3 +249,3 @@ ```jsx | ||
*default:* `<VictoryLabel/>` | ||
_default:_ `<VictoryLabel/>` | ||
@@ -268,3 +266,3 @@ ```playground | ||
*default:* `"centroid"` | ||
_default:_ `"centroid"` | ||
@@ -313,3 +311,3 @@ ```playground | ||
```jsx | ||
name="series-1" | ||
name = "series-1"; | ||
``` | ||
@@ -351,3 +349,3 @@ | ||
*default (provided by default theme):* `padding={50}` | ||
_default (provided by default theme):_ `padding={50}` | ||
@@ -364,3 +362,2 @@ ```jsx | ||
```playground | ||
@@ -373,3 +370,2 @@ <VictoryPie | ||
### sharedEvents | ||
@@ -388,3 +384,3 @@ | ||
```jsx | ||
sortKey="x" | ||
sortKey = "x"; | ||
``` | ||
@@ -398,3 +394,3 @@ | ||
*default:* `sortOrder="ascending"` | ||
_default:_ `sortOrder="ascending"` | ||
@@ -407,3 +403,3 @@ ### standalone | ||
*default:* `standalone={true}` | ||
_default:_ `standalone={true}` | ||
@@ -428,5 +424,4 @@ ```playground | ||
*default:* `endAngle={0}` | ||
_default:_ `endAngle={0}` | ||
```playground | ||
@@ -453,3 +448,3 @@ <div> | ||
*default (provided by default theme):* See [grayscale theme][] for more detail | ||
_default (provided by default theme):_ See [grayscale theme][] for more detail | ||
@@ -478,3 +473,3 @@ ```playground | ||
*default:* `theme={VictoryTheme.grayscale}` | ||
_default:_ `theme={VictoryTheme.grayscale}` | ||
@@ -491,3 +486,3 @@ ```jsx | ||
*default (provided by default theme):* `width={400}` | ||
_default (provided by default theme):_ `width={400}` | ||
@@ -507,3 +502,3 @@ ```jsx | ||
```jsx | ||
x="employee.name" | ||
x = "employee.name"; | ||
``` | ||
@@ -523,8 +518,7 @@ | ||
[Animations Guide]: https://formidable.com/open-source/victory/guides/animations | ||
[Data Accessors Guide]: https://formidable.com/open-source/victory/guides/data-accessors | ||
[Custom Components Guide]: https://formidable.com/open-source/victory/guides/custom-components | ||
[Events Guide]: https://formidable.com/open-source/victory/guides/events | ||
[Themes Guide]: https://formidable.com/open-source/victory/guides/themes | ||
[animations guide]: https://formidable.com/open-source/victory/guides/animations | ||
[data accessors guide]: https://formidable.com/open-source/victory/guides/data-accessors | ||
[custom components guide]: https://formidable.com/open-source/victory/guides/custom-components | ||
[events guide]: https://formidable.com/open-source/victory/guides/events | ||
[themes guide]: https://formidable.com/open-source/victory/guides/themes | ||
[grayscale theme]: https://github.com/FormidableLabs/victory-core/blob/master/src/victory-theme/grayscale.js |
@@ -26,6 +26,8 @@ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2, 45, 135, 180, 225, 315] }]*/ | ||
} | ||
return Math.min( | ||
props.width - padding.left - padding.right, | ||
props.height - padding.top - padding.bottom | ||
) / 2; | ||
return ( | ||
Math.min( | ||
props.width - padding.left - padding.right, | ||
props.height - padding.top - padding.bottom | ||
) / 2 | ||
); | ||
}; | ||
@@ -43,3 +45,4 @@ | ||
const getSlices = (props, data) => { | ||
const layoutFunction = d3Shape.pie() | ||
const layoutFunction = d3Shape | ||
.pie() | ||
.sort(null) | ||
@@ -49,3 +52,5 @@ .startAngle(Helpers.degreesToRadians(props.startAngle)) | ||
.padAngle(Helpers.degreesToRadians(props.padAngle)) | ||
.value((datum) => { return datum._y; }); | ||
.value((datum) => { | ||
return datum._y; | ||
}); | ||
return layoutFunction(data); | ||
@@ -86,5 +91,6 @@ }; | ||
const getLabelArc = (radius, labelRadius, style) => { | ||
const padding = style && style.padding || 0; | ||
const padding = (style && style.padding) || 0; | ||
const arcRadius = labelRadius || radius + padding; | ||
return d3Shape.arc() | ||
return d3Shape | ||
.arc() | ||
.outerRadius(arcRadius) | ||
@@ -139,3 +145,5 @@ .innerRadius(arcRadius); | ||
const labelStyle = Helpers.evaluateStyle( | ||
assign({ padding: 0 }, style.labels), datum, props.active | ||
assign({ padding: 0 }, style.labels), | ||
datum, | ||
props.active | ||
); | ||
@@ -147,3 +155,7 @@ const labelRadius = Helpers.evaluateProp(props.labelRadius, datum); | ||
return { | ||
index, datum, data, slice, orientation, | ||
index, | ||
datum, | ||
data, | ||
slice, | ||
orientation, | ||
style: labelStyle, | ||
@@ -164,4 +176,12 @@ x: Math.round(position[0]) + origin.x, | ||
const { | ||
labels, events, sharedEvents, height, width, standalone, name, | ||
innerRadius, cornerRadius, padAngle | ||
labels, | ||
events, | ||
sharedEvents, | ||
height, | ||
width, | ||
standalone, | ||
name, | ||
innerRadius, | ||
cornerRadius, | ||
padAngle | ||
} = props; | ||
@@ -174,12 +194,18 @@ const radius = props.radius || defaultRadius; | ||
return slices.reduce((childProps, slice, index) => { | ||
const datum = defaults( | ||
{}, data[index], { | ||
startAngle: Helpers.radiansToDegrees(slice.startAngle), | ||
endAngle: Helpers.radiansToDegrees(slice.endAngle), | ||
padAngle: Helpers.radiansToDegrees(slice.padAngle) | ||
} | ||
); | ||
const datum = defaults({}, data[index], { | ||
startAngle: Helpers.radiansToDegrees(slice.startAngle), | ||
endAngle: Helpers.radiansToDegrees(slice.endAngle), | ||
padAngle: Helpers.radiansToDegrees(slice.padAngle) | ||
}); | ||
const eventKey = datum.eventKey || index; | ||
const dataProps = { | ||
index, slice, datum, data, origin, innerRadius, radius, cornerRadius, padAngle, | ||
index, | ||
slice, | ||
datum, | ||
data, | ||
origin, | ||
innerRadius, | ||
radius, | ||
cornerRadius, | ||
padAngle, | ||
style: getSliceStyle(index, calculatedValues) | ||
@@ -191,3 +217,3 @@ }; | ||
const text = getLabelText(props, datum, index); | ||
if (text !== undefined && text !== null || (labels && (events || sharedEvents))) { | ||
if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) { | ||
childProps[eventKey].labels = getLabelProps(props, dataProps, calculatedValues); | ||
@@ -194,0 +220,0 @@ } |
@@ -7,3 +7,2 @@ import React from "react"; | ||
export default class Slice extends React.Component { | ||
@@ -22,7 +21,6 @@ static propTypes = { | ||
sliceStartAngle: PropTypes.oneOfType([PropTypes.number, PropTypes.func]) | ||
}; | ||
static defaultProps = { | ||
pathComponent: <Path/> | ||
pathComponent: <Path /> | ||
}; | ||
@@ -38,5 +36,3 @@ | ||
const radius = Helpers.evaluateProp(props.radius, datum, active); | ||
const padAngle = Helpers.degreesToRadians( | ||
Helpers.evaluateProp(props.padAngle, datum, active) | ||
); | ||
const padAngle = Helpers.degreesToRadians(Helpers.evaluateProp(props.padAngle, datum, active)); | ||
const startAngle = Helpers.degreesToRadians( | ||
@@ -48,3 +44,4 @@ Helpers.evaluateProp(props.sliceStartAngle, datum, active) | ||
); | ||
const pathFunction = d3Shape.arc() | ||
const pathFunction = d3Shape | ||
.arc() | ||
.cornerRadius(cornerRadius) | ||
@@ -58,4 +55,12 @@ .outerRadius(radius) | ||
const { | ||
datum, active, role, shapeRendering, className, | ||
origin, events, pathComponent, style, clipPath | ||
datum, | ||
active, | ||
role, | ||
shapeRendering, | ||
className, | ||
origin, | ||
events, | ||
pathComponent, | ||
style, | ||
clipPath | ||
} = this.props; | ||
@@ -65,3 +70,8 @@ const defaultTransform = origin ? `translate(${origin.x}, ${origin.y})` : undefined; | ||
return React.cloneElement(pathComponent, { | ||
className, role, shapeRendering, events, transform, clipPath, | ||
className, | ||
role, | ||
shapeRendering, | ||
events, | ||
transform, | ||
clipPath, | ||
style: Helpers.evaluateStyle(style, datum, active), | ||
@@ -68,0 +78,0 @@ d: this.getPath(this.props) |
@@ -5,3 +5,8 @@ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/ | ||
import { | ||
addEvents, Helpers, Data, PropTypes as CustomPropTypes, VictoryContainer, VictoryLabel, | ||
addEvents, | ||
Helpers, | ||
Data, | ||
PropTypes as CustomPropTypes, | ||
VictoryContainer, | ||
VictoryLabel, | ||
VictoryTheme | ||
@@ -35,8 +40,17 @@ } from "victory-core"; | ||
const animationWhitelist = [ | ||
"data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", | ||
"colorScale", "startAngle", "style", "width" | ||
]; | ||
class VictoryPie extends React.Component { | ||
static animationWhitelist = [ | ||
"data", | ||
"endAngle", | ||
"height", | ||
"innerRadius", | ||
"cornerRadius", | ||
"padAngle", | ||
"padding", | ||
"colorScale", | ||
"startAngle", | ||
"style", | ||
"width" | ||
]; | ||
class VictoryPie extends React.Component { | ||
static displayName = "VictoryPie"; | ||
@@ -55,3 +69,4 @@ | ||
after: (datum) => ({ | ||
y_: datum._y, label: datum.label | ||
y_: datum._y, | ||
label: datum.label | ||
}) | ||
@@ -66,7 +81,14 @@ } | ||
PropTypes.oneOf([ | ||
"grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue" | ||
"grayscale", | ||
"qualitative", | ||
"heatmap", | ||
"warm", | ||
"cool", | ||
"red", | ||
"green", | ||
"blue" | ||
]) | ||
]), | ||
containerComponent: PropTypes.element, | ||
cornerRadius: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
cornerRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
data: PropTypes.array, | ||
@@ -80,35 +102,33 @@ dataComponent: PropTypes.element, | ||
]), | ||
events: PropTypes.arrayOf(PropTypes.shape({ | ||
target: PropTypes.oneOf(["data", "labels", "parent"]), | ||
eventKey: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), | ||
PropTypes.string | ||
]), | ||
eventHandlers: PropTypes.object | ||
})), | ||
externalEventMutations: PropTypes.arrayOf(PropTypes.shape({ | ||
callback: PropTypes.function, | ||
childName: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.array | ||
]), | ||
eventKey: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), | ||
PropTypes.string | ||
]), | ||
mutation: PropTypes.function, | ||
target: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.array | ||
]) | ||
})), | ||
events: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
target: PropTypes.oneOf(["data", "labels", "parent"]), | ||
eventKey: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), | ||
PropTypes.string | ||
]), | ||
eventHandlers: PropTypes.object | ||
}) | ||
), | ||
externalEventMutations: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
callback: PropTypes.function, | ||
childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), | ||
eventKey: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]), | ||
PropTypes.string | ||
]), | ||
mutation: PropTypes.function, | ||
target: PropTypes.oneOfType([PropTypes.string, PropTypes.array]) | ||
}) | ||
), | ||
groupComponent: PropTypes.element, | ||
height: CustomPropTypes.nonNegative, | ||
innerRadius: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
innerRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
labelComponent: PropTypes.element, | ||
labelPosition: PropTypes.oneOf(["startAngle", "centroid", "endAngle"]), | ||
labelRadius: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]), | ||
labelRadius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]), | ||
name: PropTypes.string, | ||
@@ -119,11 +139,13 @@ origin: PropTypes.shape({ | ||
}), | ||
padAngle: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
padAngle: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
padding: PropTypes.oneOfType([ | ||
PropTypes.number, | ||
PropTypes.shape({ | ||
top: PropTypes.number, bottom: PropTypes.number, | ||
left: PropTypes.number, right: PropTypes.number | ||
top: PropTypes.number, | ||
bottom: PropTypes.number, | ||
left: PropTypes.number, | ||
right: PropTypes.number | ||
}) | ||
]), | ||
radius: PropTypes.oneOfType([ CustomPropTypes.nonNegative, PropTypes.func ]), | ||
radius: PropTypes.oneOfType([CustomPropTypes.nonNegative, PropTypes.func]), | ||
sharedEvents: PropTypes.shape({ | ||
@@ -143,3 +165,5 @@ events: PropTypes.array, | ||
style: PropTypes.shape({ | ||
parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object | ||
parent: PropTypes.object, | ||
data: PropTypes.object, | ||
labels: PropTypes.object | ||
}), | ||
@@ -171,6 +195,6 @@ theme: PropTypes.object, | ||
standalone: true, | ||
dataComponent: <Slice/>, | ||
labelComponent: <VictoryLabel/>, | ||
containerComponent: <VictoryContainer/>, | ||
groupComponent: <g/>, | ||
dataComponent: <Slice />, | ||
labelComponent: <VictoryLabel />, | ||
containerComponent: <VictoryContainer />, | ||
groupComponent: <g />, | ||
sortOrder: "ascending", | ||
@@ -183,3 +207,6 @@ theme: VictoryTheme.grayscale | ||
static expectedComponents = [ | ||
"dataComponent", "labelComponent", "groupComponent", "containerComponent" | ||
"dataComponent", | ||
"labelComponent", | ||
"groupComponent", | ||
"containerComponent" | ||
]; | ||
@@ -193,4 +220,5 @@ | ||
render() { | ||
const { role } = this.constructor; | ||
const { animationWhitelist, role } = VictoryPie; | ||
const props = Helpers.modifyProps(this.props, fallbackProps, role); | ||
if (this.shouldAnimate()) { | ||
@@ -197,0 +225,0 @@ return this.animateComponent(props, animationWhitelist); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1352764
24568
502
Updatedvictory-core@^31.1.0