Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master to release #1052

Merged
merged 32 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
53a44fb
WIP(ssr): add emphasis style in ssr css apache/echarts#18334
Ovilia Mar 14, 2023
2088b3c
Merge branch 'master' into ssr
Ovilia Mar 28, 2023
26abab1
feat(ssr): add style in meta data
Ovilia Mar 31, 2023
4ca836e
fix(svg): duplicate id for background rect with multiple charts
Ovilia Apr 3, 2023
d7005b8
feat(ssr): improve code
Ovilia May 31, 2023
fb4c265
feat(ssr): provide registerSSRDataGetter
Ovilia Jun 13, 2023
58bcfcf
feat: add `lib/all.js` to sideEffects
liuyang0826 Aug 31, 2023
8129bd8
fix(svg): fix assigning style attribute does not work when CSP is enf…
alxnddr Sep 18, 2023
9263428
Merge pull request #1030 from alxnddr/fix-csp-issue
plainheart Sep 22, 2023
997c753
fix(canvas): remove `__painter` from `Layer` and inject `painter` in …
plainheart Sep 22, 2023
8288aa6
Merge pull request #1032 from ecomfe/fix-canvas-layer-painter
plainheart Sep 23, 2023
ac1bc40
Merge pull request #1029 from liuyang0826/patch-2
plainheart Sep 23, 2023
5e9add1
feat(matrix): allow rotating relative to a point different than the o…
ChepteaCatalin Sep 23, 2023
97f6e72
Merge pull request #1034 from ChepteaCatalin/fix-1033
Ovilia Sep 25, 2023
894f408
fix: detect node21.1.0
Uzlopak Nov 2, 2023
401e314
Merge pull request #1036 from Uzlopak/node-21
plainheart Nov 2, 2023
a78b088
fix(ssr): remove a not used method
Ovilia Nov 16, 2023
1ee4156
fix(svg): remove id
Ovilia Nov 16, 2023
8c6b137
fix: el null check
Ovilia Nov 16, 2023
78f84fd
Merge pull request #999 from ecomfe/ssr
Ovilia Nov 16, 2023
2c11063
Merge pull request #1002 from ecomfe/fix-18194
plainheart Nov 16, 2023
e8cc0f9
fix: avoid errors when executing unfinished operations after calling …
yechunxi Dec 19, 2023
0b21ebd
fix: add missing disposed check for some methods and fix format flaw
plainheart Dec 20, 2023
52e5155
chore: fix typo
plainheart Dec 20, 2023
c4fc3e0
Merge pull request #1031 from yechunxi/master
plainheart Dec 20, 2023
cd1f473
fix(type): make the last two parameters `ellipsis` & `options` of the…
plainheart Dec 31, 2023
03d4cec
fix(svg): skip to set SSR attributes with `undefined` values
plainheart Jan 2, 2024
e7caf87
Merge pull request #1048 from ecomfe/fix/svg-ssr/skip-undefined-attri…
Ovilia Jan 3, 2024
d53f1c8
Merge pull request #1047 from ecomfe/types/truncateText
Ovilia Jan 3, 2024
f3b0784
feat: change to default ESM package. For developer testing and node u…
100pah Jan 15, 2024
565dac5
[lint] enable comma-dangle, which has been deprecated in eslint.
100pah Jan 22, 2024
dbf1bd5
Merge pull request #1051 from ecomfe/module_default_esm
Ovilia Jan 22, 2024
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
3 changes: 3 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"sideEffects": [
"lib/canvas/canvas.js",
"lib/svg/svg.js"
"lib/svg/svg.js",
"lib/all.js"
],
"devDependencies": {
"@microsoft/api-extractor": "^7.7.2",
Expand All @@ -58,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"
}
}
}
2 changes: 1 addition & 1 deletion src/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,22 @@ class Element<Props extends ElementProps = ElementProps> {
}
}

/**
* Return if el.silent or any ancestor element has silent true.
*/
isSilent() {
let isSilent = this.silent;
let ancestor = this.parent;
while (!isSilent && ancestor) {
if (ancestor.silent) {
isSilent = true;
break;
}
ancestor = ancestor.parent;
}
return isSilent;
}

