lazy load jspdf to speed up page load

This commit is contained in:
Przemek Wiech
2020-04-29 22:29:25 +02:00
parent a12515008e
commit 68b9f4baa5

View File

@@ -1,5 +1,4 @@
import * as React from 'react'; import * as React from 'react';
import jsPDF from 'jspdf';
import {event, select, Selection} from 'd3-selection'; import {event, select, Selection} from 'd3-selection';
import {interpolateNumber} from 'd3-interpolate'; import {interpolateNumber} from 'd3-interpolate';
import {intlShape} from 'react-intl'; import {intlShape} from 'react-intl';
@@ -395,8 +394,10 @@ export class Chart extends React.PureComponent<ChartProps, {}> {
} }
async downloadPdf() { async downloadPdf() {
// Lazy load jspdf.
const {default: jspdf} = await import('jspdf');
const canvas = await this.drawOnCanvas(); const canvas = await this.drawOnCanvas();
const doc = new jsPDF({ const doc = new jspdf({
orientation: canvas.width > canvas.height ? 'l' : 'p', orientation: canvas.width > canvas.height ? 'l' : 'p',
unit: 'pt', unit: 'pt',
format: [canvas.width, canvas.height], format: [canvas.width, canvas.height],