1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
| <script setup>
| import { ref, computed } from "vue";
| const props = defineProps({
| offset: {
| type: Array,
| default() {
| return [0, 0];
| },
| },
| fillColor: {
| type: String,
| default: "#073451",
| },
| lineWidth: {
| type: [Number, String],
| default: 2,
| },
| color: {
| type: String,
| default: "#4ec5f7",
| },
| text: {
| type: [String, Array],
| default: '',
| },
| fontSize: {
| type: [Number, String],
| default: 14,
| },
| width: {
| type: [Number, String],
| default: 130,
| },
| height: {
| type: [Number, String],
| default: 130,
| },
| img: {
| type: String,
| default: '',
| },
| imgWidth: {
| type: [Number, String],
| default: 120,
| },
| imgHeight: {
| type: [Number, String],
| default: 90,
| },
| rx: {
| type: [Number, String],
| default: 8,
| },
| ry: {
| type: [Number, String],
| default: 8,
| }
| });
|
| const imgX = computed(() => {
| return (props.width - props.imgWidth) / 2;
| });
|
| const imgY = computed(() => {
| return props.text ? (props.height - props.imgHeight + props.fontSize * 1.2) / 2 : (props.height - props.imgHeight) / 2;
| });
|
| const textX = computed(() => {
| return props.width / 2;
| });
|
| const textY = computed(() => {
| return props.fontSize * 1.2;
| });
|
| </script>
|
| <template>
| <g :transform="'translate(' + offset.join(',') + ')'">
| <rect
| :width="width"
| :height="height"
| :stroke="color"
| :fill="fillColor"
| :stroke-width='lineWidth'
| :rx="rx"
| :ry="ry"
| />
| <image
| :x="imgX"
| :y="imgY"
| :width="imgWidth"
| :height="imgHeight"
| :xlink:href="img"
| />
| <text
| v-if="text"
| :x="textX"
| :y="textY"
| :dy="fontSize/2"
| :fill="color"
| text-anchor="middle"
| :font-size="fontSize"
| >{{ text }}</text
| >
| </g>
| </template>
|
|