• 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: any, 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      };
72    };
73
74    subscribe(evt: string, fn: (b: any) => void): void;
75
76    subscribeOnce(evt: string, fn: (b: any) => void): void;
77
78    unsubscribe(evt: string, fn: (b: any) => void): void;
79
80    publish(evt: string, data: any): void;
81
82    clearTraceRowComplete(): void;
83  }
84}
85
86Number.prototype.n2x = function (): number {
87  return Number(this);
88};
89
90Array.prototype.isEmpty = function <T>(): boolean {
91  return this == null || this == undefined || this.length == 0;
92};
93Array.prototype.isNotEmpty = function <T>(): boolean {
94  return this != null && this != undefined && this.length > 0;
95};
96
97HTMLElement.prototype.containPoint = function (ev, cut) {
98  let rect = this.getBoundingClientRect();
99  return (
100    ev.pageX >= rect.left + (cut?.left ?? 0) &&
101    ev.pageX <= rect.right - (cut?.right ?? 0) &&
102    ev.pageY >= rect.top + (cut?.top ?? 0) &&
103    ev.pageY <= rect.bottom - (cut?.bottom ?? 0)
104  );
105};
106
107window.SmartEvent = {
108  UI: {
109    MenuTrace: 'SmartEvent-UI-MenuTrace',
110    RefreshCanvas: 'SmartEvent-UI-RefreshCanvas',
111    RowHeightChange: 'SmartEvent-UI-RowHeightChange',
112    SliceMark: 'SmartEvent-UI-SliceMark',
113    TimeRange: 'SmartEvent-UI-TimeRange',
114    TraceRowComplete: 'SmartEvent-UI-TraceRowComplete',
115    KeyboardEnable: 'SmartEvent-UI-StopWASD',
116    MouseEventEnable: 'SmartEvent-UI-StopMouseEvent',
117    UploadSOFile: 'SmartEvent-UI-UploadSoFile',
118    Loading: 'SmartEvent-UI-Loading',
119    Error: 'SmartEvent-UI-Error',
120    CheckALL: 'SmartEvent-UI-CheckALL',
121    CollapseAllLane: 'SmartEvent-UI-Collapse-All-Lane',
122    CollectGroupChange: 'SmartEvent-UI-Collect-group-change',
123    WakeupList: 'SmartEvent-UI-WakeupList',
124    DeviceConnect: 'SmartEvent-DEVICE_CONNECT',
125    DeviceDisConnect: 'SmartEvent-DEVICE_DISCONNECT',
126    HoverNull: 'SmartEvent-Hover-NULL',
127    KeyPath: 'SmartEvent-UI-UploadKeyPath',
128    LoadFinish: 'SmartEvent-UI-LoadFinish',//所有泳道刷新完成触发
129    LoadFinishFrame: 'SmartEvent-UI-LoadFinishFrame',//单个泳道刷新完成触发
130  },
131};
132Window.prototype.subscribe = (ev, fn) => EventCenter.subscribe(ev, fn);
133Window.prototype.unsubscribe = (ev, fn) => EventCenter.unsubscribe(ev, fn);
134Window.prototype.publish = (ev, data) => EventCenter.publish(ev, data);
135Window.prototype.subscribeOnce = (ev, data) => EventCenter.subscribeOnce(ev, data);
136Window.prototype.clearTraceRowComplete = () => EventCenter.clearTraceRowComplete();
137export {};
138
139export function dpr() {
140  return window.devicePixelRatio || 1;
141}
142