• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 package ohos.devtools.views.charts.model;
17 
18 import java.util.HashMap;
19 import java.util.Map;
20 
21 import static ohos.devtools.views.charts.utils.ChartConstants.DEFAULT_MAX_MILLIS;
22 import static ohos.devtools.views.charts.utils.ChartConstants.DEFAULT_TIME_UNIT;
23 
24 /**
25  * Chart绘制标准,用于统一Timeline和Chart
26  *
27  * @since 2021/1/26 15:10
28  */
29 public class ChartStandard {
30     /**
31      * sessionId
32      */
33     private final long sessionId;
34 
35     /**
36      * 用户框选时间范围的集合
37      *
38      * @see "Key: 区别各个Chart的key, value: 框选的时间范围"
39      */
40     private final Map<String, ChartDataRange> selectedRangeMap = new HashMap<>();
41 
42     /**
43      * 窗体上可以展示的最大毫秒数,单位为毫秒
44      */
45     private int maxDisplayMillis;
46 
47     /**
48      * Timeline和Chart刻度线上的最小刻度间隔,单位为毫秒
49      */
50     private int minMarkInterval;
51 
52     /**
53      * 本次Chart首次创建并启动刷新时的时间戳
54      */
55     private long firstTimestamp;
56 
57     /**
58      * 本次Chart最后一个数据的时间戳
59      */
60     private long lastTimestamp;
61 
62     /**
63      * Chart展示的时间范围
64      */
65     private ChartDataRange displayRange;
66 
67     /**
68      * 构造函数
69      *
70      * @param sessionId sessionId
71      */
ChartStandard(long sessionId)72     public ChartStandard(long sessionId) {
73         this.sessionId = sessionId;
74         maxDisplayMillis = DEFAULT_MAX_MILLIS;
75         minMarkInterval = DEFAULT_TIME_UNIT;
76     }
77 
78     /**
79      * 修改Chart展示的时间范围
80      *
81      * @param start 开始时间
82      * @param end 结束时间
83      */
updateDisplayTimeRange(int start, int end)84     public void updateDisplayTimeRange(int start, int end) {
85         if (displayRange == null) {
86             displayRange = new ChartDataRange();
87         }
88         displayRange.setStartTime(start);
89         displayRange.setEndTime(end);
90     }
91 
92     /**
93      * 根据Key获取对应的框选时间范围
94      *
95      * @param key 区别各个Chart的key
96      * @return ChartDataRange
97      */
getSelectedRange(String key)98     public ChartDataRange getSelectedRange(String key) {
99         return selectedRangeMap.get(key);
100     }
101 
102     /**
103      * 更新用户框选的起始时间和坐标点
104      *
105      * @param key 区别各个Chart的key
106      * @param startTime 用户新框选的时间范围
107      */
updateSelectedStart(String key, int startTime)108     public void updateSelectedStart(String key, int startTime) {
109         ChartDataRange range = selectedRangeMap.get(key);
110         if (range == null) {
111             range = new ChartDataRange();
112             selectedRangeMap.put(key, range);
113         }
114         range.setStartTime(startTime);
115     }
116 
117     /**
118      * 更新用户框选的起始时间和坐标点
119      *
120      * @param key 区别各个Chart的key
121      * @param endTime 用户新框选的时间范围
122      */
updateSelectedEnd(String key, int endTime)123     public void updateSelectedEnd(String key, int endTime) {
124         ChartDataRange range = selectedRangeMap.get(key);
125         if (range == null) {
126             range = new ChartDataRange();
127             selectedRangeMap.put(key, range);
128         }
129         range.setEndTime(endTime);
130     }
131 
132     /**
133      * 清空所有Chart的框选时间范围
134      */
clearAllSelectedRanges()135     public void clearAllSelectedRanges() {
136         selectedRangeMap.clear();
137     }
138 
139     /**
140      * 清空指定Chart的框选时间范围
141      *
142      * @param key 区别各个Chart的key
143      */
clearSelectedRange(String key)144     public void clearSelectedRange(String key) {
145         selectedRangeMap.remove(key);
146     }
147 
getSessionId()148     public long getSessionId() {
149         return sessionId;
150     }
151 
getMaxDisplayMillis()152     public int getMaxDisplayMillis() {
153         return maxDisplayMillis;
154     }
155 
setMaxDisplayMillis(int maxDisplayMillis)156     public void setMaxDisplayMillis(int maxDisplayMillis) {
157         this.maxDisplayMillis = maxDisplayMillis;
158     }
159 
getMinMarkInterval()160     public int getMinMarkInterval() {
161         return minMarkInterval;
162     }
163 
setMinMarkInterval(int minMarkInterval)164     public void setMinMarkInterval(int minMarkInterval) {
165         this.minMarkInterval = minMarkInterval;
166     }
167 
getFirstTimestamp()168     public long getFirstTimestamp() {
169         return firstTimestamp;
170     }
171 
setFirstTimestamp(long firstTimestamp)172     public void setFirstTimestamp(long firstTimestamp) {
173         this.firstTimestamp = firstTimestamp;
174     }
175 
getLastTimestamp()176     public long getLastTimestamp() {
177         return lastTimestamp;
178     }
179 
setLastTimestamp(long lastTimestamp)180     public void setLastTimestamp(long lastTimestamp) {
181         this.lastTimestamp = lastTimestamp;
182     }
183 
getDisplayRange()184     public ChartDataRange getDisplayRange() {
185         return displayRange;
186     }
187 }
188