From 7f9333c3080422635ced6fc61ecb0c5df2c7359d Mon Sep 17 00:00:00 2001 From: Cerberuser Date: Fri, 29 Jun 2018 14:39:23 +0700 Subject: [PATCH] Cytoscape: export image to Blob --- types/cytoscape/cytoscape-tests.ts | 27 +++++++++++++++++++++++++-- types/cytoscape/index.d.ts | 29 ++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/types/cytoscape/cytoscape-tests.ts b/types/cytoscape/cytoscape-tests.ts index 10a38145de..5db427e9e1 100644 --- a/types/cytoscape/cytoscape-tests.ts +++ b/types/cytoscape/cytoscape-tests.ts @@ -343,17 +343,29 @@ const positions = oneOf({a: {x: 100, y: 100}}, (node: cytoscape.NodeCollection): // TODO: cy.style +// $ExpectType String cy.png({ - output: oneOf('base64uri', 'base64', 'blob', undefined), + output: oneOf('base64uri', 'base64', undefined), bg: oneOf('#ffffff', undefined), full: true, scale: 2, maxWidth: 100, maxHeight: 100 }); +// $ExpectType Blob +cy.png({ + output: 'blob', + bg: oneOf('#ffffff', undefined), + full: true, + scale: 2, + maxWidth: 100, + maxHeight: 100 +}); + aliases(cy.jpg, cy.jpeg); +// $ExpectType String cy.jpg({ - output: oneOf('base64uri', 'base64', 'blob', undefined), + output: oneOf('base64uri', 'base64', undefined), bg: oneOf('#ffffff', undefined), full: true, scale: 2, @@ -361,6 +373,17 @@ cy.jpg({ maxHeight: 100, quality: 0.5 }); +// $ExpectType Blob +cy.jpg({ + output: 'blob', + bg: oneOf('#ffffff', undefined), + full: true, + scale: 2, + maxWidth: 100, + maxHeight: 100, + quality: 0.5 +}); + cy.json(cy.json()); // Types possible to call methods diff --git a/types/cytoscape/index.d.ts b/types/cytoscape/index.d.ts index 1fcdcb0f08..282a90c7a4 100644 --- a/types/cytoscape/index.d.ts +++ b/types/cytoscape/index.d.ts @@ -1052,10 +1052,6 @@ declare namespace cytoscape { * http://js.cytoscape.org/#core/export */ interface ExportOptions { - /** - * output Whether the output should be 'base64uri' (default), 'base64', or 'blob'. - */ - output?: "base64uri" | "base64" | "blob"; /** * The background colour of the image (transparent by default). */ @@ -1077,6 +1073,18 @@ declare namespace cytoscape { */ maxHeight?: number; } + interface ExportStringOptions extends ExportOptions { + /** + * output Whether the output should be 'base64uri' (default), 'base64', or 'blob'. + */ + output?: "base64uri" | "base64"; + } + interface ExportBlobOptions extends ExportOptions { + /** + * output Whether the output should be 'base64uri' (default), 'base64', or 'blob'. + */ + output?: "blob"; + } interface ExportJpgOptions extends ExportOptions { /** @@ -1086,22 +1094,29 @@ declare namespace cytoscape { */ quality?: number; } + interface ExportJpgStringOptions extends ExportJpgOptions, ExportStringOptions { + } + interface ExportJpgBlobOptions extends ExportJpgOptions, ExportBlobOptions { + } interface CoreExport { /** * Export the current graph view as a PNG image in Base64 representation. */ - png(options?: ExportOptions): string; + png(options?: ExportStringOptions): string; + png(options?: ExportBlobOptions): Blob; /** * Export the current graph view as a JPG image in Base64 representation. */ - jpg(options?: ExportJpgOptions): string; + jpg(options?: ExportJpgStringOptions): string; + jpg(options?: ExportJpgBlobOptions): Blob; /** * Export the current graph view as a JPG image in Base64 representation. */ - jpeg(options?: ExportJpgOptions): string; + jpeg(options?: ExportJpgStringOptions): string; + jpeg(options?: ExportJpgBlobOptions): Blob; /** * Export the graph as JSON, the same format used at initialisation.