@gravity-ui/charts 1.8.0 → 1.10.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 (255) hide show
  1. package/dist/cjs/components/Axis/AxisX.d.ts +2 -1
  2. package/dist/cjs/components/Axis/AxisX.js +147 -141
  3. package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
  4. package/dist/cjs/components/Axis/AxisY.js +118 -116
  5. package/dist/cjs/components/ChartInner/index.js +36 -9
  6. package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.js +59 -10
  9. package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
  10. package/dist/cjs/components/ChartInner/utils.js +28 -0
  11. package/dist/cjs/components/Legend/index.js +202 -191
  12. package/dist/cjs/components/Legend/styles.css +2 -0
  13. package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  14. package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
  15. package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
  16. package/dist/cjs/components/Tooltip/index.d.ts +1 -1
  17. package/dist/cjs/constants/chart-types.d.ts +12 -0
  18. package/dist/cjs/constants/chart-types.js +12 -0
  19. package/dist/cjs/constants/defaults/axis.d.ts +3 -1
  20. package/dist/cjs/constants/defaults/axis.js +10 -0
  21. package/dist/cjs/constants/index.d.ts +6 -47
  22. package/dist/cjs/constants/index.js +6 -72
  23. package/dist/cjs/constants/layout-algorithms.d.ts +7 -0
  24. package/dist/cjs/constants/layout-algorithms.js +8 -0
  25. package/dist/cjs/constants/line-styles.d.ts +20 -0
  26. package/dist/cjs/constants/line-styles.js +20 -0
  27. package/dist/cjs/constants/palette.d.ts +1 -0
  28. package/dist/cjs/constants/palette.js +22 -0
  29. package/dist/cjs/constants/symbol-types.d.ts +7 -0
  30. package/dist/cjs/constants/symbol-types.js +8 -0
  31. package/dist/cjs/constants/typography.d.ts +1 -0
  32. package/dist/cjs/constants/typography.js +1 -0
  33. package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
  34. package/dist/cjs/hooks/hooks-utils/index.js +1 -0
  35. package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
  36. package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
  37. package/dist/cjs/hooks/index.d.ts +1 -0
  38. package/dist/cjs/hooks/index.js +1 -0
  39. package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
  40. package/dist/cjs/hooks/useAxisScales/index.js +22 -8
  41. package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
  42. package/dist/cjs/hooks/useBrush/index.js +70 -0
  43. package/dist/cjs/hooks/useBrush/styles.css +10 -0
  44. package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
  45. package/dist/cjs/hooks/useBrush/types.js +1 -0
  46. package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
  47. package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
  48. package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
  49. package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
  50. package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
  51. package/dist/cjs/hooks/useChartOptions/index.js +3 -2
  52. package/dist/cjs/hooks/useChartOptions/types.d.ts +6 -2
  53. package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
  54. package/dist/cjs/hooks/useChartOptions/x-axis.js +22 -13
  55. package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
  56. package/dist/cjs/hooks/useChartOptions/y-axis.js +36 -21
  57. package/dist/cjs/hooks/useCrosshair/index.d.ts +17 -0
  58. package/dist/cjs/hooks/useCrosshair/index.js +139 -0
  59. package/dist/cjs/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
  60. package/dist/cjs/hooks/useCrosshair/useCrosshairHover.js +18 -0
  61. package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
  62. package/dist/cjs/hooks/useSeries/index.js +41 -22
  63. package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  64. package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
  65. package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
  66. package/dist/cjs/hooks/useSeries/prepare-legend.js +27 -9
  67. package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -2
  68. package/dist/cjs/hooks/useSeries/prepare-line.js +3 -3
  69. package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
  70. package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
  71. package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
  72. package/dist/cjs/hooks/useShapes/area/index.js +1 -1
  73. package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
  74. package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
  75. package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
  76. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  77. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
  78. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  79. package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
  80. package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
  81. package/dist/cjs/hooks/useShapes/index.js +40 -31
  82. package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
  83. package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
  84. package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
  85. package/dist/cjs/hooks/useShapes/marker.js +2 -2
  86. package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
  87. package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  88. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
  89. package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  90. package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
  91. package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
  92. package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
  93. package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
  94. package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
  95. package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  96. package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
  97. package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
  98. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  99. package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
  100. package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
  101. package/dist/cjs/hooks/useZoom/index.js +54 -0
  102. package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
  103. package/dist/cjs/hooks/useZoom/types.js +1 -0
  104. package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
  105. package/dist/cjs/hooks/useZoom/utils.js +128 -0
  106. package/dist/cjs/types/chart/axis.d.ts +26 -21
  107. package/dist/cjs/types/chart/chart.d.ts +5 -0
  108. package/dist/cjs/types/chart/line.d.ts +1 -1
  109. package/dist/cjs/types/chart/pie.d.ts +1 -1
  110. package/dist/cjs/types/chart/series.d.ts +1 -1
  111. package/dist/cjs/types/chart/tooltip.d.ts +1 -1
  112. package/dist/cjs/types/chart/zoom.d.ts +36 -0
  113. package/dist/cjs/types/chart/zoom.js +1 -0
  114. package/dist/cjs/types/index.d.ts +1 -0
  115. package/dist/cjs/types/index.js +1 -0
  116. package/dist/cjs/types/misc.d.ts +7 -0
  117. package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
  118. package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
  119. package/dist/cjs/utils/chart/axis.d.ts +2 -1
  120. package/dist/cjs/utils/chart/axis.js +10 -2
  121. package/dist/cjs/utils/chart/get-closest-data.js +1 -1
  122. package/dist/cjs/utils/chart/text.d.ts +7 -7
  123. package/dist/cjs/utils/chart/text.js +37 -29
  124. package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
  125. package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
  126. package/dist/cjs/validation/index.d.ts +1 -1
  127. package/dist/cjs/validation/index.js +16 -16
  128. package/dist/esm/components/Axis/AxisX.d.ts +2 -1
  129. package/dist/esm/components/Axis/AxisX.js +147 -141
  130. package/dist/esm/components/Axis/AxisY.d.ts +2 -1
  131. package/dist/esm/components/Axis/AxisY.js +118 -116
  132. package/dist/esm/components/ChartInner/index.js +36 -9
  133. package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
  134. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
  135. package/dist/esm/components/ChartInner/useChartInnerProps.js +59 -10
  136. package/dist/esm/components/ChartInner/utils.d.ts +3 -0
  137. package/dist/esm/components/ChartInner/utils.js +28 -0
  138. package/dist/esm/components/Legend/index.js +202 -191
  139. package/dist/esm/components/Legend/styles.css +2 -0
  140. package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
  141. package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
  142. package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
  143. package/dist/esm/components/Tooltip/index.d.ts +1 -1
  144. package/dist/esm/constants/chart-types.d.ts +12 -0
  145. package/dist/esm/constants/chart-types.js +12 -0
  146. package/dist/esm/constants/defaults/axis.d.ts +3 -1
  147. package/dist/esm/constants/defaults/axis.js +10 -0
  148. package/dist/esm/constants/index.d.ts +6 -47
  149. package/dist/esm/constants/index.js +6 -72
  150. package/dist/esm/constants/layout-algorithms.d.ts +7 -0
  151. package/dist/esm/constants/layout-algorithms.js +8 -0
  152. package/dist/esm/constants/line-styles.d.ts +20 -0
  153. package/dist/esm/constants/line-styles.js +20 -0
  154. package/dist/esm/constants/palette.d.ts +1 -0
  155. package/dist/esm/constants/palette.js +22 -0
  156. package/dist/esm/constants/symbol-types.d.ts +7 -0
  157. package/dist/esm/constants/symbol-types.js +8 -0
  158. package/dist/esm/constants/typography.d.ts +1 -0
  159. package/dist/esm/constants/typography.js +1 -0
  160. package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
  161. package/dist/esm/hooks/hooks-utils/index.js +1 -0
  162. package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
  163. package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
  164. package/dist/esm/hooks/index.d.ts +1 -0
  165. package/dist/esm/hooks/index.js +1 -0
  166. package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
  167. package/dist/esm/hooks/useAxisScales/index.js +22 -8
  168. package/dist/esm/hooks/useBrush/index.d.ts +3 -0
  169. package/dist/esm/hooks/useBrush/index.js +70 -0
  170. package/dist/esm/hooks/useBrush/styles.css +10 -0
  171. package/dist/esm/hooks/useBrush/types.d.ts +24 -0
  172. package/dist/esm/hooks/useBrush/types.js +1 -0
  173. package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
  174. package/dist/esm/hooks/useChartDimensions/index.js +2 -2
  175. package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
  176. package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
  177. package/dist/esm/hooks/useChartOptions/chart.js +80 -1
  178. package/dist/esm/hooks/useChartOptions/index.js +3 -2
  179. package/dist/esm/hooks/useChartOptions/types.d.ts +6 -2
  180. package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
  181. package/dist/esm/hooks/useChartOptions/x-axis.js +22 -13
  182. package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
  183. package/dist/esm/hooks/useChartOptions/y-axis.js +36 -21
  184. package/dist/esm/hooks/useCrosshair/index.d.ts +17 -0
  185. package/dist/esm/hooks/useCrosshair/index.js +139 -0
  186. package/dist/esm/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
  187. package/dist/esm/hooks/useCrosshair/useCrosshairHover.js +18 -0
  188. package/dist/esm/hooks/useSeries/index.d.ts +8 -6
  189. package/dist/esm/hooks/useSeries/index.js +41 -22
  190. package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
  191. package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
  192. package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
  193. package/dist/esm/hooks/useSeries/prepare-legend.js +27 -9
  194. package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -2
  195. package/dist/esm/hooks/useSeries/prepare-line.js +3 -3
  196. package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
  197. package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
  198. package/dist/esm/hooks/useSeries/types.d.ts +2 -1
  199. package/dist/esm/hooks/useShapes/area/index.js +1 -1
  200. package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
  201. package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
  202. package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
  203. package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
  204. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
  205. package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
  206. package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
  207. package/dist/esm/hooks/useShapes/index.d.ts +1 -1
  208. package/dist/esm/hooks/useShapes/index.js +40 -31
  209. package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
  210. package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
  211. package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
  212. package/dist/esm/hooks/useShapes/marker.js +2 -2
  213. package/dist/esm/hooks/useShapes/pie/index.js +3 -3
  214. package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
  215. package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
  216. package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
  217. package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
  218. package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
  219. package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
  220. package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
  221. package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
  222. package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
  223. package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
  224. package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
  225. package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
  226. package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
  227. package/dist/esm/hooks/useZoom/index.d.ts +18 -0
  228. package/dist/esm/hooks/useZoom/index.js +54 -0
  229. package/dist/esm/hooks/useZoom/types.d.ts +19 -0
  230. package/dist/esm/hooks/useZoom/types.js +1 -0
  231. package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
  232. package/dist/esm/hooks/useZoom/utils.js +128 -0
  233. package/dist/esm/types/chart/axis.d.ts +26 -21
  234. package/dist/esm/types/chart/chart.d.ts +5 -0
  235. package/dist/esm/types/chart/line.d.ts +1 -1
  236. package/dist/esm/types/chart/pie.d.ts +1 -1
  237. package/dist/esm/types/chart/series.d.ts +1 -1
  238. package/dist/esm/types/chart/tooltip.d.ts +1 -1
  239. package/dist/esm/types/chart/zoom.d.ts +36 -0
  240. package/dist/esm/types/chart/zoom.js +1 -0
  241. package/dist/esm/types/index.d.ts +1 -0
  242. package/dist/esm/types/index.js +1 -0
  243. package/dist/esm/types/misc.d.ts +7 -0
  244. package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
  245. package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
  246. package/dist/esm/utils/chart/axis.d.ts +2 -1
  247. package/dist/esm/utils/chart/axis.js +10 -2
  248. package/dist/esm/utils/chart/get-closest-data.js +1 -1
  249. package/dist/esm/utils/chart/text.d.ts +7 -7
  250. package/dist/esm/utils/chart/text.js +37 -29
  251. package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
  252. package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
  253. package/dist/esm/validation/index.d.ts +1 -1
  254. package/dist/esm/validation/index.js +16 -16
  255. package/package.json +2 -1
