@wonderflow/charts 12.8.0 → 12.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 (148) hide show
  1. package/dist/components/bar-chart/bar-chart.d.ts +54 -0
  2. package/dist/components/bar-chart/bar-chart.d.ts.map +1 -0
  3. package/dist/components/bar-chart/bar-chart.js +56 -0
  4. package/dist/components/bar-chart/bar-chart.test.d.ts +2 -0
  5. package/dist/components/bar-chart/bar-chart.test.d.ts.map +1 -0
  6. package/dist/components/bar-chart/bar-chart.test.js +15 -0
  7. package/dist/components/bar-chart/index.d.ts +3 -0
  8. package/dist/components/bar-chart/index.d.ts.map +1 -0
  9. package/dist/components/bar-chart/index.js +16 -0
  10. package/dist/components/cartesian-base/cartesian-base-axis.js +15 -15
  11. package/dist/components/cartesian-base/cartesian-base-brush.d.ts +21 -0
  12. package/dist/components/cartesian-base/cartesian-base-brush.d.ts.map +1 -0
  13. package/dist/components/cartesian-base/cartesian-base-brush.js +59 -0
  14. package/dist/components/cartesian-base/cartesian-base-grid.d.ts +1 -1
  15. package/dist/components/cartesian-base/cartesian-base-grid.d.ts.map +1 -1
  16. package/dist/components/cartesian-base/cartesian-base-legend.d.ts +3 -2
  17. package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
  18. package/dist/components/cartesian-base/cartesian-base-legend.js +9 -8
  19. package/dist/components/cartesian-base/cartesian-base.d.ts +26 -6
  20. package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
  21. package/dist/components/cartesian-base/cartesian-base.js +41 -76
  22. package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
  23. package/dist/components/cartesian-base/cartesian-base.test.d.ts +1 -1
  24. package/dist/components/cartesian-base/cartesian-base.test.d.ts.map +1 -1
  25. package/dist/components/cartesian-base/cartesian-base.test.js +33 -6
  26. package/dist/components/index.d.ts +1 -0
  27. package/dist/components/index.d.ts.map +1 -1
  28. package/dist/components/index.js +1 -0
  29. package/dist/components/line-chart/line-chart.d.ts +59 -2
  30. package/dist/components/line-chart/line-chart.d.ts.map +1 -1
  31. package/dist/components/line-chart/line-chart.js +16 -41
  32. package/dist/components/loader/loader.test.js +3 -1
  33. package/dist/components/shapes/bars/bars.d.ts +3 -0
  34. package/dist/components/shapes/bars/bars.d.ts.map +1 -0
  35. package/dist/components/shapes/bars/bars.js +24 -0
  36. package/dist/components/shapes/bars/bars.module.css +1 -0
  37. package/dist/components/shapes/bars/bars.test.d.ts +2 -0
  38. package/dist/components/shapes/bars/bars.test.d.ts.map +1 -0
  39. package/dist/components/shapes/bars/bars.test.js +71 -0
  40. package/dist/components/shapes/bars/index.d.ts +2 -0
  41. package/dist/components/shapes/bars/index.d.ts.map +1 -0
  42. package/dist/components/shapes/bars/index.js +16 -0
  43. package/dist/components/shapes/index.d.ts +1 -0
  44. package/dist/components/shapes/index.d.ts.map +1 -1
  45. package/dist/components/shapes/index.js +1 -0
  46. package/dist/components/shapes/lines/lines-average.d.ts +3 -0
  47. package/dist/components/shapes/lines/lines-average.d.ts.map +1 -0
  48. package/dist/components/shapes/lines/lines-average.js +69 -0
  49. package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
  50. package/dist/components/shapes/lines/lines-marker-labels.js +14 -7
  51. package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
  52. package/dist/components/shapes/lines/lines-overlay.js +8 -5
  53. package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
  54. package/dist/components/shapes/lines/lines-series.js +10 -7
  55. package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
  56. package/dist/components/shapes/lines/lines-tooltip.js +16 -20
  57. package/dist/components/shapes/lines/lines.d.ts.map +1 -1
  58. package/dist/components/shapes/lines/lines.js +18 -16
  59. package/dist/components/shapes/lines/lines.module.css +1 -1
  60. package/dist/components/shapes/lines/lines.test.js +13 -7
  61. package/dist/hooks/hooks.test.d.ts +2 -0
  62. package/dist/hooks/hooks.test.d.ts.map +1 -0
  63. package/dist/hooks/hooks.test.js +153 -0
  64. package/dist/hooks/index.d.ts +8 -0
  65. package/dist/hooks/index.d.ts.map +1 -0
  66. package/dist/hooks/index.js +19 -0
  67. package/dist/hooks/useBrush.d.ts +74 -0
  68. package/dist/hooks/useBrush.d.ts.map +1 -0
  69. package/dist/hooks/useBrush.js +175 -0
  70. package/dist/hooks/useCartesian.d.ts +73 -0
  71. package/dist/hooks/useCartesian.d.ts.map +1 -0
  72. package/dist/hooks/useCartesian.js +143 -0
  73. package/dist/hooks/useLineChart.d.ts +39 -0
  74. package/dist/hooks/useLineChart.d.ts.map +1 -0
  75. package/dist/hooks/useLineChart.js +79 -0
  76. package/dist/hooks/useSSR.d.ts +5 -0
  77. package/dist/hooks/useSSR.d.ts.map +1 -0
  78. package/dist/hooks/useSSR.js +24 -0
  79. package/dist/index.d.ts +2 -0
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +3 -1
  82. package/dist/providers/cartesian.d.ts +1 -0
  83. package/dist/providers/cartesian.d.ts.map +1 -1
  84. package/dist/providers/cartesian.js +20 -18
  85. package/dist/providers/data.d.ts +3 -1
  86. package/dist/providers/data.d.ts.map +1 -1
  87. package/dist/providers/data.js +19 -17
  88. package/dist/providers/layout.d.ts.map +1 -1
  89. package/dist/providers/layout.js +17 -16
  90. package/dist/providers/style-config.d.ts.map +1 -1
  91. package/dist/providers/style-config.js +17 -16
  92. package/dist/providers/theme.d.ts.map +1 -1
  93. package/dist/providers/theme.js +16 -16
  94. package/dist/style-config/brush.d.ts +3 -0
  95. package/dist/style-config/brush.d.ts.map +1 -0
  96. package/dist/style-config/brush.js +28 -0
  97. package/dist/style-config/cartesian.d.ts.map +1 -1
  98. package/dist/style-config/cartesian.js +5 -3
  99. package/dist/style-config/index.d.ts +1 -0
  100. package/dist/style-config/index.d.ts.map +1 -1
  101. package/dist/style-config/index.js +2 -1
  102. package/dist/style-config/lines.d.ts.map +1 -1
  103. package/dist/style-config/lines.js +13 -1
  104. package/dist/style-config/themes.d.ts.map +1 -1
  105. package/dist/style-config/themes.js +33 -1
  106. package/dist/types/bar-chart.d.ts +49 -0
  107. package/dist/types/bar-chart.d.ts.map +1 -0
  108. package/dist/types/bar-chart.js +54 -0
  109. package/dist/types/brush.d.ts +14 -0
  110. package/dist/types/brush.d.ts.map +1 -0
  111. package/dist/types/brush.js +16 -0
  112. package/dist/types/cartesian.d.ts +4 -2
  113. package/dist/types/cartesian.d.ts.map +1 -1
  114. package/dist/types/cartesian.js +1 -1
  115. package/dist/types/index.d.ts +1 -0
  116. package/dist/types/index.d.ts.map +1 -1
  117. package/dist/types/index.js +1 -0
  118. package/dist/types/line-chart.d.ts +4 -1
  119. package/dist/types/line-chart.d.ts.map +1 -1
  120. package/dist/types/line-chart.js +1 -1
  121. package/dist/types/lines.d.ts +14 -0
  122. package/dist/types/lines.d.ts.map +1 -1
  123. package/dist/types/lines.js +1 -1
  124. package/dist/types/main.d.ts +9 -1
  125. package/dist/types/main.d.ts.map +1 -1
  126. package/dist/types/main.js +1 -1
  127. package/dist/types/themes.d.ts +16 -0
  128. package/dist/types/themes.d.ts.map +1 -1
  129. package/dist/types/themes.js +1 -1
  130. package/dist/types/viewport.d.ts +4 -4
  131. package/dist/types/viewport.d.ts.map +1 -1
  132. package/dist/types/viewport.js +1 -1
  133. package/dist/utils/axis.js +14 -14
  134. package/dist/utils/data.d.ts +10 -7
  135. package/dist/utils/data.d.ts.map +1 -1
  136. package/dist/utils/data.js +26 -1
  137. package/dist/utils/data.test.js +109 -1
  138. package/dist/utils/lines.d.ts +3 -3
  139. package/dist/utils/lines.d.ts.map +1 -1
  140. package/dist/utils/lines.js +3 -3
  141. package/dist/utils/lines.test.js +6 -6
  142. package/dist/utils/metadata.d.ts +7 -4
  143. package/dist/utils/metadata.d.ts.map +1 -1
  144. package/dist/utils/metadata.js +6 -2
  145. package/dist/utils/metadata.test.js +8 -8
  146. package/dist/utils/viewport.d.ts +3 -1
  147. package/dist/utils/viewport.d.ts.map +1 -1
  148. package/package.json +15 -14
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /*
3
- * Copyright 2023 Wonderflow Design Team
3
+ * Copyright 2023-2024 Wonderflow Design Team
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -17,30 +17,33 @@ 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 { useMemo } from 'react';
20
+ import { useCallback, useMemo } from 'react';
21
21
  import { v4 as uuid } from 'uuid';
22
22
  import { useCartesianContext, useDataContext, useLayoutContext, useStyleConfigContext, useThemeContext, } from '../../../providers';
23
23
  import { createSubPaths, getCoordinates, getLinesRenderer, getValueFromObjectByPath, } from '../../../utils';
24
- import { LinesItem, } from './lines.module.css';
24
+ import { LinesItem, LinesItemBlurred, } from './lines.module.css';
25
25
  export const LinesSeries = () => {
26
26
  const theme = useThemeContext();
27
27
  const { lines: defaultStyle, themes } = useStyleConfigContext();
28
28
  const { data, metadata } = useDataContext();
29
29
  const { isHorizontal } = useLayoutContext();
30
- const { axis } = useCartesianContext();
30
+ const { axis, hoveredLegendItem: overLegend } = useCartesianContext();
31
31
  const { left, bottom } = axis;
32
32
  const { index, renderAs, showMarker, showMarkerLabel, series, hideMissingDataConnection, } = metadata;
33
33
  const indexAxis = isHorizontal ? bottom : left;
34
34
  const seriesAxis = isHorizontal ? left : bottom;
35
35
  const renderer = useMemo(() => getLinesRenderer(renderAs, isHorizontal), [isHorizontal, renderAs]);
36
- const getSeriesCoordinates = (datum, dataKey, isHorizontal) => getCoordinates({
36
+ const getSeriesCoordinates = useMemo(() => (datum, dataKey, isHorizontal) => getCoordinates({
37
37
  datum,
38
38
  indexAxis: indexAxis,
39
39
  indexDataKey: index,
40
40
  otherAxis: seriesAxis,
41
41
  otherDataKey: dataKey,
42
42
  isHorizontal,
43
- });
43
+ }), [index, indexAxis, seriesAxis]);
44
+ const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
45
+ ? LinesItem
46
+ : LinesItemBlurred), []);
44
47
  return (_jsx(_Fragment, { children: series.dataKey.map((dataKey, di) => {
45
48
  const subPaths = createSubPaths(data, d => _.isNil(getValueFromObjectByPath(d, dataKey)));
46
49
  const hasMarker = Boolean(showMarker
@@ -48,7 +51,7 @@ export const LinesSeries = () => {
48
51
  || series.style?.[di]?.showMarker
49
52
  || series.style?.[di]?.showMarkerLabel);
50
53
  const segmentStroke = hideMissingDataConnection ? 'transparent' : themes[theme].lines.noData;
51
- return (subPaths.map((subPathData, si) => (_jsxs(Group, { className: LinesItem, children: [_jsx(LinePath, { "data-testid": "lines-series", data: subPathData, curve: renderer, x: datum => getSeriesCoordinates(datum, dataKey, isHorizontal).x, y: datum => getSeriesCoordinates(datum, dataKey, isHorizontal).y, stroke: si % 2 === 0
54
+ return (subPaths.map((subPathData, si) => (_jsxs(Group, { className: dynamicClassName(overLegend, dataKey), children: [_jsx(LinePath, { "data-testid": "lines-series", data: subPathData, curve: renderer, x: datum => getSeriesCoordinates(datum, dataKey, isHorizontal).x, y: datum => getSeriesCoordinates(datum, dataKey, isHorizontal).y, stroke: si % 2 === 0
52
55
  ? series.colors[di]
53
56
  : segmentStroke, strokeWidth: series.style?.[di]?.strokeWidth ?? defaultStyle.path.strokeWidth, strokeOpacity: series.style?.[di]?.strokeOpacity ?? defaultStyle.path.strokeOpacity, strokeDasharray: si % 2 === 0
54
57
  ? series.style?.[di]?.strokeDasharray
@@ -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,EAyPhC,CAAC"}
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,19 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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
  /* eslint-disable @typescript-eslint/ban-ts-comment */
