@wonderflow/charts 12.10.0 → 13.0.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 (161) hide show
  1. package/dist/components/bar-chart/bar-chart.d.ts +33 -5
  2. package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
  3. package/dist/components/bar-chart/bar-chart.js +20 -45
  4. package/dist/components/bar-chart/bar-chart.test.js +7 -1
  5. package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -1
  6. package/dist/components/cartesian-base/cartesian-base-axis.js +10 -11
  7. package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
  8. package/dist/components/cartesian-base/cartesian-base-legend.js +3 -3
  9. package/dist/components/cartesian-base/cartesian-base.d.ts +27 -0
  10. package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
  11. package/dist/components/cartesian-base/cartesian-base.js +7 -3
  12. package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
  13. package/dist/components/headings/headings.d.ts +19 -2
  14. package/dist/components/headings/headings.d.ts.map +1 -1
  15. package/dist/components/headings/headings.js +72 -6
  16. package/dist/components/headings/headings.module.css +1 -0
  17. package/dist/components/headings/headings.test.d.ts +1 -1
  18. package/dist/components/headings/headings.test.d.ts.map +1 -1
  19. package/dist/components/headings/headings.test.js +37 -3
  20. package/dist/components/line-chart/line-chart.d.ts +29 -13
  21. package/dist/components/line-chart/line-chart.d.ts.map +1 -1
  22. package/dist/components/line-chart/line-chart.js +4 -2
  23. package/dist/components/line-chart/line-chart.test.js +2 -2
  24. package/dist/components/loader/bar-chart-loader.d.ts.map +1 -1
  25. package/dist/components/loader/bar-chart-loader.js +1 -1
  26. package/dist/components/loader/loader.js +2 -2
  27. package/dist/components/loader/loader.test.js +4 -2
  28. package/dist/components/shapes/bars/bars-average.d.ts +3 -0
  29. package/dist/components/shapes/bars/bars-average.d.ts.map +1 -0
  30. package/dist/components/shapes/bars/bars-average.js +30 -0
  31. package/dist/components/shapes/bars/bars-overlay.d.ts +6 -0
  32. package/dist/components/shapes/bars/bars-overlay.d.ts.map +1 -0
  33. package/dist/components/shapes/bars/bars-overlay.js +59 -0
  34. package/dist/components/shapes/bars/bars-series.d.ts +6 -0
  35. package/dist/components/shapes/bars/bars-series.d.ts.map +1 -0
  36. package/dist/components/shapes/bars/bars-series.js +56 -0
  37. package/dist/components/shapes/bars/bars-tooltip.d.ts +3 -0
  38. package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -0
  39. package/dist/components/shapes/bars/bars-tooltip.js +85 -0
  40. package/dist/components/shapes/bars/bars-trendline.d.ts +3 -0
  41. package/dist/components/shapes/bars/bars-trendline.d.ts.map +1 -0
  42. package/dist/components/shapes/bars/bars-trendline.js +43 -0
  43. package/dist/components/shapes/bars/bars.d.ts.map +1 -1
  44. package/dist/components/shapes/bars/bars.js +25 -18
  45. package/dist/components/shapes/bars/bars.module.css +1 -1
  46. package/dist/components/shapes/bars/bars.test.js +39 -8
  47. package/dist/components/shapes/bars/index.d.ts +5 -0
  48. package/dist/components/shapes/bars/index.d.ts.map +1 -1
  49. package/dist/components/shapes/bars/index.js +6 -1
  50. package/dist/components/shapes/lines/lines-average.d.ts.map +1 -1
  51. package/dist/components/shapes/lines/lines-average.js +8 -46
  52. package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
  53. package/dist/components/shapes/lines/lines-marker-labels.js +10 -10
  54. package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
  55. package/dist/components/shapes/lines/lines-overlay.js +21 -26
  56. package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
  57. package/dist/components/shapes/lines/lines-series.js +6 -19
  58. package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
  59. package/dist/components/shapes/lines/lines-tooltip.js +20 -27
  60. package/dist/components/shapes/lines/lines-trendline.d.ts +3 -0
  61. package/dist/components/shapes/lines/lines-trendline.d.ts.map +1 -0
  62. package/dist/components/shapes/lines/lines-trendline.js +43 -0
  63. package/dist/components/shapes/lines/lines.d.ts.map +1 -1
  64. package/dist/components/shapes/lines/lines.js +2 -1
  65. package/dist/components/shapes/lines/lines.test.js +29 -8
  66. package/dist/hooks/hooks.test.d.ts.map +1 -1
  67. package/dist/hooks/hooks.test.js +157 -5
  68. package/dist/hooks/index.d.ts +4 -0
  69. package/dist/hooks/index.d.ts.map +1 -1
  70. package/dist/hooks/index.js +4 -0
  71. package/dist/hooks/useAverage.d.ts +82 -0
  72. package/dist/hooks/useAverage.d.ts.map +1 -0
  73. package/dist/hooks/useAverage.js +83 -0
  74. package/dist/hooks/useBarChart.d.ts +16 -0
  75. package/dist/hooks/useBarChart.d.ts.map +1 -0
  76. package/dist/hooks/useBarChart.js +104 -0
  77. package/dist/hooks/useBars.d.ts +52 -0
  78. package/dist/hooks/useBars.d.ts.map +1 -0
  79. package/dist/hooks/useBars.js +82 -0
  80. package/dist/hooks/useCartesian.d.ts +11 -2
  81. package/dist/hooks/useCartesian.d.ts.map +1 -1
  82. package/dist/hooks/useCartesian.js +16 -5
  83. package/dist/hooks/useLineChart.d.ts +3 -27
  84. package/dist/hooks/useLineChart.d.ts.map +1 -1
  85. package/dist/hooks/useLineChart.js +22 -13
  86. package/dist/hooks/useLines.d.ts +48 -0
  87. package/dist/hooks/useLines.d.ts.map +1 -0
  88. package/dist/hooks/useLines.js +70 -0
  89. package/dist/hooks/useTrendline.d.ts +56 -0
  90. package/dist/hooks/useTrendline.d.ts.map +1 -0
  91. package/dist/hooks/useTrendline.js +84 -0
  92. package/dist/providers/cartesian.d.ts +5 -1
  93. package/dist/providers/cartesian.d.ts.map +1 -1
  94. package/dist/providers/cartesian.js +19 -3
  95. package/dist/providers/data.d.ts +6 -7
  96. package/dist/providers/data.d.ts.map +1 -1
  97. package/dist/providers/data.js +4 -3
  98. package/dist/style-config/axis.js +3 -3
  99. package/dist/style-config/bars.d.ts +3 -0
  100. package/dist/style-config/bars.d.ts.map +1 -0
  101. package/dist/style-config/bars.js +33 -0
  102. package/dist/style-config/cartesian.d.ts.map +1 -1
  103. package/dist/style-config/cartesian.js +2 -0
  104. package/dist/style-config/colors.d.ts +1 -4
  105. package/dist/style-config/colors.d.ts.map +1 -1
  106. package/dist/style-config/colors.js +30 -36
  107. package/dist/style-config/headings.d.ts.map +1 -1
  108. package/dist/style-config/headings.js +16 -1
  109. package/dist/style-config/lines.d.ts.map +1 -1
  110. package/dist/style-config/lines.js +6 -0
  111. package/dist/style-config/themes.d.ts.map +1 -1
  112. package/dist/style-config/themes.js +18 -0
  113. package/dist/types/bar-chart.d.ts +20 -15
  114. package/dist/types/bar-chart.d.ts.map +1 -1
  115. package/dist/types/bar-chart.js +1 -39
  116. package/dist/types/bars.d.ts +29 -0
  117. package/dist/types/bars.d.ts.map +1 -0
  118. package/dist/types/bars.js +16 -0
  119. package/dist/types/cartesian.d.ts +3 -0
  120. package/dist/types/cartesian.d.ts.map +1 -1
  121. package/dist/types/headings.d.ts +15 -0
  122. package/dist/types/headings.d.ts.map +1 -1
  123. package/dist/types/headings.js +1 -1
  124. package/dist/types/index.d.ts +3 -0
  125. package/dist/types/index.d.ts.map +1 -1
  126. package/dist/types/index.js +4 -1
  127. package/dist/types/line-chart.d.ts +12 -12
  128. package/dist/types/line-chart.d.ts.map +1 -1
  129. package/dist/types/lines.d.ts +6 -0
  130. package/dist/types/lines.d.ts.map +1 -1
  131. package/dist/types/main.d.ts +14 -1
  132. package/dist/types/main.d.ts.map +1 -1
  133. package/dist/types/themes.d.ts +9 -0
  134. package/dist/types/themes.d.ts.map +1 -1
  135. package/dist/utils/axis.d.ts +12 -2
  136. package/dist/utils/axis.d.ts.map +1 -1
  137. package/dist/utils/axis.js +52 -15
  138. package/dist/utils/axis.test.js +72 -8
  139. package/dist/utils/bars.d.ts +15 -0
  140. package/dist/utils/bars.d.ts.map +1 -0
  141. package/dist/utils/bars.js +71 -0
  142. package/dist/utils/bars.test.d.ts +2 -0
  143. package/dist/utils/bars.test.d.ts.map +1 -0
  144. package/dist/utils/bars.test.js +95 -0
  145. package/dist/utils/data.d.ts +9 -6
  146. package/dist/utils/data.d.ts.map +1 -1
  147. package/dist/utils/data.js +87 -15
  148. package/dist/utils/data.test.js +173 -80
  149. package/dist/utils/format.d.ts +1 -0
  150. package/dist/utils/format.d.ts.map +1 -1
  151. package/dist/utils/format.js +2 -1
  152. package/dist/utils/index.d.ts +1 -0
  153. package/dist/utils/index.d.ts.map +1 -1
  154. package/dist/utils/index.js +2 -1
  155. package/dist/utils/lines.test.js +25 -0
  156. package/dist/utils/metadata.d.ts +7 -8
  157. package/dist/utils/metadata.d.ts.map +1 -1
  158. package/dist/utils/metadata.js +3 -20
  159. package/dist/utils/metadata.test.js +3 -56
  160. package/dist/utils/viewport.test.js +8 -0
  161. package/package.json +4 -2
