@gravity-ui/chartkit 3.4.3 → 3.6.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 (62) hide show
  1. package/build/plugins/d3/renderer/D3Widget.js +3 -3
  2. package/build/plugins/d3/renderer/components/Chart.d.ts +3 -1
  3. package/build/plugins/d3/renderer/components/Chart.js +13 -12
  4. package/build/plugins/d3/renderer/components/Legend.d.ts +3 -2
  5. package/build/plugins/d3/renderer/components/Legend.js +101 -61
  6. package/build/plugins/d3/renderer/components/Tooltip/DefaultContent.js +12 -0
  7. package/build/plugins/d3/renderer/components/styles.css +4 -13
  8. package/build/plugins/d3/renderer/constants.d.ts +3 -0
  9. package/build/plugins/d3/renderer/constants.js +3 -0
  10. package/build/plugins/d3/renderer/hooks/index.d.ts +1 -1
  11. package/build/plugins/d3/renderer/hooks/index.js +1 -1
  12. package/build/plugins/d3/renderer/hooks/useAxisScales/index.d.ts +2 -2
  13. package/build/plugins/d3/renderer/hooks/useAxisScales/index.js +2 -2
  14. package/build/plugins/d3/renderer/hooks/useChartDimensions/index.d.ts +2 -2
  15. package/build/plugins/d3/renderer/hooks/useChartDimensions/index.js +2 -4
  16. package/build/plugins/d3/renderer/hooks/useChartOptions/chart.js +21 -15
  17. package/build/plugins/d3/renderer/hooks/useChartOptions/index.d.ts +3 -1
  18. package/build/plugins/d3/renderer/hooks/useChartOptions/legend.js +7 -2
  19. package/build/plugins/d3/renderer/hooks/useChartOptions/title.js +2 -2
  20. package/build/plugins/d3/renderer/hooks/useChartOptions/types.d.ts +3 -1
  21. package/build/plugins/d3/renderer/hooks/useChartOptions/x-axis.js +3 -3
  22. package/build/plugins/d3/renderer/hooks/useChartOptions/y-axis.js +3 -3
  23. package/build/plugins/d3/renderer/hooks/useSeries/constants.d.ts +1 -0
  24. package/build/plugins/d3/renderer/hooks/useSeries/constants.js +1 -0
  25. package/build/plugins/d3/renderer/hooks/useSeries/index.d.ts +10 -8
  26. package/build/plugins/d3/renderer/hooks/useSeries/index.js +43 -14
  27. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.d.ts +9 -0
  28. package/build/plugins/d3/renderer/hooks/useSeries/prepareSeries.js +85 -0
  29. package/build/plugins/d3/renderer/hooks/useSeries/types.d.ts +29 -0
  30. package/build/plugins/d3/renderer/hooks/useSeries/types.js +1 -0
  31. package/build/plugins/d3/renderer/hooks/useSeries/utils.d.ts +3 -0
  32. package/build/plugins/d3/renderer/hooks/useSeries/utils.js +11 -0
  33. package/build/plugins/d3/renderer/hooks/useShapes/bar-x.d.ts +3 -0
  34. package/build/plugins/d3/renderer/hooks/useShapes/bar-x.js +7 -3
  35. package/build/plugins/d3/renderer/hooks/useShapes/index.d.ts +7 -2
  36. package/build/plugins/d3/renderer/hooks/useShapes/index.js +26 -2
  37. package/build/plugins/d3/renderer/hooks/useShapes/pie.d.ts +13 -0
  38. package/build/plugins/d3/renderer/hooks/useShapes/pie.js +126 -0
  39. package/build/plugins/d3/renderer/hooks/useShapes/scatter.d.ts +2 -1
  40. package/build/plugins/d3/renderer/hooks/useShapes/scatter.js +6 -3
  41. package/build/plugins/d3/renderer/hooks/useShapes/styles.css +22 -0
  42. package/build/plugins/d3/renderer/utils/index.d.ts +49 -7
  43. package/build/plugins/d3/renderer/utils/index.js +50 -18
  44. package/build/plugins/d3/renderer/utils/math.d.ts +23 -0
  45. package/build/plugins/d3/renderer/utils/math.js +43 -0
  46. package/build/plugins/highcharts/renderer/components/HighchartsComponent.js +1 -1
  47. package/build/plugins/highcharts/renderer/components/HighchartsReact.d.ts +18 -0
  48. package/build/plugins/highcharts/renderer/components/HighchartsReact.js +46 -0
  49. package/build/plugins/index.d.ts +1 -0
  50. package/build/plugins/index.js +1 -0
  51. package/build/types/widget-data/bar-x.d.ts +6 -1
  52. package/build/types/widget-data/base.d.ts +12 -0
  53. package/build/types/widget-data/legend.d.ts +32 -0
  54. package/build/types/widget-data/pie.d.ts +37 -1
  55. package/build/types/widget-data/scatter.d.ts +6 -1
  56. package/package.json +1 -3
  57. package/build/plugins/d3/renderer/hooks/useChartOptions/constants.d.ts +0 -3
  58. package/build/plugins/d3/renderer/hooks/useChartOptions/constants.js +0 -3
  59. package/build/plugins/d3/renderer/hooks/useChartOptions/utils.d.ts +0 -5
  60. package/build/plugins/d3/renderer/hooks/useChartOptions/utils.js +0 -18
  61. package/build/plugins/d3/renderer/hooks/useLegend/index.d.ts +0 -13
  62. package/build/plugins/d3/renderer/hooks/useLegend/index.js +0 -28
