• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { EventCenter } from './EventCenter';
17
18declare global {
19  interface Number {
20    n2x(): number;
21  }
22
23  interface Array<T> {
24    isEmpty(): boolean;
25
26    isNotEmpty(): boolean;
27  }
28
29  interface HTMLElement {
30    containPoint(
31      ev: MouseEvent,
32      cut?: {
33        left?: number;
34        right?: number;
35        top?: number;
36        bottom?: number;
37      }
38    ): boolean;
39  }
40
41  interface Window {
42    postMessage(message: unknown, transfer?: Transferable[]): void;
43    // queryFromWasm: boolean;//use cache or query from db
44    isLastFrame: boolean; //last frame mast be draw
45    recordStartNS: number;
46    recordEndNS: number;
47    totalNS: number;
48    SmartEvent: {
49      UI: {
50        MenuTrace: string; //selected menu trace
51        RefreshCanvas: string; //selected menu trace
52        RowHeightChange: string; //function row height change
53        SliceMark: string; //Set the tag scope
54        TimeRange: string; //Set the timeline range
55        TraceRowComplete: string; //Triggered after the row component has finished loading data
56        KeyboardEnable: string; // SystemTrace Keyboard enable
57        MouseEventEnable: string; // Mouse Event Keyboard enable
58        UploadSOFile: string; // Upload so file
59        Loading: string; // Upload so file
60        Error: string; // load error
61        CheckALL: string; // Check all child chart
62        CollapseAllLane: string; //collapse/uncollapse all lane row
63        CollectGroupChange: string; //collapse/uncollapse all lane row
64        WakeupList: string; //show wakeup list table
65        DeviceConnect: string;
66        DeviceDisConnect: string;
67        HoverNull: string;
68        KeyPath: string;
69        LoadFinish: string;
70        LoadFinishFrame: string;
71        ShowBottomTab: string;
72        ImportRecord: string; //导出时间区间和泳道图收藏记录
73        ExportRecord: string; //导出时间区间和泳道图收藏记录
74      };
75    };
76
77    subscribe(evt: string, fn: (b: unknown) => void): void;
78
79    subscribeOnce(evt: string, fn: (b: unknown) => void): void;
80
81    unsubscribe(evt: string, fn: (b: unknown) => void): void;
82
83    publish(evt: string, data: unknown): void;
84
85    clearTraceRowComplete(): void;
86  }
87}
88
89HTMLElement.prototype.containPoint = function (ev, cut): boolean {
90  let rect = this.getBoundingClientRect();
91  return (
92    ev.pageX >= rect.left + (cut?.left ?? 0) &&
93    ev.pageX <= rect.right - (cut?.right ?? 0) &&
94    ev.pageY >= rect.top + (cut?.top ?? 0) &&
95    ev.pageY <= rect.bottom - (cut?.bottom ?? 0)
96  );
97};
98
99window.SmartEvent = {
100  UI: {
101    MenuTrace: 'SmartEvent-UI-MenuTrace',
102    RefreshCanvas: 'SmartEvent-UI-RefreshCanvas',
103    RowHeightChange: 'SmartEvent-UI-RowHeightChange',
104    SliceMark: 'SmartEvent-UI-SliceMark',
105    TimeRange: 'SmartEvent-UI-TimeRange',
106    TraceRowComplete: 'SmartEvent-UI-TraceRowComplete',
107    KeyboardEnable: 'SmartEvent-UI-StopWASD',
108    MouseEventEnable: 'SmartEvent-UI-StopMouseEvent',
109    UploadSOFile: 'SmartEvent-UI-UploadSoFile',
110    Loading: 'SmartEvent-UI-Loading',
111    Error: 'SmartEvent-UI-Error',
112    CheckALL: 'SmartEvent-UI-CheckALL',
113    CollapseAllLane: 'SmartEvent-UI-Collapse-All-Lane',
114    CollectGroupChange: 'SmartEvent-UI-Collect-group-change',
115    WakeupList: 'SmartEvent-UI-WakeupList',
116    DeviceConnect: 'SmartEvent-DEVICE_CONNECT',
117    DeviceDisConnect: 'SmartEvent-DEVICE_DISCONNECT',
118    HoverNull: 'SmartEvent-Hover-NULL',
119    KeyPath: 'SmartEvent-UI-UploadKeyPath',
120    LoadFinish: 'SmartEvent-UI-LoadFinish', //所有泳道刷新完成触发
121    LoadFinishFrame: 'SmartEvent-UI-LoadFinishFrame', //单个泳道刷新完成触发
122    ShowBottomTab: 'SmartEvent-UI-ShowBottomTab', // 显示底部 tab
123    ImportRecord: 'SmartEvent-UI-ImportRecord',
124    ExportRecord: 'SmartEvent-UI-ExportRecord',
125  },
126};
127Window.prototype.subscribe = (ev, fn): void => EventCenter.subscribe(ev, fn);
128Window.prototype.unsubscribe = (ev, fn): void => EventCenter.unsubscribe(ev, fn);
129Window.prototype.publish = (ev, data): void => EventCenter.publish(ev, data);
130Window.prototype.subscribeOnce = (ev, data): void => EventCenter.subscribeOnce(ev, data);
131Window.prototype.clearTraceRowComplete = (): void => EventCenter.clearTraceRowComplete();
132export {};
133
134export function dpr(): number {
135  return window.devicePixelRatio || 1;
136}
137
138export const isEmpty = function <T>(list: Array<T> | undefined): boolean {
139  return list === null || list === undefined || list.length === 0;
140};
141export const isNotEmpty = function <T>(list: Array<T> | undefined): boolean {
142  return list !== null && list !== undefined && list.length > 0;
143};
144