@@ -1,24 +1,31 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*
3
- * Copyright 2023 Wonderflow Design Team
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
3
+ * Copyright 2023-2024 Wonderflow Design Team
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
17
  import { Group } from '@visx/group';
18
- import { useCartesianContext } from '../../../providers/cartesian';
19
- import { BarsItemGroup, } from './bars.module.css';
18
+ import { useSSR } from '../../../hooks';
19
+ import { useCartesianContext } from '../../../providers';
20
+ import { BarsAverage } from './bars-average';
21
+ import { BarsOverlay } from './bars-overlay';
22
+ import { BarsSeries } from './bars-series';
23
+ import { BarsTooltip } from './bars-tooltip';
24
+ import { BarsTrendline } from './bars-trendline';
20
25
  export const Bars = () => {
21
26
  const { position } = useCartesianContext();
22
- return (_jsx(Group, { top: position.top, left: position.left, children: _jsx(Group, { className: BarsItemGroup, "data-testid": "bars" }) }));
27
+ const { top, left } = position;
28
+ const { isBrowser, isServer } = useSSR();
29
+ return (_jsxs(Group, { top: top, left: left, children: [isServer && (_jsxs(Group, { "data-testid": "bars", children: [_jsx(BarsTrendline, {}), _jsx(BarsSeries, { "data-testid": "bars-series" }), _jsx(BarsOverlay, { "data-testid": "bars-overlay" })] })), isBrowser && (_jsx(BarsTooltip, { children: _jsxs(Group, { "data-testid": "bars", children: [_jsx(BarsTrendline, {}), _jsx(BarsSeries, { "data-testid": "bars-series" }), _jsx(BarsOverlay, { "data-testid": "bars-overlay" })] }) })), _jsx(BarsAverage, {})] }));
23
30
  };
24
31
  Bars.displayName = 'Bars';
@@ -1 +1 @@
1
- .BarsItemGroup{filter:saturate(100%)}
1
+ .BarsItem{filter:saturate(100%) opacity(1)}.BarsItemBlurred{filter:opacity(.2) blur(2px)}.BarsTooltipContent{display:block;padding:0 1rem .5rem}.BarsTooltipContent p{font-size:12px}.BarsTooltipContent ul{list-style:none;padding:0;width:100%}.BarsTooltipContent li{grid-gap:8px 4px;display:grid;grid-template-columns:1fr auto .5fr;grid-template-rows:1fr}.BarsTooltipContent li div:nth-child(n+2){text-align:right}.BarsTooltipItem{align-items:center;display:flex;flex-direction:row;font-size:12px;gap:4px;justify-content:flex-start}.ExtraContent{border-style:solid;border-width:1px;border-bottom:none;border-left:none;border-right:none;padding:.25rem 1rem}.NoData{font-size:12px}
@@ -18,13 +18,37 @@ const mockMetadata = {
18
18
  dataKey: ['a'],
19
19
  names: ['A'],
20
20
  colors: ['ca'],
21
+ average: undefined,
22
+ trendline: [{
23
+ name: 'A',
24
+ slope: 1,
25
+ intercept: 1,
26
+ coefficients: [1],
27
+ score: { r: 1 },
28
+ trendline: [1],
29
+ from: 1,
30
+ to: 1,
31
+ }],
21
32
  },
