@gravity-ui/charts 1.10.2 → 1.11.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.
Files changed (91) hide show
  1. package/dist/cjs/components/Axis/AxisY.js +3 -0
  2. package/dist/cjs/components/ChartInner/index.js +8 -3
  3. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +2 -1
  4. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +1 -5
  5. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +2 -0
  6. package/dist/cjs/components/ChartInner/useChartInnerProps.js +11 -3
  7. package/dist/cjs/components/ChartInner/utils.d.ts +1 -1
  8. package/dist/cjs/components/ChartInner/utils.js +3 -3
  9. package/dist/cjs/components/Legend/index.js +4 -1
  10. package/dist/cjs/hooks/hooks-utils/zoom.d.ts +1 -1
  11. package/dist/cjs/hooks/hooks-utils/zoom.js +2 -2
  12. package/dist/cjs/hooks/useAxisScales/index.js +49 -18
  13. package/dist/cjs/hooks/useChartOptions/x-axis.js +3 -14
  14. package/dist/cjs/hooks/useChartOptions/y-axis.js +5 -24
  15. package/dist/cjs/hooks/useSeries/prepare-area.js +2 -1
  16. package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -2
  17. package/dist/cjs/hooks/useShapes/area/index.d.ts +1 -0
  18. package/dist/cjs/hooks/useShapes/area/index.js +13 -9
  19. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -0
  20. package/dist/cjs/hooks/useShapes/area/prepare-data.js +4 -3
  21. package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
  22. package/dist/cjs/hooks/useShapes/bar-x/index.d.ts +1 -0
  23. package/dist/cjs/hooks/useShapes/bar-x/index.js +2 -2
  24. package/dist/cjs/hooks/useShapes/bar-y/index.d.ts +1 -0
  25. package/dist/cjs/hooks/useShapes/bar-y/index.js +2 -2
  26. package/dist/cjs/hooks/useShapes/index.d.ts +2 -0
  27. package/dist/cjs/hooks/useShapes/index.js +146 -137
  28. package/dist/cjs/hooks/useShapes/line/index.d.ts +1 -0
  29. package/dist/cjs/hooks/useShapes/line/index.js +16 -12
  30. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -0
  31. package/dist/cjs/hooks/useShapes/line/prepare-data.js +2 -1
  32. package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
  33. package/dist/cjs/hooks/useShapes/marker.js +6 -0
  34. package/dist/cjs/hooks/useShapes/scatter/prepare-data.d.ts +1 -0
  35. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +6 -3
  36. package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
  37. package/dist/cjs/hooks/useShapes/waterfall/index.d.ts +1 -0
  38. package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
  39. package/dist/cjs/hooks/useZoom/index.js +1 -1
  40. package/dist/cjs/hooks/useZoom/utils.d.ts +1 -1
  41. package/dist/cjs/hooks/useZoom/utils.js +3 -3
  42. package/dist/cjs/types/chart/axis.d.ts +4 -5
  43. package/dist/cjs/utils/chart/axis-generators/bottom.js +3 -1
  44. package/dist/cjs/utils/chart/index.d.ts +2 -0
  45. package/dist/cjs/utils/chart/index.js +31 -0
  46. package/dist/esm/components/Axis/AxisY.js +3 -0
  47. package/dist/esm/components/ChartInner/index.js +8 -3
  48. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +2 -1
  49. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +1 -5
  50. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +2 -0
  51. package/dist/esm/components/ChartInner/useChartInnerProps.js +11 -3
  52. package/dist/esm/components/ChartInner/utils.d.ts +1 -1
  53. package/dist/esm/components/ChartInner/utils.js +3 -3
  54. package/dist/esm/components/Legend/index.js +4 -1
  55. package/dist/esm/hooks/hooks-utils/zoom.d.ts +1 -1
  56. package/dist/esm/hooks/hooks-utils/zoom.js +2 -2
  57. package/dist/esm/hooks/useAxisScales/index.js +49 -18
  58. package/dist/esm/hooks/useChartOptions/x-axis.js +3 -14
  59. package/dist/esm/hooks/useChartOptions/y-axis.js +5 -24
  60. package/dist/esm/hooks/useSeries/prepare-area.js +2 -1
  61. package/dist/esm/hooks/useSeries/prepare-legend.js +2 -2
  62. package/dist/esm/hooks/useShapes/area/index.d.ts +1 -0
  63. package/dist/esm/hooks/useShapes/area/index.js +13 -9
  64. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -0
  65. package/dist/esm/hooks/useShapes/area/prepare-data.js +4 -3
  66. package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
  67. package/dist/esm/hooks/useShapes/bar-x/index.d.ts +1 -0
  68. package/dist/esm/hooks/useShapes/bar-x/index.js +2 -2
  69. package/dist/esm/hooks/useShapes/bar-y/index.d.ts +1 -0
  70. package/dist/esm/hooks/useShapes/bar-y/index.js +2 -2
  71. package/dist/esm/hooks/useShapes/index.d.ts +2 -0
  72. package/dist/esm/hooks/useShapes/index.js +146 -137
  73. package/dist/esm/hooks/useShapes/line/index.d.ts +1 -0
  74. package/dist/esm/hooks/useShapes/line/index.js +16 -12
  75. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -0
  76. package/dist/esm/hooks/useShapes/line/prepare-data.js +2 -1
  77. package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
  78. package/dist/esm/hooks/useShapes/marker.js +6 -0
  79. package/dist/esm/hooks/useShapes/scatter/prepare-data.d.ts +1 -0
  80. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +6 -3
  81. package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
  82. package/dist/esm/hooks/useShapes/waterfall/index.d.ts +1 -0
  83. package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
  84. package/dist/esm/hooks/useZoom/index.js +1 -1
  85. package/dist/esm/hooks/useZoom/utils.d.ts +1 -1
  86. package/dist/esm/hooks/useZoom/utils.js +3 -3
  87. package/dist/esm/types/chart/axis.d.ts +4 -5
  88. package/dist/esm/utils/chart/axis-generators/bottom.js +3 -1
  89. package/dist/esm/utils/chart/index.d.ts +2 -0
  90. package/dist/esm/utils/chart/index.js +31 -0
  91. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  export function selectionToZoomBounds(args) {
2
- const { selection, xAxis, xScale, yAxises, yScales, zoomType } = args;
2
+ const { selection, xAxis, xScale, yAxes, yScales, zoomType } = args;
3
3
  const zoomState = {};
4
4
  switch (zoomType) {
5
5
  case 'x': {
@@ -9,7 +9,7 @@ export function selectionToZoomBounds(args) {
9
9
  }
10
10
  case 'y': {
11
11
  const [y1, y0] = selection;
12
- yAxises.forEach((yAxis, index) => {
12
+ yAxes.forEach((yAxis, index) => {
13
13
  if (!Array.isArray(zoomState.y)) {
14
14
  zoomState.y = [];
15
15
  }
@@ -25,7 +25,7 @@ export function selectionToZoomBounds(args) {
25
25
  const [x0, y0] = selection[0];
26
26
  const [x1, y1] = selection[1];
27
27
  zoomState.x = selectionXToZoomBounds({ xAxis, xScale, selection: [x0, x1] });
28
- yAxises.forEach((yAxis, index) => {
28
+ yAxes.forEach((yAxis, index) => {
29
29
  if (!Array.isArray(zoomState.y)) {
30
30
  zoomState.y = [];
31
31
  }
@@ -53,6 +53,8 @@ export interface ChartAxis {
53
53
  };
54
54
  /** The minimum value of the axis. If undefined the min value is automatically calculate. */
55
55
  min?: number;
56
+ /** The maximum value of the axis. If undefined the max value is automatically calculate. */
57
+ max?: number;
56
58
  /** The grid lines settings. */
57
59
  grid?: {
58
60
  /** Enable or disable the grid lines.
@@ -130,11 +132,8 @@ export interface AxisCrosshair extends Omit<AxisPlotLine, 'value'> {
130
132
  enabled?: boolean;
131
133
  }
132
134
  export interface ChartYAxis extends ChartAxis {
133
- /** Axis location.
134
- * Possible values - 'left' and 'right'.
135
- * */
135
+ /** Axis location. */
136
136
  position?: 'left' | 'right';
137
- /** Property for splitting charts. Determines which area the axis is located in.
138
- * */
137
+ /** Property for splitting charts. Determines which area the axis is located in. */
139
138
  plotIndex?: number;
140
139
  }
@@ -106,6 +106,7 @@ export async function axisBottom(args) {
106
106
  .remove();
107
107
  // add an ellipsis to the labels that go beyond the boundaries of the chart
108
108
  labels.each(function (_d, i, nodes) {
109
+ var _a;
109
110
  if (i === 0) {
110
111
  const currentElement = this;
111
112
  const text = select(currentElement);
@@ -113,7 +114,8 @@ export async function axisBottom(args) {
113
114
  const nextElement = nodes[i + 1];
114
115
  const nextElementPosition = nextElement === null || nextElement === void 0 ? void 0 : nextElement.getBoundingClientRect();
115
116
  if (currentElementPosition.left < leftmostLimit) {
116
- const remainSpace = nextElementPosition.left -
117
+ const rightmostPossiblePoint = (_a = nextElementPosition === null || nextElementPosition === void 0 ? void 0 : nextElementPosition.left) !== null && _a !== void 0 ? _a : right;
118
+ const remainSpace = rightmostPossiblePoint -
117
119
  currentElementPosition.right +
118
120
  x -
119
121
  labelsMargin;
@@ -44,6 +44,8 @@ export declare function isSeriesWithCategoryValues(series: UnknownSeries): serie
44
44
  };
45
45
  export declare const getDomainDataXBySeries: (series: UnknownSeries[]) => unknown[];
46
46
  export declare function getDefaultMaxXAxisValue(series: UnknownSeries[]): 0 | undefined;
47
+ export declare function getDefaultMinXAxisValue(series: UnknownSeries[]): number | undefined;
48
+ export declare function getDefaultMinYAxisValue(series?: UnknownSeries[]): number | undefined;
47
49
  export declare const getDomainDataYBySeries: (series: UnknownSeries[]) => unknown[];
48
50
  export declare const getSeriesNames: (series: ChartSeries[]) => string[];
49
51
  export declare const getOnlyVisibleSeries: <T extends {
@@ -6,6 +6,7 @@ import sortBy from 'lodash/sortBy';
6
6
  import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
7
7
  import { getSeriesStackId } from '../../hooks/useSeries/utils';
8
8
  import { formatNumber, getNumberUnitRate } from '../../libs/format-number';
9
+ import { getWaterfallPointSubtotal } from './series/waterfall';
9
10
  import { getDefaultDateFormat } from './time';
10
11
  export * from './math';
11
12
  export * from './text';
@@ -90,6 +91,36 @@ export function getDefaultMaxXAxisValue(series) {
90
91
  }
91
92
  return undefined;
92
93
  }
94
+ export function getDefaultMinXAxisValue(series) {
95
+ if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_X_AXIS.includes(s.type))) {
96
+ return series.reduce((minValue, s) => {
97
+ // https://github.com/gravity-ui/charts/issues/160
98
+ // @ts-expect-error
99
+ const minXValue = s.data.reduce((res, d) => Math.min(res, get(d, 'x', 0)), 0);
100
+ return Math.min(minValue, minXValue);
101
+ }, 0);
102
+ }
103
+ return undefined;
104
+ }
105
+ export function getDefaultMinYAxisValue(series) {
106
+ if (series === null || series === void 0 ? void 0 : series.some((s) => CHART_SERIES_WITH_VOLUME_ON_Y_AXIS.includes(s.type))) {
107
+ return series.reduce((minValue, s) => {
108
+ switch (s.type) {
109
+ case 'waterfall': {
110
+ const minSubTotal = s.data.reduce((res, d) => Math.min(res, getWaterfallPointSubtotal(d, s) || 0), 0);
111
+ return Math.min(minValue, minSubTotal);
112
+ }
113
+ default: {
114
+ // https://github.com/gravity-ui/charts/issues/160
115
+ // @ts-expect-error
116
+ const minYValue = s.data.reduce((res, d) => Math.min(res, get(d, 'y', 0)), 0);
117
+ return Math.min(minValue, minYValue);
118
+ }
119
+ }
120
+ }, 0);
121
+ }
122
+ return undefined;
123
+ }
93
124
  export const getDomainDataYBySeries = (series) => {
94
125
  const groupedSeries = group(series, (item) => item.type);
95
126
  return Array.from(groupedSeries).reduce((acc, [type, seriesList]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.10.2",
3
+ "version": "1.11.1",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",