18
18
  /* eslint-disable @typescript-eslint/naming-convention */
19
19
  // @ts-nocheck
@@ -65,12 +65,8 @@ export const LinesTooltip = () => {
65
65
  ? accessorInvertValue
66
66
  : new Date(domainIndexValue);
67
67
  const lineIndicatorPos = scale(indexScaleValue);
68
- const tooltipLeft = isHorizontal
69
- ? (coords.x + lBound / 8)
70
- : coords.x;
71
- const tooltipTop = isHorizontal
72
- ? coords.y
73
- : (coords.y + tBound / 8);
68
+ const tooltipLeft = ('clientX' in event ? event.clientX : 0) - lBound / 8;
69
+ const tooltipTop = ('clientY' in event ? event.clientY : 0) - tBound / 8;
74
70
  const datum = data[indexOfBisectValue];
75
71
  const hasSeriesData = series.dataKey.every(s => !_.isNil(getPrimitiveFromObjectByPath(datum, s)));
76
72
  const hasOverlayData = !_.isNil(getPrimitiveFromObjectByPath(datum, overlay.dataKey));
@@ -1 +1 @@
1
- {"version":3,"file":"lines.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/lines/lines.tsx"],"names":[],"mappings":";AA2BA,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAiBzB,CAAC"}
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,28 +1,30 @@
1
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 { useSSR } from '../../../hooks';
18
19
  import { useCartesianContext } from '../../../providers/cartesian';