22
33
  overlay: {
23
- dataKey: 'b',
24
- name: 'B',
25
- color: 'ob',
34
+ dataKey: ['b'],
35
+ names: ['B'],
36
+ colors: ['ob'],
37
+ average: undefined,
38
+ trendline: [{
39
+ name: 'A',
40
+ slope: 1,
41
+ intercept: 1,
42
+ coefficients: [1],
43
+ score: { r: 1 },
44
+ trendline: [1],
45
+ from: 1,
46
+ to: 1,
47
+ }],
26
48
  },
27
49
  hidePadding: true,
50
+ showAverage: true,
51
+ showTrendline: true,
28
52
  };
29
53
  const mockedAxisSystem = {
30
54
  top: {
@@ -45,7 +69,7 @@ const mockedAxisSystem = {
45
69
  },
46
70
  bottom: {
47
71
  domain: ['01-01-2020', '01-01-2024'],
48
- scaleType: 'time',
72
+ scaleType: 'label',
49
73
  orientation: 'bottom',
50
74
  top: 600,
51
75
  left: 0,
@@ -62,10 +86,17 @@ const mockedAxisSystem = {
62
86
  };
63
87
  describe('<Bars>', () => {
64
88
  it('should render the component', () => {
65
- render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], filteredData: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { position: {
89
+ render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], filteredData: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { hoveredLegendItem: "", position: {
90
+ top: 24, right: 24, bottom: 24, left: 24,
91
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, preventTooltipOpening: false, hasReversedIndex: false, hasMirroredDomainsHorizontal: false, hasMirroredDomainsVertical: false, children: _jsx(Bars, {}) }) }) }) }));
92
+ const elementBarsGroup = screen.getByTestId('bars');
93
+ expect(elementBarsGroup).toBeDefined();
94
+ });
95
+ it('should render the component with vertical layout', () => {
96
+ render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.VERTICAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], filteredData: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { hoveredLegendItem: "", position: {
66
97
  top: 24, right: 24, bottom: 24, left: 24,
67
- }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, hoveredLegendItem: "", children: _jsx(Bars, {}) }) }) }) }));
68
- const element = screen.getByTestId('bars');
69
- expect(element).toBeDefined();
98
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, preventTooltipOpening: false, hasReversedIndex: false, hasMirroredDomainsHorizontal: false, hasMirroredDomainsVertical: false, children: _jsx(Bars, {}) }) }) }) }));
99
+ const elementBarsGroup = screen.getByTestId('bars');
100
+ expect(elementBarsGroup).toBeDefined();
70
101
  });
71
102
  });
@@ -1,2 +1,7 @@
1
1
  export { Bars } from './bars';
2
+ export { BarsAverage } from './bars-average';
3
+ export { BarsOverlay } from './bars-overlay';
4
+ export { BarsSeries } from './bars-series';
5
+ export { BarsTooltip } from './bars-tooltip';
6
+ export { BarsTrendline } from './bars-trendline';
2
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2023 Wonderflow Design Team
2
+ * Copyright 2023-2024 Wonderflow Design Team
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,3 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export { Bars } from './bars';
17
+ export { BarsAverage } from './bars-average';
18
+ export { BarsOverlay } from './bars-overlay';
19
+ export { BarsSeries } from './bars-series';
20
+ export { BarsTooltip } from './bars-tooltip';
21
+ export { BarsTrendline } from './bars-trendline';
@@ -1 +1 @@
1
- {"version":3,"file":"lines-average.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-average.tsx"],"names":[],"mappings":";AA0BA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EA2IhC,CAAC"}
1
+ {"version":3,"file":"lines-average.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-average.tsx"],"names":[],"mappings":";AA2BA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EA+FhC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*
3
3
  * Copyright 2023-2024 Wonderflow Design Team
4
4
  *
@@ -17,53 +17,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
17
17
  import { Label } from '@visx/annotation';
18
18
  import { Group } from '@visx/group';
19
19
  import { Line } from '@visx/shape';