@@ -1,19 +1,39 @@
1
+ import { select } from 'd3';
2
+ import get from 'lodash/get';
1
3
  import { dateTime } from '@gravity-ui/date-utils';
2
4
  import { formatNumber } from '../../../shared';
5
+ import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../constants';
6
+ export * from './math';
3
7
  const CHARTS_WITHOUT_AXIS = ['pie'];
4
- // Сhecks whether the series should be drawn with axes
5
- export const isAxisRelatedSeries = (series) => {
8
+ /**
9
+ * Checks whether the series should be drawn with axes.
10
+ *
11
+ * @param series - The series object to check.
12
+ * @returns `true` if the series should be drawn with axes, `false` otherwise.
13
+ */
14
+ export function isAxisRelatedSeries(series) {
6
15
  return !CHARTS_WITHOUT_AXIS.includes(series.type);
7
- };
16
+ }
17
+ export function isSeriesWithNumericalXValues(series) {
18
+ return isAxisRelatedSeries(series);
19
+ }
20
+ export function isSeriesWithNumericalYValues(series) {
21
+ return isAxisRelatedSeries(series);
22
+ }
23
+ export function isSeriesWithCategoryValues(series) {
24
+ return isAxisRelatedSeries(series);
25
+ }
8
26
  export const getDomainDataXBySeries = (series) => {
9
- return series.filter(isAxisRelatedSeries).reduce((acc, s) => {
10
- acc.push(...s.data.map((d) => 'x' in d && d.x));
27
+ return series.reduce((acc, s) => {
28
+ if (isSeriesWithNumericalXValues(s)) {
29
+ acc.push(...s.data.map((d) => d.x));
30
+ }
11
31
  return acc;
12
32
  }, []);
13
33
  };
14
34
  export const getDomainDataYBySeries = (series) => {
15
- return series.filter(isAxisRelatedSeries).reduce((acc, s) => {
16
- acc.push(...s.data.map((d) => 'y' in d && d.y));
35
+ return series.filter(isSeriesWithNumericalYValues).reduce((acc, s) => {
36
+ acc.push(...s.data.map((d) => d.y));
17
37
  return acc;
18
38
  }, []);
19
39
  };
@@ -26,17 +46,6 @@ export const getSeriesNames = (series) => {
26
46
  return acc;
27
47
  }, []);
28
48
  };
29
- // Uses to get all visible series names array (except `pie` charts)
30
- export const getVisibleSeriesNames = (series) => {
31
- return series.reduce((acc, s) => {
32
- var _a;
33
- const visible = (_a = s.visible) !== null && _a !== void 0 ? _a : true;
34
- if ('name' in s && typeof s.name === 'string' && visible) {
35
- acc.push(s.name);
36
- }
37
- return acc;
38
- }, []);
39
- };
40
49
  export const getOnlyVisibleSeries = (series) => {
41
50
  return series.filter((s) => s.visible);
42
51
  };
@@ -69,3 +78,26 @@ export const formatAxisTickLabel = (args) => {
69
78
  }
70
79
  }
71
80
  };
