@gravity-ui/charts 1.38.6 → 1.39.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.
Files changed (169) hide show
  1. package/dist/cjs/components/AxisX/prepare-axis-data.d.ts +1 -1
  2. package/dist/cjs/components/AxisX/prepare-axis-data.js +10 -10
  3. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +1 -1
  4. package/dist/cjs/components/AxisY/prepare-axis-data.js +2 -2
  5. package/dist/cjs/components/ChartInner/index.js +25 -8
  6. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
  7. package/dist/cjs/components/ChartInner/useChartInnerHandlers.js +5 -1
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +19 -20
  9. package/dist/cjs/components/ChartInner/useChartInnerProps.js +230 -139
  10. package/dist/cjs/components/ChartInner/useChartInnerState.js +2 -1
  11. package/dist/cjs/components/ChartInner/useDefaultState.d.ts +26 -0
  12. package/dist/cjs/components/ChartInner/useDefaultState.js +74 -0
  13. package/dist/cjs/components/ChartInner/utils/axis.d.ts +44 -0
  14. package/dist/cjs/components/ChartInner/utils/axis.js +35 -0
  15. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
  16. package/dist/{esm/components/ChartInner/utils.d.ts → cjs/components/ChartInner/utils/common.d.ts} +2 -1
  17. package/dist/cjs/components/ChartInner/utils/index.d.ts +7 -0
  18. package/dist/cjs/components/ChartInner/utils/index.js +7 -0
  19. package/dist/cjs/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
  20. package/dist/cjs/components/ChartInner/utils/normalized-original-data.js +21 -0
  21. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
  22. package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/title.js +1 -1
  23. package/dist/cjs/components/ChartInner/utils/tooltip.d.ts +8 -0
  24. package/dist/cjs/components/ChartInner/utils/tooltip.js +7 -0
  25. package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
  26. package/dist/{esm/hooks/useChartOptions → cjs/components/ChartInner/utils}/zoom.js +1 -1
  27. package/dist/cjs/components/Legend/index.d.ts +1 -1
  28. package/dist/cjs/components/Legend/index.js +1 -1
  29. package/dist/cjs/hooks/index.d.ts +1 -4
  30. package/dist/cjs/hooks/index.js +1 -4
  31. package/dist/cjs/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
  32. package/dist/cjs/hooks/useAxis/index.d.ts +41 -6
  33. package/dist/cjs/hooks/useAxis/index.js +55 -40
  34. package/dist/cjs/hooks/useAxis/types.d.ts +0 -2
  35. package/dist/cjs/hooks/useAxis/y-axis.js +1 -3
  36. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -0
  37. package/dist/cjs/hooks/useAxisScales/index.js +1 -1
  38. package/dist/cjs/hooks/useAxisScales/x-scale.js +0 -1
  39. package/dist/cjs/hooks/useAxisScales/y-scale.js +0 -1
  40. package/dist/cjs/hooks/useCrosshair/index.d.ts +1 -1
  41. package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
  42. package/dist/cjs/hooks/useRangeSlider/utils.d.ts +1 -1
  43. package/dist/cjs/hooks/useSeries/index.d.ts +10 -14
  44. package/dist/cjs/hooks/useSeries/index.js +8 -80
  45. package/dist/cjs/hooks/useSeries/prepare-area.d.ts +2 -2
  46. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
  47. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +2 -2
  48. package/dist/cjs/hooks/useSeries/prepare-radar.d.ts +1 -1
  49. package/dist/cjs/hooks/useShapes/index.d.ts +4 -0
  50. package/dist/cjs/hooks/useShapes/index.js +209 -189
  51. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +0 -1
  52. package/dist/cjs/hooks/useSplit/index.d.ts +5 -2
  53. package/dist/cjs/hooks/useSplit/index.js +27 -30
  54. package/dist/cjs/hooks/useTooltip/index.d.ts +1 -1
  55. package/dist/cjs/hooks/useZoom/index.d.ts +2 -2
  56. package/dist/cjs/hooks/useZoom/index.js +2 -2
  57. package/dist/cjs/index.d.ts +1 -1
  58. package/dist/cjs/index.js +1 -1
  59. package/dist/cjs/types/index.d.ts +24 -11
  60. package/dist/cjs/utils/chart/axis/common.d.ts +2 -2
  61. package/dist/cjs/utils/chart/axis/common.js +1 -1
  62. package/dist/cjs/utils/chart/chart-dimensions.d.ts +24 -0
  63. package/dist/cjs/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
  64. package/dist/cjs/utils/chart/common.d.ts +28 -0
  65. package/dist/cjs/utils/chart/common.js +192 -0
  66. package/dist/cjs/utils/chart/get-closest-data.js +0 -1
  67. package/dist/cjs/utils/chart/index.d.ts +2 -28
  68. package/dist/cjs/utils/chart/index.js +2 -192
  69. package/dist/cjs/utils/chart/tooltip.d.ts +6 -0
  70. package/dist/cjs/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
  71. package/dist/cjs/utils/chart/zoom.js +0 -2
  72. package/dist/esm/components/AxisX/prepare-axis-data.d.ts +1 -1
  73. package/dist/esm/components/AxisX/prepare-axis-data.js +10 -10
  74. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +1 -1
  75. package/dist/esm/components/AxisY/prepare-axis-data.js +2 -2
  76. package/dist/esm/components/ChartInner/index.js +25 -8
  77. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -2
  78. package/dist/esm/components/ChartInner/useChartInnerHandlers.js +5 -1
  79. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +19 -20
  80. package/dist/esm/components/ChartInner/useChartInnerProps.js +230 -139
  81. package/dist/esm/components/ChartInner/useChartInnerState.js +2 -1
  82. package/dist/esm/components/ChartInner/useDefaultState.d.ts +26 -0
  83. package/dist/esm/components/ChartInner/useDefaultState.js +74 -0
  84. package/dist/esm/components/ChartInner/utils/axis.d.ts +44 -0
  85. package/dist/esm/components/ChartInner/utils/axis.js +35 -0
  86. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.d.ts +2 -2
  87. package/dist/{cjs/components/ChartInner/utils.d.ts → esm/components/ChartInner/utils/common.d.ts} +2 -1
  88. package/dist/esm/components/ChartInner/utils/index.d.ts +7 -0
  89. package/dist/esm/components/ChartInner/utils/index.js +7 -0
  90. package/dist/esm/components/ChartInner/utils/normalized-original-data.d.ts +33 -0
  91. package/dist/esm/components/ChartInner/utils/normalized-original-data.js +21 -0
  92. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/title.d.ts +2 -2
  93. package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/title.js +1 -1
  94. package/dist/esm/components/ChartInner/utils/tooltip.d.ts +8 -0
  95. package/dist/esm/components/ChartInner/utils/tooltip.js +7 -0
  96. package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/zoom.d.ts +3 -3
  97. package/dist/{cjs/hooks/useChartOptions → esm/components/ChartInner/utils}/zoom.js +1 -1
  98. package/dist/esm/components/Legend/index.d.ts +1 -1
  99. package/dist/esm/components/Legend/index.js +1 -1
  100. package/dist/esm/hooks/index.d.ts +1 -4
  101. package/dist/esm/hooks/index.js +1 -4
  102. package/dist/esm/hooks/{useChartOptions/types.d.ts → types.d.ts} +1 -1
  103. package/dist/esm/hooks/useAxis/index.d.ts +41 -6
  104. package/dist/esm/hooks/useAxis/index.js +55 -40
  105. package/dist/esm/hooks/useAxis/types.d.ts +0 -2
  106. package/dist/esm/hooks/useAxis/y-axis.js +1 -3
  107. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -0
  108. package/dist/esm/hooks/useAxisScales/index.js +1 -1
  109. package/dist/esm/hooks/useAxisScales/x-scale.js +0 -1
  110. package/dist/esm/hooks/useAxisScales/y-scale.js +0 -1
  111. package/dist/esm/hooks/useCrosshair/index.d.ts +1 -1
  112. package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
  113. package/dist/esm/hooks/useRangeSlider/utils.d.ts +1 -1
  114. package/dist/esm/hooks/useSeries/index.d.ts +10 -14
  115. package/dist/esm/hooks/useSeries/index.js +8 -80
  116. package/dist/esm/hooks/useSeries/prepare-area.d.ts +2 -2
  117. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
  118. package/dist/esm/hooks/useSeries/prepare-line.d.ts +2 -2
  119. package/dist/esm/hooks/useSeries/prepare-radar.d.ts +1 -1
  120. package/dist/esm/hooks/useShapes/index.d.ts +4 -0
  121. package/dist/esm/hooks/useShapes/index.js +209 -189
  122. package/dist/esm/hooks/useShapes/pie/prepare-data.js +0 -1
  123. package/dist/esm/hooks/useSplit/index.d.ts +5 -2
  124. package/dist/esm/hooks/useSplit/index.js +27 -30
  125. package/dist/esm/hooks/useTooltip/index.d.ts +1 -1
  126. package/dist/esm/hooks/useZoom/index.d.ts +2 -2
  127. package/dist/esm/hooks/useZoom/index.js +2 -2
  128. package/dist/esm/index.d.ts +1 -1
  129. package/dist/esm/index.js +1 -1
  130. package/dist/esm/types/index.d.ts +24 -11
  131. package/dist/esm/utils/chart/axis/common.d.ts +2 -2
  132. package/dist/esm/utils/chart/axis/common.js +1 -1
  133. package/dist/esm/utils/chart/chart-dimensions.d.ts +24 -0
  134. package/dist/esm/{hooks/useChartDimensions/index.js → utils/chart/chart-dimensions.js} +56 -33
  135. package/dist/esm/utils/chart/common.d.ts +28 -0
  136. package/dist/esm/utils/chart/common.js +192 -0
  137. package/dist/esm/utils/chart/get-closest-data.js +0 -1
  138. package/dist/esm/utils/chart/index.d.ts +2 -28
  139. package/dist/esm/utils/chart/index.js +2 -192
  140. package/dist/esm/utils/chart/tooltip.d.ts +6 -0
  141. package/dist/esm/{hooks/useChartOptions → utils/chart}/tooltip.js +2 -7
  142. package/dist/esm/utils/chart/zoom.js +0 -2
  143. package/package.json +3 -1
  144. package/dist/cjs/components/ChartInner/useLegend.d.ts +0 -14
  145. package/dist/cjs/components/ChartInner/useLegend.js +0 -34
  146. package/dist/cjs/hooks/useChartDimensions/index.d.ts +0 -17
  147. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +0 -10
  148. package/dist/cjs/hooks/useChartDimensions/utils.js +0 -41
  149. package/dist/cjs/hooks/useChartOptions/tooltip.d.ts +0 -13
  150. package/dist/cjs/hooks/useNormalizedOriginalData/index.d.ts +0 -38
  151. package/dist/cjs/hooks/useNormalizedOriginalData/index.js +0 -32
  152. package/dist/cjs/hooks/useYAxisLabelWidth/index.d.ts +0 -11
  153. package/dist/cjs/hooks/useYAxisLabelWidth/index.js +0 -48
  154. package/dist/esm/components/ChartInner/useLegend.d.ts +0 -14
  155. package/dist/esm/components/ChartInner/useLegend.js +0 -34
  156. package/dist/esm/hooks/useChartDimensions/index.d.ts +0 -17
  157. package/dist/esm/hooks/useChartDimensions/utils.d.ts +0 -10
  158. package/dist/esm/hooks/useChartDimensions/utils.js +0 -41
  159. package/dist/esm/hooks/useChartOptions/tooltip.d.ts +0 -13
  160. package/dist/esm/hooks/useNormalizedOriginalData/index.d.ts +0 -38
  161. package/dist/esm/hooks/useNormalizedOriginalData/index.js +0 -32
  162. package/dist/esm/hooks/useYAxisLabelWidth/index.d.ts +0 -11
  163. package/dist/esm/hooks/useYAxisLabelWidth/index.js +0 -48
  164. /package/dist/cjs/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
  165. /package/dist/cjs/components/ChartInner/{utils.js → utils/common.js} +0 -0
  166. /package/dist/cjs/hooks/{useChartOptions/types.js → types.js} +0 -0
  167. /package/dist/esm/{hooks/useChartOptions → components/ChartInner/utils}/chart.js +0 -0
  168. /package/dist/esm/components/ChartInner/{utils.js → utils/common.js} +0 -0
  169. /package/dist/esm/hooks/{useChartOptions/types.js → types.js} +0 -0