20
- import { useMemo } from 'react';
21
- import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
20
+ import { useAverage } from '../../../hooks';
21
+ // import { useAverage } from '../../../hooks';
22
+ import { useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
22
23
  export const LinesAverage = () => {
23
24
  const theme = useThemeContext();
24
- const { lines: defaultStyle, themes, viewport } = useStyleConfigContext();
25
- const { metadata } = useDataContext();
25
+ const { themes } = useStyleConfigContext();
26
26
  const { isHorizontal } = useLayoutContext();
27
- const { axis, dimension } = useCartesianContext();
28
- const { top, right, bottom, left, } = axis;
29
- const seriesAxis = isHorizontal ? left : bottom;
30
- const overlayAxis = isHorizontal ? right : top;
31
- const { showAverage, series, overlay } = metadata;
32
- const { maxHeight, maxWidth } = dimension;
33
- const { backgroundPadding, backgroundProps, maxLabelWidth, opacity, pointerEvents, strokeDasharray, strokeWidth, titleFontSize, titleFontWeight, titleProps, } = defaultStyle.average;
34
- const averageSeries = series.average?.average;
35
- const averageOverlay = overlay.average?.average;
36
- const averageSeriesScale = seriesAxis.scale(averageSeries) ?? 0;
37
- const averageOverlayScale = (overlayAxis && averageOverlay) ? overlayAxis.scale(averageOverlay) : 0;
38
- const hasAverageSeries = Boolean(showAverage && averageSeries);
39
- const hasAverageOverlay = Boolean(showAverage && averageOverlay);
40
- const hasLabel = dimension.maxWidth > viewport.small.maxWidth;
41
- const coordinates = useMemo(() => (isHorizontal
42
- ? {
43
- series: {
44
- from: { x: 0, y: averageSeriesScale },
45
- to: { x: maxWidth, y: averageSeriesScale },
46
- label: { x: 4, y: averageSeriesScale },
47
- },
48
- overlay: {
49
- from: { x: 0, y: averageOverlayScale },
50
- to: { x: maxWidth, y: averageOverlayScale },
51
- label: { x: maxWidth - 4, y: averageOverlayScale },
52
- },
53
- }
54
- : {
55
- series: {
56
- from: { x: averageSeriesScale, y: 0 },
57
- to: { x: averageSeriesScale, y: maxHeight },
58
- label: { x: averageSeriesScale, y: maxHeight - 16 },
59
- },
60
- overlay: {
61
- from: { x: averageOverlayScale ?? 0, y: 0 },
62
- to: { x: averageOverlayScale ?? 0, y: maxHeight },
63
- label: { x: averageOverlayScale, y: 16 },
64
- },
65
- }), [isHorizontal, averageSeriesScale, maxWidth, averageOverlayScale, maxHeight]);
66
- const formatAverage = (value) => value.toFixed(2);
67
- return (_jsxs(_Fragment, { children: [hasAverageSeries && (_jsxs(Group, { children: [_jsx(Line, { from: coordinates.series.from, to: coordinates.series.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }), hasLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.series.label.x, y: coordinates.series.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${formatAverage(averageSeries)}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'start' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth }))] })), hasAverageOverlay && (_jsxs(Group, { children: [_jsx(Line, { from: coordinates.overlay.from, to: coordinates.overlay.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }), hasLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.overlay.label.x, y: coordinates.overlay.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${formatAverage(averageOverlay)}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'end' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth }))] }))] }));
27
+ const { averageSeries, averageOverlay, hasAverageSeries, hasAverageOverlay, hasAverageOverlayLabel, hasAverageSeriesLabel, coordinates, style, } = useAverage();
28
+ const { backgroundPadding, backgroundProps, maxLabelWidth, opacity, pointerEvents, strokeDasharray, strokeWidth, titleFontSize, titleFontWeight, titleProps, } = style;
29
+ return (_jsxs(Group, { children: [hasAverageSeries && (_jsx(Line, { from: coordinates.series.from, to: coordinates.series.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity })), hasAverageOverlay && (_jsx(Line, { from: coordinates.overlay.from, to: coordinates.overlay.to, stroke: themes[theme].lines.average, strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity })), hasAverageSeriesLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.series.label.x, y: coordinates.series.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${averageSeries}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'start' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth })), hasAverageOverlayLabel && (_jsx(Label, { backgroundFill: themes[theme].lines.average, x: coordinates.overlay.label.x, y: coordinates.overlay.label.y, fontColor: themes[theme].lines.averageFontColor, title: `Average: ${averageOverlay}`, titleFontSize: titleFontSize, titleFontWeight: titleFontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: isHorizontal ? 'end' : 'middle', verticalAnchor: "middle", showBackground: true, backgroundPadding: backgroundPadding, backgroundProps: backgroundProps, maxWidth: maxLabelWidth }))] }));
68
30
  };
69
31
  LinesAverage.displayName = 'LinesAverage';
@@ -1 +1 @@
1
- {"version":3,"file":"lines-marker-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-marker-labels.tsx"],"names":[],"mappings":";AAmCA,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAsJrC,CAAC"}
1
+ {"version":3,"file":"lines-marker-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-marker-labels.tsx"],"names":[],"mappings":";AAmCA,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EA8JrC,CAAC"}
@@ -65,15 +65,15 @@ export const LinesMarkerLabels = () => {
65
65
  const { background, fontColor, fontSize, fontWeight, titleProps, anchor, verticalAnchor, padding, backgroundProps, } = markerLabelProps;
66
66
  return (isVisible
67
67
  ? (_jsx(Label, { "data-testid": "lines-marker-label", backgroundFill: background, x: coordinates.x, y: coordinates.y, fontColor: fontColor, title: title, titleFontSize: fontSize, titleFontWeight: fontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: anchor, verticalAnchor: verticalAnchor, showBackground: true, backgroundPadding: padding, backgroundProps: backgroundProps }, uuid())) : null);
68
- }) }, uuid()))), hasOverlay && (showMarkerLabel || overlay.style?.showMarkerLabel)
69
- && data.map((d, di) => {
70
- const isVisible = isMarkerLabelVisible(di, totalLabels);
71
- const title = `${getPrimitiveFromObjectByPath(d, overlay.dataKey) ?? ''}`;
72
- const coordinates = getOverlayCoordinates(d, overlay.dataKey, isHorizontal);
73
- const markerLabelProps = getMarkerLabelProps(coordinates, dimension, isHorizontal, themeConfig);
74
- const { background, fontColor, fontSize, fontWeight, titleProps, anchor, verticalAnchor, padding, backgroundProps, } = markerLabelProps;
75
- return (isVisible
76
- ? (_jsx(Label, { className: dynamicClassName(overLegend, overlay.dataKey), backgroundFill: background, x: coordinates.x, y: coordinates.y, fontColor: fontColor, title: title, titleFontSize: fontSize, titleFontWeight: fontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: anchor, verticalAnchor: verticalAnchor, showBackground: true, backgroundPadding: padding, backgroundProps: backgroundProps }, uuid())) : null);
77
- })] }));
68
+ }) }, uuid()))), hasOverlay && overlay.dataKey?.map((k, i) => (_jsx(Group, { className: dynamicClassName(overLegend, k), children: (showMarkerLabel || overlay.style?.[i]?.showMarkerLabel)
69
+ && data.map((d, di) => {
70
+ const isVisible = isMarkerLabelVisible(di, totalLabels);
71
+ const title = `${getPrimitiveFromObjectByPath(d, k) ?? ''}`;
72
+ const coordinates = getOverlayCoordinates(d, k, isHorizontal);
73
+ const markerLabelProps = getMarkerLabelProps(coordinates, dimension, isHorizontal, themeConfig);
74
+ const { background, fontColor, fontSize, fontWeight, titleProps, anchor, verticalAnchor, padding, backgroundProps, } = markerLabelProps;
75
+ return (isVisible
76
+ ? (_jsx(Label, { "data-testid": "overlay-lines-marker-label", className: dynamicClassName(overLegend, k), backgroundFill: background, x: coordinates.x, y: coordinates.y, fontColor: fontColor, title: title, titleFontSize: fontSize, titleFontWeight: fontWeight, titleProps: titleProps, showAnchorLine: false, horizontalAnchor: anchor, verticalAnchor: verticalAnchor, showBackground: true, backgroundPadding: padding, backgroundProps: backgroundProps }, uuid())) : null);
77
+ }) }, uuid())))] }));
78
78
  };
79
79
  LinesMarkerLabels.displayName = 'LinesMarkerLabels';
