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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # victory-pie
2
2
 
3
+ ## 37.3.2
4
+
5
+ ## 37.3.1
6
+
7
+ ### Patch Changes
8
+
9
+ - Added logic to sort pie chart slices by categories prop ([#2934](https://github.com/FormidableLabs/victory/pull/2934))
10
+
11
+ * Remove duplicate types from interfaces ([#2940](https://github.com/FormidableLabs/victory/pull/2940))
12
+
3
13
  ## 37.3.0
4
14
 
5
15
  ## 37.2.0
@@ -77,6 +77,30 @@ const getSlices = (props, data) => {
77
77
  });
78
78
  return layoutFunction(data);
79
79
  };
80
+ const getCategoriesFromProps = props => Array.isArray(props.categories) ? props.categories : props?.categories?.x ?? [];
81
+
82
+ /**
83
+ * Sorts data by props.categories or props.categories.x. If all of the data keys aren't
84
+ * included in categories, any remaining data will be appended to the data array.
85
+ * If extraneous categories are included in the categories prop, the will be ignored and
86
+ * have no effect on the rendered component.
87
+ */
88
+ const getDataSortedByCategories = (props, data) => {
89
+ const sorted = [];
90
+ getCategoriesFromProps(props).forEach(category => {
91
+ const idx = data.findIndex(_ref => {
92
+ let {
93
+ x
94
+ } = _ref;
95
+ return x === category;
96
+ });
97
+ if (idx >= 0) {
98
+ const datum = data.splice(idx, 1)[0];
99
+ sorted.push(datum);
100
+ }
101
+ });
102
+ return [...sorted, ...data];
103
+ };
80
104
  const getCalculatedValues = props => {
81
105
  const {
82
106
  colorScale,
@@ -88,7 +112,7 @@ const getCalculatedValues = props => {
88
112
  const padding = victory_core__WEBPACK_IMPORTED_MODULE_3__.getPadding(props);
89
113
  const defaultRadius = getRadius(props, padding);
90
114
  const origin = getOrigin(props, padding);
91
- const data = victory_core__WEBPACK_IMPORTED_MODULE_5__.getData(props);
115
+ const data = getDataSortedByCategories(props, victory_core__WEBPACK_IMPORTED_MODULE_5__.getData(props));
92
116
  const slices = getSlices(props, data);
93
117
  return Object.assign({}, props, {
94
118
  style,
@@ -519,7 +543,7 @@ const datumHasXandY = datum => {
519
543
  return !victory_core__WEBPACK_IMPORTED_MODULE_1__.isNil(datum._x) && !victory_core__WEBPACK_IMPORTED_MODULE_1__.isNil(datum._y);
520
544
  };
521
545
 
522
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
546
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
523
547
 
524
548
  class VictoryPieBase extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component) {
525
549
  static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"];
@@ -5024,7 +5048,7 @@ const interpolateFunction = function (a, b) {
5024
5048
  return b;
5025
5049
  }
5026
5050
  return function () {
5027
- /* eslint-disable no-invalid-this, prefer-rest-params */
5051
+ /* eslint-disable prefer-rest-params */
5028
5052
  const aval = typeof a === "function" ? a.apply(this, arguments) : a;
5029
5053
  const bval = typeof b === "function" ? b.apply(this, arguments) : b;
5030
5054
  return (0,victory_vendor_d3_interpolate__WEBPACK_IMPORTED_MODULE_2__.interpolate)(aval, bval)(t);
@@ -5416,9 +5440,9 @@ const VictoryContainer = initialProps => {
5416
5440
  ...style,
5417
5441
  width: responsive ? style?.width : dimensions.width,
5418
5442
  height: responsive ? style?.height : dimensions.height,
5419
- pointerEvents: "none",
5420
- touchAction: "none",
5421
- position: "relative"
5443
+ pointerEvents: style?.pointerEvents ?? "none",
5444
+ touchAction: style?.touchAction ?? "none",
5445
+ position: style?.position ?? "relative"
5422
5446
  },
5423
5447
  "data-ouia-component-id": ouiaId,
5424
5448
  "data-ouia-component-type": ouiaType,
@@ -7588,7 +7612,7 @@ class VictoryTransition extends (react__WEBPACK_IMPORTED_MODULE_2___default().Co
7588
7612
  componentDidMount() {
7589
7613
  this.setState({
7590
7614
  nodesShouldLoad: true
7591
- }); // eslint-disable-line react/no-did-mount-set-state
7615
+ });
7592
7616
  }
7593
7617
  shouldComponentUpdate(nextProps) {
7594
7618
  if (!react_fast_compare__WEBPACK_IMPORTED_MODULE_3___default()(this.props, nextProps)) {
@@ -7802,7 +7826,7 @@ const defaultComponents = [{
7802
7826
  function addEvents(WrappedComponent, options) {
7803
7827
  if (options === void 0) {
7804
7828
  options = {};
7805
- } // eslint-disable-next-line @typescript-eslint/no-empty-interface
7829
+ } // eslint-disable-next-line @typescript-eslint/no-empty-object-type
7806
7830
  // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
7807
7831
  class AddEventsMixin extends WrappedComponent {
7808
7832
  constructor(props) {
@@ -8171,7 +8195,6 @@ __webpack_require__.r(__webpack_exports__);
8171
8195
 
8172
8196
 
8173
8197
 
8174
- /* eslint-disable no-use-before-define */
8175
8198
 
8176
8199
 
8177
8200
 
@@ -8297,8 +8320,6 @@ function formatDataFromDomain(dataset, domain, defaultBaseline) {
8297
8320
  const isUnderMinY = underMin(minDomainY);
8298
8321
  const isOverMaxX = overMax(maxDomainX);
8299
8322
  const isOverMaxY = overMax(maxDomainY);
8300
-
8301
- // eslint-disable-next-line complexity
8302
8323
  return dataset.map(datum => {
8303
8324
  let {
8304
8325
  _x,
@@ -8409,7 +8430,6 @@ function formatData(dataset, props, expectedKeys) {
8409
8430
  };
8410
8431
  }
8411
8432
  const data = preformattedData ? dataset : dataset.reduce((dataArr, datum, index) => {
8412
- // eslint-disable-line complexity
8413
8433
  const parsedDatum = parseDatum(datum);
8414
8434
  const fallbackValues = {
8415
8435
  x: index,
@@ -8600,7 +8620,6 @@ __webpack_require__.r(__webpack_exports__);
8600
8620
 
8601
8621
 
8602
8622
 
8603
- /* eslint-disable no-use-before-define */
8604
8623
 
8605
8624
  const GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
8606
8625
 
@@ -8648,11 +8667,10 @@ getScopedEvents) {
8648
8667
  */
8649
8668
  const getAllEvents = () => {
8650
8669
  // Mandatory usage: `getEvents.bind(this)`
8651
- /* eslint-disable no-invalid-this */
8670
+
8652
8671
  if (Array.isArray(this.componentEvents)) {
8653
8672
  return Array.isArray(props.events) ? this.componentEvents.concat(...props.events) : this.componentEvents;
8654
8673
  }
8655
- /* eslint-enable no-invalid-this */
8656
8674
  return props.events;
8657
8675
  };
8658
8676
  const allEvents = getAllEvents();
@@ -8677,7 +8695,7 @@ function getScopedEvents(events, namespace, childType, baseProps) {
8677
8695
  }
8678
8696
 
8679
8697
  // Mandatory usage: `getScopedEvents.bind(this)`
8680
- // eslint-disable-next-line no-invalid-this
8698
+
8681
8699
  const newBaseProps = baseProps || this.baseProps;
8682
8700
  // returns the original base props or base state of a given target element
8683
8701
  const getTargetProps = (identifier, type) => {
@@ -8686,7 +8704,6 @@ function getScopedEvents(events, namespace, childType, baseProps) {
8686
8704
  target,
8687
8705
  key
8688
8706
  } = identifier;
8689
- // eslint-disable-next-line no-invalid-this
8690
8707
  const baseType = type === "props" ? newBaseProps : this.state || {};
8691
8708
  const base = childName === undefined || childName === null || !baseType[childName] ? baseType : baseType[childName];
8692
8709
  return key === "parent" ? base.parent : base[key] && base[key][target];
@@ -8713,7 +8730,6 @@ function getScopedEvents(events, namespace, childType, baseProps) {
8713
8730
 
8714
8731
  // returns the state object with mutated props applied for a single key
8715
8732
  const getMutationObject = (key, childName) => {
8716
- // eslint-disable-next-line no-invalid-this
8717
8733
  const baseState = this.state || {};
8718
8734
  if (!(0,_helpers__WEBPACK_IMPORTED_MODULE_4__.isFunction)(eventReturn.mutation)) {
8719
8735
  return baseState;
@@ -8786,11 +8802,9 @@ function getScopedEvents(events, namespace, childType, baseProps) {
8786
8802
  // into a state mutation, and calls setState
8787
8803
  // eslint-disable-next-line max-params
8788
8804
  const onEvent = (evt, childProps, eventKey, eventName) => {
8789
- // eslint-disable-next-line no-invalid-this
8790
8805
  const eventReturn = events[eventName](evt, childProps, eventKey, this);
8791
8806
  if (!lodash_isEmpty__WEBPACK_IMPORTED_MODULE_3___default()(eventReturn)) {
8792
8807
  const callbacks = compileCallbacks(eventReturn);
8793
- // eslint-disable-next-line no-invalid-this
8794
8808
  this.setState(parseEventReturn(eventReturn, eventKey), callbacks);
8795
8809
  }
8796
8810
  };
@@ -8820,7 +8834,7 @@ function getPartialEvents(events, eventKey, childProps) {
8820
8834
  // eslint-disable-next-line max-params
8821
8835
  function getEventState(eventKey, namespace, childType) {
8822
8836
  // Mandatory usage: `getEventState.bind(this)`
8823
- // eslint-disable-next-line no-invalid-this
8837
+
8824
8838
  const state = this.state || {};
8825
8839
  if (!childType) {
8826
8840
  return eventKey === "parent" ? state[eventKey] && state[eventKey][namespace] || state[eventKey] : state[eventKey] && state[eventKey][namespace];
@@ -9013,7 +9027,6 @@ __webpack_require__.r(__webpack_exports__);
9013
9027
 
9014
9028
 
9015
9029
 
9016
- /* eslint-disable no-use-before-define */
9017
9030
 
9018
9031
  // Private Functions
9019
9032
 
@@ -9482,7 +9495,6 @@ __webpack_require__.r(__webpack_exports__);
9482
9495
  /* harmony import */ var lodash_defaults__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_defaults__WEBPACK_IMPORTED_MODULE_0__);
9483
9496
  /* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers */ "../../victory-core/es/victory-util/helpers.js");
9484
9497
 
9485
- /* eslint-disable no-use-before-define */
9486
9498
 
9487
9499
  // Private Functions
9488
9500
 
@@ -9802,7 +9814,6 @@ __webpack_require__.r(__webpack_exports__);
9802
9814
  /* harmony import */ var _collection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./collection */ "../../victory-core/es/victory-util/collection.js");
9803
9815
  /* harmony import */ var victory_vendor_d3_scale__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! victory-vendor/d3-scale */ "../../victory-vendor/es/d3-scale.js");
9804
9816
 
9805
- /* eslint-disable no-use-before-define */
9806
9817
 
9807
9818
 
9808
9819
 
@@ -10593,8 +10604,6 @@ function getChildBeforeLoad(animate, child, data, cb) {
10593
10604
  clipWidth: 0
10594
10605
  };
10595
10606
  }
10596
-
10597
- // eslint-disable-next-line max-params
10598
10607
  function getChildOnLoad(animate, data, cb) {
10599
10608
  const newAnimate = Object.assign({}, animate, {
10600
10609
  onEnd: cb
@@ -10617,7 +10626,7 @@ function getChildOnLoad(animate, data, cb) {
10617
10626
  };
10618
10627
  }
10619
10628
 
10620
- // eslint-disable-next-line max-params, max-len
10629
+ // eslint-disable-next-line max-params
10621
10630
  function getChildPropsOnExit(animate, child, data, exitingNodes, cb) {
10622
10631
  // Whether or not _this_ child has exiting nodes, we want the exit-
10623
10632
  // transition for all children to have the same duration, delay, etc.
@@ -10641,7 +10650,7 @@ function getChildPropsOnExit(animate, child, data, exitingNodes, cb) {
10641
10650
  };
10642
10651
  }
10643
10652
 
10644
- // eslint-disable-next-line max-params,max-len
10653
+ // eslint-disable-next-line max-params
10645
10654
  function getChildPropsBeforeEnter(animate, child, data, enteringNodes, cb) {
10646
10655
  let newAnimate = animate;
10647
10656
  let newData = data;
@@ -10666,7 +10675,7 @@ function getChildPropsBeforeEnter(animate, child, data, enteringNodes, cb) {
10666
10675
  };
10667
10676
  }
10668
10677
 
10669
- // eslint-disable-next-line max-params, max-len
10678
+ // eslint-disable-next-line max-params
10670
10679
  function getChildPropsOnEnter(animate, data, enteringNodes, cb) {
10671
10680
  // Whether or not _this_ child has entering nodes, we want the entering-
10672
10681
  // transition for all children to have the same duration, delay, etc.
@@ -10773,8 +10782,6 @@ function getTransitionPropsFactory(props, state, setState) {
10773
10782
  }
10774
10783
  return {};
10775
10784
  };
10776
-
10777
- // eslint-disable-next-line max-statements, complexity, max-len
10778
10785
  return function getTransitionProps(child, index) {
10779
10786
  const data = getChildData(child) || [];
10780
10787
  const animate = lodash_defaults__WEBPACK_IMPORTED_MODULE_1___default()({}, props.animate, child.props.animate);