Skip to content

Commit b606906

Browse files
committed
Improvement - VueUiXy - Dynamic import of pdf deps
1 parent 0fcea8b commit b606906

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/components/vue-ui-xy.vue

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,6 @@
11521152
</template>
11531153

11541154
<script>
1155-
import pdf from '../pdf';
1156-
import img from "../img";
11571155
import {
11581156
abbreviate,
11591157
adaptColorToBackground,
@@ -2218,11 +2216,9 @@ export default {
22182216
error,
22192217
functionReturnsString,
22202218
hasDeepProperty,
2221-
img,
22222219
isFunction,
22232220
isSafeValue,
22242221
objectIsEmpty,
2225-
pdf,
22262222
setOpacity,
22272223
shiftHue,
22282224
translateSize,
@@ -2615,17 +2611,24 @@ export default {
26152611
showSpinnerPdf() {
26162612
this.isPrinting = true;
26172613
},
2618-
generatePdf(){
2614+
async generatePdf() {
26192615
this.showSpinnerPdf();
26202616
clearTimeout(this.__to__);
2621-
this.__to__ = setTimeout(() => {
2622-
this.pdf({
2617+
this.isPrinting = true; // Set isPrinting to true before starting
2618+
2619+
this.__to__ = setTimeout(async () => {
2620+
try {
2621+
const { default: pdf } = await import('../pdf.js');
2622+
await pdf({
26232623
domElement: document.getElementById(`vue-ui-xy_${this.uniqueId}`),
2624-
fileName: this.FINAL_CONFIG.chart.title.text || 'vue-ui-xy'
2625-
}).finally(() => {
2626-
this.isPrinting = false;
2624+
fileName: this.FINAL_CONFIG.chart.title.text || 'vue-ui-xy',
26272625
});
2628-
}, 100)
2626+
} catch (error) {
2627+
console.error('Error generating PDF:', error);
2628+
} finally {
2629+
this.isPrinting = false;
2630+
}
2631+
}, 100);
26292632
},
26302633
generateCsv() {
26312634
const title = [[this.FINAL_CONFIG.chart.title.text], [this.FINAL_CONFIG.chart.title.subtitle.text], [""]];
@@ -2638,19 +2641,25 @@ export default {
26382641
showSpinnerImage() {
26392642
this.isImaging = true;
26402643
},
2641-
generateImage() {
2644+
async generateImage() {
26422645
this.showSpinnerImage();
26432646
clearTimeout(this.__to__);
2644-
this.__to__ = setTimeout(() => {
2645-
this.img({
2647+
this.isImaging = true;
2648+
this.__to__ = setTimeout(async () => {
2649+
try {
2650+
const { default: img } = await import('../img.js');
2651+
await img({
26462652
domElement: document.getElementById(`vue-ui-xy_${this.uniqueId}`),
26472653
fileName: this.FINAL_CONFIG.chart.title.text || 'vue-ui-xy',
2648-
format: 'png'
2649-
}).finally(() => {
2654+
format: 'png',
2655+
});
2656+
} catch (error) {
2657+
console.error('Error generating image:', error);
2658+
} finally {
26502659
this.isImaging = false;
2651-
});
2652-
}, 100)
2653-
}
2660+
}
2661+
}, 100);
2662+
},
26542663
}
26552664
}
26562665
</script>

0 commit comments

Comments
 (0)