mirror of
https://github.com/nasa/openmct.git
synced 2025-04-09 20:31:26 +00:00
add parameter for background color, only change color when parameter is passed in (export image service is used in notebook which needs the background color not changed
added tests
This commit is contained in:
parent
5d3adc6a7f
commit
3669e776a9
@ -415,7 +415,7 @@ define(
|
||||
PlotController.prototype.exportPNG = function () {
|
||||
var self = this;
|
||||
self.hideExportButtons = true;
|
||||
self.exportImageService.exportPNG(self.$element[0], "plot.png").finally(function () {
|
||||
self.exportImageService.exportPNG(self.$element[0], "plot.png", 'white').finally(function () {
|
||||
self.hideExportButtons = false;
|
||||
});
|
||||
};
|
||||
@ -426,7 +426,7 @@ define(
|
||||
PlotController.prototype.exportJPG = function () {
|
||||
var self = this;
|
||||
self.hideExportButtons = true;
|
||||
self.exportImageService.exportJPG(self.$element[0], "plot.jpg").finally(function () {
|
||||
self.exportImageService.exportJPG(self.$element[0], "plot.jpg", 'white').finally(function () {
|
||||
self.hideExportButtons = false;
|
||||
});
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ define(
|
||||
* @param {string} type of image to convert the element to
|
||||
* @returns {promise}
|
||||
*/
|
||||
function renderElement(element, type) {
|
||||
function renderElement(element, type, color) {
|
||||
var defer = self.$q.defer(),
|
||||
validTypes = ["png", "jpg", "jpeg"],
|
||||
renderTimeout,
|
||||
@ -72,11 +72,13 @@ define(
|
||||
return;
|
||||
}
|
||||
|
||||
// Save color to be restored later
|
||||
originalColor = element.style.backgroundColor || '';
|
||||
if (color) {
|
||||
// Save color to be restored later
|
||||
originalColor = element.style.backgroundColor || '';
|
||||
|
||||
// Defaulting to white so we can see the chart when printed
|
||||
self.changeBackgroundColor(element, 'white');
|
||||
// Defaulting to white so we can see the chart when printed
|
||||
self.changeBackgroundColor(element, color);
|
||||
}
|
||||
|
||||
renderTimeout = self.$timeout(function () {
|
||||
defer.reject("html2canvas timed out");
|
||||
@ -86,7 +88,9 @@ define(
|
||||
try {
|
||||
self.html2canvas(element, {
|
||||
onrendered: function (canvas) {
|
||||
self.changeBackgroundColor(element, originalColor);
|
||||
if (color) {
|
||||
self.changeBackgroundColor(element, originalColor);
|
||||
}
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case "png":
|
||||
@ -106,7 +110,10 @@ define(
|
||||
|
||||
defer.promise.finally(function () {
|
||||
renderTimeout.cancel();
|
||||
self.changeBackgroundColor(element, originalColor);
|
||||
|
||||
if (color) {
|
||||
self.changeBackgroundColor(element, originalColor);
|
||||
}
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
@ -149,8 +156,8 @@ define(
|
||||
* @param {string} filename the exported image
|
||||
* @returns {promise}
|
||||
*/
|
||||
ExportImageService.prototype.exportJPG = function (element, filename) {
|
||||
return renderElement(element, "jpeg").then(function (img) {
|
||||
ExportImageService.prototype.exportJPG = function (element, filename, color) {
|
||||
return renderElement(element, "jpeg", color).then(function (img) {
|
||||
self.saveAs(img, filename);
|
||||
});
|
||||
};
|
||||
@ -161,8 +168,8 @@ define(
|
||||
* @param {string} filename the exported image
|
||||
* @returns {promise}
|
||||
*/
|
||||
ExportImageService.prototype.exportPNG = function (element, filename) {
|
||||
return renderElement(element, "png").then(function (img) {
|
||||
ExportImageService.prototype.exportPNG = function (element, filename, color) {
|
||||
return renderElement(element, "png", color).then(function (img) {
|
||||
self.saveAs(img, filename);
|
||||
});
|
||||
};
|
||||
|
@ -121,16 +121,26 @@ define(
|
||||
});
|
||||
|
||||
it("changes background color to white and returns color back to original after snapshot, for better visibility of plot lines on print", function () {
|
||||
exportImageService.exportPNG(testElement, "plot.png");
|
||||
exportImageService.exportPNG(testElement, "plot.png", 'white');
|
||||
|
||||
expect(mockChangeBackgroundColor).toHaveBeenCalledWith(testElement, 'white');
|
||||
expect(mockChangeBackgroundColor).toHaveBeenCalledWith(testElement, 'black');
|
||||
|
||||
exportImageService.exportJPG(testElement, "plot.jpg");
|
||||
exportImageService.exportJPG(testElement, "plot.jpg", 'white');
|
||||
|
||||
expect(mockChangeBackgroundColor).toHaveBeenCalledWith(testElement, 'white');
|
||||
expect(mockChangeBackgroundColor).toHaveBeenCalledWith(testElement, 'black');
|
||||
});
|
||||
|
||||
it("does not change background color when color is not specified in parameters", function () {
|
||||
exportImageService.exportPNG(testElement, "plot.png");
|
||||
|
||||
expect(mockChangeBackgroundColor).not.toHaveBeenCalled();
|
||||
|
||||
exportImageService.exportJPG(testElement, "plot.jpg");
|
||||
|
||||
expect(mockChangeBackgroundColor).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user