@gravity-ui/charts 1.15.0 → 1.17.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 (141) hide show
  1. package/dist/{esm/components/Axis → cjs/components/AxisX}/AxisX.js +1 -15
  2. package/dist/cjs/components/{Axis → AxisY}/AxisY.d.ts +2 -10
  3. package/dist/cjs/components/AxisY/AxisY.js +173 -0
  4. package/dist/cjs/components/AxisY/prepare-axis-data.d.ts +9 -0
  5. package/dist/cjs/components/AxisY/prepare-axis-data.js +306 -0
  6. package/dist/cjs/components/AxisY/styles.css +15 -0
  7. package/dist/cjs/components/AxisY/types.d.ts +81 -0
  8. package/dist/cjs/components/AxisY/types.js +1 -0
  9. package/dist/cjs/components/AxisY/utils.d.ts +12 -0
  10. package/dist/cjs/components/AxisY/utils.js +71 -0
  11. package/dist/cjs/components/ChartInner/index.js +31 -3
  12. package/dist/cjs/components/ChartInner/useChartInnerProps.js +13 -1
  13. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +4 -2
  14. package/dist/cjs/components/Tooltip/ChartTooltipContent.js +2 -2
  15. package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
  16. package/dist/cjs/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
  17. package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
  18. package/dist/cjs/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
  19. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
  20. package/dist/cjs/components/Tooltip/DefaultTooltipContent/index.js +174 -114
  21. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.d.ts +7 -1
  22. package/dist/cjs/components/Tooltip/DefaultTooltipContent/utils.js +12 -7
  23. package/dist/cjs/components/Tooltip/index.js +1 -1
  24. package/dist/cjs/components/Tooltip/styles.css +11 -1
  25. package/dist/cjs/constants/date.d.ts +1 -0
  26. package/dist/cjs/constants/date.js +1 -0
  27. package/dist/cjs/constants/index.d.ts +1 -0
  28. package/dist/cjs/constants/index.js +1 -0
  29. package/dist/cjs/hooks/useChartOptions/types.d.ts +7 -1
  30. package/dist/cjs/hooks/useChartOptions/x-axis.js +5 -5
  31. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -1
  32. package/dist/cjs/hooks/useChartOptions/y-axis.js +20 -20
  33. package/dist/cjs/hooks/useCrosshair/index.js +2 -1
  34. package/dist/cjs/hooks/useSeries/prepare-area.js +1 -0
  35. package/dist/cjs/hooks/useSeries/prepare-bar-x.js +1 -0
  36. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +1 -0
  37. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +1 -0
  38. package/dist/cjs/hooks/useSeries/prepare-line.js +1 -0
  39. package/dist/cjs/hooks/useSeries/prepare-pie.js +1 -0
  40. package/dist/cjs/hooks/useSeries/prepare-radar.js +1 -0
  41. package/dist/cjs/hooks/useSeries/prepare-sankey.js +1 -0
  42. package/dist/cjs/hooks/useSeries/prepare-scatter.js +1 -0
  43. package/dist/cjs/hooks/useSeries/prepare-treemap.js +1 -0
  44. package/dist/cjs/hooks/useSeries/prepare-waterfall.js +1 -0
  45. package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
  46. package/dist/cjs/i18n/keysets/en.json +2 -1
  47. package/dist/cjs/i18n/keysets/ru.json +2 -1
  48. package/dist/cjs/index.d.ts +1 -1
  49. package/dist/cjs/index.js +1 -1
  50. package/dist/cjs/types/chart/axis.d.ts +11 -1
  51. package/dist/cjs/types/chart/base.d.ts +14 -0
  52. package/dist/cjs/types/chart/tooltip.d.ts +5 -1
  53. package/dist/cjs/utils/chart/axis-generators/bottom.js +3 -3
  54. package/dist/cjs/utils/chart/axis.d.ts +14 -8
  55. package/dist/cjs/utils/chart/axis.js +34 -9
  56. package/dist/cjs/utils/chart/format.d.ts +9 -2
  57. package/dist/cjs/utils/chart/format.js +40 -5
  58. package/dist/cjs/utils/chart/index.d.ts +6 -17
  59. package/dist/cjs/utils/chart/index.js +6 -43
  60. package/dist/cjs/utils/chart/text.d.ts +2 -1
  61. package/dist/cjs/utils/chart/text.js +3 -10
  62. package/dist/cjs/utils/misc.d.ts +1 -0
  63. package/dist/cjs/utils/misc.js +6 -0
  64. package/dist/{cjs/components/Axis → esm/components/AxisX}/AxisX.js +1 -15
  65. package/dist/esm/components/{Axis → AxisY}/AxisY.d.ts +2 -10
  66. package/dist/esm/components/AxisY/AxisY.js +173 -0
  67. package/dist/esm/components/AxisY/prepare-axis-data.d.ts +9 -0
  68. package/dist/esm/components/AxisY/prepare-axis-data.js +306 -0
  69. package/dist/esm/components/AxisY/styles.css +15 -0
  70. package/dist/esm/components/AxisY/types.d.ts +81 -0
  71. package/dist/esm/components/AxisY/types.js +1 -0
  72. package/dist/esm/components/AxisY/utils.d.ts +12 -0
  73. package/dist/esm/components/AxisY/utils.js +71 -0
  74. package/dist/esm/components/ChartInner/index.js +31 -3
  75. package/dist/esm/components/ChartInner/useChartInnerProps.js +13 -1
  76. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +4 -2
  77. package/dist/esm/components/Tooltip/ChartTooltipContent.js +2 -2
  78. package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.d.ts +2 -1
  79. package/dist/esm/components/Tooltip/DefaultTooltipContent/Row.js +3 -3
  80. package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.d.ts → RowWithAggregation.d.ts} +2 -1
  81. package/dist/esm/components/Tooltip/DefaultTooltipContent/{RowTotals.js → RowWithAggregation.js} +3 -3
  82. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.d.ts +4 -2
  83. package/dist/esm/components/Tooltip/DefaultTooltipContent/index.js +174 -114
  84. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.d.ts +7 -1
  85. package/dist/esm/components/Tooltip/DefaultTooltipContent/utils.js +12 -7
  86. package/dist/esm/components/Tooltip/index.js +1 -1
  87. package/dist/esm/components/Tooltip/styles.css +11 -1
  88. package/dist/esm/constants/date.d.ts +1 -0
  89. package/dist/esm/constants/date.js +1 -0
  90. package/dist/esm/constants/index.d.ts +1 -0
  91. package/dist/esm/constants/index.js +1 -0
  92. package/dist/esm/hooks/useChartOptions/types.d.ts +7 -1
  93. package/dist/esm/hooks/useChartOptions/x-axis.js +5 -5
  94. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -1
  95. package/dist/esm/hooks/useChartOptions/y-axis.js +20 -20
  96. package/dist/esm/hooks/useCrosshair/index.js +2 -1
  97. package/dist/esm/hooks/useSeries/prepare-area.js +1 -0
  98. package/dist/esm/hooks/useSeries/prepare-bar-x.js +1 -0
  99. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +1 -0
  100. package/dist/esm/hooks/useSeries/prepare-bar-y.js +1 -0
  101. package/dist/esm/hooks/useSeries/prepare-line.js +1 -0
  102. package/dist/esm/hooks/useSeries/prepare-pie.js +1 -0
  103. package/dist/esm/hooks/useSeries/prepare-radar.js +1 -0
  104. package/dist/esm/hooks/useSeries/prepare-sankey.js +1 -0
  105. package/dist/esm/hooks/useSeries/prepare-scatter.js +1 -0
  106. package/dist/esm/hooks/useSeries/prepare-treemap.js +1 -0
  107. package/dist/esm/hooks/useSeries/prepare-waterfall.js +1 -0
  108. package/dist/esm/hooks/useSeries/types.d.ts +2 -1
  109. package/dist/esm/i18n/keysets/en.json +2 -1
  110. package/dist/esm/i18n/keysets/ru.json +2 -1
  111. package/dist/esm/index.d.ts +1 -1
  112. package/dist/esm/index.js +1 -1
  113. package/dist/esm/types/chart/axis.d.ts +11 -1
  114. package/dist/esm/types/chart/base.d.ts +14 -0
  115. package/dist/esm/types/chart/tooltip.d.ts +5 -1
  116. package/dist/esm/utils/chart/axis-generators/bottom.js +3 -3
  117. package/dist/esm/utils/chart/axis.d.ts +14 -8
  118. package/dist/esm/utils/chart/axis.js +34 -9
  119. package/dist/esm/utils/chart/format.d.ts +9 -2
  120. package/dist/esm/utils/chart/format.js +40 -5
  121. package/dist/esm/utils/chart/index.d.ts +6 -17
  122. package/dist/esm/utils/chart/index.js +6 -43
  123. package/dist/esm/utils/chart/text.d.ts +2 -1
  124. package/dist/esm/utils/chart/text.js +3 -10
  125. package/dist/esm/utils/misc.d.ts +1 -0
  126. package/dist/esm/utils/misc.js +6 -0
  127. package/package.json +1 -1
  128. package/dist/cjs/components/Axis/AxisY.js +0 -416
  129. package/dist/cjs/components/Axis/index.d.ts +0 -2
  130. package/dist/cjs/components/Axis/index.js +0 -2
  131. package/dist/cjs/components/Tooltip/utils.d.ts +0 -30
  132. package/dist/cjs/components/Tooltip/utils.js +0 -126
  133. package/dist/esm/components/Axis/AxisY.js +0 -416
  134. package/dist/esm/components/Axis/index.d.ts +0 -2
  135. package/dist/esm/components/Axis/index.js +0 -2
  136. package/dist/esm/components/Tooltip/utils.d.ts +0 -30
  137. package/dist/esm/components/Tooltip/utils.js +0 -126
  138. /package/dist/cjs/components/{Axis → AxisX}/AxisX.d.ts +0 -0
  139. /package/dist/cjs/components/{Axis → AxisX}/styles.css +0 -0
  140. /package/dist/esm/components/{Axis → AxisX}/AxisX.d.ts +0 -0
  141. /package/dist/esm/components/{Axis → AxisX}/styles.css +0 -0
