Skip to content

Commit 6ab9b30

Browse files
committed
Add text label to SVG
1 parent 326a69d commit 6ab9b30

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ angle (default is right / 3 o'clock).
3636
## Properties
3737
|prop|description|default|options|
3838
|:---|---|---|---|
39+
|`size`|width and height of element|`10rem`|String|
3940
|`dashCount`|Total number of dashes|`60`|Natural number|
4041
|`activeCount`|Number of dashes on top|`10`|Natural number|
4142
|`strokeWidth`|Bottom stroke as a percentage of the radius|`20`|`0` to `100`|
@@ -45,6 +46,7 @@ angle (default is right / 3 o'clock).
4546
|`dashSpacing`|Fraction of width taken up by space between dashes|`1/4`|`0` to `1`|
4647
|`rotate`|Degrees rotation for start angle (0 = right)|`-90`|`-360` to `360`|
4748
|`reverse`|Reverse the direction of counting (true = counter-clockwise)|`false`|`false` or `true`|
49+
|`text`|Text string to display inside SVG|`""`|String|
4850

4951
## License
5052

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div id="app">
3-
<circle-counter width="20rem" height="20rem"/>
3+
<circle-counter width="20rem" height="20rem" text="label"/>
44
</div>
55
</template>
66

src/CircleCounter.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<svg :viewBox="`0 0 ${UNITS} ${UNITS}`" height="100%" width="100%">
2+
<svg
3+
:viewBox="`0 0 ${UNITS} ${UNITS}`"
4+
:height="size || '100%'"
5+
:width="size || '100%'"
6+
>
37
<g :transform="`rotate(${rotate},${UNITS/2},${UNITS/2}) ${reverse ? 'scale(1,-1) translate(0, -' + UNITS +')' : ''}`">
48
<circle
59
:cx="UNITS/2"
@@ -18,16 +22,25 @@
1822
:stroke-dasharray="getLengths()"
1923
/>
2024
</g>
25+
<text fill="currentColor" x="50%" y="50%" text-anchor="middle" dominant-baseline="middle" >{{text}}</text>
2126
</svg>
2227
</template>
2328

2429
<script>
2530
export default {
2631
beforeCreate() {
2732
// Arbitrary dimensions of SVG to set up user-space units
28-
this.UNITS = 32;
33+
this.UNITS = 200;
2934
},
3035
props: {
36+
size: {
37+
type: String,
38+
default: ''
39+
},
40+
text: {
41+
type: String,
42+
default: ''
43+
},
3144
dashCount: {
3245
type: Number,
3346
default: 60

0 commit comments

Comments
 (0)