@coinbase/cds-mobile-visualization 3.4.0-beta.12 → 3.4.0-beta.14

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 (48) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dts/chart/CartesianChart.d.ts +35 -1
  3. package/dts/chart/CartesianChart.d.ts.map +1 -1
  4. package/dts/chart/bar/Bar.d.ts +4 -0
  5. package/dts/chart/bar/Bar.d.ts.map +1 -1
  6. package/dts/chart/bar/BarChart.d.ts +6 -3
  7. package/dts/chart/bar/BarChart.d.ts.map +1 -1
  8. package/dts/chart/bar/BarStack.d.ts +11 -2
  9. package/dts/chart/bar/BarStack.d.ts.map +1 -1
  10. package/dts/chart/index.d.ts +1 -0
  11. package/dts/chart/index.d.ts.map +1 -1
  12. package/dts/chart/legend/DefaultLegendEntry.d.ts +5 -0
  13. package/dts/chart/legend/DefaultLegendEntry.d.ts.map +1 -0
  14. package/dts/chart/legend/DefaultLegendShape.d.ts +5 -0
  15. package/dts/chart/legend/DefaultLegendShape.d.ts.map +1 -0
  16. package/dts/chart/legend/Legend.d.ts +168 -0
  17. package/dts/chart/legend/Legend.d.ts.map +1 -0
  18. package/dts/chart/legend/index.d.ts +4 -0
  19. package/dts/chart/legend/index.d.ts.map +1 -0
  20. package/dts/chart/line/LineChart.d.ts.map +1 -1
  21. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts +24 -2
  22. package/dts/chart/scrubber/DefaultScrubberBeacon.d.ts.map +1 -1
  23. package/dts/chart/scrubber/Scrubber.d.ts +28 -2
  24. package/dts/chart/scrubber/Scrubber.d.ts.map +1 -1
  25. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts +10 -0
  26. package/dts/chart/scrubber/ScrubberBeaconGroup.d.ts.map +1 -1
  27. package/dts/chart/utils/chart.d.ts +18 -0
  28. package/dts/chart/utils/chart.d.ts.map +1 -1
  29. package/esm/chart/CartesianChart.js +40 -10
  30. package/esm/chart/__stories__/CartesianChart.stories.js +3 -3
  31. package/esm/chart/bar/Bar.js +2 -0
  32. package/esm/chart/bar/BarStack.js +8 -1
  33. package/esm/chart/index.js +1 -0
  34. package/esm/chart/legend/DefaultLegendEntry.js +42 -0
  35. package/esm/chart/legend/DefaultLegendShape.js +64 -0
  36. package/esm/chart/legend/Legend.js +59 -0
  37. package/esm/chart/legend/__stories__/Legend.stories.js +574 -0
  38. package/esm/chart/legend/index.js +3 -0
  39. package/esm/chart/line/LineChart.js +2 -1
  40. package/esm/chart/line/__stories__/LineChart.stories.js +161 -6
  41. package/esm/chart/scrubber/DefaultScrubberBeacon.js +14 -10
  42. package/esm/chart/scrubber/Scrubber.js +5 -2
  43. package/esm/chart/scrubber/ScrubberBeaconGroup.js +6 -2
  44. package/esm/chart/utils/chart.js +13 -0
  45. package/esm/sparkline/__figma__/Sparkline.figma.js +1 -1
  46. package/esm/sparkline/sparkline-interactive/__figma__/SparklineInteractive.figma.js +1 -1
  47. package/esm/sparkline/sparkline-interactive-header/__figma__/SparklineInteractiveHeader.figma.js +1 -1
  48. package/package.json +5 -6
@@ -1,4 +1,4 @@
1
- const _excluded = ["series", "children", "animate", "enableScrubbing", "xAxis", "yAxis", "inset", "onScrubberPositionChange", "width", "height", "style", "styles", "allowOverflowGestures", "fontFamilies", "fontProvider", "collapsable"];
1
+ const _excluded = ["series", "children", "animate", "enableScrubbing", "xAxis", "yAxis", "inset", "onScrubberPositionChange", "legend", "legendPosition", "legendAccessibilityLabel", "width", "height", "style", "styles", "allowOverflowGestures", "fontFamilies", "fontProvider", "collapsable"];
2
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
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
4
  import React, { forwardRef, memo, useCallback, useMemo } from 'react';
@@ -9,8 +9,9 @@ import { ScrubberProvider } from './scrubber/ScrubberProvider';
9
9
  import { convertToSerializableScale } from './utils/scale';
10
10
  import { useChartContextBridge } from './ChartContextBridge';
11
11
  import { CartesianChartProvider } from './ChartProvider';