81
+ /**
82
+ * Calculates the height of a text element in a horizontal SVG layout.
83
+ *
84
+ * @param {Object} args - The arguments for the function.
85
+ * @param {string} args.text - The text to be measured.
86
+ * @param {Partial<BaseTextStyle>} args.style - Optional style properties for the text element.
87
+ * @return {number} The height of the text element.
88
+ */
89
+ export const getHorisontalSvgTextHeight = (args) => {
90
+ const { text, style } = args;
91
+ const textSelection = select(document.body).append('text').text(text);
92
+ const fontSize = get(style, 'fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE);
93
+ let height = 0;
94
+ if (fontSize) {
95
+ textSelection.style('font-size', fontSize);
96
+ }
97
+ textSelection
98
+ .each(function () {
99
+ height = this.getBoundingClientRect().height;
100
+ })
101
+ .remove();
102
+ return height;
103
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Calculates a numeric property based on the given arguments.
3
+ *
4
+ * @param {Object} args - The arguments for the calculation.
5
+ * @param {string | number | null} args.value - The value to calculate the property for.
6
+ * @param {number} args.base - The base value to use in the calculation.
7
+ * @return {number | undefined} The calculated numeric property, or undefined if the value is invalid.
8
+ * @example
9
+ * const result1 = calculateNumericProperty({value: 1});
10
+ * console.log(result1); // Output: 1
11
+ * const result2 = calculateNumericProperty({value: '10px'});
12
+ * console.log(result2); // Output: 10
13
+ * const result3 = calculateNumericProperty({value: '50%', base: 200});
14
+ * console.log(result3); // Output: 100
15
+ * const result4 = calculateNumericProperty({value: '50%'});
16
+ * console.log(result4); // Output: undefined
17
+ * const result5 = calculateNumericProperty({value: 'invalid_value'});
18
+ * console.log(result5); // Output: undefined
19
+ */
20
+ export declare const calculateNumericProperty: (args: {
21
+ value?: string | number | null;
22
+ base?: number;
23
+ }) => number | undefined;
@@ -0,0 +1,43 @@
1
+ import isNil from 'lodash/isNil';
2
+ const isStringValueInPercent = (value = '') => {
3
+ return value.endsWith('%') && !Number.isNaN(Number.parseFloat(value));
4
+ };
5
+ const isStringValueInPixel = (value = '') => {
6
+ return value.endsWith('px') && !Number.isNaN(Number.parseFloat(value));
7
+ };
8
+ /**
9
+ * Calculates a numeric property based on the given arguments.
10
+ *
11
+ * @param {Object} args - The arguments for the calculation.
12
+ * @param {string | number | null} args.value - The value to calculate the property for.
13
+ * @param {number} args.base - The base value to use in the calculation.
14
+ * @return {number | undefined} The calculated numeric property, or undefined if the value is invalid.
15
+ * @example
16
+ * const result1 = calculateNumericProperty({value: 1});
17
+ * console.log(result1); // Output: 1
18
+ * const result2 = calculateNumericProperty({value: '10px'});
19
+ * console.log(result2); // Output: 10
20
+ * const result3 = calculateNumericProperty({value: '50%', base: 200});
21
+ * console.log(result3); // Output: 100
22
+ * const result4 = calculateNumericProperty({value: '50%'});
23
+ * console.log(result4); // Output: undefined
24
+ * const result5 = calculateNumericProperty({value: 'invalid_value'});
25
+ * console.log(result5); // Output: undefined
26
+ */
27
+ export const calculateNumericProperty = (args) => {
28
+ const { value = '', base } = args;
29
+ if (isNil(value)) {
30
+ return undefined;
31
+ }
32
+ if (typeof value === 'string') {
33
+ if (isStringValueInPercent(value) && typeof base === 'number') {
34
+ const fraction = Number.parseFloat(value) / 100;
35
+ return base * fraction;
36
+ }
37
+ if (isStringValueInPixel(value)) {
38
+ return Number.parseFloat(value);
39
+ }
40
+ return undefined;
41
+ }
42
+ return value;
43
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import Highcharts from 'highcharts';
3
- import HighchartsReact from 'highcharts-react-official';
3
+ import HighchartsReact from './HighchartsReact';
4
4
  import get from 'lodash/get';
5
5
  import { settings } from '../../../../libs';
6
6
  import { settingsEventEmitter } from '../../../../libs/settings/settings';
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import Highcharts from 'highcharts';
3
+ interface HighchartsReactRefObject {
4
+ chart: Highcharts.Chart | null | undefined;
5
+ container: React.RefObject<HTMLDivElement | undefined>;
6
+ }
7
+ interface HighchartsReactProps {
8
+ [key: string]: any;
9
+ constructorType?: keyof typeof Highcharts;
10
+ containerProps?: {
11
+ [key: string]: any;
12
+ };
13
+ highcharts?: typeof Highcharts;
14
+ options: Highcharts.Options;
15
+ callback?: Highcharts.ChartCallbackFunction;
16
+ }
17
+ export declare const HighchartsReact: React.ForwardRefExoticComponent<React.PropsWithoutRef<HighchartsReactProps> & React.RefAttributes<HighchartsReactRefObject>>;
18
+ export default HighchartsReact;
@@ -0,0 +1,46 @@
1
+ /* eslint no-console: ["error", { allow: ["warn", "error"]}] */
2
+ import React from 'react';
3
+ const useIsomorphicLayoutEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
4
+ export const HighchartsReact = React.memo(React.forwardRef(function HighchartsReact(props, ref) {
5
+ const containerRef = React.useRef(null);
6
+ const chartRef = React.useRef();
7
+ useIsomorphicLayoutEffect(() => {
8
+ function createChart() {
9
+ const { highcharts: HighchartsComponent } = props;
10
+ const constructorType = props.constructorType || 'chart';
11
+ if (!HighchartsComponent) {
12
+ console.warn('The "highcharts" property was not passed.');
13
+ }
14
+ else if (!HighchartsComponent[constructorType]) {
15
+ console.warn('The "constructorType" property is incorrect or some ' +
16
+ 'required module is not imported.');
17
+ }
18
+ else if (props.options) {
19
+ chartRef.current = HighchartsComponent[constructorType](containerRef.current, props.options, props.callback);
20
+ }
21
+ else {
22
+ console.warn('The "options" property was not passed.');
23
+ }
24
+ }
25
+ if (!chartRef.current) {
26
+ createChart();
27
+ }
28
+ }, [props.options, props.allowChartUpdate, props.containerProps, props.highcharts, props.constructorType]);
29
+ useIsomorphicLayoutEffect(() => {
30
+ return () => {
31
+ if (chartRef.current) {
32
+ chartRef.current.destroy();
33
+ chartRef.current = null;
34
+ }
35
+ };
36
+ }, []);
37
+ React.useImperativeHandle(ref, () => ({
38
+ get chart() {
39
+ return chartRef.current;
40
+ },
41
+ container: containerRef,
42
+ }), []);
43
+ return React.createElement("div", Object.assign({}, props.containerProps, { ref: containerRef }));
44
+ }));
45
+ HighchartsReact.displayName = 'HighchartsReact';
46
+ export default HighchartsReact;
@@ -4,3 +4,4 @@ export { IndicatorPlugin } from './indicator';
4
4
  export type { IndicatorWidgetData } from './indicator/types';
5
5
  export { HighchartsPlugin } from './highcharts';
6
6
  export * from './highcharts/types';
7
+ export { HighchartsReact } from './highcharts/renderer/components/HighchartsReact';
@@ -3,3 +3,4 @@ export * from './yagr/types';
3
3
  export { IndicatorPlugin } from './indicator';
4
4
  export { HighchartsPlugin } from './highcharts';
5
5
  export * from './highcharts/types';
6
+ export { HighchartsReact } from './highcharts/renderer/components/HighchartsReact';
@@ -1,5 +1,6 @@
1
1
  import type { BaseSeries, BaseSeriesData } from './base';
2
2
  import type { ChartKitWidgetSeriesOptions } from './series';
3
+ import { ChartKitWidgetLegend, RectLegendSymbolOptions } from './legend';
3
4
  export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
4
5
  /** The x value of the point */
5
6
  x?: number;
@@ -11,7 +12,7 @@ export type BarXSeriesData<T = any> = BaseSeriesData<T> & {
11
12
  export type BarXSeries<T = any> = BaseSeries & {
12
13
  type: 'bar-x';
13
14
  data: BarXSeriesData<T>[];
14
- /** The name of the series (used in legend) */
15
+ /** The name of the series (used in legend, tooltip etc) */
15
16
  name: string;
16
17
  /** The main color of the series (hex, rgba) */
17
18
  color?: string;
@@ -28,4 +29,8 @@ export type BarXSeries<T = any> = BaseSeries & {
28
29
  /** Whether to align the data label inside the box or to the actual value point */
29
30
  inside?: boolean;
30
31
  };
32
+ /** Individual series legend options. Has higher priority than legend options in widget data */
33
+ legend?: ChartKitWidgetLegend & {
34
+ symbol?: RectLegendSymbolOptions;
35
+ };
31
36
  };
@@ -1,6 +1,18 @@
1
1
  export type BaseSeries = {
2
2
  /** Initial visibility of the series */
3
3
  visible?: boolean;
4
+ /**
5
+ * Options for the series data labels, appearing next to each data point.
6
+ *
7
+ * Note: now this option is supported only for `pie` charts.
8
+ * */
9
+ dataLabels?: {
10
+ /**
11
+ * Enable or disable the data labels
12
+ * @default true
13
+ */
14
+ enabled?: boolean;
15
+ };
4
16
  };
5
17
  export type BaseSeriesData<T = any> = {
6
18
  /**
@@ -1,3 +1,35 @@
1
1
  export type ChartKitWidgetLegend = {
2
2
  enabled?: boolean;
3
+ /** The horizontal alignment of the legend box within the chart area.
4
+ *
5
+ * @default center
6
+ * */
7
+ align?: 'left' | 'center' | 'right';
8
+ /** Defines the pixel distance between each legend item
9
+ *
10
+ * @default 20
11
+ * */
12
+ itemDistance?: number;
13
+ };
14
+ export type BaseLegendSymbol = {
15
+ /** The pixel padding between the legend item symbol and the legend item text.
16
+ *
17
+ * @default 5
18
+ * */
19
+ padding?: number;
20
+ };
21
+ export type RectLegendSymbolOptions = BaseLegendSymbol & {
22
+ /** The pixel width of the symbol for series types that use a rectangle in the legend
23
+ *
24
+ * @default 10
25
+ * */
26
+ width?: number;
27
+ /** The pixel width of the symbol for series types that use a rectangle in the legend
28
+ *
29
+ * @default 10
30
+ * */
31
+ height?: number;
32
+ /** The border radius of the symbol for series types that use a rectangle in the legend.
33
+ * Defaults to half the symbolHeight, effectively creating a circle. */
34
+ radius?: number;
3
35
  };
@@ -1,10 +1,46 @@
1
1
  import type { BaseSeries, BaseSeriesData } from './base';
2
+ import { ChartKitWidgetLegend, RectLegendSymbolOptions } from './legend';
2
3
  export type PieSeriesData<T = any> = BaseSeriesData<T> & {
4
+ /** The value of the pie segment. */
3
5
  value: number;
4
- color: string;
6
+ /** The name of the pie segment (used in legend, tooltip etc). */
5
7
  name: string;
8
+ /** Individual color for the pie segment. */
9
+ color?: string;
10
+ /** Initial visibility of the pie segment. */
11
+ visible?: boolean;
12
+ /** Initial data label of the pie segment. If not specified, the value is used. */
13
+ label?: string;
6
14
  };
7
15
  export type PieSeries<T = any> = BaseSeries & {
8
16
  type: 'pie';
9
17
  data: PieSeriesData<T>[];
18
+ /**
19
+ * The color of the border surrounding each segment.
20
+ * @default `--g-color-base-background` from @gravity-ui/uikit.
21
+ */
22
+ borderColor?: string;
23
+ /**
24
+ * The width of the border surrounding each segment.
25
+ * @default '1px'
26
+ */
27
+ borderWidth?: number;
28
+ /**
29
+ * The corner radius of the border surrounding each segment.
30
+ * @default 0
31
+ */
32
+ borderRadius?: number;
33
+ /** The center of the pie chart relative to the chart area. */
34
+ center?: [string | number | null, string | number | null];
35
+ /**
36
+ * The inner radius of the pie.
37
+ * @default 0
38
+ */
39
+ innerRadius?: string | number;
40
+ /** The radius of the pie relative to the chart area. The default behaviour is to scale to the chart area. */
41
+ radius?: string | number;
42
+ /** Individual series legend options. Has higher priority than legend options in widget data */
43
+ legend?: ChartKitWidgetLegend & {
44
+ symbol?: RectLegendSymbolOptions;
45
+ };
10
46
  };
@@ -1,4 +1,5 @@
1
1
  import type { BaseSeries, BaseSeriesData } from './base';
2
+ import type { ChartKitWidgetLegend, RectLegendSymbolOptions } from './legend';
2
3
  export type ScatterSeriesData<T = any> = BaseSeriesData<T> & {
3
4
  /** The x value of the point */
4
5
  x?: number;
@@ -11,10 +12,14 @@ export type ScatterSeriesData<T = any> = BaseSeriesData<T> & {
11
12
  export type ScatterSeries<T = any> = BaseSeries & {
12
13
  type: 'scatter';
13
14
  data: ScatterSeriesData<T>[];
14
- /** The name of the series (used in legend) */
15
+ /** The name of the series (used in legend, tooltip etc) */
15
16
  name: string;
16
17
  /** The main color of the series (hex, rgba) */
17
18
  color?: string;
18
19
  /** A predefined shape or symbol for the dot */
19
20
  symbol?: string;
21
+ /** Individual series legend options. Has higher priority than legend options in widget data */
22
+ legend?: ChartKitWidgetLegend & {
23
+ symbol?: RectLegendSymbolOptions;
24
+ };
20
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/chartkit",
3
- "version": "3.4.3",
3
+ "version": "3.6.0",
4
4
  "description": "React component used to render charts based on any sources you need",
5
5
  "license": "MIT",
6
6
  "repository": "git@github.com:gravity-ui/ChartKit.git",
@@ -54,7 +54,6 @@
54
54
  "gulp-replace": "^1.1.3",
55
55
  "gulp-typescript": "^5.0.1",
56
56
  "highcharts": "^8.2.2",
57
- "highcharts-react-official": "^3.2.0",
58
57
  "husky": "^4.2.5",
59
58
  "jest": "^28.1.3",
60
59
  "jest-environment-jsdom": "^28.1.2",
@@ -77,7 +76,6 @@
77
76
  "peerDependencies": {
78
77
  "@gravity-ui/uikit": "^5.0.0",
79
78
  "highcharts": "^8.2.2",
80
- "highcharts-react-official": "^3.2.0",
81
79
  "react": "^16.0.0 || ^17.0.0 || ^18.0.0"
82
80
  },
83
81
  "scripts": {
@@ -1,3 +0,0 @@
1
- export declare const DEFAULT_AXIS_LABEL_FONT_SIZE = "11px";
2
- export declare const DEFAULT_AXIS_LABEL_PADDING = 10;
3
- export declare const DEFAULT_AXIS_TITLE_FONT_SIZE = "14px";
@@ -1,3 +0,0 @@
1
- export const DEFAULT_AXIS_LABEL_FONT_SIZE = '11px';
2
- export const DEFAULT_AXIS_LABEL_PADDING = 10;
3
- export const DEFAULT_AXIS_TITLE_FONT_SIZE = '14px';
@@ -1,5 +0,0 @@
1
- import type { BaseTextStyle } from '../../../../../types/widget-data';
2
- export declare const getHorisontalSvgTextDimensions: (args: {
3
- text: string;
4
- style?: Partial<BaseTextStyle>;
5
- }) => number;
@@ -1,18 +0,0 @@
1
- import { select } from 'd3';
2
- import get from 'lodash/get';
3
- import { DEFAULT_AXIS_LABEL_FONT_SIZE } from './constants';
4
- export const getHorisontalSvgTextDimensions = (args) => {
5
- const { text, style } = args;
6
- const textSelection = select(document.body).append('text').text(text);
7
- const fontSize = get(style, 'fontSize', DEFAULT_AXIS_LABEL_FONT_SIZE);
8
- let height = 0;
9
- if (fontSize) {
10
- textSelection.style('font-size', fontSize);
11
- }
12
- textSelection
13
- .each(function () {
14
- height = this.getBoundingClientRect().height;
15
- })
16
- .remove();
17
- return height;
18
- };
@@ -1,13 +0,0 @@
1
- import type { ChartKitWidgetSeries } from '../../../../../types/widget-data';
2
- export type OnLegendItemClick = (data: {
3
- name: string;
4
- metaKey: boolean;
5
- }) => void;
6
- type Args = {
7
- series: ChartKitWidgetSeries[];
8
- };
9
- export declare const useLegend: (args: Args) => {
10
- activeLegendItems: string[];
11
- handleLegendItemClick: OnLegendItemClick;
12
- };
13
- export {};
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import { getVisibleSeriesNames } from '../../utils';
3
- export const useLegend = (args) => {
4
- const { series } = args;
5
- const [activeLegendItems, setActiveLegendItems] = React.useState(getVisibleSeriesNames(series));
6
- const handleLegendItemClick = React.useCallback(({ name, metaKey }) => {
7
- const onlyItemSelected = activeLegendItems.length === 1 && activeLegendItems.includes(name);
8
- let nextActiveLegendItems;
9
- if (metaKey && activeLegendItems.includes(name)) {
10
- nextActiveLegendItems = activeLegendItems.filter((item) => item !== name);
11
- }
12
- else if (metaKey && !activeLegendItems.includes(name)) {
13
- nextActiveLegendItems = activeLegendItems.concat(name);
14
- }
15
- else if (onlyItemSelected) {
16
- nextActiveLegendItems = getVisibleSeriesNames(series);
17
- }
18
- else {
19
- nextActiveLegendItems = [name];
20
- }
21
- setActiveLegendItems(nextActiveLegendItems);
22
- }, [series, activeLegendItems]);
23
- // FIXME: remove effect. It initiates extra rerender
24
- React.useEffect(() => {
25
- setActiveLegendItems(getVisibleSeriesNames(series));
26
- }, [series]);
27
- return { activeLegendItems, handleLegendItemClick };
28
- };