From 53a44fb3bd73c5279ed9699f2dafefaedefae209 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Tue, 14 Mar 2023 18:12:38 +0800 Subject: [PATCH 01/20] WIP(ssr): add emphasis style in ssr css apache/echarts#18334 --- src/Element.ts | 5 +++ src/svg/Painter.ts | 10 ++++- src/svg/core.ts | 10 +++++ src/svg/cssEmphasis.ts | 71 +++++++++++++++++++++++++++++++ src/svg/graphic.ts | 15 ++++++- test/svg-meta-data.html | 92 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 src/svg/cssEmphasis.ts create mode 100644 test/svg-meta-data.html diff --git a/src/Element.ts b/src/Element.ts index eb87cc5f9..ec1211ac1 100644 --- a/src/Element.ts +++ b/src/Element.ts @@ -368,6 +368,11 @@ class Element { */ __inHover: boolean + /** + * Any information to be binded on the element when rendering. + */ + __metaData: Record + /** * path to clip the elements and its children, if it is a group. * @see http://www.w3.org/TR/2dcontext/#clipping-region diff --git a/src/svg/Painter.ts b/src/svg/Painter.ts index fc85ed939..59f0ab3a9 100644 --- a/src/svg/Painter.ts +++ b/src/svg/Painter.ts @@ -128,6 +128,7 @@ class SVGPainter implements PainterBase { willUpdate?: boolean compress?: boolean, useViewBox?: boolean + emphasis?: boolean }) { opts = opts || {}; @@ -140,6 +141,7 @@ class SVGPainter implements PainterBase { scope.animation = opts.animation; scope.willUpdate = opts.willUpdate; scope.compress = opts.compress; + scope.emphasis = opts.emphasis; const children: SVGVNode[] = []; @@ -173,7 +175,12 @@ class SVGPainter implements PainterBase { * If add css animation. * @default true */ - cssAnimation?: boolean + cssAnimation?: boolean, + /** + * If add css emphasis. + * @default true + */ + cssEmphasis?: boolean, /** * If use viewBox * @default true @@ -183,6 +190,7 @@ class SVGPainter implements PainterBase { opts = opts || {}; return vNodeToString(this.renderToVNode({ animation: retrieve2(opts.cssAnimation, true), + emphasis: retrieve2(opts.cssEmphasis, true), willUpdate: false, compress: true, useViewBox: retrieve2(opts.useViewBox, true) diff --git a/src/svg/core.ts b/src/svg/core.ts index d4b7c4210..d694c4592 100644 --- a/src/svg/core.ts +++ b/src/svg/core.ts @@ -8,6 +8,7 @@ export const SVGNS = 'http://www.w3.org/2000/svg'; export const XLINKNS = 'http://www.w3.org/1999/xlink'; export const XMLNS = 'http://www.w3.org/2000/xmlns/'; export const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'; +export const META_DATA_PREFIX = 'ecmeta_'; export function createElement(name: string) { return document.createElementNS(SVGNS, name); @@ -128,6 +129,10 @@ export interface BrushScope { cssNodes: Record cssAnims: Record>> + /** + * Cache for css style string, mapping from style string to class name. + */ + cssStyleCache: Record cssClassIdx: number cssAnimIdx: number @@ -141,6 +146,10 @@ export interface BrushScope { * If create animates nodes. */ animation?: boolean, + /** + * If create emphasis styles. + */ + emphasis?: boolean, /** * If will update. Some optimization for string generation can't be applied. @@ -164,6 +173,7 @@ export function createBrushScope(zrId: string): BrushScope { cssNodes: {}, cssAnims: {}, + cssStyleCache: {}, cssClassIdx: 0, cssAnimIdx: 0, diff --git a/src/svg/cssEmphasis.ts b/src/svg/cssEmphasis.ts new file mode 100644 index 000000000..354071c32 --- /dev/null +++ b/src/svg/cssEmphasis.ts @@ -0,0 +1,71 @@ +import LRU from '../core/LRU'; +import { extend, isGradientObject, isString, map } from '../core/util'; +import * as colorTool from '../tool/color'; +import Displayable from '../graphic/Displayable'; +import { GradientObject } from '../graphic/Gradient'; +import { BrushScope, SVGVNodeAttrs } from './core'; + +// TODO: Consider deleting the same logic in ECharts and call this method? +const liftedColorCache = new LRU(100); +function liftColor(color: GradientObject): GradientObject; +function liftColor(color: string): string; +function liftColor(color: string | GradientObject): string | GradientObject { + if (isString(color)) { + let liftedColor = liftedColorCache.get(color); + if (!liftedColor) { + liftedColor = colorTool.lift(color, -0.1); + liftedColorCache.put(color, liftedColor); + } + return liftedColor; + } + else if (isGradientObject(color)) { + const ret = extend({}, color) as GradientObject; + ret.colorStops = map(color.colorStops, stop => ({ + offset: stop.offset, + color: colorTool.lift(stop.color, -0.1) + })); + return ret; + } + // Change nothing. + return color; +} + +export function createCSSEmphasis( + el: Displayable, + attrs: SVGVNodeAttrs, + scope: BrushScope +) { + if (el.states.emphasis) { + const empahsisStyle = el.states.emphasis.style; + let fill = empahsisStyle.fill; + if (!fill) { + // No empahsis fill, lift color + const normalFill = el.style.fill; + const selectFill = el.states.select.style.fill; + const fromFill = el.currentStates.indexOf('select') >= 0 + ? (selectFill || normalFill) + : normalFill; + if (fromFill) { + fill = liftColor(fromFill); + } + else { + // No fill information, ignore css + return; + } + } + const style = { + cursor: 'pointer', // TODO: Should be included in el + fill: fill, + stroke: empahsisStyle.stroke, + 'stroke-width': empahsisStyle.lineWidth + }; + const styleKey = JSON.stringify(style); + let className = scope.cssStyleCache[styleKey]; + if (!className) { + className = scope.zrId + '-cls-' + scope.cssClassIdx++; + scope.cssStyleCache[styleKey] = className; + scope.cssNodes['.' + className + ':hover'] = style; + } + attrs.class = attrs.class ? (attrs.class + ' ' + className) : className; + } +} diff --git a/src/svg/graphic.ts b/src/svg/graphic.ts index 49a0e139b..47ad3cd73 100644 --- a/src/svg/graphic.ts +++ b/src/svg/graphic.ts @@ -26,7 +26,7 @@ import { getLineHeight } from '../contain/text'; import TSpan, { TSpanStyleProps } from '../graphic/TSpan'; import SVGPathRebuilder from './SVGPathRebuilder'; import mapStyleToAttrs from './mapStyleToAttrs'; -import { SVGVNodeAttrs, createVNode, SVGVNode, vNodeToString, BrushScope } from './core'; +import { SVGVNodeAttrs, createVNode, SVGVNode, vNodeToString, BrushScope, META_DATA_PREFIX } from './core'; import { MatrixArray } from '../core/matrix'; import Displayable from '../graphic/Displayable'; import { assert, clone, isFunction, isString, logError, map, retrieve2 } from '../core/util'; @@ -39,6 +39,7 @@ import { ImageLike } from '../core/types'; import { createCSSAnimation } from './cssAnimation'; import { hasSeparateFont, parseFontSize } from '../graphic/Text'; import { DEFAULT_FONT, DEFAULT_FONT_FAMILY } from '../core/platform'; +import { createCSSEmphasis } from './cssEmphasis'; const round = Math.round; @@ -69,6 +70,14 @@ function setStyleAttrs(attrs: SVGVNodeAttrs, style: AllStyleOption, el: Path | T setShadow(el, attrs, scope); } +function setMetaData(attrs: SVGVNodeAttrs, el: Path | TSpan | ZRImage) { + if (el.__metaData) { + for (const key in el.__metaData) { + attrs[META_DATA_PREFIX + key] = el.__metaData[key] + ''; + } + } +} + function noRotateScale(m: MatrixArray) { return isAroundZero(m[0] - 1) && isAroundZero(m[1]) @@ -204,8 +213,10 @@ export function brushSVGPath(el: Path, scope: BrushScope) { setTransform(attrs, el.transform); setStyleAttrs(attrs, style, el, scope); + setMetaData(attrs, el); scope.animation && createCSSAnimation(el, attrs, scope); + scope.emphasis && createCSSEmphasis(el, attrs, scope); return createVNode(svgElType, el.id + '', attrs); } @@ -248,6 +259,7 @@ export function brushSVGImage(el: ZRImage, scope: BrushScope) { setTransform(attrs, el.transform); setStyleAttrs(attrs, style, el, scope); + setMetaData(attrs, el); scope.animation && createCSSAnimation(el, attrs, scope); @@ -319,6 +331,7 @@ export function brushSVGTSpan(el: TSpan, scope: BrushScope) { } setTransform(attrs, el.transform); setStyleAttrs(attrs, style, el, scope); + setMetaData(attrs, el); scope.animation && createCSSAnimation(el, attrs, scope); diff --git a/test/svg-meta-data.html b/test/svg-meta-data.html new file mode 100644 index 000000000..afc4a1d9c --- /dev/null +++ b/test/svg-meta-data.html @@ -0,0 +1,92 @@ + + + + + Image + + + + + +
+ + + + \ No newline at end of file From 26abab131ccfaea50144f2ba0ad190f9946e939d Mon Sep 17 00:00:00 2001 From: Ovilia Date: Fri, 31 Mar 2023 15:31:51 +0800 Subject: [PATCH 02/20] feat(ssr): add style in meta data --- src/svg/Painter.ts | 6 +++--- src/svg/cssEmphasis.ts | 33 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/svg/Painter.ts b/src/svg/Painter.ts index 59f0ab3a9..c20543854 100644 --- a/src/svg/Painter.ts +++ b/src/svg/Painter.ts @@ -124,10 +124,10 @@ class SVGPainter implements PainterBase { } renderToVNode(opts?: { - animation?: boolean - willUpdate?: boolean + animation?: boolean, + willUpdate?: boolean, compress?: boolean, - useViewBox?: boolean + useViewBox?: boolean, emphasis?: boolean }) { diff --git a/src/svg/cssEmphasis.ts b/src/svg/cssEmphasis.ts index 354071c32..d3ab72d17 100644 --- a/src/svg/cssEmphasis.ts +++ b/src/svg/cssEmphasis.ts @@ -35,30 +35,41 @@ export function createCSSEmphasis( attrs: SVGVNodeAttrs, scope: BrushScope ) { - if (el.states.emphasis) { - const empahsisStyle = el.states.emphasis.style; + if (!el.ignore && el.__metaData) { + const empahsisStyle = el.states.emphasis + ? el.states.emphasis.style + : {}; let fill = empahsisStyle.fill; if (!fill) { // No empahsis fill, lift color const normalFill = el.style.fill; - const selectFill = el.states.select.style.fill; + const selectFill = el.states.select && el.states.select.style.fill; const fromFill = el.currentStates.indexOf('select') >= 0 ? (selectFill || normalFill) : normalFill; if (fromFill) { fill = liftColor(fromFill); } - else { - // No fill information, ignore css - return; - } + } + let lineWidth = empahsisStyle.lineWidth; + if (lineWidth) { + // Symbols use transform to set size, so lineWidth + // should be divided by scaleX + const scaleX = el.transform ? el.transform[0] : 1; + lineWidth = lineWidth / scaleX; } const style = { cursor: 'pointer', // TODO: Should be included in el - fill: fill, - stroke: empahsisStyle.stroke, - 'stroke-width': empahsisStyle.lineWidth - }; + } as any; + if (fill) { + style.fill = fill; + } + if (empahsisStyle.stroke) { + style.stroke = empahsisStyle.stroke; + } + if (lineWidth) { + style['stroke-width'] = lineWidth; + } const styleKey = JSON.stringify(style); let className = scope.cssStyleCache[styleKey]; if (!className) { From 4ca836e572a216045c8510f78a24bcdedefec4e8 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Mon, 3 Apr 2023 16:39:25 +0800 Subject: [PATCH 03/20] fix(svg): duplicate id for background rect with multiple charts --- src/svg/Painter.ts | 5 +++-- test/svg-backgroundColor.html | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/svg/Painter.ts b/src/svg/Painter.ts index fc85ed939..27bdeeb39 100644 --- a/src/svg/Painter.ts +++ b/src/svg/Painter.ts @@ -143,7 +143,7 @@ class SVGPainter implements PainterBase { const children: SVGVNode[] = []; - const bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope); + const bgVNode = this._bgVNode = createBackgroundVNode(this._id, width, height, this._backgroundColor, scope); bgVNode && children.push(bgVNode); // Ignore the root g if wan't the output to be more tight. @@ -360,6 +360,7 @@ function createMethodNotSupport(method: string): any { } function createBackgroundVNode( + zrId: string, width: number, height: number, backgroundColor: SVGPainterBackgroundColor, @@ -375,7 +376,7 @@ function createBackgroundVNode( height, x: '0', y: '0', - id: '0' + id: zrId + '-bg' } ); if (isGradient(backgroundColor)) { diff --git a/test/svg-backgroundColor.html b/test/svg-backgroundColor.html index b8603e37f..40e1e79a7 100644 --- a/test/svg-backgroundColor.html +++ b/test/svg-backgroundColor.html @@ -16,6 +16,9 @@
+ +

This should not have a rect with the same id as the above instance.

+
@@ -46,11 +43,6 @@

This should not have a rect with the same id as the above instance.

}); zr.add(txt); - var zr2 = zrender.init(document.getElementById('main2'), { - renderer: 'svg' - }); - zr2.add(txt); - var linearGradient = new zrender.LinearGradient(); linearGradient.addColorStop(0, '#a598e1'); linearGradient.addColorStop(1, '#14c4ba'); @@ -104,7 +96,6 @@

This should not have a rect with the same id as the above instance.

bg = text = 'none'; } zr.setBackgroundColor(bg); - zr2.setBackgroundColor(bg); txt.setStyle({ text: 'SVG BackgroundColor: ' + text }); i++; } From 8c6b137fdccea52aa2bb3bcaf317b1595abd5171 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Thu, 16 Nov 2023 15:21:39 +0800 Subject: [PATCH 13/20] fix: el null check --- src/canvas/Layer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/canvas/Layer.ts b/src/canvas/Layer.ts index ed67e8622..43a512f71 100644 --- a/src/canvas/Layer.ts +++ b/src/canvas/Layer.ts @@ -311,7 +311,7 @@ export default class Layer extends Eventful { * rect if and only if it's not painted this frame and was * previously painted on the canvas. */ - const shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true); + const shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true); if (el && (!shouldPaint || !el.__zr) && el.__isRendered) { // el was removed const prevRect = el.getPrevPaintRect(); From e8cc0f9353f1b7dc230ae2908c4bb37d259057d0 Mon Sep 17 00:00:00 2001 From: yechunxi Date: Tue, 19 Dec 2023 17:34:16 +0800 Subject: [PATCH 14/20] fix: avoid errors when executing unfinished operations after calling dispose Signed-off-by: yechunxi --- src/zrender.ts | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/zrender.ts b/src/zrender.ts index 44fd886b6..694707783 100644 --- a/src/zrender.ts +++ b/src/zrender.ts @@ -81,7 +81,7 @@ class ZRender { private _needsRefresh = true private _needsRefreshHover = true - + private _disposed = false; /** * If theme is dark mode. It will determine the color strategy for labels. */ @@ -154,7 +154,7 @@ class ZRender { * 添加元素 */ add(el: Element) { - if (!el) { + if (!el || this._disposed) { return; } this.storage.addRoot(el); @@ -166,7 +166,7 @@ class ZRender { * 删除元素 */ remove(el: Element) { - if (!el) { + if (!el || this._disposed) { return; } this.storage.delRoot(el); @@ -178,6 +178,9 @@ class ZRender { * Change configuration of layer */ configLayer(zLevel: number, config: LayerConfig) { + if(this._disposed) { + return; + } if (this.painter.configLayer) { this.painter.configLayer(zLevel, config); } @@ -188,6 +191,9 @@ class ZRender { * Set background color */ setBackgroundColor(backgroundColor: string | GradientObject | PatternObject) { + if(this._disposed) { + return; + } if (this.painter.setBackgroundColor) { this.painter.setBackgroundColor(backgroundColor); } @@ -215,6 +221,9 @@ class ZRender { * Repaint the canvas immediately */ refreshImmediately(fromInside?: boolean) { + if(this._disposed) { + return; + } // const start = new Date(); if (!fromInside) { // Update animation if refreshImmediately is invoked from outside. @@ -234,6 +243,9 @@ class ZRender { * Mark and repaint the canvas in the next frame of browser */ refresh() { + if(this._disposed) { + return; + } this._needsRefresh = true; // Active the animation again. this.animation.start(); @@ -243,6 +255,9 @@ class ZRender { * Perform all refresh */ flush() { + if(this._disposed) { + return; + } this._flush(false); } @@ -288,6 +303,9 @@ class ZRender { * Wake up animation loop. But not render. */ wakeUp() { + if(this._disposed) { + return; + } this.animation.start(); // Reset the frame count. this._stillFrameAccum = 0; @@ -304,6 +322,9 @@ class ZRender { * Refresh hover immediately */ refreshHoverImmediately() { + if(this._disposed) { + return; + } this._needsRefreshHover = false; if (this.painter.refreshHover && this.painter.getType() === 'canvas') { this.painter.refreshHover(); @@ -318,6 +339,9 @@ class ZRender { width?: number| string height?: number | string }) { + if(this._disposed) { + return; + } opts = opts || {}; this.painter.resize(opts.width, opts.height); this.handler.resize(); @@ -327,6 +351,9 @@ class ZRender { * Stop and clear all animation immediately */ clearAnimation() { + if(this._disposed) { + return; + } this.animation.clear(); } @@ -334,6 +361,9 @@ class ZRender { * Get container width */ getWidth(): number { + if(this._disposed) { + return; + } return this.painter.getWidth(); } @@ -341,6 +371,9 @@ class ZRender { * Get container height */ getHeight(): number { + if(this._disposed) { + return; + } return this.painter.getHeight(); } @@ -381,6 +414,9 @@ class ZRender { */ // eslint-disable-next-line max-len off(eventName?: string, eventHandler?: EventCallback) { + if(this._disposed) { + return; + } this.handler.off(eventName, eventHandler); } @@ -391,6 +427,9 @@ class ZRender { * @param event Event object */ trigger(eventName: string, event?: unknown) { + if(this._disposed) { + return; + } this.handler.trigger(eventName, event); } @@ -399,6 +438,9 @@ class ZRender { * Clear all objects and the canvas. */ clear() { + if(this._disposed) { + return; + } const roots = this.storage.getRoots(); for (let i = 0; i < roots.length; i++) { if (roots[i] instanceof Group) { @@ -425,6 +467,8 @@ class ZRender { this.painter = this.handler = null; + this._disposed = true; + delInstance(this.id); } } From 0b21ebdc43514fdd7ed71743fbd331ce9a521d7e Mon Sep 17 00:00:00 2001 From: plainheart Date: Thu, 21 Dec 2023 01:14:25 +0800 Subject: [PATCH 15/20] fix: add missing disposed check for some methods and fix format flaw --- src/zrender.ts | 54 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/zrender.ts b/src/zrender.ts index 694707783..cbc68005b 100644 --- a/src/zrender.ts +++ b/src/zrender.ts @@ -81,7 +81,7 @@ class ZRender { private _needsRefresh = true private _needsRefreshHover = true - private _disposed = false; + private _disposed: boolean; /** * If theme is dark mode. It will determine the color strategy for labels. */ @@ -154,7 +154,7 @@ class ZRender { * 添加元素 */ add(el: Element) { - if (!el || this._disposed) { + if (this._disposed || !el) { return; } this.storage.addRoot(el); @@ -166,7 +166,7 @@ class ZRender { * 删除元素 */ remove(el: Element) { - if (!el || this._disposed) { + if (this._disposed || !el) { return; } this.storage.delRoot(el); @@ -178,7 +178,7 @@ class ZRender { * Change configuration of layer */ configLayer(zLevel: number, config: LayerConfig) { - if(this._disposed) { + if (this._disposed) { return; } if (this.painter.configLayer) { @@ -191,7 +191,7 @@ class ZRender { * Set background color */ setBackgroundColor(backgroundColor: string | GradientObject | PatternObject) { - if(this._disposed) { + if (this._disposed) { return; } if (this.painter.setBackgroundColor) { @@ -221,7 +221,7 @@ class ZRender { * Repaint the canvas immediately */ refreshImmediately(fromInside?: boolean) { - if(this._disposed) { + if (this._disposed) { return; } // const start = new Date(); @@ -243,7 +243,7 @@ class ZRender { * Mark and repaint the canvas in the next frame of browser */ refresh() { - if(this._disposed) { + if (this._disposed) { return; } this._needsRefresh = true; @@ -255,7 +255,7 @@ class ZRender { * Perform all refresh */ flush() { - if(this._disposed) { + if (this._disposed) { return; } this._flush(false); @@ -303,7 +303,7 @@ class ZRender { * Wake up animation loop. But not render. */ wakeUp() { - if(this._disposed) { + if (this._disposed) { return; } this.animation.start(); @@ -322,7 +322,7 @@ class ZRender { * Refresh hover immediately */ refreshHoverImmediately() { - if(this._disposed) { + if (this._disposed) { return; } this._needsRefreshHover = false; @@ -339,7 +339,7 @@ class ZRender { width?: number| string height?: number | string }) { - if(this._disposed) { + if (this._disposed) { return; } opts = opts || {}; @@ -351,7 +351,7 @@ class ZRender { * Stop and clear all animation immediately */ clearAnimation() { - if(this._disposed) { + if (this._disposed) { return; } this.animation.clear(); @@ -360,8 +360,8 @@ class ZRender { /** * Get container width */ - getWidth(): number { - if(this._disposed) { + getWidth(): number | undefined { + if (this._disposed) { return; } return this.painter.getWidth(); @@ -370,8 +370,8 @@ class ZRender { /** * Get container height */ - getHeight(): number { - if(this._disposed) { + getHeight(): number | undefined { + if (this._disposed) { return; } return this.painter.getHeight(); @@ -382,6 +382,9 @@ class ZRender { * @param cursorStyle='default' 例如 crosshair */ setCursorStyle(cursorStyle: string) { + if (this._disposed) { + return; + } this.handler.setCursorStyle(cursorStyle); } @@ -394,7 +397,10 @@ class ZRender { findHover(x: number, y: number): { target: Displayable topTarget: Displayable - } { + } | undefined { + if (this._disposed) { + return; + } return this.handler.findHover(x, y); } @@ -403,7 +409,9 @@ class ZRender { on(eventName: string, eventHandler: WithThisType, unknown extends Ctx ? ZRenderType : Ctx>, context?: Ctx): this // eslint-disable-next-line max-len on(eventName: string, eventHandler: (...args: any) => any, context?: Ctx): this { - this.handler.on(eventName, eventHandler, context); + if (!this._disposed) { + this.handler.on(eventName, eventHandler, context); + } return this; } @@ -414,7 +422,7 @@ class ZRender { */ // eslint-disable-next-line max-len off(eventName?: string, eventHandler?: EventCallback) { - if(this._disposed) { + if (this._disposed) { return; } this.handler.off(eventName, eventHandler); @@ -427,7 +435,7 @@ class ZRender { * @param event Event object */ trigger(eventName: string, event?: unknown) { - if(this._disposed) { + if (this._disposed) { return; } this.handler.trigger(eventName, event); @@ -438,7 +446,7 @@ class ZRender { * Clear all objects and the canvas. */ clear() { - if(this._disposed) { + if (this._disposed) { return; } const roots = this.storage.getRoots(); @@ -455,6 +463,10 @@ class ZRender { * Dispose self. */ dispose() { + if (this._disposed) { + return; + } + this.animation.stop(); this.clear(); From 52e5155ad19120f9141f5238475c0b85a3ccdbcc Mon Sep 17 00:00:00 2001 From: plainheart Date: Thu, 21 Dec 2023 01:16:49 +0800 Subject: [PATCH 16/20] chore: fix typo --- src/zrender.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zrender.ts b/src/zrender.ts index cbc68005b..90e93af02 100644 --- a/src/zrender.ts +++ b/src/zrender.ts @@ -123,7 +123,7 @@ class ZRender { this.storage = storage; this.painter = painter; - const handerProxy = (!env.node && !env.worker && !ssrMode) + const handlerProxy = (!env.node && !env.worker && !ssrMode) ? new HandlerProxy(painter.getViewportRoot(), painter.root) : null; @@ -137,7 +137,7 @@ class ZRender { pointerSize = zrUtil.retrieve2(opts.pointerSize, defaultPointerSize); } - this.handler = new Handler(storage, painter, handerProxy, painter.root, pointerSize); + this.handler = new Handler(storage, painter, handlerProxy, painter.root, pointerSize); this.animation = new Animation({ stage: { @@ -284,7 +284,7 @@ class ZRender { } else if (this._sleepAfterStill > 0) { this._stillFrameAccum++; - // Stop the animiation after still for 10 frames. + // Stop the animation after still for 10 frames. if (this._stillFrameAccum > this._sleepAfterStill) { this.animation.stop(); } From cd1f473b0b1695296b95aa0d9c61361bce1a034b Mon Sep 17 00:00:00 2001 From: plainheart Date: Sun, 31 Dec 2023 20:14:23 +0800 Subject: [PATCH 17/20] fix(type): make the last two parameters `ellipsis` & `options` of the function `truncateText` optional. resolves apache/echarts#19447 --- src/graphic/helper/parseText.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/graphic/helper/parseText.ts b/src/graphic/helper/parseText.ts index 201d8fc00..275e36b0d 100644 --- a/src/graphic/helper/parseText.ts +++ b/src/graphic/helper/parseText.ts @@ -41,8 +41,8 @@ export function truncateText( text: string, containerWidth: number, font: string, - ellipsis: string, - options: InnerTruncateOption + ellipsis?: string, + options?: InnerTruncateOption ): string { if (!containerWidth) { return ''; @@ -63,8 +63,8 @@ export function truncateText( function prepareTruncateOptions( containerWidth: number, font: string, - ellipsis: string, - options: InnerTruncateOption + ellipsis?: string, + options?: InnerTruncateOption ): InnerPreparedTruncateOption { options = options || {}; let preparedOpts = extend({}, options) as InnerPreparedTruncateOption; From 03d4cec094ebeabc63e1e7c360d50f17c20cc526 Mon Sep 17 00:00:00 2001 From: plainheart Date: Wed, 3 Jan 2024 01:19:53 +0800 Subject: [PATCH 18/20] fix(svg): skip to set SSR attributes with `undefined` values --- src/svg/graphic.ts | 3 +-- src/zrender.ts | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/svg/graphic.ts b/src/svg/graphic.ts index 8f9c08b39..096014967 100644 --- a/src/svg/graphic.ts +++ b/src/svg/graphic.ts @@ -79,8 +79,7 @@ function setMetaData(attrs: SVGVNodeAttrs, el: Path | TSpan | ZRImage) { const metaData = getElementSSRData(el); if (metaData) { metaData.each((val, key) => { - attrs[(META_DATA_PREFIX + key).toLowerCase()] - = val + ''; + val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + ''); }); if (el.isSilent()) { attrs[META_DATA_PREFIX + 'silent'] = 'true'; diff --git a/src/zrender.ts b/src/zrender.ts index 225ca75c0..acafbbffb 100644 --- a/src/zrender.ts +++ b/src/zrender.ts @@ -541,9 +541,7 @@ export function registerPainter(name: string, Ctor: PainterBaseCtor) { export type ElementSSRData = zrUtil.HashMap; export type ElementSSRDataGetter = (el: Element) => zrUtil.HashMap; -let ssrDataGetter = function (el: Element): ElementSSRData { - return null; -} +let ssrDataGetter: ElementSSRDataGetter; export function getElementSSRData(el: Element): ElementSSRData { if (typeof ssrDataGetter === 'function') { From f3b078455f0fbe7679c2e6e72cfa67eed1f890ac Mon Sep 17 00:00:00 2001 From: 100pah Date: Tue, 16 Jan 2024 04:26:00 +0800 Subject: [PATCH 19/20] feat: change to default ESM package. For developer testing and node usage in customization module scenario. See apache/echarts#19513 --- build/package.json | 3 +++ dist/package.json | 3 +++ package.json | 14 +++++++++++++- test/package.json | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 build/package.json create mode 100644 dist/package.json create mode 100644 test/package.json diff --git a/build/package.json b/build/package.json new file mode 100644 index 000000000..6a0d2ef2a --- /dev/null +++ b/build/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} \ No newline at end of file diff --git a/dist/package.json b/dist/package.json new file mode 100644 index 000000000..6a0d2ef2a --- /dev/null +++ b/dist/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} \ No newline at end of file diff --git a/package.json b/package.json index 7c2beebc5..bbd92f092 100644 --- a/package.json +++ b/package.json @@ -59,5 +59,17 @@ "ts-jest": "^27.0.6", "typescript": "^4.4.3", "uglify-js": "^3.10.0" + }, + "type": "module", + "exports": { + ".": { + "types": "./index.d.ts", + "require": "./dist/zrender.js", + "import": "./index.js" + }, + "./*.js": "./*.js", + "./*.ts": "./*.ts", + "./*.json": "./*.json", + "./*": "./*.js" } -} +} \ No newline at end of file diff --git a/test/package.json b/test/package.json new file mode 100644 index 000000000..6a0d2ef2a --- /dev/null +++ b/test/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} \ No newline at end of file From 565dac52837f5c8054b6990741bc29ccc6915a09 Mon Sep 17 00:00:00 2001 From: 100pah Date: Mon, 22 Jan 2024 12:40:36 +0800 Subject: [PATCH 20/20] [lint] enable comma-dangle, which has been deprecated in eslint. --- src/.eslintrc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/.eslintrc.yaml b/src/.eslintrc.yaml index 8fb078f0f..752deedd0 100644 --- a/src/.eslintrc.yaml +++ b/src/.eslintrc.yaml @@ -21,7 +21,7 @@ rules: - "warn" - "error" no-constant-condition: 0 - comma-dangle: 2 + comma-dangle: 0 no-debugger: 2 no-dupe-keys: 2 no-empty-character-class: 2