@gravity-ui/charts 1.8.0 → 1.9.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 (83) hide show
  1. package/dist/cjs/components/Axis/AxisX.js +10 -8
  2. package/dist/cjs/components/Axis/AxisY.js +16 -36
  3. package/dist/cjs/components/ChartInner/index.js +14 -0
  4. package/dist/cjs/components/ChartInner/useChartInnerProps.js +4 -1
  5. package/dist/cjs/components/Legend/index.js +10 -2
  6. package/dist/cjs/components/Legend/styles.css +2 -0
  7. package/dist/cjs/constants/chart-types.d.ts +12 -0
  8. package/dist/cjs/constants/chart-types.js +12 -0
  9. package/dist/cjs/constants/defaults/axis.d.ts +3 -1
  10. package/dist/cjs/constants/defaults/axis.js +10 -0
  11. package/dist/cjs/constants/index.d.ts +6 -47
  12. package/dist/cjs/constants/index.js +6 -72
  13. package/dist/cjs/constants/layout-algorithms.d.ts +7 -0
  14. package/dist/cjs/constants/layout-algorithms.js +8 -0
  15. package/dist/cjs/constants/line-styles.d.ts +20 -0
  16. package/dist/cjs/constants/line-styles.js +20 -0
  17. package/dist/cjs/constants/palette.d.ts +1 -0
  18. package/dist/cjs/constants/palette.js +22 -0
  19. package/dist/cjs/constants/symbol-types.d.ts +7 -0
  20. package/dist/cjs/constants/symbol-types.js +8 -0
  21. package/dist/cjs/constants/typography.d.ts +1 -0
  22. package/dist/cjs/constants/typography.js +1 -0
  23. package/dist/cjs/hooks/index.d.ts +1 -0
  24. package/dist/cjs/hooks/index.js +1 -0
  25. package/dist/cjs/hooks/useChartOptions/types.d.ts +4 -2
  26. package/dist/cjs/hooks/useChartOptions/x-axis.js +11 -2
  27. package/dist/cjs/hooks/useChartOptions/y-axis.js +14 -3
  28. package/dist/cjs/hooks/useCrosshair/index.d.ts +17 -0
  29. package/dist/cjs/hooks/useCrosshair/index.js +139 -0
  30. package/dist/cjs/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
  31. package/dist/cjs/hooks/useCrosshair/useCrosshairHover.js +18 -0
  32. package/dist/cjs/hooks/useSeries/prepare-legend.js +21 -4
  33. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -2
  34. package/dist/cjs/hooks/useSeries/prepare-line.js +3 -3
  35. package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
  36. package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
  37. package/dist/cjs/types/chart/axis.d.ts +26 -21
  38. package/dist/cjs/types/chart/line.d.ts +1 -1
  39. package/dist/cjs/types/chart/series.d.ts +1 -1
  40. package/dist/cjs/utils/chart/axis.d.ts +1 -0
  41. package/dist/cjs/utils/chart/axis.js +8 -0
  42. package/dist/esm/components/Axis/AxisX.js +10 -8
  43. package/dist/esm/components/Axis/AxisY.js +16 -36
  44. package/dist/esm/components/ChartInner/index.js +14 -0
  45. package/dist/esm/components/ChartInner/useChartInnerProps.js +4 -1
  46. package/dist/esm/components/Legend/index.js +10 -2
  47. package/dist/esm/components/Legend/styles.css +2 -0
  48. package/dist/esm/constants/chart-types.d.ts +12 -0
  49. package/dist/esm/constants/chart-types.js +12 -0
  50. package/dist/esm/constants/defaults/axis.d.ts +3 -1
  51. package/dist/esm/constants/defaults/axis.js +10 -0
  52. package/dist/esm/constants/index.d.ts +6 -47
  53. package/dist/esm/constants/index.js +6 -72
  54. package/dist/esm/constants/layout-algorithms.d.ts +7 -0
  55. package/dist/esm/constants/layout-algorithms.js +8 -0
  56. package/dist/esm/constants/line-styles.d.ts +20 -0
  57. package/dist/esm/constants/line-styles.js +20 -0
  58. package/dist/esm/constants/palette.d.ts +1 -0
  59. package/dist/esm/constants/palette.js +22 -0
  60. package/dist/esm/constants/symbol-types.d.ts +7 -0
  61. package/dist/esm/constants/symbol-types.js +8 -0
  62. package/dist/esm/constants/typography.d.ts +1 -0
  63. package/dist/esm/constants/typography.js +1 -0
  64. package/dist/esm/hooks/index.d.ts +1 -0
  65. package/dist/esm/hooks/index.js +1 -0
  66. package/dist/esm/hooks/useChartOptions/types.d.ts +4 -2
  67. package/dist/esm/hooks/useChartOptions/x-axis.js +11 -2
  68. package/dist/esm/hooks/useChartOptions/y-axis.js +14 -3
  69. package/dist/esm/hooks/useCrosshair/index.d.ts +17 -0
  70. package/dist/esm/hooks/useCrosshair/index.js +139 -0
  71. package/dist/esm/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
  72. package/dist/esm/hooks/useCrosshair/useCrosshairHover.js +18 -0
  73. package/dist/esm/hooks/useSeries/prepare-legend.js +21 -4
  74. package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -2
  75. package/dist/esm/hooks/useSeries/prepare-line.js +3 -3
  76. package/dist/esm/hooks/useSeries/types.d.ts +2 -1
  77. package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
  78. package/dist/esm/types/chart/axis.d.ts +26 -21
  79. package/dist/esm/types/chart/line.d.ts +1 -1
  80. package/dist/esm/types/chart/series.d.ts +1 -1
  81. package/dist/esm/utils/chart/axis.d.ts +1 -0
  82. package/dist/esm/utils/chart/axis.js +8 -0
  83. package/package.json +1 -1
