victory-pie 37.2.0 → 37.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/victory-pie.js +54 -33
- package/dist/victory-pie.min.js +1 -1
- package/es/helper-methods.js +25 -1
- package/es/victory-pie.d.ts +2 -4
- package/lib/helper-methods.js +25 -1
- package/lib/victory-pie.d.ts +2 -4
- package/package.json +3 -3
- package/src/helper-methods.ts +26 -1
- package/src/victory-pie.tsx +0 -3
package/es/helper-methods.js
CHANGED
|
@@ -39,6 +39,30 @@ const getSlices = (props, data) => {
|
|
|
39
39
|
});
|
|
40
40
|
return layoutFunction(data);
|
|
41
41
|
};
|
|
42
|
+
const getCategoriesFromProps = props => Array.isArray(props.categories) ? props.categories : props?.categories?.x ?? [];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sorts data by props.categories or props.categories.x. If all of the data keys aren't
|
|
46
|
+
* included in categories, any remaining data will be appended to the data array.
|
|
47
|
+
* If extraneous categories are included in the categories prop, the will be ignored and
|
|
48
|
+
* have no effect on the rendered component.
|
|
49
|
+
*/
|
|
50
|
+
const getDataSortedByCategories = (props, data) => {
|
|
51
|
+
const sorted = [];
|
|
52
|
+
getCategoriesFromProps(props).forEach(category => {
|
|
53
|
+
const idx = data.findIndex(_ref => {
|
|
54
|
+
let {
|
|
55
|
+
x
|
|
56
|
+
} = _ref;
|
|
57
|
+
return x === category;
|
|
58
|
+
});
|
|
59
|
+
if (idx >= 0) {
|
|
60
|
+
const datum = data.splice(idx, 1)[0];
|
|
61
|
+
sorted.push(datum);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return [...sorted, ...data];
|
|
65
|
+
};
|
|
42
66
|
const getCalculatedValues = props => {
|
|
43
67
|
const {
|
|
44
68
|
colorScale,
|
|
@@ -50,7 +74,7 @@ const getCalculatedValues = props => {
|
|
|
50
74
|
const padding = Helpers.getPadding(props);
|
|
51
75
|
const defaultRadius = getRadius(props, padding);
|
|
52
76
|
const origin = getOrigin(props, padding);
|
|
53
|
-
const data = Data.getData(props);
|
|
77
|
+
const data = getDataSortedByCategories(props, Data.getData(props));
|
|
54
78
|
const slices = getSlices(props, data);
|
|
55
79
|
return Object.assign({}, props, {
|
|
56
80
|
style,
|
package/es/victory-pie.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Data,
|
|
2
|
+
import { Data, EventPropTypeInterface, NumberOrCallback, SliceNumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass, VictoryDatableProps } from "victory-core";
|
|
3
3
|
import { SliceProps, VictorySliceTTargetType, VictorySliceLabelPlacementType, VictorySliceLabelPositionType } from "./slice";
|
|
4
|
-
export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, VictoryDatableProps,
|
|
5
|
-
colorScale?: ColorScalePropType;
|
|
4
|
+
export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, VictoryDatableProps, VictoryMultiLabelableProps {
|
|
6
5
|
cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
|
|
7
6
|
endAngle?: number;
|
|
8
7
|
events?: EventPropTypeInterface<VictorySliceTTargetType, StringOrNumberOrCallback | string[] | number[]>[];
|
|
@@ -15,7 +14,6 @@ export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, Vict
|
|
|
15
14
|
labelPosition?: VictorySliceLabelPositionType | ((props: SliceProps) => VictorySliceLabelPositionType);
|
|
16
15
|
labelIndicatorComponent?: React.ReactElement;
|
|
17
16
|
labelRadius?: number | ((props: SliceProps) => number);
|
|
18
|
-
origin?: OriginType;
|
|
19
17
|
padAngle?: NumberOrCallback;
|
|
20
18
|
radius?: NumberOrCallback;
|
|
21
19
|
startAngle?: number;
|
package/lib/helper-methods.js
CHANGED
|
@@ -49,6 +49,30 @@ const getSlices = (props, data) => {
|
|
|
49
49
|
});
|
|
50
50
|
return layoutFunction(data);
|
|
51
51
|
};
|
|
52
|
+
const getCategoriesFromProps = props => Array.isArray(props.categories) ? props.categories : props?.categories?.x ?? [];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Sorts data by props.categories or props.categories.x. If all of the data keys aren't
|
|
56
|
+
* included in categories, any remaining data will be appended to the data array.
|
|
57
|
+
* If extraneous categories are included in the categories prop, the will be ignored and
|
|
58
|
+
* have no effect on the rendered component.
|
|
59
|
+
*/
|
|
60
|
+
const getDataSortedByCategories = (props, data) => {
|
|
61
|
+
const sorted = [];
|
|
62
|
+
getCategoriesFromProps(props).forEach(category => {
|
|
63
|
+
const idx = data.findIndex(_ref => {
|
|
64
|
+
let {
|
|
65
|
+
x
|
|
66
|
+
} = _ref;
|
|
67
|
+
return x === category;
|
|
68
|
+
});
|
|
69
|
+
if (idx >= 0) {
|
|
70
|
+
const datum = data.splice(idx, 1)[0];
|
|
71
|
+
sorted.push(datum);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return [...sorted, ...data];
|
|
75
|
+
};
|
|
52
76
|
const getCalculatedValues = props => {
|
|
53
77
|
const {
|
|
54
78
|
colorScale,
|
|
@@ -60,7 +84,7 @@ const getCalculatedValues = props => {
|
|
|
60
84
|
const padding = _victoryCore.Helpers.getPadding(props);
|
|
61
85
|
const defaultRadius = getRadius(props, padding);
|
|
62
86
|
const origin = getOrigin(props, padding);
|
|
63
|
-
const data = _victoryCore.Data.getData(props);
|
|
87
|
+
const data = getDataSortedByCategories(props, _victoryCore.Data.getData(props));
|
|
64
88
|
const slices = getSlices(props, data);
|
|
65
89
|
return Object.assign({}, props, {
|
|
66
90
|
style,
|
package/lib/victory-pie.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Data,
|
|
2
|
+
import { Data, EventPropTypeInterface, NumberOrCallback, SliceNumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass, VictoryDatableProps } from "victory-core";
|
|
3
3
|
import { SliceProps, VictorySliceTTargetType, VictorySliceLabelPlacementType, VictorySliceLabelPositionType } from "./slice";
|
|
4
|
-
export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, VictoryDatableProps,
|
|
5
|
-
colorScale?: ColorScalePropType;
|
|
4
|
+
export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, VictoryDatableProps, VictoryMultiLabelableProps {
|
|
6
5
|
cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
|
|
7
6
|
endAngle?: number;
|
|
8
7
|
events?: EventPropTypeInterface<VictorySliceTTargetType, StringOrNumberOrCallback | string[] | number[]>[];
|
|
@@ -15,7 +14,6 @@ export interface VictoryPieProps extends Omit<VictoryCommonProps, "polar">, Vict
|
|
|
15
14
|
labelPosition?: VictorySliceLabelPositionType | ((props: SliceProps) => VictorySliceLabelPositionType);
|
|
16
15
|
labelIndicatorComponent?: React.ReactElement;
|
|
17
16
|
labelRadius?: number | ((props: SliceProps) => number);
|
|
18
|
-
origin?: OriginType;
|
|
19
17
|
padAngle?: NumberOrCallback;
|
|
20
18
|
radius?: NumberOrCallback;
|
|
21
19
|
startAngle?: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-pie",
|
|
3
|
-
"version": "37.
|
|
3
|
+
"version": "37.3.1",
|
|
4
4
|
"description": "Pie Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"lodash": "^4.17.19",
|
|
24
|
-
"victory-core": "37.
|
|
25
|
-
"victory-vendor": "37.
|
|
24
|
+
"victory-core": "37.3.1",
|
|
25
|
+
"victory-vendor": "37.3.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": ">=16.6.0"
|
package/src/helper-methods.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { defaults, isPlainObject } from "lodash";
|
|
|
3
3
|
import * as d3Shape from "victory-vendor/d3-shape";
|
|
4
4
|
|
|
5
5
|
import { Helpers, Data, Style } from "victory-core";
|
|
6
|
+
import { VictoryPieProps } from "./victory-pie";
|
|
7
|
+
import { getCategories } from "victory-core/lib/victory-util/data";
|
|
6
8
|
|
|
7
9
|
const checkForValidText = (text) => {
|
|
8
10
|
if (text === undefined || text === null || Helpers.isFunction(text)) {
|
|
@@ -59,6 +61,29 @@ const getSlices = (props, data) => {
|
|
|
59
61
|
return layoutFunction(data);
|
|
60
62
|
};
|
|
61
63
|
|
|
64
|
+
const getCategoriesFromProps = (props: VictoryPieProps) =>
|
|
65
|
+
Array.isArray(props.categories)
|
|
66
|
+
? props.categories
|
|
67
|
+
: (props?.categories as { x: string[] })?.x ?? [];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sorts data by props.categories or props.categories.x. If all of the data keys aren't
|
|
71
|
+
* included in categories, any remaining data will be appended to the data array.
|
|
72
|
+
* If extraneous categories are included in the categories prop, the will be ignored and
|
|
73
|
+
* have no effect on the rendered component.
|
|
74
|
+
*/
|
|
75
|
+
const getDataSortedByCategories = (props: VictoryPieProps, data) => {
|
|
76
|
+
const sorted: string[] = [];
|
|
77
|
+
getCategoriesFromProps(props).forEach((category) => {
|
|
78
|
+
const idx = data.findIndex(({ x }) => x === category);
|
|
79
|
+
if (idx >= 0) {
|
|
80
|
+
const datum = data.splice(idx, 1)[0];
|
|
81
|
+
sorted.push(datum);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return [...sorted, ...data];
|
|
85
|
+
};
|
|
86
|
+
|
|
62
87
|
const getCalculatedValues = (props) => {
|
|
63
88
|
const { colorScale, theme } = props;
|
|
64
89
|
const styleObject = Helpers.getDefaultStyles(props, "pie");
|
|
@@ -69,7 +94,7 @@ const getCalculatedValues = (props) => {
|
|
|
69
94
|
const padding = Helpers.getPadding(props);
|
|
70
95
|
const defaultRadius = getRadius(props, padding);
|
|
71
96
|
const origin = getOrigin(props, padding);
|
|
72
|
-
const data = Data.getData(props);
|
|
97
|
+
const data = getDataSortedByCategories(props, Data.getData(props));
|
|
73
98
|
const slices = getSlices(props, data);
|
|
74
99
|
return Object.assign({}, props, {
|
|
75
100
|
style,
|
package/src/victory-pie.tsx
CHANGED
|
@@ -33,9 +33,7 @@ import {
|
|
|
33
33
|
export interface VictoryPieProps
|
|
34
34
|
extends Omit<VictoryCommonProps, "polar">,
|
|
35
35
|
VictoryDatableProps,
|
|
36
|
-
VictoryLabelableProps,
|
|
37
36
|
VictoryMultiLabelableProps {
|
|
38
|
-
colorScale?: ColorScalePropType;
|
|
39
37
|
cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
|
|
40
38
|
endAngle?: number;
|
|
41
39
|
events?: EventPropTypeInterface<
|
|
@@ -56,7 +54,6 @@ export interface VictoryPieProps
|
|
|
56
54
|
|
|
57
55
|
labelIndicatorComponent?: React.ReactElement;
|
|
58
56
|
labelRadius?: number | ((props: SliceProps) => number);
|
|
59
|
-
origin?: OriginType;
|
|
60
57
|
padAngle?: NumberOrCallback;
|
|
61
58
|
radius?: NumberOrCallback;
|
|
62
59
|
startAngle?: number;
|