@coinbase/cds-mobile-visualization 3.3.0 → 3.4.0-beta.10
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/CHANGELOG.md +80 -0
- package/dts/chart/CartesianChart.d.ts +125 -0
- package/dts/chart/CartesianChart.d.ts.map +1 -0
- package/dts/chart/ChartContextBridge.d.ts +28 -0
- package/dts/chart/ChartContextBridge.d.ts.map +1 -0
- package/dts/chart/ChartProvider.d.ts +6 -0
- package/dts/chart/ChartProvider.d.ts.map +1 -0
- package/dts/chart/Path.d.ts +91 -0
- package/dts/chart/Path.d.ts.map +1 -0
- package/dts/chart/PeriodSelector.d.ts +85 -0
- package/dts/chart/PeriodSelector.d.ts.map +1 -0
- package/dts/chart/area/Area.d.ts +77 -0
- package/dts/chart/area/Area.d.ts.map +1 -0
- package/dts/chart/area/AreaChart.d.ts +131 -0
- package/dts/chart/area/AreaChart.d.ts.map +1 -0
- package/dts/chart/area/DottedArea.d.ts +46 -0
- package/dts/chart/area/DottedArea.d.ts.map +1 -0
- package/dts/chart/area/GradientArea.d.ts +36 -0
- package/dts/chart/area/GradientArea.d.ts.map +1 -0
- package/dts/chart/area/SolidArea.d.ts +23 -0
- package/dts/chart/area/SolidArea.d.ts.map +1 -0
- package/dts/chart/area/index.d.ts +6 -0
- package/dts/chart/area/index.d.ts.map +1 -0
- package/dts/chart/axis/Axis.d.ts +194 -0
- package/dts/chart/axis/Axis.d.ts.map +1 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
- package/dts/chart/axis/XAxis.d.ts +16 -0
- package/dts/chart/axis/XAxis.d.ts.map +1 -0
- package/dts/chart/axis/YAxis.d.ts +21 -0
- package/dts/chart/axis/YAxis.d.ts.map +1 -0
- package/dts/chart/axis/index.d.ts +5 -0
- package/dts/chart/axis/index.d.ts.map +1 -0
- package/dts/chart/bar/Bar.d.ts +92 -0
- package/dts/chart/bar/Bar.d.ts.map +1 -0
- package/dts/chart/bar/BarChart.d.ts +113 -0
- package/dts/chart/bar/BarChart.d.ts.map +1 -0
- package/dts/chart/bar/BarPlot.d.ts +30 -0
- package/dts/chart/bar/BarPlot.d.ts.map +1 -0
- package/dts/chart/bar/BarStack.d.ts +102 -0
- package/dts/chart/bar/BarStack.d.ts.map +1 -0
- package/dts/chart/bar/BarStackGroup.d.ts +36 -0
- package/dts/chart/bar/BarStackGroup.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBar.d.ts +7 -0
- package/dts/chart/bar/DefaultBar.d.ts.map +1 -0
- package/dts/chart/bar/DefaultBarStack.d.ts +7 -0
- package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -0
- package/dts/chart/bar/index.d.ts +8 -0
- package/dts/chart/bar/index.d.ts.map +1 -0
- package/dts/chart/gradient/Gradient.d.ts +25 -0
- package/dts/chart/gradient/Gradient.d.ts.map +1 -0
- package/dts/chart/gradient/index.d.ts +2 -0
- package/dts/chart/gradient/index.d.ts.map +1 -0
- package/dts/chart/index.d.ts +15 -0
- package/dts/chart/index.d.ts.map +1 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
- package/dts/chart/line/DottedLine.d.ts +20 -0
- package/dts/chart/line/DottedLine.d.ts.map +1 -0
- package/dts/chart/line/Line.d.ts +115 -0
- package/dts/chart/line/Line.d.ts.map +1 -0
- package/dts/chart/line/LineChart.d.ts +118 -0
- package/dts/chart/line/LineChart.d.ts.map +1 -0
- package/dts/chart/line/ReferenceLine.d.ts +139 -0
- package/dts/chart/line/ReferenceLine.d.ts.map +1 -0
- package/dts/chart/line/SolidLine.d.ts +15 -0
- package/dts/chart/line/SolidLine.d.ts.map +1 -0
- package/dts/chart/line/index.d.ts +7 -0
- package/dts/chart/line/index.d.ts.map +1 -0
- package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
- package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
- package/dts/chart/point/Point.d.ts +120 -0
- package/dts/chart/point/Point.d.ts.map +1 -0
- package/dts/chart/point/index.d.ts +3 -0
- package/dts/chart/point/index.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +8 -0
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
- package/dts/chart/scrubber/Scrubber.d.ts +233 -0
- package/dts/chart/scrubber/Scrubber.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +44 -0
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +31 -0
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts +20 -0
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -0
- package/dts/chart/scrubber/index.d.ts +5 -0
- package/dts/chart/scrubber/index.d.ts.map +1 -0
- package/dts/chart/text/ChartText.d.ts +164 -0
- package/dts/chart/text/ChartText.d.ts.map +1 -0
- package/dts/chart/text/ChartTextGroup.d.ts +61 -0
- package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
- package/dts/chart/text/index.d.ts +3 -0
- package/dts/chart/text/index.d.ts.map +1 -0
- package/dts/chart/utils/axis.d.ts +342 -0
- package/dts/chart/utils/axis.d.ts.map +1 -0
- package/dts/chart/utils/bar.d.ts +20 -0
- package/dts/chart/utils/bar.d.ts.map +1 -0
- package/dts/chart/utils/chart.d.ts +124 -0
- package/dts/chart/utils/chart.d.ts.map +1 -0
- package/dts/chart/utils/context.d.ts +116 -0
- package/dts/chart/utils/context.d.ts.map +1 -0
- package/dts/chart/utils/gradient.d.ts +117 -0
- package/dts/chart/utils/gradient.d.ts.map +1 -0
- package/dts/chart/utils/index.d.ts +11 -0
- package/dts/chart/utils/index.d.ts.map +1 -0
- package/dts/chart/utils/path.d.ts +160 -0
- package/dts/chart/utils/path.d.ts.map +1 -0
- package/dts/chart/utils/point.d.ts +134 -0
- package/dts/chart/utils/point.d.ts.map +1 -0
- package/dts/chart/utils/scale.d.ts +134 -0
- package/dts/chart/utils/scale.d.ts.map +1 -0
- package/dts/chart/utils/scrubber.d.ts +39 -0
- package/dts/chart/utils/scrubber.d.ts.map +1 -0
- package/dts/chart/utils/transition.d.ts +140 -0
- package/dts/chart/utils/transition.d.ts.map +1 -0
- package/dts/index.d.ts +2 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/Counter.d.ts +7 -2
- package/dts/sparkline/Sparkline.d.ts +67 -16
- package/dts/sparkline/Sparkline.d.ts.map +1 -1
- package/dts/sparkline/SparklineArea.d.ts +10 -4
- package/dts/sparkline/SparklineArea.d.ts.map +1 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +12 -4
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +1 -1
- package/dts/sparkline/SparklineGradient.d.ts +21 -10
- package/dts/sparkline/SparklineGradient.d.ts.map +1 -1
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +1 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +8 -2
- package/dts/sparkline/generateSparklineWithId.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +8 -3
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +132 -110
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +22 -9
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +18 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +9 -4
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +7 -5
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +22 -10
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +21 -7
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +1 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +21 -16
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +29 -23
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +22 -14
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +9 -5
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +11 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +5 -2
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +17 -17
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +16 -13
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +106 -98
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +1 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +22 -19
- package/esm/chart/CartesianChart.js +335 -0
- package/esm/chart/ChartContextBridge.js +148 -0
- package/esm/chart/ChartProvider.js +10 -0
- package/esm/chart/Path.js +218 -0
- package/esm/chart/PeriodSelector.js +136 -0
- package/esm/chart/__stories__/CartesianChart.stories.js +723 -0
- package/esm/chart/__stories__/Chart.stories.js +77 -0
- package/esm/chart/__stories__/PeriodSelector.stories.js +322 -0
- package/esm/chart/area/Area.js +75 -0
- package/esm/chart/area/AreaChart.js +151 -0
- package/esm/chart/area/DottedArea.js +80 -0
- package/esm/chart/area/GradientArea.js +54 -0
- package/esm/chart/area/SolidArea.js +38 -0
- package/esm/chart/area/__stories__/AreaChart.stories.js +100 -0
- package/esm/chart/area/index.js +7 -0
- package/esm/chart/axis/Axis.js +45 -0
- package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
- package/esm/chart/axis/XAxis.js +188 -0
- package/esm/chart/axis/YAxis.js +177 -0
- package/esm/chart/axis/__stories__/Axis.stories.js +276 -0
- package/esm/chart/axis/index.js +6 -0
- package/esm/chart/bar/Bar.js +69 -0
- package/esm/chart/bar/BarChart.js +125 -0
- package/esm/chart/bar/BarPlot.js +102 -0
- package/esm/chart/bar/BarStack.js +551 -0
- package/esm/chart/bar/BarStackGroup.js +79 -0
- package/esm/chart/bar/DefaultBar.js +56 -0
- package/esm/chart/bar/DefaultBarStack.js +47 -0
- package/esm/chart/bar/__stories__/BarChart.stories.js +668 -0
- package/esm/chart/bar/index.js +9 -0
- package/esm/chart/gradient/Gradient.js +53 -0
- package/esm/chart/gradient/index.js +1 -0
- package/esm/chart/index.js +16 -0
- package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
- package/esm/chart/line/DottedLine.js +50 -0
- package/esm/chart/line/Line.js +178 -0
- package/esm/chart/line/LineChart.js +121 -0
- package/esm/chart/line/ReferenceLine.js +132 -0
- package/esm/chart/line/SolidLine.js +46 -0
- package/esm/chart/line/__stories__/LineChart.stories.js +2372 -0
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +132 -0
- package/esm/chart/line/index.js +8 -0
- package/esm/chart/point/DefaultPointLabel.js +39 -0
- package/esm/chart/point/Point.js +188 -0
- package/esm/chart/point/index.js +2 -0
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +179 -0
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
- package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
- package/esm/chart/scrubber/Scrubber.js +166 -0
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
- package/esm/chart/scrubber/ScrubberProvider.js +135 -0
- package/esm/chart/scrubber/index.js +4 -0
- package/esm/chart/text/ChartText.js +305 -0
- package/esm/chart/text/ChartTextGroup.js +211 -0
- package/esm/chart/text/index.js +4 -0
- package/esm/chart/utils/axis.js +592 -0
- package/esm/chart/utils/bar.js +24 -0
- package/esm/chart/utils/chart.js +270 -0
- package/esm/chart/utils/context.js +15 -0
- package/esm/chart/utils/gradient.js +305 -0
- package/esm/chart/utils/index.js +12 -0
- package/esm/chart/utils/path.js +274 -0
- package/esm/chart/utils/point.js +229 -0
- package/esm/chart/utils/scale.js +277 -0
- package/esm/chart/utils/scrubber.js +139 -0
- package/esm/chart/utils/transition.js +185 -0
- package/esm/index.js +4 -1
- package/esm/sparkline/Sparkline.js +129 -16
- package/esm/sparkline/SparklineArea.js +7 -2
- package/esm/sparkline/SparklineAreaPattern.js +4 -2
- package/esm/sparkline/SparklineGradient.js +4 -0
- package/esm/sparkline/__stories__/Sparkline.stories.js +11 -7
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +7 -4
- package/esm/sparkline/generateSparklineWithId.js +3 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +5 -1
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +5 -2
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +4 -0
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +76 -24
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +17 -9
- package/package.json +17 -11
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/Sparkline.stories.d.ts.map +0 -1
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts +0 -3
- package/dts/sparkline/__stories__/SparklineGradient.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts +0 -3
- package/dts/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractive.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveHoverDate.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePanGestureHandler.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractivePeriodSelector.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/SparklineInteractiveTimeseriesPaths.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__tests__/useMinMaxTransform.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts +0 -4
- package/dts/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/SparklineInteractiveHeader.test.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__tests__/useSparklineInteractiveHeaderStyles.test.d.ts.map +0 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const _excluded = ["axisId", "position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "TickLabelComponent", "GridLineComponent", "LineComponent", "TickMarkLineComponent", "tickMarkLabelGap", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "label", "labelGap", "width"];
|
|
2
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
3
|
+
import { memo, useCallback, useEffect, useId, useMemo } from 'react';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { Group, vec } from '@shopify/react-native-skia';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { DottedLine } from '../line/DottedLine';
|
|
8
|
+
import { ReferenceLine } from '../line/ReferenceLine';
|
|
9
|
+
import { SolidLine } from '../line/SolidLine';
|
|
10
|
+
import { ChartText } from '../text/ChartText';
|
|
11
|
+
import { ChartTextGroup } from '../text/ChartTextGroup';
|
|
12
|
+
import { getAxisTicksData, isCategoricalScale, lineToPath } from '../utils';
|
|
13
|
+
import { DefaultAxisTickLabel } from './DefaultAxisTickLabel';
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
const AXIS_WIDTH = 44;
|
|
16
|
+
const LABEL_SIZE = 20;
|
|
17
|
+
export const YAxis = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
axisId,
|
|
20
|
+
position = 'right',
|
|
21
|
+
showGrid,
|
|
22
|
+
requestedTickCount = 5,
|
|
23
|
+
ticks,
|
|
24
|
+
tickLabelFormatter,
|
|
25
|
+
TickLabelComponent = DefaultAxisTickLabel,
|
|
26
|
+
GridLineComponent = DottedLine,
|
|
27
|
+
LineComponent = SolidLine,
|
|
28
|
+
TickMarkLineComponent = SolidLine,
|
|
29
|
+
tickMarkLabelGap = 8,
|
|
30
|
+
minTickLabelGap = 0,
|
|
31
|
+
showTickMarks,
|
|
32
|
+
showLine,
|
|
33
|
+
tickMarkSize = 4,
|
|
34
|
+
tickInterval,
|
|
35
|
+
label,
|
|
36
|
+
labelGap = 4,
|
|
37
|
+
width = label ? AXIS_WIDTH + LABEL_SIZE : AXIS_WIDTH
|
|
38
|
+
} = _ref,
|
|
39
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
40
|
+
const theme = useTheme();
|
|
41
|
+
const registrationId = useId();
|
|
42
|
+
const {
|
|
43
|
+
animate,
|
|
44
|
+
getYScale,
|
|
45
|
+
getYAxis,
|
|
46
|
+
registerAxis,
|
|
47
|
+
unregisterAxis,
|
|
48
|
+
getAxisBounds
|
|
49
|
+
} = useCartesianChartContext();
|
|
50
|
+
const yScale = getYScale(axisId);
|
|
51
|
+
const yAxis = getYAxis(axisId);
|
|
52
|
+
const axisBounds = getAxisBounds(registrationId);
|
|
53
|
+
|
|
54
|
+
// Note: gridOpacity not currently used in Skia version
|
|
55
|
+
// const gridOpacity = useSharedValue(1);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
registerAxis(registrationId, position, width);
|
|
59
|
+
return () => unregisterAxis(registrationId);
|
|
60
|
+
}, [registrationId, registerAxis, unregisterAxis, position, width]);
|
|
61
|
+
const formatTick = useCallback(value => {
|
|
62
|
+
var _tickLabelFormatter;
|
|
63
|
+
// If we have string labels and no custom formatter, use the labels
|
|
64
|
+
const axisData = yAxis == null ? void 0 : yAxis.data;
|
|
65
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
66
|
+
if (hasStringLabels && !tickLabelFormatter && axisData[value] !== undefined) {
|
|
67
|
+
// Use the string label from the data array
|
|
68
|
+
return axisData[value];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Otherwise use the formatter (if provided) or the value itself
|
|
72
|
+
return (_tickLabelFormatter = tickLabelFormatter == null ? void 0 : tickLabelFormatter(value)) != null ? _tickLabelFormatter : value;
|
|
73
|
+
}, [yAxis == null ? void 0 : yAxis.data, tickLabelFormatter]);
|
|
74
|
+
|
|
75
|
+
// Use D3 to get the ticks data
|
|
76
|
+
// Result contains each tick value and its axis position
|
|
77
|
+
const ticksData = useMemo(() => {
|
|
78
|
+
if (!yScale) return [];
|
|
79
|
+
|
|
80
|
+
// Check if we have string labels
|
|
81
|
+
const axisData = yAxis == null ? void 0 : yAxis.data;
|
|
82
|
+
const hasStringLabels = axisData && Array.isArray(axisData) && typeof axisData[0] === 'string';
|
|
83
|
+
|
|
84
|
+
// For band scales, we need categories
|
|
85
|
+
let categories;
|
|
86
|
+
if (hasStringLabels) {
|
|
87
|
+
categories = axisData;
|
|
88
|
+
} else if (isCategoricalScale(yScale)) {
|
|
89
|
+
// For band scales without explicit string data, generate numeric categories
|
|
90
|
+
// based on the domain of the scale
|
|
91
|
+
const domain = yScale.domain();
|
|
92
|
+
categories = domain.map(String);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// For numeric data or no explicit data, use default tick generation
|
|
96
|
+
return getAxisTicksData({
|
|
97
|
+
scaleFunction: yScale,
|
|
98
|
+
ticks,
|
|
99
|
+
requestedTickCount: tickInterval !== undefined ? undefined : requestedTickCount != null ? requestedTickCount : 5,
|
|
100
|
+
categories,
|
|
101
|
+
possibleTickValues: axisData && Array.isArray(axisData) && typeof axisData[0] === 'number' ? axisData : undefined,
|
|
102
|
+
tickInterval: tickInterval
|
|
103
|
+
});
|
|
104
|
+
}, [ticks, yScale, requestedTickCount, tickInterval, yAxis == null ? void 0 : yAxis.data]);
|
|
105
|
+
const chartTextData = useMemo(() => {
|
|
106
|
+
if (!axisBounds) return null;
|
|
107
|
+
return ticksData.map(tick => {
|
|
108
|
+
const tickOffset = tickMarkLabelGap + (showTickMarks ? tickMarkSize : 0);
|
|
109
|
+
const labelX = position === 'left' ? axisBounds.x + axisBounds.width - tickOffset : axisBounds.x + tickOffset;
|
|
110
|
+
return {
|
|
111
|
+
x: labelX,
|
|
112
|
+
y: tick.position,
|
|
113
|
+
label: String(formatTick(tick.tick)),
|
|
114
|
+
chartTextProps: {
|
|
115
|
+
color: theme.color.fgMuted,
|
|
116
|
+
verticalAlignment: 'middle',
|
|
117
|
+
horizontalAlignment: position === 'left' ? 'right' : 'left'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}, [axisBounds, ticksData, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, theme.color.fgMuted]);
|
|
122
|
+
if (!yScale || !axisBounds) return;
|
|
123
|
+
const labelX = position === 'left' ? axisBounds.x + LABEL_SIZE / 2 : axisBounds.x + axisBounds.width - LABEL_SIZE / 2;
|
|
124
|
+
const labelY = axisBounds.y + axisBounds.height / 2;
|
|
125
|
+
return /*#__PURE__*/_jsxs(Group, {
|
|
126
|
+
children: [showGrid && /*#__PURE__*/_jsx(Group, {
|
|
127
|
+
children: ticksData.map((tick, index) => {
|
|
128
|
+
const horizontalLine = /*#__PURE__*/_jsx(ReferenceLine, {
|
|
129
|
+
LineComponent: GridLineComponent,
|
|
130
|
+
dataY: tick.tick,
|
|
131
|
+
yAxisId: axisId
|
|
132
|
+
});
|
|
133
|
+
return /*#__PURE__*/_jsx(Group, {
|
|
134
|
+
children: horizontalLine
|
|
135
|
+
}, "grid-" + tick.tick + "-" + index);
|
|
136
|
+
})
|
|
137
|
+
}), chartTextData && /*#__PURE__*/_jsx(ChartTextGroup, {
|
|
138
|
+
prioritizeEndLabels: true,
|
|
139
|
+
LabelComponent: TickLabelComponent,
|
|
140
|
+
labels: chartTextData,
|
|
141
|
+
minGap: minTickLabelGap
|
|
142
|
+
}), axisBounds && showTickMarks && /*#__PURE__*/_jsx(Group, {
|
|
143
|
+
children: ticksData.map((tick, index) => {
|
|
144
|
+
const tickX = position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x;
|
|
145
|
+
const tickMarkSizePixels = tickMarkSize;
|
|
146
|
+
const tickX2 = position === 'left' ? axisBounds.x + axisBounds.width - tickMarkSizePixels : axisBounds.x + tickMarkSizePixels;
|
|
147
|
+
return /*#__PURE__*/_jsx(TickMarkLineComponent, {
|
|
148
|
+
animate: false,
|
|
149
|
+
clipPath: null,
|
|
150
|
+
d: lineToPath(tickX, tick.position, tickX2, tick.position),
|
|
151
|
+
stroke: theme.color.fg,
|
|
152
|
+
strokeCap: "square",
|
|
153
|
+
strokeWidth: 1
|
|
154
|
+
}, "tick-mark-" + tick.tick + "-" + index);
|
|
155
|
+
})
|
|
156
|
+
}), showLine && /*#__PURE__*/_jsx(LineComponent, {
|
|
157
|
+
animate: false,
|
|
158
|
+
clipPath: null,
|
|
159
|
+
d: lineToPath(position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x, axisBounds.y, position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x, axisBounds.y + axisBounds.height),
|
|
160
|
+
stroke: theme.color.fg,
|
|
161
|
+
strokeCap: "square",
|
|
162
|
+
strokeWidth: 1
|
|
163
|
+
}), label && /*#__PURE__*/_jsx(Group, {
|
|
164
|
+
origin: vec(labelX, labelY),
|
|
165
|
+
transform: [{
|
|
166
|
+
rotate: position === 'left' ? -Math.PI / 2 : Math.PI / 2
|
|
167
|
+
}],
|
|
168
|
+
children: /*#__PURE__*/_jsx(ChartText, {
|
|
169
|
+
horizontalAlignment: "center",
|
|
170
|
+
verticalAlignment: "middle",
|
|
171
|
+
x: labelX,
|
|
172
|
+
y: labelY,
|
|
173
|
+
children: label
|
|
174
|
+
})
|
|
175
|
+
})]
|
|
176
|
+
});
|
|
177
|
+
});
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
|
|
4
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
5
|
+
import { CartesianChart } from '../../CartesianChart';
|
|
6
|
+
import { LineChart, SolidLine } from '../../line';
|
|
7
|
+
import { Line } from '../../line/Line';
|
|
8
|
+
import { Scrubber } from '../../scrubber/Scrubber';
|
|
9
|
+
import { XAxis, YAxis } from '..';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const defaultChartHeight = 250;
|
|
12
|
+
const ThinSolidLine = /*#__PURE__*/memo(props => /*#__PURE__*/_jsx(SolidLine, _extends({}, props, {
|
|
13
|
+
strokeWidth: 1
|
|
14
|
+
})));
|
|
15
|
+
const Simple = () => {
|
|
16
|
+
const data = [{
|
|
17
|
+
name: 'Page A',
|
|
18
|
+
uv: 4000,
|
|
19
|
+
pv: 2400,
|
|
20
|
+
amt: 2400
|
|
21
|
+
}, {
|
|
22
|
+
name: 'Page B',
|
|
23
|
+
uv: 3000,
|
|
24
|
+
pv: 1398,
|
|
25
|
+
amt: 2210
|
|
26
|
+
}, {
|
|
27
|
+
name: 'Page C',
|
|
28
|
+
uv: 2000,
|
|
29
|
+
pv: 9800,
|
|
30
|
+
amt: 2290
|
|
31
|
+
}, {
|
|
32
|
+
name: 'Page D',
|
|
33
|
+
uv: 2780,
|
|
34
|
+
pv: 3908,
|
|
35
|
+
amt: 2000
|
|
36
|
+
}, {
|
|
37
|
+
name: 'Page E',
|
|
38
|
+
uv: 1890,
|
|
39
|
+
pv: 4800,
|
|
40
|
+
amt: 2181
|
|
41
|
+
}, {
|
|
42
|
+
name: 'Page F',
|
|
43
|
+
uv: 2390,
|
|
44
|
+
pv: 3800,
|
|
45
|
+
amt: 2500
|
|
46
|
+
}, {
|
|
47
|
+
name: 'Page G',
|
|
48
|
+
uv: 3490,
|
|
49
|
+
pv: 4300,
|
|
50
|
+
amt: 2100
|
|
51
|
+
}];
|
|
52
|
+
const pageViews = data.map(d => d.pv);
|
|
53
|
+
const pageNames = data.map(d => d.name);
|
|
54
|
+
const pageUniqueVisitors = data.map(d => d.uv);
|
|
55
|
+
return /*#__PURE__*/_jsx(LineChart, {
|
|
56
|
+
enableScrubbing: true,
|
|
57
|
+
showXAxis: true,
|
|
58
|
+
showYAxis: true,
|
|
59
|
+
height: defaultChartHeight,
|
|
60
|
+
inset: 32,
|
|
61
|
+
series: [{
|
|
62
|
+
id: 'pageViews',
|
|
63
|
+
data: pageViews,
|
|
64
|
+
label: 'Page Views',
|
|
65
|
+
color: '#8884d8',
|
|
66
|
+
curve: 'monotone'
|
|
67
|
+
}, {
|
|
68
|
+
id: 'uniqueVisitors',
|
|
69
|
+
data: pageUniqueVisitors,
|
|
70
|
+
label: 'Unique Visitors',
|
|
71
|
+
color: '#82ca9d',
|
|
72
|
+
curve: 'monotone'
|
|
73
|
+
}],
|
|
74
|
+
xAxis: {
|
|
75
|
+
data: pageNames,
|
|
76
|
+
showLine: true,
|
|
77
|
+
showGrid: true,
|
|
78
|
+
showTickMarks: true,
|
|
79
|
+
GridLineComponent: ThinSolidLine,
|
|
80
|
+
position: 'bottom',
|
|
81
|
+
requestedTickCount: 5
|
|
82
|
+
},
|
|
83
|
+
yAxis: {
|
|
84
|
+
domain: {
|
|
85
|
+
min: 0
|
|
86
|
+
},
|
|
87
|
+
showGrid: true,
|
|
88
|
+
showLine: true,
|
|
89
|
+
showTickMarks: true,
|
|
90
|
+
GridLineComponent: ThinSolidLine,
|
|
91
|
+
position: 'left',
|
|
92
|
+
requestedTickCount: 5
|
|
93
|
+
},
|
|
94
|
+
children: /*#__PURE__*/_jsx(Scrubber, {})
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const TimeOfDayAxesExample = () => {
|
|
98
|
+
const theme = useTheme();
|
|
99
|
+
const lineA = [5, 5, 10, 90, 85, 70, 30, 25, 25];
|
|
100
|
+
const lineB = [90, 85, 70, 25, 23, 40, 45, 40, 50];
|
|
101
|
+
const timeData = useMemo(() => [new Date(2023, 7, 31), new Date(2023, 7, 31, 12), new Date(2023, 8, 1), new Date(2023, 8, 1, 12), new Date(2023, 8, 2), new Date(2023, 8, 2, 12), new Date(2023, 8, 3), new Date(2023, 8, 3, 12), new Date(2023, 8, 4)].map(d => d.getTime()), []);
|
|
102
|
+
const dateFormatter = useCallback(index => {
|
|
103
|
+
return new Date(timeData[index]).toLocaleDateString('en-US', {
|
|
104
|
+
month: '2-digit',
|
|
105
|
+
day: '2-digit'
|
|
106
|
+
});
|
|
107
|
+
}, [timeData]);
|
|
108
|
+
const timeOfDayFormatter = useCallback(index => {
|
|
109
|
+
return new Date(timeData[index]).toLocaleTimeString('en-US', {
|
|
110
|
+
hour: '2-digit'
|
|
111
|
+
});
|
|
112
|
+
}, [timeData]);
|
|
113
|
+
const timeOfDayTicks = useMemo(() => {
|
|
114
|
+
return timeData.map((d, index) => index);
|
|
115
|
+
}, [timeData]);
|
|
116
|
+
const dateTicks = useMemo(() => {
|
|
117
|
+
return timeData.map((d, index) => index).filter(d => d % 2 === 0);
|
|
118
|
+
}, [timeData]);
|
|
119
|
+
return /*#__PURE__*/_jsxs(LineChart, {
|
|
120
|
+
enableScrubbing: true,
|
|
121
|
+
height: defaultChartHeight,
|
|
122
|
+
series: [{
|
|
123
|
+
id: 'lineA',
|
|
124
|
+
data: lineA,
|
|
125
|
+
color: theme.color.accentBoldBlue
|
|
126
|
+
}, {
|
|
127
|
+
id: 'lineB',
|
|
128
|
+
data: lineB,
|
|
129
|
+
color: theme.color.accentBoldGreen
|
|
130
|
+
}],
|
|
131
|
+
yAxis: {
|
|
132
|
+
domain: {
|
|
133
|
+
min: 0,
|
|
134
|
+
max: 100
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
138
|
+
showLine: true,
|
|
139
|
+
showTickMarks: true,
|
|
140
|
+
position: "top",
|
|
141
|
+
tickLabelFormatter: dateFormatter,
|
|
142
|
+
ticks: dateTicks
|
|
143
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
144
|
+
showGrid: true,
|
|
145
|
+
showLine: true,
|
|
146
|
+
showTickMarks: true,
|
|
147
|
+
tickLabelFormatter: timeOfDayFormatter,
|
|
148
|
+
ticks: timeOfDayTicks
|
|
149
|
+
}), /*#__PURE__*/_jsx(Scrubber, {})]
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const MultipleYAxesExample = () => /*#__PURE__*/_jsxs(CartesianChart, {
|
|
153
|
+
enableScrubbing: true,
|
|
154
|
+
height: defaultChartHeight,
|
|
155
|
+
series: [{
|
|
156
|
+
id: 'linear',
|
|
157
|
+
yAxisId: 'linearAxis',
|
|
158
|
+
data: [1, 10, 30, 50, 70, 90, 100],
|
|
159
|
+
label: 'linear'
|
|
160
|
+
}, {
|
|
161
|
+
id: 'log',
|
|
162
|
+
yAxisId: 'logAxis',
|
|
163
|
+
data: [1, 10, 30, 50, 70, 90, 100],
|
|
164
|
+
label: 'log'
|
|
165
|
+
}],
|
|
166
|
+
xAxis: {
|
|
167
|
+
data: [1, 10, 30, 50, 70, 90, 100]
|
|
168
|
+
},
|
|
169
|
+
yAxis: [{
|
|
170
|
+
id: 'linearAxis',
|
|
171
|
+
scaleType: 'linear'
|
|
172
|
+
}, {
|
|
173
|
+
id: 'logAxis',
|
|
174
|
+
scaleType: 'log'
|
|
175
|
+
}],
|
|
176
|
+
children: [/*#__PURE__*/_jsx(XAxis, {
|
|
177
|
+
showLine: true,
|
|
178
|
+
showTickMarks: true
|
|
179
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
180
|
+
showLine: true,
|
|
181
|
+
showTickMarks: true,
|
|
182
|
+
axisId: "logAxis",
|
|
183
|
+
position: "left"
|
|
184
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
185
|
+
showLine: true,
|
|
186
|
+
showTickMarks: true,
|
|
187
|
+
axisId: "linearAxis",
|
|
188
|
+
position: "left"
|
|
189
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
190
|
+
curve: "natural",
|
|
191
|
+
seriesId: "linear"
|
|
192
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
193
|
+
curve: "natural",
|
|
194
|
+
seriesId: "log"
|
|
195
|
+
}), /*#__PURE__*/_jsx(Scrubber, {})]
|
|
196
|
+
});
|
|
197
|
+
const DomainLimitType = _ref => {
|
|
198
|
+
let {
|
|
199
|
+
limit
|
|
200
|
+
} = _ref;
|
|
201
|
+
const exponentialData = [1, 2, 4, 8, 15, 30, 65, 140, 280, 580, 1200, 2400, 4800, 9500, 19000, 38000, 75000, 150000];
|
|
202
|
+
return /*#__PURE__*/_jsxs(CartesianChart, {
|
|
203
|
+
enableScrubbing: true,
|
|
204
|
+
height: defaultChartHeight,
|
|
205
|
+
series: [{
|
|
206
|
+
id: 'growthLinear',
|
|
207
|
+
data: exponentialData,
|
|
208
|
+
color: '#10b981',
|
|
209
|
+
yAxisId: 'linear'
|
|
210
|
+
}, {
|
|
211
|
+
id: 'growthExponential',
|
|
212
|
+
data: exponentialData,
|
|
213
|
+
color: '#10b981',
|
|
214
|
+
yAxisId: 'exponential'
|
|
215
|
+
}],
|
|
216
|
+
yAxis: [{
|
|
217
|
+
id: 'linear',
|
|
218
|
+
scaleType: 'linear',
|
|
219
|
+
domainLimit: limit
|
|
220
|
+
}, {
|
|
221
|
+
id: 'exponential',
|
|
222
|
+
scaleType: 'log',
|
|
223
|
+
domainLimit: limit
|
|
224
|
+
}],
|
|
225
|
+
children: [/*#__PURE__*/_jsx(Line, {
|
|
226
|
+
showArea: true,
|
|
227
|
+
curve: "natural",
|
|
228
|
+
seriesId: "growthLinear"
|
|
229
|
+
}), /*#__PURE__*/_jsx(Line, {
|
|
230
|
+
showArea: true,
|
|
231
|
+
curve: "natural",
|
|
232
|
+
seriesId: "growthExponential"
|
|
233
|
+
}), /*#__PURE__*/_jsx(XAxis, {
|
|
234
|
+
showLine: true
|
|
235
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
236
|
+
showLine: true,
|
|
237
|
+
showTickMarks: true,
|
|
238
|
+
axisId: "exponential",
|
|
239
|
+
position: "left",
|
|
240
|
+
requestedTickCount: 6,
|
|
241
|
+
tickLabelFormatter: value => value.toLocaleString(),
|
|
242
|
+
width: 70
|
|
243
|
+
}), /*#__PURE__*/_jsx(YAxis, {
|
|
244
|
+
showLine: true,
|
|
245
|
+
showTickMarks: true,
|
|
246
|
+
axisId: "linear",
|
|
247
|
+
tickLabelFormatter: value => value.toLocaleString(),
|
|
248
|
+
width: 70
|
|
249
|
+
}), /*#__PURE__*/_jsx(Scrubber, {})]
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
const AxisStories = () => {
|
|
253
|
+
return /*#__PURE__*/_jsxs(ExampleScreen, {
|
|
254
|
+
children: [/*#__PURE__*/_jsx(Example, {
|
|
255
|
+
title: "Basic",
|
|
256
|
+
children: /*#__PURE__*/_jsx(Simple, {})
|
|
257
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
258
|
+
title: "Time of Day",
|
|
259
|
+
children: /*#__PURE__*/_jsx(TimeOfDayAxesExample, {})
|
|
260
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
261
|
+
title: "Multiple Axes on Same Side",
|
|
262
|
+
children: /*#__PURE__*/_jsx(MultipleYAxesExample, {})
|
|
263
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
264
|
+
title: "Strict Domain Limit",
|
|
265
|
+
children: /*#__PURE__*/_jsx(DomainLimitType, {
|
|
266
|
+
limit: "strict"
|
|
267
|
+
})
|
|
268
|
+
}), /*#__PURE__*/_jsx(Example, {
|
|
269
|
+
title: "Nice Domain Limit",
|
|
270
|
+
children: /*#__PURE__*/_jsx(DomainLimitType, {
|
|
271
|
+
limit: "nice"
|
|
272
|
+
})
|
|
273
|
+
})]
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
export default AxisStories;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { memo, useMemo } from 'react';
|
|
2
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
3
|
+
import { getBarPath } from '../utils';
|
|
4
|
+
import { DefaultBar } from './DefaultBar';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Simple bar component that renders a single bar at the specified position.
|
|
8
|
+
*
|
|
9
|
+
* This component is intentionally kept simple - it just renders a static bar at the given
|
|
10
|
+
* x, y, width, height coordinates. Complex positioning logic (like handling stacks,
|
|
11
|
+
* groups, gaps, etc.) should be handled by parent components like BarChart or BarStack.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <Bar x={10} y={20} width={50} height={100} fill="blue" />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const Bar = /*#__PURE__*/memo(_ref => {
|
|
19
|
+
let {
|
|
20
|
+
x,
|
|
21
|
+
y,
|
|
22
|
+
width,
|
|
23
|
+
height,
|
|
24
|
+
originY,
|
|
25
|
+
dataX,
|
|
26
|
+
dataY,
|
|
27
|
+
BarComponent = DefaultBar,
|
|
28
|
+
fill,
|
|
29
|
+
fillOpacity = 1,
|
|
30
|
+
stroke,
|
|
31
|
+
strokeWidth,
|
|
32
|
+
borderRadius = 4,
|
|
33
|
+
roundTop = true,
|
|
34
|
+
roundBottom = true,
|
|
35
|
+
transition
|
|
36
|
+
} = _ref;
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
|
|
39
|
+
// Use theme color as default if no fill is provided
|
|
40
|
+
const effectiveFill = fill != null ? fill : theme.color.fgPrimary;
|
|
41
|
+
const borderRadiusPixels = useMemo(() => borderRadius != null ? borderRadius : 0, [borderRadius]);
|
|
42
|
+
const barPath = useMemo(() => {
|
|
43
|
+
return getBarPath(x, y, width, height, borderRadiusPixels, roundTop, roundBottom);
|
|
44
|
+
}, [x, y, width, height, borderRadiusPixels, roundTop, roundBottom]);
|
|
45
|
+
const effectiveOriginY = originY != null ? originY : y + height;
|
|
46
|
+
if (!barPath) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Always use the BarComponent for rendering
|
|
51
|
+
return /*#__PURE__*/_jsx(BarComponent, {
|
|
52
|
+
borderRadius: borderRadius,
|
|
53
|
+
d: barPath,
|
|
54
|
+
dataX: dataX,
|
|
55
|
+
dataY: dataY,
|
|
56
|
+
fill: effectiveFill,
|
|
57
|
+
fillOpacity: fillOpacity,
|
|
58
|
+
height: height,
|
|
59
|
+
originY: effectiveOriginY,
|
|
60
|
+
roundBottom: roundBottom,
|
|
61
|
+
roundTop: roundTop,
|
|
62
|
+
stroke: stroke,
|
|
63
|
+
strokeWidth: strokeWidth,
|
|
64
|
+
transition: transition,
|
|
65
|
+
width: width,
|
|
66
|
+
x: x,
|
|
67
|
+
y: y
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const _excluded = ["series", "stacked", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children", "barPadding", "BarComponent", "fillOpacity", "stroke", "strokeWidth", "borderRadius", "roundBaseline", "BarStackComponent", "stackGap", "barMinSize", "stackMinSize", "transition"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"];
|
|
4
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
5
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
6
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
7
|
+
import { XAxis, YAxis } from '../axis';
|
|
8
|
+
import { CartesianChart } from '../CartesianChart';
|
|
9
|
+
import { defaultChartInset, defaultStackId, getChartInset } from '../utils';
|
|
10
|
+
import { BarPlot } from './BarPlot';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
export const BarChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
13
|
+
let {
|
|
14
|
+
series,
|
|
15
|
+
stacked,
|
|
16
|
+
showXAxis,
|
|
17
|
+
showYAxis,
|
|
18
|
+
xAxis,
|
|
19
|
+
yAxis,
|
|
20
|
+
inset,
|
|
21
|
+
children,
|
|
22
|
+
barPadding,
|
|
23
|
+
BarComponent,
|
|
24
|
+
fillOpacity,
|
|
25
|
+
stroke,
|
|
26
|
+
strokeWidth,
|
|
27
|
+
borderRadius,
|
|
28
|
+
roundBaseline,
|
|
29
|
+
BarStackComponent,
|
|
30
|
+
stackGap,
|
|
31
|
+
barMinSize,
|
|
32
|
+
stackMinSize,
|
|
33
|
+
transition
|
|
34
|
+
} = _ref,
|
|
35
|
+
chartProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
36
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
37
|
+
const transformedSeries = useMemo(() => {
|
|
38
|
+
if (!stacked || !series) return series;
|
|
39
|
+
return series.map(s => {
|
|
40
|
+
var _s$stackId;
|
|
41
|
+
return _extends({}, s, {
|
|
42
|
+
stackId: (_s$stackId = s.stackId) != null ? _s$stackId : defaultStackId
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}, [series, stacked]);
|
|
46
|
+
|
|
47
|
+
// Unlike other charts with custom props per series, we do not need to pick out
|
|
48
|
+
// the props from each series that shouldn't be passed to CartesianChart
|
|
49
|
+
const seriesToRender = transformedSeries != null ? transformedSeries : series;
|
|
50
|
+
const seriesIds = seriesToRender == null ? void 0 : seriesToRender.map(s => s.id);
|
|
51
|
+
|
|
52
|
+
// Split axis props into config props for Chart and visual props for axis components
|
|
53
|
+
const _ref2 = xAxis || {},
|
|
54
|
+
{
|
|
55
|
+
scaleType: xScaleType,
|
|
56
|
+
data: xData,
|
|
57
|
+
categoryPadding: xCategoryPadding,
|
|
58
|
+
domain: xDomain,
|
|
59
|
+
domainLimit: xDomainLimit,
|
|
60
|
+
range: xRange
|
|
61
|
+
} = _ref2,
|
|
62
|
+
xAxisVisualProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
63
|
+
const _ref3 = yAxis || {},
|
|
64
|
+
{
|
|
65
|
+
scaleType: yScaleType,
|
|
66
|
+
data: yData,
|
|
67
|
+
categoryPadding: yCategoryPadding,
|
|
68
|
+
domain: yDomain,
|
|
69
|
+
domainLimit: yDomainLimit,
|
|
70
|
+
range: yRange,
|
|
71
|
+
id: yAxisId
|
|
72
|
+
} = _ref3,
|
|
73
|
+
yAxisVisualProps = _objectWithoutPropertiesLoose(_ref3, _excluded3);
|
|
74
|
+
const xAxisConfig = {
|
|
75
|
+
scaleType: xScaleType != null ? xScaleType : 'band',
|
|
76
|
+
data: xData,
|
|
77
|
+
categoryPadding: xCategoryPadding,
|
|
78
|
+
domain: xDomain,
|
|
79
|
+
domainLimit: xDomainLimit,
|
|
80
|
+
range: xRange
|
|
81
|
+
};
|
|
82
|
+
const hasNegativeValues = useMemo(() => {
|
|
83
|
+
if (!series) return false;
|
|
84
|
+
return series.some(s => {
|
|
85
|
+
var _s$data;
|
|
86
|
+
return (_s$data = s.data) == null ? void 0 : _s$data.some(value => typeof value === 'number' && value < 0 || Array.isArray(value) && value.some(v => typeof v === 'number' && v < 0));
|
|
87
|
+
});
|
|
88
|
+
}, [series]);
|
|
89
|
+
|
|
90
|
+
// Set default min domain to 0 for area chart, but only if there are no negative values
|
|
91
|
+
const yAxisConfig = {
|
|
92
|
+
scaleType: yScaleType,
|
|
93
|
+
data: yData,
|
|
94
|
+
categoryPadding: yCategoryPadding,
|
|
95
|
+
domain: hasNegativeValues ? yDomain : _extends({
|
|
96
|
+
min: 0
|
|
97
|
+
}, yDomain),
|
|
98
|
+
domainLimit: yDomainLimit,
|
|
99
|
+
range: yRange
|
|
100
|
+
};
|
|
101
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
|
|
102
|
+
ref: ref,
|
|
103
|
+
inset: calculatedInset,
|
|
104
|
+
series: seriesToRender,
|
|
105
|
+
xAxis: xAxisConfig,
|
|
106
|
+
yAxis: yAxisConfig,
|
|
107
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
|
|
108
|
+
axisId: yAxisId
|
|
109
|
+
}, yAxisVisualProps)), /*#__PURE__*/_jsx(BarPlot, {
|
|
110
|
+
BarComponent: BarComponent,
|
|
111
|
+
BarStackComponent: BarStackComponent,
|
|
112
|
+
barMinSize: barMinSize,
|
|
113
|
+
barPadding: barPadding,
|
|
114
|
+
borderRadius: borderRadius,
|
|
115
|
+
fillOpacity: fillOpacity,
|
|
116
|
+
roundBaseline: roundBaseline,
|
|
117
|
+
seriesIds: seriesIds,
|
|
118
|
+
stackGap: stackGap,
|
|
119
|
+
stackMinSize: stackMinSize,
|
|
120
|
+
stroke: stroke,
|
|
121
|
+
strokeWidth: strokeWidth,
|
|
122
|
+
transition: transition
|
|
123
|
+
}), children]
|
|
124
|
+
}));
|
|
125
|
+
}));
|