@@ -50,11 +50,11 @@ export const AxisX = React.memo(function AxisX(props) {
50
50
  }
51
51
  const svgElement = select(ref.current);
52
52
  svgElement.selectAll('*').remove();
53
- const plotClassName = b('plot-x');
53
+ const plotDataAttr = 'data-plot-x';
54
54
  let plotContainer = null;
55
55
  if (plotRef === null || plotRef === void 0 ? void 0 : plotRef.current) {
56
56
  plotContainer = select(plotRef.current);
57
- plotContainer.selectAll(`.${plotClassName}`).remove();
57
+ plotContainer.selectAll(`[${plotDataAttr}]`).remove();
58
58
  }
59
59
  if (!axis.visible) {
60
60
  return;
@@ -116,12 +116,13 @@ export const AxisX = React.memo(function AxisX(props) {
116
116
  }
117
117
  // add plot bands
118
118
  if (plotContainer && axis.plotBands.length > 0) {
119
- const plotBandClassName = b('plot-x-band');
119
+ const plotBandDataAttr = 'plot-x-band';
120
120
  const plotBandsSelection = plotContainer
121
- .selectAll(`.${plotBandClassName}-x`)
121
+ .selectAll(`[${plotBandDataAttr}]`)
122
122
  .data(axis.plotBands)
123
123
  .join('g')
124
- .attr('class', `${plotClassName} ${plotBandClassName}-x`);
124
+ .attr(plotDataAttr, 1)
125
+ .attr(plotBandDataAttr, 1);
125
126
  plotBandsSelection
126
127
  .append('rect')
127
128
  .attr('x', (band) => {
@@ -153,12 +154,13 @@ export const AxisX = React.memo(function AxisX(props) {
153
154
  }
154
155
  // add plot lines
155
156
  if (plotContainer && axis.plotLines.length > 0) {
156
- const plotLineClassName = b('plot-x-line');
157
+ const plotLineDataAttr = 'plot-x-line';
157
158
  const plotLinesSelection = plotContainer
158
- .selectAll(`.${plotLineClassName}`)
159
+ .selectAll(`[${plotLineDataAttr}]`)
159
160
  .data(axis.plotLines)
160
161
  .join('g')
161
- .attr('class', `${plotClassName} ${plotLineClassName}`);
162
+ .attr(plotDataAttr, 1)
163
+ .attr(plotLineDataAttr, 1);
162
164
  const lineGenerator = line();
163
165
  plotLinesSelection
164
166
  .append('path')
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { axisLeft, axisRight, line, select } from 'd3';
3
- import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisTitleRows, getBandsPosition, getClosestPointsRange, getLineDashArray, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
3
+ import { block, calculateCos, calculateSin, formatAxisTickLabel, getAxisHeight, getAxisPlotsPosition, getAxisTitleRows, getBandsPosition, getClosestPointsRange, getLineDashArray, getScaleTicks, getTicksCount, handleOverflowingText, parseTransformStyle, setEllipsisForOverflowTexts, wrapText, } from '../../utils';
4
4
  import './styles.css';
5
5
  const b = block('axis');
6
6
  function transformLabel(args) {
@@ -97,39 +97,17 @@ export const AxisY = (props) => {
97
97
  const svgElement = select(ref.current);
98
98
  svgElement.selectAll('*').remove();
99
99
  let plotContainer = null;
100
- const plotClassName = b('plot-y');
100
+ const plotDataAttr = 'data-plot-y';
101
101
  if (plotRef === null || plotRef === void 0 ? void 0 : plotRef.current) {
102
102
  plotContainer = select(plotRef.current);
103
- plotContainer.selectAll(`.${plotClassName}`).remove();
103
+ plotContainer.selectAll(`[${plotDataAttr}]`).remove();
104
104
  }
105
- const getAxisPosition = (axis) => {
106
- var _a;
107
- const top = ((_a = split.plots[axis.plotIndex]) === null || _a === void 0 ? void 0 : _a.top) || 0;
108
- if (axis.position === 'left') {
109
- return `translate(0, ${top}px)`;
110
- }
111
- return `translate(${width}px, 0)`;
112
- };
113
- const plotLines = axes.reduce((acc, axis) => {
114
- if (axis.plotLines.length) {
115
- acc.push(...axis.plotLines.map((plotLine) => {
116
- return Object.assign(Object.assign({}, plotLine), { transform: getAxisPosition(axis) });
117
- }));
118
- }
119
- return acc;
120
- }, []);
121
- const plotBands = axes.reduce((acc, axis) => {
122
- if (axis.plotBands.length) {
123
- acc.push(...axis.plotBands.map((plotBand) => (Object.assign(Object.assign({}, plotBand), { transform: getAxisPosition(axis) }))));
124
- }
125
- return acc;
126
- }, []);
127
105
  const axisSelection = svgElement
128
106
  .selectAll('axis')
129
107
  .data(axes)
130
108
  .join('g')
131
109
  .attr('class', b())
132
- .style('transform', (d) => getAxisPosition(d));
110
+ .style('transform', (d) => getAxisPlotsPosition(d, split, width));
133
111
  axisSelection.each((d, index, node) => {
134
112
  const seriesScale = scale[index];
135
113
  const axisItem = select(node[index]);
@@ -197,13 +175,14 @@ export const AxisY = (props) => {
197
175
  .remove();
198
176
  }
199
177
  if (plotContainer && d.plotBands.length > 0) {
200
- const plotBandClassName = b('plot-y-band');
178
+ const plotBandDataAttr = `data-plot-y-band-${index}`;
201
179
  const plotBandsSelection = plotContainer
202
- .selectAll(`.${plotBandClassName}`)
203
- .data(plotBands)
180
+ .selectAll(`[${plotBandDataAttr}]`)
181
+ .data(d.plotBands)
204
182
  .join('g')
205
- .attr('class', `${plotClassName} ${plotBandClassName}`)
206
- .style('transform', (plotBand) => plotBand.transform);
183
+ .attr(plotDataAttr, 1)
184
+ .attr(plotBandDataAttr, 1)
185
+ .style('transform', getAxisPlotsPosition(d, split));
207
186
  plotBandsSelection
208
187
  .append('rect')
209
188
  .attr('x', 0)
@@ -234,13 +213,14 @@ export const AxisY = (props) => {
234
213
  });
235
214
  }
236
215
  if (plotContainer && d.plotLines.length > 0) {
237
- const plotLineClassName = b('plot-y-line');
216
+ const plotLineDataAttr = `data-plot-y-line-${index}`;
238
217
  const plotLinesSelection = plotContainer
239
- .selectAll(`.${plotLineClassName}`)
240
- .data(plotLines)
218
+ .selectAll(`[${plotLineDataAttr}]`)
219
+ .data(d.plotLines)
241
220
  .join('g')
242
- .attr('class', `${plotClassName} ${plotLineClassName}`)
243
- .style('transform', (plotLine) => plotLine.transform);
221
+ .attr(plotDataAttr, 1)
222
+ .attr(plotLineDataAttr, 1)
223
+ .style('transform', getAxisPlotsPosition(d, split));
244
224
  plotLinesSelection
245
225
  .append('path')
246
226
  .attr('d', (plotLine) => {
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useCrosshair } from '../../hooks';
2
3
  import { EventType, block, getDispatcher } from '../../utils';
3
4
  import { AxisX, AxisY } from '../Axis';
4
5
  import { Legend } from '../Legend';
@@ -39,6 +40,19 @@ export const ChartInner = (props) => {
39
40
  });
40
41
  const clickHandler = (_b = (_a = data.chart) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.click;
41
42
  const pointerMoveHandler = (_d = (_c = data.chart) === null || _c === void 0 ? void 0 : _c.events) === null || _d === void 0 ? void 0 : _d.pointermove;
43
+ useCrosshair({
44
+ split: preparedSplit,
45
+ plotElement: plotRef.current,
46
+ boundsOffsetLeft,
47
+ boundsOffsetTop,
48
+ width: boundsWidth,
49
+ height: boundsHeight,
50
+ xAxis,
51
+ yAxes: yAxis,
52
+ yScale,
53
+ xScale,
54
+ dispatcher,
55
+ });
42
56
  React.useEffect(() => {
43
57
  if (clickHandler) {
44
58
  dispatcher.on(EventType.CLICK_CHART, clickHandler);
@@ -56,9 +56,12 @@ export function useChartInnerProps(props) {
56
56
  htmlLayout,
57
57
  });
58
58
  const boundsOffsetTop = chart.margin.top;
59
- // We need to calculate the width of each axis because the first axis can be hidden
59
+ // We need to calculate the width of each left axis because the first axis can be hidden
60
60
  const boundsOffsetLeft = chart.margin.left +
61
61
  yAxis.reduce((acc, axis) => {
62
+ if (axis.position !== 'left') {
63
+ return acc;
64
+ }
62
65
  const axisWidth = getYAxisWidth(axis);
63
66
  if (acc < axisWidth) {
64
67
  acc = axisWidth;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { line as lineGenerator, scaleLinear, select, symbol } from 'd3';
3
3
  import { CONTINUOUS_LEGEND_SIZE } from '../../constants';
4
4
  import { formatNumber } from '../../libs';
5
- import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineDashArray, getSymbol, } from '../../utils';
5
+ import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineDashArray, getSymbol, handleOverflowingText, } from '../../utils';
6
6
  import { axisBottom } from '../../utils/chart/axis-generators';
7
7
  import './styles.css';
8
8
  const b = block('legend');
@@ -198,6 +198,9 @@ export const Legend = (props) => {
198
198
  })
199
199
  .style('font-size', legend.itemStyle.fontSize)
200
200
  .style('position', 'absolute')
201
+ .style('max-width', function (d) {
202
+ return `${d.textWidth}px`;
203
+ })
201
204
  .style('left', function (d, i) {
202
205
  return `${getXPosition(i) + d.symbol.width + d.symbol.padding}px`;
203
206
  })
@@ -230,7 +233,12 @@ export const Legend = (props) => {
230
233
  .html(function (d) {
231
234
  return ('name' in d && d.name);
232
235
  })
233
- .style('font-size', legend.itemStyle.fontSize);
236
+ .style('font-size', legend.itemStyle.fontSize)
237
+ .each((d, index, nodes) => {
238
+ if (d.overflowed) {
239
+ handleOverflowingText(nodes[index], d.textWidth);
240
+ }
241
+ });
234
242
  }
235
243
  const contentWidth = (legend.html
236
244
  ? getXPosition(line.length) - legend.itemDistance
@@ -28,9 +28,11 @@
28
28
  fill: var(--g-color-text-complementary);
29
29
  }
30
30
  .gcharts-legend__item-text-html {
31
+ overflow: hidden;
31
32
  cursor: pointer;
32
33
  user-select: none;
33
34
  white-space: nowrap;
35
+ text-overflow: ellipsis;
34
36
  }
35
37
  .gcharts-legend__item-text-html_unselected {
36
38
  color: var(--g-color-text-hint);
@@ -0,0 +1,12 @@
1
+ export declare const SeriesType: {
2
+ readonly Area: "area";
3
+ readonly BarX: "bar-x";
4
+ readonly BarY: "bar-y";
5
+ readonly Line: "line";
6
+ readonly Pie: "pie";
7
+ readonly Scatter: "scatter";
8
+ readonly Treemap: "treemap";
9
+ readonly Waterfall: "waterfall";
10
+ readonly Sankey: "sankey";
11
+ readonly Radar: "radar";
12
+ };
@@ -0,0 +1,12 @@
1
+ export const SeriesType = {
2
+ Area: 'area',
3
+ BarX: 'bar-x',
4
+ BarY: 'bar-y',
5
+ Line: 'line',
6
+ Pie: 'pie',
7
+ Scatter: 'scatter',
8
+ Treemap: 'treemap',
9
+ Waterfall: 'waterfall',
10
+ Sankey: 'sankey',
11
+ Radar: 'radar',
12
+ };
@@ -1,4 +1,4 @@
1
- import type { BaseTextStyle, ChartAxis, ChartAxisType } from '../../types';
1
+ import type { AxisCrosshair, BaseTextStyle, ChartAxis, ChartAxisType } from '../../types';
2
2
  export declare const axisLabelsDefaults: {
3
3
  margin: number;
4
4
  padding: number;
@@ -8,6 +8,8 @@ export declare const axisLabelsDefaults: {
8
8
  type AxisTitleDefaults = Required<ChartAxis['title']> & {
9
9
  style: BaseTextStyle;
10
10
  };
11
+ type AxisCrosshairDefaults = Required<AxisCrosshair>;
12
+ export declare const axisCrosshairDefaults: AxisCrosshairDefaults;
11
13
  export declare const xAxisTitleDefaults: AxisTitleDefaults;
12
14
  export declare const yAxisTitleDefaults: AxisTitleDefaults;
13
15
  export declare const DEFAULT_AXIS_TYPE: ChartAxisType;
@@ -1,3 +1,4 @@
1
+ import { DASH_STYLE } from '../line-styles';
1
2
  export const axisLabelsDefaults = {
2
3
  margin: 10,
3
4
  padding: 10,
@@ -13,6 +14,15 @@ const axisTitleDefaults = {
13
14
  align: 'center',
14
15
  maxRowCount: 1,
15
16
  };
17
+ export const axisCrosshairDefaults = {
18
+ enabled: false,
19
+ color: 'var(--g-color-line-generic)',
20
+ width: 1,
21
+ snap: true,
22
+ dashStyle: DASH_STYLE.Solid,
23
+ opacity: 1,
24
+ layerPlacement: 'after',
25
+ };
16
26
  export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
17
27
  export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
18
28
  export const DEFAULT_AXIS_TYPE = 'linear';
@@ -1,49 +1,8 @@
1
1
  export * from './defaults';
2
2
  export * from './misc';
3
- export declare const SeriesType: {
4
- readonly Area: "area";
5
- readonly BarX: "bar-x";
6
- readonly BarY: "bar-y";
7
- readonly Line: "line";
8
- readonly Pie: "pie";
9
- readonly Scatter: "scatter";
10
- readonly Treemap: "treemap";
11
- readonly Waterfall: "waterfall";
12
- readonly Sankey: "sankey";
13
- readonly Radar: "radar";
14
- };
15
- export declare enum DashStyle {
16
- Dash = "Dash",
17
- DashDot = "DashDot",
18
- Dot = "Dot",
19
- LongDash = "LongDash",
20
- LongDashDot = "LongDashDot",
21
- LongDashDotDot = "LongDashDotDot",
22
- ShortDash = "ShortDash",
23
- ShortDashDot = "ShortDashDot",
24
- ShortDashDotDot = "ShortDashDotDot",
25
- ShortDot = "ShortDot",
26
- Solid = "Solid"
27
- }
28
- export declare enum SymbolType {
29
- Circle = "circle",
30
- Diamond = "diamond",
31
- Square = "square",
32
- Triangle = "triangle",
33
- TriangleDown = "triangle-down"
34
- }
35
- export declare enum LineCap {
36
- Butt = "butt",
37
- Round = "round",
38
- Square = "square",
39
- None = "none"
40
- }
41
- export declare enum LayoutAlgorithm {
42
- Binary = "binary",
43
- Dice = "dice",
44
- Slice = "slice",
45
- SliceDice = "slice-dice",
46
- Squarify = "squarify"
47
- }
48
- export declare const DEFAULT_PALETTE: string[];
49
- export declare const DEFAULT_AXIS_LABEL_FONT_SIZE = "11px";
3
+ export * from './chart-types';
4
+ export * from './line-styles';
5
+ export * from './symbol-types';
6
+ export * from './layout-algorithms';
7
+ export * from './palette';
8
+ export * from './typography';
@@ -1,74 +1,8 @@
1
1
  export * from './defaults';
2
2
  export * from './misc';
3
- export const SeriesType = {
4
- Area: 'area',
5
- BarX: 'bar-x',
6
- BarY: 'bar-y',
7
- Line: 'line',
8
- Pie: 'pie',
9
- Scatter: 'scatter',
10
- Treemap: 'treemap',
11
- Waterfall: 'waterfall',
12
- Sankey: 'sankey',
13
- Radar: 'radar',
14
- };
15
- export var DashStyle;
16
- (function (DashStyle) {
17
- DashStyle["Dash"] = "Dash";
18
- DashStyle["DashDot"] = "DashDot";
19
- DashStyle["Dot"] = "Dot";
20
- DashStyle["LongDash"] = "LongDash";
21
- DashStyle["LongDashDot"] = "LongDashDot";
22
- DashStyle["LongDashDotDot"] = "LongDashDotDot";
23
- DashStyle["ShortDash"] = "ShortDash";
24
- DashStyle["ShortDashDot"] = "ShortDashDot";
25
- DashStyle["ShortDashDotDot"] = "ShortDashDotDot";
26
- DashStyle["ShortDot"] = "ShortDot";
27
- DashStyle["Solid"] = "Solid";
28
- })(DashStyle || (DashStyle = {}));
29
- export var SymbolType;
30
- (function (SymbolType) {
31
- SymbolType["Circle"] = "circle";
32
- SymbolType["Diamond"] = "diamond";
33
- SymbolType["Square"] = "square";
34
- SymbolType["Triangle"] = "triangle";
35
- SymbolType["TriangleDown"] = "triangle-down";
36
- })(SymbolType || (SymbolType = {}));
37
- export var LineCap;
38
- (function (LineCap) {
39
- LineCap["Butt"] = "butt";
40
- LineCap["Round"] = "round";
41
- LineCap["Square"] = "square";
42
- LineCap["None"] = "none";
43
- })(LineCap || (LineCap = {}));
44
- export var LayoutAlgorithm;
45
- (function (LayoutAlgorithm) {
46
- LayoutAlgorithm["Binary"] = "binary";
47
- LayoutAlgorithm["Dice"] = "dice";
48
- LayoutAlgorithm["Slice"] = "slice";
49
- LayoutAlgorithm["SliceDice"] = "slice-dice";
50
- LayoutAlgorithm["Squarify"] = "squarify";
51
- })(LayoutAlgorithm || (LayoutAlgorithm = {}));
52
- export const DEFAULT_PALETTE = [
53
- '#4DA2F1',
54
- '#FF3D64',
55
- '#8AD554',
56
- '#FFC636',
57
- '#FFB9DD',
58
- '#84D1EE',
59
- '#FF91A1',
60
- '#54A520',
61
- '#DB9100',
62
- '#BA74B3',
63
- '#1F68A9',
64
- '#ED65A9',
65
- '#0FA08D',
66
- '#FF7E00',
67
- '#E8B0A4',
68
- '#52A6C5',
69
- '#BE2443',
70
- '#70C1AF',
71
- '#FFB46C',
72
- '#DCA3D7',
73
- ];
74
- export const DEFAULT_AXIS_LABEL_FONT_SIZE = '11px';
3
+ export * from './chart-types';
4
+ export * from './line-styles';
5
+ export * from './symbol-types';
6
+ export * from './layout-algorithms';
7
+ export * from './palette';
8
+ export * from './typography';
@@ -0,0 +1,7 @@
1
+ export declare enum LayoutAlgorithm {
2
+ Binary = "binary",
3
+ Dice = "dice",
4
+ Slice = "slice",
5
+ SliceDice = "slice-dice",
6
+ Squarify = "squarify"
7
+ }
@@ -0,0 +1,8 @@
1
+ export var LayoutAlgorithm;
2
+ (function (LayoutAlgorithm) {
3
+ LayoutAlgorithm["Binary"] = "binary";
4
+ LayoutAlgorithm["Dice"] = "dice";
5
+ LayoutAlgorithm["Slice"] = "slice";
6
+ LayoutAlgorithm["SliceDice"] = "slice-dice";
7
+ LayoutAlgorithm["Squarify"] = "squarify";
8
+ })(LayoutAlgorithm || (LayoutAlgorithm = {}));
@@ -0,0 +1,20 @@
1
+ export declare const DASH_STYLE: {
2
+ readonly Dash: "Dash";
3
+ readonly DashDot: "DashDot";
4
+ readonly Dot: "Dot";
5
+ readonly LongDash: "LongDash";
6
+ readonly LongDashDot: "LongDashDot";
7
+ readonly LongDashDotDot: "LongDashDotDot";
8
+ readonly ShortDash: "ShortDash";
9
+ readonly ShortDashDot: "ShortDashDot";
10
+ readonly ShortDashDotDot: "ShortDashDotDot";
11
+ readonly ShortDot: "ShortDot";
12
+ readonly Solid: "Solid";
13
+ };
14
+ export type DashStyle = keyof typeof DASH_STYLE;
15
+ export declare enum LineCap {
16
+ Butt = "butt",
17
+ Round = "round",
18
+ Square = "square",
19
+ None = "none"
20
+ }
@@ -0,0 +1,20 @@
1
+ export const DASH_STYLE = {
2
+ Dash: 'Dash',
3
+ DashDot: 'DashDot',
4
+ Dot: 'Dot',
5
+ LongDash: 'LongDash',
6
+ LongDashDot: 'LongDashDot',
7
+ LongDashDotDot: 'LongDashDotDot',
8
+ ShortDash: 'ShortDash',
9
+ ShortDashDot: 'ShortDashDot',
10
+ ShortDashDotDot: 'ShortDashDotDot',
11
+ ShortDot: 'ShortDot',
12
+ Solid: 'Solid',
13
+ };
14
+ export var LineCap;
15
+ (function (LineCap) {
16
+ LineCap["Butt"] = "butt";
17
+ LineCap["Round"] = "round";
18
+ LineCap["Square"] = "square";
19
+ LineCap["None"] = "none";
20
+ })(LineCap || (LineCap = {}));
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_PALETTE: string[];
@@ -0,0 +1,22 @@
1
+ export const DEFAULT_PALETTE = [
2
+ '#4DA2F1',
3
+ '#FF3D64',
4
+ '#8AD554',
5
+ '#FFC636',
6
+ '#FFB9DD',
7
+ '#84D1EE',
8
+ '#FF91A1',
9
+ '#54A520',
10
+ '#DB9100',
11
+ '#BA74B3',
12
+ '#1F68A9',
13
+ '#ED65A9',
14
+ '#0FA08D',
15
+ '#FF7E00',
16
+ '#E8B0A4',
17
+ '#52A6C5',
18
+ '#BE2443',
19
+ '#70C1AF',
20
+ '#FFB46C',
21
+ '#DCA3D7',
22
+ ];
@@ -0,0 +1,7 @@
1
+ export declare enum SymbolType {
2
+ Circle = "circle",
3
+ Diamond = "diamond",
4
+ Square = "square",
5
+ Triangle = "triangle",
6
+ TriangleDown = "triangle-down"
7
+ }
@@ -0,0 +1,8 @@
1
+ export var SymbolType;
2
+ (function (SymbolType) {
3
+ SymbolType["Circle"] = "circle";
4
+ SymbolType["Diamond"] = "diamond";
5
+ SymbolType["Square"] = "square";
6
+ SymbolType["Triangle"] = "triangle";
7
+ SymbolType["TriangleDown"] = "triangle-down";
8
+ })(SymbolType || (SymbolType = {}));
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_AXIS_LABEL_FONT_SIZE = "11px";
@@ -0,0 +1 @@
1
+ export const DEFAULT_AXIS_LABEL_FONT_SIZE = '11px';
@@ -9,3 +9,4 @@ export * from './useShapes';
9
9
  export * from './useTooltip';
10
10
  export * from './useSplit';
11
11
  export * from './useSplit/types';
12
+ export * from './useCrosshair';
@@ -9,3 +9,4 @@ export * from './useShapes';
9
9
  export * from './useTooltip';
10
10
  export * from './useSplit';
11
11
  export * from './useSplit/types';
12
+ export * from './useCrosshair';
@@ -1,5 +1,5 @@
1
- import type { DashStyle } from 'src/constants';
2
- import type { AxisPlotBand, BaseTextStyle, ChartAxis, ChartAxisLabels, ChartAxisTitleAlignment, ChartAxisType, ChartData, ChartMargin, PlotLayerPlacement } from '../../types';
1
+ import type { DashStyle } from '../../constants';
2
+ import type { AxisCrosshair, AxisPlotBand, BaseTextStyle, ChartAxis, ChartAxisLabels, ChartAxisTitleAlignment, ChartAxisType, ChartData, ChartMargin, PlotLayerPlacement } from '../../types';
3
3
  type PreparedAxisLabels = Omit<ChartAxisLabels, 'enabled' | 'padding' | 'style' | 'autoRotation'> & Required<Pick<ChartAxisLabels, 'enabled' | 'padding' | 'margin' | 'rotation'>> & {
4
4
  style: BaseTextStyle;
5
5
  rotation: number;
@@ -12,6 +12,7 @@ export type PreparedChart = {
12
12
  margin: ChartMargin;
13
13
  };
14
14
  export type PreparedAxisPlotBand = Required<AxisPlotBand>;
15
+ export type PreparedAxisCrosshair = Required<AxisCrosshair>;
15
16
  export type PreparedAxisPlotLine = {
16
17
  value: number;
17
18
  color: string;
@@ -44,6 +45,7 @@ export type PreparedAxis = Omit<ChartAxis, 'type' | 'labels' | 'plotLines' | 'pl
44
45
  plotIndex: number;
45
46
  plotLines: PreparedAxisPlotLine[];
46
47
  plotBands: PreparedAxisPlotBand[];
48
+ crosshair: PreparedAxisCrosshair;
47
49
  };
48
50
  export type PreparedTitle = ChartData['title'] & {
49
51
  height: number;
@@ -1,5 +1,5 @@
1
1
  import get from 'lodash/get';
2
- import { DEFAULT_AXIS_LABEL_FONT_SIZE, DashStyle, axisLabelsDefaults, xAxisTitleDefaults, } from '../../constants';
2
+ import { DASH_STYLE, DEFAULT_AXIS_LABEL_FONT_SIZE, axisCrosshairDefaults, axisLabelsDefaults, xAxisTitleDefaults, } from '../../constants';
3
3
  import { CHART_SERIES_WITH_VOLUME_ON_X_AXIS, calculateCos, formatAxisTickLabel, getClosestPointsRange, getHorisontalSvgTextHeight, getLabelsSize, getMaxTickCount, getTicksCount, getXAxisItems, hasOverlappingLabels, wrapText, } from '../../utils';
4
4
  import { createXScale } from '../useAxisScales';
5
5
  function getLabelSettings({ axis, series, width, autoRotation = true, }) {
@@ -106,7 +106,7 @@ export const getPreparedXAxis = ({ xAxis, series, width, }) => {
106
106
  value: get(d, 'value', 0),
107
107
  color: get(d, 'color', 'var(--g-color-base-brand)'),
108
108
  width: get(d, 'width', 1),
109
- dashStyle: get(d, 'dashStyle', DashStyle.Solid),
109
+ dashStyle: get(d, 'dashStyle', DASH_STYLE.Solid),
110
110
  opacity: get(d, 'opacity', 1),
111
111
  layerPlacement: get(d, 'layerPlacement', 'before'),
112
112
  })),
@@ -117,6 +117,15 @@ export const getPreparedXAxis = ({ xAxis, series, width, }) => {
117
117
  to: get(d, 'to', 0),
118
118
  layerPlacement: get(d, 'layerPlacement', 'before'),
119
119
  })),
120
+ crosshair: {
121
+ enabled: get(xAxis, 'crosshair.enabled', axisCrosshairDefaults.enabled),
122
+ color: get(xAxis, 'crosshair.color', axisCrosshairDefaults.color),
123
+ layerPlacement: get(xAxis, 'crosshair.layerPlacement', axisCrosshairDefaults.layerPlacement),
124
+ snap: get(xAxis, 'crosshair.snap', axisCrosshairDefaults.snap),
125
+ dashStyle: get(xAxis, 'crosshair.dashStyle', axisCrosshairDefaults.dashStyle),
126
+ width: get(xAxis, 'crosshair.width', axisCrosshairDefaults.width),
127
+ opacity: get(xAxis, 'crosshair.opacity', axisCrosshairDefaults.opacity),
128
+ },
120
129
  visible: get(xAxis, 'visible', true),
121
130
  };
122
131
  const { height, rotation } = getLabelSettings({