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 { BaseElement, element } from '../../../../../base-ui/BaseElement'; 17import { LitTable } from '../../../../../base-ui/table/lit-table'; 18import { SelectionParam } from '../../../../bean/BoxSelection'; 19import { Utils } from '../../base/Utils'; 20import { log } from '../../../../../log/Log'; 21import { resizeObserver } from '../SheetUtils'; 22import { getTabFps } from '../../../../database/sql/SqlLite.sql'; 23 24@element('tabpane-fps') 25export class TabPaneFps extends BaseElement { 26 private fpsTbl: LitTable | null | undefined; 27 private fpsRange: HTMLLabelElement | null | undefined; 28 29 set data(fpsSelection: SelectionParam | unknown) { 30 this.fpsRange!.textContent = `Selected range: ${parseFloat( 31 // @ts-ignore 32 ((fpsSelection.rightNs - fpsSelection.leftNs) / 1000000.0).toFixed(5) 33 )} ms`; // @ts-ignore 34 getTabFps(fpsSelection.leftNs, fpsSelection.rightNs).then((fpsResult) => { 35 if (fpsResult !== null && fpsResult.length > 0) { 36 log('getTabFps result size : ' + fpsResult.length); 37 // @ts-ignore 38 let index = fpsResult.findIndex((d) => d.startNS >= fpsSelection.leftNs); 39 if (index !== -1) { 40 let arr = fpsResult.splice(index > 0 ? index - 1 : index); 41 arr.map((e) => (e.timeStr = Utils.getTimeString(e.startNS))); 42 this.fpsTbl!.recycleDataSource = arr; 43 } else { 44 let last = fpsResult[fpsResult.length - 1]; 45 last.timeStr = Utils.getTimeString(last.startNS); 46 this.fpsTbl!.recycleDataSource = [last]; 47 } 48 } else { 49 this.fpsTbl!.recycleDataSource = []; 50 } 51 }); 52 } 53 54 initElements(): void { 55 this.fpsTbl = this.shadowRoot?.querySelector<LitTable>('#tb-fps'); 56 this.fpsRange = this.shadowRoot?.querySelector('#fps-time-range'); 57 } 58 59 connectedCallback(): void { 60 super.connectedCallback(); 61 resizeObserver(this.parentElement!, this.fpsTbl!); 62 } 63 64 initHtml(): string { 65 return ` 66 <style> 67 .fps-label{ 68 text-align: end; 69 } 70 :host{ 71 display: flex; 72 flex-direction: column; 73 padding: 10px 10px; 74 } 75 </style> 76 <label id="fps-time-range" class="fps-label" style="width: 100%;height: 20px;font-size: 10pt;margin-bottom: 5px">Selected range:0.0 ms</label> 77 <lit-table id="tb-fps" style="height: auto"> 78 <lit-table-column class="fps-column" width="1fr" title="Time" data-index="timeStr" key="timeStr" align="flex-start"> 79 </lit-table-column> 80 <lit-table-column class="fps-column" width="1fr" title="FPS" data-index="fps" key="fps" align="flex-start" > 81 </lit-table-column> 82 </lit-table> 83 `; 84 } 85} 86