@@ -1 +1 @@
1
- {"version":3,"file":"lines-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-overlay.tsx"],"names":[],"mappings":";AAkCA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAqFhC,CAAC"}
1
+ {"version":3,"file":"lines-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-overlay.tsx"],"names":[],"mappings":";AAoCA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAiFhC,CAAC"}
@@ -17,39 +17,34 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
17
17
  import { Group } from '@visx/group';
18
18
  import { LinePath } from '@visx/shape';
19
19
  import _ from 'lodash';
20
- import { useCallback, useMemo } from 'react';
20
+ import { useCallback } from 'react';
21
21
  import { v4 as uuid } from 'uuid';
22
- import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
23
- import { createSubPaths, getCoordinates, getLinesRenderer, getValueFromObjectByPath, } from '../../../utils';
22
+ import { useLines } from '../../../hooks';
23
+ import { useCartesianContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
24
+ import { createSubPaths, getValueFromObjectByPath, } from '../../../utils';
24
25
  import { LinesItem, LinesItemBlurred, } from './lines.module.css';
25
26
  export const LinesOverlay = () => {
26
27
  const theme = useThemeContext();
27
28
  const { lines: defaultStyle, themes } = useStyleConfigContext();
28
- const { data, metadata } = useDataContext();
29
- const { isHorizontal } = useLayoutContext();
30
- const { axis, hoveredLegendItem: overLegend } = useCartesianContext();
31
- const { index, renderAs, showMarker, showMarkerLabel, overlay, hideMissingDataConnection, } = metadata;
32
- const indexAxis = isHorizontal ? axis.bottom : axis.left;
33
- const overlayAxis = isHorizontal ? axis?.right : axis?.top;
34
- const hasOverlay = Boolean(overlayAxis && overlay.dataKey);
35
- const renderer = useMemo(() => getLinesRenderer(renderAs, isHorizontal), [isHorizontal, renderAs]);
36
- const getOverlayCoordinates = useMemo(() => (datum, dataKey, isHorizontal) => getCoordinates({
37
- datum,
38
- indexAxis,
39
- indexDataKey: index,
40
- otherAxis: overlayAxis,
41
- otherDataKey: dataKey,
42
- isHorizontal,
43
- }), [index, indexAxis, overlayAxis]);
44
- const subPaths = useMemo(() => createSubPaths(data, d => hasOverlay && _.isNil(getValueFromObjectByPath(d, overlay.dataKey))), [data, hasOverlay, overlay.dataKey]);
45
- const hasMarker = Boolean(showMarker
46
- || showMarkerLabel
47
- || overlay.style?.showMarker
48
- || overlay.style?.showMarkerLabel);
49
- const segmentStroke = hideMissingDataConnection ? 'transparent' : themes[theme].lines.noData;
29
+ const { hoveredLegendItem: overLegend } = useCartesianContext();
30
+ const { getOverlayCoordinates, hasOverlay, hideMissingDataConnection, isHorizontal, overlay, renderer, showMarker, showMarkerLabel, data, } = useLines();
50
31
  const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
51
32
  ? LinesItem
52
33
  : LinesItemBlurred), []);
53
- return (_jsx(_Fragment, { children: hasOverlay && (subPaths.map((subPathData, si) => (_jsxs(Group, { className: dynamicClassName(overLegend, overlay.dataKey), children: [_jsx(LinePath, { "data-testid": "lines-overlay", data: subPathData, curve: renderer, x: datum => getOverlayCoordinates(datum, overlay.dataKey, isHorizontal).x, y: datum => getOverlayCoordinates(datum, overlay.dataKey, isHorizontal).y, stroke: si % 2 === 0 ? overlay.color : segmentStroke, strokeWidth: overlay.style?.strokeWidth ?? defaultStyle.path.strokeWidth, strokeOpacity: overlay.style?.strokeOpacity ?? defaultStyle.path.strokeOpacity, strokeDasharray: si % 2 === 0 ? overlay.style?.strokeDasharray : defaultStyle.segment.strokeDashArray }), hasMarker && subPathData.map((d) => (_jsx("circle", { r: defaultStyle.marker.radius, cx: getOverlayCoordinates(d, overlay.dataKey, isHorizontal).x, cy: getOverlayCoordinates(d, overlay.dataKey, isHorizontal).y, stroke: overlay.color, fill: themes[theme].marker.fill, strokeWidth: overlay.style?.strokeWidth ?? defaultStyle.marker.strokeWidth, strokeOpacity: overlay.style?.strokeOpacity ?? defaultStyle.marker.strokeOpacity }, uuid())))] }, uuid())))) }));
34
+ if (!hasOverlay)
35
+ return null;
36
+ return (_jsx(_Fragment, { children: overlay.dataKey.map((dataKey, di) => {
37
+ const subPaths = createSubPaths(data, d => _.isNil(getValueFromObjectByPath(d, dataKey)));
38
+ const hasMarker = Boolean(showMarker
39
+ || showMarkerLabel
40
+ || overlay.style?.[di]?.showMarker
41
+ || overlay.style?.[di]?.showMarkerLabel);
42
+ const segmentStroke = hideMissingDataConnection ? 'transparent' : themes[theme].lines.noData;
43
+ return (subPaths.map((subPathData, si) => (_jsxs(Group, { className: dynamicClassName(overLegend, dataKey), children: [_jsx(LinePath, { "data-testid": "lines-overlay", data: subPathData, curve: renderer, x: datum => getOverlayCoordinates(datum, dataKey, isHorizontal).x, y: datum => getOverlayCoordinates(datum, dataKey, isHorizontal).y, stroke: si % 2 === 0
44
+ ? overlay.colors?.[di]
45
+ : segmentStroke, strokeWidth: overlay.style?.[di]?.strokeWidth ?? defaultStyle.path.strokeWidth, strokeOpacity: overlay.style?.[di]?.strokeOpacity ?? defaultStyle.path.strokeOpacity, strokeDasharray: si % 2 === 0
46
+ ? overlay.style?.[di]?.strokeDasharray
47
+ : defaultStyle.segment.strokeDashArray }), hasMarker && subPathData.map((d) => (_jsx("circle", { r: defaultStyle.marker.radius, cx: getOverlayCoordinates(d, dataKey, isHorizontal).x, cy: getOverlayCoordinates(d, dataKey, isHorizontal).y, stroke: overlay.colors[di], fill: themes[theme].marker.fill, strokeWidth: overlay.style?.[di]?.strokeWidth ?? defaultStyle.marker.strokeWidth, strokeOpacity: overlay.style?.[di]?.strokeOpacity ?? defaultStyle.marker.strokeOpacity }, uuid())))] }, uuid()))));
48
+ }) }));
54
49
  };
