@coinbase/cds-mobile-visualization 3.4.0-beta.1 → 3.4.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dts/chart/CartesianChart.d.ts +57 -33
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/ChartContextBridge.d.ts +28 -0
  5. package/dts/chart/ChartContextBridge.d.ts.map +1 -0
  6. package/dts/chart/Path.d.ts +77 -34
  7. package/dts/chart/Path.d.ts.map +1 -1
  8. package/dts/chart/PeriodSelector.d.ts +2 -2
  9. package/dts/chart/PeriodSelector.d.ts.map +1 -1
  10. package/dts/chart/area/Area.d.ts +42 -27
  11. package/dts/chart/area/Area.d.ts.map +1 -1
  12. package/dts/chart/area/AreaChart.d.ts +51 -10
  13. package/dts/chart/area/AreaChart.d.ts.map +1 -1
  14. package/dts/chart/area/DottedArea.d.ts +21 -2
  15. package/dts/chart/area/DottedArea.d.ts.map +1 -1
  16. package/dts/chart/area/GradientArea.d.ts +19 -13
  17. package/dts/chart/area/GradientArea.d.ts.map +1 -1
  18. package/dts/chart/area/SolidArea.d.ts +17 -2
  19. package/dts/chart/area/SolidArea.d.ts.map +1 -1
  20. package/dts/chart/axis/Axis.d.ts +86 -118
  21. package/dts/chart/axis/Axis.d.ts.map +1 -1
  22. package/dts/chart/axis/DefaultAxisTickLabel.d.ts +8 -0
  23. package/dts/chart/axis/DefaultAxisTickLabel.d.ts.map +1 -0
  24. package/dts/chart/axis/XAxis.d.ts +1 -1
  25. package/dts/chart/axis/XAxis.d.ts.map +1 -1
  26. package/dts/chart/axis/YAxis.d.ts +2 -2
  27. package/dts/chart/axis/YAxis.d.ts.map +1 -1
  28. package/dts/chart/axis/index.d.ts +1 -0
  29. package/dts/chart/axis/index.d.ts.map +1 -1
  30. package/dts/chart/bar/Bar.d.ts +16 -13
  31. package/dts/chart/bar/Bar.d.ts.map +1 -1
  32. package/dts/chart/bar/BarChart.d.ts +36 -20
  33. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  34. package/dts/chart/bar/BarPlot.d.ts +2 -1
  35. package/dts/chart/bar/BarPlot.d.ts.map +1 -1
  36. package/dts/chart/bar/BarStack.d.ts +39 -48
  37. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  38. package/dts/chart/bar/BarStackGroup.d.ts +1 -0
  39. package/dts/chart/bar/BarStackGroup.d.ts.map +1 -1
  40. package/dts/chart/bar/DefaultBar.d.ts +1 -1
  41. package/dts/chart/bar/DefaultBar.d.ts.map +1 -1
  42. package/dts/chart/bar/DefaultBarStack.d.ts.map +1 -1
  43. package/dts/chart/gradient/Gradient.d.ts +25 -0
  44. package/dts/chart/gradient/Gradient.d.ts.map +1 -0
  45. package/dts/chart/gradient/index.d.ts +2 -0
  46. package/dts/chart/gradient/index.d.ts.map +1 -0
  47. package/dts/chart/index.d.ts +3 -1
  48. package/dts/chart/index.d.ts.map +1 -1
  49. package/dts/chart/line/DefaultReferenceLineLabel.d.ts +9 -0
  50. package/dts/chart/line/DefaultReferenceLineLabel.d.ts.map +1 -0
  51. package/dts/chart/line/DottedLine.d.ts +13 -5
  52. package/dts/chart/line/DottedLine.d.ts.map +1 -1
  53. package/dts/chart/line/Line.d.ts +64 -25
  54. package/dts/chart/line/Line.d.ts.map +1 -1
  55. package/dts/chart/line/LineChart.d.ts +43 -9
  56. package/dts/chart/line/LineChart.d.ts.map +1 -1
  57. package/dts/chart/line/ReferenceLine.d.ts +68 -20
  58. package/dts/chart/line/ReferenceLine.d.ts.map +1 -1
  59. package/dts/chart/line/SolidLine.d.ts +8 -5
  60. package/dts/chart/line/SolidLine.d.ts.map +1 -1
  61. package/dts/chart/line/index.d.ts +1 -1
  62. package/dts/chart/line/index.d.ts.map +1 -1
  63. package/dts/chart/point/DefaultPointLabel.d.ts +10 -0
  64. package/dts/chart/point/DefaultPointLabel.d.ts.map +1 -0
  65. package/dts/chart/point/Point.d.ts +120 -0
  66. package/dts/chart/point/Point.d.ts.map +1 -0
  67. package/dts/chart/point/index.d.ts +3 -0
  68. package/dts/chart/point/index.d.ts.map +1 -0
  69. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +8 -0
  70. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -0
  71. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts +12 -0
  72. package/dts/chart/scrubber/DefaultScrubberBeaconLabel.d.ts.map +1 -0
  73. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts +11 -0
  74. package/dts/chart/scrubber/DefaultScrubberLabel.d.ts.map +1 -0
  75. package/dts/chart/scrubber/Scrubber.d.ts +172 -43
  76. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  77. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +44 -0
  78. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -0
  79. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts +31 -0
  80. package/dts/chart/scrubber/ScrubberBeaconLabelGroup.d.ts.map +1 -0
  81. package/dts/chart/scrubber/ScrubberProvider.d.ts +6 -3
  82. package/dts/chart/scrubber/ScrubberProvider.d.ts.map +1 -1
  83. package/dts/chart/scrubber/index.d.ts +3 -0
  84. package/dts/chart/scrubber/index.d.ts.map +1 -1
  85. package/dts/chart/text/ChartText.d.ts +151 -77
  86. package/dts/chart/text/ChartText.d.ts.map +1 -1
  87. package/dts/chart/text/{SmartChartTextGroup.d.ts → ChartTextGroup.d.ts} +9 -3
  88. package/dts/chart/text/ChartTextGroup.d.ts.map +1 -0
  89. package/dts/chart/text/index.d.ts +1 -1
  90. package/dts/chart/text/index.d.ts.map +1 -1
  91. package/dts/chart/utils/axis.d.ts +25 -1
  92. package/dts/chart/utils/axis.d.ts.map +1 -1
  93. package/dts/chart/utils/chart.d.ts +34 -7
  94. package/dts/chart/utils/chart.d.ts.map +1 -1
  95. package/dts/chart/utils/context.d.ts +28 -7
  96. package/dts/chart/utils/context.d.ts.map +1 -1
  97. package/dts/chart/utils/gradient.d.ts +117 -0
  98. package/dts/chart/utils/gradient.d.ts.map +1 -0
  99. package/dts/chart/utils/index.d.ts +3 -0
  100. package/dts/chart/utils/index.d.ts.map +1 -1
  101. package/dts/chart/utils/path.d.ts +53 -0
  102. package/dts/chart/utils/path.d.ts.map +1 -1
  103. package/dts/chart/utils/point.d.ts +71 -7
  104. package/dts/chart/utils/point.d.ts.map +1 -1
  105. package/dts/chart/utils/scale.d.ts +102 -0
  106. package/dts/chart/utils/scale.d.ts.map +1 -1
  107. package/dts/chart/utils/scrubber.d.ts +39 -0
  108. package/dts/chart/utils/scrubber.d.ts.map +1 -0
  109. package/dts/chart/utils/transition.d.ts +140 -0
  110. package/dts/chart/utils/transition.d.ts.map +1 -0
  111. package/esm/chart/CartesianChart.js +164 -70
  112. package/esm/chart/ChartContextBridge.js +148 -0
  113. package/esm/chart/Path.js +198 -113
  114. package/esm/chart/PeriodSelector.js +2 -2
  115. package/esm/chart/__stories__/CartesianChart.stories.js +378 -131
  116. package/esm/chart/__stories__/Chart.stories.js +2 -4
  117. package/esm/chart/__stories__/PeriodSelector.stories.js +103 -75
  118. package/esm/chart/area/Area.js +25 -35
  119. package/esm/chart/area/AreaChart.js +17 -12
  120. package/esm/chart/area/DottedArea.js +61 -109
  121. package/esm/chart/area/GradientArea.js +35 -91
  122. package/esm/chart/area/SolidArea.js +22 -8
  123. package/esm/chart/area/__stories__/AreaChart.stories.js +1 -1
  124. package/esm/chart/axis/Axis.js +5 -39
  125. package/esm/chart/axis/DefaultAxisTickLabel.js +11 -0
  126. package/esm/chart/axis/XAxis.js +148 -66
  127. package/esm/chart/axis/YAxis.js +149 -65
  128. package/esm/chart/axis/__stories__/Axis.stories.js +259 -1
  129. package/esm/chart/axis/index.js +1 -0
  130. package/esm/chart/bar/Bar.js +3 -1
  131. package/esm/chart/bar/BarChart.js +15 -37
  132. package/esm/chart/bar/BarPlot.js +41 -35
  133. package/esm/chart/bar/BarStack.js +75 -38
  134. package/esm/chart/bar/BarStackGroup.js +6 -16
  135. package/esm/chart/bar/DefaultBar.js +26 -48
  136. package/esm/chart/bar/DefaultBarStack.js +23 -58
  137. package/esm/chart/bar/__stories__/BarChart.stories.js +502 -77
  138. package/esm/chart/gradient/Gradient.js +53 -0
  139. package/esm/chart/gradient/index.js +1 -0
  140. package/esm/chart/index.js +3 -1
  141. package/esm/chart/line/DefaultReferenceLineLabel.js +66 -0
  142. package/esm/chart/line/DottedLine.js +29 -14
  143. package/esm/chart/line/Line.js +106 -67
  144. package/esm/chart/line/LineChart.js +20 -14
  145. package/esm/chart/line/ReferenceLine.js +80 -63
  146. package/esm/chart/line/SolidLine.js +25 -10
  147. package/esm/chart/line/__stories__/LineChart.stories.js +2101 -1977
  148. package/esm/chart/line/__stories__/ReferenceLine.stories.js +83 -28
  149. package/esm/chart/line/index.js +1 -1
  150. package/esm/chart/point/DefaultPointLabel.js +39 -0
  151. package/esm/chart/point/Point.js +188 -0
  152. package/esm/chart/point/index.js +2 -0
  153. package/esm/chart/scrubber/DefaultScrubberBeacon.js +179 -0
  154. package/esm/chart/scrubber/DefaultScrubberBeaconLabel.js +43 -0
  155. package/esm/chart/scrubber/DefaultScrubberLabel.js +28 -0
  156. package/esm/chart/scrubber/Scrubber.js +126 -146
  157. package/esm/chart/scrubber/ScrubberBeaconGroup.js +161 -0
  158. package/esm/chart/scrubber/ScrubberBeaconLabelGroup.js +185 -0
  159. package/esm/chart/scrubber/ScrubberProvider.js +46 -54
  160. package/esm/chart/scrubber/index.js +3 -1
  161. package/esm/chart/text/ChartText.js +242 -174
  162. package/esm/chart/text/{SmartChartTextGroup.js → ChartTextGroup.js} +6 -5
  163. package/esm/chart/text/index.js +1 -1
  164. package/esm/chart/utils/axis.js +45 -29
  165. package/esm/chart/utils/chart.js +44 -3
  166. package/esm/chart/utils/gradient.js +305 -0
  167. package/esm/chart/utils/index.js +3 -0
  168. package/esm/chart/utils/path.js +76 -8
  169. package/esm/chart/utils/point.js +171 -17
  170. package/esm/chart/utils/scale.js +242 -2
  171. package/esm/chart/utils/scrubber.js +139 -0
  172. package/esm/chart/utils/transition.js +185 -0
  173. package/esm/sparkline/__stories__/Sparkline.stories.js +11 -7
  174. package/esm/sparkline/__stories__/SparklineGradient.stories.js +7 -4
  175. package/esm/sparkline/sparkline-interactive/__stories__/SparklineInteractive.stories.js +51 -26
  176. package/esm/sparkline/sparkline-interactive-header/__stories__/SparklineInteractiveHeader.stories.js +17 -9
  177. package/package.json +15 -9
  178. package/dts/chart/Point.d.ts +0 -103
  179. package/dts/chart/Point.d.ts.map +0 -1
  180. package/dts/chart/line/GradientLine.d.ts +0 -45
  181. package/dts/chart/line/GradientLine.d.ts.map +0 -1
  182. package/dts/chart/scrubber/ScrubberBeacon.d.ts +0 -75
  183. package/dts/chart/scrubber/ScrubberBeacon.d.ts.map +0 -1
  184. package/dts/chart/text/SmartChartTextGroup.d.ts.map +0 -1
  185. package/esm/chart/Point.js +0 -111
  186. package/esm/chart/line/GradientLine.js +0 -62
  187. package/esm/chart/scrubber/ScrubberBeacon.js +0 -199
