@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,53 @@
|
|
|
1
|
+
import { memo, useMemo } from 'react';
|
|
2
|
+
import { LinearGradient, vec } from '@shopify/react-native-skia';
|
|
3
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
4
|
+
import { getColorWithOpacity, getGradientConfig } from '../utils/gradient';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Renders a Skia LinearGradient element based on a GradientDefinition.
|
|
8
|
+
* The gradient should be used as a child of a Path component.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <Path d={pathString} stroke="red">
|
|
12
|
+
* {gradient && <Gradient gradient={gradient} yAxisId={yAxisId} />}
|
|
13
|
+
* </Path>
|
|
14
|
+
*/
|
|
15
|
+
export const Gradient = /*#__PURE__*/memo(_ref => {
|
|
16
|
+
var _gradient$axis;
|
|
17
|
+
let {
|
|
18
|
+
gradient,
|
|
19
|
+
yAxisId
|
|
20
|
+
} = _ref;
|
|
21
|
+
const context = useCartesianChartContext();
|
|
22
|
+
const xScale = context.getXScale();
|
|
23
|
+
const yScale = context.getYScale(yAxisId);
|
|
24
|
+
const axis = (_gradient$axis = gradient.axis) != null ? _gradient$axis : 'y';
|
|
25
|
+
const scale = axis === 'x' ? xScale : yScale;
|
|
26
|
+
|
|
27
|
+
// Process gradient definition into stops
|
|
28
|
+
const stops = useMemo(() => {
|
|
29
|
+
if (!xScale || !yScale) return;
|
|
30
|
+
return getGradientConfig(gradient, xScale, yScale);
|
|
31
|
+
}, [gradient, xScale, yScale]);
|
|
32
|
+
if (!stops || !scale) return;
|
|
33
|
+
const range = scale.range();
|
|
34
|
+
|
|
35
|
+
// Determine gradient direction based on axis
|
|
36
|
+
// For y-axis, we need to flip the gradient direction because y-scales are inverted
|
|
37
|
+
// (higher data values have smaller pixel values, appearing at the top)
|
|
38
|
+
const start = axis === 'x' ? vec(range[0], 0) : vec(0, range[0]);
|
|
39
|
+
const end = axis === 'x' ? vec(range[1], 0) : vec(0, range[1]);
|
|
40
|
+
|
|
41
|
+
// Extract colors and positions for LinearGradient
|
|
42
|
+
const colors = stops.map(s => {
|
|
43
|
+
var _s$opacity;
|
|
44
|
+
return getColorWithOpacity(s.color, (_s$opacity = s.opacity) != null ? _s$opacity : 1);
|
|
45
|
+
});
|
|
46
|
+
const positions = stops.map(s => s.offset);
|
|
47
|
+
return /*#__PURE__*/_jsx(LinearGradient, {
|
|
48
|
+
colors: colors,
|
|
49
|
+
end: end,
|
|
50
|
+
positions: positions,
|
|
51
|
+
start: start
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Gradient';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// codegen:start {preset: barrel, include: [./*.tsx, ./*/index.ts]}
|
|
2
|
+
export * from './area';
|
|
3
|
+
export * from './axis';
|
|
4
|
+
export * from './bar';
|
|
5
|
+
export * from './CartesianChart';
|
|
6
|
+
export * from './ChartContextBridge';
|
|
7
|
+
export * from './ChartProvider';
|
|
8
|
+
export * from './gradient';
|
|
9
|
+
export * from './line';
|
|
10
|
+
export * from './Path';
|
|
11
|
+
export * from './PeriodSelector';
|
|
12
|
+
export * from './point';
|
|
13
|
+
export * from './scrubber';
|
|
14
|
+
export * from './text';
|
|
15
|
+
export * from './utils';
|
|
16
|
+
// codegen:end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const _excluded = ["color", "elevated", "borderRadius", "inset", "boundsInset"];
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { memo, useMemo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile';
|
|
6
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
7
|
+
import { ChartText } from '../text';
|
|
8
|
+
import { getChartInset } from '../utils';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const elevatedInset = {
|
|
11
|
+
top: 8,
|
|
12
|
+
bottom: 8,
|
|
13
|
+
left: 12,
|
|
14
|
+
right: 12
|
|
15
|
+
};
|
|
16
|
+
const elevatedBorderRadius = 4;
|
|
17
|
+
// Default bounds inset when elevated to prevent shadow clipping
|
|
18
|
+
const elevatedBoundsInset = {
|
|
19
|
+
top: 4,
|
|
20
|
+
bottom: 20,
|
|
21
|
+
left: 12,
|
|
22
|
+
right: 12
|
|
23
|
+
};
|
|
24
|
+
const nonElevatedBoundsInset = {
|
|
25
|
+
top: 0,
|
|
26
|
+
bottom: 0,
|
|
27
|
+
left: 0,
|
|
28
|
+
right: 0
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* DefaultReferenceLineLabel is the default label component for ReferenceLine.
|
|
33
|
+
* Provides standard styling with elevation, inset, and color defaults.
|
|
34
|
+
* When elevated, automatically adds bounds to prevent shadow cutoff at chart edges.
|
|
35
|
+
*/
|
|
36
|
+
export const DefaultReferenceLineLabel = /*#__PURE__*/memo(_ref => {
|
|
37
|
+
let {
|
|
38
|
+
color,
|
|
39
|
+
elevated,
|
|
40
|
+
borderRadius = elevated ? elevatedBorderRadius : undefined,
|
|
41
|
+
inset = elevated ? elevatedInset : undefined,
|
|
42
|
+
boundsInset: boundsInsetProp
|
|
43
|
+
} = _ref,
|
|
44
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
45
|
+
const theme = useTheme();
|
|
46
|
+
const {
|
|
47
|
+
width: chartWidth,
|
|
48
|
+
height: chartHeight
|
|
49
|
+
} = useCartesianChartContext();
|
|
50
|
+
const bounds = useMemo(() => {
|
|
51
|
+
const boundsInset = getChartInset(boundsInsetProp, elevated ? elevatedBoundsInset : nonElevatedBoundsInset);
|
|
52
|
+
return {
|
|
53
|
+
x: boundsInset.left,
|
|
54
|
+
y: boundsInset.top,
|
|
55
|
+
width: chartWidth - boundsInset.left - boundsInset.right,
|
|
56
|
+
height: chartHeight - boundsInset.top - boundsInset.bottom
|
|
57
|
+
};
|
|
58
|
+
}, [elevated, boundsInsetProp, chartWidth, chartHeight]);
|
|
59
|
+
return /*#__PURE__*/_jsx(ChartText, _extends({
|
|
60
|
+
borderRadius: borderRadius,
|
|
61
|
+
bounds: bounds,
|
|
62
|
+
color: color != null ? color : theme.color.fgMuted,
|
|
63
|
+
elevated: elevated,
|
|
64
|
+
inset: inset
|
|
65
|
+
}, props));
|
|
66
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "dashIntervals", "strokeCap", "strokeJoin", "strokeOpacity", "strokeWidth", "gradient", "yAxisId", "d", "animate", "transition"];
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { DashPathEffect } from '@shopify/react-native-skia';
|
|
7
|
+
import { Gradient } from '../gradient';
|
|
8
|
+
import { Path } from '../Path';
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
/**
|
|
11
|
+
* A customizable dotted line component.
|
|
12
|
+
* Supports gradient for gradient effects on the dots and smooth data transitions via AnimatedPath.
|
|
13
|
+
*/
|
|
14
|
+
export const DottedLine = /*#__PURE__*/memo(_ref => {
|
|
15
|
+
let {
|
|
16
|
+
fill = 'none',
|
|
17
|
+
stroke,
|
|
18
|
+
dashIntervals = [0, 4],
|
|
19
|
+
strokeCap = 'round',
|
|
20
|
+
strokeJoin = 'round',
|
|
21
|
+
strokeOpacity = 1,
|
|
22
|
+
strokeWidth = 2,
|
|
23
|
+
gradient,
|
|
24
|
+
yAxisId,
|
|
25
|
+
d,
|
|
26
|
+
animate,
|
|
27
|
+
transition
|
|
28
|
+
} = _ref,
|
|
29
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
|
+
const theme = useTheme();
|
|
31
|
+
return /*#__PURE__*/_jsxs(Path, _extends({
|
|
32
|
+
animate: animate,
|
|
33
|
+
clipOffset: strokeWidth,
|
|
34
|
+
d: d,
|
|
35
|
+
fill: fill,
|
|
36
|
+
stroke: stroke != null ? stroke : theme.color.fgPrimary,
|
|
37
|
+
strokeCap: strokeCap,
|
|
38
|
+
strokeJoin: strokeJoin,
|
|
39
|
+
strokeOpacity: strokeOpacity,
|
|
40
|
+
strokeWidth: strokeWidth,
|
|
41
|
+
transition: transition
|
|
42
|
+
}, props, {
|
|
43
|
+
children: [/*#__PURE__*/_jsx(DashPathEffect, {
|
|
44
|
+
intervals: dashIntervals
|
|
45
|
+
}), gradient && /*#__PURE__*/_jsx(Gradient, {
|
|
46
|
+
gradient: gradient,
|
|
47
|
+
yAxisId: yAxisId
|
|
48
|
+
})]
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
const _excluded = ["seriesId", "curve", "type", "areaType", "areaBaseline", "stroke", "strokeOpacity", "showArea", "LineComponent", "AreaComponent", "opacity", "points", "connectNulls", "transition", "gradient"];
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import React, { memo, useEffect, useMemo } from 'react';
|
|
5
|
+
import { useSharedValue, withDelay, withTiming } from 'react-native-reanimated';
|
|
6
|
+
import { useTheme } from '@coinbase/cds-mobile';
|
|
7
|
+
import { Group } from '@shopify/react-native-skia';
|
|
8
|
+
import { Area } from '../area/Area';
|
|
9
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
10
|
+
import { Point } from '../point';
|
|
11
|
+
import { accessoryFadeTransitionDelay, accessoryFadeTransitionDuration, getLineData, getLinePath } from '../utils';
|
|
12
|
+
import { evaluateGradientAtValue, getGradientStops } from '../utils/gradient';
|
|
13
|
+
import { convertToSerializableScale } from '../utils/scale';
|
|
14
|
+
import { DottedLine } from './DottedLine';
|
|
15
|
+
import { SolidLine } from './SolidLine';
|
|
16
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export const Line = /*#__PURE__*/memo(_ref => {
|
|
18
|
+
var _ref2;
|
|
19
|
+
let {
|
|
20
|
+
seriesId,
|
|
21
|
+
curve = 'bump',
|
|
22
|
+
type = 'solid',
|
|
23
|
+
areaType = 'gradient',
|
|
24
|
+
areaBaseline,
|
|
25
|
+
stroke: strokeProp,
|
|
26
|
+
strokeOpacity,
|
|
27
|
+
showArea,
|
|
28
|
+
LineComponent: SelectedLineComponent,
|
|
29
|
+
AreaComponent,
|
|
30
|
+
opacity = 1,
|
|
31
|
+
points,
|
|
32
|
+
connectNulls,
|
|
33
|
+
transition,
|
|
34
|
+
gradient: gradientProp
|
|
35
|
+
} = _ref,
|
|
36
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
const {
|
|
39
|
+
animate,
|
|
40
|
+
getSeries,
|
|
41
|
+
getSeriesData,
|
|
42
|
+
getXScale,
|
|
43
|
+
getYScale,
|
|
44
|
+
getXAxis
|
|
45
|
+
} = useCartesianChartContext();
|
|
46
|
+
|
|
47
|
+
// Animation state for delayed point rendering (matches web timing)
|
|
48
|
+
const pointsOpacity = useSharedValue(animate ? 0 : 1);
|
|
49
|
+
|
|
50
|
+
// Delay point appearance until after path enter animation completes
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (animate) {
|
|
53
|
+
pointsOpacity.value = withDelay(accessoryFadeTransitionDelay, withTiming(1, {
|
|
54
|
+
duration: accessoryFadeTransitionDuration
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
}, [animate, pointsOpacity]);
|
|
58
|
+
const matchedSeries = useMemo(() => getSeries(seriesId), [getSeries, seriesId]);
|
|
59
|
+
const gradient = useMemo(() => gradientProp != null ? gradientProp : matchedSeries == null ? void 0 : matchedSeries.gradient, [gradientProp, matchedSeries == null ? void 0 : matchedSeries.gradient]);
|
|
60
|
+
const sourceData = useMemo(() => getSeriesData(seriesId), [getSeriesData, seriesId]);
|
|
61
|
+
const xAxis = useMemo(() => getXAxis(), [getXAxis]);
|
|
62
|
+
const xScale = useMemo(() => getXScale(), [getXScale]);
|
|
63
|
+
const yScale = useMemo(() => getYScale(matchedSeries == null ? void 0 : matchedSeries.yAxisId), [getYScale, matchedSeries == null ? void 0 : matchedSeries.yAxisId]);
|
|
64
|
+
|
|
65
|
+
// Convert sourceData to number array (line only supports numbers, not tuples)
|
|
66
|
+
const chartData = useMemo(() => getLineData(sourceData), [sourceData]);
|
|
67
|
+
const path = useMemo(() => {
|
|
68
|
+
if (!xScale || !yScale || chartData.length === 0) return '';
|
|
69
|
+
|
|
70
|
+
// Get numeric x-axis data if available
|
|
71
|
+
const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
|
|
72
|
+
return getLinePath({
|
|
73
|
+
data: chartData,
|
|
74
|
+
xScale,
|
|
75
|
+
yScale,
|
|
76
|
+
curve,
|
|
77
|
+
xData,
|
|
78
|
+
connectNulls
|
|
79
|
+
});
|
|
80
|
+
}, [chartData, xScale, yScale, curve, xAxis == null ? void 0 : xAxis.data, connectNulls]);
|
|
81
|
+
const LineComponent = useMemo(() => {
|
|
82
|
+
if (SelectedLineComponent) {
|
|
83
|
+
return SelectedLineComponent;
|
|
84
|
+
}
|
|
85
|
+
switch (type) {
|
|
86
|
+
case 'dotted':
|
|
87
|
+
return DottedLine;
|
|
88
|
+
default:
|
|
89
|
+
return SolidLine;
|
|
90
|
+
}
|
|
91
|
+
}, [SelectedLineComponent, type]);
|
|
92
|
+
|
|
93
|
+
// Get series color for stroke
|
|
94
|
+
const stroke = (_ref2 = strokeProp != null ? strokeProp : matchedSeries == null ? void 0 : matchedSeries.color) != null ? _ref2 : theme.color.fgPrimary;
|
|
95
|
+
const xData = useMemo(() => {
|
|
96
|
+
const data = xAxis == null ? void 0 : xAxis.data;
|
|
97
|
+
return data && Array.isArray(data) && data.length > 0 && typeof data[0] === 'number' ? data : null;
|
|
98
|
+
}, [xAxis == null ? void 0 : xAxis.data]);
|
|
99
|
+
const gradientConfig = useMemo(() => {
|
|
100
|
+
if (!gradient || !xScale || !yScale) return;
|
|
101
|
+
const gradientScale = gradient.axis === 'x' ? xScale : yScale;
|
|
102
|
+
const serializableScale = convertToSerializableScale(gradientScale);
|
|
103
|
+
if (!serializableScale) return;
|
|
104
|
+
const domain = {
|
|
105
|
+
min: serializableScale.domain[0],
|
|
106
|
+
max: serializableScale.domain[1]
|
|
107
|
+
};
|
|
108
|
+
const stops = getGradientStops(gradient.stops, domain);
|
|
109
|
+
return {
|
|
110
|
+
scale: serializableScale,
|
|
111
|
+
stops
|
|
112
|
+
};
|
|
113
|
+
}, [gradient, xScale, yScale]);
|
|
114
|
+
if (!xScale || !yScale || !path) return;
|
|
115
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
116
|
+
children: [showArea && /*#__PURE__*/_jsx(Area, {
|
|
117
|
+
AreaComponent: AreaComponent,
|
|
118
|
+
baseline: areaBaseline,
|
|
119
|
+
connectNulls: connectNulls,
|
|
120
|
+
curve: curve,
|
|
121
|
+
fill: stroke,
|
|
122
|
+
fillOpacity: opacity,
|
|
123
|
+
gradient: gradient,
|
|
124
|
+
seriesId: seriesId,
|
|
125
|
+
transition: transition,
|
|
126
|
+
type: areaType
|
|
127
|
+
}), /*#__PURE__*/_jsx(LineComponent, _extends({
|
|
128
|
+
d: path,
|
|
129
|
+
gradient: gradient,
|
|
130
|
+
stroke: stroke,
|
|
131
|
+
strokeOpacity: strokeOpacity != null ? strokeOpacity : opacity,
|
|
132
|
+
transition: transition,
|
|
133
|
+
yAxisId: matchedSeries == null ? void 0 : matchedSeries.yAxisId
|
|
134
|
+
}, props)), points && /*#__PURE__*/_jsx(Group, {
|
|
135
|
+
opacity: pointsOpacity,
|
|
136
|
+
children: chartData.map((value, index) => {
|
|
137
|
+
if (value === null) return;
|
|
138
|
+
const xValue = xData && xData[index] !== undefined ? xData[index] : index;
|
|
139
|
+
let pointFill = stroke;
|
|
140
|
+
if (gradientConfig && gradient) {
|
|
141
|
+
var _gradient$axis;
|
|
142
|
+
// Use the appropriate data value based on gradient axis
|
|
143
|
+
const axis = (_gradient$axis = gradient.axis) != null ? _gradient$axis : 'y';
|
|
144
|
+
const dataValue = axis === 'x' ? xValue : value;
|
|
145
|
+
const evaluatedColor = evaluateGradientAtValue(gradientConfig.stops, dataValue, gradientConfig.scale);
|
|
146
|
+
if (evaluatedColor) {
|
|
147
|
+
// Apply gradient color to fill if not explicitly set
|
|
148
|
+
pointFill = evaluatedColor;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Build defaults that would be passed to Point
|
|
153
|
+
const defaults = {
|
|
154
|
+
dataX: xValue,
|
|
155
|
+
dataY: value,
|
|
156
|
+
fill: pointFill,
|
|
157
|
+
yAxisId: matchedSeries == null ? void 0 : matchedSeries.yAxisId,
|
|
158
|
+
opacity
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// If points is true, render with defaults
|
|
162
|
+
if (points === true) {
|
|
163
|
+
return /*#__PURE__*/_jsx(Point, _extends({
|
|
164
|
+
transition: transition
|
|
165
|
+
}, defaults), seriesId + "-" + xValue);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Call the function with defaults
|
|
169
|
+
const result = points(defaults);
|
|
170
|
+
if (!result) return;
|
|
171
|
+
const pointConfig = result === true ? {} : result;
|
|
172
|
+
return /*#__PURE__*/_jsx(Point, _extends({
|
|
173
|
+
transition: transition
|
|
174
|
+
}, defaults, pointConfig), seriesId + "-" + xValue);
|
|
175
|
+
})
|
|
176
|
+
})]
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const _excluded = ["series", "showArea", "areaType", "type", "LineComponent", "AreaComponent", "curve", "points", "strokeWidth", "strokeOpacity", "connectNulls", "transition", "opacity", "showXAxis", "showYAxis", "xAxis", "yAxis", "inset", "children"],
|
|
2
|
+
_excluded2 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range"],
|
|
3
|
+
_excluded3 = ["scaleType", "data", "categoryPadding", "domain", "domainLimit", "range", "id"],
|
|
4
|
+
_excluded4 = ["id", "data", "label", "color", "yAxisId"];
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
8
|
+
import { XAxis } from '../axis/XAxis';
|
|
9
|
+
import { YAxis } from '../axis/YAxis';
|
|
10
|
+
import { CartesianChart } from '../CartesianChart';
|
|
11
|
+
import { defaultChartInset, getChartInset } from '../utils';
|
|
12
|
+
import { Line } from './Line';
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
export const LineChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
|
|
15
|
+
let {
|
|
16
|
+
series,
|
|
17
|
+
showArea,
|
|
18
|
+
areaType,
|
|
19
|
+
type,
|
|
20
|
+
LineComponent,
|
|
21
|
+
AreaComponent,
|
|
22
|
+
curve,
|
|
23
|
+
points,
|
|
24
|
+
strokeWidth,
|
|
25
|
+
strokeOpacity,
|
|
26
|
+
connectNulls,
|
|
27
|
+
transition,
|
|
28
|
+
opacity,
|
|
29
|
+
showXAxis,
|
|
30
|
+
showYAxis,
|
|
31
|
+
xAxis,
|
|
32
|
+
yAxis,
|
|
33
|
+
inset,
|
|
34
|
+
children
|
|
35
|
+
} = _ref,
|
|
36
|
+
chartProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
37
|
+
const calculatedInset = useMemo(() => getChartInset(inset, defaultChartInset), [inset]);
|
|
38
|
+
|
|
39
|
+
// Convert LineSeries to Series for Chart context
|
|
40
|
+
const chartSeries = useMemo(() => {
|
|
41
|
+
return series == null ? void 0 : series.map(s => ({
|
|
42
|
+
id: s.id,
|
|
43
|
+
data: s.data,
|
|
44
|
+
label: s.label,
|
|
45
|
+
color: s.color,
|
|
46
|
+
yAxisId: s.yAxisId,
|
|
47
|
+
stackId: s.stackId,
|
|
48
|
+
gradient: s.gradient
|
|
49
|
+
}));
|
|
50
|
+
}, [series]);
|
|
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,
|
|
76
|
+
data: xData,
|
|
77
|
+
categoryPadding: xCategoryPadding,
|
|
78
|
+
domain: xDomain,
|
|
79
|
+
domainLimit: xDomainLimit,
|
|
80
|
+
range: xRange
|
|
81
|
+
};
|
|
82
|
+
const yAxisConfig = {
|
|
83
|
+
scaleType: yScaleType,
|
|
84
|
+
data: yData,
|
|
85
|
+
categoryPadding: yCategoryPadding,
|
|
86
|
+
domain: yDomain,
|
|
87
|
+
domainLimit: yDomainLimit,
|
|
88
|
+
range: yRange
|
|
89
|
+
};
|
|
90
|
+
return /*#__PURE__*/_jsxs(CartesianChart, _extends({}, chartProps, {
|
|
91
|
+
ref: ref,
|
|
92
|
+
inset: calculatedInset,
|
|
93
|
+
series: chartSeries,
|
|
94
|
+
xAxis: xAxisConfig,
|
|
95
|
+
yAxis: yAxisConfig,
|
|
96
|
+
children: [showXAxis && /*#__PURE__*/_jsx(XAxis, _extends({}, xAxisVisualProps)), showYAxis && /*#__PURE__*/_jsx(YAxis, _extends({
|
|
97
|
+
axisId: yAxisId
|
|
98
|
+
}, yAxisVisualProps)), series == null ? void 0 : series.map(_ref4 => {
|
|
99
|
+
var _linePropsFromSeries$;
|
|
100
|
+
let {
|
|
101
|
+
id
|
|
102
|
+
} = _ref4,
|
|
103
|
+
linePropsFromSeries = _objectWithoutPropertiesLoose(_ref4, _excluded4);
|
|
104
|
+
return /*#__PURE__*/_jsx(Line, _extends({
|
|
105
|
+
AreaComponent: AreaComponent,
|
|
106
|
+
LineComponent: LineComponent,
|
|
107
|
+
areaType: areaType,
|
|
108
|
+
connectNulls: connectNulls,
|
|
109
|
+
curve: curve,
|
|
110
|
+
opacity: opacity,
|
|
111
|
+
points: points,
|
|
112
|
+
seriesId: id,
|
|
113
|
+
showArea: showArea,
|
|
114
|
+
strokeOpacity: strokeOpacity,
|
|
115
|
+
strokeWidth: strokeWidth,
|
|
116
|
+
transition: (_linePropsFromSeries$ = linePropsFromSeries.transition) != null ? _linePropsFromSeries$ : transition,
|
|
117
|
+
type: type
|
|
118
|
+
}, linePropsFromSeries), id);
|
|
119
|
+
}), children]
|
|
120
|
+
}));
|
|
121
|
+
}));
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { useDerivedValue } from 'react-native-reanimated';
|
|
3
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
4
|
+
import { useCartesianChartContext } from '../ChartProvider';
|
|
5
|
+
import { unwrapAnimatedValue } from '../utils';
|
|
6
|
+
import { getPointOnSerializableScale } from '../utils/point';
|
|
7
|
+
import { DefaultReferenceLineLabel } from './DefaultReferenceLineLabel';
|
|
8
|
+
import { DottedLine } from './DottedLine';
|
|
9
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
export const ReferenceLine = /*#__PURE__*/memo(_ref => {
|
|
11
|
+
let {
|
|
12
|
+
dataX,
|
|
13
|
+
dataY,
|
|
14
|
+
yAxisId,
|
|
15
|
+
label,
|
|
16
|
+
labelPosition = dataY !== undefined ? 'right' : 'top',
|
|
17
|
+
LineComponent = DottedLine,
|
|
18
|
+
LabelComponent = DefaultReferenceLineLabel,
|
|
19
|
+
labelElevated,
|
|
20
|
+
labelFont,
|
|
21
|
+
labelDx,
|
|
22
|
+
labelDy,
|
|
23
|
+
labelHorizontalAlignment,
|
|
24
|
+
labelVerticalAlignment,
|
|
25
|
+
labelBoundsInset,
|
|
26
|
+
stroke,
|
|
27
|
+
opacity = 1
|
|
28
|
+
} = _ref;
|
|
29
|
+
const theme = useTheme();
|
|
30
|
+
const {
|
|
31
|
+
getXSerializableScale,
|
|
32
|
+
getYSerializableScale,
|
|
33
|
+
drawingArea
|
|
34
|
+
} = useCartesianChartContext();
|
|
35
|
+
const xScale = getXSerializableScale();
|
|
36
|
+
const yScale = getYSerializableScale(yAxisId);
|
|
37
|
+
const effectiveLineStroke = stroke != null ? stroke : theme.color.bgLine;
|
|
38
|
+
|
|
39
|
+
// For horizontal lines (dataY defined): default to verticalAlignment: 'middle'
|
|
40
|
+
// For vertical lines (dataX defined): default to horizontalAlignment: 'center'
|
|
41
|
+
const isHorizontal = dataY !== undefined;
|
|
42
|
+
const xPixel = useDerivedValue(() => {
|
|
43
|
+
const dataXValue = unwrapAnimatedValue(dataX);
|
|
44
|
+
return dataXValue !== undefined && xScale ? getPointOnSerializableScale(dataXValue, xScale) : undefined;
|
|
45
|
+
}, [dataX, xScale]);
|
|
46
|
+
const yPixel = useDerivedValue(() => {
|
|
47
|
+
const dataYValue = unwrapAnimatedValue(dataY);
|
|
48
|
+
return dataYValue !== undefined && yScale ? getPointOnSerializableScale(dataYValue, yScale) : undefined;
|
|
49
|
+
}, [dataY, yScale]);
|
|
50
|
+
const horizontalLine = useDerivedValue(() => {
|
|
51
|
+
if (yPixel.value === undefined) return;
|
|
52
|
+
return "M" + drawingArea.x + "," + yPixel.value + " L" + (drawingArea.x + drawingArea.width) + "," + yPixel.value;
|
|
53
|
+
}, [drawingArea, yPixel]);
|
|
54
|
+
const verticalLine = useDerivedValue(() => {
|
|
55
|
+
if (xPixel.value === undefined) return;
|
|
56
|
+
return "M" + xPixel.value + "," + drawingArea.y + " L" + xPixel.value + "," + (drawingArea.y + drawingArea.height);
|
|
57
|
+
}, [drawingArea, xPixel]);
|
|
58
|
+
const labelXPixel = useDerivedValue(() => {
|
|
59
|
+
var _xPixel$value;
|
|
60
|
+
return (_xPixel$value = xPixel.value) != null ? _xPixel$value : 0;
|
|
61
|
+
}, [xPixel]);
|
|
62
|
+
const labelYPixel = useDerivedValue(() => {
|
|
63
|
+
var _yPixel$value;
|
|
64
|
+
return (_yPixel$value = yPixel.value) != null ? _yPixel$value : 0;
|
|
65
|
+
}, [yPixel]);
|
|
66
|
+
const labelOpacity = useDerivedValue(() => {
|
|
67
|
+
const isVisible = dataY !== undefined && yPixel.value !== undefined || dataX !== undefined && xPixel.value !== undefined;
|
|
68
|
+
return isVisible ? unwrapAnimatedValue(opacity) : 0;
|
|
69
|
+
}, [yPixel, xPixel, opacity]);
|
|
70
|
+
if (dataY !== undefined) {
|
|
71
|
+
let labelX;
|
|
72
|
+
if (labelPosition === 'left') {
|
|
73
|
+
labelX = drawingArea.x;
|
|
74
|
+
} else if (labelPosition === 'center') {
|
|
75
|
+
labelX = drawingArea.x + drawingArea.width / 2;
|
|
76
|
+
} else {
|
|
77
|
+
labelX = drawingArea.x + drawingArea.width;
|
|
78
|
+
}
|
|
79
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
80
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
81
|
+
animate: false,
|
|
82
|
+
d: horizontalLine,
|
|
83
|
+
stroke: effectiveLineStroke,
|
|
84
|
+
strokeOpacity: opacity
|
|
85
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
86
|
+
boundsInset: labelBoundsInset,
|
|
87
|
+
dx: labelDx,
|
|
88
|
+
dy: labelDy,
|
|
89
|
+
elevated: labelElevated,
|
|
90
|
+
font: labelFont,
|
|
91
|
+
horizontalAlignment: labelHorizontalAlignment,
|
|
92
|
+
opacity: labelOpacity,
|
|
93
|
+
verticalAlignment: labelVerticalAlignment != null ? labelVerticalAlignment : isHorizontal ? 'middle' : undefined,
|
|
94
|
+
x: labelX,
|
|
95
|
+
y: labelYPixel,
|
|
96
|
+
children: label
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Vertical reference line logic
|
|
102
|
+
if (dataX !== undefined) {
|
|
103
|
+
let labelY;
|
|
104
|
+
if (labelPosition === 'top') {
|
|
105
|
+
labelY = drawingArea.y;
|
|
106
|
+
} else if (labelPosition === 'middle') {
|
|
107
|
+
labelY = drawingArea.y + drawingArea.height / 2;
|
|
108
|
+
} else {
|
|
109
|
+
labelY = drawingArea.y + drawingArea.height;
|
|
110
|
+
}
|
|
111
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
112
|
+
children: [/*#__PURE__*/_jsx(LineComponent, {
|
|
113
|
+
animate: false,
|
|
114
|
+
d: verticalLine,
|
|
115
|
+
stroke: effectiveLineStroke,
|
|
116
|
+
strokeOpacity: opacity
|
|
117
|
+
}), label && /*#__PURE__*/_jsx(LabelComponent, {
|
|
118
|
+
boundsInset: labelBoundsInset,
|
|
119
|
+
dx: labelDx,
|
|
120
|
+
dy: labelDy,
|
|
121
|
+
elevated: labelElevated,
|
|
122
|
+
font: labelFont,
|
|
123
|
+
horizontalAlignment: labelHorizontalAlignment != null ? labelHorizontalAlignment : !isHorizontal ? 'center' : undefined,
|
|
124
|
+
opacity: labelOpacity,
|
|
125
|
+
verticalAlignment: labelVerticalAlignment,
|
|
126
|
+
x: labelXPixel,
|
|
127
|
+
y: labelY,
|
|
128
|
+
children: label
|
|
129
|
+
})]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const _excluded = ["fill", "stroke", "strokeCap", "strokeJoin", "strokeOpacity", "strokeWidth", "gradient", "yAxisId", "d", "animate", "transition"];
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
|
|
6
|
+
import { Gradient } from '../gradient';
|
|
7
|
+
import { Path } from '../Path';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
/**
|
|
10
|
+
* A customizable solid line component.
|
|
11
|
+
* Supports gradient for gradient effects and smooth data transitions via AnimatedPath.
|
|
12
|
+
*/
|
|
13
|
+
export const SolidLine = /*#__PURE__*/memo(_ref => {
|
|
14
|
+
let {
|
|
15
|
+
fill = 'none',
|
|
16
|
+
stroke,
|
|
17
|
+
strokeCap = 'round',
|
|
18
|
+
strokeJoin = 'round',
|
|
19
|
+
strokeOpacity = 1,
|
|
20
|
+
strokeWidth = 2,
|
|
21
|
+
gradient,
|
|
22
|
+
yAxisId,
|
|
23
|
+
d,
|
|
24
|
+
animate,
|
|
25
|
+
transition
|
|
26
|
+
} = _ref,
|
|
27
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
|
+
const theme = useTheme();
|
|
29
|
+
return /*#__PURE__*/_jsx(Path, _extends({
|
|
30
|
+
animate: animate,
|
|
31
|
+
clipOffset: strokeWidth,
|
|
32
|
+
d: d,
|
|
33
|
+
fill: fill,
|
|
34
|
+
stroke: stroke != null ? stroke : theme.color.fgPrimary,
|
|
35
|
+
strokeCap: strokeCap,
|
|
36
|
+
strokeJoin: strokeJoin,
|
|
37
|
+
strokeOpacity: strokeOpacity,
|
|
38
|
+
strokeWidth: strokeWidth,
|
|
39
|
+
transition: transition
|
|
40
|
+
}, props, {
|
|
41
|
+
children: gradient && /*#__PURE__*/_jsx(Gradient, {
|
|
42
|
+
gradient: gradient,
|
|
43
|
+
yAxisId: yAxisId
|
|
44
|
+
})
|
|
45
|
+
}));
|
|
46
|
+
});
|