/**
* Update animation targets when reference is changed.
*/
Expand Down
7 changes: 2 additions & 5 deletions src/canvas/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export default class Layer extends Eventful {

private _paintRects: BoundingRect[]

__painter: CanvasPainter

__dirty = true
__firstTimePaint = true

Expand Down Expand Up @@ -311,7 +309,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();
Expand Down Expand Up @@ -449,9 +447,8 @@ export default class Layer extends Eventful {
clearColorGradientOrPattern = createCanvasPattern(
ctx, clearColor, {
dirty() {
// TODO
self.setUnpainted();
self.__painter.refresh();
self.painter.refresh();
}
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export default class CanvasPainter implements PainterBase {

layersMap[zlevel] = layer;

// Vitual layer will not directly show on the screen.
// Virtual layer will not directly show on the screen.
// (It can be a WebGL layer and assigned to a ZRImage element)
// But it still under management of zrender.
if (!layer.virtual) {
Expand All @@ -623,7 +623,7 @@ export default class CanvasPainter implements PainterBase {
}
}

layer.__painter = this;
layer.painter || (layer.painter = this);
}

// Iterate each layer
Expand Down
5 changes: 4 additions & 1 deletion src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ else if (typeof document === 'undefined' && typeof self !== 'undefined') {
// In worker
env.worker = true;
}
else if (typeof navigator === 'undefined') {
else if (
typeof navigator === 'undefined' ||
navigator.userAgent.indexOf('Node.js') === 0
) {
// In node
env.node = true;
env.svgSupported = true;
Expand Down
11 changes: 8 additions & 3 deletions src/core/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ export function translate(out: MatrixArray, a: MatrixArray, v: VectorArray): Mat
/**
* 旋转变换
*/
export function rotate(out: MatrixArray, a: MatrixArray, rad: number): MatrixArray {
export function rotate(
out: MatrixArray,
a: MatrixArray,
rad: number,
pivot: VectorArray = [0, 0]
): MatrixArray {
const aa = a[0];
const ac = a[2];
const atx = a[4];
Expand All @@ -93,8 +98,8 @@ export function rotate(out: MatrixArray, a: MatrixArray, rad: number): MatrixArr
out[1] = -aa * st + ab * ct;
out[2] = ac * ct + ad * st;
out[3] = -ac * st + ct * ad;
out[4] = ct * atx + st * aty;
out[5] = ct * aty - st * atx;
out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
return out;
}

Expand Down
8 changes: 4 additions & 4 deletions src/graphic/helper/parseText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand All @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions src/svg/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ class SVGPainter implements PainterBase {
}

renderToVNode(opts?: {
animation?: boolean
willUpdate?: boolean
animation?: boolean,
willUpdate?: boolean,
compress?: boolean,
useViewBox?: boolean
useViewBox?: boolean,
emphasis?: boolean
}) {

opts = opts || {};
Expand All @@ -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[] = [];

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -374,8 +382,7 @@ function createBackgroundVNode(
width,
height,
x: '0',
y: '0',
id: '0'
y: '0'
}
);
if (isGradient(backgroundColor)) {
Expand Down
12 changes: 10 additions & 2 deletions src/svg/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -128,8 +129,11 @@ export interface BrushScope {

cssNodes: Record<string, CSSSelectorVNode>
cssAnims: Record<string, Record<string, Record<string, string>>>
/**
* Cache for css style string, mapping from style string to class name.
*/
cssStyleCache: Record<string, string>

cssClassIdx: number
cssAnimIdx: number

shadowIdx: number
Expand All @@ -141,6 +145,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.
Expand All @@ -164,8 +172,8 @@ export function createBrushScope(zrId: string): BrushScope {

cssNodes: {},
cssAnims: {},
cssStyleCache: {},

cssClassIdx: 0,
cssAnimIdx: 0,

shadowIdx: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/svg/cssAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Animator from '../animation/Animator';
import CompoundPath from '../graphic/CompoundPath';
import { AnimationEasing } from '../animation/easing';
import { createCubicEasingFunc } from '../animation/cubicEasing';
import { getClassId } from './cssClassId';

export const EASING_MAP: Record<string, string> = {
// From https://easings.net/
Expand Down Expand Up @@ -355,7 +356,7 @@ export function createCSSAnimation(
}

if (cssAnimations.length) {
const className = scope.zrId + '-cls-' + scope.cssClassIdx++;
const className = scope.zrId + '-cls-' + getClassId();
scope.cssNodes['.' + className] = {
animation: cssAnimations.join(',')
};
Expand Down
5 changes: 5 additions & 0 deletions src/svg/cssClassId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let cssClassIdx = 0;

export function getClassId() {
return cssClassIdx++;
}
73 changes: 73 additions & 0 deletions src/svg/cssEmphasis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Displayable from '../graphic/Displayable';
import { liftColor } from '../tool/color';
import { BrushScope, SVGVNodeAttrs } from './core';
import { getClassId } from './cssClassId';

export function createCSSEmphasis(
el: Displayable,
attrs: SVGVNodeAttrs,
scope: BrushScope
) {
if (!el.ignore) {
if (el.isSilent()) {
// If el is silent, it can not be hovered nor selected.
// So set pointer-events to pass through.
const style = {
'pointer-events': 'none'
};
setClassAttribute(style, attrs, scope, true);
}
else {
const emphasisStyle = el.states.emphasis && el.states.emphasis.style
? el.states.emphasis.style
: {};
let fill = emphasisStyle.fill;
if (!fill) {
// No empahsis fill, lift color
const normalFill = el.style && el.style.fill;
const selectFill = el.states.select
&& el.states.select.style
&& el.states.select.style.fill;
const fromFill = el.currentStates.indexOf('select') >= 0
? (selectFill || normalFill)
: normalFill;
if (fromFill) {
fill = liftColor(fromFill);
}
}
let lineWidth = emphasisStyle.lineWidth;
if (lineWidth) {
// Symbols use transform to set size, so lineWidth
// should be divided by scaleX
const scaleX = (!emphasisStyle.strokeNoScale && el.transform)
? el.transform[0]
: 1;
lineWidth = lineWidth / scaleX;
}
const style = {
cursor: 'pointer', // TODO: Should this be customized?
} as any;
if (fill) {
style.fill = fill;
}
if (emphasisStyle.stroke) {
style.stroke = emphasisStyle.stroke;
}
if (lineWidth) {
style['stroke-width'] = lineWidth;
}
setClassAttribute(style, attrs, scope, true);
}
}
}

function setClassAttribute(style: object, attrs: SVGVNodeAttrs, scope: BrushScope, withHover: boolean) {
const styleKey = JSON.stringify(style);
let className = scope.cssStyleCache[styleKey];
if (!className) {
className = scope.zrId + '-cls-' + getClassId();
scope.cssStyleCache[styleKey] = className;
scope.cssNodes['.' + className + (withHover ? ':hover' : '')] = style as any;
}
attrs.class = attrs.class ? (attrs.class + ' ' + className) : className;
}
Loading
Loading