Adding link labels rewritten

This commit is contained in:
Piotr Pekala 2019-06-06 04:44:32 -07:00
parent db1025d2f7
commit 8a3896af28
2 changed files with 40 additions and 6 deletions

View File

@ -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);
});

View File

@ -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
}
}
]