@@ -1,17 +1,18 @@
1
- const _excluded = ["axisId", "position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "style", "className", "styles", "classNames", "GridLineComponent", "tickMarkLabelGap", "width", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval"];
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); }
1
+ const _excluded = ["axisId", "position", "showGrid", "requestedTickCount", "ticks", "tickLabelFormatter", "TickLabelComponent", "GridLineComponent", "LineComponent", "TickMarkLineComponent", "tickMarkLabelGap", "minTickLabelGap", "showTickMarks", "showLine", "tickMarkSize", "tickInterval", "label", "labelGap", "width", "bandGridLinePlacement", "bandTickMarkPlacement"];
3
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; }
4
3
  import { memo, useCallback, useEffect, useId, useMemo } from 'react';
5
- import Animated, { useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
6
- import { G, Line } from 'react-native-svg';
7
4
  import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
5
+ import { Group, vec } from '@shopify/react-native-skia';
8
6
  import { useCartesianChartContext } from '../ChartProvider';
9
7
  import { DottedLine } from '../line/DottedLine';
10
- import { ReferenceLine } from '../line/ReferenceLine';
11
- import { SmartChartTextGroup } from '../text/SmartChartTextGroup';
12
- import { getAxisTicksData, isCategoricalScale } from '../utils';
8
+ import { SolidLine } from '../line/SolidLine';
9
+ import { ChartText } from '../text/ChartText';
10
+ import { ChartTextGroup } from '../text/ChartTextGroup';
11
+ import { getAxisTicksData, getPointOnScale, isCategoricalScale, lineToPath, toPointAnchor } from '../utils';
12
+ import { DefaultAxisTickLabel } from './DefaultAxisTickLabel';
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- const AnimatedG = Animated.createAnimatedComponent(G);
14
+ const AXIS_WIDTH = 44;
15
+ const LABEL_SIZE = 20;
15
16
  export const YAxis = /*#__PURE__*/memo(_ref => {
16
17
  let {
17
18
  axisId,
@@ -20,22 +21,28 @@ export const YAxis = /*#__PURE__*/memo(_ref => {
20
21
  requestedTickCount = 5,
21
22
  ticks,
22
23
  tickLabelFormatter,
23
- styles,
24
- classNames,
24
+ TickLabelComponent = DefaultAxisTickLabel,
25
25
  GridLineComponent = DottedLine,
26
+ LineComponent = SolidLine,
27
+ TickMarkLineComponent = SolidLine,
26
28
  tickMarkLabelGap = 8,
27
- width = 44,
28
29
  minTickLabelGap = 0,
29
30
  showTickMarks,
30
31
  showLine,
31
32
  tickMarkSize = 4,
32
- tickInterval
33
+ tickInterval,
34
+ label,
35
+ labelGap = 4,
36
+ width = label ? AXIS_WIDTH + LABEL_SIZE : AXIS_WIDTH,
37
+ bandGridLinePlacement = 'edges',
38
+ bandTickMarkPlacement = 'middle'
33
39
  } = _ref,
34
40
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
35
41
  const theme = useTheme();
36
42
  const registrationId = useId();
37
43
  const {
38
44
  animate,
45
+ drawingArea,
39
46
  getYScale,
40
47
  getYAxis,
41
48
  registerAxis,
@@ -45,17 +52,6 @@ export const YAxis = /*#__PURE__*/memo(_ref => {
45
52
  const yScale = getYScale(axisId);
46
53
  const yAxis = getYAxis(axisId);
47
54
  const axisBounds = getAxisBounds(registrationId);
48
- const gridOpacity = useSharedValue(1);
49
- const axisLineProps = useMemo(() => ({
50
- stroke: theme.color.fg,
51
- strokeLinecap: 'square',
52
- strokeWidth: 1
53
- }), [theme.color.fg]);
54
- const axisTickMarkProps = useMemo(() => ({
55
- stroke: theme.color.fg,
56
- strokeLinecap: 'square',
57
- strokeWidth: 1
58
- }), [theme.color.fg]);
59
55
  useEffect(() => {
60
56
  registerAxis(registrationId, position, width);
61
57
  return () => unregisterAxis(registrationId);
@@ -104,6 +100,72 @@ export const YAxis = /*#__PURE__*/memo(_ref => {
104
100
  tickInterval: tickInterval
105
101
  });
106
102
  }, [ticks, yScale, requestedTickCount, tickInterval, yAxis == null ? void 0 : yAxis.data]);
103
+ const isBandScale = useMemo(() => {
104
+ if (!yScale) return false;
105
+ return isCategoricalScale(yScale);
106
+ }, [yScale]);
107
+
108
+ // Compute grid line positions (including bounds closing line for band scales)
109
+ const gridLinePositions = useMemo(() => {
110
+ if (!yScale) return [];
111
+ return ticksData.flatMap((tick, index) => {
112
+ if (!isBandScale) {
113
+ return [{
114
+ y: tick.position,
115
+ key: "grid-" + tick.tick + "-" + index
116
+ }];
117
+ }
118
+ const bandScale = yScale;
119
+ const isLastTick = index === ticksData.length - 1;
120
+ const isEdges = bandGridLinePlacement === 'edges';
121
+ const startY = getPointOnScale(tick.tick, bandScale, toPointAnchor(bandGridLinePlacement));
122
+ const positions = [{
123
+ y: startY,
124
+ key: "grid-" + tick.tick + "-" + index
125
+ }];
126
+
127
+ // For edges on last tick, add the closing line at stepEnd
128
+ if (isLastTick && isEdges) {
129
+ const endY = getPointOnScale(tick.tick, bandScale, 'stepEnd');
130
+ positions.push({
131
+ y: endY,
132
+ key: "grid-" + tick.tick + "-" + index + "-end"
133
+ });
134
+ }
135
+ return positions;
136
+ });
137
+ }, [ticksData, yScale, isBandScale, bandGridLinePlacement]);
138
+
139
+ // Compute tick mark positions (including bounds closing tick for band scales)
140
+ const tickMarkPositions = useMemo(() => {
141
+ if (!yScale) return [];
142
+ return ticksData.flatMap((tick, index) => {
143
+ if (!isBandScale) {
144
+ return [{
145
+ y: tick.position,
146
+ key: "tick-mark-" + tick.tick + "-" + index
147
+ }];
148
+ }
149
+ const bandScale = yScale;
150
+ const isLastTick = index === ticksData.length - 1;
151
+ const isEdges = bandTickMarkPlacement === 'edges';
152
+ const startY = getPointOnScale(tick.tick, bandScale, toPointAnchor(bandTickMarkPlacement));
153
+ const positions = [{
154
+ y: startY,
155
+ key: "tick-mark-" + tick.tick + "-" + index
156
+ }];
157
+
158
+ // For edges on last tick, add the closing tick mark at stepEnd
159
+ if (isLastTick && isEdges) {
160
+ const endY = getPointOnScale(tick.tick, bandScale, 'stepEnd');
161
+ positions.push({
162
+ y: endY,
163
+ key: "tick-mark-" + tick.tick + "-" + index + "-end"
164
+ });
165
+ }
166
+ return positions;
167
+ });
168
+ }, [ticksData, yScale, isBandScale, bandTickMarkPlacement]);
107
169
  const chartTextData = useMemo(() => {
108
170
  if (!axisBounds) return null;
109
171
  return ticksData.map(tick => {
@@ -114,57 +176,79 @@ export const YAxis = /*#__PURE__*/memo(_ref => {
114
176
  y: tick.position,
115
177
  label: String(formatTick(tick.tick)),
116
178
  chartTextProps: {
117
- className: classNames == null ? void 0 : classNames.tickLabel,
118
179
  color: theme.color.fgMuted,
119
180
  verticalAlignment: 'middle',
120
- style: styles == null ? void 0 : styles.tickLabel,
121
181
  horizontalAlignment: position === 'left' ? 'right' : 'left'
122
182
  }
123
183
  };
124
184
  });
125
- }, [axisBounds, ticksData, theme.color.fgMuted, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, classNames == null ? void 0 : classNames.tickLabel, styles == null ? void 0 : styles.tickLabel]);
126
- const gridAnimatedStyle = useAnimatedStyle(() => ({
127
- opacity: gridOpacity.value
128
- }));
129
- if (!yScale) return;
130
- return /*#__PURE__*/_jsxs(G, _extends({
131
- "data-axis": "y",
132
- "data-position": position
133
- }, props, {
134
- children: [showGrid && /*#__PURE__*/_jsx(AnimatedG, {
135
- animatedProps: gridAnimatedStyle,
136
- children: ticksData.map((tick, index) => {
137
- const horizontalLine = /*#__PURE__*/_jsx(ReferenceLine, {
138
- LineComponent: GridLineComponent,
139
- dataY: tick.tick,
140
- yAxisId: axisId
141
- });
142
- return /*#__PURE__*/_jsx(G, {
143
- children: horizontalLine
144
- }, "grid-" + tick.tick + "-" + index);
185
+ }, [axisBounds, ticksData, tickMarkLabelGap, showTickMarks, tickMarkSize, position, formatTick, theme.color.fgMuted]);
186
+ if (!yScale || !axisBounds) return;
187
+ const labelX = position === 'left' ? axisBounds.x + LABEL_SIZE / 2 : axisBounds.x + axisBounds.width - LABEL_SIZE / 2;
188
+ const labelY = axisBounds.y + axisBounds.height / 2;
189
+
190
+ // Pre-compute tick mark X coordinates
191
+ const tickXLeft = axisBounds.x;
192
+ const tickXRight = axisBounds.x + axisBounds.width;
193
+ const tickXStart = position === 'left' ? tickXRight : tickXLeft;
194
+ const tickXEnd = position === 'left' ? tickXRight - tickMarkSize : tickXLeft + tickMarkSize;
195
+
196
+ // Note: Unlike web, mobile renders grid lines and tick marks immediately without fade animation.
197
+ // This is because Skia can measure text dimensions synchronously, so there's no need to hide
198
+ // elements while waiting for measurements (web uses async ResizeObserver).
199
+ return /*#__PURE__*/_jsxs(Group, {
200
+ children: [showGrid && /*#__PURE__*/_jsx(Group, {
201
+ children: gridLinePositions.map(_ref2 => {
202
+ let {
203
+ y,
204
+ key
205
+ } = _ref2;
206
+ return /*#__PURE__*/_jsx(GridLineComponent, {
207
+ animate: false,
208
+ clipPath: null,
209
+ d: lineToPath(drawingArea.x, y, drawingArea.x + drawingArea.width, y),
210
+ stroke: theme.color.bgLine
211
+ }, key);
145
212
  })
146
- }), chartTextData && /*#__PURE__*/_jsx(SmartChartTextGroup, {
213
+ }), chartTextData && /*#__PURE__*/_jsx(ChartTextGroup, {
147
214
  prioritizeEndLabels: true,
215
+ LabelComponent: TickLabelComponent,
148
216
  labels: chartTextData,
149
217
  minGap: minTickLabelGap
150
- }), axisBounds && showTickMarks && /*#__PURE__*/_jsx(G, {
151
- "data-testid": "tick-marks",
152
- children: ticksData.map((tick, index) => {
153
- const tickX = position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x;
154
- const tickMarkSizePixels = tickMarkSize;
155
- const tickX2 = position === 'left' ? axisBounds.x + axisBounds.width - tickMarkSizePixels : axisBounds.x + tickMarkSizePixels;
156
- return /*#__PURE__*/_jsx(Line, _extends({}, axisTickMarkProps, {
157
- x1: tickX,
158
- x2: tickX2,
159
- y1: tick.position,
160
- y2: tick.position
161
- }), "tick-mark-" + tick.tick + "-" + index);
218
+ }), axisBounds && showTickMarks && /*#__PURE__*/_jsx(Group, {
219
+ children: tickMarkPositions.map(_ref3 => {
220
+ let {
221
+ y,
222
+ key
223
+ } = _ref3;
224
+ return /*#__PURE__*/_jsx(TickMarkLineComponent, {
225
+ animate: false,
226
+ clipPath: null,
227
+ d: lineToPath(tickXStart, y, tickXEnd, y),
228
+ stroke: theme.color.fg,
229
+ strokeCap: "square",
230
+ strokeWidth: 1
231
+ }, key);
232
+ })
233
+ }), showLine && /*#__PURE__*/_jsx(LineComponent, {
234
+ animate: false,
235
+ clipPath: null,
236
+ d: lineToPath(position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x, axisBounds.y, position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x, axisBounds.y + axisBounds.height),
237
+ stroke: theme.color.fg,
238
+ strokeCap: "square",
239
+ strokeWidth: 1
240
+ }), label && /*#__PURE__*/_jsx(Group, {
241
+ origin: vec(labelX, labelY),
242
+ transform: [{
243
+ rotate: position === 'left' ? -Math.PI / 2 : Math.PI / 2
244
+ }],
245
+ children: /*#__PURE__*/_jsx(ChartText, {
246
+ horizontalAlignment: "center",
247
+ verticalAlignment: "middle",
248
+ x: labelX,
249
+ y: labelY,
250
+ children: label
162
251
  })
163
- }), axisBounds && showLine && /*#__PURE__*/_jsx(Line, _extends({}, axisLineProps, {
164
- x1: position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x,
165
- x2: position === 'left' ? axisBounds.x + axisBounds.width : axisBounds.x,
166
- y1: axisBounds.y,
167
- y2: axisBounds.y + axisBounds.height
168
- }))]
169
- }));
252
+ })]
253
+ });
170
254
  });
@@ -2,6 +2,7 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
2
2
  import { memo, useCallback, useMemo } from 'react';
3
3
  import { Example, ExampleScreen } from '@coinbase/cds-mobile/examples/ExampleScreen';
4
4
  import { useTheme } from '@coinbase/cds-mobile/hooks/useTheme';
5
+ import { BarPlot } from '../../bar';
5
6
  import { CartesianChart } from '../../CartesianChart';
6
7
  import { LineChart, SolidLine } from '../../line';
7
8
  import { Line } from '../../line/Line';
@@ -118,7 +119,6 @@ const TimeOfDayAxesExample = () => {
118
119
  }, [timeData]);
119
120
  return /*#__PURE__*/_jsxs(LineChart, {
120
121
  enableScrubbing: true,
121
- curve: "monotone",
122
122
  height: defaultChartHeight,
123
123
  series: [{
124
124
  id: 'lineA',
@@ -195,6 +195,105 @@ const MultipleYAxesExample = () => /*#__PURE__*/_jsxs(CartesianChart, {
195
195
  seriesId: "log"
196
196
  }), /*#__PURE__*/_jsx(Scrubber, {})]
197
197
  });
198
+ const AxesOnAllSides = () => {
199
+ const theme = useTheme();
200
+ const data = [30, 45, 60, 80, 55, 40, 65];
201
+ const labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
202
+ return /*#__PURE__*/_jsxs(CartesianChart, {
203
+ height: defaultChartHeight,
204
+ series: [{
205
+ id: 'data',
206
+ data,
207
+ color: theme.color.accentBoldBlue
208
+ }],
209
+ xAxis: {
210
+ data: labels
211
+ },
212
+ yAxis: {
213
+ domain: {
214
+ min: 0,
215
+ max: 100
216
+ }
217
+ },
218
+ children: [/*#__PURE__*/_jsx(XAxis, {
219
+ showLine: true,
220
+ showTickMarks: true,
221
+ label: "Bottom Axis",
222
+ position: "bottom",
223
+ ticks: labels.map((label, index) => index)
224
+ }), /*#__PURE__*/_jsx(XAxis, {
225
+ showLine: true,
226
+ showTickMarks: true,
227
+ label: "Top Axis",
228
+ position: "top",
229
+ ticks: labels.map((label, index) => index)
230
+ }), /*#__PURE__*/_jsx(YAxis, {
231
+ showLine: true,
232
+ showTickMarks: true,
233
+ label: "Left Axis",
234
+ position: "left"
235
+ }), /*#__PURE__*/_jsx(YAxis, {
236
+ showLine: true,
237
+ showTickMarks: true,
238
+ label: "Right Axis",
239
+ position: "right"
240
+ }), /*#__PURE__*/_jsx(Line, {
241
+ curve: "natural",
242
+ seriesId: "data"
243
+ })]
244
+ });
245
+ };
246
+ const CustomTickMarkSizes = () => {
247
+ const theme = useTheme();
248
+ const data = [25, 50, 75, 60, 45, 80, 35];
249
+ return /*#__PURE__*/_jsxs(CartesianChart, {
250
+ height: 300,
251
+ series: [{
252
+ id: 'data',
253
+ data,
254
+ color: theme.color.accentBoldGreen
255
+ }],
256
+ xAxis: {
257
+ data: ['A', 'B', 'C', 'D', 'E', 'F', 'G']
258
+ },
259
+ yAxis: {
260
+ domain: {
261
+ min: 0,
262
+ max: 100
263
+ }
264
+ },
265
+ children: [/*#__PURE__*/_jsx(XAxis, {
266
+ showLine: true,
267
+ showTickMarks: true,
268
+ label: "tickMarkSize=4 (default)",
269
+ tickMarkSize: 4
270
+ }), /*#__PURE__*/_jsx(XAxis, {
271
+ showLine: true,
272
+ showTickMarks: true,
273
+ height: 60,
274
+ label: "tickMarkSize=8",
275
+ position: "top",
276
+ tickMarkSize: 8
277
+ }), /*#__PURE__*/_jsx(YAxis, {
278
+ showLine: true,
279
+ showTickMarks: true,
280
+ label: "tickMarkSize=16",
281
+ position: "left",
282
+ tickMarkSize: 16,
283
+ width: 76
284
+ }), /*#__PURE__*/_jsx(YAxis, {
285
+ showLine: true,
286
+ showTickMarks: true,
287
+ label: "tickMarkSize=24",
288
+ position: "right",
289
+ tickMarkSize: 24,
290
+ width: 84
291
+ }), /*#__PURE__*/_jsx(Line, {
292
+ curve: "monotone",
293
+ seriesId: "data"
294
+ })]
295
+ });
296
+ };
198
297
  const DomainLimitType = _ref => {
199
298
  let {
200
299
  limit
@@ -250,6 +349,97 @@ const DomainLimitType = _ref => {
250
349
  }), /*#__PURE__*/_jsx(Scrubber, {})]
251
350
  });
252
351
  };
352
+
353
+ // Band scale with tick filtering - show every other tick
354
+ const BandScaleTickFiltering = () => /*#__PURE__*/_jsxs(CartesianChart, {
355
+ height: defaultChartHeight,
356
+ inset: 8,
357
+ series: [{
358
+ id: 'data',
359
+ data: [10, 22, 29, 45, 98, 45, 22, 35, 42, 18, 55, 67]
360
+ }],
361
+ xAxis: {
362
+ scaleType: 'band',
363
+ data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
364
+ },
365
+ yAxis: {
366
+ domain: {
367
+ min: 0
368
+ }
369
+ },
370
+ children: [/*#__PURE__*/_jsx(XAxis, {
371
+ showGrid: true,
372
+ showLine: true,
373
+ showTickMarks: true,
374
+ label: "ticks={(i) => i % 2 === 0}",
375
+ ticks: i => i % 2 === 0
376
+ }), /*#__PURE__*/_jsx(BarPlot, {})]
377
+ });
378
+
379
+ // Band scale with explicit ticks array
380
+ const BandScaleExplicitTicks = () => /*#__PURE__*/_jsxs(CartesianChart, {
381
+ height: defaultChartHeight,
382
+ inset: 8,
383
+ series: [{
384
+ id: 'data',
385
+ data: [10, 22, 29, 45, 98, 45, 22]
386
+ }],
387
+ xAxis: {
388
+ scaleType: 'band',
389
+ data: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
390
+ },
391
+ yAxis: {
392
+ domain: {
393
+ min: 0
394
+ }
395
+ },
396
+ children: [/*#__PURE__*/_jsx(XAxis, {
397
+ showGrid: true,
398
+ showLine: true,
399
+ showTickMarks: true,
400
+ label: "ticks={[0, 3, 6]} (first, middle, last)",
401
+ ticks: [0, 3, 6]
402
+ }), /*#__PURE__*/_jsx(BarPlot, {})]
403
+ });
404
+
405
+ // Line chart on band scale - comparing grid placements
406
+ const LineChartOnBandScale = _ref2 => {
407
+ let {
408
+ bandGridLinePlacement
409
+ } = _ref2;
410
+ const theme = useTheme();
411
+ return /*#__PURE__*/_jsxs(CartesianChart, {
412
+ height: 180,
413
+ inset: 8,
414
+ series: [{
415
+ id: 'line1',
416
+ data: [10, 22, 29, 45, 98, 45, 22],
417
+ color: theme.color.accentBoldBlue
418
+ }],
419
+ xAxis: {
420
+ scaleType: 'band',
421
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
422
+ },
423
+ yAxis: {
424
+ domain: {
425
+ min: 0
426
+ }
427
+ },
428
+ children: [/*#__PURE__*/_jsx(XAxis, {
429
+ showGrid: true,
430
+ showLine: true,
431
+ showTickMarks: true,
432
+ bandGridLinePlacement: bandGridLinePlacement,
433
+ bandTickMarkPlacement: bandGridLinePlacement,
434
+ label: "bandGridLinePlacement: " + bandGridLinePlacement
435
+ }), /*#__PURE__*/_jsx(YAxis, {
436
+ showGrid: true,
437
+ position: "left"
438
+ }), /*#__PURE__*/_jsx(Line, {
439
+ seriesId: "line1"
440
+ })]
441
+ });
442
+ };
253
443
  const AxisStories = () => {
254
444
  return /*#__PURE__*/_jsxs(ExampleScreen, {
255
445
  children: [/*#__PURE__*/_jsx(Example, {
@@ -271,6 +461,74 @@ const AxisStories = () => {
271
461
  children: /*#__PURE__*/_jsx(DomainLimitType, {
272
462
  limit: "nice"
273
463
  })
464
+ }), /*#__PURE__*/_jsx(Example, {
465
+ title: "Band Axis Grid Alignment",
466
+ children: /*#__PURE__*/_jsxs(CartesianChart, {
467
+ height: 350,
468
+ inset: 8,
469
+ series: [{
470
+ id: 'prices',
471
+ data: [10, 22, 29, 45, 98, 45, 22]
472
+ }],
473
+ xAxis: {
474
+ scaleType: 'band',
475
+ data: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
476
+ },
477
+ yAxis: {
478
+ domain: {
479
+ min: 0
480
+ }
481
+ },
482
+ children: [/*#__PURE__*/_jsx(XAxis, {
483
+ showGrid: true,
484
+ showLine: true,
485
+ showTickMarks: true,
486
+ label: "Default"
487
+ }), /*#__PURE__*/_jsx(XAxis, {
488
+ showLine: true,
489
+ showTickMarks: true,
490
+ bandTickMarkPlacement: "start",
491
+ label: "Start"
492
+ }), /*#__PURE__*/_jsx(XAxis, {
493
+ showLine: true,
494
+ showTickMarks: true,
495
+ bandTickMarkPlacement: "end",
496
+ label: "End"
497
+ }), /*#__PURE__*/_jsx(XAxis, {
498
+ showLine: true,
499
+ showTickMarks: true,
500
+ bandTickMarkPlacement: "middle",
501
+ label: "Middle"
502
+ }), /*#__PURE__*/_jsx(XAxis, {
503
+ showLine: true,
504
+ showTickMarks: true,
505
+ bandTickMarkPlacement: "edges",
506
+ label: "Edges"
507
+ }), /*#__PURE__*/_jsx(BarPlot, {})]
508
+ })
509
+ }), /*#__PURE__*/_jsx(Example, {
510
+ title: "Band Scale - Tick Filtering",
511
+ children: /*#__PURE__*/_jsx(BandScaleTickFiltering, {})
512
+ }), /*#__PURE__*/_jsx(Example, {
513
+ title: "Band Scale - Explicit Ticks",
514
+ children: /*#__PURE__*/_jsx(BandScaleExplicitTicks, {})
515
+ }), /*#__PURE__*/_jsxs(Example, {
516
+ title: "Line Chart on Band Scale - Grid Positions",
517
+ children: [/*#__PURE__*/_jsx(LineChartOnBandScale, {
518
+ bandGridLinePlacement: "edges"
519
+ }), /*#__PURE__*/_jsx(LineChartOnBandScale, {
520
+ bandGridLinePlacement: "start"
521
+ }), /*#__PURE__*/_jsx(LineChartOnBandScale, {
522
+ bandGridLinePlacement: "middle"
523
+ }), /*#__PURE__*/_jsx(LineChartOnBandScale, {
524
+ bandGridLinePlacement: "end"
525
+ })]
526
+ }), /*#__PURE__*/_jsx(Example, {
527
+ title: "Axes on All Sides",
528
+ children: /*#__PURE__*/_jsx(AxesOnAllSides, {})
529
+ }), /*#__PURE__*/_jsx(Example, {
530
+ title: "Custom Tick Mark Sizes",
531
+ children: /*#__PURE__*/_jsx(CustomTickMarkSizes, {})
274
532
  })]
275
533
  });
276
534
  };
@@ -1,5 +1,6 @@
1
1
  // codegen:start {preset: barrel, include: ./*.tsx, exclude: ./__stories__/*.tsx}
2
2
  export * from './Axis';
3
+ export * from './DefaultAxisTickLabel';
3
4
  export * from './XAxis';
4
5
  export * from './YAxis';
5
6
  // codegen:end
@@ -31,7 +31,8 @@ export const Bar = /*#__PURE__*/memo(_ref => {
31
31
  strokeWidth,
32
32
  borderRadius = 4,
33
33
  roundTop = true,
34
- roundBottom = true
34
+ roundBottom = true,
35
+ transition
35
36
  } = _ref;
36
37
  const theme = useTheme();
37
38
 
@@ -60,6 +61,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
60
61
  roundTop: roundTop,
61
62
  stroke: stroke,
62
63
  strokeWidth: strokeWidth,
64
+ transition: transition,
63
65
  width: width,
64
66
  x: x,
65
67
  y: y