1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { ColorUtils } from "../component/trace/base/ColorUtils.js"; 17import {BaseStruct} from "./BaseStruct.js"; 18 19export class NetworkAbilityMonitorStruct extends BaseStruct { 20 static maxNetworkRate: number = 0 21 static maxNetworkRateName: string = "0 KB/S" 22 static hoverNetworkAbilityStruct: NetworkAbilityMonitorStruct | undefined; 23 static selectNetworkAbilityStruct: NetworkAbilityMonitorStruct | undefined; 24 value: number | undefined 25 startNS: number | undefined 26 dur: number | undefined 27 28 static draw(context2D: any, data: NetworkAbilityMonitorStruct) { 29 if (data.frame) { 30 let width = data.frame.width || 0; 31 let index = 0 32 index += 2 33 context2D.fillStyle = ColorUtils.colorForTid(index) 34 context2D.strokeStyle = ColorUtils.colorForTid(index) 35 if (data.startNS === NetworkAbilityMonitorStruct.hoverNetworkAbilityStruct?.startNS) { 36 context2D.lineWidth = 1; 37 context2D.globalAlpha = 0.6; 38 let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0) * 1.0) / NetworkAbilityMonitorStruct.maxNetworkRate); 39 context2D.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight) 40 context2D.beginPath() 41 context2D.arc(data.frame.x, data.frame.y + data.frame.height - drawHeight, 3, 0, 2 * Math.PI, true) 42 context2D.fill() 43 context2D.globalAlpha = 1.0; 44 context2D.stroke(); 45 context2D.beginPath() 46 context2D.moveTo(data.frame.x + 3, data.frame.y + data.frame.height - drawHeight); 47 context2D.lineWidth = 3; 48 context2D.lineTo(data.frame.x + width, data.frame.y + data.frame.height - drawHeight) 49 context2D.stroke(); 50 } else { 51 context2D.globalAlpha = 0.6; 52 context2D.lineWidth = 1; 53 let drawHeight: number = Math.floor(((data.value || 0) * (data.frame.height || 0)) / NetworkAbilityMonitorStruct.maxNetworkRate); 54 context2D.fillRect(data.frame.x, data.frame.y + data.frame.height - drawHeight, width, drawHeight) 55 } 56 } 57 context2D.globalAlpha = 1.0; 58 context2D.lineWidth = 1; 59 } 60} 61