5
5
:x2 =" to.x"
6
6
:y2 =" to.y"
7
7
:stroke =" color"
8
- :stroke-width =" lineWidth"
8
+ :stroke-width =" lineWidth * invScale "
9
9
:stroke-dasharray =" dashArray"
10
10
/>
11
11
<Label
@@ -50,7 +50,7 @@ if (props.to === undefined && props.slope === undefined) {
50
50
throw new Error (" Line requires either a `to` prop or a `slope` prop" );
51
51
}
52
52
53
- const context = useGraphContext ();
53
+ const { domain, scale, offset, invScale } = useGraphContext ();
54
54
const { parseColor } = useColors ();
55
55
56
56
const color = parseColor (toRef (props , " color" ), " stroke" );
@@ -63,52 +63,54 @@ const from = computed(() => {
63
63
if (props .from ) {
64
64
return new Vector2 (props .from )
65
65
.mul (new Vector2 (1 , - 1 ))
66
- .mul (context . scale .value )
67
- .add (context . offset .value );
66
+ .mul (scale .value )
67
+ .add (offset .value );
68
68
}
69
69
70
70
if (props .to ) {
71
71
return new Vector2 (0 , 0 )
72
72
.mul (new Vector2 (1 , - 1 ))
73
- .mul (context . scale .value )
74
- .add (context . offset .value );
73
+ .mul (scale .value )
74
+ .add (offset .value );
75
75
}
76
76
77
- let x = (context . domain .value .y .x - props .yIntercept ) / props .slope ! ;
78
- x = clamp (x , context . domain .value .x .x , context . domain .value .x .y );
77
+ let x = (domain .value .y .x - props .yIntercept ) / props .slope ! ;
78
+ x = clamp (x , domain .value .x .x , domain .value .x .y );
79
79
const y = props .slope ! * x + props .yIntercept ;
80
80
return new Vector2 (x , y )
81
81
.mul (new Vector2 (1 , - 1 ))
82
- .mul (context . scale .value )
83
- .add (context . offset .value );
82
+ .mul (scale .value )
83
+ .add (offset .value );
84
84
});
85
85
const to = computed (() => {
86
86
if (props .to ) {
87
87
return new Vector2 (props .to )
88
88
.mul (new Vector2 (1 , - 1 ))
89
- .mul (context . scale .value )
90
- .add (context . offset .value );
89
+ .mul (scale .value )
90
+ .add (offset .value );
91
91
}
92
92
93
- let x = (context . domain .value .y .y - props .yIntercept ) / props .slope ! ;
94
- x = clamp (x , context . domain .value .x .x , context . domain .value .x .y );
93
+ let x = (domain .value .y .y - props .yIntercept ) / props .slope ! ;
94
+ x = clamp (x , domain .value .x .x , domain .value .x .y );
95
95
const y = props .slope ! * x + props .yIntercept ;
96
96
return new Vector2 (x , y )
97
97
.mul (new Vector2 (1 , - 1 ))
98
- .mul (context . scale .value )
99
- .add (context . offset .value );
98
+ .mul (scale .value )
99
+ .add (offset .value );
100
100
});
101
101
const labelPosition = computed (() => {
102
102
const localSpaceFrom = from .value
103
- .sub (context . offset .value )
104
- .div (context . scale .value )
103
+ .sub (offset .value )
104
+ .div (scale .value )
105
105
.mul (new Vector2 (1 , - 1 ));
106
106
const localSpaceTo = to .value
107
- .sub (context . offset .value )
108
- .div (context . scale .value )
107
+ .sub (offset .value )
108
+ .div (scale .value )
109
109
.mul (new Vector2 (1 , - 1 ));
110
110
const diff = localSpaceTo .sub (localSpaceFrom );
111
111
return localSpaceFrom .add (diff .normalized ().scale (diff .length () / 2 ));
112
112
});
113
- const dashArray = computed (() => (props .dashed ? " 6,4" : " 0,0" ));
113
+ const dashArray = computed (() =>
114
+ props .dashed ? [6 * invScale .value , 4 * invScale .value ].join (" ," ) : " 0,0" ,
115
+ );
114
116
</script >
0 commit comments