@@ -1,5 +1,12 @@
1
- import type { ValueFormat } from '../../types';
1
+ import type { AxisDomain } from 'd3';
2
+ import type { PreparedAxis } from '../../hooks';
3
+ import type { CustomFormat, ValueFormat } from '../../types';
2
4
  export declare function getFormattedValue(args: {
3
5
  value: string | number | undefined | null;
4
- format?: ValueFormat;
6
+ format?: ValueFormat | CustomFormat;
7
+ }): string;
8
+ export declare function formatAxisTickLabel(args: {
9
+ axis: PreparedAxis;
10
+ value: AxisDomain;
11
+ step?: number;
5
12
  }): string;
@@ -1,17 +1,52 @@
1
1
  import { dateTime } from '@gravity-ui/date-utils';
2
- import { formatNumber } from '../../libs';
2
+ import capitalize from 'lodash/capitalize';
3
+ import { DEFAULT_DATE_FORMAT } from '../../constants';
4
+ import { formatNumber, getDefaultUnit } from '../../libs';
5
+ import { getDefaultDateFormat } from './time';
6
+ const LETTER_MOUNTH_AT_START_FORMAT_REGEXP = /^M{3,}/;
7
+ function getFormattedDate(args) {
8
+ const { value, format = DEFAULT_DATE_FORMAT } = args;
9
+ const date = dateTime({ input: value });
10
+ if (date === null || date === void 0 ? void 0 : date.isValid()) {
11
+ const formattedDate = date.format(format);
12
+ if (LETTER_MOUNTH_AT_START_FORMAT_REGEXP.test(format)) {
13
+ return capitalize(formattedDate);
14
+ }
15
+ return formattedDate;
16
+ }
17
+ return String(value);
18
+ }
3
19
  export function getFormattedValue(args) {
20
+ var _a;
4
21
  const { value, format } = args;
5
22
  switch (format === null || format === void 0 ? void 0 : format.type) {
6
23
  case 'number': {
7
24
  return formatNumber(Number(value), format);
8
25
  }
9
26
  case 'date': {
10
- const date = dateTime({ input: value });
11
- if (date === null || date === void 0 ? void 0 : date.isValid()) {
12
- return date.format(format.format);
13
- }
27
+ return getFormattedDate({ value, format: format.format });
28
+ }
29
+ case 'custom': {
30
+ return (_a = format.formatter) === null || _a === void 0 ? void 0 : _a.call(format, { value });
14
31
  }
15
32
  }
16
33
  return String(value);
17
34
  }
