99 :stroke-width =" lineWidth * invScale"
1010 :stroke-dasharray =" dashArray"
1111 />
12+
1213 <Label
1314 v-if =" label"
1415 :text =" label"
@@ -30,7 +31,7 @@ import Label from "./Label.vue";
3031import { useGraphContext } from " ../composables/useGraphContext.ts" ;
3132import { useColors } from " ../composables/useColors.ts" ;
3233import { usePointerIntersection } from " ../composables/usePointerIntersection.ts" ;
33- import { useLocalToWorld } from " ../composables/useLocalToWorld .ts" ;
34+ import { useMatrices } from " ../composables/useMatrices .ts" ;
3435import { distanceToLineSegment } from " ../utils/geometry.ts" ;
3536
3637const props = withDefaults (
@@ -61,50 +62,59 @@ if (props.to === undefined && props.slope === undefined) {
6162
6263const { domain, invScale } = useGraphContext ();
6364const { parseColor } = useColors ();
64- const matrix = useLocalToWorld ();
65+ const { parentToWorld, cameraMatrix } = useMatrices ();
6566
6667const color = parseColor (toRef (props , " color" ), " stroke" );
6768const active = defineModel (" active" , { default: false });
68- usePointerIntersection (
69- active ,
70- ( point ) =>
69+ usePointerIntersection (active , ( point ) => {
70+ const matrix = cameraMatrix . value . multiply ( parentToWorld . value . inverse );
71+ return (
7172 distanceToLineSegment (
72- from .value .transform (matrix . value . inverse ),
73- to .value .transform (matrix . value . inverse ),
73+ from .value .transform (matrix ),
74+ to .value .transform (matrix ),
7475 point ,
75- ) <= props .highlightThreshold ,
76- );
76+ ) <= props .highlightThreshold
77+ );
78+ });
7779
7880function clamp(x : number , min : number , max : number ) {
7981 return Math .min (max , Math .max (min , x ));
8082}
8183
8284const from = computed (() => {
8385 if (props .from ) {
84- return new Vector2 (props .from ).transform (matrix .value );
86+ return new Vector2 (props .from ).transform (parentToWorld .value );
8587 }
8688
8789 if (props .to ) {
88- return new Vector2 (0 , 0 ).transform (matrix .value );
90+ return new Vector2 (0 , 0 ).transform (parentToWorld .value );
8991 }
9092
9193 let x = (domain .value .y .x - props .yIntercept ) / props .slope ! ;
92- x = clamp (x , domain .value .x .x , domain .value .x .y );
94+ x = clamp (
95+ x ,
96+ domain .value .x .x + cameraMatrix .value .tx ,
97+ domain .value .x .y - cameraMatrix .value .tx ,
98+ );
9399 const y = props .slope ! * x + props .yIntercept ;
94- return new Vector2 (x , y ).transform (matrix .value );
100+ return new Vector2 (x , y ).transform (parentToWorld .value );
95101});
96102const to = computed (() => {
97103 if (props .to ) {
98- return new Vector2 (props .to ).transform (matrix .value );
104+ return new Vector2 (props .to ).transform (parentToWorld .value );
99105 }
100106
101107 let x = (domain .value .y .y - props .yIntercept ) / props .slope ! ;
102- x = clamp (x , domain .value .x .x , domain .value .x .y );
108+ x = clamp (
109+ x ,
110+ domain .value .x .x + cameraMatrix .value .tx ,
111+ domain .value .x .y - cameraMatrix .value .tx ,
112+ );
103113 const y = props .slope ! * x + props .yIntercept ;
104- return new Vector2 (x , y ).transform (matrix .value );
114+ return new Vector2 (x , y ).transform (parentToWorld .value );
105115});
106116const labelPosition = computed (() => {
107- const worldToLocal = matrix .value .inverse ;
117+ const worldToLocal = parentToWorld .value .inverse ;
108118 const localSpaceFrom = from .value .transform (worldToLocal );
109119 const localSpaceTo = to .value .transform (worldToLocal );
110120 const diff = localSpaceTo .sub (localSpaceFrom );
0 commit comments