JSFiddle - React, Tailwind, and code Playground

by rpaul

JavaScript

/* Flot plugin to save the graph as PDF
 */

(function ($) {
    function saveAsPDF(graphContainerID, legendContainerID) {
        html2canvas($(graphContainerID).get(0), {
            onrendered: function(canvas) {
                var legendRenderDeferred = jQuery.Deferred();
                var doc = new jsPDF('l', 'mm', [
                    445, 310
                ]);
                addHeaderToPDF(doc, 150, 10);
                addBodyToPDF(doc, canvas, 10, 20, legendRenderDeferred, legendContainerID);
                addFooterToPDF(doc, 330, 220);
                $.when( legendRenderDeferred.promise() ).then(
                    function( status ) {
                        doc.save('graph.pdf');
                    },
                    function( status ) {
                        alert( status + "pdf generation failed" );
                    },
                    function( status ) {
                    }
                );
            }
        });
    };
    function addHeaderToPDF(doc, x, y) {
        doc.setFontSize(20);
        doc.setTextColor(0, 87, 184);
        var header = InnotechController.Constants.getSiteName() + ' - ' + InnotechController.Constants.getControllerName();
        doc.text(header,  x, y);
    }
    function addBodyToPDF(doc, canvas, x, y, dfd, legendContainerID) {
        var imgData = canvas.toDataURL('image/png');
        doc.addImage(imgData, 'PNG', x, y);
        var elem = $(legendContainerID).get(0);
        $(legendContainerID).show();
        debugger;
        html2canvas(elem, {
            onrendered: function(canvas1) {
                debugger;
                var imgData1 = canvas1.toDataURL('image/png');
                doc.addImage(imgData1, 'PNG', 10, 220);
                $(legendContainerID).hide();
                dfd.resolve( "legend rendering is done" );
            }
        });
    }
    function addFooterToPDF(doc, x, y) {
        doc.setFontSize(12);
        doc.setTextColor(0, 0, 0);
        var...