Skip to content

Commit 69f7504

Browse files
committed
Fix - VueUiMolecule - Fix rendering issues when config updates dynamically
1 parent 0ed6f59 commit 69f7504

File tree

3 files changed

+66
-56
lines changed

3 files changed

+66
-56
lines changed

src/atoms/RecursiveCircles.vue

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</template>
5050

5151
<script setup>
52-
import { toRef } from 'vue';
52+
import { ref, watch } from 'vue';
5353
5454
const props = defineProps({
5555
color: {
@@ -62,39 +62,39 @@ const props = defineProps({
6262
},
6363
hoveredUid: {
6464
type: String,
65-
default: null
65+
default: null,
6666
},
6767
linkColor: {
6868
type: String,
6969
default: '#CCCCCC',
7070
},
7171
stroke: {
7272
type: String,
73-
default: "#FFFFFF"
73+
default: '#FFFFFF',
7474
},
7575
strokeHovered: {
7676
type: String,
77-
default: '#000000'
77+
default: '#000000',
7878
},
7979
});
8080
81-
const emit = defineEmits(["click", 'hover']);
81+
const emit = defineEmits(['click', 'hover']);
8282
8383
function click(node) {
84-
emit('click', node)
84+
emit('click', node);
8585
}
8686
8787
function hover(node) {
88-
emit('hover', node)
88+
emit('hover', node);
8989
}
9090
91-
const nodes = toRef(props, 'dataset');
91+
const nodes = ref([]);
9292
93-
nodes.value.forEach((node) => {
94-
if (node.nodes && node.nodes.length > 0) {
95-
node.nodes.forEach((childNode) => {
96-
childNode.ancestor = node;
97-
});
98-
}
99-
});
93+
watch(
94+
() => props.dataset,
95+
(newDataset) => {
96+
nodes.value = newDataset || [];
97+
},
98+
{ immediate: true }
99+
);
100100
</script>

src/atoms/RecursiveLabels.vue

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
<template>
2-
<template v-for="(node, i) in dataset">
2+
<template v-for="(node, i) in nodes" :key="`level_${i}`">
33
<template v-if="node.polygonPath && node.polygonPath.coordinates">
44
<template v-for="(coordinate, index) in node.polygonPath.coordinates" :key="`node_${i}_${index}`">
5-
<text
6-
data-cy="recursive-label"
7-
:x="coordinate.x"
8-
:y="coordinate.y + node.circleRadius *2"
9-
:fill="color"
10-
:font-size="node.circleRadius"
11-
text-anchor="middle"
12-
style="opacity:0.8; pointer-events: none;"
13-
>
5+
<text data-cy="recursive-label" :x="coordinate.x" :y="coordinate.y + node.circleRadius * 2"
6+
:fill="color" :font-size="node.circleRadius" text-anchor="middle"
7+
style="opacity: 0.8; pointer-events: none;">
148
{{ node.name }}
159
</text>
1610
</template>
11+
1712
<template v-if="node.nodes && node.nodes.length > 0">
18-
<RecursiveLabels
19-
:dataset="node.nodes"
20-
:color="color"
21-
:hoveredUid="hoveredUid"
22-
/>
13+
<RecursiveLabels :dataset="node.nodes" :color="color" :hoveredUid="hoveredUid" />
2314
</template>
2415
</template>
2516
</template>
2617
</template>
2718

2819
<script setup>
29-
import { toRef } from 'vue';
20+
import { ref, watch } from 'vue';
3021
31-
const emit = defineEmits(["zoom", 'hover']);
22+
const emit = defineEmits(['zoom', 'hover']);
3223
3324
const props = defineProps({
3425
color: {
@@ -41,17 +32,17 @@ const props = defineProps({
4132
},
4233
hoveredUid: {
4334
type: String,
44-
default: null
35+
default: null,
4536
},
4637
});
4738
48-
const nodes = toRef(props, 'dataset');
39+
const nodes = ref([]);
4940
50-
nodes.value.forEach((node) => {
51-
if (node.nodes && node.nodes.length > 0) {
52-
node.nodes.forEach((childNode) => {
53-
childNode.ancestor = node;
54-
});
55-
}
56-
});
41+
watch(
42+
() => props.dataset,
43+
(newDataset) => {
44+
nodes.value = newDataset || [];
45+
},
46+
{ immediate: true }
47+
);
5748
</script>

src/atoms/RecursiveLinks.vue

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<template>
2-
<template v-for="(node, i) in dataset">
2+
<template v-for="(node, i) in nodes" :key="`level_${i}`">
33
<template v-if="node.polygonPath && node.polygonPath.coordinates">
4-
<template v-for="(coordinate, index) in node.polygonPath.coordinates" :key="`node_${i}_${index}`">
4+
<template
5+
v-for="(coordinate, index) in node.polygonPath.coordinates"
6+
:key="`node_${i}_${index}`"
7+
>
58
<template v-if="node.ancestor && node.ancestor.polygonPath">
69
<line
710
data-cy="recursive-link-wrapper"
@@ -25,17 +28,22 @@
2528
</template>
2629
</template>
2730
</template>
28-
<template v-for="node in dataset">
31+
32+
<template v-for="node in nodes" :key="`children_${node.uid || node.name}`">
2933
<template v-if="node.polygonPath && node.polygonPath.coordinates">
3034
<template v-if="node.nodes && node.nodes.length > 0">
31-
<RecursiveLinks :dataset="node.nodes" :color="color" :backgroundColor="backgroundColor"/>
35+
<RecursiveLinks
36+
:dataset="node.nodes"
37+
:color="color"
38+
:backgroundColor="backgroundColor"
39+
/>
3240
</template>
3341
</template>
3442
</template>
3543
</template>
3644

3745
<script setup>
38-
import { toRef } from 'vue';
46+
import { ref, watch } from 'vue';
3947
4048
const props = defineProps({
4149
dataset: {
@@ -48,18 +56,29 @@ const props = defineProps({
4856
},
4957
backgroundColor: {
5058
type: String,
51-
default: '#FFFFFF'
52-
}
59+
default: '#FFFFFF',
60+
},
5361
});
5462
55-
const nodes = toRef(props, 'dataset');
63+
const nodes = ref([]);
64+
65+
watch(
66+
() => props.dataset,
67+
(newDataset) => {
68+
const data = newDataset || [];
5669
57-
nodes.value.forEach((node) => {
58-
if (node.nodes && node.nodes.length > 0) {
59-
node.nodes.forEach((childNode) => {
60-
childNode.ancestor = node;
70+
data.forEach((node) => {
71+
if (node.nodes && node.nodes.length > 0) {
72+
node.nodes.forEach((childNode) => {
73+
if (childNode.ancestor !== node) {
74+
childNode.ancestor = node;
75+
}
76+
});
77+
}
6178
});
62-
}
63-
});
64-
</script>
6579
80+
nodes.value = data;
81+
},
82+
{ immediate: true }
83+
);
84+
</script>

0 commit comments

Comments
 (0)