@@ -0,0 +1,33 @@
1
+ import type { ChartData } from '../../../types';
2
+ export declare function getNormalizedXAxis(props: {
3
+ xAxis: ChartData['xAxis'];
4
+ }): {
5
+ categories: string[] | undefined;
6
+ rangeSlider?: import("../../../types").ChartAxisRangeSlider;
7
+ crosshair?: import("../../../types").AxisCrosshair;
8
+ timestamps?: number[];
9
+ type?: import("../../../types").ChartAxisType;
10
+ labels?: import("../../../types").ChartAxisLabels;
11
+ lineColor?: string;
12
+ title?: import("../../../types").ChartAxisTitle;
13
+ min?: number;
14
+ max?: number;
15
+ grid?: {
16
+ enabled?: boolean;
17
+ };
18
+ ticks?: {
19
+ pixelInterval?: number;
20
+ interval?: number | string;
21
+ };
22
+ maxPadding?: number;
23
+ plotLines?: import("../../../types").AxisPlotLine[];
24
+ plotBands?: import("../../../types").AxisPlotBand[];
25
+ tickMarks?: import("../../../types").ChartAxisTickMarks;
26
+ visible?: boolean;
27
+ order?: "sortAsc" | "sortDesc" | "reverse";
28
+ startOnTick?: boolean;
29
+ endOnTick?: boolean;
30
+ };
31
+ export declare function getNormalizedYAxis(props: {
32
+ yAxis: ChartData['yAxis'];
33
+ }): import("../../../types").ChartYAxis[] | undefined;
@@ -0,0 +1,21 @@
1
+ import { getAxisCategories } from '../../../utils';
2
+ export function getNormalizedXAxis(props) {
3
+ var _a;
4
+ let categories = (_a = props.xAxis) === null || _a === void 0 ? void 0 : _a.categories;
5
+ if (props.xAxis && props.xAxis.categories) {
6
+ categories = getAxisCategories(props.xAxis);
7
+ }
8
+ return Object.assign(Object.assign({}, props.xAxis), { categories });
9
+ }
10
+ export function getNormalizedYAxis(props) {
11
+ if (Array.isArray(props.yAxis) && props.yAxis.some((axis) => axis.categories)) {
12
+ return props.yAxis.map((axis) => {
13
+ let categories = axis.categories;
14
+ if (axis.categories) {
15
+ categories = getAxisCategories(axis);
16
+ }
17
+ return Object.assign(Object.assign({}, axis), { categories });
18
+ });
19
+ }
20
+ return props.yAxis;
21
+ }
@@ -1,5 +1,5 @@
1
- import type { ChartData } from '../../types';
2
- import type { PreparedTitle } from './types';
1
+ import type { PreparedTitle } from '../../../hooks/types';
2
+ import type { ChartData } from '../../../types';
3
3
  export declare const getPreparedTitle: ({ title, }: {
4
4
  title: ChartData["title"];
5
5
  }) => PreparedTitle | undefined;
