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

feat(routers.RightAngle): support user defined vertices #2224

Merged
merged 39 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7ac117e
feat(routers.RightAngle): minor improvements
MartinKanera Jun 16, 2023
dd6a2b9
feat(routers.RightAngle): support vertices
MartinKanera Jun 19, 2023
9be7edc
fix(routers.RightAngle): code improvements
MartinKanera Jun 19, 2023
ef50c74
fix(routers.RightAngle): code improvements
MartinKanera Jun 26, 2023
1ed050b
fix(routers.RightAngle): code improvements
MartinKanera Jun 26, 2023
beb9936
feat(test.Routers): add tests for rightAngle router with vertices
MartinKanera Jun 26, 2023
c819794
fix(test.Routers): code formatting
MartinKanera Jun 26, 2023
87d16e0
fix(routers.RightAngle): code improvements
MartinKanera Jun 26, 2023
836a313
feat(routers.RightAngle): add useVertices option
MartinKanera Jun 26, 2023
e80c5d4
feat(test.Routers): use useVertices option for test purposes
MartinKanera Jun 26, 2023
95c5de1
feat(routers.RightAngle): improve discussed issues
MartinKanera Jul 27, 2023
0b5bc1b
feat(test.Routers): update generated routes for updated rightAngle ro…
MartinKanera Jul 27, 2023
570e47a
feat(routers.RightAngle): new approach to connect vertices
MartinKanera Aug 7, 2023
6ffe3ed
feat(routers.RightAngle): new approach to connect vertices
MartinKanera Sep 14, 2023
e27ccd8
feat(routers.RightAngle): remove duplicit points
MartinKanera Sep 14, 2023
269ebb8
feat(demo): add right angle router playground
MartinKanera Sep 27, 2023
fca782b
feat(routers.RightAngle): improve behaviour
MartinKanera Sep 27, 2023
ae4c2b0
feat(demo): add resize tool to the playground
MartinKanera Sep 27, 2023
0204306
feat(demo): add link to link example
MartinKanera Oct 12, 2023
8262fcd
feat(routers.RightAngle): improve last segment of the route
MartinKanera Oct 12, 2023
2875233
feat(routers.RightAngle): working solution for vertex inside of a bbo…
MartinKanera Oct 13, 2023
2050eb3
fix(routers.RightAngle): remove redundant points when no vertices pro…
MartinKanera Oct 13, 2023
5704fc3
fix(test.Routers): fix tests for new routing solution
MartinKanera Oct 13, 2023
bd3e587
feat(test.Routers): add tests for vertex positioned in bbox of source…
MartinKanera Oct 13, 2023
37164ee
chore(routers.RightAngle): remove unused margin parameter
MartinKanera Oct 14, 2023
508091c
feat(routers.RightAngle): construct a loop in edge cases
MartinKanera Oct 16, 2023
4921105
fix(routers.RightAngle): wrong route
MartinKanera Oct 16, 2023
0c35937
feat(test.Routers): change tests to match with changes made to the ro…
MartinKanera Oct 16, 2023
8feb0c2
feat(routers.RightAngle): first segment route improvements
MartinKanera Oct 16, 2023
d898c73
feat(test.Routers): change tests to match with changes made to the ro…
MartinKanera Oct 16, 2023
38f99d7
fix(routers.RightAngle): wrong route
MartinKanera Oct 17, 2023
790364a
feat(test.Routers): change tests to match with changes made to the ro…
MartinKanera Oct 17, 2023
8127f6b
feat(routers.RightAngle): vertex in the target bbox improvements
MartinKanera Oct 17, 2023
deeff21
fix(routers.RightAngle): correct route for source: bottom and target:…
MartinKanera Oct 18, 2023
e924e70
fix(routers.RightAngle): no loop for straight overlapping segments
MartinKanera Oct 18, 2023
82dbe73
feat(demo.rightAngle): change resizing and size of anchor tools
MartinKanera Oct 19, 2023
e55afa3
feat(types): mark the useVertices option as experimental
MartinKanera Oct 19, 2023
496b7d5
feat(routers.RightAngle): small code improvements and route optimization
MartinKanera Oct 19, 2023
a82c46f
Update comments
kumilingus Oct 20, 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
9 changes: 9 additions & 0 deletions demo/right-angle-playground/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
body {
margin: 0;
padding: 0;
}

