Max Chu | 6a4bb65 | 2017-09-29 17:15:56 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an 'AS IS' BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | import {IMicrosemiStats, IMicrosemiStatsData} from './stats-service'; |
| 19 | import './cfmstat.component.scss'; |
| 20 | |
| 21 | class CfmStatComponent { |
| 22 | static $inject = [ |
| 23 | '$interval', |
| 24 | '$stateParams', |
| 25 | 'MicrosemiStats' |
| 26 | ]; |
| 27 | |
| 28 | public options = { |
| 29 | animation: { |
| 30 | duration: 0 |
| 31 | }, |
| 32 | scales: { |
| 33 | yAxes: [{ |
| 34 | ticks: { |
| 35 | beginAtZero: true, |
| 36 | fontColor: '#fff', |
| 37 | }, |
| 38 | gridLines: { |
| 39 | color: '#555', |
| 40 | zeroLineColor: '#888' |
| 41 | } |
| 42 | }], |
| 43 | xAxes: [{ |
| 44 | ticks: { |
| 45 | beginAtZero: true, |
| 46 | fontColor: '#fff', |
| 47 | }, |
| 48 | gridLines: { |
| 49 | color: '#555' |
| 50 | } |
| 51 | }] |
| 52 | }, |
| 53 | |
| 54 | }; |
| 55 | |
| 56 | public lineOptions = { |
| 57 | animation: { |
| 58 | duration: 0 |
| 59 | }, |
| 60 | scales: { |
| 61 | yAxes: [{ |
| 62 | ticks: { |
| 63 | beginAtZero: true, |
| 64 | callback: val => `${(Math.round(val * 1000) / 1000).toFixed(3)} ms`, |
| 65 | fontColor: '#fff', |
| 66 | }, |
| 67 | gridLines: { |
| 68 | color: '#555', |
| 69 | zeroLineColor: '#888' |
| 70 | } |
| 71 | }], |
| 72 | xAxes: [{ |
| 73 | ticks: { |
| 74 | beginAtZero: true, |
| 75 | fontColor: '#fff', |
| 76 | }, |
| 77 | gridLines: { |
| 78 | color: '#555', |
| 79 | } |
| 80 | }] |
| 81 | }, |
| 82 | bezierCurve: false |
| 83 | }; |
| 84 | |
| 85 | public lineChart = { |
| 86 | series: ['Jitter Avg', 'Jitter Max', 'Jitter Min', 'Delay Avg', 'Delay Max', 'Delay Min'], |
| 87 | labels: [], |
| 88 | data: [], |
| 89 | dataset: [] |
| 90 | }; |
| 91 | |
| 92 | public delayBin = { |
| 93 | series: ['Current Delay Bin'], |
| 94 | labels: ['0 - 10 ms', '10 - 20 ms', '20 - 37 ms', '> 37 ms'], |
| 95 | data: [], |
| 96 | dataset: { |
| 97 | backgroundColor: '#6f6db9' |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | public jitterBin = { |
| 102 | series: ['Current Jitter Bin'], |
| 103 | labels: ['0 - 3 ms', '3 - 8 ms', '8 - 100 ms', '> 100 ms'], |
| 104 | data: [], |
| 105 | dataset: { |
| 106 | backgroundColor: '#ffa500' |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | public allLineColors = ['#c55d01', '#ffa500', '#8b0000', '#6f6db9', '#add8e6', '#00008b']; |
| 111 | public lineColors = this.allLineColors; |
| 112 | public lineFill = [ |
| 113 | {fill: false, borderColor: '#c55d01'}, |
| 114 | {fill: false, borderColor: '#ffa500'}, |
| 115 | {fill: false, borderColor: '#8b0000'}, |
| 116 | {fill: false, borderColor: '#6f6db9'}, |
| 117 | {fill: false, borderColor: '#add8e6'}, |
| 118 | {fill: false, borderColor: '#00008b'}]; |
| 119 | |
| 120 | public graphOption = 'both'; |
| 121 | public graphTitle = 'Delay and Jitter Graph'; |
| 122 | public linedata = []; |
| 123 | |
| 124 | constructor( |
| 125 | private $interval: ng.IIntervalService, |
| 126 | private $stateParams: ng.ui.IStateParamsService, |
| 127 | private MicrosemiStats: IMicrosemiStats, |
| 128 | ) { |
| 129 | |
| 130 | } |
| 131 | |
| 132 | $onInit() { |
| 133 | const load = () => { |
| 134 | this.MicrosemiStats.get(this.$stateParams.mdName, this.$stateParams.maName, this.$stateParams.mepId, this.$stateParams.dmId || 1) |
| 135 | .then((res: IMicrosemiStatsData) => { |
| 136 | const data = this.MicrosemiStats.getAllData(res); |
| 137 | |
| 138 | this.linedata = data.line.data; |
| 139 | this.lineChart.labels = data.line.labels; |
| 140 | this.lineChart.data = data.line.data; |
| 141 | this.delayBin.data = data.delay.data; |
| 142 | this.jitterBin.data = data.jitter.data; |
| 143 | |
| 144 | }); |
| 145 | }; |
| 146 | |
| 147 | load(); |
| 148 | |
| 149 | this.renderGraph(); |
| 150 | |
| 151 | this.$interval(() => { |
| 152 | load(); |
| 153 | }, 1000 * 60); |
| 154 | } |
| 155 | |
| 156 | renderGraph() : void { |
| 157 | this.graphTitle = this.graphTitleRender(); |
| 158 | this.graphDisplayRender(); |
| 159 | } |
| 160 | |
| 161 | graphTitleRender() : string { |
| 162 | let output; |
| 163 | switch (this.graphOption) { |
| 164 | default: |
| 165 | case 'both': |
| 166 | output = 'Delay and Jitter Graph'; |
| 167 | break; |
| 168 | case 'delay': |
| 169 | output = 'Delay Graph'; |
| 170 | break; |
| 171 | case 'jitter': |
| 172 | output = 'Jitter Graph'; |
| 173 | break; |
| 174 | } |
| 175 | return output; |
| 176 | } |
| 177 | |
| 178 | graphDisplayRender() : void { |
| 179 | switch (this.graphOption) { |
| 180 | |
| 181 | default: |
| 182 | case 'both': |
| 183 | this.lineChart.series = ['Jitter Avg', 'Jitter Max', 'Jitter Min', 'Delay Avg', 'Delay Max', 'Delay Min']; |
| 184 | this.lineChart.data = this.linedata; |
| 185 | this.lineChart.dataset = this.lineFill; |
| 186 | this.lineColors = this.allLineColors; |
| 187 | break; |
| 188 | |
| 189 | case 'delay': |
| 190 | this.lineChart.series = ['Delay Avg', 'Delay Max', 'Delay Min']; |
| 191 | this.lineChart.data = this.linedata.slice(3); |
| 192 | this.lineChart.dataset = this.lineFill.slice(3); |
| 193 | this.lineColors = this.allLineColors.slice(3); |
| 194 | break; |
| 195 | |
| 196 | case 'jitter': |
| 197 | this.lineChart.series = ['Jitter Avg', 'Jitter Max', 'Jitter Min']; |
| 198 | this.lineChart.data = this.linedata.slice(0, 3); |
| 199 | this.lineChart.dataset = this.lineFill.slice(0, 3); |
| 200 | this.lineColors = this.allLineColors.slice(0, 3); |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | } |
| 206 | |
| 207 | |
| 208 | export const cfmStatComponent: angular.IComponentOptions = { |
| 209 | template: require('./cfmstat.component.html'), |
| 210 | controllerAs: 'vm', |
| 211 | controller: CfmStatComponent |
| 212 | }; |