@@ -1,5 +1,5 @@
1
1
  import get from 'lodash/get';
2
- import { getHorizontalSvgTextHeight } from '../../utils';
2
+ import { getHorizontalSvgTextHeight } from '../../../utils';
3
3
  const DEFAULT_TITLE_FONT_SIZE = '15px';
4
4
  const TITLE_PADDINGS = 8 * 2;
5
5
  export const getPreparedTitle = ({ title, }) => {
@@ -0,0 +1,8 @@
1
+ import type { PreparedTooltip } from '../../../hooks/types';
2
+ import type { ChartData, ChartSeries, ChartXAxis, ChartYAxis } from '../../../types';
3
+ export declare const getPreparedTooltip: (args: {
4
+ tooltip: ChartData["tooltip"];
5
+ seriesData: ChartSeries[];
6
+ yAxes?: ChartYAxis[];
7
+ xAxis?: ChartXAxis;
8
+ }) => PreparedTooltip;
@@ -0,0 +1,7 @@
1
+ import get from 'lodash/get';
2
+ import { getDefaultTooltipHeaderFormat } from '../../../utils/chart/tooltip';
3
+ export const getPreparedTooltip = (args) => {
4
+ var _a, _b;
5
+ const { tooltip, seriesData, yAxes, xAxis } = args;
6
+ return Object.assign(Object.assign({}, tooltip), { enabled: get(tooltip, 'enabled', true), throttle: (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.throttle) !== null && _a !== void 0 ? _a : 0, headerFormat: (_b = tooltip === null || tooltip === void 0 ? void 0 : tooltip.headerFormat) !== null && _b !== void 0 ? _b : getDefaultTooltipHeaderFormat({ seriesData, yAxes, xAxis }) });
7
+ };
@@ -1,6 +1,6 @@
1
- import type { ZoomType } from '../../constants';
2
- import type { ChartSeries, ChartZoom } from '../../types';
3
- import type { PreparedZoom } from './types';
1
+ import type { ZoomType } from '../../../constants';
2
+ import type { PreparedZoom } from '../../../hooks/types';
3
+ import type { ChartSeries, ChartZoom } from '../../../types';
4
4
  export declare function getZoomType(args: {
5
5
  seriesData: ChartSeries[];
6
6
  zoomType?: ZoomType;
@@ -1,6 +1,6 @@
1
1
  import intersection from 'lodash/intersection';
2
2
  import merge from 'lodash/merge';
3
- import { SERIES_TYPE, ZOOM_TYPE, brushDefaults } from '../../constants';
3
+ import { SERIES_TYPE, ZOOM_TYPE, brushDefaults } from '../../../constants';
4
4
  function mapSeriesTypeToZoomType(seriesType) {
5
5
  switch (seriesType) {
6
6
  case SERIES_TYPE.Area: {
@@ -5,7 +5,7 @@ import './styles.css';
5
5
  type Props = {
6
6
  chartSeries: PreparedSeries[];
7
7
  legend: PreparedLegend;
8
- items: LegendItem[][];
8
+ items: LegendItem[][] | undefined;
9
9
  config: LegendConfig;
10
10
  htmlLayout: HTMLElement | null;
11
11
  onItemClick: OnLegendItemClick;
@@ -130,7 +130,7 @@ function renderLegendSymbol(args) {
130
130
  });
131
131
  }
132
132
  export const Legend = (props) => {
133
- const { chartSeries, legend, items, config, htmlLayout, onItemClick, onUpdate } = props;
133
+ const { chartSeries, legend, items = [], config, htmlLayout, onItemClick, onUpdate } = props;
134
134
  const ref = React.useRef(null);
135
135
  const [pageIndex, setPageIndex] = React.useState(0);
136
136
  React.useEffect(() => {
@@ -4,10 +4,7 @@ export * from './useAxisScales';
4
4
  export * from './useAxisScales/types';
5
5
  export * from './useBrush';
6
6
  export * from './useBrush/types';
7
- export * from './useChartDimensions';
8
- export * from './useChartOptions/types';
9
7
  export * from './useCrosshair';
10
- export * from './useNormalizedOriginalData';
11
8
  export * from './usePrevious';
12
9
  export * from './useRangeSlider';
13
10
  export * from './useRangeSlider/types';
@@ -17,6 +14,6 @@ export * from './useShapes';
17
14
  export * from './useSplit';
18
15
  export * from './useSplit/types';
19
16
  export * from './useTooltip';
20
- export * from './useYAxisLabelWidth';
21
17
  export * from './useZoom';
22
18
  export * from './useZoom/types';
19
+ export * from './types';
@@ -4,10 +4,7 @@ export * from './useAxisScales';
4
4
  export * from './useAxisScales/types';
5
5
  export * from './useBrush';
6
6
  export * from './useBrush/types';
7
- export * from './useChartDimensions';
8
- export * from './useChartOptions/types';
9
7
  export * from './useCrosshair';
10
- export * from './useNormalizedOriginalData';
11
8
  export * from './usePrevious';
12
9
  export * from './useRangeSlider';
13
10
  export * from './useRangeSlider/types';
@@ -17,6 +14,6 @@ export * from './useShapes';
17
14
  export * from './useSplit';
18
15
  export * from './useSplit/types';
19
16
  export * from './useTooltip';
20
- export * from './useYAxisLabelWidth';
21
17
  export * from './useZoom';
22
18
  export * from './useZoom/types';
19
+ export * from './types';
@@ -1,4 +1,4 @@
1
- import type { ChartBrush, ChartData, ChartMargin, ChartZoom, DeepRequired } from '../../types';
1
+ import type { ChartBrush, ChartData, ChartMargin, ChartZoom, DeepRequired } from '../types';
2
2
  export type PreparedZoom = DeepRequired<Omit<ChartZoom, 'enabled' | 'brush'>> & DeepRequired<{
3
3
  brush: ChartBrush;
4
4
  }>;
@@ -1,6 +1,5 @@
1
- import React from 'react';
2
1
  import type { ChartXAxis, ChartYAxis, LegendConfig } from '../../types';
3
- import type { PreparedChart } from '../useChartOptions/types';
2
+ import type { PreparedChart } from '../types';
4
3
  import type { PreparedLegend, PreparedSeries, PreparedSeriesOptions } from '../useSeries/types';
5
4
  import type { AxesState } from './types';
6
5
  interface UseAxesProps {
@@ -15,9 +14,45 @@ interface UseAxesProps {
15
14
  xAxis?: ChartXAxis;
16
15
  yAxis?: ChartYAxis[];
17
16
  }
18
- export declare function useAxis(props: UseAxesProps): {
19
- setAxes: React.Dispatch<React.SetStateAction<AxesState>>;
17
+ export declare function getAxes(props: UseAxesProps): Promise<{
20
18
  xAxis: import("./types").PreparedXAxis | null;
21
- yAxis: import("./types").PreparedYAxis[];
22
- };
19
+ yAxis: (Omit<import("../../types").ChartAxis, "type" | "labels" | "plotLines" | "plotBands"> & {
20
+ type: import("../../types").ChartAxisType;
21
+ labels: Omit<import("../../types").ChartAxisLabels, "style" | "enabled" | "padding" | "autoRotation"> & Required<Pick<import("../../types").ChartAxisLabels, "margin" | "enabled" | "html" | "rotation" | "padding">> & {
22
+ style: import("../../types").BaseTextStyle;
23
+ rotation: number;
24
+ height: number;
25
+ width: number;
26
+ lineHeight: number;
27
+ maxWidth: number;
28
+ };
29
+ title: {
30
+ height: number;
31
+ width: number;
32
+ text: string;
33
+ margin: number;
34
+ style: import("../../types").BaseTextStyle;
35
+ align: import("../../types").ChartAxisTitleAlignment;
36
+ maxRowCount: number;
37
+ rotation: number;
38
+ maxWidth: number;
39
+ html: boolean;
40
+ };
41
+ min?: number;
42
+ grid: {
43
+ enabled: boolean;
44
+ };
45
+ maxPadding: number;
46
+ ticks: {
47
+ pixelInterval?: number;
48
+ };
49
+ tickMarks: import("./types").PreparedAxisTickMarks;
50
+ position: "left" | "right" | "top" | "bottom";
51
+ plotIndex: number;
52
+ plotLines: import("./types").PreparedAxisPlotLine[];
53
+ plotBands: import("./types").PreparedAxisPlotBand[];
54
+ crosshair: Required<import("../../types").AxisCrosshair>;
55
+ })[];
56
+ }>;
57
+ export declare function useAxis(props: UseAxesProps): AxesState;
23
58
  export {};
@@ -1,8 +1,52 @@
1
1
  import React from 'react';
2
2
  import isEqual from 'lodash/isEqual';
3
- import { getWidthOccupiedByYAxis } from '../useChartDimensions/utils';
3
+ import { getWidthOccupiedByYAxis } from '../../utils';
4
4
  import { getPreparedXAxis } from './x-axis';
5
5
  import { getPreparedYAxis } from './y-axis';
6
+ export async function getAxes(props) {
7
+ var _a, _b;
8
+ const { boundsHeight, height, preparedChart, legendConfig, preparedLegend, preparedSeries, width, xAxis, yAxis, } = props;
9
+ const seriesData = preparedSeries.filter((s) => s.visible);
10
+ const estimatedPreparedYAxis = await getPreparedYAxis({
11
+ height,
12
+ boundsHeight: height,
13
+ width,
14
+ seriesData,
15
+ yAxis,
16
+ });
17
+ const axesWidth = getWidthOccupiedByYAxis({ preparedAxis: estimatedPreparedYAxis });
18
+ const estimatedBoundsWidth = width - (axesWidth + preparedChart.margin.left + preparedChart.margin.right);
19
+ const preparedXAxis = await getPreparedXAxis({
20
+ xAxis,
21
+ width,
22
+ boundsWidth: estimatedBoundsWidth,
23
+ seriesData,
24
+ });
25
+ let estimatedBoundsHeight = boundsHeight !== null && boundsHeight !== void 0 ? boundsHeight : height;
26
+ if (preparedXAxis && typeof boundsHeight !== 'number') {
27
+ estimatedBoundsHeight =
28
+ height -
29
+ (preparedXAxis.title.height +
30
+ preparedXAxis.title.margin +
31
+ preparedXAxis.labels.margin +
32
+ preparedXAxis.labels.height +
33
+ (preparedXAxis.rangeSlider.enabled
34
+ ? preparedXAxis.rangeSlider.height + preparedXAxis.rangeSlider.margin
35
+ : 0) +
36
+ ((_a = legendConfig === null || legendConfig === void 0 ? void 0 : legendConfig.height) !== null && _a !== void 0 ? _a : 0) +
37
+ ((_b = preparedLegend === null || preparedLegend === void 0 ? void 0 : preparedLegend.margin) !== null && _b !== void 0 ? _b : 0) +
38
+ preparedChart.margin.top +
39
+ preparedChart.margin.bottom);
40
+ }
41
+ const preparedYAxis = await getPreparedYAxis({
42
+ height,
43
+ boundsHeight: estimatedBoundsHeight,
44
+ width,
45
+ seriesData,
46
+ yAxis,
47
+ });
48
+ return { xAxis: preparedXAxis, yAxis: preparedYAxis };
49
+ }
6
50
  export function useAxis(props) {
7
51
  const { boundsHeight, height, preparedChart, legendConfig, preparedLegend, preparedSeries, preparedSeriesOptions, width, xAxis, yAxis, } = props;
8
52
  const [axesState, setAxes] = React.useState({ xAxis: null, yAxis: [] });
@@ -16,48 +60,19 @@ export function useAxis(props) {
16
60
  return;
17
61
  }
18
62
  (async function () {
19
- var _a, _b;
20
63
  const currentRun = axesStateRunRef.current;
21
- const seriesData = preparedSeries.filter((s) => s.visible);
22
- const estimatedPreparedYAxis = await getPreparedYAxis({
64
+ const newStateValue = await getAxes({
65
+ boundsHeight,
23
66
  height,
24
- boundsHeight: height,
67
+ preparedChart,
68
+ legendConfig,
69
+ preparedLegend,
70
+ preparedSeries,
71
+ preparedSeriesOptions,
25
72
  width,
26
- seriesData,
27
- yAxis,
28
- });
29
- const axesWidth = getWidthOccupiedByYAxis({ preparedAxis: estimatedPreparedYAxis });
30
- const estimatedBoundsWidth = width - (axesWidth + preparedChart.margin.left + preparedChart.margin.right);
31
- const preparedXAxis = await getPreparedXAxis({
32
73
  xAxis,
33
- width,
34
- boundsWidth: estimatedBoundsWidth,
35
- seriesData,
36
- });
37
- let estimatedBoundsHeight = boundsHeight !== null && boundsHeight !== void 0 ? boundsHeight : height;
38
- if (preparedXAxis && typeof boundsHeight !== 'number') {
39
- estimatedBoundsHeight =
40
- height -
41
- (preparedXAxis.title.height +
42
- preparedXAxis.title.margin +
43
- preparedXAxis.labels.margin +
44
- preparedXAxis.labels.height +
45
- (preparedXAxis.rangeSlider.enabled
46
- ? preparedXAxis.rangeSlider.height + preparedXAxis.rangeSlider.margin
47
- : 0) +
48
- ((_a = legendConfig === null || legendConfig === void 0 ? void 0 : legendConfig.height) !== null && _a !== void 0 ? _a : 0) +
49
- ((_b = preparedLegend === null || preparedLegend === void 0 ? void 0 : preparedLegend.margin) !== null && _b !== void 0 ? _b : 0) +
50
- preparedChart.margin.top +
51
- preparedChart.margin.bottom);
52
- }
53
- const preparedYAxis = await getPreparedYAxis({
54
- height,
55
- boundsHeight: estimatedBoundsHeight,
56
- width,
57
- seriesData,
58
74
  yAxis,
59
75
  });
60
- const newStateValue = { xAxis: preparedXAxis, yAxis: preparedYAxis };
61
76
  if (axesStateRunRef.current === currentRun) {
62
77
  if (!isEqual(prevAxesStateValue.current, newStateValue)) {
63
78
  setAxes(newStateValue);
@@ -69,7 +84,7 @@ export function useAxis(props) {
69
84
  }, [
70
85
  boundsHeight,
71
86
  height,
72
- preparedChart.margin,
87
+ preparedChart,
73
88
  legendConfig,
74
89
  preparedLegend,
75
90
  preparedSeries,
@@ -81,10 +96,10 @@ export function useAxis(props) {
81
96
  const isAxesReady = axesStateReady.current;
82
97
  const result = React.useMemo(() => {
83
98
  if (isAxesReady) {
84
- return Object.assign(Object.assign({}, axesState), { setAxes });
99
+ return axesState;
85
100
  }
86
101
  prevAxesStateValue.current = { xAxis: null, yAxis: [] };
87
- return Object.assign(Object.assign({}, prevAxesStateValue.current), { setAxes });
102
+ return prevAxesStateValue.current;
88
103
  }, [isAxesReady, axesState]);
89
104
  return result;
90
105
  }
@@ -1,4 +1,3 @@
1
- import type React from 'react';
2
1
  import type { DashStyle } from '../../constants';
3
2
  import type { AxisCrosshair, AxisPlotBand, BaseTextStyle, ChartAxis, ChartAxisLabels, ChartAxisRangeSlider, ChartAxisTitleAlignment, ChartAxisType, DeepRequired, MeaningfulAny, PlotLayerPlacement } from '../../types';
4
3
  type PreparedAxisLabels = Omit<ChartAxisLabels, 'enabled' | 'padding' | 'style' | 'autoRotation'> & Required<Pick<ChartAxisLabels, 'enabled' | 'padding' | 'margin' | 'rotation' | 'html'>> & {
@@ -80,5 +79,4 @@ export type AxesState = {
80
79
  xAxis: PreparedXAxis | null;
81
80
  yAxis: PreparedYAxis[];
82
81
  };
83
- export type SetAxes = React.Dispatch<React.SetStateAction<AxesState>>;
84
82
  export {};
@@ -49,9 +49,7 @@ export const getPreparedYAxis = ({ height, boundsHeight, width, seriesData, yAxi
49
49
  if (!hasAxisRelatedSeries) {
50
50
  return Promise.resolve([]);
51
51
  }
52
- return Promise.all(
53
- // eslint-disable-next-line complexity
54
- axisItems.map(async (axisItem, axisIndex) => {
52
+ return Promise.all(axisItems.map(async (axisItem, axisIndex) => {
55
53
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
56
54
  const plotIndex = get(axisItem, 'plotIndex', 0);
57
55
  const firstPlotAxis = !axisByPlot[plotIndex];
@@ -17,6 +17,10 @@ type ReturnValue = {
17
17
  xScale?: ChartScale;
18
18
  yScale?: (ChartScale | undefined)[];
19
19
  };
20
+ export declare const createScales: (args: Args) => {
21
+ xScale: import("d3-scale").ScaleLinear<number, number, never> | import("d3-scale").ScaleBand<string> | import("d3-scale").ScaleTime<number, number, never> | undefined;
22
+ yScale: (ChartScale | undefined)[];
23
+ };
20
24
  /**
21
25
  * Uses to create scales for axis related series
22
26
  */
@@ -7,7 +7,7 @@ import { createXScale } from './x-scale';
7
7
  import { createYScale } from './y-scale';
8
8
  export { createXScale } from './x-scale';
9
9
  export { createYScale } from './y-scale';
10
- const createScales = (args) => {
10
+ export const createScales = (args) => {
11
11
  const { boundsWidth, boundsHeight, isRangeSlider, rangeSliderState, series, split, xAxis, yAxis, zoomState, } = args;
12
12
  // For range slider: always use all series regardless of visibility so the slider domain
13
13
  // stays stable when the user hides/shows series via the legend.
@@ -34,7 +34,6 @@ function getXScaleRange({ boundsWidth, hasZoomX }) {
34
34
  const range = hasZoomX ? xRangeZoom : xRange;
35
35
  return range;
36
36
  }
37
- // eslint-disable-next-line complexity
38
37
  export function createXScale(args) {
39
38
  const { axis, boundsWidth, series, rangeSliderState, zoomStateX } = args;
40
39
  const effectiveX = getEffectiveXRange(zoomStateX, rangeSliderState);
@@ -117,7 +117,6 @@ function getDomainMaxAlignedToEndTick(args) {
117
117
  }
118
118
  return dNewMax;
119
119
  }
120
- // eslint-disable-next-line complexity
121
120
  export function createYScale(args) {
122
121
  const { axis, boundsHeight, series, primaryAxis, primaryTicksCount, zoomStateY } = args;
123
122
  const [yMinPropsOrState, yMaxPropsOrState] = getMinMaxPropsOrState({
@@ -7,7 +7,7 @@ type Props = {
7
7
  height: number;
8
8
  xScale?: ChartScale;
9
9
  yScale?: (ChartScale | undefined)[];
10
- split: PreparedSplit;
10
+ split: PreparedSplit | undefined;
11
11
  plotElement: SVGGElement | null;
12
12
  dispatcher: Dispatch<object>;
13
13
  boundsOffsetLeft: number;
@@ -1,8 +1,8 @@
1
1
  import type { ChartXAxis, ChartYAxis, LegendConfig } from '../../types';
2
+ import type { PreparedChart } from '../types';
2
3
  import type { PreparedRangeSlider, PreparedXAxis, PreparedYAxis } from '../useAxis/types';
3
4
  import type { ChartScale } from '../useAxisScales/types';
4
5
  import type { BrushSelection, UseBrushProps } from '../useBrush/types';
5
- import type { PreparedChart } from '../useChartOptions/types';
6
6
  import type { PreparedLegend, PreparedSeries, PreparedSeriesOptions } from '../useSeries/types';
7
7
  export type RangeSliderState = {
8
8
  max: number;
@@ -1,7 +1,7 @@
1
+ import type { PreparedChart } from '../types';
1
2
  import type { PreparedRangeSlider } from '../useAxis/types';
2
3
  import type { ChartScale } from '../useAxisScales/types';
3
4
  import type { BrushSelection } from '../useBrush/types';
4
- import type { PreparedChart } from '../useChartOptions/types';
5
5
  import type { PreparedLegend } from '../useSeries/types';
6
6
  import type { RangeSliderState } from './types';
7
7
  export declare function getRangeSliderOffsetTop(args: {
@@ -1,16 +1,12 @@
1
1
  import type { ChartData } from '../../types';
2
- import type { OnLegendItemClick, PreparedLegend, PreparedSeries } from './types';
3
- type Args = {
4
- colors: string[];
5
- legend: ChartData['legend'];
6
- originalSeriesData: ChartData['series']['data'];
7
- seriesData: ChartData['series']['data'];
8
- seriesOptions: ChartData['series']['options'];
9
- preparedLegend?: PreparedLegend;
10
- };
11
- export declare const useSeries: (args: Args) => {
12
- preparedLegend: PreparedLegend | null;
2
+ import type { PreparedLegend, PreparedSeries } from './types';
3
+ export declare const getVisibleSeries: ({ preparedSeries, activeLegendItems, }: {
13
4
  preparedSeries: PreparedSeries[];
14
- handleLegendItemClick: OnLegendItemClick;
15
- };
16
- export {};
5
+ activeLegendItems: string[];
6
+ }) => PreparedSeries[];
7
+ export declare const getPreparedSeries: ({ seriesData, seriesOptions, colors, preparedLegend, }: {
8
+ seriesData: ChartData["series"]["data"];
9
+ seriesOptions: ChartData["series"]["options"];
10
+ colors: string[];
11
+ preparedLegend?: PreparedLegend | null;
12
+ }) => Promise<PreparedSeries[]>;
@@ -1,21 +1,15 @@
1
- import React from 'react';
2
1
  import { group, scaleOrdinal } from 'd3';
3
2
  import { getSeriesNames } from '../../utils';
4
- import { usePrevious } from '../usePrevious';
5
- import { getPreparedLegend } from './prepare-legend';
6
3
  import { prepareSeries } from './prepareSeries';
7
- import { getActiveLegendItems, getAllLegendItems } from './utils';
8
- const useVisibleSeries = ({ preparedSeries, activeLegendItems, }) => {
9
- return React.useMemo(() => {
10
- return preparedSeries.map((singleSeries) => {
11
- if (singleSeries.legend.enabled) {
12
- return Object.assign(Object.assign({}, singleSeries), { visible: activeLegendItems.includes(singleSeries.legend.groupId) });
13
- }
14
- return singleSeries;
15
- });
16
- }, [preparedSeries, activeLegendItems]);
4
+ export const getVisibleSeries = ({ preparedSeries, activeLegendItems, }) => {
5
+ return preparedSeries.map((singleSeries) => {
6
+ if (singleSeries.legend.enabled) {
7
+ return Object.assign(Object.assign({}, singleSeries), { visible: activeLegendItems.includes(singleSeries.legend.groupId) });
8
+ }
9
+ return singleSeries;
10
+ });
17
11
  };
18
- const getPreparedSeries = async ({ seriesData, seriesOptions, colors, preparedLegend, }) => {
12
+ export const getPreparedSeries = async ({ seriesData, seriesOptions, colors, preparedLegend, }) => {
19
13
  const seriesNames = getSeriesNames(seriesData);
20
14
  const colorScale = scaleOrdinal(seriesNames, colors);
21
15
  const groupedSeries = group(seriesData, (item) => item.type);
@@ -37,69 +31,3 @@ const getPreparedSeries = async ({ seriesData, seriesOptions, colors, preparedLe
37
31
  }
38
32
  return acc;
39
33
  };
40
- export const useSeries = (args) => {
41
- const { legend, originalSeriesData, seriesData, seriesOptions, colors, preparedLegend: preparedLegendProps = null, } = args;
42
- const [preparedLegend, setPreparedLegend] = React.useState(preparedLegendProps);
43
- const legendRunRef = React.useRef(0);
44
- React.useEffect(() => {
45
- if (!preparedLegendProps) {
46
- const currentRun = ++legendRunRef.current;
47
- getPreparedLegend({ legend, series: seriesData }).then((value) => {
48
- if (legendRunRef.current === currentRun) {
49
- setPreparedLegend(value);
50
- }
51
- });
52
- }
53
- }, [legend, preparedLegendProps, seriesData]);
54
- const [preparedSeries, setPreparedSeries] = React.useState([]);
55
- const [activeLegendItems, setActiveLegendItems] = React.useState(getActiveLegendItems(preparedSeries));
56
- const seriesRunRef = React.useRef(0);
57
- React.useEffect(() => {
58
- const currentRun = ++seriesRunRef.current;
59
- (async () => {
60
- const items = await getPreparedSeries({
61
- seriesData,
62
- seriesOptions,
63
- preparedLegend,
64
- colors,
65
- });
66
- if (seriesRunRef.current === currentRun) {
67
- setPreparedSeries(items);
68
- setActiveLegendItems(getActiveLegendItems(items));
69
- }
70
- })();
71
- }, [seriesData, seriesOptions, preparedLegend, colors]);
72
- const prevOriginalSeriesData = usePrevious(originalSeriesData);
73
- const chartSeries = useVisibleSeries({ preparedSeries, activeLegendItems });
74
- const handleLegendItemClick = React.useCallback(({ id, metaKey }) => {
75
- const allItems = getAllLegendItems(preparedSeries);
76
- const onlyItemSelected = activeLegendItems.length === 1 && activeLegendItems.includes(id);
77
- let nextActiveLegendItems;
78
- if (metaKey && activeLegendItems.includes(id)) {
79
- nextActiveLegendItems = activeLegendItems.filter((item) => item !== id);
80
- }
81
- else if (metaKey && !activeLegendItems.includes(id)) {
82
- nextActiveLegendItems = activeLegendItems.concat(id);
83
- }
84
- else if (onlyItemSelected && allItems.length === 1) {
85
- nextActiveLegendItems = [];
86
- }
87
- else if (onlyItemSelected) {
88
- nextActiveLegendItems = allItems;
89
- }
90
- else {
91
- nextActiveLegendItems = [id];
92
- }
93
- setActiveLegendItems(nextActiveLegendItems);
94
- }, [preparedSeries, activeLegendItems]);
95
- React.useEffect(() => {
96
- if (prevOriginalSeriesData !== originalSeriesData) {
97
- setActiveLegendItems(getActiveLegendItems(preparedSeries));
98
- }
99
- }, [originalSeriesData, prevOriginalSeriesData, preparedSeries]);
100
- return {
101
- preparedLegend,
102
- preparedSeries: chartSeries,
103
- handleLegendItemClick,
104
- };
105
- };
@@ -5,9 +5,9 @@ export declare const DEFAULT_LINE_WIDTH = 1;
5
5
  export declare const DEFAULT_MARKER: {
6
6
  enabled: boolean;
7
7
  symbol: `${import("../../constants").SymbolType}`;
8
- radius: number;
9
- borderWidth: number;
10
8
  borderColor: string;
9
+ borderWidth: number;
10
+ radius: number;
11
11
  };
12
12
  type PrepareAreaSeriesArgs = {
13
13
  colorScale: ScaleOrdinal<string, string>;
@@ -1,5 +1,5 @@
1
1
  import type { ChartData } from '../../types';
2
- import type { PreparedChart } from '../useChartOptions/types';
2
+ import type { PreparedChart } from '../types';
3
3
  import type { LegendItem, PreparedLegend, PreparedSeries } from './types';
4
4
  export declare function getPreparedLegend(args: {
5
5
  legend: ChartData['legend'];
@@ -7,9 +7,9 @@ export declare const DEFAULT_DASH_STYLE: "Solid";
7
7
  export declare const DEFAULT_MARKER: {
8
8
  enabled: boolean;
9
9
  symbol: `${import("../../constants").SymbolType}`;
10
- radius: number;
11
- borderWidth: number;
12
10
  borderColor: string;
11
+ borderWidth: number;
12
+ radius: number;
13
13
  };
14
14
  type PrepareLineSeriesArgs = {
15
15
  colorScale: ScaleOrdinal<string, string>;
@@ -10,8 +10,8 @@ export declare const DEFAULT_MARKER: {
10
10
  enabled: boolean;
11
11
  radius: number;
12
12
  symbol: `${import("../../constants").SymbolType}`;
13
- borderWidth: number;
14
13
  borderColor: string;
14
+ borderWidth: number;
15
15
  };
16
16
  export declare function prepareRadarSeries(args: PrepareRadarSeriesArgs): PreparedRadarSeries[];
17
17
  export {};