1
1
<template >
2
- <path
3
- v-if =" fill"
4
- :d =" `M ${scaledB.x} ${scaledB.y} L ${start.x} ${start.y} A ${scaledRadius} ${scaledRadius} 0 ${sweep} 0 ${end.x} ${end.y}`"
5
- stroke =" none"
6
- :fill =" fill"
7
- />
2
+ <g >
3
+ <path
4
+ v-if =" fill"
5
+ :d =" `M ${scaledB.x} ${scaledB.y} L ${start.x} ${start.y} A ${scaledRadius} ${scaledRadius} 0 ${sweep} 0 ${end.x} ${end.y}`"
6
+ stroke =" none"
7
+ :fill =" fill"
8
+ />
8
9
9
- <path
10
- :d =" `M ${start.x} ${start.y} A ${scaledRadius} ${scaledRadius} 0 ${sweep} 0 ${end.x} ${end.y}`"
11
- :stroke-width =" lineWidth * invScale"
12
- :stroke =" stroke"
13
- :stroke-dasharray =" dashArray"
14
- fill =" none"
15
- />
10
+ <path
11
+ :d =" `M ${start.x} ${start.y} A ${scaledRadius} ${scaledRadius} 0 ${sweep} 0 ${end.x} ${end.y}`"
12
+ :stroke-width =" lineWidth * invScale"
13
+ :stroke =" stroke"
14
+ :stroke-dasharray =" dashArray"
15
+ fill =" none"
16
+ />
17
+
18
+ <Label
19
+ v-if =" label"
20
+ :text =" label"
21
+ :position =" labelPosition"
22
+ :color =" color"
23
+ :size =" labelSize"
24
+ />
25
+ </g >
16
26
</template >
17
27
18
28
<script setup lang="ts">
@@ -22,6 +32,8 @@ import { PossibleVector2, Vector2 } from "../utils/Vector2.ts";
22
32
import { useGraphContext } from " ../composables/useGraphContext.ts" ;
23
33
import { Color } from " ../types.ts" ;
24
34
import { useColors } from " ../composables/useColors.ts" ;
35
+ import Label from " ./Label.vue" ;
36
+ import { TAU } from " ../utils/constants.ts" ;
25
37
26
38
const props = withDefaults (
27
39
defineProps <{
@@ -33,12 +45,15 @@ const props = withDefaults(
33
45
c: PossibleVector2 ;
34
46
dashed? : boolean ;
35
47
lineWidth? : number ;
48
+ label? : string ;
49
+ labelSize? : " small" | " normal" | " large" ;
36
50
}>(),
37
51
{
38
52
position : () => new Vector2 (),
39
53
radius: 1 ,
40
54
dashed: false ,
41
55
lineWidth: 1.5 ,
56
+ labelSize: " small" ,
42
57
},
43
58
);
44
59
@@ -81,4 +96,16 @@ const end = computed(() => {
81
96
const dashArray = computed (() =>
82
97
props .dashed ? [6 * invScale .value , 4 * invScale .value ].join (" ," ) : " 0,0" ,
83
98
);
99
+ const labelPosition = computed (() => {
100
+ const bToA = a .value .sub (b .value );
101
+ const bToC = c .value .sub (b .value );
102
+ const dot = bToA .dot (bToC );
103
+ const det = bToA .x * bToC .y - bToA .y * bToC .x ;
104
+ const angle = (Math .atan2 (det , dot ) + TAU ) % TAU ;
105
+ return bToA
106
+ .normalized ()
107
+ .scale (props .radius )
108
+ .rotate (angle / 2 )
109
+ .add (b .value );
110
+ });
84
111
</script >
0 commit comments