Skip to content

Commit ba4aa44

Browse files
committed
Fix - VueUiWordCloud - Fix NaN font size when all datapoints all have the same value
1 parent 9d128be commit ba4aa44

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { ref, watch, computed, nextTick, onMounted, onBeforeUnmount } from 'vue';
2+
import { ref, watch, computed, nextTick, onMounted, onBeforeUnmount, onBeforeMount } from 'vue';
33
import themes from "../themes.json";
44
import Title from '../atoms/Title.vue';
55
import UserOptions from '../atoms/UserOptions.vue';
@@ -53,9 +53,9 @@ const isDataset = computed({
5353
set(bool) {
5454
return bool
5555
}
56-
})
56+
});
5757
58-
const drawableDataset = ref(typeof props.dataset === 'string' ? createWordCloudDatasetFromPlainText(props.dataset) : props.dataset.map(dp => {
58+
const drawableDataset = ref(typeof props.dataset === 'string' ? createWordCloudDatasetFromPlainText(props.dataset) : props.dataset.map((dp, i) => {
5959
return {
6060
...dp,
6161
value: checkNaN(dp.value)
@@ -253,10 +253,10 @@ const positionedWords = ref([]);
253253
watch(() => props.dataset, generateWordCloud, { immediate: true });
254254
255255
const wordMin = computed(() => {
256-
return Math.min(...drawableDataset.value.map(w => w.value))
256+
return Math.round(Math.min(...drawableDataset.value.map(w => w.value)));
257257
})
258258
const wordMax = computed(() => {
259-
return Math.max(...drawableDataset.value.map(w => w.value))
259+
return Math.round(Math.max(...drawableDataset.value.map(w => w.value)));
260260
})
261261
262262
function generateWordCloud() {
@@ -265,7 +265,8 @@ function generateWordCloud() {
265265
const minValue = Math.min(...values);
266266
267267
const scaledWords = [...drawableDataset.value].filter(w => w.value >= slicer.value).map((word, i) => {
268-
const fontSize = ((word.value - minValue) / (maxValue - minValue)) * (svg.value.maxFontSize - svg.value.minFontSize) + svg.value.minFontSize;
268+
let fontSize = ((word.value - minValue) / (maxValue - minValue)) * (svg.value.maxFontSize - svg.value.minFontSize) + svg.value.minFontSize;
269+
fontSize = isNaN(fontSize) ? svg.value.minFontSize : fontSize;
269270
const size = measureTextSize(word.name, fontSize);
270271
return {
271272
...word,
@@ -570,7 +571,7 @@ function useTooltip(word) {
570571

571572
<div ref="chartSlicer" :style="`width:100%;background:transparent`" data-html2canvas-ignore>
572573
<MonoSlicer
573-
v-if="FINAL_CONFIG.style.chart.zoom.show"
574+
v-if="FINAL_CONFIG.style.chart.zoom.show && wordMin < wordMax"
574575
v-model:value="slicer"
575576
:min="wordMin"
576577
:max="wordMax"

0 commit comments

Comments
 (0)