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

fix: polyline & autoscale #35

Merged
merged 2 commits into from
Apr 20, 2023
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vesoft-inc/veditor",
"version": "4.4.3-beta.3",
"version": "4.4.5",
"description": "svg flow editor",
"main": "./dist/VEditor.js",
"types": "./types/index.d.ts",
Expand Down
16 changes: 9 additions & 7 deletions src/Shape/Lines/PolyLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PolyLine: LineRender = {
...Line,
startSpace: 1,
arcRadius: 5,
lineDistance: 50,
makePath(
from: InstanceNodePoint,
to: InstanceNodePoint,
Expand All @@ -26,16 +27,17 @@ const PolyLine: LineRender = {
start.y += startSpace * Math.sin(startAngle);
end.x += endSpace * Math.cos(endAngle);
end.y += endSpace * Math.sin(endAngle);
const disX = end.x - start.x;
const disY = end.y - start.y;

const disX = Math.abs(end.x - start.x);
const disY = Math.abs(end.y - start.y);
const lineDistanceY = this.lineDistance || (disY * .5);
const lineDistanceX = this.lineDistance || (disX * .5);
const paths: any = [{
x: start.x + disX * .5 * Math.cos(startAngle) * (disX > 0 ? 1 : -1),
y: start.y + disY * .5 * Math.sin(startAngle),
x: start.x + lineDistanceX * Math.cos(startAngle) * (disX > 0 ? 1 : -1),
y: start.y + lineDistanceY * Math.sin(startAngle),
type: "L"
}, {
x: end.x + disX * .5 * Math.cos(endAngle) * (disX > 0 ? 1 : -1),
y: end.y + disY * .5 * Math.sin(endAngle),
x: end.x + (disX - lineDistanceX) * Math.cos(endAngle) * (disX > 0 ? 1 : -1),
y: end.y + (disY - lineDistanceY) * Math.sin(endAngle),
type: "L"
}];

Expand Down
4 changes: 3 additions & 1 deletion src/Utils/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Controller extends Utils.Event {
achors: number[] = [];
status: string;
startPosition: { x: any; y: any };
disableScroll: boolean = false;
constructor(editor: VEditor) {
super();
this.editor = editor;
Expand Down Expand Up @@ -113,15 +114,16 @@ class Controller extends Utils.Event {
if (this.status === "disabled") {
return;
}
e.preventDefault();

if (e.ctrlKey) {
// 双指
const newScale = Math.max(1 - e.deltaY * this.scaleRatio, 0.1);
this.zoom(newScale, e.offsetX, e.offsetY);
} else {
if (this.disableScroll) return;
this.pan(-e.deltaX, -e.deltaY);
}
e.preventDefault();
};

panStart = (ev: MouseEvent) => {
Expand Down