zrender-nightly 5.5.0-dev.20221018 → 5.5.0-dev.20221020
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/prepareNightly.js +12 -2
- package/dist/zrender.js +103 -43
- package/dist/zrender.js.map +1 -1
- package/dist/zrender.min.js +1 -1
- package/lib/canvas/Layer.js +6 -1
- package/lib/graphic/Gradient.d.ts +2 -0
- package/lib/svg/Painter.d.ts +4 -1
- package/lib/svg/Painter.js +51 -34
- package/lib/svg/graphic.d.ts +3 -1
- package/lib/svg/graphic.js +49 -11
- package/lib/svg/helper.js +1 -1
- package/lib/zrender.d.ts +1 -1
- package/lib/zrender.js +1 -1
- package/package.json +2 -2
- package/src/canvas/Layer.ts +9 -1
- package/src/graphic/Gradient.ts +2 -0
- package/src/svg/Painter.ts +72 -41
- package/src/svg/graphic.ts +53 -13
- package/src/svg/helper.ts +1 -1
- package/src/zrender.ts +1 -1
package/lib/canvas/Layer.js
CHANGED
|
@@ -246,7 +246,10 @@ var Layer = (function (_super) {
|
|
|
246
246
|
if (clearColor && clearColor !== 'transparent') {
|
|
247
247
|
var clearColorGradientOrPattern = void 0;
|
|
248
248
|
if (util.isGradientObject(clearColor)) {
|
|
249
|
-
|
|
249
|
+
var shouldCache = clearColor.global || (clearColor.__width === width
|
|
250
|
+
&& clearColor.__height === height);
|
|
251
|
+
clearColorGradientOrPattern = shouldCache
|
|
252
|
+
&& clearColor.__canvasGradient
|
|
250
253
|
|| getCanvasGradient(ctx, clearColor, {
|
|
251
254
|
x: 0,
|
|
252
255
|
y: 0,
|
|
@@ -254,6 +257,8 @@ var Layer = (function (_super) {
|
|
|
254
257
|
height: height
|
|
255
258
|
});
|
|
256
259
|
clearColor.__canvasGradient = clearColorGradientOrPattern;
|
|
260
|
+
clearColor.__width = width;
|
|
261
|
+
clearColor.__height = height;
|
|
257
262
|
}
|
|
258
263
|
else if (util.isImagePatternObject(clearColor)) {
|
|
259
264
|
clearColor.scaleX = clearColor.scaleX || dpr;
|
package/lib/svg/Painter.d.ts
CHANGED
|
@@ -2,11 +2,14 @@ import Displayable from '../graphic/Displayable';
|
|
|
2
2
|
import Storage from '../Storage';
|
|
3
3
|
import { PainterBase } from '../PainterBase';
|
|
4
4
|
import { SVGVNode, BrushScope } from './core';
|
|
5
|
+
import { GradientObject } from '../graphic/Gradient';
|
|
6
|
+
import { PatternObject } from '../graphic/Pattern';
|
|
5
7
|
interface SVGPainterOption {
|
|
6
8
|
width?: number;
|
|
7
9
|
height?: number;
|
|
8
10
|
ssr?: boolean;
|
|
9
11
|
}
|
|
12
|
+
declare type SVGPainterBackgroundColor = string | GradientObject | PatternObject;
|
|
10
13
|
declare class SVGPainter implements PainterBase {
|
|
11
14
|
type: string;
|
|
12
15
|
storage: Storage;
|
|
@@ -41,7 +44,7 @@ declare class SVGPainter implements PainterBase {
|
|
|
41
44
|
cssAnimation?: boolean;
|
|
42
45
|
useViewBox?: boolean;
|
|
43
46
|
}): string;
|
|
44
|
-
setBackgroundColor(backgroundColor:
|
|
47
|
+
setBackgroundColor(backgroundColor: SVGPainterBackgroundColor): void;
|
|
45
48
|
getSvgRoot(): SVGElement;
|
|
46
49
|
_paintList(list: Displayable[], scope: BrushScope, out?: SVGVNode[]): void;
|
|
47
50
|
resize(width: number, height: number): void;
|
package/lib/svg/Painter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { brush, setClipPath } from './graphic.js';
|
|
1
|
+
import { brush, setClipPath, setGradient, setPattern } from './graphic.js';
|
|
2
2
|
import { createElement, createVNode, vNodeToString, getCssString, createBrushScope, createSVGVNode } from './core.js';
|
|
3
|
-
import { normalizeColor, encodeBase64 } from './helper.js';
|
|
4
|
-
import { extend, keys, logError, map, retrieve2 } from '../core/util.js';
|
|
3
|
+
import { normalizeColor, encodeBase64, isGradient, isPattern } from './helper.js';
|
|
4
|
+
import { extend, keys, logError, map, noop, retrieve2 } from '../core/util.js';
|
|
5
5
|
import patch, { updateAttrs } from './patch.js';
|
|
6
6
|
import { getSize } from '../canvas/helper.js';
|
|
7
7
|
var svgId = 0;
|
|
@@ -59,7 +59,6 @@ var SVGPainter = (function () {
|
|
|
59
59
|
SVGPainter.prototype.renderToVNode = function (opts) {
|
|
60
60
|
opts = opts || {};
|
|
61
61
|
var list = this.storage.getDisplayList(true);
|
|
62
|
-
var bgColor = this._backgroundColor;
|
|
63
62
|
var width = this._width;
|
|
64
63
|
var height = this._height;
|
|
65
64
|
var scope = createBrushScope(this._id);
|
|
@@ -67,22 +66,8 @@ var SVGPainter = (function () {
|
|
|
67
66
|
scope.willUpdate = opts.willUpdate;
|
|
68
67
|
scope.compress = opts.compress;
|
|
69
68
|
var children = [];
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this._bgVNode = createVNode('rect', 'bg', {
|
|
73
|
-
width: width,
|
|
74
|
-
height: height,
|
|
75
|
-
x: '0',
|
|
76
|
-
y: '0',
|
|
77
|
-
id: '0',
|
|
78
|
-
fill: color,
|
|
79
|
-
'fill-opacity': opacity
|
|
80
|
-
});
|
|
81
|
-
children.push(this._bgVNode);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
this._bgVNode = null;
|
|
85
|
-
}
|
|
69
|
+
var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
|
|
70
|
+
bgVNode && children.push(bgVNode);
|
|
86
71
|
var mainVNode = !opts.compress
|
|
87
72
|
? (this._mainVNode = createVNode('g', 'main', {}, [])) : null;
|
|
88
73
|
this._paintList(list, scope, mainVNode ? mainVNode.children : children);
|
|
@@ -111,14 +96,6 @@ var SVGPainter = (function () {
|
|
|
111
96
|
};
|
|
112
97
|
SVGPainter.prototype.setBackgroundColor = function (backgroundColor) {
|
|
113
98
|
this._backgroundColor = backgroundColor;
|
|
114
|
-
var bgVNode = this._bgVNode;
|
|
115
|
-
if (bgVNode && bgVNode.elm) {
|
|
116
|
-
var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
|
|
117
|
-
bgVNode.elm.setAttribute('fill', color);
|
|
118
|
-
if (opacity < 1) {
|
|
119
|
-
bgVNode.elm.setAttribute('fill-opacity', opacity);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
99
|
};
|
|
123
100
|
SVGPainter.prototype.getSvgRoot = function () {
|
|
124
101
|
return this._mainVNode && this._mainVNode.elm;
|
|
@@ -183,10 +160,20 @@ var SVGPainter = (function () {
|
|
|
183
160
|
viewportStyle.width = width + 'px';
|
|
184
161
|
viewportStyle.height = height + 'px';
|
|
185
162
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
svgDom
|
|
189
|
-
|
|
163
|
+
if (!isPattern(this._backgroundColor)) {
|
|
164
|
+
var svgDom = this._svgDom;
|
|
165
|
+
if (svgDom) {
|
|
166
|
+
svgDom.setAttribute('width', width);
|
|
167
|
+
svgDom.setAttribute('height', height);
|
|
168
|
+
}
|
|
169
|
+
var bgEl = this._bgVNode && this._bgVNode.elm;
|
|
170
|
+
if (bgEl) {
|
|
171
|
+
bgEl.setAttribute('width', width);
|
|
172
|
+
bgEl.setAttribute('height', height);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.refresh();
|
|
190
177
|
}
|
|
191
178
|
}
|
|
192
179
|
};
|
|
@@ -214,13 +201,13 @@ var SVGPainter = (function () {
|
|
|
214
201
|
this._oldVNode = null;
|
|
215
202
|
};
|
|
216
203
|
SVGPainter.prototype.toDataURL = function (base64) {
|
|
217
|
-
var str =
|
|
204
|
+
var str = this.renderToString();
|
|
218
205
|
var prefix = 'data:image/svg+xml;';
|
|
219
206
|
if (base64) {
|
|
220
207
|
str = encodeBase64(str);
|
|
221
208
|
return str && prefix + 'base64,' + str;
|
|
222
209
|
}
|
|
223
|
-
return prefix + 'charset=UTF-8,' + str;
|
|
210
|
+
return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
|
|
224
211
|
};
|
|
225
212
|
return SVGPainter;
|
|
226
213
|
}());
|
|
@@ -231,4 +218,34 @@ function createMethodNotSupport(method) {
|
|
|
231
218
|
}
|
|
232
219
|
};
|
|
233
220
|
}
|
|
221
|
+
function createBackgroundVNode(width, height, backgroundColor, scope) {
|
|
222
|
+
var bgVNode;
|
|
223
|
+
if (backgroundColor && backgroundColor !== 'none') {
|
|
224
|
+
bgVNode = createVNode('rect', 'bg', {
|
|
225
|
+
width: width,
|
|
226
|
+
height: height,
|
|
227
|
+
x: '0',
|
|
228
|
+
y: '0',
|
|
229
|
+
id: '0'
|
|
230
|
+
});
|
|
231
|
+
if (isGradient(backgroundColor)) {
|
|
232
|
+
setGradient({ fill: backgroundColor }, bgVNode.attrs, 'fill', scope);
|
|
233
|
+
}
|
|
234
|
+
else if (isPattern(backgroundColor)) {
|
|
235
|
+
setPattern({
|
|
236
|
+
style: {
|
|
237
|
+
fill: backgroundColor
|
|
238
|
+
},
|
|
239
|
+
dirty: noop,
|
|
240
|
+
getBoundingRect: function () { return ({ width: width, height: height }); }
|
|
241
|
+
}, bgVNode.attrs, 'fill', scope);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
|
|
245
|
+
bgVNode.attrs.fill = color;
|
|
246
|
+
opacity < 1 && (bgVNode.attrs.fillOpacity = opacity);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return bgVNode;
|
|
250
|
+
}
|
|
234
251
|
export default SVGPainter;
|
package/lib/svg/graphic.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Path from '../graphic/Path';
|
|
1
|
+
import Path, { PathStyleProps } from '../graphic/Path';
|
|
2
2
|
import ZRImage from '../graphic/Image';
|
|
3
3
|
import TSpan from '../graphic/TSpan';
|
|
4
4
|
import { SVGVNodeAttrs, SVGVNode, BrushScope } from './core';
|
|
@@ -7,4 +7,6 @@ export declare function brushSVGPath(el: Path, scope: BrushScope): SVGVNode;
|
|
|
7
7
|
export declare function brushSVGImage(el: ZRImage, scope: BrushScope): SVGVNode;
|
|
8
8
|
export declare function brushSVGTSpan(el: TSpan, scope: BrushScope): SVGVNode;
|
|
9
9
|
export declare function brush(el: Displayable, scope: BrushScope): SVGVNode;
|
|
10
|
+
export declare function setGradient(style: PathStyleProps, attrs: SVGVNodeAttrs, target: 'fill' | 'stroke', scope: BrushScope): void;
|
|
11
|
+
export declare function setPattern(el: Displayable, attrs: SVGVNodeAttrs, target: 'fill' | 'stroke', scope: BrushScope): void;
|
|
10
12
|
export declare function setClipPath(clipPath: Path, attrs: SVGVNodeAttrs, scope: BrushScope): void;
|
package/lib/svg/graphic.js
CHANGED
|
@@ -75,7 +75,7 @@ function createAttrsConvert(desc) {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
var
|
|
78
|
+
var builtinShapesDef = {
|
|
79
79
|
circle: [createAttrsConvert(['cx', 'cy', 'r'])],
|
|
80
80
|
polyline: [convertPolyShape, validatePolyShape],
|
|
81
81
|
polygon: [convertPolyShape, validatePolyShape]
|
|
@@ -92,7 +92,7 @@ function hasShapeAnimation(el) {
|
|
|
92
92
|
export function brushSVGPath(el, scope) {
|
|
93
93
|
var style = el.style;
|
|
94
94
|
var shape = el.shape;
|
|
95
|
-
var builtinShpDef =
|
|
95
|
+
var builtinShpDef = builtinShapesDef[el.type];
|
|
96
96
|
var attrs = {};
|
|
97
97
|
var needsAnimate = scope.animation;
|
|
98
98
|
var svgElType = 'path';
|
|
@@ -277,7 +277,7 @@ function setShadow(el, attrs, scope) {
|
|
|
277
277
|
attrs.filter = getIdURL(shadowId);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
function setGradient(style, attrs, target, scope) {
|
|
280
|
+
export function setGradient(style, attrs, target, scope) {
|
|
281
281
|
var val = style[target];
|
|
282
282
|
var gradientTag;
|
|
283
283
|
var gradientAttrs = {
|
|
@@ -331,11 +331,14 @@ function setGradient(style, attrs, target, scope) {
|
|
|
331
331
|
}
|
|
332
332
|
attrs[target] = getIdURL(gradientId);
|
|
333
333
|
}
|
|
334
|
-
function setPattern(el, attrs, target, scope) {
|
|
334
|
+
export function setPattern(el, attrs, target, scope) {
|
|
335
335
|
var val = el.style[target];
|
|
336
|
-
var
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
var boundingRect = el.getBoundingRect();
|
|
337
|
+
var patternAttrs = {};
|
|
338
|
+
var repeat = val.repeat;
|
|
339
|
+
var noRepeat = repeat === 'no-repeat';
|
|
340
|
+
var repeatX = repeat === 'repeat-x';
|
|
341
|
+
var repeatY = repeat === 'repeat-y';
|
|
339
342
|
var child;
|
|
340
343
|
if (isImagePattern(val)) {
|
|
341
344
|
var imageWidth_1 = val.imageWidth;
|
|
@@ -360,8 +363,20 @@ function setPattern(el, attrs, target, scope) {
|
|
|
360
363
|
var setSizeToVNode_1 = function (vNode, img) {
|
|
361
364
|
if (vNode) {
|
|
362
365
|
var svgEl = vNode.elm;
|
|
363
|
-
var width =
|
|
364
|
-
var height =
|
|
366
|
+
var width = imageWidth_1 || img.width;
|
|
367
|
+
var height = imageHeight_1 || img.height;
|
|
368
|
+
if (vNode.tag === 'pattern') {
|
|
369
|
+
if (repeatX) {
|
|
370
|
+
height = 1;
|
|
371
|
+
width /= boundingRect.width;
|
|
372
|
+
}
|
|
373
|
+
else if (repeatY) {
|
|
374
|
+
width = 1;
|
|
375
|
+
height /= boundingRect.height;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
vNode.attrs.width = width;
|
|
379
|
+
vNode.attrs.height = height;
|
|
365
380
|
if (svgEl) {
|
|
366
381
|
svgEl.setAttribute('width', width);
|
|
367
382
|
svgEl.setAttribute('height', height);
|
|
@@ -369,7 +384,7 @@ function setPattern(el, attrs, target, scope) {
|
|
|
369
384
|
}
|
|
370
385
|
};
|
|
371
386
|
var createdImage = createOrUpdateImage(imageSrc, null, el, function (img) {
|
|
372
|
-
setSizeToVNode_1(patternVNode, img);
|
|
387
|
+
noRepeat || setSizeToVNode_1(patternVNode, img);
|
|
373
388
|
setSizeToVNode_1(child, img);
|
|
374
389
|
});
|
|
375
390
|
if (createdImage && createdImage.width && createdImage.height) {
|
|
@@ -393,7 +408,30 @@ function setPattern(el, attrs, target, scope) {
|
|
|
393
408
|
if (!child) {
|
|
394
409
|
return;
|
|
395
410
|
}
|
|
396
|
-
|
|
411
|
+
var patternWidth;
|
|
412
|
+
var patternHeight;
|
|
413
|
+
if (noRepeat) {
|
|
414
|
+
patternWidth = patternHeight = 1;
|
|
415
|
+
}
|
|
416
|
+
else if (repeatX) {
|
|
417
|
+
patternHeight = 1;
|
|
418
|
+
patternWidth = patternAttrs.width / boundingRect.width;
|
|
419
|
+
}
|
|
420
|
+
else if (repeatY) {
|
|
421
|
+
patternWidth = 1;
|
|
422
|
+
patternHeight = patternAttrs.height / boundingRect.height;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
patternAttrs.patternUnits = 'userSpaceOnUse';
|
|
426
|
+
}
|
|
427
|
+
if (patternWidth != null && !isNaN(patternWidth)) {
|
|
428
|
+
patternAttrs.width = patternWidth;
|
|
429
|
+
}
|
|
430
|
+
if (patternHeight != null && !isNaN(patternHeight)) {
|
|
431
|
+
patternAttrs.height = patternHeight;
|
|
432
|
+
}
|
|
433
|
+
var patternTransform = getSRTTransformString(val);
|
|
434
|
+
patternTransform && (patternAttrs.patternTransform = patternTransform);
|
|
397
435
|
var patternVNode = createVNode('pattern', '', patternAttrs, [child]);
|
|
398
436
|
var patternKey = vNodeToString(patternVNode);
|
|
399
437
|
var patternCache = scope.patternCache;
|
package/lib/svg/helper.js
CHANGED
|
@@ -136,7 +136,7 @@ export function getSRTTransformString(transform) {
|
|
|
136
136
|
export var encodeBase64 = (function () {
|
|
137
137
|
if (env.hasGlobalWindow && isFunction(window.btoa)) {
|
|
138
138
|
return function (str) {
|
|
139
|
-
return window.btoa(unescape(str));
|
|
139
|
+
return window.btoa(unescape(encodeURIComponent(str)));
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
if (typeof Buffer !== 'undefined') {
|
package/lib/zrender.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare function dispose(zr: ZRender): void;
|
|
|
84
84
|
export declare function disposeAll(): void;
|
|
85
85
|
export declare function getInstance(id: number): ZRender;
|
|
86
86
|
export declare function registerPainter(name: string, Ctor: PainterBaseCtor): void;
|
|
87
|
-
export declare const version = "5.
|
|
87
|
+
export declare const version = "5.5.0-dev.20221020";
|
|
88
88
|
export interface ZRenderType extends ZRender {
|
|
89
89
|
}
|
|
90
90
|
export {};
|
package/lib/zrender.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zrender-nightly",
|
|
3
|
-
"version": "5.5.0-dev.
|
|
3
|
+
"version": "5.5.0-dev.20221020",
|
|
4
4
|
"description": "A lightweight graphic library providing 2d draw for Apache ECharts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"canvas",
|
|
@@ -58,4 +58,4 @@
|
|
|
58
58
|
"typescript": "^4.4.3",
|
|
59
59
|
"uglify-js": "^3.10.0"
|
|
60
60
|
}
|
|
61
|
-
}
|
|
61
|
+
}
|
package/src/canvas/Layer.ts
CHANGED
|
@@ -422,8 +422,14 @@ export default class Layer extends Eventful {
|
|
|
422
422
|
let clearColorGradientOrPattern;
|
|
423
423
|
// Gradient
|
|
424
424
|
if (util.isGradientObject(clearColor)) {
|
|
425
|
+
// shouldn't cache when clearColor is not global and size changed
|
|
426
|
+
const shouldCache = clearColor.global || (
|
|
427
|
+
(clearColor as InnerGradientObject).__width === width
|
|
428
|
+
&& (clearColor as InnerGradientObject).__height === height
|
|
429
|
+
);
|
|
425
430
|
// Cache canvas gradient
|
|
426
|
-
clearColorGradientOrPattern =
|
|
431
|
+
clearColorGradientOrPattern = shouldCache
|
|
432
|
+
&& (clearColor as InnerGradientObject).__canvasGradient
|
|
427
433
|
|| getCanvasGradient(ctx, clearColor, {
|
|
428
434
|
x: 0,
|
|
429
435
|
y: 0,
|
|
@@ -432,6 +438,8 @@ export default class Layer extends Eventful {
|
|
|
432
438
|
});
|
|
433
439
|
|
|
434
440
|
(clearColor as InnerGradientObject).__canvasGradient = clearColorGradientOrPattern;
|
|
441
|
+
(clearColor as InnerGradientObject).__width = width;
|
|
442
|
+
(clearColor as InnerGradientObject).__height = height;
|
|
435
443
|
}
|
|
436
444
|
// Pattern
|
|
437
445
|
else if (util.isImagePatternObject(clearColor)) {
|
package/src/graphic/Gradient.ts
CHANGED
package/src/svg/Painter.ts
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
brush,
|
|
6
|
+
brush,
|
|
7
|
+
setClipPath,
|
|
8
|
+
setGradient,
|
|
9
|
+
setPattern
|
|
7
10
|
} from './graphic';
|
|
8
11
|
import Displayable from '../graphic/Displayable';
|
|
9
12
|
import Storage from '../Storage';
|
|
@@ -19,11 +22,13 @@ import {
|
|
|
19
22
|
createBrushScope,
|
|
20
23
|
createSVGVNode
|
|
21
24
|
} from './core';
|
|
22
|
-
import { normalizeColor, encodeBase64 } from './helper';
|
|
23
|
-
import { extend, keys, logError, map, retrieve2 } from '../core/util';
|
|
25
|
+
import { normalizeColor, encodeBase64, isGradient, isPattern } from './helper';
|
|
26
|
+
import { extend, keys, logError, map, noop, retrieve2 } from '../core/util';
|
|
24
27
|
import Path from '../graphic/Path';
|
|
25
28
|
import patch, { updateAttrs } from './patch';
|
|
26
29
|
import { getSize } from '../canvas/helper';
|
|
30
|
+
import { GradientObject } from '../graphic/Gradient';
|
|
31
|
+
import { PatternObject } from '../graphic/Pattern';
|
|
27
32
|
|
|
28
33
|
let svgId = 0;
|
|
29
34
|
|
|
@@ -33,6 +38,8 @@ interface SVGPainterOption {
|
|
|
33
38
|
ssr?: boolean
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
type SVGPainterBackgroundColor = string | GradientObject | PatternObject;
|
|
42
|
+
|
|
36
43
|
class SVGPainter implements PainterBase {
|
|
37
44
|
|
|
38
45
|
type = 'svg'
|
|
@@ -53,7 +60,7 @@ class SVGPainter implements PainterBase {
|
|
|
53
60
|
private _width: number
|
|
54
61
|
private _height: number
|
|
55
62
|
|
|
56
|
-
private _backgroundColor:
|
|
63
|
+
private _backgroundColor: SVGPainterBackgroundColor
|
|
57
64
|
|
|
58
65
|
private _id: string
|
|
59
66
|
|
|
@@ -126,7 +133,6 @@ class SVGPainter implements PainterBase {
|
|
|
126
133
|
opts = opts || {};
|
|
127
134
|
|
|
128
135
|
const list = this.storage.getDisplayList(true);
|
|
129
|
-
const bgColor = this._backgroundColor;
|
|
130
136
|
const width = this._width;
|
|
131
137
|
const height = this._height;
|
|
132
138
|
|
|
@@ -137,26 +143,8 @@ class SVGPainter implements PainterBase {
|
|
|
137
143
|
|
|
138
144
|
const children: SVGVNode[] = [];
|
|
139
145
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this._bgVNode = createVNode(
|
|
143
|
-
'rect',
|
|
144
|
-
'bg',
|
|
145
|
-
{
|
|
146
|
-
width: width,
|
|
147
|
-
height: height,
|
|
148
|
-
x: '0',
|
|
149
|
-
y: '0',
|
|
150
|
-
id: '0',
|
|
151
|
-
fill: color,
|
|
152
|
-
'fill-opacity': opacity
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
children.push(this._bgVNode);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
this._bgVNode = null;
|
|
159
|
-
}
|
|
146
|
+
const bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
|
|
147
|
+
bgVNode && children.push(bgVNode);
|
|
160
148
|
|
|
161
149
|
// Ignore the root g if wan't the output to be more tight.
|
|
162
150
|
const mainVNode = !opts.compress
|
|
@@ -201,16 +189,8 @@ class SVGPainter implements PainterBase {
|
|
|
201
189
|
}), { newline: true });
|
|
202
190
|
}
|
|
203
191
|
|
|
204
|
-
setBackgroundColor(backgroundColor:
|
|
192
|
+
setBackgroundColor(backgroundColor: SVGPainterBackgroundColor) {
|
|
205
193
|
this._backgroundColor = backgroundColor;
|
|
206
|
-
const bgVNode = this._bgVNode;
|
|
207
|
-
if (bgVNode && bgVNode.elm) {
|
|
208
|
-
const { color, opacity } = normalizeColor(backgroundColor);
|
|
209
|
-
(bgVNode.elm as SVGElement).setAttribute('fill', color);
|
|
210
|
-
if (opacity < 1) {
|
|
211
|
-
(bgVNode.elm as SVGElement).setAttribute('fill-opacity', opacity as any);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
194
|
}
|
|
215
195
|
|
|
216
196
|
getSvgRoot() {
|
|
@@ -302,11 +282,23 @@ class SVGPainter implements PainterBase {
|
|
|
302
282
|
viewportStyle.height = height + 'px';
|
|
303
283
|
}
|
|
304
284
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
285
|
+
if (!isPattern(this._backgroundColor)) {
|
|
286
|
+
const svgDom = this._svgDom;
|
|
287
|
+
if (svgDom) {
|
|
288
|
+
// Set width by 'svgRoot.width = width' is invalid
|
|
289
|
+
svgDom.setAttribute('width', width as any);
|
|
290
|
+
svgDom.setAttribute('height', height as any);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const bgEl = this._bgVNode && this._bgVNode.elm as SVGElement;
|
|
294
|
+
if (bgEl) {
|
|
295
|
+
bgEl.setAttribute('width', width as any);
|
|
296
|
+
bgEl.setAttribute('height', height as any);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
// pattern backgroundColor requires a full refresh
|
|
301
|
+
this.refresh();
|
|
310
302
|
}
|
|
311
303
|
}
|
|
312
304
|
}
|
|
@@ -344,13 +336,13 @@ class SVGPainter implements PainterBase {
|
|
|
344
336
|
this._oldVNode = null;
|
|
345
337
|
}
|
|
346
338
|
toDataURL(base64?: boolean) {
|
|
347
|
-
let str =
|
|
339
|
+
let str = this.renderToString();
|
|
348
340
|
const prefix = 'data:image/svg+xml;';
|
|
349
341
|
if (base64) {
|
|
350
342
|
str = encodeBase64(str);
|
|
351
343
|
return str && prefix + 'base64,' + str;
|
|
352
344
|
}
|
|
353
|
-
return prefix + 'charset=UTF-8,' + str;
|
|
345
|
+
return prefix + 'charset=UTF-8,' + encodeURIComponent(str);
|
|
354
346
|
}
|
|
355
347
|
|
|
356
348
|
refreshHover = createMethodNotSupport('refreshHover') as PainterBase['refreshHover'];
|
|
@@ -367,5 +359,44 @@ function createMethodNotSupport(method: string): any {
|
|
|
367
359
|
};
|
|
368
360
|
}
|
|
369
361
|
|
|
362
|
+
function createBackgroundVNode(
|
|
363
|
+
width: number,
|
|
364
|
+
height: number,
|
|
365
|
+
backgroundColor: SVGPainterBackgroundColor,
|
|
366
|
+
scope: BrushScope
|
|
367
|
+
) {
|
|
368
|
+
let bgVNode;
|
|
369
|
+
if (backgroundColor && backgroundColor !== 'none') {
|
|
370
|
+
bgVNode = createVNode(
|
|
371
|
+
'rect',
|
|
372
|
+
'bg',
|
|
373
|
+
{
|
|
374
|
+
width,
|
|
375
|
+
height,
|
|
376
|
+
x: '0',
|
|
377
|
+
y: '0',
|
|
378
|
+
id: '0'
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
if (isGradient(backgroundColor)) {
|
|
382
|
+
setGradient({ fill: backgroundColor as any }, bgVNode.attrs, 'fill', scope);
|
|
383
|
+
}
|
|
384
|
+
else if (isPattern(backgroundColor)) {
|
|
385
|
+
setPattern({
|
|
386
|
+
style: {
|
|
387
|
+
fill: backgroundColor
|
|
388
|
+
},
|
|
389
|
+
dirty: noop,
|
|
390
|
+
getBoundingRect: () => ({ width, height })
|
|
391
|
+
} as any, bgVNode.attrs, 'fill', scope);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
const { color, opacity } = normalizeColor(backgroundColor);
|
|
395
|
+
bgVNode.attrs.fill = color;
|
|
396
|
+
opacity < 1 && (bgVNode.attrs.fillOpacity = opacity);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return bgVNode;
|
|
400
|
+
}
|
|
370
401
|
|
|
371
402
|
export default SVGPainter;
|