@gravity-ui/charts 1.34.10 → 1.35.0

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.
@@ -1,4 +1,4 @@
1
- import { ascending, descending, sort } from 'd3';
1
+ import { ascending, descending, reverse, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
4
  import { getFormattedValue } from '../../../utils/chart/format';
@@ -103,9 +103,13 @@ export const prepareBarXData = async (args) => {
103
103
  let positiveStackHeight = 0;
104
104
  let negativeStackHeight = 0;
105
105
  const stackItems = [];
106
- const sortedData = sortKey
107
- ? sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
108
- : yValues;
106
+ let sortedData = yValues;
107
+ if (sortKey) {
108
+ sortedData = sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)));
109
+ }
110
+ else if ((sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc') {
111
+ sortedData = reverse(yValues);
112
+ }
109
113
  for (let yValueIndex = 0; yValueIndex < sortedData.length; yValueIndex++) {
110
114
  const yValue = sortedData[yValueIndex];
111
115
  const yAxisIndex = yValue.series.yAxis;
@@ -119,7 +123,6 @@ export const prepareBarXData = async (args) => {
119
123
  if (xAxis.type === 'category') {
120
124
  const xBandScale = xScale;
121
125
  const xBandScaleDomain = xBandScale.domain();
122
- // eslint-disable-next-line max-depth
123
126
  if (xBandScaleDomain.indexOf(xValue) === -1) {
124
127
  continue;
125
128
  }
@@ -1,4 +1,4 @@
1
- import { ascending, descending, sort } from 'd3';
1
+ import { ascending, descending, reverse, sort } from 'd3';
2
2
  import get from 'lodash/get';
3
3
  import { getDataCategoryValue, getLabelsSize } from '../../../utils';
4
4
  import { getFormattedValue } from '../../../utils/chart/format';
@@ -103,9 +103,13 @@ export const prepareBarXData = async (args) => {
103
103
  let positiveStackHeight = 0;
104
104
  let negativeStackHeight = 0;
105
105
  const stackItems = [];
106
- const sortedData = sortKey
107
- ? sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
108
- : yValues;
106
+ let sortedData = yValues;
107
+ if (sortKey) {
108
+ sortedData = sort(yValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)));
109
+ }
110
+ else if ((sortingOptions === null || sortingOptions === void 0 ? void 0 : sortingOptions.direction) === 'desc') {
111
+ sortedData = reverse(yValues);
112
+ }
109
113
  for (let yValueIndex = 0; yValueIndex < sortedData.length; yValueIndex++) {
110
114
  const yValue = sortedData[yValueIndex];
111
115
  const yAxisIndex = yValue.series.yAxis;
@@ -119,7 +123,6 @@ export const prepareBarXData = async (args) => {
119
123
  if (xAxis.type === 'category') {
120
124
  const xBandScale = xScale;
121
125
  const xBandScaleDomain = xBandScale.domain();
122
- // eslint-disable-next-line max-depth
123
126
  if (xBandScaleDomain.indexOf(xValue) === -1) {
124
127
  continue;
125
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.34.10",
3
+ "version": "1.35.0",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",