@@ -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');
@@ -142,212 +142,223 @@ export const Legend = (props) => {
142
142
  setPageIndex(0);
143
143
  }, [boundsWidth]);
144
144
  React.useEffect(() => {
145
- var _a, _b, _c, _d, _e, _f, _g, _h;
146
- if (!ref.current || !htmlLayout) {
147
- return;
148
- }
149
- const svgElement = select(ref.current);
150
- svgElement.selectAll('*').remove();
151
- const htmlElement = select(htmlLayout);
152
- htmlElement.selectAll('[data-legend]').remove();
153
- const htmlContainer = legend.html
154
- ? htmlElement.append('div').attr('data-legend', 1).style('position', 'absolute')
155
- : null;
156
- let legendWidth = 0;
157
- if (legend.type === 'discrete') {
158
- const start = (_b = (_a = config.pagination) === null || _a === void 0 ? void 0 : _a.pages[pageIndex]) === null || _b === void 0 ? void 0 : _b.start;
159
- const end = (_d = (_c = config.pagination) === null || _c === void 0 ? void 0 : _c.pages[pageIndex]) === null || _d === void 0 ? void 0 : _d.end;
160
- const pageItems = typeof start === 'number' && typeof end === 'number'
161
- ? items.slice(start, end)
162
- : items;
163
- const legendLineHeights = [];
164
- pageItems.forEach((line) => {
165
- var _a;
166
- const legendLine = svgElement.append('g').attr('class', b('line'));
167
- const htmlLegendLine = htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.append('div').style('position', 'absolute');
168
- const legendItemTemplate = legendLine
169
- .selectAll('legend-history')
170
- .data(line)
171
- .enter()
172
- .append('g')
173
- .attr('class', b('item'))
174
- .on('click', function (e, d) {
175
- onItemClick({ name: d.name, metaKey: e.metaKey });
176
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
177
- });
178
- const getXPosition = (i) => {
179
- return line.slice(0, i).reduce((acc, legendItem) => {
180
- return (acc +
181
- legendItem.symbol.width +
182
- legendItem.symbol.padding +
183
- legendItem.textWidth +
184
- legend.itemDistance);
185
- }, 0);
186
- };
187
- const legendLineHeight = Math.max(...line.map((l) => l.height));
188
- renderLegendSymbol({ selection: legendItemTemplate, legend, legendLineHeight });
189
- if (htmlLegendLine) {
190
- htmlLegendLine
191
- .selectAll('legend-item')
145
+ async function prepareLegend() {
146
+ var _a, _b, _c, _d, _e, _f, _g, _h;
147
+ if (!ref.current || !htmlLayout) {
148
+ return;
149
+ }
150
+ const svgElement = select(ref.current);
151
+ svgElement.selectAll('*').remove();
152
+ const htmlElement = select(htmlLayout);
153
+ htmlElement.selectAll('[data-legend]').remove();
154
+ const htmlContainer = legend.html
155
+ ? htmlElement.append('div').attr('data-legend', 1).style('position', 'absolute')
156
+ : null;
157
+ let legendWidth = 0;
158
+ if (legend.type === 'discrete') {
159
+ const start = (_b = (_a = config.pagination) === null || _a === void 0 ? void 0 : _a.pages[pageIndex]) === null || _b === void 0 ? void 0 : _b.start;
160
+ const end = (_d = (_c = config.pagination) === null || _c === void 0 ? void 0 : _c.pages[pageIndex]) === null || _d === void 0 ? void 0 : _d.end;
161
+ const pageItems = typeof start === 'number' && typeof end === 'number'
162
+ ? items.slice(start, end)
163
+ : items;
164
+ const legendLineHeights = [];
165
+ pageItems.forEach((line) => {
166
+ var _a;
167
+ const legendLine = svgElement.append('g').attr('class', b('line'));
168
+ const htmlLegendLine = htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.append('div').style('position', 'absolute');
169
+ const legendItemTemplate = legendLine
170
+ .selectAll('legend-history')
192
171
  .data(line)
193
172
  .enter()
194
- .append('div')
195
- .attr('class', function (d) {
196
- const mods = { selected: d.visible, unselected: !d.visible };
197
- return b('item-text-html', mods);
198
- })
199
- .style('font-size', legend.itemStyle.fontSize)
200
- .style('position', 'absolute')
201
- .style('left', function (d, i) {
202
- return `${getXPosition(i) + d.symbol.width + d.symbol.padding}px`;
203
- })
204
- .style('top', function (d) {
205
- if (d.height < legendLineHeight) {
206
- return `${(legendLineHeight - d.height) / 2}px`;
207
- }
208
- return '0px';
209
- })
173
+ .append('g')
174
+ .attr('class', b('item'))
210
175
  .on('click', function (e, d) {
211
176
  onItemClick({ name: d.name, metaKey: e.metaKey });
212
177
  onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
213
- })[legend.html ? 'html' : 'text'](function (d) {
214
- return d.name;
178
+ });
179
+ const getXPosition = (i) => {
180
+ return line.slice(0, i).reduce((acc, legendItem) => {
181
+ return (acc +
182
+ legendItem.symbol.width +
183
+ legendItem.symbol.padding +
184
+ legendItem.textWidth +
185
+ legend.itemDistance);
186
+ }, 0);
187
+ };
188
+ const legendLineHeight = Math.max(...line.map((l) => l.height));
189
+ renderLegendSymbol({ selection: legendItemTemplate, legend, legendLineHeight });
190
+ if (htmlLegendLine) {
191
+ htmlLegendLine
192
+ .selectAll('legend-item')
193
+ .data(line)
194
+ .enter()
195
+ .append('div')
196
+ .attr('class', function (d) {
197
+ const mods = { selected: d.visible, unselected: !d.visible };
198
+ return b('item-text-html', mods);
199
+ })
200
+ .style('font-size', legend.itemStyle.fontSize)
201
+ .style('position', 'absolute')
202
+ .style('max-width', function (d) {
203
+ return `${d.textWidth}px`;
204
+ })
205
+ .style('left', function (d, i) {
206
+ return `${getXPosition(i) + d.symbol.width + d.symbol.padding}px`;
207
+ })
208
+ .style('top', function (d) {
209
+ if (d.height < legendLineHeight) {
210
+ return `${(legendLineHeight - d.height) / 2}px`;
211
+ }
212
+ return '0px';
213
+ })
214
+ .on('click', function (e, d) {
215
+ onItemClick({ name: d.name, metaKey: e.metaKey });
216
+ onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
217
+ })[legend.html ? 'html' : 'text'](function (d) {
218
+ return d.name;
219
+ });
220
+ }
221
+ else {
222
+ legendItemTemplate
223
+ .append('text')
224
+ .attr('x', function (legendItem, i) {
225
+ return (getXPosition(i) +
226
+ legendItem.symbol.width +
227
+ legendItem.symbol.padding);
228
+ })
229
+ .attr('height', legend.height)
230
+ .attr('class', function (d) {
231
+ const mods = { selected: d.visible, unselected: !d.visible };
232
+ return b('item-text', mods);
233
+ })
234
+ .html(function (d) {
235
+ return ('name' in d && d.name);
236
+ })
237
+ .style('font-size', legend.itemStyle.fontSize)
238
+ .each((d, index, nodes) => {
239
+ if (d.overflowed) {
240
+ handleOverflowingText(nodes[index], d.textWidth);
241
+ }
242
+ });
243
+ }
244
+ const contentWidth = (legend.html
245
+ ? getXPosition(line.length) - legend.itemDistance
246
+ : (_a = legendLine.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 0;
247
+ let left = 0;
248
+ switch (legend.justifyContent) {
249
+ case 'center': {
250
+ const legendLinePostion = getLegendPosition({
251
+ align: legend.align,
252
+ width: boundsWidth,
253
+ offsetWidth: 0,
254
+ contentWidth,
255
+ });
256
+ left = legendLinePostion.left;
257
+ legendWidth = boundsWidth;
258
+ break;
259
+ }
260
+ case 'start': {
261
+ legendWidth = Math.max(legendWidth, contentWidth);
262
+ break;
263
+ }
264
+ }
265
+ const top = legendLineHeights.reduce((acc, h) => acc + h, 0);
266
+ legendLineHeights.push(legendLineHeight);
267
+ legendLine.attr('transform', `translate(${[left, top].join(',')})`);
268
+ htmlLegendLine === null || htmlLegendLine === void 0 ? void 0 : htmlLegendLine.style('transform', `translate(${left}px, ${top}px)`);
269
+ });
270
+ if (config.pagination) {
271
+ const transform = `translate(${[0, legend.height - legend.lineHeight / 2].join(',')})`;
272
+ appendPaginator({
273
+ container: svgElement,
274
+ pageIndex: pageIndex,
275
+ legend,
276
+ transform,
277
+ pages: config.pagination.pages,
278
+ onArrowClick: setPageIndex,
215
279
  });
216
280
  }
217
- else {
218
- legendItemTemplate
219
- .append('text')
220
- .attr('x', function (legendItem, i) {
221
- return (getXPosition(i) +
222
- legendItem.symbol.width +
223
- legendItem.symbol.padding);
224
- })
225
- .attr('height', legend.height)
226
- .attr('class', function (d) {
227
- const mods = { selected: d.visible, unselected: !d.visible };
228
- return b('item-text', mods);
229
- })
230
- .html(function (d) {
231
- return ('name' in d && d.name);
232
- })
233
- .style('font-size', legend.itemStyle.fontSize);
234
- }
235
- const contentWidth = (legend.html
236
- ? getXPosition(line.length) - legend.itemDistance
237
- : (_a = legendLine.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 0;
238
- let left = 0;
239
- switch (legend.justifyContent) {
281
+ }
282
+ else {
283
+ // gradient rect
284
+ const domain = (_e = legend.colorScale.domain) !== null && _e !== void 0 ? _e : [];
285
+ const rectHeight = CONTINUOUS_LEGEND_SIZE.height;
286
+ svgElement.call(createGradientRect, {
287
+ y: legend.title.height + legend.title.margin,
288
+ height: rectHeight,
289
+ width: legend.width,
290
+ interpolator: getContinuesColorFn({
291
+ values: [0, 1],
292
+ colors: legend.colorScale.colors,
293
+ stops: legend.colorScale.stops,
294
+ }),
295
+ });
296
+ // ticks
297
+ const scale = scaleLinear(domain, [0, legend.width]);
298
+ const xAxisGenerator = await axisBottom({
299
+ scale,
300
+ ticks: {
301
+ items: [[0, -rectHeight]],
302
+ labelsMargin: legend.ticks.labelsMargin,
303
+ labelsLineHeight: legend.ticks.labelsLineHeight,
304
+ maxTickCount: 4,
305
+ tickColor: '#fff',
306
+ labelFormat: (value) => formatNumber(value, { unit: 'auto' }),
307
+ },
308
+ domain: {
309
+ size: legend.width,
310
+ color: 'transparent',
311
+ },
312
+ });
313
+ const tickTop = legend.title.height + legend.title.margin + rectHeight;
314
+ svgElement
315
+ .append('g')
316
+ .attr('transform', `translate(0, ${tickTop})`)
317
+ .call(xAxisGenerator);
318
+ legendWidth = legend.width;
319
+ }
320
+ if (legend.title.enable) {
321
+ const { maxWidth: titleWidth } = await getLabelsSize({
322
+ labels: [legend.title.text],
323
+ style: legend.title.style,
324
+ });
325
+ let dx = 0;
326
+ switch (legend.title.align) {
240
327
  case 'center': {
241
- const legendLinePostion = getLegendPosition({
242
- align: legend.align,
243
- width: boundsWidth,
244
- offsetWidth: 0,
245
- contentWidth,
246
- });
247
- left = legendLinePostion.left;
248
- legendWidth = boundsWidth;
328
+ dx = legend.width / 2 - titleWidth / 2;
249
329
  break;
250
330
  }
251
- case 'start': {
252
- legendWidth = Math.max(legendWidth, contentWidth);
331
+ case 'right': {
332
+ dx = legend.width - titleWidth;
333
+ break;
334
+ }
335
+ case 'left':
336
+ default: {
337
+ dx = 0;
253
338
  break;
254
339
  }
255
340
  }
256
- const top = legendLineHeights.reduce((acc, h) => acc + h, 0);
257
- legendLineHeights.push(legendLineHeight);
258
- legendLine.attr('transform', `translate(${[left, top].join(',')})`);
259
- htmlLegendLine === null || htmlLegendLine === void 0 ? void 0 : htmlLegendLine.style('transform', `translate(${left}px, ${top}px)`);
260
- });
261
- if (config.pagination) {
262
- const transform = `translate(${[0, legend.height - legend.lineHeight / 2].join(',')})`;
263
- appendPaginator({
264
- container: svgElement,
265
- pageIndex: pageIndex,
266
- legend,
267
- transform,
268
- pages: config.pagination.pages,
269
- onArrowClick: setPageIndex,
270
- });
341
+ svgElement
342
+ .append('g')
343
+ .attr('class', b('title'))
344
+ .append('text')
345
+ .attr('dx', dx)
346
+ .attr('font-weight', (_f = legend.title.style.fontWeight) !== null && _f !== void 0 ? _f : null)
347
+ .attr('font-size', (_g = legend.title.style.fontSize) !== null && _g !== void 0 ? _g : null)
348
+ .attr('fill', (_h = legend.title.style.fontColor) !== null && _h !== void 0 ? _h : null)
349
+ .style('dominant-baseline', 'text-before-edge')
350
+ .html(legend.title.text);
271
351
  }
272
- }
273
- else {
274
- // gradient rect
275
- const domain = (_e = legend.colorScale.domain) !== null && _e !== void 0 ? _e : [];
276
- const rectHeight = CONTINUOUS_LEGEND_SIZE.height;
277
- svgElement.call(createGradientRect, {
278
- y: legend.title.height + legend.title.margin,
279
- height: rectHeight,
280
- width: legend.width,
281
- interpolator: getContinuesColorFn({
282
- values: [0, 1],
283
- colors: legend.colorScale.colors,
284
- stops: legend.colorScale.stops,
285
- }),
286
- });
287
- // ticks
288
- const scale = scaleLinear(domain, [0, legend.width]);
289
- const xAxisGenerator = axisBottom({
290
- scale,
291
- ticks: {
292
- items: [[0, -rectHeight]],
293
- labelsMargin: legend.ticks.labelsMargin,
294
- labelsLineHeight: legend.ticks.labelsLineHeight,
295
- maxTickCount: 4,
296
- tickColor: '#fff',
297
- labelFormat: (value) => formatNumber(value, { unit: 'auto' }),
298
- },
299
- domain: {
300
- size: legend.width,
301
- color: 'transparent',
302
- },
303
- });
304
- const tickTop = legend.title.height + legend.title.margin + rectHeight;
305
- svgElement
306
- .append('g')
307
- .attr('transform', `translate(0, ${tickTop})`)
308
- .call(xAxisGenerator);
309
- legendWidth = legend.width;
310
- }
311
- if (legend.title.enable) {
312
- const { maxWidth: titleWidth } = getLabelsSize({
313
- labels: [legend.title.text],
314
- style: legend.title.style,
352
+ const { left } = getLegendPosition({
353
+ align: legend.align,
354
+ width: boundsWidth,
355
+ offsetWidth: config.offset.left,
356
+ contentWidth: legendWidth,
315
357
  });
316
- let dx = 0;
317
- switch (legend.title.align) {
318
- case 'center': {
319
- dx = legend.width / 2 - titleWidth / 2;
320
- break;
321
- }
322
- case 'right': {
323
- dx = legend.width - titleWidth;
324
- break;
325
- }
326
- case 'left':
327
- default: {
328
- dx = 0;
329
- break;
330
- }
331
- }
332
- svgElement
333
- .append('g')
334
- .attr('class', b('title'))
335
- .append('text')
336
- .attr('dx', dx)
337
- .attr('font-weight', (_f = legend.title.style.fontWeight) !== null && _f !== void 0 ? _f : null)
338
- .attr('font-size', (_g = legend.title.style.fontSize) !== null && _g !== void 0 ? _g : null)
339
- .attr('fill', (_h = legend.title.style.fontColor) !== null && _h !== void 0 ? _h : null)
340
- .style('dominant-baseline', 'text-before-edge')
341
- .html(legend.title.text);
358
+ svgElement.attr('transform', `translate(${[left, config.offset.top].join(',')})`);
359
+ htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.style('transform', `translate(${left}px, ${config.offset.top}px)`);
342
360
  }
343
- const { left } = getLegendPosition({
344
- align: legend.align,
345
- width: boundsWidth,
346
- offsetWidth: config.offset.left,
347
- contentWidth: legendWidth,
348
- });
349
- svgElement.attr('transform', `translate(${[left, config.offset.top].join(',')})`);
350
- htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.style('transform', `translate(${left}px, ${config.offset.top}px)`);
361
+ prepareLegend();
351
362
  }, [
352
363
  boundsWidth,
353
364
  chartSeries,
@@ -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);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import type { ChartTooltip, ChartXAxis, ChartYAxis, TooltipDataChunk } from '../../types';
3
3
  export interface ChartTooltipContentProps {
4
4
  hovered?: TooltipDataChunk[];
5
- xAxis?: ChartXAxis;
5
+ xAxis?: ChartXAxis | null;
6
6
  yAxis?: ChartYAxis;
7
7
  renderer?: ChartTooltip['renderer'];
8
8
  valueFormat?: ChartTooltip['valueFormat'];
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import type { ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../types';
3
3
  type Props = {
4
4
  hovered: TooltipDataChunk[];
5
- xAxis?: ChartXAxis;
5
+ xAxis?: ChartXAxis | null;
6
6
  yAxis?: ChartYAxis;
7
7
  valueFormat?: ValueFormat;
8
8
  };
@@ -38,7 +38,7 @@ const getMeasureValue = ({ data, xAxis, yAxis, valueFormat, }) => {
38
38
  format,
39
39
  });
40
40
  };
41
- function getDefaultValueFormat({ axis }) {
41
+ function getDefaultValueFormat({ axis, }) {
42
42
  switch (axis === null || axis === void 0 ? void 0 : axis.type) {
43
43
  case 'linear':
44
44
  case 'logarithmic': {
@@ -6,7 +6,7 @@ type TooltipProps = {
6
6
  dispatcher: Dispatch<object>;
7
7
  tooltip: PreparedTooltip;
8
8
  svgContainer: SVGSVGElement | null;
9
- xAxis: PreparedAxis;
9
+ xAxis: PreparedAxis | null;
10
10
  yAxis: PreparedAxis;
11
11
  tooltipPinned: boolean;
12
12
  onOutsideClick?: () => void;
@@ -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';