diff --git a/common/changes/@visactor/vrender-core/fix-symbol-array-size_2024-11-13-03-22.json b/common/changes/@visactor/vrender-core/fix-symbol-array-size_2024-11-13-03-22.json new file mode 100644 index 000000000..34751a1e3 --- /dev/null +++ b/common/changes/@visactor/vrender-core/fix-symbol-array-size_2024-11-13-03-22.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender-core", + "comment": "fix: fix drawing issue when size is array", + "type": "none" + } + ], + "packageName": "@visactor/vrender-core" +} \ No newline at end of file diff --git a/packages/vrender-core/src/graphic/builtin-symbol/arrow.ts b/packages/vrender-core/src/graphic/builtin-symbol/arrow.ts index 02f70b605..67af20a99 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/arrow.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/arrow.ts @@ -62,12 +62,12 @@ export class ArrowSymbol extends BaseSymbol implements ISymbolClass { 'M-0.07142857142857142,0.5L0.07142857142857142,0.5L0.07142857142857142,-0.0625L0.2,-0.0625L0,-0.5L-0.2,-0.0625L-0.07142857142857142,-0.0625Z'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return arrow(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return arrow(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-down.ts b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-down.ts index 6dfe2e71b..d15a576ef 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-down.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-down.ts @@ -18,12 +18,12 @@ export class Arrow2DownSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M -0.5 -0.25 L 0 0.25 l 0.5 -0.25'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 4; + const r = this.parseSize(size) / 4; return arrow2Down(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 4 + offset; + const r = this.parseSize(size) / 4 + offset; return arrow2Down(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-left.ts b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-left.ts index f02fa0211..ea4c35f2b 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-left.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-left.ts @@ -48,12 +48,12 @@ export class Arrow2LeftSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M 0.25 -0.5 L -0.25 0 l 0.25 0.5'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 4; + const r = this.parseSize(size) / 4; return arrow2Left(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 4 + offset; + const r = this.parseSize(size) / 4 + offset; return arrow2Left(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-right.ts b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-right.ts index bffd6efaa..4a4e30785 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-right.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-right.ts @@ -48,12 +48,12 @@ export class Arrow2RightSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M -0.25 -0.5 l 0.25 0 l -0.25 0.5'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 4; + const r = this.parseSize(size) / 4; return arrow2Right(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 4 + offset; + const r = this.parseSize(size) / 4 + offset; return arrow2Right(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-up.ts b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-up.ts index 5ad9fed50..b81281ef8 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/arrow2-up.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/arrow2-up.ts @@ -18,12 +18,12 @@ export class Arrow2UpSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M -0.5 0.25 L 0 -0.25 l 0.5 0.25'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 4; + const r = this.parseSize(size) / 4; return arrow2Up(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 4 + offset; + const r = this.parseSize(size) / 4 + offset; return arrow2Up(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/base.ts b/packages/vrender-core/src/graphic/builtin-symbol/base.ts index a966492a4..9640a6976 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/base.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/base.ts @@ -16,4 +16,8 @@ export class BaseSymbol { bounds.y2 = size[1] / 2; } } + + protected parseSize(size: number | [number, number]) { + return isNumber(size) ? size : Math.min(size[0], size[1]); + } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/circle.ts b/packages/vrender-core/src/graphic/builtin-symbol/circle.ts index 567b7196b..9853551cf 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/circle.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/circle.ts @@ -4,7 +4,7 @@ import type { IContext2d, SymbolType, ISymbolClass, IPath2D } from '../../interf import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -37,17 +37,17 @@ export class CircleSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M0.5,0A0.5,0.5,0,1,1,-0.5,0A0.5,0.5,0,1,1,0.5,0'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return circle(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return circle(ctx, r, x, y, z); } drawToSvgPath(size: number, x: number, y: number, z?: number): string { - const r = size / 2; + const r = this.parseSize(size) / 2; return `M ${x - r}, ${y} a ${r},${r} 0 1,0 ${r * 2},0 a ${r},${r} 0 1,0 -${r * 2},0`; } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/close.ts b/packages/vrender-core/src/graphic/builtin-symbol/close.ts index 6299fea90..36c95898f 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/close.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/close.ts @@ -18,17 +18,17 @@ export class CloseSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,-0.5L0.5,0.5,M0.5,-0.5L-0.5,0.5'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return close(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return close(ctx, r, x, y, z); } drawToSvgPath(size: number, x: number, y: number, z?: number): string { - const r = size / 2; + const r = this.parseSize(size) / 2; return `M ${x - r}, ${y - r} L ${x + r},${y + r} M ${x + r}, ${y - r} L ${x - r},${y + r}`; } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/cross.ts b/packages/vrender-core/src/graphic/builtin-symbol/cross.ts index da2395ccf..72b01625d 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/cross.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/cross.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -62,12 +62,12 @@ export class CrossSymbol extends BaseSymbol implements ISymbolClass { 'M-0.5,-0.2L-0.5,0.2L-0.2,0.2L-0.2,0.5L0.2,0.5L0.2,0.2L0.5,0.2L0.5,-0.2L0.2,-0.2L0.2,-0.5L-0.2,-0.5L-0.2,-0.2Z'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 6; + const r = this.parseSize(size) / 6; return cross(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 6; + const r = this.parseSize(size) / 6; return crossOffset(ctx, r, x, y, offset, z); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/diamond.ts b/packages/vrender-core/src/graphic/builtin-symbol/diamond.ts index 5ce4f738b..ac332d9ab 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/diamond.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/diamond.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -37,18 +37,18 @@ export class DiamondSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,0L0,-0.5L0.5,0L0,0.5Z'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return diamond(ctx, r, x, y, z); } // 适应方向的draw drawFitDir(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return diamond(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return diamond(ctx, r, x, y, z); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/line-h.ts b/packages/vrender-core/src/graphic/builtin-symbol/line-h.ts index 21436fee0..4d58a3869 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/line-h.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/line-h.ts @@ -15,17 +15,17 @@ export class LineHSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,0L0.5,0'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return lineH(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return lineH(ctx, r, x, y, z); } drawToSvgPath(size: number, x: number, y: number, z?: number): string { - const r = size / 2; + const r = this.parseSize(size) / 2; return `M ${x - r}, ${y} L ${x + r},${y}`; } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/line-v.ts b/packages/vrender-core/src/graphic/builtin-symbol/line-v.ts index d57767e35..b70206790 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/line-v.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/line-v.ts @@ -15,17 +15,17 @@ export class LineVSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M0,-0.5L0,0.5'; draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return lineV(ctx, r, x, y, z); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number, z?: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return lineV(ctx, r, x, y, z); } drawToSvgPath(size: number, x: number, y: number, z?: number): string { - const r = size / 2; + const r = this.parseSize(size) / 2; return `M ${x}, ${y - r} L ${x},${y + r}`; } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/square.ts b/packages/vrender-core/src/graphic/builtin-symbol/square.ts index baeddc5ee..b786244cb 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/square.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/square.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -32,12 +32,12 @@ export class SquareSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,-0.5h1v1h-1Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return square(ctx, r, x, y); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return square(ctx, r, x, y); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/star.ts b/packages/vrender-core/src/graphic/builtin-symbol/star.ts index c02afe8ac..d96e28ebc 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/star.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/star.ts @@ -4,7 +4,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -51,12 +51,12 @@ export class StarSymbol extends BaseSymbol implements ISymbolClass { 'M0 -1L0.22451398828979266 -0.3090169943749474L0.9510565162951535 -0.30901699437494745L0.3632712640026804 0.1180339887498948L0.5877852522924732 0.8090169943749473L8.326672684688674e-17 0.3819660112501051L-0.587785252292473 0.8090169943749476L-0.3632712640026804 0.11803398874989487L-0.9510565162951536 -0.30901699437494723L-0.22451398828979274 -0.30901699437494734Z'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return star(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return star(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/stroke.ts b/packages/vrender-core/src/graphic/builtin-symbol/stroke.ts index 30fd1513a..db5ba3ecf 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/stroke.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/stroke.ts @@ -45,12 +45,12 @@ export class StrokeSymbol extends BaseSymbol implements ISymbolClass { pathStr: '' = ''; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return stroke(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return stroke(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/thin-triangle.ts b/packages/vrender-core/src/graphic/builtin-symbol/thin-triangle.ts index 01ad3c2b0..b817fcd28 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/thin-triangle.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/thin-triangle.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -37,12 +37,12 @@ export class ThinTriangleSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M0,-0.5773502691896257L-0.5,0.28867513459481287L0.5,0.28867513459481287Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2 / sqrt3; + const r = this.parseSize(size) / 2 / sqrt3; return thinTriangle(ctx, r, x, y); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2 / sqrt3 + offset; + const r = this.parseSize(size) / 2 / sqrt3 + offset; return thinTriangle(ctx, r, x, y); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/triangle-down.ts b/packages/vrender-core/src/graphic/builtin-symbol/triangle-down.ts index 62409766c..192d09582 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/triangle-down.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/triangle-down.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -34,12 +34,12 @@ export class TriangleDownSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,-0.5 L0.5,-0.5 L0,0.5 Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglDownOffset(ctx, r, x, y); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglDownOffset(ctx, r, x, y, offset); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/triangle-left.ts b/packages/vrender-core/src/graphic/builtin-symbol/triangle-left.ts index d856fff8d..53e5f6f27 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/triangle-left.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/triangle-left.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -35,12 +35,12 @@ export class TriangleLeftSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,0 L0.5,0.5 L0.5,-0.5 Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglLeftOffset(ctx, r, x, y, 0); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglLeftOffset(ctx, r, x, y, offset); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/triangle-right.ts b/packages/vrender-core/src/graphic/builtin-symbol/triangle-right.ts index 55b0f8d9a..84cc5e999 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/triangle-right.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/triangle-right.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -35,12 +35,12 @@ export class TriangleRightSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M-0.5,0.5 L0.5,0 L-0.5,-0.5 Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglRightOffset(ctx, r, x, y); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglRightOffset(ctx, r, x, y, offset); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/triangle-up.ts b/packages/vrender-core/src/graphic/builtin-symbol/triangle-up.ts index 818394571..d1cd43966 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/triangle-up.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/triangle-up.ts @@ -3,7 +3,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -35,12 +35,12 @@ export class TriangleUpSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M0.5,0.5 L-0.5,0.5 L0,-0.5 Z'; draw(ctx: IContext2d, size: number, x: number, y: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglUpOffset(ctx, r, x, y); } drawOffset(ctx: IContext2d, size: number, x: number, y: number, offset: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return trianglUpOffset(ctx, r, x, y, offset); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/utils.ts b/packages/vrender-core/src/graphic/builtin-symbol/utils.ts index 9bf034008..ca1259e13 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/utils.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/utils.ts @@ -1,4 +1,4 @@ -import { isArray, type IBounds, AABBBounds } from '@visactor/vutils'; +import { isArray, type IBounds, AABBBounds, isNumber } from '@visactor/vutils'; import { renderCommandList } from '../../common/render-command-list'; import type { IContext2d, ICustomPath2D, IGraphicAttribute, ISymbolClass } from '../../interface'; @@ -33,6 +33,7 @@ export class CustomSymbolClass implements ISymbolClass { z?: number, cb?: (path: ICustomPath2D, attribute?: Record) => void ) { + size = this.parseSize(size); if (this.isSvg) { if (!this.svgCache) { return false; @@ -56,10 +57,16 @@ export class CustomSymbolClass implements ISymbolClass { z?: number, cb?: (path: ICustomPath2D, attribute?: Record) => void ) { + size = this.parseSize(size); return this.drawOffset(ctx, size, x, y, 0, z, cb); } + protected parseSize(size: number | [number, number]): number { + return isNumber(size) ? size : Math.min(size[0], size[1]); + } + bounds(size: number, bounds: IBounds) { + size = this.parseSize(size); if (this.isSvg) { if (!this.svgCache) { return; diff --git a/packages/vrender-core/src/graphic/builtin-symbol/wedge.ts b/packages/vrender-core/src/graphic/builtin-symbol/wedge.ts index b5a9db86a..e87c63f4e 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/wedge.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/wedge.ts @@ -48,12 +48,12 @@ export class WedgeSymbol extends BaseSymbol implements ISymbolClass { pathStr: string = 'M0,-0.5773502691896257L-0.125,0.28867513459481287L0.125,0.28867513459481287Z'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; return wedge(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; return wedge(ctx, r, transX, transY); } } diff --git a/packages/vrender-core/src/graphic/builtin-symbol/wye.ts b/packages/vrender-core/src/graphic/builtin-symbol/wye.ts index 0e8b0202b..76c50a3bf 100644 --- a/packages/vrender-core/src/graphic/builtin-symbol/wye.ts +++ b/packages/vrender-core/src/graphic/builtin-symbol/wye.ts @@ -4,7 +4,7 @@ import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; import { BaseSymbol } from './base'; /** - * + * *Copyright 2010-2021 Mike Bostock Permission to use, copy, modify, and/or distribute this software for any purpose @@ -54,13 +54,13 @@ export class WyeSymbol extends BaseSymbol implements ISymbolClass { 'M0.25 0.14433756729740646L0.25 0.6443375672974064L-0.25 0.6443375672974064L-0.25 0.14433756729740643L-0.6830127018922193 -0.10566243270259357L-0.4330127018922193 -0.5386751345948129L0 -0.28867513459481287L0.4330127018922193 -0.5386751345948129L0.6830127018922193 -0.10566243270259357Z'; draw(ctx: IContext2d, size: number, transX: number, transY: number) { - const r = size / 2; + const r = this.parseSize(size) / 2; // const r = sqrt(size / a); return wye(ctx, r, transX, transY); } drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { - const r = size / 2 + offset; + const r = this.parseSize(size) / 2 + offset; // const r = sqrt(size / a); return wye(ctx, r, transX, transY); }