Skip to content

Commit 3eeeed6

Browse files
committed
New feature - VueUiWordCloud - Add optional zoom feature
1 parent 9bf0fd0 commit 3eeeed6

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

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

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import themes from "../themes.json";
44
import Title from '../atoms/Title.vue';
55
import UserOptions from '../atoms/UserOptions.vue';
66
import { createUid, createWordCloudDatasetFromPlainText } from '../lib';
7+
import { debounce } from '../canvas-lib';
78
import {
89
downloadCsv,
910
error,
@@ -18,6 +19,7 @@ import {
1819
import { throttle } from '../canvas-lib';
1920
import Accordion from "./vue-ui-accordion.vue";
2021
import DataTable from '../atoms/DataTable.vue';
22+
import MonoSlicer from '../atoms/MonoSlicer.vue';
2123
import { useNestedProp } from '../useNestedProp';
2224
import { usePrinter } from '../usePrinter';
2325
import { useResponsive } from '../useResponsive';
@@ -74,12 +76,40 @@ const FINAL_CONFIG = computed(() => {
7476
}
7577
});
7678
79+
const chartSlicer = ref(null);
80+
const slicer = ref(FINAL_CONFIG.value.style.chart.width);
81+
7782
const svg = ref({
78-
width: FINAL_CONFIG.value.style.chart.width,
79-
height: FINAL_CONFIG.value.style.chart.height,
83+
width: slicer.value,
84+
height: FINAL_CONFIG.value.style.chart.height / FINAL_CONFIG.value.style.chart.height * slicer.value,
8085
maxFontSize: FINAL_CONFIG.value.style.chart.words.maxFontSize,
8186
minFontSize: FINAL_CONFIG.value.style.chart.words.minFontSize
82-
})
87+
});
88+
89+
const handleResize = throttle(() => {
90+
const { width, height } = useResponsive({
91+
chart: wordCloudChart.value,
92+
title: FINAL_CONFIG.value.style.chart.title.text ? chartTitle.value : null,
93+
slicer: FINAL_CONFIG.value.style.chart.zoom.show && chartSlicer.value
94+
});
95+
svg.value.width = width;
96+
svg.value.height = height;
97+
nextTick(generateWordCloud)
98+
});
99+
100+
watch(() => slicer.value, () => {
101+
debounceUpdateCloud()
102+
});
103+
104+
const debounceUpdateCloud = debounce(() => {
105+
svg.value.width = Number(slicer.value)
106+
svg.value.height = FINAL_CONFIG.value.style.chart.height / FINAL_CONFIG.value.style.chart.height * Number(slicer.value)
107+
generateWordCloud()
108+
}, 10);
109+
110+
function refreshSlicer() {
111+
slicer.value = FINAL_CONFIG.value.style.chart.width;
112+
}
83113
84114
const resizeObserver = ref(null);
85115
@@ -88,7 +118,7 @@ onMounted(() => {
88118
error({
89119
componentName: 'VueUiWordCloud',
90120
type: 'dataset'
91-
})
121+
});
92122
} else {
93123
drawableDataset.value.forEach((w, i) => {
94124
getMissingDatasetAttributes({
@@ -101,21 +131,11 @@ onMounted(() => {
101131
type: 'datasetSerieAttribute',
102132
property: attr,
103133
index: i
104-
})
105-
})
106-
})
107-
}
108-
if (FINAL_CONFIG.value.responsive) {
109-
const handleResize = throttle(() => {
110-
const { width, height } = useResponsive({
111-
chart: wordCloudChart.value,
112-
title: FINAL_CONFIG.value.style.chart.title.text ? chartTitle.value : null,
134+
});
113135
});
114-
svg.value.width = width;
115-
svg.value.height = height;
116-
nextTick(generateWordCloud)
117136
});
118-
137+
}
138+
if (FINAL_CONFIG.value.responsive) {
119139
resizeObserver.value = new ResizeObserver(handleResize);
120140
resizeObserver.value.observe(wordCloudChart.value.parentNode);
121141
}
@@ -311,6 +331,7 @@ defineExpose({
311331
<template>
312332
<div class="vue-ui-word-cloud" ref="wordCloudChart" :id="`wordCloud_${uid}`"
313333
:style="`width: 100%; font-family:${FINAL_CONFIG.style.fontFamily};background:${FINAL_CONFIG.style.chart.backgroundColor};${FINAL_CONFIG.responsive ? 'height:100%' : ''}`">
334+
314335
<div ref="chartTitle" v-if="FINAL_CONFIG.style.chart.title.text" :style="`width:100%;background:${FINAL_CONFIG.style.chart.backgroundColor};padding-bottom:24px`">
315336
<Title :config="{
316337
title: {
@@ -389,6 +410,27 @@ defineExpose({
389410
<slot name="watermark" v-bind="{ isPrinting: isPrinting || isImaging }"/>
390411
</div>
391412

413+
<div ref="chartSlicer" :style="`width:100%;background:${FINAL_CONFIG.style.chart.backgroundColor}`" data-html2canvas-ignore>
414+
<MonoSlicer
415+
v-if="FINAL_CONFIG.style.chart.zoom.show"
416+
v-model:value="slicer"
417+
:min="100"
418+
:max="FINAL_CONFIG.style.chart.width * 3"
419+
:textColor="FINAL_CONFIG.style.chart.color"
420+
:inputColor="FINAL_CONFIG.style.chart.zoom.color"
421+
:selectColor="FINAL_CONFIG.style.chart.zoom.highlightColor"
422+
:useResetSlot="FINAL_CONFIG.style.chart.zoom.useResetSlot"
423+
:background="FINAL_CONFIG.style.chart.zoom.color"
424+
:borderColor="FINAL_CONFIG.style.chart.backgroundColor"
425+
:source="FINAL_CONFIG.style.chart.width"
426+
@reset="refreshSlicer"
427+
>
428+
<template #reset-action="{ reset }">
429+
<slot name="reset-action" v-bind="{ reset }"/>
430+
</template>
431+
</MonoSlicer>
432+
</div>
433+
392434
<Accordion hideDetails v-if="isDataset" :config="{
393435
open: mutableConfig.showTable,
394436
maxHeight: 10000,

0 commit comments

Comments
 (0)