@wonderflow/charts 12.11.0 → 14.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.
- package/dist/components/bar-chart/bar-chart.d.ts +35 -7
- package/dist/components/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/components/bar-chart/bar-chart.js +21 -46
- package/dist/components/bar-chart/bar-chart.test.js +7 -1
- package/dist/components/cartesian-base/cartesian-base-axis.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-axis.js +10 -11
- package/dist/components/cartesian-base/cartesian-base-legend.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base-legend.js +3 -3
- package/dist/components/cartesian-base/cartesian-base.d.ts +32 -0
- package/dist/components/cartesian-base/cartesian-base.d.ts.map +1 -1
- package/dist/components/cartesian-base/cartesian-base.js +8 -3
- package/dist/components/cartesian-base/cartesian-base.module.css +1 -1
- package/dist/components/headings/headings.d.ts +19 -2
- package/dist/components/headings/headings.d.ts.map +1 -1
- package/dist/components/headings/headings.js +72 -6
- package/dist/components/headings/headings.module.css +1 -0
- package/dist/components/headings/headings.test.d.ts +1 -1
- package/dist/components/headings/headings.test.d.ts.map +1 -1
- package/dist/components/headings/headings.test.js +37 -3
- package/dist/components/line-chart/line-chart.d.ts +31 -15
- package/dist/components/line-chart/line-chart.d.ts.map +1 -1
- package/dist/components/line-chart/line-chart.js +5 -3
- package/dist/components/line-chart/line-chart.test.js +2 -2
- package/dist/components/loader/bar-chart-loader.d.ts.map +1 -1
- package/dist/components/loader/bar-chart-loader.js +1 -1
- package/dist/components/loader/loader.js +2 -2
- package/dist/components/loader/loader.test.js +4 -2
- package/dist/components/shapes/bars/bars-average.d.ts +3 -0
- package/dist/components/shapes/bars/bars-average.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-average.js +30 -0
- package/dist/components/shapes/bars/bars-label.d.ts +22 -0
- package/dist/components/shapes/bars/bars-label.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-label.js +35 -0
- package/dist/components/shapes/bars/bars-layout.d.ts +3 -0
- package/dist/components/shapes/bars/bars-layout.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-layout.js +36 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay-labels.js +62 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-overlay.js +59 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series-labels.js +62 -0
- package/dist/components/shapes/bars/bars-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-series.js +56 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-overlay.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-overlay.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series-labels.js +50 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts +6 -0
- package/dist/components/shapes/bars/bars-stack-series.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-stack-series.js +48 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts +3 -0
- package/dist/components/shapes/bars/bars-tooltip.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-tooltip.js +96 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts +3 -0
- package/dist/components/shapes/bars/bars-trendline.d.ts.map +1 -0
- package/dist/components/shapes/bars/bars-trendline.js +43 -0
- package/dist/components/shapes/bars/bars.d.ts.map +1 -1
- package/dist/components/shapes/bars/bars.js +27 -18
- package/dist/components/shapes/bars/bars.module.css +1 -1
- package/dist/components/shapes/bars/bars.test.js +132 -8
- package/dist/components/shapes/bars/index.d.ts +13 -0
- package/dist/components/shapes/bars/index.d.ts.map +1 -1
- package/dist/components/shapes/bars/index.js +14 -1
- package/dist/components/shapes/lines/lines-average.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-average.js +8 -46
- package/dist/components/shapes/lines/lines-marker-labels.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-marker-labels.js +16 -12
- package/dist/components/shapes/lines/lines-overlay.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-overlay.js +21 -26
- package/dist/components/shapes/lines/lines-series.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-series.js +6 -19
- package/dist/components/shapes/lines/lines-tooltip.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines-tooltip.js +21 -28
- package/dist/components/shapes/lines/lines-trendline.d.ts +3 -0
- package/dist/components/shapes/lines/lines-trendline.d.ts.map +1 -0
- package/dist/components/shapes/lines/lines-trendline.js +43 -0
- package/dist/components/shapes/lines/lines.d.ts.map +1 -1
- package/dist/components/shapes/lines/lines.js +2 -1
- package/dist/components/shapes/lines/lines.test.js +29 -8
- package/dist/hooks/hooks.test.d.ts.map +1 -1
- package/dist/hooks/hooks.test.js +162 -5
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/useAverage.d.ts +82 -0
- package/dist/hooks/useAverage.d.ts.map +1 -0
- package/dist/hooks/useAverage.js +83 -0
- package/dist/hooks/useBarChart.d.ts +17 -0
- package/dist/hooks/useBarChart.d.ts.map +1 -0
- package/dist/hooks/useBarChart.js +110 -0
- package/dist/hooks/useBars.d.ts +66 -0
- package/dist/hooks/useBars.d.ts.map +1 -0
- package/dist/hooks/useBars.js +121 -0
- package/dist/hooks/useCartesian.d.ts +12 -2
- package/dist/hooks/useCartesian.d.ts.map +1 -1
- package/dist/hooks/useCartesian.js +19 -7
- package/dist/hooks/useLineChart.d.ts +3 -27
- package/dist/hooks/useLineChart.d.ts.map +1 -1
- package/dist/hooks/useLineChart.js +27 -16
- package/dist/hooks/useLines.d.ts +51 -0
- package/dist/hooks/useLines.d.ts.map +1 -0
- package/dist/hooks/useLines.js +70 -0
- package/dist/hooks/useTrendline.d.ts +60 -0
- package/dist/hooks/useTrendline.d.ts.map +1 -0
- package/dist/hooks/useTrendline.js +84 -0
- package/dist/providers/cartesian.d.ts +5 -1
- package/dist/providers/cartesian.d.ts.map +1 -1
- package/dist/providers/cartesian.js +19 -3
- package/dist/providers/data.d.ts +6 -7
- package/dist/providers/data.d.ts.map +1 -1
- package/dist/providers/data.js +4 -3
- package/dist/style-config/axis.js +3 -3
- package/dist/style-config/bars.d.ts +3 -0
- package/dist/style-config/bars.d.ts.map +1 -0
- package/dist/style-config/bars.js +43 -0
- package/dist/style-config/cartesian.d.ts.map +1 -1
- package/dist/style-config/cartesian.js +2 -0
- package/dist/style-config/colors.d.ts +1 -4
- package/dist/style-config/colors.d.ts.map +1 -1
- package/dist/style-config/colors.js +30 -36
- package/dist/style-config/headings.d.ts.map +1 -1
- package/dist/style-config/headings.js +16 -1
- package/dist/style-config/lines.d.ts.map +1 -1
- package/dist/style-config/lines.js +6 -0
- package/dist/style-config/themes.d.ts.map +1 -1
- package/dist/style-config/themes.js +18 -0
- package/dist/types/bar-chart.d.ts +26 -22
- package/dist/types/bar-chart.d.ts.map +1 -1
- package/dist/types/bar-chart.js +1 -39
- package/dist/types/bars.d.ts +68 -0
- package/dist/types/bars.d.ts.map +1 -0
- package/dist/types/bars.js +16 -0
- package/dist/types/cartesian.d.ts +7 -0
- package/dist/types/cartesian.d.ts.map +1 -1
- package/dist/types/headings.d.ts +15 -0
- package/dist/types/headings.d.ts.map +1 -1
- package/dist/types/headings.js +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/line-chart.d.ts +17 -19
- package/dist/types/line-chart.d.ts.map +1 -1
- package/dist/types/lines.d.ts +6 -0
- package/dist/types/lines.d.ts.map +1 -1
- package/dist/types/main.d.ts +15 -2
- package/dist/types/main.d.ts.map +1 -1
- package/dist/types/themes.d.ts +9 -0
- package/dist/types/themes.d.ts.map +1 -1
- package/dist/utils/axis.d.ts +12 -2
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +52 -15
- package/dist/utils/axis.test.js +72 -8
- package/dist/utils/bars.d.ts +63 -0
- package/dist/utils/bars.d.ts.map +1 -0
- package/dist/utils/bars.js +316 -0
- package/dist/utils/bars.test.d.ts +2 -0
- package/dist/utils/bars.test.d.ts.map +1 -0
- package/dist/utils/bars.test.js +388 -0
- package/dist/utils/data.d.ts +14 -6
- package/dist/utils/data.d.ts.map +1 -1
- package/dist/utils/data.js +128 -21
- package/dist/utils/data.test.js +195 -86
- package/dist/utils/format.d.ts +1 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +2 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/lines.d.ts +3 -3
- package/dist/utils/lines.d.ts.map +1 -1
- package/dist/utils/lines.js +3 -1
- package/dist/utils/lines.test.js +26 -1
- package/dist/utils/metadata.d.ts +5 -8
- package/dist/utils/metadata.d.ts.map +1 -1
- package/dist/utils/metadata.js +8 -20
- package/dist/utils/metadata.test.js +5 -58
- package/dist/utils/viewport.test.js +8 -0
- package/package.json +13 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-series.tsx"],"names":[],"mappings":";AA+BA,eAAO,MAAM,UAAU;;;CA6ItB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 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 { Bar, BarGroup, BarGroupHorizontal } from '@visx/shape';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import { useCallback } from 'react';
|
|
21
|
+
import { useBars } from '../../../hooks';
|
|
22
|
+
import { extractBarValueFromNestedKey, getBarSizeAndPosition, getBarThickness, sortBarsBy, } from '../../../utils';
|
|
23
|
+
import { useCartesianContext, useStyleConfigContext, useThemeContext } from '../../../providers';
|
|
24
|
+
import { BarsItem, BarsItemBlurred } from './bars.module.css';
|
|
25
|
+
export const BarsSeries = () => {
|
|
26
|
+
const { hoveredLegendItem: overLegend } = useCartesianContext();
|
|
27
|
+
const theme = useThemeContext();
|
|
28
|
+
const { themes } = useStyleConfigContext();
|
|
29
|
+
const { data, isHorizontal, series, sortBy, hasBackgroundSeries, seriesAxis, maxWidth, maxHeight, X0Y0, scaleXY0, scaleXY1, style, fixedBarSize, } = useBars();
|
|
30
|
+
const { bar: barStyle, background, maxSize } = style;
|
|
31
|
+
const bgColor = themes[theme].bars.backgroundColor;
|
|
32
|
+
const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
|
|
33
|
+
? BarsItem
|
|
34
|
+
: BarsItemBlurred), []);
|
|
35
|
+
if (!isHorizontal) {
|
|
36
|
+
return (_jsx(BarGroupHorizontal, { data: data, keys: series.dataKey, width: maxWidth, y0: X0Y0, y0Scale: scaleXY0, y1Scale: scaleXY1, xScale: seriesAxis.scale, color: (_, i) => series.colors[i], children: barGroups => barGroups.map((barGroup, i) => {
|
|
37
|
+
const updatedBars = extractBarValueFromNestedKey(barGroup, i, data, seriesAxis.scale, maxWidth, isHorizontal);
|
|
38
|
+
const sortedBars = sortBarsBy(updatedBars, sortBy, isHorizontal);
|
|
39
|
+
return (_jsx(Group, { top: barGroup.y0, children: sortedBars.map((bar) => {
|
|
40
|
+
const thickness = getBarThickness(bar.height, maxSize, fixedBarSize);
|
|
41
|
+
const { x, y, width } = getBarSizeAndPosition(bar, seriesAxis, thickness, isHorizontal);
|
|
42
|
+
return (_jsxs(Group, { children: [hasBackgroundSeries && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: 0, y: bar.y, width: maxWidth, height: thickness, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: x, y: y, width: width, height: thickness, fill: bar.color, rx: barStyle.rx, opacity: barStyle.opacity, onClick: () => ({}) })] }, _.uniqueId()));
|
|
43
|
+
}) }, _.uniqueId()));
|
|
44
|
+
}) }));
|
|
45
|
+
}
|
|
46
|
+
return (_jsx(BarGroup, { data: data, keys: series.dataKey, height: maxHeight, x0: X0Y0, x0Scale: scaleXY0, x1Scale: scaleXY1, yScale: seriesAxis.scale, color: (_, i) => series.colors[i], children: barGroups => barGroups.map((barGroup, i) => {
|
|
47
|
+
const updatedBars = extractBarValueFromNestedKey(barGroup, i, data, seriesAxis.scale, maxHeight, isHorizontal);
|
|
48
|
+
const sortedBars = sortBarsBy(updatedBars, sortBy, isHorizontal);
|
|
49
|
+
return (_jsx(Group, { left: barGroup.x0, children: sortedBars.map((bar) => {
|
|
50
|
+
const thickness = getBarThickness(bar.width, maxSize, fixedBarSize);
|
|
51
|
+
const { x, y, height } = getBarSizeAndPosition(bar, seriesAxis, thickness, isHorizontal);
|
|
52
|
+
return (_jsxs(Group, { children: [hasBackgroundSeries && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: bar.x, y: 0, width: thickness, height: maxHeight, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: x, y: y, width: thickness, height: height, fill: bar.color, opacity: barStyle.opacity, rx: barStyle.rx, onClick: () => ({}) })] }, _.uniqueId()));
|
|
53
|
+
}) }, _.uniqueId()));
|
|
54
|
+
}) }));
|
|
55
|
+
};
|
|
56
|
+
BarsSeries.displayName = 'BarSeries';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-stack-overlay-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-stack-overlay-labels.tsx"],"names":[],"mappings":";AAgCA,eAAO,MAAM,sBAAsB;;;CAoJlC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 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 { BarStack, BarStackHorizontal } from '@visx/shape';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import { useBars } from '../../../hooks';
|
|
21
|
+
import { getPrimitiveFromObjectByPath, getStackBarIndexPositionOverlay, getStackBarLabelContent, getStackBarLabelMorphology, getStackBarThickness, } from '../../../utils';
|
|
22
|
+
import { useStyleConfigContext } from '../../../providers';
|
|
23
|
+
import { BarsLabel } from './bars-label';
|
|
24
|
+
export const BarsStackOverlayLabels = () => {
|
|
25
|
+
const { bars } = useStyleConfigContext();
|
|
26
|
+
const { data, isHorizontal, isVertical, sortStackBy, maxWidth, maxHeight, X0Y0, scaleXY0, style, showLabel, fixedBarSize, scaleColorStackOverlay, scaleStackOverlay, hasOverlay, hasLabel, overlay, } = useBars();
|
|
27
|
+
const { maxSize } = style;
|
|
28
|
+
const { fontWeight, fontWeightValue } = bars.label;
|
|
29
|
+
if (!hasOverlay || !hasLabel)
|
|
30
|
+
return null;
|
|
31
|
+
if (isVertical) {
|
|
32
|
+
return (_jsx(BarStackHorizontal, { data: data, keys: overlay.dataKey, height: maxHeight, y: X0Y0, xScale: scaleStackOverlay, yScale: scaleXY0, color: scaleColorStackOverlay, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, i) => (_jsx(Group, { children: barStack.bars.map((bar, j) => {
|
|
33
|
+
const thickness = getStackBarThickness(bar.height, maxSize, fixedBarSize, hasOverlay);
|
|
34
|
+
const yPos = getStackBarIndexPositionOverlay(bar, thickness, isHorizontal);
|
|
35
|
+
const { value, separator, extra } = getStackBarLabelContent(data[j], overlay.dataKey, overlay.extraData, i);
|
|
36
|
+
const { rect, text } = getStackBarLabelMorphology(bar, overlay.extraData, { value, separator, extra }, thickness, { x: undefined, y: yPos }, { xMax: maxWidth, yMax: maxHeight }, isHorizontal);
|
|
37
|
+
const weigth = overlay.extraData ? fontWeightValue : fontWeight;
|
|
38
|
+
return (_jsx(Group, { children: showLabel && (_jsx(BarsLabel, { wrapper: { ...rect }, text: text, value: value, separator: separator, extraData: extra, fontWeightValue: weigth, dataKey: bar.key })) }, _.uniqueId()));
|
|
39
|
+
}) }, _.uniqueId()))) }));
|
|
40
|
+
}
|
|
41
|
+
return (_jsx(BarStack, { data: data, keys: overlay.dataKey, width: maxWidth, x: X0Y0, xScale: scaleXY0, yScale: scaleStackOverlay, color: scaleColorStackOverlay, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, i) => (_jsx(Group, { children: barStack.bars.map((bar, j) => {
|
|
42
|
+
const thickness = getStackBarThickness(bar.width, maxSize, fixedBarSize, hasOverlay);
|
|
43
|
+
const xPos = getStackBarIndexPositionOverlay(bar, thickness, isHorizontal);
|
|
44
|
+
const { value, separator, extra } = getStackBarLabelContent(data[j], overlay.dataKey, overlay.extraData, i);
|
|
45
|
+
const { rect, text } = getStackBarLabelMorphology(bar, overlay.extraData, { value, separator, extra }, thickness, { x: xPos, y: undefined }, { xMax: maxWidth, yMax: maxHeight }, isHorizontal);
|
|
46
|
+
const weigth = overlay.extraData ? fontWeightValue : fontWeight;
|
|
47
|
+
return (_jsx(Group, { children: showLabel && (_jsx(BarsLabel, { wrapper: { ...rect }, text: text, value: value, separator: separator, extraData: extra, fontWeightValue: weigth, dataKey: bar.key })) }, _.uniqueId()));
|
|
48
|
+
}) }, _.uniqueId()))) }));
|
|
49
|
+
};
|
|
50
|
+
BarsStackOverlayLabels.displayName = 'BarsStackOverlayLabels';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-stack-overlay.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-stack-overlay.tsx"],"names":[],"mappings":";AA+BA,eAAO,MAAM,gBAAgB;;;CA4I5B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 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 { Bar, BarStack, BarStackHorizontal } from '@visx/shape';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import { useCallback } from 'react';
|
|
21
|
+
import { useBars } from '../../../hooks';
|
|
22
|
+
import { getPrimitiveFromObjectByPath, getStackBarIndexPositionOverlay, getStackBarThickness, } from '../../../utils';
|
|
23
|
+
import { useCartesianContext, useStyleConfigContext, useThemeContext } from '../../../providers';
|
|
24
|
+
import { BarsItem, BarsItemBlurred } from './bars.module.css';
|
|
25
|
+
export const BarsStackOverlay = () => {
|
|
26
|
+
const { hoveredLegendItem: overLegend } = useCartesianContext();
|
|
27
|
+
const theme = useThemeContext();
|
|
28
|
+
const { themes } = useStyleConfigContext();
|
|
29
|
+
const { data, isHorizontal, isVertical, overlay, sortStackBy, maxWidth, maxHeight, X0Y0, scaleXY0, style, fixedBarSize, scaleColorStackOverlay, scaleStackOverlay, hasOverlay, hasBackgroundOverlay, } = useBars();
|
|
30
|
+
const { bar: barStyle, maxSize, background } = style;
|
|
31
|
+
const bgColor = themes[theme].bars.backgroundColor;
|
|
32
|
+
const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
|
|
33
|
+
? BarsItem
|
|
34
|
+
: BarsItemBlurred), []);
|
|
35
|
+
if (!hasOverlay)
|
|
36
|
+
return null;
|
|
37
|
+
if (isVertical) {
|
|
38
|
+
return (_jsx(BarStackHorizontal, { data: data, keys: overlay.dataKey, height: maxHeight, y: X0Y0, xScale: scaleStackOverlay, yScale: scaleXY0, color: scaleColorStackOverlay, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, index) => (_jsx(Group, { children: barStack.bars.map((bar) => {
|
|
39
|
+
const thickness = getStackBarThickness(bar.height, maxSize, fixedBarSize, hasOverlay);
|
|
40
|
+
const yPos = getStackBarIndexPositionOverlay(bar, thickness, isHorizontal);
|
|
41
|
+
return (_jsxs(Group, { children: [(hasBackgroundOverlay && index === 0) && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: 0, y: yPos, width: maxWidth, height: thickness, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: bar.x, y: yPos, width: bar.width, height: thickness, fill: bar.color, rx: 0, opacity: barStyle.opacity, onClick: () => ({}) })] }, _.uniqueId()));
|
|
42
|
+
}) }, _.uniqueId()))) }));
|
|
43
|
+
}
|
|
44
|
+
return (_jsx(BarStack, { data: data, keys: overlay.dataKey, width: maxWidth, x: X0Y0, xScale: scaleXY0, yScale: scaleStackOverlay, color: scaleColorStackOverlay, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, index) => (_jsx(Group, { children: barStack.bars.map((bar) => {
|
|
45
|
+
const thickness = getStackBarThickness(bar.width, maxSize, fixedBarSize, hasOverlay);
|
|
46
|
+
const xPos = getStackBarIndexPositionOverlay(bar, thickness, isHorizontal);
|
|
47
|
+
return (_jsxs(Group, { children: [(hasBackgroundOverlay && index === 0) && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: xPos, y: 0, width: thickness, height: maxHeight, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: xPos, y: bar.y, width: thickness, height: bar.height, fill: bar.color, opacity: barStyle.opacity, rx: 0, onClick: () => ({}) })] }, _.uniqueId()));
|
|
48
|
+
}) }, _.uniqueId()))) }));
|
|
49
|
+
};
|
|
50
|
+
BarsStackOverlay.displayName = 'BarsStackOverlay';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-stack-series-labels.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-stack-series-labels.tsx"],"names":[],"mappings":";AAgCA,eAAO,MAAM,qBAAqB;;;CAyIjC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 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 { BarStack, BarStackHorizontal } from '@visx/shape';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import { useBars } from '../../../hooks';
|
|
21
|
+
import { getPrimitiveFromObjectByPath, getStackBarIndexPositionSeries, getStackBarLabelContent, getStackBarLabelMorphology, getStackBarThickness, } from '../../../utils';
|
|
22
|
+
import { useStyleConfigContext } from '../../../providers';
|
|
23
|
+
import { BarsLabel } from './bars-label';
|
|
24
|
+
export const BarsStackSeriesLabels = () => {
|
|
25
|
+
const { bars } = useStyleConfigContext();
|
|
26
|
+
const { data, isHorizontal, isVertical, series, sortStackBy, maxWidth, maxHeight, X0Y0, scaleXY0, style, showLabel, fixedBarSize, scaleColorStackSeries, scaleStackSeries, hasOverlay, hasLabel, } = useBars();
|
|
27
|
+
const { maxSize } = style;
|
|
28
|
+
const { fontWeight, fontWeightValue } = bars.label;
|
|
29
|
+
if (!hasLabel)
|
|
30
|
+
return null;
|
|
31
|
+
if (isVertical) {
|
|
32
|
+
return (_jsx(BarStackHorizontal, { data: data, keys: series.dataKey, height: maxHeight, y: X0Y0, xScale: scaleStackSeries, yScale: scaleXY0, color: scaleColorStackSeries, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, i) => (_jsx(Group, { children: barStack.bars.map((bar, j) => {
|
|
33
|
+
const thickness = getStackBarThickness(bar.height, maxSize, fixedBarSize, hasOverlay);
|
|
34
|
+
const yPos = getStackBarIndexPositionSeries(bar, thickness, hasOverlay, isHorizontal);
|
|
35
|
+
const { value, separator, extra } = getStackBarLabelContent(data[j], series.dataKey, series.extraData, i);
|
|
36
|
+
const { rect, text } = getStackBarLabelMorphology(bar, series.extraData, { value, separator, extra }, thickness, { x: undefined, y: yPos }, { xMax: maxWidth, yMax: maxHeight }, isHorizontal);
|
|
37
|
+
const weigth = series.extraData ? fontWeightValue : fontWeight;
|
|
38
|
+
return (_jsx(Group, { children: showLabel && (_jsx(BarsLabel, { wrapper: { ...rect }, text: text, value: value, separator: separator, extraData: extra, fontWeightValue: weigth, dataKey: bar.key })) }, _.uniqueId()));
|
|
39
|
+
}) }, _.uniqueId()))) }));
|
|
40
|
+
}
|
|
41
|
+
return (_jsx(BarStack, { data: data, keys: series.dataKey, width: maxWidth, x: X0Y0, xScale: scaleXY0, yScale: scaleStackSeries, color: scaleColorStackSeries, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, i) => (_jsx(Group, { children: barStack.bars.map((bar, j) => {
|
|
42
|
+
const thickness = getStackBarThickness(bar.width, maxSize, fixedBarSize, hasOverlay);
|
|
43
|
+
const xPos = getStackBarIndexPositionSeries(bar, thickness, hasOverlay, isHorizontal);
|
|
44
|
+
const { value, separator, extra } = getStackBarLabelContent(data[j], series.dataKey, series.extraData, i);
|
|
45
|
+
const { rect, text } = getStackBarLabelMorphology(bar, series.extraData, { value, separator, extra }, thickness, { x: xPos, y: undefined }, { xMax: maxWidth, yMax: maxHeight }, isHorizontal);
|
|
46
|
+
const weigth = series.extraData ? fontWeightValue : fontWeight;
|
|
47
|
+
return (_jsx(Group, { children: showLabel && (_jsx(BarsLabel, { wrapper: { ...rect }, text: text, value: value, separator: separator, extraData: extra, fontWeightValue: weigth, dataKey: bar.key })) }, _.uniqueId()));
|
|
48
|
+
}) }, _.uniqueId()))) }));
|
|
49
|
+
};
|
|
50
|
+
BarsStackSeriesLabels.displayName = 'BarsStackSeriesLabels';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-stack-series.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-stack-series.tsx"],"names":[],"mappings":";AA+BA,eAAO,MAAM,eAAe;;;CA0I3B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 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 { Bar, BarStack, BarStackHorizontal } from '@visx/shape';
|
|
19
|
+
import _ from 'lodash';
|
|
20
|
+
import { useCallback } from 'react';
|
|
21
|
+
import { useBars } from '../../../hooks';
|
|
22
|
+
import { getPrimitiveFromObjectByPath, getStackBarIndexPositionSeries, getStackBarThickness, } from '../../../utils';
|
|
23
|
+
import { useCartesianContext, useStyleConfigContext, useThemeContext } from '../../../providers';
|
|
24
|
+
import { BarsItem, BarsItemBlurred } from './bars.module.css';
|
|
25
|
+
export const BarsStackSeries = () => {
|
|
26
|
+
const { hoveredLegendItem: overLegend } = useCartesianContext();
|
|
27
|
+
const theme = useThemeContext();
|
|
28
|
+
const { themes } = useStyleConfigContext();
|
|
29
|
+
const { data, isHorizontal, isVertical, series, sortStackBy, maxWidth, maxHeight, X0Y0, scaleXY0, style, fixedBarSize, scaleColorStackSeries, scaleStackSeries, hasOverlay, hasBackgroundSeries, } = useBars();
|
|
30
|
+
const { bar: barStyle, maxSize, background } = style;
|
|
31
|
+
const bgColor = themes[theme].bars.backgroundColor;
|
|
32
|
+
const dynamicClassName = useCallback((overLegend, dataKey) => ((overLegend === dataKey || overLegend === '')
|
|
33
|
+
? BarsItem
|
|
34
|
+
: BarsItemBlurred), []);
|
|
35
|
+
if (isVertical) {
|
|
36
|
+
return (_jsx(BarStackHorizontal, { data: data, keys: series.dataKey, height: maxHeight, y: X0Y0, xScale: scaleStackSeries, yScale: scaleXY0, color: scaleColorStackSeries, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, index) => (_jsx(Group, { children: barStack.bars.map((bar) => {
|
|
37
|
+
const thickness = getStackBarThickness(bar.height, maxSize, fixedBarSize, hasOverlay);
|
|
38
|
+
const yPos = getStackBarIndexPositionSeries(bar, thickness, hasOverlay, isHorizontal);
|
|
39
|
+
return (_jsxs(Group, { children: [(hasBackgroundSeries && index === 0) && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: 0, y: bar.y, width: maxWidth, height: thickness, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: bar.x, y: yPos, width: bar.width, height: thickness, fill: bar.color, rx: 0, opacity: barStyle.opacity, onClick: () => ({}) })] }, _.uniqueId()));
|
|
40
|
+
}) }, _.uniqueId()))) }));
|
|
41
|
+
}
|
|
42
|
+
return (_jsx(BarStack, { data: data, keys: series.dataKey, width: maxWidth, x: X0Y0, xScale: scaleXY0, yScale: scaleStackSeries, color: scaleColorStackSeries, value: (d, k) => getPrimitiveFromObjectByPath(d, k) ?? 0, order: sortStackBy, offset: "diverging", children: barStacks => barStacks.map((barStack, index) => (_jsx(Group, { children: barStack.bars.map((bar) => {
|
|
43
|
+
const thickness = getStackBarThickness(bar.width, maxSize, fixedBarSize, hasOverlay);
|
|
44
|
+
const xPos = getStackBarIndexPositionSeries(bar, thickness, hasOverlay, isHorizontal);
|
|
45
|
+
return (_jsxs(Group, { children: [(hasBackgroundSeries && index === 0) && (_jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: bar.x, y: 0, width: thickness, height: maxHeight, fill: bgColor, opacity: background.opacity, rx: background.rx })), _jsx(Bar, { className: dynamicClassName(overLegend, bar.key), x: xPos, y: bar.y, width: thickness, height: bar.height, fill: bar.color, opacity: barStyle.opacity, rx: 0, onClick: () => ({}) })] }, _.uniqueId()));
|
|
46
|
+
}) }, _.uniqueId()))) }));
|
|
47
|
+
};
|
|
48
|
+
BarsStackSeries.displayName = 'BarsStackSeries';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-tooltip.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-tooltip.tsx"],"names":[],"mappings":";AA0DA,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAkO/B,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
18
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
19
|
+
// @ts-nocheck
|
|
20
|
+
import { localPoint } from '@visx/event';
|
|
21
|
+
import { useTooltip, useTooltipInPortal } from '@visx/tooltip';
|
|
22
|
+
import _ from 'lodash';
|
|
23
|
+
import { useCallback } from 'react';
|
|
24
|
+
import { v4 as uuid } from 'uuid';
|
|
25
|
+
import { useBars } from '../../../hooks';
|
|
26
|
+
import { useStyleConfigContext, useThemeContext, } from '../../../providers';
|
|
27
|
+
import { accessorInvert, bisectIndex, getDataKeyParentObject, getPrimitiveFromObjectByPath, } from '../../../utils';
|
|
28
|
+
import { tooltipTheme } from '../../../style-config/tooltip';
|
|
29
|
+
import { Placeholder } from '../../placeholder';
|
|
30
|
+
import { Tooltip } from '../../tooltip';
|
|
31
|
+
import { BarsTooltipContent, BarsTooltipItem, ExtraContent, NoData, } from './bars.module.css';
|
|
32
|
+
export const BarsTooltip = ({ children }) => {
|
|
33
|
+
const theme = useThemeContext();
|
|
34
|
+
const { bars, themes } = useStyleConfigContext();
|
|
35
|
+
const { data, hasOverlay, hasReversedIndex, isHorizontal, index, indexAxis, isStacked, maxWidth: xMax, maxHeight: yMax, overlay, series, preventTooltipDisplay, preventTooltipOpening, tooltipExtraContent, scaleXY0, } = useBars();
|
|
36
|
+
const { tooltipLeft, tooltipTop, tooltipOpen, tooltipData, hideTooltip, showTooltip, } = useTooltip();
|
|
37
|
+
const { containerRef, containerBounds } = useTooltipInPortal({
|
|
38
|
+
detectBounds: true,
|
|
39
|
+
scroll: true,
|
|
40
|
+
debounce: 500,
|
|
41
|
+
zIndex: 4,
|
|
42
|
+
});
|
|
43
|
+
const handleTooltip = useCallback((event) => {
|
|
44
|
+
const { scaleType, } = indexAxis;
|
|
45
|
+
const domain = scaleXY0.domain();
|
|
46
|
+
const { top: tBound, left: lBound } = containerBounds;
|
|
47
|
+
const hiddenPos = { x: -999, y: -999 };
|
|
48
|
+
const xy = isHorizontal ? 'x' : 'y';
|
|
49
|
+
const coords = localPoint(event.target.ownerSVGElement, event) ?? hiddenPos;
|
|
50
|
+
const accessorInvertValue = accessorInvert({ ...indexAxis, domain }, coords[xy]);
|
|
51
|
+
const indexOfBisectValue = scaleType === 'label'
|
|
52
|
+
? domain.indexOf(accessorInvertValue)
|
|
53
|
+
: bisectIndex(domain, accessorInvertValue, 0) - 1;
|
|
54
|
+
const domainIndexValue = domain[indexOfBisectValue];
|
|
55
|
+
const indexScaleValue = scaleType === 'label'
|
|
56
|
+
? accessorInvertValue
|
|
57
|
+
: new Date(domainIndexValue);
|
|
58
|
+
const barIndicatorPos = scaleXY0(indexScaleValue) ?? -999;
|
|
59
|
+
const barIndicatorSize = scaleXY0.bandwidth();
|
|
60
|
+
const barStackIndicatorPos = hasOverlay ? barIndicatorPos - 1 : barIndicatorPos;
|
|
61
|
+
const barStackIndicatorSize = hasOverlay ? Number(barIndicatorSize) + 2 : barIndicatorSize;
|
|
62
|
+
const tooltipLeft = ('clientX' in event ? event.clientX : 0) - lBound / 8;
|
|
63
|
+
const tooltipTop = ('clientY' in event ? event.clientY : 0) - tBound / 8;
|
|
64
|
+
const datum = hasReversedIndex ? data.at(-(indexOfBisectValue - 1)) : data[indexOfBisectValue];
|
|
65
|
+
const hasSeriesData = series.dataKey.every(s => !_.isNil(getPrimitiveFromObjectByPath(datum, s)));
|
|
66
|
+
const hasOverlayData = overlay.dataKey?.every(s => !_.isNil(getPrimitiveFromObjectByPath(datum, s)));
|
|
67
|
+
const tooltipData = {
|
|
68
|
+
coords,
|
|
69
|
+
data: datum,
|
|
70
|
+
hasData: hasSeriesData || hasOverlayData,
|
|
71
|
+
barIndicatorPos: isStacked ? barStackIndicatorPos : barIndicatorPos,
|
|
72
|
+
barIndicatorSize: isStacked ? barStackIndicatorSize : barIndicatorSize,
|
|
73
|
+
};
|
|
74
|
+
showTooltip({
|
|
75
|
+
tooltipLeft,
|
|
76
|
+
tooltipTop,
|
|
77
|
+
tooltipData,
|
|
78
|
+
});
|
|
79
|
+
}, [indexAxis,
|
|
80
|
+
scaleXY0,
|
|
81
|
+
containerBounds,
|
|
82
|
+
isHorizontal,
|
|
83
|
+
hasOverlay,
|
|
84
|
+
hasReversedIndex,
|
|
85
|
+
data,
|
|
86
|
+
series.dataKey,
|
|
87
|
+
overlay.dataKey,
|
|
88
|
+
isStacked,
|
|
89
|
+
showTooltip]);
|
|
90
|
+
const hasTooltip = Boolean(tooltipData?.data && !preventTooltipOpening && !preventTooltipDisplay);
|
|
91
|
+
return (_jsxs(_Fragment, { children: [hasTooltip && (_jsx("rect", { x: isHorizontal ? tooltipData?.barIndicatorPos : 0, y: isHorizontal ? 0 : tooltipData?.barIndicatorPos, width: isHorizontal ? tooltipData?.barIndicatorSize : xMax, height: isHorizontal ? yMax : tooltipData?.barIndicatorSize, fill: themes[theme].bars.overlayColor, fillOpacity: bars.overlay.opacity })), 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
|
|
92
|
+
&& (_jsxs(Tooltip, { isOpen: tooltipOpen, top: tooltipTop, left: tooltipLeft, children: [_jsxs("div", { className: BarsTooltipContent, "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: BarsTooltipItem, children: [_jsx(Placeholder, { color: series.colors[di] }), _jsx("span", { children: series.names[di] })] }), _jsx("div", { children: series?.extraData && (_jsx("p", { children: series.extraData(getDataKeyParentObject(tooltipData?.data, dataKey)) })) }), _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: BarsTooltipItem, children: [_jsx(Placeholder, { color: overlay.colors?.[di] }), _jsx("span", { children: overlay.names?.[di] })] }), _jsx("div", { children: overlay?.extraData && (_jsx("p", { children: overlay.extraData(getDataKeyParentObject(tooltipData?.data, dataKey)) })) }), _jsx("div", { children: _jsx("p", { children: _jsx("b", { children: `${getPrimitiveFromObjectByPath(tooltipData?.data, dataKey) ?? 'n/a'}` }) }) })] }, uuid())))] })] }), (tooltipExtraContent || !tooltipData?.hasData) && (_jsxs("div", { className: ExtraContent, style: { borderColor: tooltipTheme[theme].separatorStroke }, children: [tooltipExtraContent, !tooltipData?.hasData && _jsx("p", { className: NoData, children: "No data available" })] }))] }))] }));
|
|
95
|
+
};
|
|
96
|
+
BarsTooltip.displayName = 'BarsTooltip';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars-trendline.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars-trendline.tsx"],"names":[],"mappings":";AA+BA,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAqEjC,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 { BarsItem, BarsItemBlurred, } from './bars.module.css';
|
|
24
|
+
export const BarsTrendline = () => {
|
|
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
|
+
? BarsItem
|
|
30
|
+
: BarsItemBlurred), []);
|
|
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
|
+
BarsTrendline.displayName = 'BarsTrendline';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../../../src/components/shapes/bars/bars.tsx"],"names":[],"mappings":";AA2BA,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAwCxB,CAAC"}
|
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
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
|
import { Group } from '@visx/group';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { useBars, useSSR } from '../../../hooks';
|
|
19
|
+
import { useCartesianContext, useLayoutContext } from '../../../providers';
|
|
20
|
+
import { BarsAverage } from './bars-average';
|
|
21
|
+
import { BarsLayout } from './bars-layout';
|
|
22
|
+
import { BarsOverlayLabels } from './bars-overlay-labels';
|
|
23
|
+
import { BarsSeriesLabels } from './bars-series-labels';
|
|
24
|
+
import { BarsTooltip } from './bars-tooltip';
|
|
20
25
|
export const Bars = () => {
|
|
26
|
+
const { isVertical } = useLayoutContext();
|
|
21
27
|
const { position } = useCartesianContext();
|
|
22
|
-
|
|
28
|
+
const { top, left } = position;
|
|
29
|
+
const { isBrowser, isServer } = useSSR();
|
|
30
|
+
const { isStacked } = useBars();
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx(Group, { clipPath: "url(#clip-path-cartesian-chart)", children: _jsxs(Group, { top: top, left: left, children: [isServer && _jsx(BarsLayout, {}), isBrowser && (_jsx(BarsTooltip, { children: _jsx(BarsLayout, {}) })), _jsx(BarsAverage, {})] }) }), (!isStacked && isVertical) && (_jsxs(Group, { top: top, left: left, children: [_jsx(BarsSeriesLabels, {}), _jsx(BarsOverlayLabels, {})] }))] }));
|
|
23
32
|
};
|
|
24
33
|
Bars.displayName = 'Bars';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.
|
|
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}
|