mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-17 22:38:08 +00:00
Preparation for interfaces labels
This commit is contained in:
8
src/app/cartography/shared/models/link-node.ts
Normal file
8
src/app/cartography/shared/models/link-node.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Label } from "./label";
|
||||||
|
|
||||||
|
export class LinkNode {
|
||||||
|
node_id: string;
|
||||||
|
adapter_number: number;
|
||||||
|
port_number: number;
|
||||||
|
label: Label;
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
export class LinkStatus {
|
export class LinkStatus {
|
||||||
public constructor(public x: number, public y: number, public status: string) {}
|
public constructor(
|
||||||
|
public x: number,
|
||||||
|
public y: number,
|
||||||
|
public status: string
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import {Node} from "./node";
|
import { Node } from "./node";
|
||||||
import {Selectable} from "../managers/selection-manager";
|
import { LinkNode } from "./link-node";
|
||||||
|
import { Selectable } from "../managers/selection-manager";
|
||||||
|
|
||||||
|
|
||||||
export class Link implements Selectable {
|
export class Link implements Selectable {
|
||||||
capture_file_name: string;
|
capture_file_name: string;
|
||||||
@ -7,7 +9,7 @@ export class Link implements Selectable {
|
|||||||
capturing: boolean;
|
capturing: boolean;
|
||||||
link_id: string;
|
link_id: string;
|
||||||
link_type: string;
|
link_type: string;
|
||||||
nodes: Node[];
|
nodes: LinkNode[];
|
||||||
project_id: string;
|
project_id: string;
|
||||||
distance: number; // this is not from server
|
distance: number; // this is not from server
|
||||||
length: number; // this is not from server
|
length: number; // this is not from server
|
||||||
|
30
src/app/cartography/shared/widgets/interface-label.ts
Normal file
30
src/app/cartography/shared/widgets/interface-label.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { SVGSelection } from "../models/types";
|
||||||
|
import { Link } from "../models/link";
|
||||||
|
|
||||||
|
|
||||||
|
export class InterfaceLabelWidget {
|
||||||
|
draw(selection: SVGSelection) {
|
||||||
|
|
||||||
|
const labels = selection
|
||||||
|
.selectAll<SVGTextElement, Link>('text.interface_label')
|
||||||
|
.data((l: Link) => [l]);
|
||||||
|
|
||||||
|
const enter = labels
|
||||||
|
.enter()
|
||||||
|
.append<SVGTextElement>('text')
|
||||||
|
.attr('class', 'interface_label');
|
||||||
|
|
||||||
|
const merge = labels
|
||||||
|
.merge(enter);
|
||||||
|
|
||||||
|
merge
|
||||||
|
.text((l: Link) => l.nodes[0].label.text)
|
||||||
|
.attr('x', (l: Link) => Math.round(l.source.x + l.nodes[0].label.x))
|
||||||
|
.attr('y', (l: Link) => Math.round(l.source.y + l.nodes[0].label.y));
|
||||||
|
|
||||||
|
labels
|
||||||
|
.exit()
|
||||||
|
.remove();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import { MultiLinkCalculatorHelper } from "../../map/helpers/multi-link-calculat
|
|||||||
import { SerialLinkWidget } from "./serial-link";
|
import { SerialLinkWidget } from "./serial-link";
|
||||||
import { EthernetLinkWidget } from "./ethernet-link";
|
import { EthernetLinkWidget } from "./ethernet-link";
|
||||||
import { Layer } from "../models/layer";
|
import { Layer } from "../models/layer";
|
||||||
|
import { InterfaceLabelWidget } from "./interface-label";
|
||||||
|
|
||||||
|
|
||||||
export class LinksWidget implements Widget {
|
export class LinksWidget implements Widget {
|
||||||
@ -95,6 +96,9 @@ export class LinksWidget implements Widget {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const interfaceLabel = new InterfaceLabelWidget();
|
||||||
|
interfaceLabel.draw(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public draw(view: SVGSelection, links?: Link[]) {
|
public draw(view: SVGSelection, links?: Link[]) {
|
||||||
@ -124,6 +128,7 @@ export class LinksWidget implements Widget {
|
|||||||
|
|
||||||
this.revise(merge);
|
this.revise(merge);
|
||||||
|
|
||||||
|
|
||||||
link
|
link
|
||||||
.exit()
|
.exit()
|
||||||
.remove();
|
.remove();
|
||||||
|
Reference in New Issue
Block a user