mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-04-08 02:54:16 +00:00
Adding link labels rewritten
This commit is contained in:
parent
db1025d2f7
commit
8a3896af28
@ -35,12 +35,45 @@ export class LinkCreatedComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onLinkCreated(linkCreated: MapLinkCreated) {
|
||||
const xLength = Math.abs(linkCreated.sourceNode.x - linkCreated.targetNode.x);
|
||||
const yLength = Math.abs(linkCreated.sourceNode.y - linkCreated.targetNode.y);
|
||||
const zLength = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2));
|
||||
const x = (45 / zLength) * xLength;
|
||||
const y = (45 / zLength) * yLength;
|
||||
|
||||
let xLabelSourceNode = 0;
|
||||
let yLabelSourceNode = 0;
|
||||
let xLabelTargetNode = 0;
|
||||
let yLabelTargetNode = 0;
|
||||
|
||||
if ((linkCreated.sourceNode.x < linkCreated.targetNode.x) && (linkCreated.sourceNode.y < linkCreated.targetNode.y)) {//tested right side
|
||||
xLabelSourceNode = Math.round(x) + 24 + 10;
|
||||
yLabelSourceNode = Math.round(y) + 24 + 10;
|
||||
xLabelTargetNode = Math.round(x) - 24 - 10;
|
||||
yLabelTargetNode = Math.round(y) - 24 - 10;
|
||||
} else if ((linkCreated.sourceNode.x > linkCreated.targetNode.x) && (linkCreated.sourceNode.y < linkCreated.targetNode.y)) {
|
||||
xLabelSourceNode = Math.round(x) - 24 - 10;
|
||||
yLabelSourceNode = Math.round(y) + 24 + 10;
|
||||
xLabelTargetNode = Math.round(x) + 24 + 10;
|
||||
yLabelTargetNode = Math.round(y) - 24 - 10;
|
||||
} else if ((linkCreated.sourceNode.x < linkCreated.targetNode.x) && (linkCreated.sourceNode.y > linkCreated.targetNode.y)) {//tested right side
|
||||
xLabelSourceNode = Math.round(x) + 24 + 10;
|
||||
yLabelSourceNode = Math.round(y) - 24 - 10;
|
||||
xLabelTargetNode = Math.round(x) - 24 - 10;
|
||||
yLabelTargetNode = Math.round(y) + 24 + 10;
|
||||
} else if ((linkCreated.sourceNode.x > linkCreated.targetNode.x) && (linkCreated.sourceNode.y > linkCreated.targetNode.y)) {
|
||||
xLabelSourceNode = Math.round(x) - 24 - 10;
|
||||
yLabelSourceNode = Math.round(y) - 24 - 10;
|
||||
xLabelTargetNode = Math.round(x) + 24 + 10;
|
||||
yLabelTargetNode = Math.round(y) + 24 + 10;
|
||||
}
|
||||
|
||||
const sourceNode = this.mapNodeToNode.convert(linkCreated.sourceNode);
|
||||
const sourcePort = this.mapPortToPort.convert(linkCreated.sourcePort);
|
||||
const targetNode = this.mapNodeToNode.convert(linkCreated.targetNode);
|
||||
const targetPort = this.mapPortToPort.convert(linkCreated.targetPort);
|
||||
|
||||
this.linkService.createLink(this.server, sourceNode, sourcePort, targetNode, targetPort).subscribe(() => {
|
||||
this.linkService.createLink(this.server, sourceNode, sourcePort, targetNode, targetPort, xLabelSourceNode, yLabelSourceNode, xLabelTargetNode, yLabelTargetNode).subscribe(() => {
|
||||
this.projectService.links(this.server, this.project.project_id).subscribe((links: Link[]) => {
|
||||
this.linksDataSource.set(links);
|
||||
});
|
||||
|
@ -14,7 +14,8 @@ import { CapturingSettings } from '../models/capturingSettings';
|
||||
export class LinkService {
|
||||
constructor(private httpServer: HttpServer) {}
|
||||
|
||||
createLink(server: Server, source_node: Node, source_port: Port, target_node: Node, target_port: Port) {
|
||||
createLink(server: Server, source_node: Node, source_port: Port, target_node: Node, target_port: Port,
|
||||
xLabelSourceNode: number, yLabelSourceNode: number, xLabelTargetNode: number, yLabelTargetNode: number) {
|
||||
return this.httpServer.post(server, `/projects/${source_node.project_id}/links`, {
|
||||
nodes: [
|
||||
{
|
||||
@ -25,8 +26,8 @@ export class LinkService {
|
||||
rotation: 0,
|
||||
style: "font-size: 10; font-style: Verdana",
|
||||
text: "0/0",
|
||||
x: -20,
|
||||
y: -20
|
||||
x: xLabelSourceNode,
|
||||
y: yLabelSourceNode
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -37,8 +38,8 @@ export class LinkService {
|
||||
rotation: 0,
|
||||
style: "font-size: 10; font-style: Verdana",
|
||||
text: "0/0",
|
||||
x: -20,
|
||||
y: -20
|
||||
x: xLabelTargetNode,
|
||||
y: yLabelTargetNode
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user