Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 15 additions & 11 deletions src/svg/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
createSVGVNode
} from './core';
import { normalizeColor, encodeBase64 } from './helper';
import { defaults, extend, keys, logError, map } from '../core/util';
import { extend, keys, logError, map, retrieve2 } from '../core/util';
import Path from '../graphic/Path';
import patch, { updateAttrs } from './patch';
import { getSize } from '../canvas/helper';
Expand Down Expand Up @@ -119,7 +119,8 @@ class SVGPainter implements PainterBase {
renderToVNode(opts?: {
animation?: boolean
willUpdate?: boolean
compress?: boolean
compress?: boolean,
useViewBox?: boolean
}) {

opts = opts || {};
Expand Down Expand Up @@ -176,24 +177,27 @@ class SVGPainter implements PainterBase {
}
}

return createSVGVNode(width, height, children);
return createSVGVNode(width, height, children, opts.useViewBox);
}

renderToString(opts?: {
/**
* If add css animation.
* @default true
*/
cssAnimation: boolean
cssAnimation?: boolean
/**
* If use viewBox
* @default true
*/
useViewBox?: boolean
}) {
const defaultOpts = {
cssAnimation: true
};
opts = defaults(opts || {}, defaultOpts);

opts = opts || {};
return vNodeToString(this.renderToVNode({
animation: defaultOpts.cssAnimation,
animation: retrieve2(opts.cssAnimation, true),
willUpdate: false,
compress: true
compress: true,
useViewBox: retrieve2(opts.useViewBox, true)
}), { newline: true });
}

Expand Down
10 changes: 8 additions & 2 deletions src/svg/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ export function createBrushScope(zrId: string): BrushScope {
};
}

export function createSVGVNode(width?: number | string, height?: number | string, children?: SVGVNode[]) {
export function createSVGVNode(
width: number | string,
height: number | string,
children?: SVGVNode[],
useViewBox?: boolean
) {
return createVNode(
'svg',
'root',
Expand All @@ -184,7 +189,8 @@ export function createSVGVNode(width?: number | string, height?: number | string
'xmlns': SVGNS,
'xmlns:xlink': XLINKNS,
'version': '1.1',
'baseProfile': 'full'
'baseProfile': 'full',
'viewBox': useViewBox ? `0 0 ${width} ${height}` : false
},
children
);
Expand Down