@coinbase/cds-mobile-visualization 3.8.1 → 4.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/CHANGELOG.md +8 -0
- package/dts/chart/index.d.ts +1 -15
- package/dts/chart/index.d.ts.map +1 -1
- package/dts/index.d.ts.map +1 -1
- package/dts/sparkline/index.d.ts +1 -5
- package/dts/sparkline/index.d.ts.map +1 -1
- package/esm/chart/index.js +1 -17
- package/esm/index.js +1 -3
- package/esm/sparkline/index.js +1 -5
- package/package.json +26 -20
- package/dts/chart/CartesianChart.d.ts +0 -206
- package/dts/chart/CartesianChart.d.ts.map +0 -1
- package/dts/chart/ChartContextBridge.d.ts +0 -28
- package/dts/chart/ChartContextBridge.d.ts.map +0 -1
- package/dts/chart/ChartProvider.d.ts +0 -9
- package/dts/chart/ChartProvider.d.ts.map +0 -1
- package/dts/chart/Path.d.ts +0 -121
- package/dts/chart/Path.d.ts.map +0 -1
- package/dts/chart/PeriodSelector.d.ts +0 -100
- package/dts/chart/PeriodSelector.d.ts.map +0 -1
- package/dts/chart/area/Area.d.ts +0 -83
- package/dts/chart/area/Area.d.ts.map +0 -1
- package/dts/chart/area/AreaChart.d.ts +0 -155
- package/dts/chart/area/AreaChart.d.ts.map +0 -1
- package/dts/chart/area/DottedArea.d.ts +0 -46
- package/dts/chart/area/DottedArea.d.ts.map +0 -1
- package/dts/chart/area/GradientArea.d.ts +0 -36
- package/dts/chart/area/GradientArea.d.ts.map +0 -1
- package/dts/chart/area/SolidArea.d.ts +0 -23
- package/dts/chart/area/SolidArea.d.ts.map +0 -1
- package/dts/chart/area/index.d.ts +0 -6
- package/dts/chart/area/index.d.ts.map +0 -1
- package/dts/chart/axis/Axis.d.ts +0 -174
- package/dts/chart/axis/Axis.d.ts.map +0 -1
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts +0 -8
- package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +0 -1
- package/dts/chart/axis/XAxis.d.ts +0 -22
- package/dts/chart/axis/XAxis.d.ts.map +0 -1
- package/dts/chart/axis/YAxis.d.ts +0 -22
- package/dts/chart/axis/YAxis.d.ts.map +0 -1
- package/dts/chart/axis/index.d.ts +0 -5
- package/dts/chart/axis/index.d.ts.map +0 -1
- package/dts/chart/bar/Bar.d.ts +0 -100
- package/dts/chart/bar/Bar.d.ts.map +0 -1
- package/dts/chart/bar/BarChart.d.ts +0 -158
- package/dts/chart/bar/BarChart.d.ts.map +0 -1
- package/dts/chart/bar/BarPlot.d.ts +0 -31
- package/dts/chart/bar/BarPlot.d.ts.map +0 -1
- package/dts/chart/bar/BarStack.d.ts +0 -127
- package/dts/chart/bar/BarStack.d.ts.map +0 -1
- package/dts/chart/bar/BarStackGroup.d.ts +0 -37
- package/dts/chart/bar/BarStackGroup.d.ts.map +0 -1
- package/dts/chart/bar/DefaultBar.d.ts +0 -7
- package/dts/chart/bar/DefaultBar.d.ts.map +0 -1
- package/dts/chart/bar/DefaultBarStack.d.ts +0 -7
- package/dts/chart/bar/DefaultBarStack.d.ts.map +0 -1
- package/dts/chart/bar/PercentageBarChart.d.ts +0 -106
- package/dts/chart/bar/PercentageBarChart.d.ts.map +0 -1
- package/dts/chart/bar/index.d.ts +0 -9
- package/dts/chart/bar/index.d.ts.map +0 -1
- package/dts/chart/gradient/Gradient.d.ts +0 -41
- package/dts/chart/gradient/Gradient.d.ts.map +0 -1
- package/dts/chart/gradient/index.d.ts +0 -2
- package/dts/chart/gradient/index.d.ts.map +0 -1
- package/dts/chart/legend/DefaultLegendEntry.d.ts +0 -5
- package/dts/chart/legend/DefaultLegendEntry.d.ts.map +0 -1
- package/dts/chart/legend/DefaultLegendShape.d.ts +0 -5
- package/dts/chart/legend/DefaultLegendShape.d.ts.map +0 -1
- package/dts/chart/legend/Legend.d.ts +0 -168
- package/dts/chart/legend/Legend.d.ts.map +0 -1
- package/dts/chart/legend/index.d.ts +0 -4
- package/dts/chart/legend/index.d.ts.map +0 -1
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts +0 -9
- package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +0 -1
- package/dts/chart/line/DottedLine.d.ts +0 -20
- package/dts/chart/line/DottedLine.d.ts.map +0 -1
- package/dts/chart/line/Line.d.ts +0 -122
- package/dts/chart/line/Line.d.ts.map +0 -1
- package/dts/chart/line/LineChart.d.ts +0 -135
- package/dts/chart/line/LineChart.d.ts.map +0 -1
- package/dts/chart/line/ReferenceLine.d.ts +0 -140
- package/dts/chart/line/ReferenceLine.d.ts.map +0 -1
- package/dts/chart/line/SolidLine.d.ts +0 -15
- package/dts/chart/line/SolidLine.d.ts.map +0 -1
- package/dts/chart/line/index.d.ts +0 -7
- package/dts/chart/line/index.d.ts.map +0 -1
- package/dts/chart/point/DefaultPointLabel.d.ts +0 -10
- package/dts/chart/point/DefaultPointLabel.d.ts.map +0 -1
- package/dts/chart/point/Point.d.ts +0 -144
- package/dts/chart/point/Point.d.ts.map +0 -1
- package/dts/chart/point/index.d.ts +0 -3
- package/dts/chart/point/index.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +0 -38
- package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +0 -12
- package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +0 -1
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +0 -12
- package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +0 -1
- package/dts/chart/scrubber/Scrubber.d.ts +0 -302
- package/dts/chart/scrubber/Scrubber.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts +0 -12
- package/dts/chart/scrubber/ScrubberAccessibilityView.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +0 -54
- package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +0 -46
- package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +0 -1
- package/dts/chart/scrubber/ScrubberProvider.d.ts +0 -20
- package/dts/chart/scrubber/ScrubberProvider.d.ts.map +0 -1
- package/dts/chart/scrubber/index.d.ts +0 -5
- package/dts/chart/scrubber/index.d.ts.map +0 -1
- package/dts/chart/text/ChartText.d.ts +0 -164
- package/dts/chart/text/ChartText.d.ts.map +0 -1
- package/dts/chart/text/ChartTextGroup.d.ts +0 -61
- package/dts/chart/text/ChartTextGroup.d.ts.map +0 -1
- package/dts/chart/text/index.d.ts +0 -3
- package/dts/chart/text/index.d.ts.map +0 -1
- package/dts/chart/utils/axis.d.ts +0 -387
- package/dts/chart/utils/axis.d.ts.map +0 -1
- package/dts/chart/utils/bar.d.ts +0 -225
- package/dts/chart/utils/bar.d.ts.map +0 -1
- package/dts/chart/utils/chart.d.ts +0 -165
- package/dts/chart/utils/chart.d.ts.map +0 -1
- package/dts/chart/utils/context.d.ts +0 -131
- package/dts/chart/utils/context.d.ts.map +0 -1
- package/dts/chart/utils/gradient.d.ts +0 -129
- package/dts/chart/utils/gradient.d.ts.map +0 -1
- package/dts/chart/utils/index.d.ts +0 -11
- package/dts/chart/utils/index.d.ts.map +0 -1
- package/dts/chart/utils/path.d.ts +0 -186
- package/dts/chart/utils/path.d.ts.map +0 -1
- package/dts/chart/utils/point.d.ts +0 -146
- package/dts/chart/utils/point.d.ts.map +0 -1
- package/dts/chart/utils/scale.d.ts +0 -145
- package/dts/chart/utils/scale.d.ts.map +0 -1
- package/dts/chart/utils/scrubber.d.ts +0 -40
- package/dts/chart/utils/scrubber.d.ts.map +0 -1
- package/dts/chart/utils/transition.d.ts +0 -181
- package/dts/chart/utils/transition.d.ts.map +0 -1
- package/dts/sparkline/Counter.d.ts +0 -8
- package/dts/sparkline/Counter.d.ts.map +0 -1
- package/dts/sparkline/Sparkline.d.ts +0 -74
- package/dts/sparkline/Sparkline.d.ts.map +0 -1
- package/dts/sparkline/SparklineArea.d.ts +0 -15
- package/dts/sparkline/SparklineArea.d.ts.map +0 -1
- package/dts/sparkline/SparklineAreaPattern.d.ts +0 -14
- package/dts/sparkline/SparklineAreaPattern.d.ts.map +0 -1
- package/dts/sparkline/SparklineGradient.d.ts +0 -24
- package/dts/sparkline/SparklineGradient.d.ts.map +0 -1
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts +0 -2
- package/dts/sparkline/__figma__/Sparkline.figma.d.ts.map +0 -1
- package/dts/sparkline/generateSparklineWithId.d.ts +0 -11
- package/dts/sparkline/generateSparklineWithId.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts +0 -23
- package/dts/sparkline/sparkline-interactive/SparklineAccessibleView.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts +0 -185
- package/dts/sparkline/sparkline-interactive/SparklineInteractive.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts +0 -28
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts +0 -13
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts +0 -17
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts +0 -11
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveMinMax.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts +0 -26
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePaths.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts +0 -25
- package/dts/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts +0 -39
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveProvider.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts +0 -31
- package/dts/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts +0 -13
- package/dts/sparkline/sparkline-interactive/useInterruptiblePathAnimation.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts +0 -16
- package/dts/sparkline/sparkline-interactive/useMinMaxTransform.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts +0 -6
- package/dts/sparkline/sparkline-interactive/useOpacityAnimation.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts +0 -22
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveConstants.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts +0 -34
- package/dts/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts +0 -118
- package/dts/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts +0 -2
- package/dts/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.d.ts.map +0 -1
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts +0 -29
- package/dts/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.d.ts.map +0 -1
- package/esm/chart/CartesianChart.js +0 -431
- package/esm/chart/ChartContextBridge.js +0 -159
- package/esm/chart/ChartProvider.js +0 -10
- package/esm/chart/Path.js +0 -255
- package/esm/chart/PeriodSelector.js +0 -139
- package/esm/chart/__stories__/CartesianChart.stories.js +0 -659
- package/esm/chart/__stories__/ChartAccessibility.stories.js +0 -721
- package/esm/chart/__stories__/ChartTransitions.stories.js +0 -693
- package/esm/chart/__stories__/PeriodSelector.stories.js +0 -420
- package/esm/chart/area/Area.js +0 -85
- package/esm/chart/area/AreaChart.js +0 -152
- package/esm/chart/area/DottedArea.js +0 -92
- package/esm/chart/area/GradientArea.js +0 -63
- package/esm/chart/area/SolidArea.js +0 -45
- package/esm/chart/area/__stories__/AreaChart.stories.js +0 -370
- package/esm/chart/area/index.js +0 -7
- package/esm/chart/axis/Axis.js +0 -9
- package/esm/chart/axis/DefaultAxisTickLabel.js +0 -11
- package/esm/chart/axis/XAxis.js +0 -256
- package/esm/chart/axis/YAxis.js +0 -255
- package/esm/chart/axis/__stories__/Axis.stories.js +0 -552
- package/esm/chart/axis/index.js +0 -6
- package/esm/chart/bar/Bar.js +0 -71
- package/esm/chart/bar/BarChart.js +0 -122
- package/esm/chart/bar/BarPlot.js +0 -106
- package/esm/chart/bar/BarStack.js +0 -173
- package/esm/chart/bar/BarStackGroup.js +0 -89
- package/esm/chart/bar/DefaultBar.js +0 -79
- package/esm/chart/bar/DefaultBarStack.js +0 -68
- package/esm/chart/bar/PercentageBarChart.js +0 -99
- package/esm/chart/bar/__stories__/BarChart.stories.js +0 -1417
- package/esm/chart/bar/__stories__/PercentageBarChart.stories.js +0 -833
- package/esm/chart/bar/index.js +0 -10
- package/esm/chart/gradient/Gradient.js +0 -156
- package/esm/chart/gradient/index.js +0 -1
- package/esm/chart/legend/DefaultLegendEntry.js +0 -42
- package/esm/chart/legend/DefaultLegendShape.js +0 -64
- package/esm/chart/legend/Legend.js +0 -59
- package/esm/chart/legend/__stories__/Legend.stories.js +0 -574
- package/esm/chart/legend/index.js +0 -3
- package/esm/chart/line/DefaultReferenceLineLabel.js +0 -66
- package/esm/chart/line/DottedLine.js +0 -57
- package/esm/chart/line/Line.js +0 -180
- package/esm/chart/line/LineChart.js +0 -149
- package/esm/chart/line/ReferenceLine.js +0 -132
- package/esm/chart/line/SolidLine.js +0 -53
- package/esm/chart/line/__stories__/LineChart.stories.js +0 -2018
- package/esm/chart/line/__stories__/ReferenceLine.stories.js +0 -226
- package/esm/chart/line/index.js +0 -8
- package/esm/chart/point/DefaultPointLabel.js +0 -39
- package/esm/chart/point/Point.js +0 -187
- package/esm/chart/point/index.js +0 -2
- package/esm/chart/scrubber/DefaultScrubberBeacon.js +0 -182
- package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +0 -43
- package/esm/chart/scrubber/DefaultScrubberLabel.js +0 -44
- package/esm/chart/scrubber/Scrubber.js +0 -198
- package/esm/chart/scrubber/ScrubberAccessibilityView.js +0 -177
- package/esm/chart/scrubber/ScrubberBeaconGroup.js +0 -169
- package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +0 -212
- package/esm/chart/scrubber/ScrubberProvider.js +0 -140
- package/esm/chart/scrubber/__stories__/Scrubber.stories.js +0 -946
- package/esm/chart/scrubber/index.js +0 -4
- package/esm/chart/text/ChartText.js +0 -305
- package/esm/chart/text/ChartTextGroup.js +0 -211
- package/esm/chart/text/index.js +0 -4
- package/esm/chart/utils/axis.js +0 -664
- package/esm/chart/utils/bar.js +0 -906
- package/esm/chart/utils/chart.js +0 -329
- package/esm/chart/utils/context.js +0 -22
- package/esm/chart/utils/gradient.js +0 -319
- package/esm/chart/utils/index.js +0 -12
- package/esm/chart/utils/path.js +0 -304
- package/esm/chart/utils/point.js +0 -282
- package/esm/chart/utils/scale.js +0 -288
- package/esm/chart/utils/scrubber.js +0 -146
- package/esm/chart/utils/transition.js +0 -241
- package/esm/sparkline/Counter.js +0 -45
- package/esm/sparkline/Sparkline.js +0 -165
- package/esm/sparkline/SparklineArea.js +0 -20
- package/esm/sparkline/SparklineAreaPattern.js +0 -38
- package/esm/sparkline/SparklineGradient.js +0 -77
- package/esm/sparkline/__figma__/Sparkline.figma.js +0 -22
- package/esm/sparkline/__stories__/Sparkline.stories.js +0 -124
- package/esm/sparkline/__stories__/SparklineGradient.stories.js +0 -126
- package/esm/sparkline/generateSparklineWithId.js +0 -7
- package/esm/sparkline/sparkline-interactive/SparklineAccessibleView.js +0 -75
- package/esm/sparkline/sparkline-interactive/SparklineInteractive.js +0 -308
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveAnimatedPath.js +0 -116
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveHoverDate.js +0 -131
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveLineVertical.js +0 -99
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMarkerDates.js +0 -82
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveMinMax.js +0 -103
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePanGestureHandler.js +0 -104
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePaths.js +0 -57
- package/esm/sparkline/sparkline-interactive/SparklineInteractivePeriodSelector.js +0 -124
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveProvider.js +0 -80
- package/esm/sparkline/sparkline-interactive/SparklineInteractiveTimeseriesPaths.js +0 -109
- package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +0 -85
- package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +0 -526
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.js +0 -58
- package/esm/sparkline/sparkline-interactive/useInterruptiblePathAnimation.test.disable.js +0 -37
- package/esm/sparkline/sparkline-interactive/useMinMaxTransform.js +0 -56
- package/esm/sparkline/sparkline-interactive/useOpacityAnimation.js +0 -23
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveConstants.js +0 -47
- package/esm/sparkline/sparkline-interactive/useSparklineInteractiveLineStyles.js +0 -34
- package/esm/sparkline/sparkline-interactive-header/SparklineInteractiveHeader.js +0 -233
- package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +0 -104
- package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +0 -565
- package/esm/sparkline/sparkline-interactive-header/useSparklineInteractiveHeaderStyles.js +0 -117
package/esm/chart/utils/path.js
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { area as d3Area, curveBumpX, curveBumpY, curveCatmullRom, curveLinear, curveLinearClosed, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore, line as d3Line } from 'd3-shape';
|
|
2
|
-
import { getPointOnScale, projectPoints } from './point';
|
|
3
|
-
import { isCategoricalScale } from './scale';
|
|
4
|
-
/**
|
|
5
|
-
* Default enter transition for path-based components (Line, Area).
|
|
6
|
-
* `{ type: 'timing', duration: 500 }`
|
|
7
|
-
*/
|
|
8
|
-
export const defaultPathEnterTransition = {
|
|
9
|
-
type: 'timing',
|
|
10
|
-
duration: 500
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Get the d3 curve function for a path.
|
|
14
|
-
* See https://d3js.org/d3-shape/curve
|
|
15
|
-
* @param curve - The curve type. Defaults to 'linear'.
|
|
16
|
-
* @param layout - The chart layout. Defaults to 'vertical'.
|
|
17
|
-
* @returns The d3 curve function.
|
|
18
|
-
*/
|
|
19
|
-
export const getPathCurveFunction = function (curve, layout) {
|
|
20
|
-
if (curve === void 0) {
|
|
21
|
-
curve = 'linear';
|
|
22
|
-
}
|
|
23
|
-
if (layout === void 0) {
|
|
24
|
-
layout = 'vertical';
|
|
25
|
-
}
|
|
26
|
-
switch (curve) {
|
|
27
|
-
case 'catmullRom':
|
|
28
|
-
return curveCatmullRom;
|
|
29
|
-
case 'monotone':
|
|
30
|
-
// For vertical layout, X is the independent axis (category/index), so use MonotoneX.
|
|
31
|
-
// For horizontal layout, Y is the independent axis (category/index), so use MonotoneY.
|
|
32
|
-
return layout !== 'horizontal' ? curveMonotoneX : curveMonotoneY;
|
|
33
|
-
case 'natural':
|
|
34
|
-
return curveNatural;
|
|
35
|
-
case 'step':
|
|
36
|
-
return curveStep;
|
|
37
|
-
case 'stepBefore':
|
|
38
|
-
return curveStepBefore;
|
|
39
|
-
case 'stepAfter':
|
|
40
|
-
return curveStepAfter;
|
|
41
|
-
case 'bump':
|
|
42
|
-
// For vertical layout, X is the independent axis (category/index), so use BumpX.
|
|
43
|
-
// For horizontal layout, Y is the independent axis (category/index), so use BumpY.
|
|
44
|
-
return layout !== 'horizontal' ? curveBumpX : curveBumpY;
|
|
45
|
-
case 'linearClosed':
|
|
46
|
-
return curveLinearClosed;
|
|
47
|
-
case 'linear':
|
|
48
|
-
default:
|
|
49
|
-
return curveLinear;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Generates an SVG line path string from data using chart scale functions.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* const chartScale = getChartScale({ chartRect, domain, range, xScale, yScale });
|
|
59
|
-
* const path = getLinePath({ data: [1, 2, 3], chartScale, curve: 'linear' });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export const getLinePath = _ref => {
|
|
63
|
-
var _pathGenerator;
|
|
64
|
-
let {
|
|
65
|
-
data,
|
|
66
|
-
curve = 'bump',
|
|
67
|
-
xScale,
|
|
68
|
-
yScale,
|
|
69
|
-
xData,
|
|
70
|
-
yData,
|
|
71
|
-
connectNulls = false,
|
|
72
|
-
layout = 'vertical'
|
|
73
|
-
} = _ref;
|
|
74
|
-
if (data.length === 0) {
|
|
75
|
-
return '';
|
|
76
|
-
}
|
|
77
|
-
const curveFunction = getPathCurveFunction(curve, layout);
|
|
78
|
-
const dataPoints = projectPoints({
|
|
79
|
-
data,
|
|
80
|
-
xScale,
|
|
81
|
-
yScale,
|
|
82
|
-
xData,
|
|
83
|
-
yData,
|
|
84
|
-
layout
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// When connectNulls is true, filter out null values before rendering
|
|
88
|
-
// When false, use defined() to create gaps in the line
|
|
89
|
-
const filteredPoints = connectNulls ? dataPoints.filter(d => d !== null) : dataPoints;
|
|
90
|
-
const pathGenerator = d3Line().x(d => d.x).y(d => d.y).curve(curveFunction).defined(d => connectNulls || d !== null);
|
|
91
|
-
return (_pathGenerator = pathGenerator(filteredPoints)) != null ? _pathGenerator : '';
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Generates an SVG area path string from data using chart scale functions.
|
|
96
|
-
* Supports both single values (area from baseline to value) and tuples ([baseline, value]).
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* // Single values - area from baseline to value
|
|
101
|
-
* const area = getAreaPath({
|
|
102
|
-
* data: [1, 2, 3],
|
|
103
|
-
* xScale,
|
|
104
|
-
* yScale,
|
|
105
|
-
* });
|
|
106
|
-
*
|
|
107
|
-
* // Range values - area from low to high
|
|
108
|
-
* const rangeArea = getAreaPath({
|
|
109
|
-
* data: [[0, 3], [2, 4], [1, 5]],
|
|
110
|
-
* xScale,
|
|
111
|
-
* yScale,
|
|
112
|
-
* curve: 'monotone'
|
|
113
|
-
* });
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
export const getAreaPath = _ref2 => {
|
|
117
|
-
let {
|
|
118
|
-
data,
|
|
119
|
-
curve = 'bump',
|
|
120
|
-
xScale,
|
|
121
|
-
yScale,
|
|
122
|
-
xData,
|
|
123
|
-
yData,
|
|
124
|
-
connectNulls = false,
|
|
125
|
-
layout = 'vertical'
|
|
126
|
-
} = _ref2;
|
|
127
|
-
if (data.length === 0) {
|
|
128
|
-
return '';
|
|
129
|
-
}
|
|
130
|
-
const curveFunction = getPathCurveFunction(curve, layout);
|
|
131
|
-
const categoryAxisIsX = layout !== 'horizontal';
|
|
132
|
-
|
|
133
|
-
// Determine baseline from the value scale.
|
|
134
|
-
const valueScale = categoryAxisIsX ? yScale : xScale;
|
|
135
|
-
const domain = valueScale.domain();
|
|
136
|
-
const min = Math.min(...domain);
|
|
137
|
-
const normalizedData = data.map((item, index) => {
|
|
138
|
-
if (item === null) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
if (Array.isArray(item)) {
|
|
142
|
-
if (item.length >= 2 && typeof item[0] === 'number' && typeof item[1] === 'number') {
|
|
143
|
-
return [item[0], item[1]];
|
|
144
|
-
}
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
if (typeof item === 'number') {
|
|
148
|
-
return [min, item];
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
|
-
});
|
|
152
|
-
const dataPoints = normalizedData.map((range, index) => {
|
|
153
|
-
if (range === null) {
|
|
154
|
-
return {
|
|
155
|
-
x: 0,
|
|
156
|
-
y: 0,
|
|
157
|
-
low: null,
|
|
158
|
-
high: null,
|
|
159
|
-
isValid: false
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Determine the position along the independent (index/category) axis.
|
|
164
|
-
let indexValue = index;
|
|
165
|
-
const indexScale = categoryAxisIsX ? xScale : yScale;
|
|
166
|
-
const indexData = categoryAxisIsX ? xData : yData;
|
|
167
|
-
if (!isCategoricalScale(indexScale) && indexData && indexData[index] !== undefined) {
|
|
168
|
-
indexValue = indexData[index];
|
|
169
|
-
}
|
|
170
|
-
const position = getPointOnScale(indexValue, indexScale);
|
|
171
|
-
const low = getPointOnScale(range[0], valueScale);
|
|
172
|
-
const high = getPointOnScale(range[1], valueScale);
|
|
173
|
-
return {
|
|
174
|
-
x: categoryAxisIsX ? position : 0,
|
|
175
|
-
y: !categoryAxisIsX ? position : 0,
|
|
176
|
-
low,
|
|
177
|
-
high,
|
|
178
|
-
isValid: true
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// When connectNulls is true, filter out invalid points before rendering
|
|
183
|
-
// When false, use defined() to create gaps in the area
|
|
184
|
-
const filteredPoints = connectNulls ? dataPoints.filter(d => d.isValid) : dataPoints;
|
|
185
|
-
const areaGenerator = d3Area();
|
|
186
|
-
if (categoryAxisIsX) {
|
|
187
|
-
areaGenerator.x(d => d.x).y0(d => {
|
|
188
|
-
var _d$low;
|
|
189
|
-
return (_d$low = d.low) != null ? _d$low : 0;
|
|
190
|
-
}).y1(d => {
|
|
191
|
-
var _d$high;
|
|
192
|
-
return (_d$high = d.high) != null ? _d$high : 0;
|
|
193
|
-
});
|
|
194
|
-
} else {
|
|
195
|
-
areaGenerator.y(d => d.y).x0(d => {
|
|
196
|
-
var _d$low2;
|
|
197
|
-
return (_d$low2 = d.low) != null ? _d$low2 : 0;
|
|
198
|
-
}).x1(d => {
|
|
199
|
-
var _d$high2;
|
|
200
|
-
return (_d$high2 = d.high) != null ? _d$high2 : 0;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
areaGenerator.curve(curveFunction).defined(d => connectNulls || d.isValid && d.low != null && d.high != null);
|
|
204
|
-
const result = areaGenerator(filteredPoints);
|
|
205
|
-
return result != null ? result : '';
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Converts line coordinates to an SVG path string.
|
|
210
|
-
* Useful for rendering axis lines and tick marks.
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```typescript
|
|
214
|
-
* const path = lineToPath(0, 0, 100, 100);
|
|
215
|
-
* // Returns: "M 0 0 L 100 100"
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
export const lineToPath = (x1, y1, x2, y2) => {
|
|
219
|
-
return "M " + x1 + " " + y1 + " L " + x2 + " " + y2;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Creates an SVG path string for a rectangle with selective corner rounding.
|
|
224
|
-
* Useful for creating bars in charts with optional rounded corners.
|
|
225
|
-
*
|
|
226
|
-
* @example
|
|
227
|
-
* ```typescript
|
|
228
|
-
* // Simple rectangle bar
|
|
229
|
-
* const barPath = getBarPath(10, 20, 50, 100, 0, false, false);
|
|
230
|
-
*
|
|
231
|
-
* // Bar with rounded top corners
|
|
232
|
-
* const roundedPath = getBarPath(10, 20, 50, 100, 8, true, false);
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
export const getBarPath = function (x, y, width, height, radius, roundTop, roundBottom, layout) {
|
|
236
|
-
if (layout === void 0) {
|
|
237
|
-
layout = 'vertical';
|
|
238
|
-
}
|
|
239
|
-
const isVerticalLayout = layout === 'vertical';
|
|
240
|
-
const roundBothSides = roundTop && roundBottom;
|
|
241
|
-
const r = Math.min(radius, width / 2, roundBothSides ? height / 2 : height);
|
|
242
|
-
const rTL = isVerticalLayout ? roundTop ? r : 0 : roundBottom ? r : 0;
|
|
243
|
-
const rTR = isVerticalLayout ? roundTop ? r : 0 : roundTop ? r : 0;
|
|
244
|
-
const rBR = isVerticalLayout ? roundBottom ? r : 0 : roundTop ? r : 0;
|
|
245
|
-
const rBL = isVerticalLayout ? roundBottom ? r : 0 : roundBottom ? r : 0;
|
|
246
|
-
|
|
247
|
-
// Build path with selective rounding
|
|
248
|
-
let path = "M " + (x + rTL) + " " + y;
|
|
249
|
-
path += " L " + (x + width - rTR) + " " + y;
|
|
250
|
-
path += " A " + rTR + " " + rTR + " 0 0 1 " + (x + width) + " " + (y + rTR);
|
|
251
|
-
path += " L " + (x + width) + " " + (y + height - rBR);
|
|
252
|
-
path += " A " + rBR + " " + rBR + " 0 0 1 " + (x + width - rBR) + " " + (y + height);
|
|
253
|
-
path += " L " + (x + rBL) + " " + (y + height);
|
|
254
|
-
path += " A " + rBL + " " + rBL + " 0 0 1 " + x + " " + (y + height - rBL);
|
|
255
|
-
path += " L " + x + " " + (y + rTL);
|
|
256
|
-
path += " A " + rTL + " " + rTL + " 0 0 1 " + (x + rTL) + " " + y;
|
|
257
|
-
path += ' Z';
|
|
258
|
-
return path;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Generates an SVG path string with circles arranged in a dotted pattern within a bounding area.
|
|
263
|
-
* Creates circles at regular intervals based on the pattern size and dot size parameters.
|
|
264
|
-
*
|
|
265
|
-
* @param bounds - The bounding rectangle to fill with dots
|
|
266
|
-
* @param patternSize - Size of the pattern unit (spacing between dots)
|
|
267
|
-
* @param dotSize - Radius of each dot
|
|
268
|
-
* @returns SVG path string containing all the circles
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* ```typescript
|
|
272
|
-
* const dotsPath = getDottedAreaPath(
|
|
273
|
-
* { x: 0, y: 0, width: 100, height: 50 },
|
|
274
|
-
* 8, // 8px spacing
|
|
275
|
-
* 2 // 2px radius dots
|
|
276
|
-
* );
|
|
277
|
-
* ```
|
|
278
|
-
*/
|
|
279
|
-
export const getDottedAreaPath = (bounds, patternSize, dotSize) => {
|
|
280
|
-
if (bounds.width <= 0 || bounds.height <= 0 || patternSize <= 0 || dotSize <= 0) {
|
|
281
|
-
return '';
|
|
282
|
-
}
|
|
283
|
-
let path = '';
|
|
284
|
-
|
|
285
|
-
// Calculate the number of dots that fit in each dimension
|
|
286
|
-
const dotsX = Math.ceil(bounds.width / patternSize);
|
|
287
|
-
const dotsY = Math.ceil(bounds.height / patternSize);
|
|
288
|
-
|
|
289
|
-
// Generate circles in a grid pattern
|
|
290
|
-
for (let row = 0; row < dotsY; row++) {
|
|
291
|
-
for (let col = 0; col < dotsX; col++) {
|
|
292
|
-
const centerX = bounds.x + col * patternSize + patternSize / 2;
|
|
293
|
-
const centerY = bounds.y + row * patternSize + patternSize / 2;
|
|
294
|
-
|
|
295
|
-
// Only draw dots that are within the bounds
|
|
296
|
-
if (centerX >= bounds.x && centerX <= bounds.x + bounds.width && centerY >= bounds.y && centerY <= bounds.y + bounds.height) {
|
|
297
|
-
// Create circle using SVG arc commands
|
|
298
|
-
// M cx,cy-r a r,r 0 1,0 0,2r a r,r 0 1,0 0,-2r
|
|
299
|
-
path += "M " + centerX + "," + (centerY - dotSize) + " a " + dotSize + "," + dotSize + " 0 1,0 0," + dotSize * 2 + " a " + dotSize + "," + dotSize + " 0 1,0 0," + -dotSize * 2 + " ";
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
return path.trim();
|
|
304
|
-
};
|
package/esm/chart/utils/point.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { applyBandScale, applySerializableScale, isCategoricalScale, isLogScale } from './scale';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Position a label should be placed relative to the point
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* 'top' would have the label be located above the point itself,
|
|
8
|
-
* and thus the vertical alignment of that text would be bottom.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Get a point from a data value and a scale.
|
|
13
|
-
*
|
|
14
|
-
* @param dataValue - The data value to convert to a pixel position.
|
|
15
|
-
* @param scale - The scale function.
|
|
16
|
-
* @param anchor (@default 'middle') - For band scales, where to anchor the point within the band.
|
|
17
|
-
* @returns The pixel value (@default 0 if data value is not defined in scale).
|
|
18
|
-
*/
|
|
19
|
-
export const getPointOnScale = function (dataValue, scale, anchor) {
|
|
20
|
-
var _scale;
|
|
21
|
-
if (anchor === void 0) {
|
|
22
|
-
anchor = 'middle';
|
|
23
|
-
}
|
|
24
|
-
if (isCategoricalScale(scale)) {
|
|
25
|
-
var _bandScale$bandwidth, _bandScale$step;
|
|
26
|
-
const bandScale = scale;
|
|
27
|
-
const bandStart = bandScale(dataValue);
|
|
28
|
-
if (bandStart === undefined) return 0;
|
|
29
|
-
const bandwidth = (_bandScale$bandwidth = bandScale.bandwidth == null ? void 0 : bandScale.bandwidth()) != null ? _bandScale$bandwidth : 0;
|
|
30
|
-
const step = (_bandScale$step = bandScale.step == null ? void 0 : bandScale.step()) != null ? _bandScale$step : bandwidth;
|
|
31
|
-
const paddingOffset = (step - bandwidth) / 2;
|
|
32
|
-
const stepStart = bandStart - paddingOffset;
|
|
33
|
-
switch (anchor) {
|
|
34
|
-
case 'stepStart':
|
|
35
|
-
return stepStart;
|
|
36
|
-
case 'bandStart':
|
|
37
|
-
return bandStart;
|
|
38
|
-
case 'middle':
|
|
39
|
-
return bandStart + bandwidth / 2;
|
|
40
|
-
case 'bandEnd':
|
|
41
|
-
return bandStart + bandwidth;
|
|
42
|
-
case 'stepEnd':
|
|
43
|
-
return stepStart + step;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// For log scales, ensure the value is positive
|
|
48
|
-
let adjustedValue = dataValue;
|
|
49
|
-
if (isLogScale(scale) && dataValue <= 0) {
|
|
50
|
-
adjustedValue = 0.001; // Use a small positive value for log scales
|
|
51
|
-
}
|
|
52
|
-
return (_scale = scale(adjustedValue)) != null ? _scale : 0;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get a point from a data value and a serializable scale (worklet-compatible).
|
|
57
|
-
*
|
|
58
|
-
* @param dataValue - The data value to convert to a pixel position.
|
|
59
|
-
* @param scale - The serializable scale function.
|
|
60
|
-
* @param anchor (@default 'middle') - For band scales, where to anchor the point within the band.
|
|
61
|
-
* @returns The pixel value (@default 0 if data value is not defined in scale).
|
|
62
|
-
*/
|
|
63
|
-
export function getPointOnSerializableScale(dataValue, scale, anchor) {
|
|
64
|
-
'worklet';
|
|
65
|
-
|
|
66
|
-
// Handle band scales with the specified position
|
|
67
|
-
if (anchor === void 0) {
|
|
68
|
-
anchor = 'middle';
|
|
69
|
-
}
|
|
70
|
-
if (scale.type === 'band') {
|
|
71
|
-
const bandScale = scale;
|
|
72
|
-
const [domainMin, domainMax] = bandScale.domain;
|
|
73
|
-
const index = dataValue - domainMin;
|
|
74
|
-
const n = domainMax - domainMin + 1;
|
|
75
|
-
if (index < 0 || index >= n) {
|
|
76
|
-
return 0;
|
|
77
|
-
}
|
|
78
|
-
const bandStart = applyBandScale(dataValue, bandScale);
|
|
79
|
-
const paddingOffset = (bandScale.step - bandScale.bandwidth) / 2;
|
|
80
|
-
const stepStart = bandStart - paddingOffset;
|
|
81
|
-
switch (anchor) {
|
|
82
|
-
case 'stepStart':
|
|
83
|
-
return stepStart;
|
|
84
|
-
case 'bandStart':
|
|
85
|
-
return bandStart;
|
|
86
|
-
case 'middle':
|
|
87
|
-
return bandStart + bandScale.bandwidth / 2;
|
|
88
|
-
case 'bandEnd':
|
|
89
|
-
return bandStart + bandScale.bandwidth;
|
|
90
|
-
case 'stepEnd':
|
|
91
|
-
return stepStart + bandScale.step;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// For log scales, ensure the value is positive
|
|
96
|
-
if (scale.type === 'log' && dataValue <= 0) {
|
|
97
|
-
dataValue = 0.001; // Use a small positive value for log scales
|
|
98
|
-
}
|
|
99
|
-
return applySerializableScale(dataValue, scale);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Projects a single data point to pixel coordinates using serializable scales.
|
|
104
|
-
* This is the worklet-compatible version for use in react-native-reanimated.
|
|
105
|
-
*/
|
|
106
|
-
export function projectPointWithSerializableScale(_ref) {
|
|
107
|
-
'worklet';
|
|
108
|
-
|
|
109
|
-
let {
|
|
110
|
-
x,
|
|
111
|
-
y,
|
|
112
|
-
xScale,
|
|
113
|
-
yScale
|
|
114
|
-
} = _ref;
|
|
115
|
-
return {
|
|
116
|
-
x: getPointOnSerializableScale(x, xScale),
|
|
117
|
-
y: getPointOnSerializableScale(y, yScale)
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Projects a data point to pixel coordinates using the chart scale.
|
|
123
|
-
* Automatically handles log scale transformations for zero/negative values.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const chartScale = getChartScale({ chartRect, domain, range, xScale, yScale });
|
|
128
|
-
* const pixelCoord = projectPoint({ x: 5, y: 10, chartScale });
|
|
129
|
-
* ```
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* const chartScale = getChartScale({ chartRect, domain, range, xScale, yScale });
|
|
133
|
-
* const pixelCoord = projectPoint({ x: 2, y: 10, chartScale, xData: ['Jan', 'Feb', 'Mar'] });
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
export const projectPoint = _ref2 => {
|
|
137
|
-
let {
|
|
138
|
-
x,
|
|
139
|
-
y,
|
|
140
|
-
xScale,
|
|
141
|
-
yScale
|
|
142
|
-
} = _ref2;
|
|
143
|
-
return {
|
|
144
|
-
x: getPointOnScale(x, xScale),
|
|
145
|
-
y: getPointOnScale(y, yScale)
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Projects multiple data points to pixel coordinates using chart scale functions.
|
|
151
|
-
* Handles both numeric and band scales automatically.
|
|
152
|
-
*
|
|
153
|
-
* @example
|
|
154
|
-
* ```typescript
|
|
155
|
-
* const chartScale = getChartScale({ chartRect, domain, range, xScale, yScale });
|
|
156
|
-
* const pixelPoints = projectPoints({ data, chartScale });
|
|
157
|
-
* // For mixed scales
|
|
158
|
-
* const pixelPoints = projectPoints({ data, chartScale, xData: ['Jan', 'Feb', 'Mar'] });
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export const projectPoints = _ref3 => {
|
|
162
|
-
let {
|
|
163
|
-
data,
|
|
164
|
-
xScale,
|
|
165
|
-
yScale,
|
|
166
|
-
xData,
|
|
167
|
-
yData,
|
|
168
|
-
layout = 'vertical'
|
|
169
|
-
} = _ref3;
|
|
170
|
-
if (data.length === 0) {
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
return data.map((value, index) => {
|
|
174
|
-
if (value === null) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
if (typeof value === 'object' && 'x' in value && 'y' in value) {
|
|
178
|
-
return projectPoint({
|
|
179
|
-
x: value.x,
|
|
180
|
-
y: value.y,
|
|
181
|
-
xScale,
|
|
182
|
-
yScale
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Determine values/scales based on role (index vs value) and layout.
|
|
187
|
-
const categoryAxisIsX = layout !== 'horizontal';
|
|
188
|
-
const indexScale = categoryAxisIsX ? xScale : yScale;
|
|
189
|
-
const indexData = categoryAxisIsX ? xData : yData;
|
|
190
|
-
|
|
191
|
-
// 1. Calculate position along the index axis (categorical or numeric domain).
|
|
192
|
-
let indexValue = index;
|
|
193
|
-
if (!isCategoricalScale(indexScale)) {
|
|
194
|
-
if (indexData && Array.isArray(indexData) && indexData.length > 0) {
|
|
195
|
-
if (typeof indexData[0] === 'number') {
|
|
196
|
-
var _indexData$index;
|
|
197
|
-
indexValue = (_indexData$index = indexData[index]) != null ? _indexData$index : index;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 2. Calculate position along the value axis (measured magnitude).
|
|
203
|
-
const valueAsNumber = value;
|
|
204
|
-
|
|
205
|
-
// 3. Project final coordinates based on layout.
|
|
206
|
-
if (categoryAxisIsX) {
|
|
207
|
-
return projectPoint({
|
|
208
|
-
x: indexValue,
|
|
209
|
-
y: valueAsNumber,
|
|
210
|
-
xScale,
|
|
211
|
-
yScale
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return projectPoint({
|
|
215
|
-
x: valueAsNumber,
|
|
216
|
-
y: indexValue,
|
|
217
|
-
xScale,
|
|
218
|
-
yScale
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Determines text alignment based on label position.
|
|
225
|
-
* For example, a 'top' position needs the text aligned to the 'bottom' so it appears above the point.
|
|
226
|
-
*/
|
|
227
|
-
export const getAlignmentFromPosition = position => {
|
|
228
|
-
let horizontalAlignment = 'center';
|
|
229
|
-
let verticalAlignment = 'middle';
|
|
230
|
-
switch (position) {
|
|
231
|
-
case 'top':
|
|
232
|
-
verticalAlignment = 'bottom';
|
|
233
|
-
break;
|
|
234
|
-
case 'bottom':
|
|
235
|
-
verticalAlignment = 'top';
|
|
236
|
-
break;
|
|
237
|
-
case 'left':
|
|
238
|
-
horizontalAlignment = 'right';
|
|
239
|
-
break;
|
|
240
|
-
case 'right':
|
|
241
|
-
horizontalAlignment = 'left';
|
|
242
|
-
break;
|
|
243
|
-
case 'center':
|
|
244
|
-
default:
|
|
245
|
-
horizontalAlignment = 'center';
|
|
246
|
-
verticalAlignment = 'middle';
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
horizontalAlignment,
|
|
251
|
-
verticalAlignment
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Calculates the final label coordinates by applying offset based on position.
|
|
257
|
-
*/
|
|
258
|
-
export const getLabelCoordinates = (x, y, position, offset) => {
|
|
259
|
-
let dx = 0;
|
|
260
|
-
let dy = 0;
|
|
261
|
-
switch (position) {
|
|
262
|
-
case 'top':
|
|
263
|
-
dy = -offset;
|
|
264
|
-
break;
|
|
265
|
-
case 'bottom':
|
|
266
|
-
dy = offset;
|
|
267
|
-
break;
|
|
268
|
-
case 'left':
|
|
269
|
-
dx = -offset;
|
|
270
|
-
break;
|
|
271
|
-
case 'right':
|
|
272
|
-
dx = offset;
|
|
273
|
-
break;
|
|
274
|
-
case 'center':
|
|
275
|
-
default:
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
x: x + dx,
|
|
280
|
-
y: y + dy
|
|
281
|
-
};
|
|
282
|
-
};
|