19
- import { LinesItemGroup, } from './lines.module.css';
20
+ import { LinesAverage } from './lines-average';
20
21
  import { LinesMarkerLabels } from './lines-marker-labels';
21
22
  import { LinesOverlay } from './lines-overlay';
22
23
  import { LinesSeries } from './lines-series';
23
24
  import { LinesTooltip } from './lines-tooltip';
24
25
  export const Lines = () => {
25
26
  const { position } = useCartesianContext();
26
- return (_jsxs(Group, { top: position.top, left: position.left, children: [_jsxs(Group, { className: LinesItemGroup, "data-testid": "lines", children: [_jsx(LinesSeries, {}), _jsx(LinesOverlay, {})] }), _jsx(LinesTooltip, {}), _jsx(LinesMarkerLabels, {})] }));
27
+ 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, {})] }));
27
29
  };
28
30
  Lines.displayName = 'Lines';
@@ -1 +1 @@
1
- .LinesItem,.LinesItem:hover{filter:saturate(100%) opacity(1)}.LinesItemGroup:hover .LinesItem:not(:hover){filter:saturate(80%) opacity(.3) blur(2px)}.LinesTooltipContent{display:block;padding:0 1rem .5rem}.LinesTooltipContent p{font-size:12px}.LinesTooltipContent ul{list-style:none;padding:0;width:100%}.LinesTooltipContent li{grid-gap:8px 4px;display:grid;grid-template-columns:1fr auto .5fr;grid-template-rows:1fr}.LinesTooltipContent li div:nth-child(n+2){text-align:right}.LinesTooltipItem{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}
1
+ .LinesItem{filter:saturate(100%) opacity(1)}.LinesItemBlurred{filter:opacity(.2) blur(2px)}.LinesTooltipContent{display:block;padding:0 1rem .5rem}.LinesTooltipContent p{font-size:12px}.LinesTooltipContent ul{list-style:none;padding:0;width:100%}.LinesTooltipContent li{grid-gap:8px 4px;display:grid;grid-template-columns:1fr auto .5fr;grid-template-rows:1fr}.LinesTooltipContent li div:nth-child(n+2){text-align:right}.LinesTooltipItem{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}
@@ -17,11 +17,13 @@ const mockMetadata = {
17
17
  dataKey: ['a'],
18
18
  names: ['A'],
19
19
  colors: ['ca'],
20
+ average: undefined,
20
21
  },
