Skip to content

Commit 94b2ac3

Browse files
authored
refactor: ssr support devicePixelRatio (#6647)
* refactor: ssr support config devicePixelRatio * chore: update version * refactor: update test snapshots
1 parent b23ff3d commit 94b2ac3

File tree

8 files changed

+150
-135
lines changed

8 files changed

+150
-135
lines changed
1.2 KB
Binary file not shown.

packages/g6-ssr/__tests__/assets/file.svg

Lines changed: 130 additions & 130 deletions
Loading
62 KB
Loading
172 KB
Loading
39 KB
Loading

packages/g6-ssr/__tests__/graph.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, readFileSync, writeFileSync } from 'fs';
1+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
22
import { join } from 'path';
33
import type { Graph, MetaData } from '../src';
44
import { createGraph } from '../src';
@@ -19,8 +19,11 @@ expect.extend({
1919
const file = received.toBuffer(meta);
2020
const pass = existsSync(_path) ? file.equals(readFileSync(_path)) : true;
2121

22+
const actualName = _path.replace('.', '-actual.');
2223
if (!pass) {
23-
writeFileSync(_path.replace('.', '-actual.'), file);
24+
writeFileSync(actualName, file);
25+
} else if (existsSync(actualName)) {
26+
unlinkSync(actualName);
2427
}
2528

2629
if (pass) {
@@ -38,7 +41,7 @@ expect.extend({
3841
});
3942

4043
describe('createGraph', () => {
41-
const fn = async (outputType?: any, imageType: any = 'png') => {
44+
const fn = async (outputType?: any, imageType: any = 'png', options = {}) => {
4245
const data = {
4346
nodes: [
4447
{ id: '0' },
@@ -158,6 +161,7 @@ describe('createGraph', () => {
158161
layout: {
159162
type: 'circular',
160163
},
164+
...options,
161165
});
162166
};
163167

@@ -210,4 +214,14 @@ describe('createGraph', () => {
210214

211215
graph.destroy();
212216
});
217+
218+
it('devicePixelRatio', async () => {
219+
const graph = await fn('image', 'jpeg', { devicePixelRatio: 1 });
220+
221+
expect(graph).toMatchFile('./assets/image_x1.jpeg');
222+
223+
graph.exportToFile(join(__dirname, './assets/image_x1'));
224+
225+
graph.destroy();
226+
});
213227
});

packages/g6-ssr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-ssr",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Support SSR for G6",
55
"keywords": [
66
"antv",

packages/g6-ssr/src/canvas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { Options } from './types';
1212
* @returns <zh/> [G6 画布, NodeCanvas 画布] | <en/> [G6Canvas, NodeCanvas]
1313
*/
1414
export function createCanvas(options: Options): [G6Canvas, NodeCanvas] {
15-
const { width, height, background, outputType } = options;
15+
const { width, height, background, outputType, devicePixelRatio = 2 } = options;
1616
const nodeCanvas = createNodeCanvas(width, height, outputType as any);
1717
const offscreenNodeCanvas = createNodeCanvas(1, 1);
1818

@@ -23,6 +23,7 @@ export function createCanvas(options: Options): [G6Canvas, NodeCanvas] {
2323
// @ts-expect-error missing types
2424
canvas: nodeCanvas as any,
2525
offscreenCanvas: offscreenNodeCanvas as any,
26+
devicePixelRatio,
2627
enableMultiLayer: false,
2728
renderer: () => {
2829
const renderer = new Renderer();

0 commit comments

Comments
 (0)