35
+ export function formatAxisTickLabel(args) {
36
+ const { axis, value, step } = args;
37
+ switch (axis.type) {
38
+ case 'category': {
39
+ return value;
40
+ }
41
+ case 'datetime': {
42
+ const date = value;
43
+ const format = axis.labels.dateFormat || getDefaultDateFormat(step);
44
+ return getFormattedDate({ value: date, format });
45
+ }
46
+ case 'linear':
47
+ default: {
48
+ const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
49
+ return formatNumber(value, numberFormat);
50
+ }
51
+ }
52
+ }
@@ -1,16 +1,15 @@
1
- import type { AxisDomain } from 'd3';
2
- import type { PreparedAxis } from '../../hooks';
3
1
  import type { BaseTextStyle, ChartSeries, ChartSeriesData } from '../../types';
4
2
  import type { AxisDirection } from './types';
5
- export * from './math';
6
- export * from './text';
7
- export * from './time';
8
3
  export * from './axis';
4
+ export * from './color';
5
+ export * from './format';
9
6
  export * from './labels';
10
7
  export * from './legend';
11
- export * from './symbol';
8
+ export * from './math';
12
9
  export * from './series';
13
- export * from './color';
10
+ export * from './symbol';
11
+ export * from './text';
12
+ export * from './time';
14
13
  export * from './zoom';