21
22
  overlay: {
22
23
  dataKey: 'b',
23
24
  name: 'B',
24
25
  color: 'ob',
26
+ average: undefined,
25
27
  },
26
28
  hidePadding: true,
27
29
  };
@@ -88,7 +90,7 @@ const mockedAxisSystem2 = {
88
90
  };
89
91
  describe('<Lines>', () => {
90
92
  it('should render the component', () => {
91
- render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { position: {
93
+ 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: {
92
94
  top: 24, right: 24, bottom: 24, left: 24,
93
95
  }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, children: _jsx(Lines, {}) }) }) }) }));
94
96
  const elementSeries = screen.getByTestId('lines-series');
@@ -97,18 +99,18 @@ describe('<Lines>', () => {
97
99
  expect(elementOverlay).toBeDefined();
98
100
  });
99
101
  it('should render the component w vertical layout', () => {
100
- render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.VERTICAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { position: {
102
+ 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, { position: {
101
103
  top: 24, right: 24, bottom: 24, left: 24,
102
- }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, children: _jsx(Lines, {}) }) }) }) }));
104
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, hoveredLegendItem: "", children: _jsx(Lines, {}) }) }) }) }));
103
105
  const elementSeries = screen.getByTestId('lines-series');
104
106
  const elementOverlay = screen.getByTestId('lines-overlay');