12
+ import { Legend } from './legend';
12
13
  import { defaultAxisId, defaultChartInset, getAxisConfig, getAxisDomain, getAxisRange, getAxisScale, getChartInset, getStackedSeriesData as calculateStackedSeriesData, useTotalAxisPadding } from './utils';
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
15
  const ChartCanvas = /*#__PURE__*/memo(_ref => {
15
16
  let {
16
17
  children,
@@ -37,6 +38,9 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2,
37
38
  yAxis: yAxisConfigProp,
38
39
  inset,
39
40
  onScrubberPositionChange,
41
+ legend,
42
+ legendPosition = 'bottom',
43
+ legendAccessibilityLabel,
40
44
  width = '100%',
41
45
  height = '100%',
42
46
  style,
@@ -309,22 +313,48 @@ export const CartesianChart = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref2,
309
313
  const rootStyles = useMemo(() => {
310
314
  return [style, styles == null ? void 0 : styles.root];
311
315
  }, [style, styles == null ? void 0 : styles.root]);
316
+ const legendElement = useMemo(() => {
317
+ if (!legend) return;
318
+ if (legend === true) {
319
+ const isHorizontal = legendPosition === 'top' || legendPosition === 'bottom';
320
+ const flexDirection = isHorizontal ? 'row' : 'column';
321
+ return /*#__PURE__*/_jsx(Legend, {
322
+ accessibilityLabel: legendAccessibilityLabel,
323
+ flexDirection: flexDirection
324
+ });
325
+ }
326
+ return legend;
327
+ }, [legend, legendAccessibilityLabel, legendPosition]);
328
+ const rootBoxProps = useMemo(() => _extends({
329
+ ref,
330
+ accessibilityLiveRegion: 'polite',
331
+ accessibilityRole: 'image',
332
+ height,
333
+ style: rootStyles,
334
+ width
335
+ }, props), [ref, height, rootStyles, width, props]);
312
336
  return /*#__PURE__*/_jsx(CartesianChartProvider, {
313
337
  value: contextValue,
314
338
  children: /*#__PURE__*/_jsx(ScrubberProvider, {
315
339
  allowOverflowGestures: allowOverflowGestures,
316
340
  enableScrubbing: enableScrubbing,
317
341
  onScrubberPositionChange: onScrubberPositionChange,
318
- children: /*#__PURE__*/_jsx(Box, _extends({
319
- ref: ref,
320
- accessibilityLiveRegion: "polite",
321
- accessibilityRole: "image",
342
+ children: legend ? /*#__PURE__*/_jsxs(Box, _extends({}, rootBoxProps, {
343
+ flexDirection: legendPosition === 'top' || legendPosition === 'bottom' ? 'column' : 'row',
344
+ children: [(legendPosition === 'top' || legendPosition === 'left') && legendElement, /*#__PURE__*/_jsx(Box, {
345
+ collapsable: collapsable,
346
+ onLayout: onContainerLayout,
347
+ style: {
348
+ flex: 1
349
+ },
350
+ children: /*#__PURE__*/_jsx(ChartCanvas, {
351
+ style: styles == null ? void 0 : styles.chart,
352
+ children: children
353
+ })
354
+ }), (legendPosition === 'bottom' || legendPosition === 'right') && legendElement]
355
+ })) : /*#__PURE__*/_jsx(Box, _extends({}, rootBoxProps, {
322
356
  collapsable: collapsable,
323
- height: height,
324
357
  onLayout: onContainerLayout,
325
- style: rootStyles,
326
- width: width
327
- }, props, {
328
358
  children: /*#__PURE__*/_jsx(ChartCanvas, {
329
359
  style: styles == null ? void 0 : styles.chart,
330
360
  children: children
@@ -155,7 +155,7 @@ const EarningsHistory = () => {
155
155
  backgroundColor: theme.color.bgPositive
156
156
  }
157
157
  });
158
- const LegendItem = /*#__PURE__*/memo(_ref2 => {
158
+ const LegendEntry = /*#__PURE__*/memo(_ref2 => {
159
159
  let {
160
160
  opacity = 1,
161
161
  label
@@ -217,10 +217,10 @@ const EarningsHistory = () => {
217
217
  }), /*#__PURE__*/_jsxs(HStack, {
218
218
  gap: 2,
219
219
  justifyContent: "flex-end",
220
- children: [/*#__PURE__*/_jsx(LegendItem, {
220
+ children: [/*#__PURE__*/_jsx(LegendEntry, {
221
221
  label: "Estimated EPS",
222
222
  opacity: 0.5
223
- }), /*#__PURE__*/_jsx(LegendItem, {
223
+ }), /*#__PURE__*/_jsx(LegendEntry, {
224
224
  label: "Actual EPS"
225
225
  })]
226
226
  })]
@@ -24,6 +24,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
24
24
  originY,
25
25
  dataX,
26
26
  dataY,
27
+ seriesId,
27
28
  BarComponent = DefaultBar,
28
29
  fill,
29
30
  fillOpacity = 1,
@@ -59,6 +60,7 @@ export const Bar = /*#__PURE__*/memo(_ref => {
59
60
  originY: effectiveOriginY,
60
61
  roundBottom: roundBottom,
61
62
  roundTop: roundTop,
63
+ seriesId: seriesId,
62
64
  stroke: stroke,
63
65
  strokeWidth: strokeWidth,
64
66
  transition: transition,
@@ -8,6 +8,11 @@ import { Bar } from './Bar';
8
8
  import { DefaultBarStack } from './DefaultBarStack';
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  const EPSILON = 1e-4;
11
+
12
+ /**
13
+ * Extended series type that includes bar-specific properties.
14
+ */
15
+
11
16
  /**
12
17
  * BarStack component that renders a single stack of bars at a specific category index.
13
18
  * Handles the stacking logic for bars within a single category.
@@ -153,6 +158,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
153
158
  // Check if the bar should be rounded based on the baseline, with an epsilon to handle floating-point rounding
154
159
  roundTop: roundBaseline || Math.abs(barTop - baseline) >= EPSILON,
155
160
  roundBottom: roundBaseline || Math.abs(barBottom - baseline) >= EPSILON,
161
+ BarComponent: s.BarComponent,
156
162
  shouldApplyGap
157
163
  });
158
164
  });
@@ -514,7 +520,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
514
520
  const xData = xAxis != null && xAxis.data && Array.isArray(xAxis.data) && typeof xAxis.data[0] === 'number' ? xAxis.data : undefined;
515
521
  const dataX = xData ? xData[categoryIndex] : categoryIndex;
516
522
  const barElements = bars.map((bar, index) => /*#__PURE__*/_jsx(Bar, {
517
- BarComponent: defaultBarComponent,
523
+ BarComponent: bar.BarComponent || defaultBarComponent,
518
524
  borderRadius: borderRadius,
519
525
  dataX: dataX,
520
526
  dataY: bar.dataY,
@@ -524,6 +530,7 @@ export const BarStack = /*#__PURE__*/memo(_ref => {
524
530
  originY: baseline,
525
531
  roundBottom: bar.roundBottom,
526
532
  roundTop: bar.roundTop,
533
+ seriesId: bar.seriesId,
527
534
  stroke: defaultStroke,
528
535
  strokeWidth: defaultStrokeWidth,
529
536
  transition: transition,
@@ -6,6 +6,7 @@ export * from './CartesianChart';
6
6
  export * from './ChartContextBridge';
7
7
  export * from './ChartProvider';
8
8
  export * from './gradient';
9
+ export * from './legend';
9
10
  export * from './line';
10
11
  export * from './Path';
11
12
  export * from './PeriodSelector';
@@ -0,0 +1,42 @@
1
+ const _excluded = ["label", "color", "shape", "ShapeComponent", "gap", "style", "styles", "testID"];
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 { StyleSheet } from 'react-native';
6
+ import { HStack } from '@coinbase/cds-mobile/layout';
7
+ import { Text } from '@coinbase/cds-mobile/typography/Text';
8
+ import { DefaultLegendShape } from './DefaultLegendShape';
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ const styles = StyleSheet.create({
11
+ legendEntry: {
12
+ alignItems: 'center'
13
+ }
14
+ });
15
+ export const DefaultLegendEntry = /*#__PURE__*/memo(_ref => {
16
+ let {
17
+ label,
18
+ color,
19
+ shape,
20
+ ShapeComponent = DefaultLegendShape,
21
+ gap = 1,
22
+ style,
23
+ styles: stylesProp,
24
+ testID
25
+ } = _ref,
26
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
27
+ return /*#__PURE__*/_jsxs(HStack, _extends({
28
+ gap: gap,
29
+ style: [styles.legendEntry, style, stylesProp == null ? void 0 : stylesProp.root],
30
+ testID: testID
31
+ }, props, {
32
+ children: [/*#__PURE__*/_jsx(ShapeComponent, {
33
+ color: color,
34
+ shape: shape,
35
+ style: stylesProp == null ? void 0 : stylesProp.shape
36
+ }), typeof label === 'string' ? /*#__PURE__*/_jsx(Text, {
37
+ font: "label1",
38
+ style: stylesProp == null ? void 0 : stylesProp.label,
39
+ children: label
40
+ }) : label]
41
+ }));
42
+ });
@@ -0,0 +1,64 @@
1
+ const _excluded = ["color", "shape", "style", "testID"];
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 { StyleSheet, View } from 'react-native';
6
+ import { useTheme } from '@coinbase/cds-mobile';
7
+ import { Box } from '@coinbase/cds-mobile/layout';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const styles = StyleSheet.create({
10
+ container: {
11
+ width: 10,
12
+ height: 24,
13
+ alignItems: 'center',
14
+ justifyContent: 'center'
15
+ },
16
+ pill: {
17
+ width: 6,
18
+ height: 24,
19
+ borderRadius: 3
20
+ },
21
+ circle: {
22
+ width: 10,
23
+ height: 10,
24
+ borderRadius: 5
25
+ },
26
+ square: {
27
+ width: 10,
28
+ height: 10
29
+ },
30
+ squircle: {
31
+ width: 10,
32
+ height: 10,
33
+ borderRadius: 2
34
+ }
35
+ });
36
+ const stylesByVariant = {
37
+ pill: styles.pill,
38
+ circle: styles.circle,
39
+ square: styles.square,
40
+ squircle: styles.squircle
41
+ };
42
+ const isVariantShape = shape => typeof shape === 'string' && shape in stylesByVariant;
43
+ export const DefaultLegendShape = /*#__PURE__*/memo(_ref => {
44
+ let {
45
+ color,
46
+ shape = 'circle',
47
+ style,
48
+ testID
49
+ } = _ref,
50
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
51
+ const theme = useTheme();
52
+ if (!isVariantShape(shape)) return shape;
53
+ const variantStyle = stylesByVariant[shape];
54
+ return /*#__PURE__*/_jsx(Box, _extends({
55
+ style: [styles.container, style],
56
+ testID: testID
57
+ }, props, {
58
+ children: /*#__PURE__*/_jsx(View, {
59
+ style: [variantStyle, {
60
+ backgroundColor: color != null ? color : theme.color.fgPrimary
61
+ }]
62
+ })
63
+ }));
64
+ });
@@ -0,0 +1,59 @@
1
+ const _excluded = ["flexDirection", "justifyContent", "alignItems", "flexWrap", "rowGap", "columnGap", "seriesIds", "EntryComponent", "ShapeComponent", "accessibilityLabel", "style", "styles"];
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 { forwardRef, memo, useMemo } from 'react';
5
+ import { Box } from '@coinbase/cds-mobile/layout';
6
+ import { useCartesianChartContext } from '../ChartProvider';
7
+ import { DefaultLegendEntry } from './DefaultLegendEntry';
8
+ import { DefaultLegendShape } from './DefaultLegendShape';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ export const Legend = /*#__PURE__*/memo(/*#__PURE__*/forwardRef((_ref, ref) => {
11
+ let {
12
+ flexDirection = 'row',
13
+ justifyContent = 'center',
14
+ alignItems = flexDirection === 'row' ? 'center' : 'flex-start',
15
+ flexWrap = 'wrap',
16
+ rowGap = 0.75,
17
+ columnGap = 2,
18
+ seriesIds,
19
+ EntryComponent = DefaultLegendEntry,
20
+ ShapeComponent = DefaultLegendShape,
21
+ accessibilityLabel = 'Legend',
22
+ style,
23
+ styles
24
+ } = _ref,
25
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
26
+ const {
27
+ series
28
+ } = useCartesianChartContext();
29
+ const filteredSeries = useMemo(() => {
30
+ if (seriesIds === undefined) return series.filter(s => s.label !== undefined);
31
+ return series.filter(s => seriesIds.includes(s.id) && s.label !== undefined);
32
+ }, [series, seriesIds]);
33
+ if (filteredSeries.length === 0) return;
34
+ return /*#__PURE__*/_jsx(Box, _extends({
35
+ ref: ref,
36
+ accessibilityLabel: accessibilityLabel,
37
+ accessibilityRole: "summary",
38
+ alignItems: alignItems,
39
+ columnGap: columnGap,
40
+ flexDirection: flexDirection,
41
+ flexWrap: flexWrap,
42
+ justifyContent: justifyContent,
43
+ rowGap: rowGap,
44
+ style: [style, styles == null ? void 0 : styles.root]
45
+ }, props, {
46
+ children: filteredSeries.map(s => /*#__PURE__*/_jsx(EntryComponent, {
47
+ ShapeComponent: ShapeComponent,
48
+ color: s.color,
49
+ label: s.label,
50
+ seriesId: s.id,
51
+ shape: s.legendShape,
52
+ styles: {
53
+ root: styles == null ? void 0 : styles.entry,
54
+ shape: styles == null ? void 0 : styles.entryShape,
55
+ label: styles == null ? void 0 : styles.entryLabel
56
+ }
57
+ }, s.id))
58
+ }));
59
+ }));