Skip to content

Commit

Permalink
fix: fix ssr cannot load image (#6648)
Browse files Browse the repository at this point in the history
* fix: fix ssr cannot load image

* chore: update version
  • Loading branch information
Aarebecca authored Dec 18, 2024
1 parent 94b2ac3 commit 7ac448c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
Binary file modified packages/g6-ssr/__tests__/assets/bin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/g6-ssr/__tests__/assets/node-image.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions packages/g6-ssr/__tests__/graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,21 @@ describe('createGraph', () => {

graph.destroy();
});

it('node image', async () => {
const graph = await fn('image', 'jpeg', {
waitForRender: 1000,
node: {
style: {
iconSrc: 'https://gw.alipayobjects.com/zos/antfincdn/FLrTNDvlna/antv.png',
},
},
});

expect(graph).toMatchFile('./assets/node-image.jpeg');

graph.exportToFile(join(__dirname, './assets/node-image'));

graph.destroy();
});
});
2 changes: 1 addition & 1 deletion packages/g6-ssr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g6-ssr",
"version": "0.0.3",
"version": "0.0.4",
"description": "Support SSR for G6",
"keywords": [
"antv",
Expand Down
5 changes: 3 additions & 2 deletions packages/g6-ssr/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Renderer } from '@antv/g-canvas';
import { Canvas as G6Canvas } from '@antv/g6';
import type { Canvas as NodeCanvas } from 'canvas';
import { createCanvas as createNodeCanvas } from 'canvas';
import { createCanvas as createNodeCanvas, Image as NodeImage } from 'canvas';
import type { Options } from './types';

/**
Expand All @@ -12,7 +12,7 @@ import type { Options } from './types';
* @returns <zh/> [G6 画布, NodeCanvas 画布] | <en/> [G6Canvas, NodeCanvas]
*/
export function createCanvas(options: Options): [G6Canvas, NodeCanvas] {
const { width, height, background, outputType, devicePixelRatio = 2 } = options;
const { width, height, background = 'white', outputType, devicePixelRatio = 2 } = options;
const nodeCanvas = createNodeCanvas(width, height, outputType as any);
const offscreenNodeCanvas = createNodeCanvas(1, 1);

Expand All @@ -25,6 +25,7 @@ export function createCanvas(options: Options): [G6Canvas, NodeCanvas] {
offscreenCanvas: offscreenNodeCanvas as any,
devicePixelRatio,
enableMultiLayer: false,
createImage: () => new NodeImage(),
renderer: () => {
const renderer = new Renderer();
const htmlRendererPlugin = renderer.getPlugin('html-renderer');
Expand Down

0 comments on commit 7ac448c

Please sign in to comment.