105
107
  expect(elementSeries).toBeDefined();
106
108
  expect(elementOverlay).toBeDefined();
107
109
  });
108
110
  it('should render the component w markerLabel', () => {
109
- render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 }], metadata: { ...mockMetadata, showMarkerLabel: true }, children: _jsx(CartesianProvider, { position: {
111
+ 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, showMarkerLabel: true }, children: _jsx(CartesianProvider, { position: {
110
112
  top: 24, right: 24, bottom: 24, left: 24,
111
- }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, children: _jsx(Lines, {}) }) }) }) }));
113
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, hoveredLegendItem: "", children: _jsx(Lines, {}) }) }) }) }));
112
114
  const elementSeries = screen.getByTestId('lines-series');
113
115
  const elementOverlay = screen.getByTestId('lines-overlay');
114
116
  expect(elementSeries).toBeDefined();
@@ -116,19 +118,23 @@ describe('<Lines>', () => {
116
118
  });
117
119
  it('should render the component w/o missing connection', () => {
118
120
  render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: 0, a: 1, b: 2 },
121
+ { date: 0, a: undefined, b: 2 },
122
+ { date: 0, a: 1, b: 2 }], filteredData: [{ date: 0, a: 1, b: 2 },
119
123
  { date: 0, a: undefined, b: 2 },
120
124
  { date: 0, a: 1, b: 2 }], metadata: { ...mockMetadata, hideMissingDataConnection: true }, children: _jsx(CartesianProvider, { position: {
121
125
  top: 24, right: 24, bottom: 24, left: 24,
122
- }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, children: _jsx(Lines, {}) }) }) }) }));
126
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem, hoveredLegendItem: "", children: _jsx(Lines, {}) }) }) }) }));
123
127
  const elementOverlay = screen.getByTestId('lines-overlay');
