@gravity-ui/chartkit 4.6.0 → 4.7.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 (99) hide show
  1. package/build/plugins/d3/examples/bar-x/Basic.d.ts +4 -0
  2. package/build/plugins/d3/examples/bar-x/Basic.js +78 -0
  3. package/build/plugins/d3/examples/bar-x/GroupedColumns.d.ts +2 -0
  4. package/build/plugins/d3/examples/bar-x/GroupedColumns.js +44 -0
  5. package/build/plugins/d3/examples/bar-x/StackedColumns.d.ts +2 -0
  6. package/build/plugins/d3/examples/bar-x/StackedColumns.js +45 -0
  7. package/build/plugins/d3/examples/nintendoGames.d.ts +62 -0
  8. package/build/plugins/d3/examples/nintendoGames.js +12037 -0
  9. package/build/plugins/d3/examples/pie/Basic.d.ts +2 -0
  10. package/build/plugins/d3/examples/pie/Basic.js +30 -0
  11. package/build/plugins/d3/examples/pie/Donut.d.ts +2 -0
  12. package/build/plugins/d3/examples/pie/Donut.js +31 -0
  13. package/build/plugins/d3/examples/scatter/Basic.d.ts +2 -0
  14. package/build/plugins/d3/examples/scatter/Basic.js +66 -0
  15. package/build/plugins/d3/renderer/D3Widget.js +11 -1
  16. package/build/plugins/d3/renderer/components/AxisX.d.ts +1 -2
  17. package/build/plugins/d3/renderer/components/AxisX.js +8 -21
  18. package/build/plugins/d3/renderer/components/AxisY.js +50 -18
  19. package/build/plugins/d3/renderer/components/Chart.js +25 -17
  20. package/build/plugins/d3/renderer/components/Legend.js +20 -22
  21. package/build/plugins/d3/renderer/components/Title.js +1 -1
  22. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.d.ts +2 -2
  23. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +8 -0
  24. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.d.ts +14 -0
  25. package/build/plugins/d3/renderer/components/Tooltip/TooltipTriggerArea.js +70 -0
  26. package/build/plugins/d3/renderer/components/Tooltip/index.d.ts +5 -3
  27. package/build/plugins/d3/renderer/components/Tooltip/index.js +4 -2
  28. package/build/plugins/d3/renderer/components/styles.css +3 -0
  29. package/build/plugins/d3/renderer/constants/defaults/axis.d.ts +9 -0
  30. package/build/plugins/d3/renderer/constants/defaults/axis.js +6 -0
  31. package/build/plugins/d3/renderer/constants/defaults/index.d.ts +1 -0
  32. package/build/plugins/d3/renderer/constants/defaults/index.js +1 -0
  33. package/build/plugins/d3/renderer/constants/defaults/series-options.d.ts +11 -0
  34. package/build/plugins/d3/renderer/constants/defaults/series-options.js +41 -0
  35. package/build/plugins/d3/renderer/constants/index.d.ts +0 -1
  36. package/build/plugins/d3/renderer/constants/index.js +0 -1
  37. package/build/plugins/d3/renderer/d3-dispatcher.d.ts +1 -0
  38. package/build/plugins/d3/renderer/d3-dispatcher.js +4 -0
  39. package/build/plugins/d3/renderer/hooks/index.d.ts +0 -1
  40. package/build/plugins/d3/renderer/hooks/index.js +0 -1
  41. package/build/plugins/d3/renderer/hooks/useAxisScales/index.d.ts +6 -5
  42. package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +2 -1
  43. package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +8 -41
  44. package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.d.ts +3 -0
  45. package/build/plugins/d3/renderer/hooks/useChartDimensions/utils.js +17 -4
  46. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.d.ts +2 -4
  47. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +4 -23
  48. package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +1 -1
  49. package/build/plugins/d3/renderer/hooks/useChartOptions/index.js +2 -10
  50. package/build/plugins/d3/renderer/hooks/useChartOptions/title.d.ts +1 -1
  51. package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +1 -0
  52. package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +8 -5
  53. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.d.ts +5 -3
  54. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +61 -6
  55. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.d.ts +1 -1
  56. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +20 -12
  57. package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +1 -0
  58. package/build/plugins/d3/renderer/hooks/useSeries/index.js +8 -2
  59. package/build/plugins/d3/renderer/hooks/useSeries/prepare-legend.js +8 -3
  60. package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.d.ts +3 -0
  61. package/build/plugins/d3/renderer/hooks/useSeries/prepare-options.js +5 -0
  62. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +6 -3
  63. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +5 -1
  64. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.d.ts +12 -0
  65. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/index.js +91 -0
  66. package/build/plugins/d3/renderer/hooks/useShapes/bar-x/prepare-data.d.ts +19 -0
  67. package/build/plugins/d3/renderer/hooks/useShapes/{bar-x.js → bar-x/prepare-data.js} +9 -88
  68. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +13 -10
  69. package/build/plugins/d3/renderer/hooks/useShapes/index.js +28 -13
  70. package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +6 -4
  71. package/build/plugins/d3/renderer/hooks/useShapes/pie.js +98 -20
  72. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.d.ts +15 -0
  73. package/build/plugins/d3/renderer/hooks/useShapes/scatter/index.js +89 -0
  74. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.d.ts +19 -0
  75. package/build/plugins/d3/renderer/hooks/useShapes/scatter/prepare-data.js +55 -0
  76. package/build/plugins/d3/renderer/hooks/useShapes/styles.css +1 -9
  77. package/build/plugins/d3/renderer/hooks/useTooltip/index.d.ts +6 -6
  78. package/build/plugins/d3/renderer/hooks/useTooltip/index.js +15 -17
  79. package/build/plugins/d3/renderer/hooks/useTooltip/types.d.ts +0 -6
  80. package/build/plugins/d3/renderer/utils/axis-generators/bottom.d.ts +3 -1
  81. package/build/plugins/d3/renderer/utils/axis-generators/bottom.js +77 -38
  82. package/build/plugins/d3/renderer/utils/axis.js +0 -6
  83. package/build/plugins/d3/renderer/utils/index.d.ts +5 -0
  84. package/build/plugins/d3/renderer/utils/index.js +13 -8
  85. package/build/plugins/d3/renderer/utils/math.d.ts +2 -0
  86. package/build/plugins/d3/renderer/utils/math.js +8 -0
  87. package/build/plugins/d3/renderer/utils/text.d.ts +6 -6
  88. package/build/plugins/d3/renderer/utils/text.js +25 -15
  89. package/build/types/widget-data/axis.d.ts +10 -0
  90. package/build/types/widget-data/series.d.ts +51 -0
  91. package/build/types/widget-data/tooltip.d.ts +18 -7
  92. package/package.json +2 -2
  93. package/build/plugins/d3/renderer/hooks/useChartEvents/index.d.ts +0 -5
  94. package/build/plugins/d3/renderer/hooks/useChartEvents/index.js +0 -15
  95. package/build/plugins/d3/renderer/hooks/useShapes/bar-x.d.ts +0 -21
  96. package/build/plugins/d3/renderer/hooks/useShapes/defaults.d.ts +0 -5
  97. package/build/plugins/d3/renderer/hooks/useShapes/defaults.js +0 -5
  98. package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +0 -19
  99. package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +0 -89
