Merge pull request #1220 from nasa/hasta-la-vista-jspdf

[export] remove pdf export
This commit is contained in:
Victor Woeltjen 2016-09-30 17:01:23 -07:00 committed by GitHub
commit 5b0fa90e39
9 changed files with 4 additions and 77 deletions

View File

@ -19,7 +19,6 @@
"comma-separated-values": "^3.6.4", "comma-separated-values": "^3.6.4",
"FileSaver.js": "^0.0.2", "FileSaver.js": "^0.0.2",
"zepto": "^1.1.6", "zepto": "^1.1.6",
"html2canvas": "^0.4.1", "html2canvas": "^0.4.1"
"jspdf": "1.2.x"
} }
} }

View File

@ -29,7 +29,6 @@ requirejs.config({
"csv": "bower_components/comma-separated-values/csv.min", "csv": "bower_components/comma-separated-values/csv.min",
"es6-promise": "bower_components/es6-promise/es6-promise.min", "es6-promise": "bower_components/es6-promise/es6-promise.min",
"html2canvas": "bower_components/html2canvas/build/html2canvas.min", "html2canvas": "bower_components/html2canvas/build/html2canvas.min",
"jsPDF": "bower_components/jspdf/dist/jspdf.debug",
"moment": "bower_components/moment/moment", "moment": "bower_components/moment/moment",
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format", "moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
"saveAs": "bower_components/FileSaver.js/FileSaver.min", "saveAs": "bower_components/FileSaver.js/FileSaver.min",
@ -48,9 +47,6 @@ requirejs.config({
"html2canvas": { "html2canvas": {
"exports": "html2canvas" "exports": "html2canvas"
}, },
"jsPDF": {
"exports": "jsPDF"
},
"moment-duration-format": { "moment-duration-format": {
"deps": ["moment"] "deps": ["moment"]
}, },

View File

@ -146,16 +146,6 @@ define([
"copyright": "Copyright © 2012 Niklas von Hertzen.", "copyright": "Copyright © 2012 Niklas von Hertzen.",
"license": "license-mit", "license": "license-mit",
"link": "https://github.com/niklasvh/html2canvas/blob/master/LICENSE" "link": "https://github.com/niklasvh/html2canvas/blob/master/LICENSE"
},
{
"name": "jsPDF",
"version": "1.2.61",
"author": "James Hall",
"description": "JavaScript HTML renderer",
"website": "https://github.com/MrRio/jsPDF",
"copyright": "Copyright © 2010-2016 James Hall",
"license": "license-mit",
"link": "https://github.com/MrRio/jsPDF/blob/master/MIT-LICENSE.txt"
} }
] ]
} }

View File

@ -23,11 +23,6 @@
class="abs holder holder-plot has-control-bar"> class="abs holder holder-plot has-control-bar">
<div class="l-control-bar" ng-show="!plot.hideExportButtons"> <div class="l-control-bar" ng-show="!plot.hideExportButtons">
<span class="l-btn-set"> <span class="l-btn-set">
<a class="s-button t-export icon-download labeled first"
ng-click="plot.exportPDF()"
title="Export This View's Data as PDF">
PDF
</a>
<a class="s-button t-export labeled" <a class="s-button t-export labeled"
ng-click="plot.exportPNG()" ng-click="plot.exportPNG()"
title="Export This View's Data as PNG"> title="Export This View's Data as PNG">

View File

@ -368,17 +368,6 @@ define(
return this.pending; return this.pending;
}; };
/**
* Export the plot to PDF
*/
PlotController.prototype.exportPDF = function () {
var self = this;
self.hideExportButtons = true;
self.exportImageService.exportPDF(self.$element[0], "plot.pdf").finally(function () {
self.hideExportButtons = false;
});
};
/** /**
* Export the plot to PNG * Export the plot to PNG
*/ */

View File

