Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added packages/g6-ssr/__tests__/assets/image_x2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions packages/g6-ssr/__tests__/graph.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
import { join } from 'path';
import type { Graph, MetaData } from '../src';
import { createGraph } from '../src';
Expand All @@ -19,8 +19,11 @@ expect.extend({
const file = received.toBuffer(meta);
const pass = existsSync(_path) ? file.equals(readFileSync(_path)) : true;

const actualName = _path.replace('.', '-actual.');
if (!pass) {
writeFileSync(_path.replace('.', '-actual.'), file);
writeFileSync(actualName, file);
} else if (existsSync(actualName)) {
unlinkSync(actualName);
}

if (pass) {
Expand All @@ -38,7 +41,7 @@ expect.extend({
});

describe('createGraph', () => {
const fn = async (outputType?: any, imageType: any = 'png') => {
const fn = async (outputType?: any, imageType: any = 'png', options = {}) => {
const data = {
nodes: [
{ id: '0' },
Expand Down Expand Up @@ -158,6 +161,7 @@ describe('createGraph', () => {
layout: {
type: 'circular',
},
...options,
});
};

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

graph.destroy();
});

it('devicePixelRatio', async () => {
const graph = await fn('image', 'jpeg', { devicePixelRatio: 2 });

expect(graph).toMatchFile('./assets/image_x2.jpeg');

graph.exportToFile(join(__dirname, './assets/image_x2'));

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.2",
"version": "0.0.3",
"description": "Support SSR for G6",
"keywords": [
"antv",
Expand Down
3 changes: 2 additions & 1 deletion packages/g6-ssr/src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = options;
const { width, height, background, outputType, devicePixelRatio = 1 } = options;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不直接默认 2,看看 1 的时候,截图清晰不?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那我更新下截图

const nodeCanvas = createNodeCanvas(width, height, outputType as any);
const offscreenNodeCanvas = createNodeCanvas(1, 1);

Expand All @@ -23,6 +23,7 @@ export function createCanvas(options: Options): [G6Canvas, NodeCanvas] {
// @ts-expect-error missing types
canvas: nodeCanvas as any,
offscreenCanvas: offscreenNodeCanvas as any,
devicePixelRatio,
enableMultiLayer: false,
renderer: () => {
const renderer = new Renderer();
Expand Down
Loading