Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an 'AS IS' BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import * as d3 from 'd3'; |
| 17 | import {LocationType} from '../../backgroundsvg/backgroundsvg.component'; |
| 18 | import { |
| 19 | LayerType, |
| 20 | Location, |
| 21 | NodeType, |
| 22 | RegionProps |
| 23 | } from './regions'; |
| 24 | |
| 25 | /** |
| 26 | * Toggle state for how labels should be displayed |
| 27 | */ |
| 28 | export enum LabelToggle { |
| 29 | NONE, |
| 30 | ID, |
| 31 | NAME |
| 32 | } |
| 33 | |
| 34 | export namespace LabelToggle { |
| 35 | export function next(current: LabelToggle) { |
| 36 | if (current === LabelToggle.NONE) { |
| 37 | return LabelToggle.ID; |
| 38 | } else if (current === LabelToggle.ID) { |
| 39 | return LabelToggle.NAME; |
| 40 | } else if (current === LabelToggle.NAME) { |
| 41 | return LabelToggle.NONE; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * model of the topo2CurrentRegion device props from Device below |
| 48 | */ |
| 49 | export interface DeviceProps { |
| 50 | latitude: number; |
| 51 | longitude: number; |
| 52 | name: string; |
| 53 | locType: LocationType; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * model of the topo2CurrentRegion Loc part of the MetaUi below |
| 58 | */ |
| 59 | export interface LocMeta { |
| 60 | lng: number; |
| 61 | lat: number; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * model of the topo2CurrentRegion MetaUi from Device below |
| 66 | */ |
| 67 | export interface MetaUi { |
| 68 | equivLoc: LocMeta; |
| 69 | x: number; |
| 70 | y: number; |
| 71 | } |
| 72 | |
| 73 | export interface HostProps { |
| 74 | gridX: number; |
| 75 | gridY: number; |
| 76 | latitude: number; |
| 77 | longitude: number; |
| 78 | locType: LocationType; |
| 79 | name: string; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Implementing SimulationNodeDatum interface into our custom Node class |
| 84 | */ |
| 85 | export abstract class Node implements d3.SimulationNodeDatum { |
| 86 | // Optional - defining optional implementation properties - required for relevant typing assistance |
| 87 | index?: number; |
| 88 | x: number; |
| 89 | y: number; |
| 90 | vx?: number; |
| 91 | vy?: number; |
| 92 | fx?: number | null; |
| 93 | fy?: number | null; |
| 94 | |
| 95 | id: string; |
| 96 | |
| 97 | protected constructor(id) { |
| 98 | this.id = id; |
| 99 | this.x = 0; |
| 100 | this.y = 0; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * model of the topo2CurrentRegion device from Region below |
| 106 | */ |
| 107 | export class Device extends Node { |
| 108 | id: string; |
| 109 | layer: LayerType; |
| 110 | location: LocationType; |
| 111 | metaUi: MetaUi; |
| 112 | master: string; |
| 113 | nodeType: NodeType; |
| 114 | online: boolean; |
| 115 | props: DeviceProps; |
| 116 | type: string; |
| 117 | |
| 118 | constructor(id: string) { |
| 119 | super(id); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | export class Host extends Node { |
| 124 | configured: boolean; |
| 125 | id: string; |
| 126 | ips: string[]; |
| 127 | layer: LayerType; |
| 128 | nodeType: NodeType; |
| 129 | props: HostProps; |
| 130 | |
| 131 | constructor(id: string) { |
| 132 | super(id); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /** |
| 138 | * model of the topo2CurrentRegion subregion from Region below |
| 139 | */ |
| 140 | export class SubRegion extends Node { |
| 141 | id: string; |
| 142 | location: Location; |
| 143 | nDevs: number; |
| 144 | nHosts: number; |
| 145 | name: string; |
| 146 | nodeType: NodeType; |
| 147 | props: RegionProps; |
| 148 | |
| 149 | constructor(id: string) { |
| 150 | super(id); |
| 151 | } |
| 152 | } |