15
14
  export declare const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS: ChartSeries['type'][];
16
15
  export declare const CHART_SERIES_WITH_VOLUME_ON_X_AXIS: ChartSeries['type'][];
@@ -52,15 +51,6 @@ export declare const getSeriesNames: (series: ChartSeries[]) => string[];
52
51
  export declare const getOnlyVisibleSeries: <T extends {
53
52
  visible: boolean;
54
53
  }>(series: T[]) => T[];
55
- export declare const parseTransformStyle: (style: string | null) => {
56
- x?: number;
57
- y?: number;
58
- };
59
- export declare const formatAxisTickLabel: (args: {
60
- axis: PreparedAxis;
61
- value: AxisDomain;
62
- step?: number;
63
- }) => string;
64
54
  export declare const getHorizontalHtmlTextHeight: (args: {
65
55
  text: string;
66
56
  style?: Partial<BaseTextStyle>;
@@ -74,5 +64,4 @@ export declare const getDataCategoryValue: (args: {
74
64
  categories: string[];
75
65
  data: ChartSeriesData;
76
66
  }) => string;
77
- export declare function getClosestPointsRange(axis: PreparedAxis, points: AxisDomain[]): number | undefined;
78
67
  export { AxisDirection };
@@ -1,22 +1,20 @@
1
- import { dateTime } from '@gravity-ui/date-utils';
2
1
  import { group, select } from 'd3';
3
2
  import get from 'lodash/get';
4
3
  import isNil from 'lodash/isNil';
5
4
  import sortBy from 'lodash/sortBy';
6
5
  import { DEFAULT_AXIS_LABEL_FONT_SIZE } from '../../constants';
7
6
  import { getSeriesStackId } from '../../hooks/useSeries/utils';
8
- import { formatNumber, getDefaultUnit } from '../../libs/format-number';
9
7
  import { getWaterfallPointSubtotal } from './series/waterfall';
10
- import { getDefaultDateFormat } from './time';
11
- export * from './math';
12
- export * from './text';
13
- export * from './time';
14
8
  export * from './axis';
9
+ export * from './color';
10
+ export * from './format';
15
11
  export * from './labels';
16
12
  export * from './legend';
17
- export * from './symbol';
13
+ export * from './math';
18
14
  export * from './series';
19
- export * from './color';
15
+ export * from './symbol';
16
+ export * from './text';
17
+ export * from './time';
20
18
  export * from './zoom';
21
19
  const CHARTS_WITHOUT_AXIS = ['pie', 'treemap', 'sankey', 'radar'];
22
20
  export const CHART_SERIES_WITH_VOLUME_ON_Y_AXIS = [
@@ -166,35 +164,6 @@ export const getSeriesNames = (series) => {
166
164
  export const getOnlyVisibleSeries = (series) => {
167
165
  return series.filter((s) => s.visible);
168
166
  };
169
- export const parseTransformStyle = (style) => {
170
- var _a;
171
- if (!style) {
172
- return {};
173
- }
174
- const stringifiedValue = ((_a = style.match(/\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
175
- const [xString, yString] = stringifiedValue.split(',');
176
- const x = Number.isNaN(Number(xString)) ? undefined : Number(xString);
177
- const y = Number.isNaN(Number(yString)) ? undefined : Number(yString);
178
- return { x, y };
179
- };
180
- export const formatAxisTickLabel = (args) => {
181
- const { axis, value, step } = args;
182
- switch (axis.type) {
183
- case 'category': {
184
- return value;
185
- }
186
- case 'datetime': {
187
- const date = value;
188
- const format = axis.labels.dateFormat || getDefaultDateFormat(step);
189
- return dateTime({ input: date }).format(format);
190
- }
191
- case 'linear':
192
- default: {
193
- const numberFormat = Object.assign({ unit: value && step ? getDefaultUnit(step) : undefined }, axis.labels.numberFormat);
194
- return formatNumber(value, numberFormat);
195
- }
196
- }
197
- };
198
167
  export const getHorizontalHtmlTextHeight = (args) => {
199
168
  var _a;
200
169
  const { text, style } = args;
@@ -248,9 +217,3 @@ export const getDataCategoryValue = (args) => {
248
217
  const categoryValue = extractCategoryValue({ axisDirection, categories, data });
249
218
  return categoryValue;
250
219
  };
251
- export function getClosestPointsRange(axis, points) {
252
- if (axis.type === 'category') {
253
- return undefined;
254
- }
255
- return Math.abs(points[1] - points[0]);
256
- }
@@ -26,9 +26,10 @@ export declare function wrapText(args: {
26
26
  text: string;
27
27
  style?: BaseTextStyle;
28
28
  width: number;
29
+ getTextSize?: ReturnType<typeof getTextSizeFn>;
29
30
  }): Promise<TextRow[]>;
30
31
  export declare function getTextSizeFn({ style }: {
31
- style: BaseTextStyle;
32
+ style?: BaseTextStyle;
32
33
  }): (str: string) => Promise<{
33
34
  width: number;
34
35
  height: number;
@@ -144,11 +144,8 @@ export async function getLabelsSize({ labels, style, rotation, html, }) {
144
144
  return result;
145
145
  }
146
146
  export async function wrapText(args) {
147
- const { text, style, width } = args;
148
- const height = (await getLabelsSize({
149
- labels: [text],
150
- style: style,
151
- })).maxHeight;
147
+ const { text, style, width, getTextSize = getTextSizeFn({ style }) } = args;
148
+ const height = (await getTextSize(text)).height;
152
149
  // @ts-ignore
153
150
  const segmenter = new Intl.Segmenter([], { granularity: 'word' });
154
151
  const segments = Array.from(segmenter.segment(text));
@@ -163,11 +160,7 @@ export async function wrapText(args) {
163
160
  });
164
161
  }
165
162
  let lastRow = acc[acc.length - 1];
166
- if (item.isWordLike &&
167
- (await getLabelsSize({
168
- labels: [lastRow.text + item.segment],
169
- style,
170
- })).maxWidth > width) {
163
+ if (item.isWordLike && (await getTextSize(lastRow.text + item.segment)).width > width) {
171
164
  lastRow = {
172
165
  text: '',
173
166
  y: acc.length * height,
@@ -11,3 +11,4 @@ export declare function isMacintosh(): boolean;
11
11
  export declare function measurePerformance(): {
12
12
  end(): number;
13
13
  };
14
+ export declare function hasVerticalScrollbar(node: HTMLElement | null): boolean;
@@ -26,3 +26,9 @@ export function measurePerformance() {
26
26
  },
27
27
  };
28
28
  }
29
+ export function hasVerticalScrollbar(node) {
30
+ if (!node) {
31
+ return false;
32
+ }
33
+ return node.scrollHeight > node.clientHeight;
34
+ }
@@ -1,23 +1,9 @@
1
1
  import React from 'react';
2
2
  import { line, select } from 'd3';
3
- import { block, formatAxisTickLabel, getAxisTitleRows, getBandsPosition, getClosestPointsRange, getLineDashArray, getMaxTickCount, getScaleTicks, getTicksCount, handleOverflowingText, } from '../../utils';
3
+ import { block, getAxisTitleRows, getBandsPosition, getLabelFormatter, getLineDashArray, getMaxTickCount, getTicksCount, handleOverflowingText, } from '../../utils';
4
4
  import { axisBottom } from '../../utils/chart/axis-generators';
5
5
  import './styles.css';
6
6
  const b = block('axis');
7
- function getLabelFormatter({ axis, scale }) {
8
- const ticks = getScaleTicks(scale);
9
- const tickStep = getClosestPointsRange(axis, ticks);
10
- return (value) => {
11
- if (!axis.labels.enabled) {
12
- return '';
13
- }
14
- return formatAxisTickLabel({
15
- axis,
16
- value,
17
- step: tickStep,
18
- });
19
- };
20
- }
21
7
  export function getTitlePosition(args) {
22
8
  const { axis, width, rowCount } = args;
23
9
  if (rowCount < 1) {
@@ -1,19 +1,11 @@
1
1
  import React from 'react';
2
- import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
2
+ import type { AxisYData } from './types';
3
3
  import './styles.css';
4
4
  interface Props {
5
- axes: PreparedAxis[];
6
- boundsOffsetTop: number;
7
- boundsOffsetLeft: number;
8
- scale: ChartScale[];
9
- width: number;
10
- height: number;
5
+ preparedAxisData: AxisYData;
11
6
  htmlLayout: HTMLElement | null;
12
- split: PreparedSplit;
13
7
  plotBeforeRef?: React.MutableRefObject<SVGGElement | null>;
14
8
  plotAfterRef?: React.MutableRefObject<SVGGElement | null>;
15
- bottomLimit?: number;
16
- topLimit?: number;
17
9
  }
18
10
  export declare const AxisY: (props: Props) => React.JSX.Element;
19
11
  export {};
@@ -0,0 +1,173 @@
1
+ import React from 'react';
2
+ import { line, select } from 'd3';
3
+ import { HtmlLayer } from '../../hooks/useShapes/HtmlLayer';
4
+ import { block, getLineDashArray } from '../../utils';
5
+ import './styles.css';
6
+ const b = block('y-axis');
7
+ export const AxisY = (props) => {
8
+ const { htmlLayout, plotBeforeRef, plotAfterRef, preparedAxisData } = props;
9
+ const ref = React.useRef(null);
10
+ const lineGenerator = line();
11
+ const htmlLabels = preparedAxisData.ticks.map((d) => d.htmlLabel).filter(Boolean);
12
+ React.useEffect(() => {
13
+ if (!ref.current) {
14
+ return;
15
+ }
16
+ const svgElement = select(ref.current);
17
+ svgElement.selectAll('*').remove();
18
+ let plotBeforeContainer = null;
19
+ let plotAfterContainer = null;
20
+ const plotDataAttr = 'data-plot-y';
21
+ if (plotBeforeRef === null || plotBeforeRef === void 0 ? void 0 : plotBeforeRef.current) {
22
+ plotBeforeContainer = select(plotBeforeRef.current);
23
+ plotBeforeContainer.selectAll(`[${plotDataAttr}]`).remove();
24
+ }
25
+ if (plotAfterRef === null || plotAfterRef === void 0 ? void 0 : plotAfterRef.current) {
26
+ plotAfterContainer = select(plotAfterRef.current);
27
+ plotAfterContainer.selectAll(`[${plotDataAttr}]`).remove();
28
+ }
29
+ if (preparedAxisData.title) {
30
+ svgElement
31
+ .append('g')
32
+ .attr('class', b('title'))
33
+ .append('text')
34
+ .attr('text-anchor', 'start')
35
+ .style('dominant-baseline', 'text-after-edge')
36
+ .style('transform', `translate(${preparedAxisData.title.x}px, ${preparedAxisData.title.y}px) rotate(${preparedAxisData.title.rotate}deg) translate(0px, ${preparedAxisData.title.offset}px)`)
37
+ .attr('font-size', preparedAxisData.title.style.fontSize)
38
+ .selectAll('tspan')
39
+ .data(preparedAxisData.title.content)
40
+ .join('tspan')
41
+ .html((d) => d.text)
42
+ .attr('x', (d) => d.x)
43
+ .attr('y', (d) => d.y)
44
+ .attr('text-anchor', 'start');
45
+ }
46
+ svgElement
47
+ .append('path')
48
+ .attr('class', b('domain'))
49
+ .attr('d', lineGenerator([preparedAxisData.domain.start, preparedAxisData.domain.end]))
50
+ .style('stroke', preparedAxisData.domain.lineColor);
51
+ const tickClassName = b('tick');
52
+ const ticks = svgElement
53
+ .selectAll(`.${tickClassName}`)
54
+ .remove()
55
+ .data(preparedAxisData.ticks)
56
+ .join('g')
57
+ .attr('class', tickClassName);
58
+ const labelClassName = b('label');
59
+ ticks.each(function () {
60
+ var _a;
61
+ const tickSelection = select(this);
62
+ const tickData = tickSelection.datum();
63
+ if (tickData.line) {
64
+ tickSelection.append('path').attr('d', lineGenerator(tickData.line.points));
65
+ }
66
+ if (tickData.svgLabel) {
67
+ const label = tickData.svgLabel;
68
+ const textSelection = tickSelection.append('text');
69
+ if (label.title) {
70
+ textSelection.append('title').html(label.title);
71
+ }
72
+ textSelection
73
+ .selectAll('tspan')
74
+ .data(label.content)
75
+ .join('tspan')
76
+ .html((d) => d.text)
77
+ .attr('x', (d) => d.x)
78
+ .attr('y', (d) => d.y)
79
+ .attr('text-anchor', 'start')
80
+ .attr('class', labelClassName)
81
+ .style('dominant-baseline', 'text-before-edge')
82
+ .style('font-size', label.style.fontSize)
83
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '');
84
+ }
85
+ });
86
+ if (preparedAxisData.plotBands.length > 0) {
87
+ const plotBandDataAttr = `data-plot-y-band-${preparedAxisData.id}`;
88
+ const setPlotBands = (plotContainer, plotBands) => {
89
+ if (!plotContainer || !plotBands.length) {
90
+ return;
91
+ }
92
+ const plotBandsSelection = plotContainer
93
+ .selectAll(`[${plotBandDataAttr}]`)
94
+ .remove()
95
+ .data(plotBands)
96
+ .join('g')
97
+ .attr(plotDataAttr, 1)
98
+ .attr(plotBandDataAttr, 1)
99
+ .style('transform', (d) => `translate(${d.x}px, ${d.y}px)`);
100
+ plotBandsSelection
101
+ .append('rect')
102
+ .attr('width', (d) => d.width)
103
+ .attr('height', (d) => d.height)
104
+ .attr('fill', (d) => d.color)
105
+ .attr('opacity', (d) => d.opacity);
106
+ plotBandsSelection.each(function () {
107
+ var _a, _b;
108
+ const plotBandSelection = select(this);
109
+ const band = plotBandSelection.datum();
110
+ const label = band.label;
111
+ if (label) {
112
+ plotBandSelection
113
+ .append('text')
114
+ .html(label.text)
115
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
116
+ .style('font-size', label.style.fontSize)
117
+ .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
118
+ .style('dominant-baseline', 'text-before-edge')
119
+ .attr('x', label.x)
120
+ .attr('y', label.y);
121
+ }
122
+ });
123
+ };
124
+ setPlotBands(plotBeforeContainer, preparedAxisData.plotBands.filter((item) => item.layerPlacement === 'before'));
125
+ setPlotBands(plotAfterContainer, preparedAxisData.plotBands.filter((item) => item.layerPlacement === 'after'));
126
+ }
127
+ if (preparedAxisData.plotLines.length > 0) {
128
+ const plotLineDataAttr = `data-plot-y-line-${preparedAxisData.id}`;
129
+ const setPlotLines = (plotContainer, plotLines) => {
130
+ if (!plotContainer || !plotLines.length) {
131
+ return;
132
+ }
133
+ const plotLinesSelection = plotContainer
134
+ .selectAll(`[${plotLineDataAttr}]`)
135
+ .remove()
136
+ .data(plotLines)
137
+ .join('g')
138
+ .attr(plotDataAttr, 1)
139
+ .attr(plotLineDataAttr, 1)
140
+ .style('transform', (d) => `translate(${d.x}px, ${d.y}px)`);
141
+ plotLinesSelection
142
+ .append('path')
143
+ .attr('d', (d) => lineGenerator(d.points))
144
+ .attr('stroke', (d) => d.color)
145
+ .attr('stroke-width', (d) => d.lineWidth)
146
+ .attr('stroke-dasharray', (d) => getLineDashArray(d.dashStyle, d.lineWidth))
147
+ .attr('opacity', (d) => d.opacity);
148
+ plotLinesSelection.each(function () {
149
+ var _a, _b;
150
+ const itemSelection = select(this);
151
+ const plotLine = itemSelection.datum();
152
+ const label = plotLine.label;
153
+ if (label) {
154
+ itemSelection
155
+ .append('text')
156
+ .text(label.text)
157
+ .style('fill', (_a = label.style.fontColor) !== null && _a !== void 0 ? _a : '')
158
+ .style('font-size', label.style.fontSize)
159
+ .style('font-weight', (_b = label.style.fontWeight) !== null && _b !== void 0 ? _b : '')
160
+ .style('dominant-baseline', 'text-before-edge')
161
+ .attr('x', label.x)
162
+ .attr('y', label.y);
163
+ }
164
+ });
165
+ };
166
+ setPlotLines(plotBeforeContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'before'));
167
+ setPlotLines(plotAfterContainer, preparedAxisData.plotLines.filter((item) => item.layerPlacement === 'after'));
168
+ }
169
+ }, [lineGenerator, plotAfterRef, plotBeforeRef, preparedAxisData]);
170
+ return (React.createElement(React.Fragment, null,
171
+ React.createElement(HtmlLayer, { preparedData: { htmlElements: htmlLabels }, htmlLayout: htmlLayout }),
172
+ React.createElement("g", { ref: ref, className: b() })));
173
+ };
@@ -0,0 +1,9 @@
1
+ import type { ChartScale, PreparedAxis, PreparedSplit } from '../../hooks';
2
+ import type { AxisYData } from './types';
3
+ export declare function prepareAxisData({ axis, split, scale, width, height, }: {
4
+ axis: PreparedAxis;
5
+ split: PreparedSplit;
6
+ scale: ChartScale;
7
+ width: number;
8
+ height: number;
9
+ }): Promise<AxisYData>;