Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.3.0 #8

Merged
merged 13 commits into from
Nov 11, 2022
Prev Previous commit
Next Next commit
feat: fallback on default export if no layers
  • Loading branch information
sgratzl committed Nov 11, 2022
commit edb68bceb9f2a677f5c7c3c040e902e3830924d9
14 changes: 14 additions & 0 deletions src/LayersPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ISVGLayerOptions,
ICanvasLayerOptions,
IPoint,
CytoscapeBaseLayer,
} from './layers';
import type { ILayerAdapter } from './layers/ABaseLayer';
import { renderPerEdge, renderPerNode } from './elements';
Expand Down Expand Up @@ -311,6 +312,10 @@ export default class LayersPlugin {
return layers[0] ?? null;
}

private hasCustomLayer(): boolean {
return this.layers.some((d) => !(d instanceof CytoscapeBaseLayer));
}

private toCanvas(
options: (cy.ExportJpgStringOptions | cy.ExportJpgBlobOptions | cy.ExportJpgBlobPromiseOptions) & LayerExportOptions
): HTMLCanvasElement {
Expand Down Expand Up @@ -393,6 +398,9 @@ export default class LayersPlugin {
png(
options?: (cy.ExportStringOptions | cy.ExportBlobOptions | cy.ExportBlobPromiseOptions) & LayerExportOptions
): any {
if (!this.hasCustomLayer()) {
return this.bak.png.call(this.cy, options);
}
return output(options ?? {}, this.toCanvas(options ?? {}), 'image/png');
}

Expand All @@ -407,6 +415,9 @@ export default class LayersPlugin {
options?: (cy.ExportJpgStringOptions | cy.ExportJpgBlobOptions | cy.ExportJpgBlobPromiseOptions) &
LayerExportOptions
): any {
if (!this.hasCustomLayer()) {
return this.bak.jpg.call(this.cy, options);
}
const o = {
bg: '#fff',
...(options ?? {}),
Expand All @@ -422,6 +433,9 @@ export default class LayersPlugin {
jpeg(options?: cy.ExportJpgBlobPromiseOptions): Promise<Blob>;

jpeg(options?: cy.ExportJpgStringOptions | cy.ExportJpgBlobOptions | cy.ExportJpgBlobPromiseOptions): any {
if (!this.hasCustomLayer()) {
return this.bak.jpeg.call(this.cy, options);
}
return this.jpg(options as unknown as any);
}

Expand Down