Skip to content

Commit 8854c16

Browse files
authored
Fix the label background position when using dy fns (#2720)
1 parent 3073fa0 commit 8854c16

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

.changeset/moody-mayflies-attack.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"victory-core": patch
3+
---
4+
5+
Fix the label background position when using dy fns

packages/victory-core/src/victory-label/victory-label.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ const getCalculatedProps = <T extends VictoryLabelProps>(props: T) => {
508508
verticalAnchor,
509509
dx,
510510
dy,
511-
originalDy: props.dy,
511+
originalDy: Helpers.evaluateProp(props.dy, props),
512512
transform,
513513
x,
514514
y,

stories/victory-label.stories.js

+32
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,38 @@ export const BackgroundStyles = () => {
581581
/>
582582
}
583583
/>
584+
<VictoryScatter
585+
{...defaultScatterProps}
586+
labelComponent={
587+
<VictoryLabel
588+
dy={({ datum }) => (datum.y > 0 ? -5 : 8)}
589+
verticalAnchor="end"
590+
backgroundPadding={{ top: 5, right: 5, bottom: 5, left: 5 }}
591+
backgroundStyle={{ fill: "plum", stroke: "#000000" }}
592+
text={[
593+
"Victory is awesome.",
594+
"background styles",
595+
"work with dy functions",
596+
]}
597+
/>
598+
}
599+
/>
600+
<VictoryScatter
601+
{...defaultScatterProps}
602+
labelComponent={
603+
<VictoryLabel
604+
dx={({ datum }) => (datum.y > 0 ? -5 : 8)}
605+
verticalAnchor="end"
606+
backgroundPadding={{ top: 5, right: 5, bottom: 5, left: 5 }}
607+
backgroundStyle={{ fill: "thistle", stroke: "#000000" }}
608+
text={[
609+
"Victory is awesome.",
610+
"background styles",
611+
"work with dx functions",
612+
]}
613+
/>
614+
}
615+
/>
584616
</div>
585617
);
586618
};

0 commit comments

Comments
 (0)