victory-pie 37.3.0 → 37.3.2

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.
@@ -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,
@@ -1,8 +1,7 @@
1
1
  import React from "react";
2
- import { Data, ColorScalePropType, EventPropTypeInterface, NumberOrCallback, OriginType, SliceNumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryLabelableProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass, VictoryDatableProps } from "victory-core";
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, VictoryLabelableProps, VictoryMultiLabelableProps {
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;
@@ -100,7 +98,7 @@ export declare const VictoryPie: {
100
98
  UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextContext: any): void;
101
99
  componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
102
100
  UNSAFE_componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
103
- componentEvents: import("victory-core/lib/victory-util/events").ComponentEvent[];
101
+ componentEvents: import("@/victory-core/lib/victory-util/events").ComponentEvent[];
104
102
  getSharedEventState: (key: string, value: string) => unknown;
105
103
  baseProps: Record<string, object>;
106
104
  dataKeys: string[];
package/es/victory-pie.js CHANGED
@@ -20,7 +20,7 @@ const datumHasXandY = datum => {
20
20
  return !Helpers.isNil(datum._x) && !Helpers.isNil(datum._y);
21
21
  };
22
22
 
23
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
24
24
 
25
25
  class VictoryPieBase extends React.Component {
26
26
  static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"];
@@ -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,
@@ -1,8 +1,7 @@
1
1
  import React from "react";
2
- import { Data, ColorScalePropType, EventPropTypeInterface, NumberOrCallback, OriginType, SliceNumberOrCallback, StringOrNumberOrCallback, VictoryCommonProps, VictoryLabelableProps, VictoryMultiLabelableProps, VictoryStyleInterface, EventsMixinClass, VictoryDatableProps } from "victory-core";
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, VictoryLabelableProps, VictoryMultiLabelableProps {
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;
@@ -100,7 +98,7 @@ export declare const VictoryPie: {
100
98
  UNSAFE_componentWillReceiveProps?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextContext: any): void;
101
99
  componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
102
100
  UNSAFE_componentWillUpdate?(nextProps: Readonly<import("victory-core").EventMixinCommonProps>, nextState: Readonly<{}>, nextContext: any): void;
103
- componentEvents: import("victory-core/lib/victory-util/events").ComponentEvent[];
101
+ componentEvents: import("@/victory-core/lib/victory-util/events").ComponentEvent[];
104
102
  getSharedEventState: (key: string, value: string) => unknown;
105
103
  baseProps: Record<string, object>;
106
104
  dataKeys: string[];
@@ -27,7 +27,7 @@ const datumHasXandY = datum => {
27
27
  return !_victoryCore.Helpers.isNil(datum._x) && !_victoryCore.Helpers.isNil(datum._y);
28
28
  };
29
29
 
30
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
30
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
31
31
 
32
32
  class VictoryPieBase extends _react.default.Component {
33
33
  static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-pie",
3
- "version": "37.3.0",
3
+ "version": "37.3.2",
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.3.0",
25
- "victory-vendor": "37.3.0"
24
+ "victory-core": "37.3.2",
25
+ "victory-vendor": "37.3.2"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=16.6.0"
@@ -213,11 +213,9 @@
213
213
  ]
214
214
  },
215
215
  "lint": {
216
- "command": "nps lint:pkg",
216
+ "command": "eslint src",
217
217
  "files": [
218
- "src/**",
219
- "../../.eslintignore",
220
- "../../.eslintrc.js"
218
+ "src/**"
221
219
  ],
222
220
  "output": [],
223
221
  "dependencies": [
@@ -231,11 +229,9 @@
231
229
  ]
232
230
  },
233
231
  "lint:fix": {
234
- "command": "pnpm run lint || nps lint:pkg:fix",
232
+ "command": "eslint --fix src",
235
233
  "files": [
236
- "src/**",
237
- "../../.eslintignore",
238
- "../../.eslintrc.js"
234
+ "src/**"
239
235
  ],
240
236
  "output": [],
241
237
  "dependencies": [
@@ -3,6 +3,7 @@ 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";
6
7
 
7
8
  const checkForValidText = (text) => {
8
9
  if (text === undefined || text === null || Helpers.isFunction(text)) {
@@ -59,6 +60,29 @@ const getSlices = (props, data) => {
59
60
  return layoutFunction(data);
60
61
  };
61
62
 
63
+ const getCategoriesFromProps = (props: VictoryPieProps) =>
64
+ Array.isArray(props.categories)
65
+ ? props.categories
66
+ : ((props?.categories as { x: string[] })?.x ?? []);
67
+
68
+ /**
69
+ * Sorts data by props.categories or props.categories.x. If all of the data keys aren't
70
+ * included in categories, any remaining data will be appended to the data array.
71
+ * If extraneous categories are included in the categories prop, the will be ignored and
72
+ * have no effect on the rendered component.
73
+ */
74
+ const getDataSortedByCategories = (props: VictoryPieProps, data) => {
75
+ const sorted: string[] = [];
76
+ getCategoriesFromProps(props).forEach((category) => {
77
+ const idx = data.findIndex(({ x }) => x === category);
78
+ if (idx >= 0) {
79
+ const datum = data.splice(idx, 1)[0];
80
+ sorted.push(datum);
81
+ }
82
+ });
83
+ return [...sorted, ...data];
84
+ };
85
+
62
86
  const getCalculatedValues = (props) => {
63
87
  const { colorScale, theme } = props;
64
88
  const styleObject = Helpers.getDefaultStyles(props, "pie");
@@ -69,7 +93,7 @@ const getCalculatedValues = (props) => {
69
93
  const padding = Helpers.getPadding(props);
70
94
  const defaultRadius = getRadius(props, padding);
71
95
  const origin = getOrigin(props, padding);
72
- const data = Data.getData(props);
96
+ const data = getDataSortedByCategories(props, Data.getData(props));
73
97
  const slices = getSlices(props, data);
74
98
  return Object.assign({}, props, {
75
99
  style,
@@ -8,14 +8,11 @@ import {
8
8
  VictoryLabel,
9
9
  VictoryTheme,
10
10
  UserProps,
11
- ColorScalePropType,
12
11
  EventPropTypeInterface,
13
12
  NumberOrCallback,
14
- OriginType,
15
13
  SliceNumberOrCallback,
16
14
  StringOrNumberOrCallback,
17
15
  VictoryCommonProps,
18
- VictoryLabelableProps,
19
16
  VictoryMultiLabelableProps,
20
17
  VictoryStyleInterface,
21
18
  EventsMixinClass,
@@ -33,9 +30,7 @@ import {
33
30
  export interface VictoryPieProps
34
31
  extends Omit<VictoryCommonProps, "polar">,
35
32
  VictoryDatableProps,
36
- VictoryLabelableProps,
37
33
  VictoryMultiLabelableProps {
38
- colorScale?: ColorScalePropType;
39
34
  cornerRadius?: SliceNumberOrCallback<SliceProps, "cornerRadius">;
40
35
  endAngle?: number;
41
36
  events?: EventPropTypeInterface<
@@ -56,7 +51,6 @@ export interface VictoryPieProps
56
51
 
57
52
  labelIndicatorComponent?: React.ReactElement;
58
53
  labelRadius?: number | ((props: SliceProps) => number);
59
- origin?: OriginType;
60
54
  padAngle?: NumberOrCallback;
61
55
  radius?: NumberOrCallback;
62
56
  startAngle?: number;
@@ -92,7 +86,7 @@ const datumHasXandY = (datum) => {
92
86
  return !Helpers.isNil(datum._x) && !Helpers.isNil(datum._y);
93
87
  };
94
88
 
95
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
89
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
96
90
  interface VictoryPieBase extends EventsMixinClass<VictoryPieProps> {}
97
91
 
98
92
  class VictoryPieBase extends React.Component<VictoryPieProps> {