#paper {
position: absolute;
inset: 0 0 0 0;
}
18 changes: 18 additions & 0 deletions demo/right-angle-playground/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8"/>
<title>Right angle router playground</title>
<link rel="stylesheet" type="text/css" href="../../build/joint.css" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<div id="paper"></div>
<!-- Dependencies: -->
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="../../node_modules/lodash/lodash.js"></script>
<script src="../../node_modules/backbone/backbone.js"></script>
<script src="../../build/joint.js"></script>
<script src="./src/index.js"></script>
</body>
</html>
170 changes: 170 additions & 0 deletions demo/right-angle-playground/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
const { dia, shapes, linkTools, elementTools } = joint;
class ResizeTool extends elementTools.Control {
getPosition(view) {
const model = view.model;
const { width, height } = model.size();
return { x: width, y: height };
}

setPosition(view, coordinates) {
const model = view.model;
model.resize(
Math.max(Math.round(coordinates.x / 2) * 2, 10),
Math.max(Math.round(coordinates.y / 2) * 2, 10)
);
}
}

const graph = new dia.Graph();

const paper = new dia.Paper({
el: document.getElementById('paper'),
width: '100%',
height: '100%',
gridSize: 10,
async: true,
frozen: true,
model: graph,
defaultRouter: { name: 'rightAngle', args: { useVertices: true }},
defaultConnector: { name: 'rounded' },
background: {
color: '#151D29'
},
defaultLinkAnchor: {
name: 'connectionRatio',
args: {
ratio: 0.25
}
}
});

const rect = new shapes.standard.Rectangle({
position: { x: 120, y: 120 },
size: { width: 220, height: 60 },
attrs: {
body: {
stroke: 'none',
fill: '#DF423D',
rx: 10,
ry: 10,
}
}
});

const rect2 = rect.clone();

rect2.resize(60, 220);
rect2.position(400, 700);

const link = new shapes.standard.Link({
attrs: {
line: {
stroke: 'white'
}
}
});

const link2 = link.clone();

link.source({ id: rect.id, anchor: { name: 'top' }});
link.target({ id: rect2.id, anchor: { name: 'right' }});
link.vertices([
{ x: 370, y: 420 },
{ x: 500, y: 500 }
]);

link2.source({ x: 670, y: 100 });
link2.target({ x: 800, y: 800 });
link2.vertices([
{ x: 670, y: 420 },
{ x: 800, y: 500 },
]);

const link3 = link.clone();
link3.attr('line/stroke', '#DF423D');
link3.source({ x: 1000, y: 600 });
link3.target({ id: link2.id });
link3.vertices([{ x: 900, y: 400 }]);

graph.addCells([rect, rect2, link, link2, link3]);

rect.findView(paper).addTools(
new dia.ToolsView({
tools: [
new ResizeTool({
selector: 'body'
})
]
})
);

rect2.findView(paper).addTools(
new dia.ToolsView({
tools: [
new ResizeTool({
selector: 'body'
})
]
})
);

const linkToolsView = new dia.ToolsView({
tools: [
new linkTools.Vertices({
focusOpacity: 0.5,
}),
new linkTools.TargetAnchor({
focusOpacity: 0.5,
scale: 1.2
}),
new linkTools.SourceAnchor({
focusOpacity: 0.5,
scale: 1.2
}),
]
});

link.findView(paper).addTools(linkToolsView);

const link2ToolsView = new dia.ToolsView({
tools: [
new linkTools.Vertices({
focusOpacity: 0.5
}),
new linkTools.SourceArrowhead({
focusOpacity: 0.5
}),
new linkTools.TargetArrowhead({
focusOpacity: 0.5
})
]
});

link2.findView(paper).addTools(link2ToolsView);

const link3ToolsView = new dia.ToolsView({
tools: [
new linkTools.Vertices({
focusOpacity: 0.5
})
]
});

link3.findView(paper).addTools(link3ToolsView);

function scaleToFit() {
const graphBBox = graph.getBBox();
paper.scaleContentToFit({
contentArea: graphBBox.clone().inflate(0, 100)
});
const { sy } = paper.scale();
const area = paper.getArea();
const yTop = area.height / 2 - graphBBox.y - graphBBox.height / 2;
const xLeft = area.width / 2 - graphBBox.x - graphBBox.width / 2;
paper.translate(xLeft * sy, yTop * sy);
}

window.addEventListener('resize', () => scaleToFit());
scaleToFit();

paper.unfreeze();
Loading