• 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 {moveFloatWindow,setFloatWindow} from './ui/floatwindow/utils/FloatWindowUtils'
17
18
19
20
21
22@Component
23export struct FloatWindowComponent {
24  private settings: RenderingContextSettings = new RenderingContextSettings(true)
25  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
26  @State title: string = "SmartPerf"
27  private XPoint: number = 5  //x起始坐标
28  private YPoint: number = 108   //Y起始坐标
29  private XScale: number =8 //刻度
30  private YScale: number = 21 //刻度
31  private XLength: number = 168 //X轴长度
32  private YLength: number = 105  //Y轴长度
33  @State data: number[]= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]   //数据集合
34  private MaxDataSize: number= this.XLength / this.XScale  //数据集合的最大长度
35  @State NumericalValue: number= 0   //数值
36  offsetX: number = -1    //悬浮框移动触摸点 X
37  offsetY: number = -1   //悬浮框移动触摸点 X
38
39  MoveWindow(offsetX: number, offsetY: number) {
40    moveFloatWindow(this.title,offsetX, offsetY)
41  }
42
43  SetWindowPosition(offsetX: number, offsetY: number) {
44    setFloatWindow(offsetX, offsetY)
45  }
46  build() {
47    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) {
48      Canvas(this.context)
49        .width('100%')
50        .height('100%')
51        .onReady(() => {
52          //Y轴
53          this.context.clearRect(this.XPoint + 0.5, this.YPoint - this.YLength, this.XLength, this.YLength)
54          this.context.beginPath()
55          this.context.strokeStyle="#ffffff"
56          this.context.moveTo(this.XPoint, this.YPoint - this.YLength)
57          this.context.lineTo(this.XPoint, this.YPoint)
58          this.context.stroke()
59          //X轴
60          this.context.beginPath()
61          this.context.strokeStyle="#ffffff"
62          this.context.moveTo(this.XPoint, this.YPoint)
63          this.context.lineTo(this.XPoint + this.XLength, this.YPoint)
64          this.context.stroke()
65          //K线绘制
66          if (this.data.length > 1) {
67            for (let i = 1; i < this.data.length; i++) {
68              this.context.beginPath()
69              this.context.strokeStyle="#ffffff"
70              console.log("GestureEvent--------------beginPath:" + this.data[i-1]);
71              this.context.moveTo(this.XPoint + (i - 1) * this.XScale, this.YPoint - this.data[i-1])
72              this.context.lineTo(this.XPoint + i * this.XScale, this.YPoint - this.data[i])
73              this.context.stroke()
74            }
75          }
76        })
77    }
78    .width('100%')
79    .height('100%').margin({  top: 20 }).gesture(
80    GestureGroup(GestureMode.Exclusive,
81    PanGesture({})
82      .onActionStart((event: GestureEvent) => {
83
84      })
85      .onActionUpdate((event: GestureEvent) => {
86        this.offsetX = event.offsetX
87        this.offsetY = event.offsetY
88
89      })
90      .onActionEnd(() => {
91        this.MoveWindow(this.offsetX, this.offsetY)
92        this.SetWindowPosition(this.offsetX, this.offsetY)
93
94
95      })
96    ))
97  }
98}