55
50
  LinesOverlay.displayName = 'LinesOverlay';
@@ -1 +1 @@
1
- {"version":3,"file":"lines-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-series.tsx"],"names":[],"mappings":";AAkCA,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EA6F/B,CAAC"}
1
+ {"version":3,"file":"lines-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-series.tsx"],"names":[],"mappings":";AAoCA,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EA6E/B,CAAC"}
@@ -17,30 +17,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
17
17
  import { Group } from '@visx/group';
18
18
  import { LinePath } from '@visx/shape';
19
19
  import _ from 'lodash';
20
- import { useCallback, useMemo } from 'react';
20
+ import { useCallback } from 'react';
21
21
  import { v4 as uuid } from 'uuid';
22
- import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
23
- import { createSubPaths, getCoordinates, getLinesRenderer, getValueFromObjectByPath, } from '../../../utils';
22
+ import { useLines } from '../../../hooks';
23
+ import { useCartesianContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
24
+ import { createSubPaths, getValueFromObjectByPath, } from '../../../utils';
24
25
  import { LinesItem, LinesItemBlurred, } from './lines.module.css';
25
26
  export const LinesSeries = () => {
26
27
  const theme = useThemeContext();
27
28
  const { lines: defaultStyle, themes } = useStyleConfigContext();
28
- const { data, metadata } = useDataContext();
29
- const { isHorizontal } = useLayoutContext();
30
- const { axis, hoveredLegendItem: overLegend } = useCartesianContext();
31
- const { left, bottom } = axis;
32
- const { index, renderAs, showMarker, showMarkerLabel, series, hideMissingDataConnection, } = metadata;
33
- const indexAxis = isHorizontal ? bottom : left;
34
- const seriesAxis = isHorizontal ? left : bottom;
35
- const renderer = useMemo(() => getLinesRenderer(renderAs, isHorizontal), [isHorizontal, renderAs]);
36
- const getSeriesCoordinates = useMemo(() => (datum, dataKey, isHorizontal) => getCoordinates({
37
- datum,
38
- indexAxis: indexAxis,
39
- indexDataKey: index,
40
- otherAxis: seriesAxis,
41
- otherDataKey: dataKey,
42
- isHorizontal,
43
- }), [index, indexAxis, seriesAxis]);
29
+ const { hoveredLegendItem: overLegend } = useCartesianContext();
30
+ const { hideMissingDataConnection, isHorizontal, getSeriesCoordinates, data, renderer, series, showMarker, showMarkerLabel, } = useLines();
44
31
  const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
45
32
  ? LinesItem
46
33
  : LinesItemBlurred), []);
@@ -1 +1 @@
1
- {"version":3,"file":"lines-tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-tooltip.tsx"],"names":[],"mappings":";AA6CA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAqPhC,CAAC"}
1
+ {"version":3,"file":"lines-tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-tooltip.tsx"],"names":[],"mappings":";AA0DA,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAyPhC,CAAC"}
@@ -24,7 +24,8 @@ import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
24
24
  import _ from 'lodash';
25
25
  import { useCallback } from 'react';
26
26
  import { v4 as uuid } from 'uuid';
27
- import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
27
+ import { useLines } from '../../../hooks';
28
+ import { useStyleConfigContext, useThemeContext, } from '../../../providers';
28
29
  import { tooltipTheme } from '../../../style-config/tooltip';
29
30
  import { accessorInvert, bisectIndex, getLabelFromPath, getPrimitiveFromObjectByPath, } from '../../../utils';
30
31
  import { Placeholder } from '../../placeholder';
