Skip to content

Commit

Permalink
Merge pull request #1545 from VisActor/fix/symbol-array-size
Browse files Browse the repository at this point in the history
fix: fix drawing issue when size is array
  • Loading branch information
neuqzxy authored Nov 20, 2024
2 parents eea8440 + e56384d commit ad4fc01
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-core",
"comment": "fix: fix drawing issue when size is array",
"type": "none"
}
],
"packageName": "@visactor/vrender-core"
}
4 changes: 2 additions & 2 deletions packages/vrender-core/src/graphic/builtin-symbol/arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vrender-core/src/graphic/builtin-symbol/arrow2-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vrender-core/src/graphic/builtin-symbol/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
8 changes: 4 additions & 4 deletions packages/vrender-core/src/graphic/builtin-symbol/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/cross.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/vrender-core/src/graphic/builtin-symbol/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/line-h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/line-v.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/square.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vrender-core/src/graphic/builtin-symbol/star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vrender-core/src/graphic/builtin-symbol/stroke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
Loading

0 comments on commit ad4fc01

Please sign in to comment.