Skip to content

Commit 0cab33d

Browse files
authored
fix: reference line opacity and build transition on mobile (#201)
* fix: set mobile reference line opacity directly instead of via group * fix: do not spread inside of buildTransition * Update tests and bump version
1 parent b8c1abd commit 0cab33d

File tree

12 files changed

+74
-34
lines changed

12 files changed

+74
-34
lines changed

packages/mobile-visualization/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ All notable changes to this project will be documented in this file.
88

99
<!-- template-start -->
1010

11+
## 3.4.0-beta.7 (12/2/2025 PST)
12+
13+
#### 🐞 Fixes
14+
15+
- Fix babel build issue with transitions. [[#201](https://github.com/coinbase/cds/pull/201)]
16+
- Improve opacity customization for ReferenceLine. [[#201](https://github.com/coinbase/cds/pull/201)]
17+
1118
## 3.4.0-beta.6 (10/16/2025 PST)
1219

1320
#### 🚀 Updates

packages/mobile-visualization/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coinbase/cds-mobile-visualization",
3-
"version": "3.4.0-beta.6",
3+
"version": "3.4.0-beta.7",
44
"description": "Coinbase Design System - Mobile Visualization Native",
55
"repository": {
66
"type": "git",

packages/mobile-visualization/src/chart/Path.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type PathBaseProps = {
5050
/**
5151
* Opacity for the path stroke.
5252
*/
53-
strokeOpacity?: number;
53+
strokeOpacity?: AnimatedProp<number>;
5454
};
5555

5656
export type PathProps = PathBaseProps &

packages/mobile-visualization/src/chart/line/Line.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type LineBaseProps = {
9191
* @note when combined with gradient, both will be applied
9292
* @default 1
9393
*/
94-
strokeOpacity?: number;
94+
strokeOpacity?: AnimatedProp<number>;
9595
/**
9696
* Width of the line
9797
* @default 2

packages/mobile-visualization/src/chart/line/ReferenceLine.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export type ReferenceLineBaseProps = {
110110
* @default theme.color.bgLine
111111
*/
112112
stroke?: string;
113+
/**
114+
* Opacity applied to both the line and label.
115+
* @default 1
116+
*/
117+
opacity?: AnimatedProp<number>;
113118
};
114119

115120
type HorizontalReferenceLineProps = ReferenceLineBaseProps & {
@@ -163,6 +168,7 @@ export const ReferenceLine = memo<ReferenceLineProps>(
163168
labelVerticalAlignment,
164169
labelBoundsInset,
165170
stroke,
171+
opacity = 1,
166172
}) => {
167173
const theme = useTheme();
168174
const { getXSerializableScale, getYSerializableScale, drawingArea } =
@@ -203,14 +209,13 @@ export const ReferenceLine = memo<ReferenceLineProps>(
203209

204210
const labelXPixel = useDerivedValue(() => xPixel.value ?? 0, [xPixel]);
205211
const labelYPixel = useDerivedValue(() => yPixel.value ?? 0, [yPixel]);
206-
const labelOpacity = useDerivedValue(
207-
() =>
212+
213+
const labelOpacity = useDerivedValue(() => {
214+
const isVisible =
208215
(dataY !== undefined && yPixel.value !== undefined) ||
209-
(dataX !== undefined && xPixel.value !== undefined)
210-
? 1
211-
: 0,
212-
[yPixel],
213-
);
216+
(dataX !== undefined && xPixel.value !== undefined);
217+
return isVisible ? unwrapAnimatedValue(opacity) : 0;
218+
}, [yPixel, xPixel, opacity]);
214219

215220
if (dataY !== undefined) {
216221
let labelX: number;
@@ -224,7 +229,12 @@ export const ReferenceLine = memo<ReferenceLineProps>(
224229

225230
return (
226231
<>
227-
<LineComponent animate={false} d={horizontalLine} stroke={effectiveLineStroke} />
232+
<LineComponent
233+
animate={false}
234+
d={horizontalLine}
235+
stroke={effectiveLineStroke}
236+
strokeOpacity={opacity}
237+
/>
228238
{label && (
229239
<LabelComponent
230240
boundsInset={labelBoundsInset}
@@ -258,7 +268,12 @@ export const ReferenceLine = memo<ReferenceLineProps>(
258268

259269
return (
260270
<>
261-
<LineComponent animate={false} d={verticalLine} stroke={effectiveLineStroke} />
271+
<LineComponent
272+
animate={false}
273+
d={verticalLine}
274+
stroke={effectiveLineStroke}
275+
strokeOpacity={opacity}
276+
/>
262277
{label && (
263278
<LabelComponent
264279
boundsInset={labelBoundsInset}

packages/mobile-visualization/src/chart/scrubber/Scrubber.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ export type ScrubberBaseProps = Pick<ScrubberBeaconGroupBaseProps, 'idlePulse'>
147147
*/
148148
seriesIds?: string[];
149149
/**
150-
* Hides the scrubber line
150+
* Hides the scrubber line.
151+
* @note This hides Scrubber's ReferenceLine including the label.
151152
*/
152153
hideLine?: boolean;
153154
/**
@@ -360,18 +361,17 @@ export const Scrubber = memo(
360361
/>
361362
)}
362363
{!hideLine && (
363-
<Group opacity={lineOpacity}>
364-
<ReferenceLine
365-
LabelComponent={LabelComponent}
366-
LineComponent={LineComponent}
367-
dataX={dataX}
368-
label={resolvedLabelValue}
369-
labelBoundsInset={labelBoundsInset}
370-
labelElevated={labelElevated}
371-
labelFont={labelFont}
372-
stroke={lineStroke}
373-
/>
374-
</Group>
364+
<ReferenceLine
365+
LabelComponent={LabelComponent}
366+
LineComponent={LineComponent}
367+
dataX={dataX}
368+
label={resolvedLabelValue}
369+
labelBoundsInset={labelBoundsInset}
370+
labelElevated={labelElevated}
371+
labelFont={labelFont}
372+
opacity={lineOpacity}
373+
stroke={lineStroke}
374+
/>
375375
)}
376376
<ScrubberBeaconGroup
377377
ref={beaconGroupRef}

packages/mobile-visualization/src/chart/utils/__tests__/transition.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('buildTransition', () => {
9494
duration: 500,
9595
});
9696

97-
expect(withTiming).toHaveBeenCalledWith(100, { duration: 500 });
97+
expect(withTiming).toHaveBeenCalledWith(100, { type: 'timing', duration: 500 });
9898
expect(result).toBe(100);
9999
});
100100

@@ -107,6 +107,7 @@ describe('buildTransition', () => {
107107
});
108108

109109
expect(withSpring).toHaveBeenCalledWith(200, {
110+
type: 'spring',
110111
damping: 10,
111112
stiffness: 100,
112113
});
@@ -132,6 +133,7 @@ describe('buildTransition', () => {
132133
buildTransition(50, config);
133134

134135
expect(withTiming).toHaveBeenCalledWith(50, {
136+
type: 'timing',
135137
duration: 1000,
136138
easing: config.easing,
137139
});
@@ -152,6 +154,7 @@ describe('buildTransition', () => {
152154
buildTransition(75, config);
153155

154156
expect(withSpring).toHaveBeenCalledWith(75, {
157+
type: 'spring',
155158
damping: 15,
156159
stiffness: 200,
157160
mass: 1,

packages/mobile-visualization/src/chart/utils/transition.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,14 @@ export const buildTransition = (targetValue: number, transition: Transition): nu
149149
'worklet';
150150
switch (transition.type) {
151151
case 'timing': {
152-
const { type, ...timingConfig } = transition;
153-
return withTiming(targetValue, timingConfig);
152+
return withTiming(targetValue, transition);
154153
}
155154
case 'spring': {
156-
const { type, ...springConfig } = transition;
157-
return withSpring(targetValue, springConfig);
155+
return withSpring(targetValue, transition);
158156
}
159157
default: {
160158
// Fallback to default transition config
161-
const { type, ...springConfig } = defaultTransition;
162-
return withSpring(targetValue, springConfig);
159+
return withSpring(targetValue, defaultTransition);
163160
}
164161
}
165162
};

packages/web-visualization/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file.
88

99
<!-- template-start -->
1010

11+
## 3.4.0-beta.7 (12/2/2025 PST)
12+
13+
#### 🐞 Fixes
14+
15+
- Improve opacity customization for ReferenceLine. [[#201](https://github.com/coinbase/cds/pull/201)]
16+
1117
## 3.4.0-beta.6 (10/16/2025 PST)
1218

1319
#### 🚀 Updates

packages/web-visualization/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coinbase/cds-web-visualization",
3-
"version": "3.4.0-beta.6",
3+
"version": "3.4.0-beta.7",
44
"description": "Coinbase Design System - Web Sparkline",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)