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

V5 feat/cubic edge,cubic horizon edge,cubic vertical edge #4669

Merged
merged 26 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9fc87a0
chore: update dependencies
liaodalin19903 Jun 8, 2023
b1a8d90
chore: add line-edge integration test
liaodalin19903 Jun 17, 2023
faadec2
chore: done feat/cubic-edge
liaodalin19903 Jun 20, 2023
9f26104
feat: v5-cubic-horizon-edge
liaodalin19903 Jun 21, 2023
6c84d07
feat: v5-cubic-horizon-edge
liaodalin19903 Jun 21, 2023
6d201d5
chore: lint fix & use English comments
liaodalin19903 Jun 25, 2023
0de4a5b
chore: change test svg link & fix cubic offset
liaodalin19903 Jun 25, 2023
b30f916
chore: fix rebase issue
liaodalin19903 Jun 26, 2023
5c7069d
Feat: add 'topRight' position configuration in BadgesShapes (#4624)
zqqcee Jun 12, 2023
ff37289
chore: fix rebase conflict
liaodalin19903 Jun 26, 2023
6443f43
V5 fix label shape error (#4645)
zqqcee Jun 15, 2023
52dfa73
v5-rect#1 (#4640)
zqqcee Jun 15, 2023
a4b7284
fix: implement onZoom as empty function for 3d node (#4647)
Yanyan-Wang Jun 15, 2023
10423fd
add: make the error message more readable (#4666)
zqqcee Jun 25, 2023
7075a15
feat: add contextmenu event for graph canvas, node, and edge (#4675)
Yanyan-Wang Jun 25, 2023
11d4bc7
feat: v5-quadratic (#4656)
zqqcee Jun 25, 2023
b9d2e0c
chore: fix rebase conflicts
liaodalin19903 Jun 26, 2023
043db64
chore: done feat/cubic-edge
liaodalin19903 Jun 20, 2023
0b79959
feat: v5-cubic-horizon-edge
liaodalin19903 Jun 21, 2023
d7991bf
feat: v5-cubic-horizon-edge
liaodalin19903 Jun 21, 2023
e1feab4
chore: lint fix & use English comments
liaodalin19903 Jun 25, 2023
51fce3e
chore: trim up code format
liaodalin19903 Jun 25, 2023
6a48a10
chore: fix base.ts
liaodalin19903 Jun 26, 2023
def9f7e
chore: fix rebase conflicts
liaodalin19903 Jun 26, 2023
b380910
chore: elint fix format
liaodalin19903 Jun 26, 2023
c548095
Merge branch 'v5' into v5-feat/cubic-edge,cubic-horizon-edge,cubic-ve…
liaodalin19903 Jun 26, 2023
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
167,286 changes: 167,286 additions & 0 deletions package-lock.json
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions packages/g6/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
runner: 'jest-electron/runner',
testEnvironment: 'jest-electron/environment',
runner: '@kayahr/jest-electron-runner',
testEnvironment: '@kayahr/jest-electron-runner/environment',
preset: 'ts-jest',
collectCoverage: false,
collectCoverageFrom: [
Expand All @@ -12,13 +12,14 @@ module.exports = {
moduleDirectories: ['node_modules', 'src'],
moduleFileExtensions: ['js', 'ts', 'json'],
moduleNameMapper: {
'@g6/types': '<rootDir>/types',
'@g6/types': '<rootDir>/src/types',
'@g6/(.*)': '<rootDir>/src/$1',
'^d3-(.*)$': `d3-$1/dist/d3-$1`,
'^d3-(.*)$': '<rootDir>/../../node_modules/d3-$1/dist/d3-$1.min.js',
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
},
globals: {
'ts-jest': {
diagnostics: false,
},
},
testTimeout: 450000,
};
17 changes: 8 additions & 9 deletions packages/g6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"fix": "eslint ./src ./tests --fix && prettier ./src ./tests --write ",
"test": "jest",
"size": "limit-size",
"test-live": "DEBUG_MODE=1 jest --watch ./tests/unit/show-animate-spec.ts",
"test-live": "DEBUG_MODE=1 jest --watch ./tests/unit/edge-spec.ts",
"test-behavior": "DEBUG_MODE=1 jest --watch ./tests/unit/item-3d-spec.ts"
},
"lint-staged": {
Expand Down Expand Up @@ -86,29 +86,28 @@
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@umijs/fabric": "^2.0.0",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"eslint": "^7.22.0",
"eslint-plugin-import": "^2.22.1",
"father": "^2.29.1",
"jest": "^26.0.1",
"jest-electron": "^0.1.7",
"jest": "^28.1.3",
"@kayahr/jest-electron-runner": "^5.1.1",
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
"jest-extended": "^0.11.2",
"limit-size": "^0.1.4",
"lint-staged": "^10.5.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"rimraf": "^3.0.0",
"rollup": "^2.39.0",
"rollup": "^2.79.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-polyfill-node": "^0.8.0",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-uglify": "^6.0.4",
"@rollup/plugin-terser": "^0.4.3",
"rollup-plugin-visualizer": "^5.6.0",
"stats.js": "^0.17.0",
"ts-jest": "^24.1.0",
"typedoc": "^0.23.24",
"typescript": "^4.6.3",
"ts-jest": "^28.0.8",
"typedoc": "^0.24.0",
"typescript": "^4.9.5",
"vite": "^4.2.2"
},
"limit-size": [
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { uglify } from 'rollup-plugin-uglify';
import terser from '@rollup/plugin-terser';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
Expand All @@ -21,7 +21,7 @@ module.exports = [
resolve(),
commonjs(),
typescript(),
uglify(),
terser(),
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
...(isBundleVis ? [visualizer()] : []),
],
},
Expand Down
6 changes: 6 additions & 0 deletions packages/g6/src/stdlib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import RotateCanvas3D from './behavior/rotate-canvas-3d';
import TrackCanvas3D from './behavior/track-canvas-3d';
import OrbitCanvas3D from './behavior/orbit-canvas-3d';
import { HoverActivate } from './behavior/hover-activate';
import { CubicEdge } from './item/edge/cubic';
import { CubicHorizonEdge } from './item/edge/cubic-horizon';
import { CubicVerticalEdge } from './item/edge/cubic-vertical';

const stdLib = {
transforms: {
Expand Down Expand Up @@ -62,6 +65,9 @@ const stdLib = {
},
edges: {
'line-edge': LineEdge,
'cubic-edge': CubicEdge,
'cubic-horizon-edge': CubicHorizonEdge,
'cubic-vertical-edge': CubicVerticalEdge
},
combos: {},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/src/stdlib/item/edge/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export abstract class BaseEdge {
}

if (labelShapeProps) {
const referShape = labelBackgroundShape || labelShape;
const referShape = labelBackgroundShape|| labelShape;
const referBounds =
this.boundsCache.labelBackgroundShapeGeometry ||
this.boundsCache.labelShapeGeometry ||
Expand Down
112 changes: 112 additions & 0 deletions packages/g6/src/stdlib/item/edge/cubic-horizon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { DisplayObject, Line } from '@antv/g';
import { EdgeDisplayModel } from 'types';
import { Point } from 'types/common';
import { EdgeModelData, EdgeShapeMap } from 'types/edge';
import { State } from 'types/item';
import { BaseEdge } from './base'
import { IPoint } from '@antv/g6';
import { vec2 } from '@antv/matrix-util';
import { CubicEdge } from './cubic';
import { off } from 'process';

export class CubicHorizonEdge extends CubicEdge {

public type = 'cubic-horizon-edge';

public defaultStyles = {
keyShape: {
x1: 0,
y1: 0,
z1: 0,
x2: 0,
y2: 0,
z2: 0,
isBillboard: true,
},
};
constructor(props) {
super(props);
// suggest to merge default styles like this to avoid style value missing
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
}

/**
* calculate the control points by curvePosition|controlPoints|curveOffset
* @param startPoint: source point position of edge
* @param endPoint target point position of edge
* @param percent the proportion of control points' in the segment, Range 0 to 1
* @param controlPoints the control point position
* @param offset the curveOffset
* @returns control points
*/
protected getControlPoints: (startPoint: Point,
endPoint: Point,
percent: number,
controlPoints: number[],
offset: number
) => [Point, Point] = (
startPoint: Point,
endPoint: Point,
percent = 0.5,
controlPoints,
offset = 20,
) => {

if ((startPoint.x - endPoint.x) * (startPoint.y - endPoint.y ) < 0) {
offset = -offset
}

const controlPoint1: IPoint = this.getControlPoint(startPoint, endPoint, percent, offset)
const controlPoint2: IPoint = this.getControlPoint(startPoint, endPoint, percent, -offset)

return [controlPoint1, controlPoint2]
}

/**
* 根据起始点、相对位置、偏移量计算控制点
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
* @param {IPoint} startPoint 起始点,包含 x,y
* @param {IPoint} endPoint 结束点, 包含 x,y
* @param {Number} percent 相对位置,范围 0-1
* @param {Number} offset 偏移量
* @return {IPoint} 控制点,包含 x,y
*/
protected getControlPoint: (
startPoint: IPoint,
endPoint: IPoint,
percent: number,
offset: number,
) => IPoint =
(startPoint: IPoint,
endPoint: IPoint,
percent = 0,
offset = 0,
) => {

const point: IPoint = {
x: (1 - percent) * startPoint.x + percent * endPoint.x,
y: 0,
};

let tangent: vec2 = [0, 0];
vec2.normalize(tangent, [endPoint.x - startPoint.x, endPoint.y - startPoint.y]);

if (!tangent || (!tangent[0] && !tangent[1])) {
tangent = [0, 0];
}
const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // 垂直向量

point.x += perpendicular[0];
point.y += perpendicular[1];

if(Math.abs(point.x - startPoint.x) < Math.abs(point.x - endPoint.x)) {
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
point.y += startPoint.y
}else {
point.y += endPoint.y
}

return point;
};



}
108 changes: 108 additions & 0 deletions packages/g6/src/stdlib/item/edge/cubic-vertical.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { DisplayObject, Line } from '@antv/g';
import { EdgeDisplayModel } from 'types';
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
import { Point } from 'types/common';
import { EdgeModelData, EdgeShapeMap } from 'types/edge';
import { State } from 'types/item';
liaodalin19903 marked this conversation as resolved.
Show resolved Hide resolved
import { BaseEdge } from './base'
import { IPoint } from '@antv/g6';
import { vec2 } from '@antv/matrix-util';
import { CubicEdge } from './cubic';

export class CubicVerticalEdge extends CubicEdge {

public type = 'cubic-vertical-edge';

public defaultStyles = {
keyShape: {
x1: 0,
y1: 0,
z1: 0,
x2: 0,
y2: 0,
z2: 0,
isBillboard: true,
},
};
constructor(props) {
super(props);
// suggest to merge default styles like this to avoid style value missing
// this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
}

/**
* calculate the control points by curvePosition|controlPoints|curveOffset
* @param startPoint: source point position of edge
* @param endPoint target point position of edge
* @param percent the proportion of control points' in the segment, Range 0 to 1
* @param controlPoints the control point position
* @param offset the curveOffset
* @returns control points
*/
protected getControlPoints: (startPoint: Point,
endPoint: Point,
percent: number,
controlPoints: number[],
offset: number
) => [Point, Point] = (
startPoint: Point,
endPoint: Point,
percent = 0.5,
controlPoints,
offset = 20,
) => {

if ((startPoint.x - endPoint.x) * (startPoint.y - endPoint.y ) > 0) {
offset = -offset
}

const controlPoint1: IPoint = this.getControlPoint(startPoint, endPoint, percent, offset)
const controlPoint2: IPoint = this.getControlPoint(startPoint, endPoint, percent, -offset)

return [controlPoint1, controlPoint2]
}

/**
* 根据起始点、相对位置、偏移量计算控制点
* @param {IPoint} startPoint 起始点,包含 x,y
* @param {IPoint} endPoint 结束点, 包含 x,y
* @param {Number} percent 相对位置,范围 0-1
* @param {Number} offset 偏移量
* @return {IPoint} 控制点,包含 x,y
*/
protected getControlPoint: (
startPoint: IPoint,
endPoint: IPoint,
percent: number,
offset: number,
) => IPoint =
(startPoint: IPoint,
endPoint: IPoint,
percent = 0,
offset = 0,
) => {

const point: IPoint = {
x: 0,
y: (1 - percent) * startPoint.y + percent * endPoint.y,
};

let tangent: vec2 = [0, 0];
vec2.normalize(tangent, [endPoint.x - startPoint.x, endPoint.y - startPoint.y]);

if (!tangent || (!tangent[0] && !tangent[1])) {
tangent = [0, 0];
}
const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // 垂直向量

point.x += perpendicular[0];
point.y += perpendicular[1];

if(Math.abs(point.y - startPoint.y) < Math.abs(point.y - endPoint.y)) {
point.x += startPoint.x
}else {
point.x += endPoint.x
}

return point;
};
}
Loading