Skip to content

Commit 17a35df

Browse files
committed
Improvement - VueUiWordCloud - Improve word opacity handling on hover
1 parent 5a0301c commit 17a35df

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

src/components/vue-ui-word-cloud.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const { loading, FINAL_DATASET, manualLoading } = useLoading({
160160
words: {
161161
color: '#6A6A6A',
162162
usePalette: false,
163+
selectedStroke: '#CCCCCC'
163164
}
164165
}
165166
}
@@ -781,14 +782,27 @@ function useTooltip(word, index) {
781782
@click="onTrapClick(word, index)"
782783
/>
783784
<text
784-
:fill="word.color"
785-
:font-weight="FINAL_CONFIG.style.chart.words.bold ? 'bold' : 'normal'" :key="index"
786-
:x="word.x" :y="word.y" :font-size="word.fontSize"
785+
:fill="word.color"
786+
:font-weight="FINAL_CONFIG.style.chart.words.bold ? 'bold' : 'normal'"
787+
:key="index"
788+
:x="word.x"
789+
:y="word.y"
790+
:font-size="word.fontSize"
787791
:transform="`translate(${word.width / 2}, ${word.height / 2})`"
788-
:class="{'animated': FINAL_CONFIG.useCssAnimation, 'word-selected': selectedWord && selectedWord === word.id && mutableConfig.showTooltip, 'word-not-selected': selectedWord && selectedWord !== word.id && mutableConfig.showTooltip }"
792+
:class="{ 'animated': FINAL_CONFIG.useCssAnimation && !loading }"
789793
text-anchor="middle"
790794
dominant-baseline="central"
791-
:style="`animation-delay:${index * FINAL_CONFIG.animationDelayMs}ms !important; pointer-events:none;`"
795+
paint-order="stroke fill"
796+
:stroke="(!selectedWord || selectedWord === word.id) ? FINAL_CONFIG.style.chart.words.selectedStroke : undefined"
797+
:stroke-width="word.height * 0.05"
798+
stroke-linecap="round"
799+
stroke-linejoin="round"
800+
:style="`
801+
animation-delay:${index * FINAL_CONFIG.animationDelayMs}ms !important;
802+
pointer-events:none;
803+
fill-opacity:${(!selectedWord || selectedWord === word.id) ? 1 : FINAL_CONFIG.style.chart.words.hoverOpacity} !important;
804+
transition:fill-opacity 0.3s ease-in-out !important;
805+
`"
792806
>
793807
{{ word.name }}
794808
</text>
@@ -916,13 +930,6 @@ text.animated {
916930
}
917931
}
918932
919-
.animated.word-selected {
920-
opacity: 1;
921-
}
922-
.word-not-selected {
923-
opacity: 0.5 !important;
924-
}
925-
926933
.reset-wrapper {
927934
display: flex;
928935
flex-direction: row;

src/themes.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8761,6 +8761,9 @@
87618761
"color": "#757575"
87628762
}
87638763
},
8764+
"words": {
8765+
"selectedStroke": "#FFF8E1"
8766+
},
87648767
"tooltip": {
87658768
"backgroundColor": "#FFECB3",
87668769
"backgroundOpacity": 30,
@@ -8795,6 +8798,9 @@
87958798
"color": "#BDBDBD"
87968799
}
87978800
},
8801+
"words": {
8802+
"selectedStroke": "#1E1E1E"
8803+
},
87988804
"tooltip": {
87998805
"backgroundColor": "#1E1E1E",
88008806
"backgroundOpacity": 30,
@@ -8828,6 +8834,9 @@
88288834
"subtitle": {
88298835
"color": "#99AA99"
88308836
}
8837+
},
8838+
"words": {
8839+
"selectedStroke": "#1A1A1A"
88318840
}
88328841
}
88338842
},
@@ -8852,6 +8861,9 @@
88528861
"subtitle": {
88538862
"color": "#99AA99"
88548863
}
8864+
},
8865+
"words": {
8866+
"selectedStroke": "#fbfafa"
88558867
}
88568868
}
88578869
},
@@ -8876,6 +8888,9 @@
88768888
"subtitle": {
88778889
"color": "#718890"
88788890
}
8891+
},
8892+
"words": {
8893+
"selectedStroke": "#f6f6fb"
88798894
}
88808895
}
88818896
},

src/useConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,9 @@ export function useConfig() {
43984398
proximity: 10,
43994399
packingWeight: 1,
44004400
color: COLOR_BLACK,
4401-
usePalette: true
4401+
usePalette: true,
4402+
hoverOpacity: 0.5,
4403+
selectedStroke: 'transparent'
44024404
},
44034405
title: TITLE,
44044406
tooltip: {

types/vue-data-ui.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6935,6 +6935,8 @@ declare module "vue-data-ui" {
69356935
packingWeight?: number;
69366936
color?: string;
69376937
usePalette?: boolean;
6938+
hoverOpacity?: number;
6939+
selectedStroke?: string;
69386940
};
69396941
title?: ChartTitle;
69406942
tooltip?: ChartTooltip & {

0 commit comments

Comments
 (0)