@ -26,32 +26,29 @@
define( define(
[ [
"html2canvas", "html2canvas",
"jsPDF",
"saveAs" "saveAs"
], ],
function ( function (
html2canvas, html2canvas,
jsPDF,
saveAs saveAs
) { ) {
var self = this; var self = this;
/** /**
* The export image service will export any HTML node to * The export image service will export any HTML node to
* PDF, JPG, or PNG. * JPG, or PNG.
* @param {object} $q * @param {object} $q
* @param {object} $timeout * @param {object} $timeout
* @param {object} $log * @param {object} $log
* @param {constant} EXPORT_IMAGE_TIMEOUT time in milliseconds before a timeout error is returned * @param {constant} EXPORT_IMAGE_TIMEOUT time in milliseconds before a timeout error is returned
* @constructor * @constructor
*/ */
function ExportImageService($q, $timeout, $log, EXPORT_IMAGE_TIMEOUT, injHtml2Canvas, injJsPDF, injSaveAs, injFileReader) { function ExportImageService($q, $timeout, $log, EXPORT_IMAGE_TIMEOUT, injHtml2Canvas, injSaveAs, injFileReader) {
self.$q = $q; self.$q = $q;
self.$timeout = $timeout; self.$timeout = $timeout;
self.$log = $log; self.$log = $log;
self.EXPORT_IMAGE_TIMEOUT = EXPORT_IMAGE_TIMEOUT; self.EXPORT_IMAGE_TIMEOUT = EXPORT_IMAGE_TIMEOUT;
self.html2canvas = injHtml2Canvas || html2canvas; self.html2canvas = injHtml2Canvas || html2canvas;
self.jsPDF = injJsPDF || jsPDF;
self.saveAs = injSaveAs || saveAs; self.saveAs = injSaveAs || saveAs;
self.reader = injFileReader || new FileReader(); self.reader = injFileReader || new FileReader();
} }
@ -128,23 +125,6 @@ define(
} }
} }
/**
* Takes a screenshot of a DOM node and exports to PDF.
* @param {node} element to be exported
* @param {string} filename the exported image
* @returns {promise}
*/
ExportImageService.prototype.exportPDF = function (element, filename) {
return renderElement(element, "jpeg").then(function (img) {
self.reader.readAsDataURL(img);
self.reader.onloadend = function () {
var pdf = new self.jsPDF("l", "px", [element.offsetHeight, element.offsetWidth]);
pdf.addImage(self.reader.result, "JPEG", 0, 0, element.offsetWidth, element.offsetHeight);
pdf.save(filename);
};
});
};
/** /**
* Takes a screenshot of a DOM node and exports to JPG. * Takes a screenshot of a DOM node and exports to JPG.
* @param {node} element to be exported * @param {node} element to be exported

View File

@ -72,7 +72,7 @@ define(
mockElement = angular.element('<div />'); mockElement = angular.element('<div />');
mockExportImageService = jasmine.createSpyObj( mockExportImageService = jasmine.createSpyObj(
"ExportImageService", "ExportImageService",
["exportJPG", "exportPNG", "exportPDF"] ["exportJPG", "exportPNG"]
); );
mockFormatter = jasmine.createSpyObj( mockFormatter = jasmine.createSpyObj(
"formatter", "formatter",

View File

@ -33,8 +33,6 @@ define(
mockLog, mockLog,
mockHtml2Canvas, mockHtml2Canvas,
mockCanvas, mockCanvas,
mockJsPDF,
mockJsPDFSave,
mockSaveAs, mockSaveAs,
mockFileReader, mockFileReader,
mockExportTimeoutConstant, mockExportTimeoutConstant,
@ -79,13 +77,6 @@ define(
"canvas", "canvas",
["toBlob"] ["toBlob"]
); );
mockJsPDFSave = jasmine.createSpy("jsPDFSave");
mockJsPDF = function () {
return {
"addImage": function () {},
"save": mockJsPDFSave
};
};
mockSaveAs = jasmine.createSpy("saveAs"); mockSaveAs = jasmine.createSpy("saveAs");
mockFileReader = jasmine.createSpyObj( mockFileReader = jasmine.createSpyObj(
"FileReader", "FileReader",
@ -100,23 +91,11 @@ define(
mockLog, mockLog,
mockExportTimeoutConstant, mockExportTimeoutConstant,
mockHtml2Canvas, mockHtml2Canvas,
mockJsPDF,
mockSaveAs, mockSaveAs,
mockFileReader mockFileReader
); );
}); });
it("runs html2canvas and tries to save a pdf", function () {
exportImageService.exportPDF(testElement, "plot.pdf");
mockFileReader.onloadend();
expect(mockHtml2Canvas).toHaveBeenCalledWith(testElement, { onrendered: jasmine.any(Function) });
expect(mockCanvas.toBlob).toHaveBeenCalledWith(mockDeferred.resolve, "image/jpeg");
expect(mockDeferred.reject).not.toHaveBeenCalled();
expect(mockJsPDFSave).toHaveBeenCalled();
expect(mockPromise.finally).toHaveBeenCalled();
});
it("runs html2canvas and tries to save a png", function () { it("runs html2canvas and tries to save a png", function () {
exportImageService.exportPNG(testElement, "plot.png"); exportImageService.exportPNG(testElement, "plot.png");

View File

@ -55,7 +55,6 @@ requirejs.config({
"csv": "bower_components/comma-separated-values/csv.min", "csv": "bower_components/comma-separated-values/csv.min",
"es6-promise": "bower_components/es6-promise/es6-promise.min", "es6-promise": "bower_components/es6-promise/es6-promise.min",
"html2canvas": "bower_components/html2canvas/build/html2canvas.min", "html2canvas": "bower_components/html2canvas/build/html2canvas.min",
"jsPDF": "bower_components/jspdf/dist/jspdf.debug",
"moment": "bower_components/moment/moment", "moment": "bower_components/moment/moment",
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format", "moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
"saveAs": "bower_components/FileSaver.js/FileSaver.min", "saveAs": "bower_components/FileSaver.js/FileSaver.min",