-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from VisActor/feat/symbol-enhance
- Loading branch information
Showing
19 changed files
with
500 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/vrender/src/graphic/builtin-symbol/arrow2-down.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { IBounds } from '@visactor/vutils'; | ||
import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; | ||
|
||
export function arrow2Down(ctx: IContext2d, r: number, transX: number, transY: number) { | ||
const r2 = r * 2; | ||
ctx.moveTo(transX - r2, transY - r); | ||
ctx.lineTo(transX, transY + r); | ||
ctx.lineTo(transX + r2, transY - r); | ||
|
||
return true; | ||
} | ||
|
||
// 以中心为锚点,size为circle外接正方形的面积 | ||
export class Arrow2DownSymbol implements ISymbolClass { | ||
type: SymbolType = 'arrow2Down'; | ||
/* eslint-disable max-len */ | ||
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; | ||
return arrow2Down(ctx, r, transX, transY); | ||
} | ||
|
||
drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { | ||
const r = size / 4 + offset; | ||
return arrow2Down(ctx, r, transX, transY); | ||
} | ||
|
||
bounds(size: number, bounds: IBounds) { | ||
const r = size / 2; | ||
bounds.x1 = -r; | ||
bounds.x2 = r; | ||
bounds.y1 = -r; | ||
bounds.y2 = r; | ||
} | ||
} | ||
|
||
export default new Arrow2DownSymbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { IBounds } from '@visactor/vutils'; | ||
import type { IContext2d, SymbolType, ISymbolClass } from '../../interface'; | ||
|
||
export function arrow2Up(ctx: IContext2d, r: number, transX: number, transY: number) { | ||
const r2 = r * 2; | ||
ctx.moveTo(transX - r2, transY + r); | ||
ctx.lineTo(transX, transY - r); | ||
ctx.lineTo(transX + r2, transY + r); | ||
|
||
return true; | ||
} | ||
|
||
// 以中心为锚点,size为circle外接正方形的面积 | ||
export class Arrow2UpSymbol implements ISymbolClass { | ||
type: SymbolType = 'arrow2Up'; | ||
/* eslint-disable max-len */ | ||
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; | ||
return arrow2Up(ctx, r, transX, transY); | ||
} | ||
|
||
drawOffset(ctx: IContext2d, size: number, transX: number, transY: number, offset: number) { | ||
const r = size / 4 + offset; | ||
return arrow2Up(ctx, r, transX, transY); | ||
} | ||
|
||
bounds(size: number, bounds: IBounds) { | ||
const r = size / 2; | ||
bounds.x1 = -r; | ||
bounds.x2 = r; | ||
bounds.y1 = -r; | ||
bounds.y2 = r; | ||
} | ||
} | ||
|
||
export default new Arrow2UpSymbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { IBounds } from '@visactor/vutils'; | ||
import { tau } from '@visactor/vutils'; | ||
import type { IContext2d, SymbolType, ISymbolClass, IPath2D } from '../../interface'; | ||
|
||
export function close(ctx: IContext2d, r: number, x: number, y: number, z?: number) { | ||
ctx.moveTo(x - r, y - r); | ||
ctx.lineTo(x + r, y + r); | ||
|
||
ctx.moveTo(x + r, y - r); | ||
ctx.lineTo(x - r, y + r); | ||
return true; | ||
} | ||
|
||
// 以中心为锚点,size为circle外接正方形的面积 | ||
export class CloseSymbol implements ISymbolClass { | ||
type: SymbolType = 'close'; | ||
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; | ||
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; | ||
return close(ctx, r, x, y, z); | ||
} | ||
|
||
drawToSvgPath(size: number, x: number, y: number, z?: number): string { | ||
const r = size / 2; | ||
return `M ${x - r}, ${y - r} L ${x + r},${y + r} M ${x + r}, ${y - r} L ${x - r},${y + r}`; | ||
} | ||
|
||
bounds(size: number, bounds: IBounds) { | ||
const r = size / 2; | ||
bounds.x1 = -r; | ||
bounds.x2 = r; | ||
bounds.y1 = -r; | ||
bounds.y2 = r; | ||
} | ||
} | ||
|
||
export default new CloseSymbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { IBounds } from '@visactor/vutils'; | ||
import { tau } from '@visactor/vutils'; | ||
import type { IContext2d, SymbolType, ISymbolClass, IPath2D } from '../../interface'; | ||
|
||
export function lineH(ctx: IContext2d, r: number, x: number, y: number, z?: number) { | ||
ctx.moveTo(x - r, y); | ||
ctx.lineTo(x + r, y); | ||
return true; | ||
} | ||
|
||
// 以中心为锚点,size为circle外接正方形的面积 | ||
export class LineHSymbol implements ISymbolClass { | ||
type: SymbolType = 'lineH'; | ||
pathStr: string = 'M-0.5,0L0.5,0'; | ||
|
||
draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { | ||
const r = 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; | ||
return lineH(ctx, r, x, y, z); | ||
} | ||
|
||
drawToSvgPath(size: number, x: number, y: number, z?: number): string { | ||
const r = size / 2; | ||
return `M ${x - r}, ${y} L ${x + r},${y}`; | ||
} | ||
|
||
bounds(size: number, bounds: IBounds) { | ||
const r = size / 2; | ||
bounds.x1 = -r; | ||
bounds.x2 = r; | ||
bounds.y1 = -r; | ||
bounds.y2 = r; | ||
} | ||
} | ||
|
||
export default new LineHSymbol(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { IBounds } from '@visactor/vutils'; | ||
import { tau } from '@visactor/vutils'; | ||
import type { IContext2d, SymbolType, ISymbolClass, IPath2D } from '../../interface'; | ||
|
||
export function lineV(ctx: IContext2d, r: number, x: number, y: number, z?: number) { | ||
ctx.moveTo(x, y - r); | ||
ctx.lineTo(x, y + r); | ||
return true; | ||
} | ||
|
||
// 以中心为锚点,size为circle外接正方形的面积 | ||
export class LineVSymbol implements ISymbolClass { | ||
type: SymbolType = 'lineV'; | ||
pathStr: string = 'M0,-0.5L0,0.5'; | ||
|
||
draw(ctx: IContext2d, size: number, x: number, y: number, z?: number) { | ||
const r = 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; | ||
return lineV(ctx, r, x, y, z); | ||
} | ||
|
||
drawToSvgPath(size: number, x: number, y: number, z?: number): string { | ||
const r = size / 2; | ||
return `M ${x}, ${y - r} L ${x},${y + r}`; | ||
} | ||
|
||
bounds(size: number, bounds: IBounds) { | ||
const r = size / 2; | ||
bounds.x1 = -r; | ||
bounds.x2 = r; | ||
bounds.y1 = -r; | ||
bounds.y2 = r; | ||
} | ||
} | ||
|
||
export default new LineVSymbol(); |
Oops, something went wrong.