@@ -2,10 +2,11 @@ import React from 'react';
2
2
  import isNil from 'lodash/isNil';
3
3
  import { block } from '../../../../../utils/cn';
4
4
  import { DefaultContent } from './DefaultContent';
5
+ export * from './TooltipTriggerArea';
5
6
  const b = block('d3-tooltip');
6
7
  const POINTER_OFFSET_X = 20;
7
8
  export const Tooltip = (props) => {
8
- const { hovered, pointerPosition, tooltip, xAxis, yAxis } = props;
9
+ const { tooltip, xAxis, yAxis, hovered, pointerPosition } = props;
9
10
  const ref = React.useRef(null);
10
11
  const size = React.useMemo(() => {
11
12
  if (ref.current && hovered) {
@@ -13,6 +14,7 @@ export const Tooltip = (props) => {
13
14
  return { width, height };
14
15
  }
15
16
  return undefined;
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
16
18
  }, [hovered, pointerPosition]);
17
19
  const position = React.useMemo(() => {
18
20
  if (hovered && pointerPosition && size) {
@@ -38,7 +40,7 @@ export const Tooltip = (props) => {
38
40
  return null;
39
41
  }
40
42
  const customTooltip = (_a = tooltip.renderer) === null || _a === void 0 ? void 0 : _a.call(tooltip, { hovered });
41
- return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered, xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
43
+ return isNil(customTooltip) ? (React.createElement(DefaultContent, { hovered: hovered[0], xAxis: xAxis, yAxis: yAxis })) : (customTooltip);
42
44
  }, [hovered, tooltip, xAxis, yAxis]);
43
45
  if (!position || !hovered) {
44
46
  return null;
@@ -4,6 +4,7 @@
4
4
 
5
5
  .chartkit-d3-axis .tick text {
6
6
  color: var(--g-color-text-secondary);
7
+ alignment-baseline: after-edge;
7
8
  }
8
9
 
9
10
  .chartkit-d3-axis .tick line {
@@ -11,6 +12,7 @@
11
12
  }
12
13
 
13
14
  .chartkit-d3-axis__title {
15
+ alignment-baseline: after-edge;
14
16
  fill: var(--g-color-text-secondary);
15
17
  }
16
18
 
@@ -29,6 +31,7 @@
29
31
 
30
32
  .chartkit-d3-legend__item-text {
31
33
  fill: var(--g-color-text-secondary);
34
+ alignment-baseline: before-edge;
32
35
  }
33
36
 
34
37
  .chartkit-d3-legend__item-text_unselected {
@@ -2,4 +2,13 @@ export declare const axisLabelsDefaults: {
2
2
  margin: number;
3
3
  padding: number;
4
4
  fontSize: number;
5
+ maxWidth: number;
6
+ };
7
+ export declare const xAxisTitleDefaults: {
8
+ margin: number;
9
+ fontSize: string;
10
+ };
11
+ export declare const yAxisTitleDefaults: {
12
+ margin: number;
13
+ fontSize: string;
5
14
  };
@@ -2,4 +2,10 @@ export const axisLabelsDefaults = {
2
2
  margin: 10,
3
3
  padding: 10,
4
4
  fontSize: 11,
5
+ maxWidth: 80,
5
6
  };
7
+ const axisTitleDefaults = {
8
+ fontSize: '14px',
9
+ };
10
+ export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
11
+ export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
@@ -1,2 +1,3 @@
1
1
  export * from './axis';
2
2
  export * from './legend';
3
+ export * from './series-options';
@@ -1,2 +1,3 @@
1
1
  export * from './axis';
2
2
  export * from './legend';
3
+ export * from './series-options';
@@ -0,0 +1,11 @@
1
+ import type { ChartKitWidgetSeriesOptions } from '../../../../../types';
2
+ type DefauleBarXSeriesOptions = Partial<ChartKitWidgetSeriesOptions['bar-x']> & {
3
+ 'bar-x': {
4
+ barMaxWidth: number;
5
+ barPadding: number;
6
+ groupPadding: number;
7
+ };
8
+ };
9
+ export type SeriesOptionsDefaults = Partial<ChartKitWidgetSeriesOptions> & DefauleBarXSeriesOptions;
10
+ export declare const seriesOptionsDefaults: SeriesOptionsDefaults;
11
+ export {};
@@ -0,0 +1,41 @@
1
+ export const seriesOptionsDefaults = {
2
+ 'bar-x': {
3
+ barMaxWidth: 50,
4
+ barPadding: 0.1,
5
+ groupPadding: 0.2,
6
+ states: {
7
+ hover: {
8
+ enabled: true,
9
+ brightness: 0.3,
10
+ },
11
+ inactive: {
12
+ enabled: true,
13
+ opacity: 0.5,
14
+ },
15
+ },
16
+ },
17
+ pie: {
18
+ states: {
19
+ hover: {
20
+ enabled: true,
21
+ brightness: 0.3,
22
+ },
23
+ inactive: {
24
+ enabled: true,
25
+ opacity: 0.5,
26
+ },
27
+ },
28
+ },
29
+ scatter: {
30
+ states: {
31
+ hover: {
32
+ enabled: true,
33
+ brightness: 0.3,
34
+ },
35
+ inactive: {
36
+ enabled: true,
37
+ opacity: 0.5,
38
+ },
39
+ },
40
+ },
41
+ };
@@ -1,4 +1,3 @@
1
1
  export * from './defaults';
2
2
  export declare const DEFAULT_PALETTE: string[];
3
3
  export declare const DEFAULT_AXIS_LABEL_FONT_SIZE = "11px";
4
- export declare const DEFAULT_AXIS_TITLE_FONT_SIZE = "14px";
@@ -22,4 +22,3 @@ export const DEFAULT_PALETTE = [
22
22
  '#DCA3D7',
23
23
  ];
24
24
  export const DEFAULT_AXIS_LABEL_FONT_SIZE = '11px';
25
- export const DEFAULT_AXIS_TITLE_FONT_SIZE = '14px';
@@ -0,0 +1 @@
1
+ export declare const getD3Dispatcher: () => import("d3-dispatch").Dispatch<object>;
@@ -0,0 +1,4 @@
1
+ import { dispatch } from 'd3';
2
+ export const getD3Dispatcher = () => {
3
+ return dispatch('hover-shape');
4
+ };
@@ -1,5 +1,4 @@
1
1
  export * from './useChartDimensions';
2
- export * from './useChartEvents';
3
2
  export * from './useChartOptions';
4
3
  export * from './useChartOptions/types';
5
4
  export * from './useAxisScales';
@@ -1,5 +1,4 @@
1
1
  export * from './useChartDimensions';
2
- export * from './useChartEvents';
3
2
  export * from './useChartOptions';
4
3
  export * from './useChartOptions/types';
5
4
  export * from './useAxisScales';
@@ -1,20 +1,21 @@
1
1
  import type { ScaleBand, ScaleLinear, ScaleTime } from 'd3';
2
- import type { ChartOptions, PreparedAxis } from '../useChartOptions/types';
2
+ import type { PreparedAxis } from '../useChartOptions/types';
3
3
  import { PreparedSeries } from '../useSeries/types';
4
+ import { ChartKitWidgetAxis, ChartKitWidgetSeries } from '../../../../../types';
4
5
  export type ChartScale = ScaleLinear<number, number> | ScaleBand<string> | ScaleTime<number, number>;
5
6
  type Args = {
6
7
  boundsWidth: number;
7
8
  boundsHeight: number;
8
9
  series: PreparedSeries[];
9
- xAxis: ChartOptions['xAxis'];
10
- yAxis: ChartOptions['yAxis'];
10
+ xAxis: PreparedAxis;
11
+ yAxis: PreparedAxis[];
11
12
  };
12
13
  type ReturnValue = {
13
14
  xScale?: ChartScale;
14
15
  yScale?: ChartScale;
15
16
  };
16
- export declare function createYScale(axis: PreparedAxis, series: PreparedSeries[], boundsHeight: number): ScaleLinear<number, number, never> | ScaleBand<string> | ScaleTime<number, number, never>;
17
- export declare function createXScale(axis: PreparedAxis, series: PreparedSeries[], boundsWidth: number): ScaleLinear<number, number, never> | ScaleBand<string> | ScaleTime<number, number, never>;
17
+ export declare function createYScale(axis: PreparedAxis, series: PreparedSeries[], boundsHeight: number): ScaleBand<string> | ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
18
+ export declare function createXScale(axis: PreparedAxis | ChartKitWidgetAxis, series: (PreparedSeries | ChartKitWidgetSeries)[], boundsWidth: number): ScaleBand<string> | ScaleLinear<number, number, never> | ScaleTime<number, number, never>;
18
19
  /**
19
20
  * Uses to create scales for axis related series
20
21
  */
@@ -67,7 +67,8 @@ export function createXScale(axis, series, boundsWidth) {
67
67
  const xType = get(axis, 'type', 'linear');
68
68
  const xCategories = get(axis, 'categories');
69
69
  const xTimestamps = get(axis, 'timestamps');
70
- const xAxisMinPadding = boundsWidth * axis.maxPadding;
70
+ const maxPadding = get(axis, 'maxPadding', 0);
71
+ const xAxisMinPadding = boundsWidth * maxPadding;
71
72
  const xRange = [0, boundsWidth - xAxisMinPadding];
72
73
  switch (xType) {
73
74
  case 'linear': {
@@ -1,51 +1,20 @@
1
1
  import React from 'react';
2
- import { createXScale } from '../../hooks';
3
- import { formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsMaxHeight, getMaxTickCount, getTicksCount, getXAxisItems, hasOverlappingLabels, isAxisRelatedSeries, } from '../../utils';
2
+ import { isAxisRelatedSeries } from '../../utils';
4
3
  import { getBoundsWidth } from './utils';
5
4
  export { getBoundsWidth } from './utils';
6
- const getHeightOccupiedByXAxis = ({ preparedXAxis, preparedSeries, width, }) => {
7
- let height = preparedXAxis.title.height;
8
- if (preparedXAxis.labels.enabled) {
9
- const scale = createXScale(preparedXAxis, preparedSeries, width);
10
- const tickCount = getTicksCount({ axis: preparedXAxis, range: width });
11
- const ticks = getXAxisItems({
12
- scale: scale,
13
- count: tickCount,
14
- maxCount: getMaxTickCount({ width, axis: preparedXAxis }),
15
- });
16
- const step = getClosestPointsRange(preparedXAxis, ticks);
17
- const labels = ticks.map((value) => {
18
- return formatAxisTickLabel({
19
- axis: preparedXAxis,
20
- value,
21
- step,
22
- });
23
- });
24
- const overlapping = hasOverlappingLabels({
25
- width,
26
- labels,
27
- padding: preparedXAxis.labels.padding,
28
- style: preparedXAxis.labels.style,
29
- });
30
- const labelsHeight = overlapping
31
- ? getLabelsMaxHeight({
32
- labels,
33
- style: preparedXAxis.labels.style,
34
- transform: 'rotate(-45)',
35
- })
36
- : getHorisontalSvgTextHeight({ text: 'Tmp', style: preparedXAxis.labels.style });
37
- height += preparedXAxis.labels.margin + labelsHeight;
38
- }
39
- return height;
40
- };
41
5
  const getBottomOffset = (args) => {
42
- const { hasAxisRelatedSeries, preparedLegend, preparedXAxis, preparedSeries, width } = args;
6
+ const { hasAxisRelatedSeries, preparedLegend, preparedXAxis } = args;
43
7
  let result = 0;
44
8
  if (preparedLegend.enabled) {
45
9
  result += preparedLegend.height + preparedLegend.margin;
46
10
  }
47
11
  if (hasAxisRelatedSeries) {
48
- result += getHeightOccupiedByXAxis({ preparedXAxis, preparedSeries, width });
12
+ if (preparedXAxis.title.text) {
13
+ result += preparedXAxis.title.height + preparedXAxis.title.margin;
14
+ }
15
+ if (preparedXAxis.labels.enabled) {
16
+ result += preparedXAxis.labels.margin + preparedXAxis.labels.height;
17
+ }
49
18
  }
50
19
  return result;
51
20
  };
@@ -58,8 +27,6 @@ export const useChartDimensions = (args) => {
58
27
  hasAxisRelatedSeries,
59
28
  preparedLegend,
60
29
  preparedXAxis,
61
- preparedSeries,
62
- width: boundsWidth,
63
30
  });
64
31
  const boundsHeight = height - margin.top - margin.bottom - bottomOffset;
65
32
  return { boundsWidth, boundsHeight };
@@ -4,3 +4,6 @@ export declare const getBoundsWidth: (args: {
4
4
  chartMargin: PreparedChart['margin'];
5
5
  preparedYAxis: PreparedAxis[];
6
6
  }) => number;
7
+ export declare function getWidthOccupiedByYAxis(args: {
8
+ preparedAxis: PreparedAxis[];
9
+ }): number;
@@ -1,7 +1,20 @@
1
1
  export const getBoundsWidth = (args) => {
2
2
  const { chartWidth, chartMargin, preparedYAxis } = args;
3
- const yAxisTitleHeight = preparedYAxis.reduce((acc, axis) => {
4
- return acc + (axis.title.height || 0);
5
- }, 0) || 0;
6
- return chartWidth - chartMargin.right - chartMargin.left - yAxisTitleHeight;
3
+ return (chartWidth -
4
+ chartMargin.right -
5
+ chartMargin.left -
6
+ getWidthOccupiedByYAxis({ preparedAxis: preparedYAxis }));
7
7
  };
8
+ export function getWidthOccupiedByYAxis(args) {
9
+ const { preparedAxis } = args;
10
+ let result = 0;
11
+ preparedAxis.forEach((axis) => {
12
+ if (axis.title.text) {
13
+ result += axis.title.height + axis.title.margin;
14
+ }
15
+ if (axis.labels.enabled) {
16
+ result += axis.labels.margin + axis.labels.width;
17
+ }
18
+ });
19
+ return result;
20
+ }
@@ -1,8 +1,6 @@
1
- import type { ChartKitWidgetData } from '../../../../../types/widget-data';
2
- import type { PreparedAxis, PreparedChart, PreparedTitle } from './types';
1
+ import type { ChartKitWidgetData } from '../../../../../types';
2
+ import type { PreparedChart, PreparedTitle } from './types';
3
3
  export declare const getPreparedChart: (args: {
4
4
  chart: ChartKitWidgetData['chart'];
5
- series: ChartKitWidgetData['series'];
6
- preparedY1Axis: PreparedAxis;
7
5
  preparedTitle?: PreparedTitle;
8
6
  }) => PreparedChart;
@@ -1,40 +1,21 @@
1
1
  import get from 'lodash/get';
2
- import { isAxisRelatedSeries, getHorisontalSvgTextHeight } from '../../utils';
3
- const AXIS_LINE_WIDTH = 1;
4
2
  const getMarginTop = (args) => {
5
- const { chart, hasAxisRelatedSeries, preparedY1Axis, preparedTitle } = args;
3
+ const { chart, preparedTitle } = args;
6
4
  let marginTop = get(chart, 'margin.top', 0);
7
- if (hasAxisRelatedSeries) {
8
- marginTop +=
9
- getHorisontalSvgTextHeight({ text: 'Tmp', style: preparedY1Axis.labels.style }) / 2;
10
- }
11
5
  if (preparedTitle === null || preparedTitle === void 0 ? void 0 : preparedTitle.height) {
12
6
  marginTop += preparedTitle.height;
13
7
  }
14
8
  return marginTop;
15
9
  };
16
- const getMarginLeft = (args) => {
17
- const { chart, hasAxisRelatedSeries, preparedY1Axis } = args;
18
- let marginLeft = get(chart, 'margin.left', 0);
19
- if (hasAxisRelatedSeries) {
20
- marginLeft +=
21
- AXIS_LINE_WIDTH +
22
- preparedY1Axis.labels.margin +
23
- (preparedY1Axis.labels.maxWidth || 0) +
24
- preparedY1Axis.title.height;
25
- }
26
- return marginLeft;
27
- };
28
10
  const getMarginRight = (args) => {
29
11
  const { chart } = args;
30
12
  return get(chart, 'margin.right', 0);
31
13
  };
32
14
  export const getPreparedChart = (args) => {
33
- const { chart, series, preparedY1Axis, preparedTitle } = args;
34
- const hasAxisRelatedSeries = series.data.some(isAxisRelatedSeries);
35
- const marginTop = getMarginTop({ chart, hasAxisRelatedSeries, preparedY1Axis, preparedTitle });
15
+ const { chart, preparedTitle } = args;
16
+ const marginTop = getMarginTop({ chart, preparedTitle });
36
17
  const marginBottom = get(chart, 'margin.bottom', 0);
37
- const marginLeft = getMarginLeft({ chart, hasAxisRelatedSeries, preparedY1Axis });
18
+ const marginLeft = get(chart, 'margin.left', 0);
38
19
  const marginRight = getMarginRight({ chart });
39
20
  return {
40
21
  margin: {
@@ -1,4 +1,4 @@
1
- import type { ChartKitWidgetData } from '../../../../../types/widget-data';
1
+ import type { ChartKitWidgetData } from '../../../../../types';
2
2
  import type { ChartOptions } from './types';
3
3
  type Args = {
4
4
  data: ChartKitWidgetData;
@@ -2,28 +2,20 @@ import React from 'react';
2
2
  import { getPreparedChart } from './chart';
3
3
  import { getPreparedTitle } from './title';
4
4
  import { getPreparedTooltip } from './tooltip';
5
- import { getPreparedXAxis } from './x-axis';
6
- import { getPreparedYAxis } from './y-axis';
7
5
  export const useChartOptions = (args) => {
8
- const { data: { chart, series, title, tooltip, xAxis, yAxis }, } = args;
6
+ const { data: { chart, title, tooltip }, } = args;
9
7
  const options = React.useMemo(() => {
10
8
  const preparedTitle = getPreparedTitle({ title });
11
9
  const preparedTooltip = getPreparedTooltip({ tooltip });
12
- const preparedYAxis = getPreparedYAxis({ series: series.data, yAxis });
13
- const preparedXAxis = getPreparedXAxis({ xAxis });
14
10
  const preparedChart = getPreparedChart({
15
11
  chart,
16
- series,
17
12
  preparedTitle,
18
- preparedY1Axis: preparedYAxis[0],
19
13
  });
20
14
  return {
21
15
  chart: preparedChart,
22
16
  title: preparedTitle,
23
17
  tooltip: preparedTooltip,
24
- xAxis: preparedXAxis,
25
- yAxis: preparedYAxis,
26
18
  };
27
- }, [chart, title, tooltip, series, xAxis, yAxis]);
19
+ }, [chart, title, tooltip]);
28
20
  return options;
29
21
  };
@@ -1,4 +1,4 @@
1
- import type { ChartKitWidgetData } from '../../../../../types/widget-data';
1
+ import type { ChartKitWidgetData } from '../../../../../types';
2
2
  import type { PreparedTitle } from './types';
3
3
  export declare const getPreparedTitle: ({ title, }: {
4
4
  title: ChartKitWidgetData['title'];
@@ -6,6 +6,7 @@ export const getPreparedTitle = ({ title, }) => {
6
6
  const titleText = get(title, 'text');
7
7
  const titleStyle = {
8
8
  fontSize: get(title, 'style.fontSize', DEFAULT_TITLE_FONT_SIZE),
9
+ fontWeight: get(title, 'style.fontWeight'),
9
10
  };
10
11
  const titleHeight = titleText
11
12
  ? getHorisontalSvgTextHeight({ text: titleText, style: titleStyle }) + TITLE_PADDINGS
@@ -1,7 +1,11 @@
1
- import type { BaseTextStyle, ChartKitWidgetData, ChartKitWidgetAxis, ChartKitWidgetAxisType, ChartKitWidgetAxisLabels, ChartMargin } from '../../../../../types/widget-data';
2
- type PreparedAxisLabels = Omit<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'style'> & Required<Pick<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'margin'>> & {
1
+ import type { BaseTextStyle, ChartKitWidgetData, ChartKitWidgetAxis, ChartKitWidgetAxisType, ChartKitWidgetAxisLabels, ChartMargin } from '../../../../../types';
2
+ type PreparedAxisLabels = Omit<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'style' | 'autoRotation'> & Required<Pick<ChartKitWidgetAxisLabels, 'enabled' | 'padding' | 'margin' | 'rotation'>> & {
3
3
  style: BaseTextStyle;
4
- maxWidth?: number;
4
+ rotation: number;
5
+ height: number;
6
+ width: number;
7
+ lineHeight: number;
8
+ maxWidth: number;
5
9
  };
6
10
  export type PreparedChart = {
7
11
  margin: ChartMargin;
@@ -12,6 +16,7 @@ export type PreparedAxis = Omit<ChartKitWidgetAxis, 'type' | 'labels'> & {
12
16
  title: {
13
17
  height: number;
14
18
  text: string;
19
+ margin: number;
15
20
  style: BaseTextStyle;
16
21
  };
17
22
  min?: number;
@@ -32,8 +37,6 @@ export type PreparedTooltip = ChartKitWidgetData['tooltip'] & {
32
37
  export type ChartOptions = {
33
38
  chart: PreparedChart;
34
39
  tooltip: PreparedTooltip;
35
- xAxis: PreparedAxis;
36
- yAxis: PreparedAxis[];
37
40
  title?: PreparedTitle;
38
41
  };
39
42
  export {};
@@ -1,5 +1,7 @@
1
- import type { ChartKitWidgetData } from '../../../../../types/widget-data';
1
+ import type { ChartKitWidgetSeries, ChartKitWidgetAxis } from '../../../../../types';
2
2
  import type { PreparedAxis } from './types';
3
- export declare const getPreparedXAxis: ({ xAxis }: {
4
- xAxis: ChartKitWidgetData['xAxis'];
3
+ export declare const getPreparedXAxis: ({ xAxis, series, width, }: {
4
+ xAxis?: ChartKitWidgetAxis | undefined;
5
+ series: ChartKitWidgetSeries[];
6
+ width: number;
5
7
  }) => PreparedAxis;
@@ -1,10 +1,52 @@
1
1
  import get from 'lodash/get';
2
- import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE, DEFAULT_AXIS_TITLE_FONT_SIZE, } from '../../constants';
3
- import { getHorisontalSvgTextHeight } from '../../utils';
4
- export const getPreparedXAxis = ({ xAxis }) => {
2
+ import { axisLabelsDefaults, DEFAULT_AXIS_LABEL_FONT_SIZE, xAxisTitleDefaults, } from '../../constants';
3
+ import { calculateCos, formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsMaxHeight, getMaxTickCount, getTicksCount, getXAxisItems, hasOverlappingLabels, } from '../../utils';
4
+ import { createXScale } from '../useAxisScales';
5
+ function getLabelSettings({ axis, series, width, autoRotation = true, }) {
6
+ const scale = createXScale(axis, series, width);
7
+ const tickCount = getTicksCount({ axis, range: width });
8
+ const ticks = getXAxisItems({
9
+ scale: scale,
10
+ count: tickCount,
11
+ maxCount: getMaxTickCount({ width, axis }),
12
+ });
13
+ const step = getClosestPointsRange(axis, ticks);
14
+ const labels = ticks.map((value) => {
15
+ return formatAxisTickLabel({
16
+ axis,
17
+ value,
18
+ step,
19
+ });
20
+ });
21
+ const overlapping = hasOverlappingLabels({
22
+ width,
23
+ labels,
24
+ padding: axis.labels.padding,
25
+ style: axis.labels.style,
26
+ });
27
+ const defaultRotation = overlapping && autoRotation ? -45 : 0;
28
+ const rotation = axis.labels.rotation || defaultRotation;
29
+ const labelsHeight = rotation
30
+ ? getLabelsMaxHeight({
31
+ labels,
32
+ style: {
33
+ 'font-size': axis.labels.style.fontSize,
34
+ 'font-weight': axis.labels.style.fontWeight || 'normal',
35
+ },
36
+ rotation,
37
+ })
38
+ : axis.labels.lineHeight;
39
+ const maxHeight = rotation ? calculateCos(rotation) * axis.labels.maxWidth : labelsHeight;
40
+ return { height: Math.min(maxHeight, labelsHeight), rotation };
41
+ }
42
+ export const getPreparedXAxis = ({ xAxis, series, width, }) => {
43
+ var _a;
5
44
  const titleText = get(xAxis, 'title.text', '');
6
45
  const titleStyle = {
7
- fontSize: get(xAxis, 'title.style.fontSize', DEFAULT_AXIS_TITLE_FONT_SIZE),
46
+ fontSize: get(xAxis, 'title.style.fontSize', xAxisTitleDefaults.fontSize),
47
+ };
48
+ const labelsStyle = {
49
+ fontSize: get(xAxis, 'labels.style.fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE),
8
50
  };
9
51
  const preparedXAxis = {
10
52
  type: get(xAxis, 'type', 'linear'),
@@ -14,8 +56,12 @@ export const getPreparedXAxis = ({ xAxis }) => {
14
56
  padding: get(xAxis, 'labels.padding', axisLabelsDefaults.padding),
15
57
  dateFormat: get(xAxis, 'labels.dateFormat'),
16
58
  numberFormat: get(xAxis, 'labels.numberFormat'),
17
- autoRotation: get(xAxis, 'labels.autoRotation', true),
18
- style: { fontSize: get(xAxis, 'labels.style.fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE) },
59
+ rotation: get(xAxis, 'labels.rotation', 0),
60
+ style: labelsStyle,
61
+ width: 0,
62
+ height: 0,
63
+ lineHeight: getHorisontalSvgTextHeight({ text: 'Tmp', style: labelsStyle }),
64
+ maxWidth: get(xAxis, 'labels.maxWidth', axisLabelsDefaults.maxWidth),
19
65
  },
20
66
  lineColor: get(xAxis, 'lineColor'),
21
67
  categories: get(xAxis, 'categories'),
@@ -23,6 +69,7 @@ export const getPreparedXAxis = ({ xAxis }) => {
23
69
  title: {
24
70
  text: titleText,
25
71
  style: titleStyle,
72
+ margin: get(xAxis, 'title.margin', xAxisTitleDefaults.margin),
26
73
  height: titleText
27
74
  ? getHorisontalSvgTextHeight({ text: titleText, style: titleStyle })
28
75
  : 0,
@@ -36,5 +83,13 @@ export const getPreparedXAxis = ({ xAxis }) => {
36
83
  pixelInterval: get(xAxis, 'ticks.pixelInterval'),
37
84
  },
38
85
  };
86
+ const { height, rotation } = getLabelSettings({
87
+ axis: preparedXAxis,
88
+ series,
89
+ width,
90
+ autoRotation: (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.labels) === null || _a === void 0 ? void 0 : _a.autoRotation,
91
+ });
92
+ preparedXAxis.labels.height = height;
93
+ preparedXAxis.labels.rotation = rotation;
39
94
  return preparedXAxis;
40
95
  };
@@ -1,4 +1,4 @@
1
- import type { ChartKitWidgetData, ChartKitWidgetSeries } from '../../../../../types/widget-data';
1
+ import type { ChartKitWidgetData, ChartKitWidgetSeries } from '../../../../../types';
2
2
  import type { PreparedAxis } from './types';
3
3
  export declare const getPreparedYAxis: ({ series, yAxis, }: {
4
4
  series: ChartKitWidgetSeries[];