• 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.js';
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    SmartEvent: {
43      UI: {
44        MenuTrace: string; //selected menu trace
45        RefreshCanvas: string; //selected menu trace
46        SliceMark: string; //Set the tag scope
47        TimeRange: string; //Set the timeline range
48        TraceRowComplete: string; //Triggered after the row component has finished loading data
49        KeyboardEnable: string; // SystemTrace Keyboard enable
50        UploadSOFile: string; // Upload so file
51        Loading: string; // Upload so file
52        Error: string; // load error
53        CheckALL: string; // Check all child chart
54      };
55    };
56
57    subscribe(evt: string, fn: (b: any) => void): void;
58
59    subscribeOnce(evt: string, fn: (b: any) => void): void;
60
61    unsubscribe(evt: string, fn: (b: any) => void): void;
62
63    publish(evt: string, data: any): void;
64
65    clearTraceRowComplete(): void;
66  }
67}
68
69Number.prototype.n2x = function (): number {
70  return Number(this);
71};
72
73Array.prototype.isEmpty = function <T>(): boolean {
74  return this == null || this == undefined || this.length == 0;
75};
76Array.prototype.isNotEmpty = function <T>(): boolean {
77  return this != null && this != undefined && this.length > 0;
78};
79
80HTMLElement.prototype.containPoint = function (ev, cut) {
81  let rect = this.getBoundingClientRect();
82  return (
83    ev.pageX >= rect.left + (cut?.left ?? 0) &&
84    ev.pageX <= rect.right - (cut?.right ?? 0) &&
85    ev.pageY >= rect.top + (cut?.top ?? 0) &&
86    ev.pageY <= rect.bottom - (cut?.bottom ?? 0)
87  );
88};
89
90window.SmartEvent = {
91  UI: {
92    MenuTrace: 'SmartEvent-UI-MenuTrace',
93    RefreshCanvas: 'SmartEvent-UI-RefreshCanvas',
94    SliceMark: 'SmartEvent-UI-SliceMark',
95    TimeRange: 'SmartEvent-UI-TimeRange',
96    TraceRowComplete: 'SmartEvent-UI-TraceRowComplete',
97    KeyboardEnable: 'SmartEvent-UI-StopWASD',
98    UploadSOFile: 'SmartEvent-UI-UploadSoFile',
99    Loading: 'SmartEvent-UI-Loading',
100    Error: 'SmartEvent-UI-Error',
101    CheckALL: 'SmartEvent-UI-CheckALL',
102  },
103};
104Window.prototype.subscribe = (ev, fn) => EventCenter.subscribe(ev, fn);
105Window.prototype.unsubscribe = (ev, fn) => EventCenter.unsubscribe(ev, fn);
106Window.prototype.publish = (ev, data) => EventCenter.publish(ev, data);
107Window.prototype.subscribeOnce = (ev, data) => EventCenter.subscribeOnce(ev, data);
108Window.prototype.clearTraceRowComplete = () => EventCenter.clearTraceRowComplete();
109export {};
110