@@ -33,22 +34,13 @@ import { ExtraContent, LinesTooltipContent, LinesTooltipItem, NoData, } from './
33
34
  export const LinesTooltip = () => {
34
35
  const theme = useThemeContext();
35
36
  const { lines: defaultStyle } = useStyleConfigContext();
36
- const { data, metadata } = useDataContext();
37
- const { isHorizontal } = useLayoutContext();
38
- const { axis, dimension } = useCartesianContext();
39
- const { maxHeight: yMax, maxWidth: xMax } = dimension;
40
- const { top, right, bottom, left, } = axis;
41
- const { index, tooltip, series, overlay, } = metadata;
42
- const indexAxis = isHorizontal ? bottom : left;
43
- const seriesAxis = isHorizontal ? left : bottom;
44
- const overlayAxis = isHorizontal ? right : top;
45
- const hasOverlay = Boolean(overlayAxis && overlay.dataKey);
37
+ const { index, tooltip, series, overlay, preventTooltipDisplay, isHorizontal, maxHeight: yMax, maxWidth: xMax, preventTooltipOpening, data, hasOverlay, indexAxis, seriesAxis, overlayAxis, } = useLines();
46
38
  const { tooltipLeft, tooltipTop, tooltipOpen, tooltipData, hideTooltip, showTooltip, } = useTooltip();
47
39
  const { containerRef, containerBounds } = useTooltipInPortal({
48
40
  detectBounds: true,
49
41
  scroll: true,
50
42
  debounce: 500,
51
- zIndex: 10,
43
+ zIndex: 4,
52
44
  });
53
45
  const handleTooltip = useCallback((event) => {
54
46
  const { scaleType, domain, scale, } = indexAxis;
@@ -69,7 +61,7 @@ export const LinesTooltip = () => {
69
61
  const tooltipTop = ('clientY' in event ? event.clientY : 0) - tBound / 8;
70
62
  const datum = data[indexOfBisectValue];
71
63
  const hasSeriesData = series.dataKey.every(s => !_.isNil(getPrimitiveFromObjectByPath(datum, s)));
72
- const hasOverlayData = !_.isNil(getPrimitiveFromObjectByPath(datum, overlay.dataKey));
64
+ const hasOverlayData = overlay.dataKey?.every(s => !_.isNil(getPrimitiveFromObjectByPath(datum, s)));
73
65
  const tooltipData = {
74
66
  coords,
75
67
  data: datum,
@@ -82,22 +74,23 @@ export const LinesTooltip = () => {
82
74
  tooltipData,
83
75
  });
84
76
  }, [indexAxis, containerBounds, isHorizontal, data, series.dataKey, overlay.dataKey, showTooltip]);
85
- return (_jsxs(_Fragment, { children: [_jsx("rect", { id: "transparent-overlay-layer", "data-testid": "transparent-overlay-layer", x: -5, y: -5, width: xMax + 10, height: yMax + 10, fill: "transparent", ref: containerRef, onMouseMove: e => handleTooltip(e), onTouchMove: e => handleTooltip(e), onTouchStart: e => handleTooltip(e), onMouseOut: hideTooltip, onMouseLeave: hideTooltip }), tooltipData?.data && (_jsxs(_Fragment, { children: [_jsxs(Group, { children: [_jsx(Line, { from: {
86
- x: isHorizontal ? tooltipData.lineIndicatorPos : 0,
87
- y: isHorizontal ? 0 : tooltipData.lineIndicatorPos,
77
+ const hasTooltip = Boolean(tooltipData?.data && !preventTooltipOpening && !preventTooltipDisplay);
78
+ return (_jsxs(_Fragment, { children: [_jsx("rect", { id: "transparent-overlay-layer", "data-testid": "transparent-overlay-layer", x: -5, y: -5, width: Number(xMax) + 10, height: Number(yMax) + 10, fill: "transparent", ref: containerRef, onMouseMove: e => handleTooltip(e), onTouchMove: e => handleTooltip(e), onTouchStart: e => handleTooltip(e), onMouseOut: hideTooltip, onMouseLeave: hideTooltip }), hasTooltip && (_jsxs(_Fragment, { children: [_jsxs(Group, { children: [_jsx(Line, { from: {
79
+ x: isHorizontal ? tooltipData?.lineIndicatorPos : 0,
80
+ y: isHorizontal ? 0 : tooltipData?.lineIndicatorPos,
88
81
  }, to: {
89
- x: isHorizontal ? tooltipData.lineIndicatorPos : xMax,
90
- y: isHorizontal ? yMax : tooltipData.lineIndicatorPos,
91
- }, stroke: tooltipTheme[theme].lineIndicatorStroke, strokeWidth: defaultStyle.lineIndicator.strokeWidth, opacity: defaultStyle.lineIndicator.opacity, pointerEvents: defaultStyle.lineIndicator.pointerEvents, strokeDasharray: defaultStyle.lineIndicator.strokeDasharray }), series.dataKey.map((dataKey, di) => (tooltipData.data[dataKey] && (_jsx("circle", { r: defaultStyle.dataPoint.radius, cx: isHorizontal
82
+ x: isHorizontal ? tooltipData?.lineIndicatorPos : xMax,
83
+ y: isHorizontal ? yMax : tooltipData?.lineIndicatorPos,
84
+ }, stroke: tooltipTheme[theme].lineIndicatorStroke, strokeWidth: defaultStyle.lineIndicator.strokeWidth, opacity: defaultStyle.lineIndicator.opacity, pointerEvents: defaultStyle.lineIndicator.pointerEvents, strokeDasharray: defaultStyle.lineIndicator.strokeDasharray }), series.dataKey.map((dataKey, di) => (tooltipData?.data[dataKey] && (_jsx("circle", { r: defaultStyle.dataPoint.radius, cx: isHorizontal
92
85
  ? tooltipData.lineIndicatorPos
93
- : seriesAxis.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey)), cy: isHorizontal
94
- ? seriesAxis.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey))
95
- : tooltipData.lineIndicatorPos, stroke: series.colors[di], fill: series.colors[di], strokeWidth: defaultStyle.dataPoint.strokeWidth }, uuid())))), hasOverlay && tooltipData.data[overlay.dataKey] && (_jsx("circle", { r: defaultStyle.dataPoint.radius, cx: isHorizontal
86
+ : seriesAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey)), cy: isHorizontal
87
+ ? seriesAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey))
88
+ : tooltipData.lineIndicatorPos, stroke: series.colors[di], fill: series.colors[di], strokeWidth: defaultStyle.dataPoint.strokeWidth }, uuid())))), hasOverlay && overlay.dataKey?.map((dataKey, di) => (tooltipData?.data[dataKey] && (_jsx("circle", { r: defaultStyle.dataPoint.radius, cx: isHorizontal
96
89
  ? tooltipData.lineIndicatorPos
97
- : overlayAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, overlay.dataKey)), cy: isHorizontal
98
- ? overlayAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, overlay.dataKey))
99
- : tooltipData.lineIndicatorPos, stroke: overlay.color, fill: overlay.color, strokeWidth: defaultStyle.dataPoint.strokeWidth }))] }), _jsxs(Tooltip, { theme: theme, isOpen: tooltipOpen, top: tooltipTop, left: tooltipLeft, children: [_jsxs("div", { className: LinesTooltipContent, "data-testid": "tooltip", children: [_jsx("p", { children: _jsx("b", { children: indexAxis.tickFormat
100
- ? indexAxis.tickFormat(getPrimitiveFromObjectByPath(tooltipData.data, index) ?? '')
101
- : getPrimitiveFromObjectByPath(tooltipData.data, index) ?? '' }) }), _jsxs("ul", { children: [series.dataKey.map((dataKey, di) => (_jsxs("li", { children: [_jsxs("div", { className: LinesTooltipItem, children: [_jsx(Placeholder, { color: series.colors[di] }), _jsx("span", { children: series.names[di] })] }), _jsx("div", { children: tooltip?.extraSeriesData && (_jsx("p", { children: tooltip.extraSeriesData(_.at(tooltipData.data, getLabelFromPath(dataKey))[0]) })) }), _jsx("div", { children: _jsx("p", { children: _jsx("b", { children: `${getPrimitiveFromObjectByPath(tooltipData.data, dataKey) ?? 'n/a'}` }) }) })] }, uuid()))), hasOverlay && (_jsxs("li", { children: [_jsxs("div", { className: LinesTooltipItem, children: [_jsx(Placeholder, { color: overlay.color }), _jsx("span", { children: overlay.name })] }), _jsx("div", { children: tooltip?.extraOverlayData && (_jsx("p", { children: tooltip.extraOverlayData(_.at(tooltipData.data, getLabelFromPath(overlay.dataKey))[0]) })) }), _jsx("div", { children: _jsx("p", { children: _jsx("b", { children: `${getPrimitiveFromObjectByPath(tooltipData.data, overlay.dataKey) ?? 'n/a'}` }) }) })] }))] })] }), (tooltip?.extraContent || !tooltipData.hasData) && (_jsxs("div", { className: ExtraContent, style: { borderColor: tooltipTheme[theme].separatorStroke }, children: [tooltip?.extraContent && tooltip.extraContent, !tooltipData.hasData && _jsx("p", { className: NoData, children: "No data available" })] }))] })] }))] }));
90
+ : overlayAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey)), cy: isHorizontal
91
+ ? overlayAxis?.scale(getPrimitiveFromObjectByPath(tooltipData.data, dataKey))
92
+ : tooltipData.lineIndicatorPos, stroke: overlay.colors?.[di], fill: overlay.colors?.[di], strokeWidth: defaultStyle.dataPoint.strokeWidth }, uuid()))))] }), _jsxs(Tooltip, { theme: theme, isOpen: tooltipOpen, top: tooltipTop, left: tooltipLeft, children: [_jsxs("div", { className: LinesTooltipContent, "data-testid": "tooltip", children: [_jsx("p", { children: _jsx("b", { children: indexAxis?.tickFormat
93
+ ? indexAxis.tickFormat(getPrimitiveFromObjectByPath(tooltipData?.data, index) ?? '')
94
+ : getPrimitiveFromObjectByPath(tooltipData?.data, index) ?? '' }) }), _jsxs("ul", { children: [series.dataKey.map((dataKey, di) => (_jsxs("li", { children: [_jsxs("div", { className: LinesTooltipItem, children: [_jsx(Placeholder, { color: series.colors[di] }), _jsx("span", { children: series.names[di] })] }), _jsx("div", { children: tooltip?.extraSeriesData && (_jsx("p", { children: tooltip.extraSeriesData(_.at(tooltipData?.data, getLabelFromPath(dataKey))[0]) })) }), _jsx("div", { children: _jsx("p", { children: _jsx("b", { children: `${getPrimitiveFromObjectByPath(tooltipData?.data, dataKey) ?? 'n/a'}` }) }) })] }, uuid()))), hasOverlay && overlay.dataKey?.map((dataKey, di) => (_jsxs("li", { children: [_jsxs("div", { className: LinesTooltipItem, children: [_jsx(Placeholder, { color: overlay.colors?.[di] }), _jsx("span", { children: overlay.names?.[di] })] }), _jsx("div", { children: tooltip?.extraSeriesData && (_jsx("p", { children: tooltip.extraSeriesData(_.at(tooltipData?.data, getLabelFromPath(dataKey))[0]) })) }), _jsx("div", { children: _jsx("p", { children: _jsx("b", { children: `${getPrimitiveFromObjectByPath(tooltipData?.data, dataKey) ?? 'n/a'}` }) }) })] }, uuid())))] })] }), (tooltip?.extraContent || !tooltipData?.hasData) && (_jsxs("div", { className: ExtraContent, style: { borderColor: tooltipTheme[theme].separatorStroke }, children: [tooltip?.extraContent && tooltip.extraContent, !tooltipData?.hasData && _jsx("p", { className: NoData, children: "No data available" })] }))] })] }))] }));
102
95
  };
