@@ -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
115120type 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 }
0 commit comments