124
128
  expect(elementOverlay).toBeDefined();
125
129
  });
126
130
  it.skip('should trigger tooltip', async () => {
127
131
  const { getByTestId, queryByTestId } = render(_jsx(ThemeProvider, { theme: "light", children: _jsx(LayoutProvider, { layout: CartesianChartLayout.HORIZONTAL, children: _jsx(DataProvider, { data: [{ date: '01-01-2020', a: 1, b: 2 },
132
+ { date: '01-01-2021', a: 3, b: 4 },
133
+ { date: '01-01-2022', a: 1, b: 2 }], filteredData: [{ date: '01-01-2020', a: 1, b: 2 },
128
134
  { date: '01-01-2021', a: 3, b: 4 },
129
135
  { date: '01-01-2022', a: 1, b: 2 }], metadata: mockMetadata, children: _jsx(CartesianProvider, { position: {
130
136
  top: 24, right: 24, bottom: 24, left: 24,
131
- }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem2, children: _jsx(Lines, {}) }) }) }) }));
137
+ }, dimension: { maxHeight: 600, maxWidth: 800 }, axis: mockedAxisSystem2, hoveredLegendItem: "", children: _jsx(Lines, {}) }) }) }) }));
132
138
  const overlay = getByTestId('transparent-overlay-layer');
133
139
  const tooltip = queryByTestId('lines-tooltip');
134
140
  expect(overlay).toBeDefined();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hooks.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.test.d.ts","sourceRoot":"","sources":["../../src/hooks/hooks.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,153 @@