103
96
  LinesTooltip.displayName = 'LinesTooltip';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const LinesTrendline: React.FC;
3
+ //# sourceMappingURL=lines-trendline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines-trendline.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines-trendline.tsx"],"names":[],"mappings":";AA+BA,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAqElC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright 2023-2024 Wonderflow Design Team
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Group } from '@visx/group';
18
+ import { Line } from '@visx/shape';
19
+ import _ from 'lodash';
20
+ import { useCallback } from 'react';
21
+ import { useTrendline } from '../../../hooks';
22
+ import { useCartesianContext, } from '../../../providers';
23
+ import { LinesItem, LinesItemBlurred, } from './lines.module.css';
24
+ export const LinesTrendline = () => {
25
+ const { hoveredLegendItem: overLegend } = useCartesianContext();
26
+ const { series, overlay, seriesAxis, overlayAxis, hasTrendlineSeries, hasTrendlineOverlay, getCoordinates, style, } = useTrendline();
27
+ const { opacity, pointerEvents, strokeDasharray, strokeWidth, } = style;
28
+ const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
29
+ ? LinesItem
30
+ : LinesItemBlurred), []);
31
+ return (_jsxs(Group, { children: [hasTrendlineSeries && series.trendline.map((t, i) => {
32
+ const from = seriesAxis?.scale(t.from) ?? 0;
33
+ const to = seriesAxis?.scale(t.to) ?? 0;
34
+ const coordinates = getCoordinates(from, to);
35
+ return (_jsx(Line, { className: dynamicClassName(overLegend, series.dataKey[i]), from: coordinates.from, to: coordinates.to, stroke: series.colors[i], strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }, _.uniqueId()));
36
+ }), hasTrendlineOverlay && overlay.trendline.map((t, i) => {
37
+ const from = overlayAxis?.scale(t.from) ?? 0;
38
+ const to = overlayAxis?.scale(t.to) ?? 0;
39
+ const coordinates = getCoordinates(from, to);
40
+ return (_jsx(Line, { className: dynamicClassName(overLegend, overlay.dataKey[i]), from: coordinates.from, to: coordinates.to, stroke: overlay.colors[i], strokeWidth: strokeWidth, pointerEvents: pointerEvents, strokeDasharray: strokeDasharray, opacity: opacity }, _.uniqueId()));
41
+ })] }));
42
+ };
43
+ LinesTrendline.displayName = 'LinesTrendline';
@@ -1 +1 @@
1
- {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines.tsx"],"names":[],"mappings":";AA0BA,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAqBzB,CAAC"}
1
+ {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines.tsx"],"names":[],"mappings":";AA2BA,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAsBzB,CAAC"}
@@ -22,9 +22,10 @@ import { LinesMarkerLabels } from './lines-marker-labels';
22
22
  import { LinesOverlay } from './lines-overlay';
23
23
  import { LinesSeries } from './lines-series';
24
24
  import { LinesTooltip } from './lines-tooltip';
25
+ import { LinesTrendline } from './lines-trendline';
25
26
  export const Lines = () => {
26
27
  const { position } = useCartesianContext();
27
28
  const { isBrowser } = useSSR();
28
- return (_jsxs(Group, { top: position.top, left: position.left, children: [_jsxs(Group, { "data-testid": "lines", children: [_jsx(LinesSeries, {}), _jsx(LinesOverlay, {})] }), isBrowser && _jsx(LinesTooltip, {}), _jsx(LinesAverage, {}), _jsx(LinesMarkerLabels, {})] }));
29
+ return (_jsxs(Group, { top: position.top, left: position.left, children: [_jsxs(Group, { "data-testid": "lines", children: [_jsx(LinesTrendline, {}), _jsx(LinesSeries, {}), _jsx(LinesOverlay, {})] }), isBrowser && _jsx(LinesTooltip, {}), _jsx(LinesAverage, {}), _jsx(LinesMarkerLabels, {})] }));
29
30
  };
30
31
  Lines.displayName = 'Lines';