Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"chai": "^4.3.4",
"chai-almost": "^1.0.1",
"cross-env": "^6.0.3",
"d3": "latest",
"eslint": "^7.28.0",
"eslint-plugin-jest": "24.3.6",
"father": "^2.30.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/g-camera-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-camera-api",
"version": "1.0.21",
"version": "1.0.22",
"description": "A simple implementation of Camera API.",
"keywords": [
"antv",
Expand Down
14 changes: 7 additions & 7 deletions packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "1.9.20",
"version": "1.9.21",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down Expand Up @@ -32,12 +32,12 @@
"sync": "tnpm sync"
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.32",
"@antv/g-plugin-canvas-picker": "^1.8.29",
"@antv/g-plugin-canvas-renderer": "^1.7.35",
"@antv/g-plugin-dom-interaction": "^1.7.32",
"@antv/g-plugin-html-renderer": "^1.7.32",
"@antv/g-plugin-image-loader": "^1.1.33",
"@antv/g-plugin-canvas-path-generator": "^1.1.33",
"@antv/g-plugin-canvas-picker": "^1.8.30",
"@antv/g-plugin-canvas-renderer": "^1.7.36",
"@antv/g-plugin-dom-interaction": "^1.7.33",
"@antv/g-plugin-html-renderer": "^1.7.33",
"@antv/g-plugin-image-loader": "^1.1.34",
"@antv/util": "^3.3.1",
"@types/offscreencanvas": "^2019.6.4",
"tslib": "^2.3.1"
Expand Down
14 changes: 7 additions & 7 deletions packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "0.8.20",
"version": "0.8.21",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down Expand Up @@ -32,12 +32,12 @@
"sync": "tnpm sync"
},
"dependencies": {
"@antv/g-plugin-canvas-path-generator": "^1.1.32",
"@antv/g-plugin-canvas-picker": "^1.8.29",
"@antv/g-plugin-canvaskit-renderer": "^1.1.33",
"@antv/g-plugin-dom-interaction": "^1.7.32",
"@antv/g-plugin-html-renderer": "^1.7.32",
"@antv/g-plugin-image-loader": "^1.1.33",
"@antv/g-plugin-canvas-path-generator": "^1.1.33",
"@antv/g-plugin-canvas-picker": "^1.8.30",
"@antv/g-plugin-canvaskit-renderer": "^1.1.34",
"@antv/g-plugin-dom-interaction": "^1.7.33",
"@antv/g-plugin-html-renderer": "^1.7.33",
"@antv/g-plugin-image-loader": "^1.1.34",
"@antv/util": "^3.3.1",
"canvaskit-wasm": "^0.34.0",
"tslib": "^2.3.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/g-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-components",
"version": "1.7.32",
"version": "1.7.33",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
92 changes: 73 additions & 19 deletions packages/g-components/src/Arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
type: Arrow.tag,
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { body, startHead, endHead, startHeadOffset, endHeadOffset, ...rest } = this.attributes;
const {
body,
startHead,
endHead,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startHeadOffset,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
endHeadOffset,
...rest
} = this.attributes;

if (!body) {
throw new Error("Arrow's body is required");
Expand Down Expand Up @@ -123,24 +131,52 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
name === 'lineWidth' ||
name === 'increasedLineWidthForHitTesting'
) {
this.applyArrowStyle({ [name]: newValue }, [this.body, this.startHead, this.endHead]);
this.applyArrowStyle({ [name]: newValue }, [
this.body,
this.startHead,
this.endHead,
]);
} else if (name === 'startHead' || name === 'endHead') {
const isStart = name === 'startHead';
// delete existed arrow head first
this.destroyArrowHead(isStart);

if (newValue) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { body, startHead, endHead, startHeadOffset, endHeadOffset, ...rest } =
this.attributes;
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
body,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startHead,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
endHead,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startHeadOffset,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
endHeadOffset,
...rest
} = this.attributes;
// append new arrow head

this.appendArrowHead(this.getArrowHeadType(newValue as ArrowHead), isStart);
this.appendArrowHead(
this.getArrowHeadType(newValue as ArrowHead),
isStart,
);
this.applyArrowStyle(rest, [isStart ? this.startHead : this.endHead]);
}
} else if (name === 'body') {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { body, startHead, endHead, startHeadOffset, endHeadOffset, ...rest } = this.attributes;
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
body,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startHead,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
endHead,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startHeadOffset,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
endHeadOffset,
...rest
} = this.attributes;
this.body.destroy();
// @ts-ignore
this.body = newValue;
Expand Down Expand Up @@ -183,7 +219,9 @@ export class Arrow extends CustomElement<ArrowStyleProps> {

this.appendChild(head);

const offset = isStart ? this.attributes.startHeadOffset : this.attributes.endHeadOffset;
const offset = isStart
? this.attributes.startHeadOffset
: this.attributes.endHeadOffset;
if (offset) {
this.moveArrowHeadAlongTangent(offset, isStart);
}
Expand All @@ -203,7 +241,12 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
const bodyType = this.body && this.body.nodeName;

if (bodyType === Shape.LINE) {
const { x1: _x1, x2: _x2, y1: _y1, y2: _y2 } = (this.body as Line).attributes;
const {
x1: _x1,
x2: _x2,
y1: _y1,
y2: _y2,
} = (this.body as Line).attributes;
x1 = isStart ? _x2 : _x1;
x2 = isStart ? _x1 : _x2;
y1 = isStart ? _y2 : _y1;
Expand Down Expand Up @@ -237,7 +280,9 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
}

head.setLocalPosition(position);
head.setLocalEulerAngles((rad * 180) / Math.PI + head.getLocalEulerAngles());
head.setLocalEulerAngles(
(rad * 180) / Math.PI + head.getLocalEulerAngles(),
);
}

private moveArrowHeadAlongTangent(offset: number, isStart: boolean) {
Expand Down Expand Up @@ -291,9 +336,9 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
return new Path({
style: {
// draw an angle '<'
path: `M${10 * cos(PI / 6)},${10 * sin(PI / 6)} L0,0 L${10 * cos(PI / 6)},-${
10 * sin(PI / 6)
}`,
path: `M${10 * cos(PI / 6)},${10 * sin(PI / 6)} L0,0 L${
10 * cos(PI / 6)
},-${10 * sin(PI / 6)}`,
stroke,
lineWidth,
transformOrigin: 'center',
Expand All @@ -302,9 +347,17 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
});
}

private applyArrowStyle(attributes: ArrowStyleProps, objects: (DisplayObject | undefined)[]) {
const { opacity, stroke, strokeOpacity, lineWidth, increasedLineWidthForHitTesting } =
attributes;
private applyArrowStyle(
attributes: ArrowStyleProps,
objects: (DisplayObject | undefined)[],
) {
const {
opacity,
stroke,
strokeOpacity,
lineWidth,
increasedLineWidthForHitTesting,
} = attributes;
objects.forEach((shape) => {
if (shape) {
if (!isNil(opacity)) {
Expand All @@ -324,7 +377,8 @@ export class Arrow extends CustomElement<ArrowStyleProps> {
}

if (!isNil(increasedLineWidthForHitTesting)) {
shape.style.increasedLineWidthForHitTesting = increasedLineWidthForHitTesting;
shape.style.increasedLineWidthForHitTesting =
increasedLineWidthForHitTesting;
}
}
});
Expand Down
Loading