[Code Review] Updates based on code review by @VWoeltjen

Set export functions on the ExportImageService prototype. Insantiated
ExportImageService in the PlotController for better dependcy injection.
This commit is contained in:
David Hudson 2016-09-02 11:54:38 +09:00
parent 3a19890be9
commit e370271093
3 changed files with 13 additions and 24 deletions

View File

@ -22,17 +22,17 @@
<span ng-controller="PlotController as plot" <span ng-controller="PlotController as plot"
class="abs holder holder-plot"> class="abs holder holder-plot">
<a class="s-button t-export icon-download labeled" <a class="s-button t-export icon-download labeled"
ng-click="exportPDF()" ng-click="plot.exportPDF()"
title="Export This View's Data"> title="Export This View's Data">
Export as PDF Export as PDF
</a> </a>
<a class="s-button t-export icon-download labeled" <a class="s-button t-export icon-download labeled"
ng-click="exportPNG()" ng-click="plot.exportPNG()"
title="Export This View's Data"> title="Export This View's Data">
Export as PNG Export as PNG
</a> </a>
<a class="s-button t-export icon-download labeled" <a class="s-button t-export icon-download labeled"
ng-click="exportJPG()" ng-click="plot.exportJPG()"
title="Export This View's Data"> title="Export This View's Data">
Export as JPG Export as JPG
</a> </a>

View File

@ -250,6 +250,7 @@ define(
self.pending = true; self.pending = true;
self.$element = $element; self.$element = $element;
self.ExportImageService = new ExportImageService();
// Initialize axes; will get repopulated when telemetry // Initialize axes; will get repopulated when telemetry
// metadata becomes available. // metadata becomes available.
@ -258,18 +259,6 @@ define(
new PlotAxis("ranges", [], AXIS_DEFAULTS[1]) new PlotAxis("ranges", [], AXIS_DEFAULTS[1])
]; ];
$scope.exportPDF = function () {
PlotController.prototype.exportPDF(self.$element, 'plot.pdf');
};
$scope.exportPNG = function () {
PlotController.prototype.exportPNG(self.$element, 'plot.png');
};
$scope.exportJPG = function () {
PlotController.prototype.exportJPG(self.$element, 'plot.jpg');
};
// Watch for changes to the selected axis // Watch for changes to the selected axis
$scope.$watch("axes[0].active.key", domainRequery); $scope.$watch("axes[0].active.key", domainRequery);
$scope.$watch("axes[1].active.key", rangeRequery); $scope.$watch("axes[1].active.key", rangeRequery);
@ -383,22 +372,22 @@ define(
/** /**
* Export the plot to PDF * Export the plot to PDF
*/ */
PlotController.prototype.exportPDF = function (element, filename) { PlotController.prototype.exportPDF = function () {
ExportImageService.exportPDF(element[0], filename); this.ExportImageService.exportPDF(this.$element[0], 'plot.pdf');
}; };
/** /**
* Export the plot to PNG * Export the plot to PNG
*/ */
PlotController.prototype.exportPNG = function (element, filename) { PlotController.prototype.exportPNG = function () {
ExportImageService.exportPNG(element, filename); this.ExportImageService.exportPNG(this.$element[0], 'plot.png');
}; };
/** /**
* Export the plot to JPG * Export the plot to JPG
*/ */
PlotController.prototype.exportJPG = function (element, filename) { PlotController.prototype.exportJPG = function () {
ExportImageService.exportJPG(element, filename); this.ExportImageService.exportJPG(this.$element[0], 'plot.jpg');
}; };
return PlotController; return PlotController;

View File

@ -71,7 +71,7 @@ define(
}); });
} }
ExportImageService.exportPDF = function (element, filename) { ExportImageService.prototype.exportPDF = function (element, filename) {
renderElement(element, function (img) { renderElement(element, function (img) {
var pdf = new jsPDF('l', 'px', [element.offsetHeight, element.offsetWidth]); var pdf = new jsPDF('l', 'px', [element.offsetHeight, element.offsetWidth]);
pdf.addImage(img, 'JPEG', 0, 0, element.offsetWidth, element.offsetHeight); pdf.addImage(img, 'JPEG', 0, 0, element.offsetWidth, element.offsetHeight);
@ -79,13 +79,13 @@ define(
}, 'jpeg'); }, 'jpeg');
}; };
ExportImageService.exportJPG = function (element, filename) { ExportImageService.prototype.exportJPG = function (element, filename) {
renderElement(element, function (img) { renderElement(element, function (img) {
saveAs(img, filename); saveAs(img, filename);
}, "blob"); }, "blob");
}; };
ExportImageService.exportPNG = function (element, filename) { ExportImageService.prototype.exportPNG = function (element, filename) {
renderElement(element, function (img) { renderElement(element, function (img) {
saveAs(img, filename); saveAs(img, filename);
}, "blob"); }, "blob");