@gravity-ui/charts 1.32.0 → 1.32.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.
@@ -45,7 +45,8 @@ export async function prepareBarYData(args) {
45
45
  stacks.forEach((measureValues, groupItemIndex) => {
46
46
  const baseValue = xAxis.type === 'logarithmic' ? 0 : xLinearScale(0);
47
47
  const base = baseValue - measureValues[0].series.borderWidth;
48
- let stackSum = base;
48
+ let positiveStack = base;
49
+ let negativeStack = base;
49
50
  const stackItems = [];
50
51
  const sortedData = sortKey
51
52
  ? sort(measureValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
@@ -93,7 +94,8 @@ export async function prepareBarYData(args) {
93
94
  const isLastStackItem = xValueIndex === sortedData.length - 1;
94
95
  // Calculate position with border compensation
95
96
  // Border extends halfBorder outward from the shape, so we need to adjust position
96
- let itemX = (xValue > baseRangeValue ? stackSum : stackSum - width) + itemStackGap;
97
+ let itemX = xValue > baseRangeValue ? positiveStack : negativeStack - width;
98
+ itemX += itemStackGap;
97
99
  const halfBorder = borderWidth / 2;
98
100
  if (isFirstInStack && xValue > 0) {
99
101
  // Positive bar: border extends left, so shift position left by halfBorder
@@ -119,7 +121,12 @@ export async function prepareBarYData(args) {
119
121
  isLastStackItem,
120
122
  };
121
123
  stackItems.push(item);
122
- stackSum += width;
124
+ if (xValue > baseRangeValue) {
125
+ positiveStack += width;
126
+ }
127
+ else {
128
+ negativeStack -= width;
129
+ }
123
130
  });
124
131
  result.push(...stackItems);
125
132
  });
@@ -104,11 +104,9 @@ export function getDefaultMaxXAxisValue(series) {
104
104
  }
105
105
  export function getDefaultMinXAxisValue(series) {
106
106
  if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_X_AXIS.includes(s.type))) {
107
- return series.reduce((minValue, s) => {
108
- // https://github.com/gravity-ui/charts/issues/160
109
- // @ts-expect-error
110
- const minXValue = s.data.reduce((res, d) => Math.min(res, get(d, 'x', 0)), 0);
111
- return Math.min(minValue, minXValue);
107
+ const domainData = getDomainDataXBySeries(series);
108
+ return domainData.reduce((minValue, d) => {
109
+ return Math.min(minValue, d);
112
110
  }, 0);
113
111
  }
114
112
  return undefined;
@@ -45,7 +45,8 @@ export async function prepareBarYData(args) {
45
45
  stacks.forEach((measureValues, groupItemIndex) => {
46
46
  const baseValue = xAxis.type === 'logarithmic' ? 0 : xLinearScale(0);
47
47
  const base = baseValue - measureValues[0].series.borderWidth;
48
- let stackSum = base;
48
+ let positiveStack = base;
49
+ let negativeStack = base;
49
50
  const stackItems = [];
50
51
  const sortedData = sortKey
51
52
  ? sort(measureValues, (a, b) => comparator(get(a, sortKey), get(b, sortKey)))
@@ -93,7 +94,8 @@ export async function prepareBarYData(args) {
93
94
  const isLastStackItem = xValueIndex === sortedData.length - 1;
94
95
  // Calculate position with border compensation
95
96
  // Border extends halfBorder outward from the shape, so we need to adjust position
96
- let itemX = (xValue > baseRangeValue ? stackSum : stackSum - width) + itemStackGap;
97
+ let itemX = xValue > baseRangeValue ? positiveStack : negativeStack - width;
98
+ itemX += itemStackGap;
97
99
  const halfBorder = borderWidth / 2;
98
100
  if (isFirstInStack && xValue > 0) {
99
101
  // Positive bar: border extends left, so shift position left by halfBorder
@@ -119,7 +121,12 @@ export async function prepareBarYData(args) {
119
121
  isLastStackItem,
120
122
  };
121
123
  stackItems.push(item);
122
- stackSum += width;
124
+ if (xValue > baseRangeValue) {
125
+ positiveStack += width;
126
+ }
127
+ else {
128
+ negativeStack -= width;
129
+ }
123
130
  });
124
131
  result.push(...stackItems);
125
132
  });
@@ -104,11 +104,9 @@ export function getDefaultMaxXAxisValue(series) {
104
104
  }
105
105
  export function getDefaultMinXAxisValue(series) {
106
106
  if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_X_AXIS.includes(s.type))) {
107
- return series.reduce((minValue, s) => {
108
- // https://github.com/gravity-ui/charts/issues/160
109
- // @ts-expect-error
110
- const minXValue = s.data.reduce((res, d) => Math.min(res, get(d, 'x', 0)), 0);
111
- return Math.min(minValue, minXValue);
107
+ const domainData = getDomainDataXBySeries(series);
108
+ return domainData.reduce((minValue, d) => {
109
+ return Math.min(minValue, d);
112
110
  }, 0);
113
111
  }
114
112
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.32.0",
3
+ "version": "1.32.1",
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",