Skip to content

Commit 9dd32f4

Browse files
committed
feat: allow labels to be rotated
1 parent 26162c2 commit 9dd32f4

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/components/Label.vue

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<template>
2-
<rect
3-
:x="position.x - boxWidth / 2"
4-
:y="position.y - boxHeight / 2 - 0.5"
5-
:width="boxWidth"
6-
:height="boxHeight"
7-
:fill="colors.labelBackground"
8-
:stroke="color"
9-
stroke-width="1.5"
10-
rx="6"
11-
/>
12-
<text
13-
:x="position.x"
14-
:y="position.y"
15-
:style="`font-family: monospace; font-size: ${fontSize}px; dominant-baseline: middle; text-anchor: middle; font-weight: 500;`"
16-
:fill="color"
17-
>
18-
{{ text }}
19-
</text>
2+
<g :transform="`rotate(${-rotation}, ${position.x}, ${position.y})`">
3+
<rect
4+
:x="position.x - boxWidth / 2"
5+
:y="position.y - boxHeight / 2 - 0.5"
6+
:width="boxWidth"
7+
:height="boxHeight"
8+
:fill="colors.labelBackground"
9+
:stroke="color"
10+
stroke-width="1.5"
11+
rx="6"
12+
/>
13+
<text
14+
:x="position.x"
15+
:y="position.y"
16+
:style="`font-family: monospace; font-size: ${fontSize}px; dominant-baseline: middle; text-anchor: middle; font-weight: 500;`"
17+
:fill="color"
18+
>
19+
{{ text }}
20+
</text>
21+
</g>
2022
</template>
2123

2224
<script setup lang="ts">
@@ -32,9 +34,14 @@ const props = withDefaults(
3234
size?: keyof typeof sizes;
3335
color?: Color;
3436
position?: PossibleVector2;
37+
rotation?: number;
3538
text: string;
3639
}>(),
37-
{ size: "normal", position: () => new Vector2() },
40+
{
41+
size: "normal",
42+
position: () => new Vector2(),
43+
rotation: 0,
44+
},
3845
);
3946
4047
const fontSizes = {

0 commit comments

Comments
 (0)