1
+ import { renderHook } from '@testing-library/react-hooks';
2
+ import { scaleLinear, scaleUtc } from '@visx/scale';
3
+ import { useBrush } from './useBrush';
4
+ import { useCartesian } from './useCartesian';
5
+ import { useLineChart } from './useLineChart';
6
+ import { useSSR } from './useSSR';
7
+ describe('useLineChart', () => {
8
+ it('should render data', () => {
9
+ const props = {
10
+ theme: 'light',
11
+ data: [{ a: 1, b: 2, c: 3 }],
12
+ index: { dataKey: 'a' },
13
+ series: { dataKey: ['b'] },
14
+ overlay: { dataKey: 'c' },
15
+ };
16
+ const { result } = renderHook(() => useLineChart(props));
17
+ const { isHorizontal, metadata } = result.current;
18
+ const expMetadata = {
19
+ hideMissingDataConnection: false,
20
+ hidePadding: false,
21
+ index: 'a',
22
+ overlay: {
23
+ average: {
24
+ average: 3,
25
+ dataKey: [
26
+ {
27
+ average: 3,
28
+ name: 'c',
29
+ },
30
+ ],
31
+ },
32
+ color: 'hsl(14 63% 53%)',
33
+ dataKey: 'c',
34
+ name: 'C',
35
+ style: undefined,
36
+ },
37
+ renderAs: 'curves',
38
+ series: {
39
+ average: {
40
+ average: 2,
41
+ dataKey: [
42
+ {
43
+ average: 2,
44
+ name: 'b',
45
+ },
46
+ ],
47
+ },
48
+ colors: [
49
+ 'hsl(149 83% 35%)',
50
+ ],
51
+ dataKey: [
52
+ 'b',
53
+ ],
54
+ names: [
55
+ 'B',
56
+ ],
57
+ style: undefined,
58
+ },
59
+ showAverage: false,
60
+ showMarker: false,
61
+ showMarkerLabel: false,
62
+ tooltip: undefined,
63
+ type: 'LINE_CHART',
64
+ };
65
+ expect(isHorizontal).toBeTruthy();
66
+ expect(metadata).toStrictEqual(expMetadata);
67
+ });
68
+ });
69
+ describe('useCartesian', () => {
70
+ const mockedAxis = {
71
+ top: {
72
+ domain: [0, 1],
73
+ scaleType: 'linear',
74
+ orientation: 'top',
75
+ },
76
+ right: {
77
+ domain: ['a', 'b'],
78
+ scaleType: 'label',
79
+ orientation: 'right',
80
+ },
81
+ bottom: {
82
+ domain: ['01-01-2020', '01-01-2024'],
83
+ scaleType: 'time',
84
+ orientation: 'bottom',
85
+ },
86
+ left: {
87
+ domain: [0, 1],
88
+ scaleType: 'linear',
89
+ orientation: 'left',
90
+ },
91
+ };
92
+ it('should render data', () => {
93
+ const props = {
94
+ axis: mockedAxis,
95
+ axisFiltered: mockedAxis,
96
+ hideLegend: false,
97
+ };
98
+ const { result } = renderHook(() => useCartesian(props));
99
+ const { cartesianConfig } = result.current;
100
+ const exp = 'hsl(0 0% 100%)';
101
+ expect(cartesianConfig.themes.light.background.from).toStrictEqual(exp);
102
+ });
103
+ });
104
+ describe('useBrush', () => {
105
+ const props = {
106
+ axisSystem: {
107
+ bottom: {
108
+ domain: ['2001', '2002'],
109
+ scaleType: 'time',
110
+ orientation: 'bottom',
111
+ scale: scaleUtc([0, 1]),
112
+ top: 100,
113
+ left: 100,
114
+ },
115
+ left: {
116
+ domain: [0, 1],
117
+ scaleType: 'linear',
118
+ orientation: 'left',
119
+ scale: scaleLinear([0, 1]),
120
+ top: 100,
121
+ left: 100,
122
+ },
123
+ top: undefined,
124
+ right: undefined,
125
+ },
126
+ position: {
127
+ top: 10,
128
+ left: 10,
129
+ },
130
+ dimension: {
131
+ maxHeight: 100,
132
+ maxWidth: 100,
133
+ },
134
+ onChange: jest.fn(),
135
+ };
136
+ it('should render data', () => {
137
+ const { result } = renderHook(() => useBrush(props));
138
+ const { margin } = result.current;
139
+ const exp = {
140
+ bottom: 0, left: 10, right: 0, top: 0,
141
+ };
142
+ expect(margin).toStrictEqual(exp);
143
+ });
144
+ });
145
+ describe('useSSR()', () => {
146
+ test('it should return true in Browser', () => {
147
+ const { result } = renderHook(() => useSSR());
148
+ const d = window?.document;
149
+ expect(d).toBeTruthy();
150
+ expect(result.current.isBrowser).toBe(true);
151
+ expect(result.current.isServer).not.toBe(true);
152
+ });
153
+ });
@@ -0,0 +1,8 @@
1
+ export type { UseBrushProps } from './useBrush';
2
+ export { useBrush } from './useBrush';
3
+ export type { UseCartesianProps } from './useCartesian';
4
+ export { useCartesian } from './useCartesian';
5
+ export type { UseLineChartProps } from './useLineChart';
6
+ export { useLineChart } from './useLineChart';
7
+ export { useSSR } from './useSSR';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAgBA,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2022-2024 Wonderflow Design Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export { useBrush } from './useBrush';
17
+ export { useCartesian } from './useCartesian';
18
+ export { useLineChart } from './useLineChart';
19
+ export { useSSR } from './useSSR';
@@ -0,0 +1,74 @@
1
+ /// <reference types="react" />
2
+ import BaseBrush from '@visx/brush/lib/BaseBrush';
3
+ import { Bounds, ResizeTriggerAreas } from '@visx/brush/lib/types';
4
+ import { CartesianxAxisSystem, Data } from '../types';
5
+ export declare type UseBrushProps = {
6
+ axisSystem: CartesianxAxisSystem;
7
+ brushSize?: number;
8
+ padding?: number;
9
+ position: {
10
+ top: number;
11
+ left: number;
12
+ };
13
+ dimension: {
14
+ maxWidth: number;
15
+ maxHeight: number;
16
+ };
17
+ isVisible?: boolean;
18
+ onChange: (filteredData: Data) => void;
19
+ };
20
+ export declare const useBrush: ({ axisSystem, brushSize, dimension, isVisible, padding, position, onChange, }: UseBrushProps) => {
21
+ ref: import("react").MutableRefObject<BaseBrush | null>;
22
+ brushDirection: "horizontal" | "vertical";
23
+ brushHeight: number;
24
+ brushWidth: number;
25
+ initialBrushPosition: {
26
+ start: {
27
+ x: number;
28
+ y?: undefined;
29
+ } | {
30
+ y: number;
31
+ x?: undefined;
32
+ };
33
+ end: {
34
+ x: number;
35
+ y?: undefined;
36
+ } | {
37
+ y: number;
38
+ x?: undefined;
39
+ };
40
+ };
41
+ margin: {
42
+ top: number;
43
+ left: number;
44
+ right: number;
45
+ bottom: number;
46
+ };
47
+ position: {
48
+ left: number;
49
+ top: number;
50
+ };
51
+ resizeTriggerAreas: ResizeTriggerAreas[];
52
+ scale: {
53
+ x: import("d3-scale").ScaleBand<string> | import("d3-scale").ScaleLinear<number, number, never> | import("d3-scale").ScaleTime<number, number, never> | undefined;
54
+ y: import("d3-scale").ScaleBand<string> | import("d3-scale").ScaleLinear<number, number, never> | import("d3-scale").ScaleTime<number, number, never> | undefined;
55
+ };
56
+ style: {
57
+ selectedBox: {
58
+ fill: string;
59
+ fillOpacity: number;
60
+ stroke: string;
61
+ strokeWidth: number;
62
+ strokeOpacity: number;
63
+ };
64
+ pattern: {
65
+ transform: string;
66
+ strokeWidth: number;
67
+ stroke: string;
68
+ fill: string;
69
+ };
70
+ };
71
+ handleBrushClear: () => void;
72
+ handleBrushChange: (domain: Bounds | null) => void;
73
+ };
74
+ //# sourceMappingURL=useBrush.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBrush.d.ts","sourceRoot":"","sources":["../../src/hooks/useBrush.ts"],"names":[],"mappings":";AAgBA,OAAO,SAA0C,MAAM,2BAA2B,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AASnE,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGtD,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,oBAAoB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,YAAY,EAAE,IAAI,KAAK,IAAI,CAAC;CACxC,CAAA;AAED,eAAO,MAAM,QAAQ,kFAQlB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAwHiC,MAAM,GAAG,IAAI;CAoE7D,CAAC"}