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.sdk.model; 17 18 import com.google.protobuf.ByteString; 19 import model.bean.ChartDataModel; 20 import model.bean.ChartEnum; 21 import model.bean.Legend; 22 23 import java.util.List; 24 25 /** 26 * AbstractSdk 27 * 28 * @since 2021/11/20 29 */ 30 public abstract class AbstractSdk { 31 private List<Legend> legends; 32 private String pluginFileName; 33 private String pluginDataName; 34 private ChartEnum chartType; 35 private String unit; 36 private String titleName; 37 38 /** 39 * AbstractSdk constructor 40 */ AbstractSdk()41 public AbstractSdk() { 42 init(); 43 } 44 45 /** 46 * init 47 */ init()48 protected abstract void init(); 49 50 /** 51 * getPluginByteString 52 * 53 * @param pid pid 54 * @return ByteString 55 */ getPluginByteString(int pid)56 public abstract ByteString getPluginByteString(int pid); 57 58 /** 59 * sampleData 60 * 61 * @param data data 62 * @return List<ChartDataModel> 63 */ sampleData(ByteString data)64 public abstract List<ChartDataModel> sampleData(ByteString data); 65 66 /** 67 * getChartDataModel 68 * 69 * @param value value 70 * @param index index 71 * @return ChartDataModel 72 */ getChartDataModel(int value, int index)73 public ChartDataModel getChartDataModel(int value, int index) { 74 Legend legend = this.getLegends().get(index); 75 ChartDataModel item = new ChartDataModel(); 76 item.setIndex(legend.getIndex()); 77 item.setColor(legend.getLegendColor()); 78 item.setName(legend.getLegendName()); 79 item.setValue(value); 80 return item; 81 } 82 83 /** 84 * getChartDataModel 85 * 86 * @param value value 87 * @param index index 88 * @return ChartDataModel 89 */ getChartDataModel(double value, int index)90 public ChartDataModel getChartDataModel(double value, int index) { 91 Legend legend = this.getLegends().get(index); 92 ChartDataModel item = new ChartDataModel(); 93 item.setIndex(legend.getIndex()); 94 item.setColor(legend.getLegendColor()); 95 item.setName(legend.getLegendName()); 96 item.setDoubleValue(value); 97 return item; 98 } 99 100 /** 101 * initLegend 102 * 103 * @param legends legends 104 */ initLegend(List<Legend> legends)105 public void initLegend(List<Legend> legends) { 106 for (int index = 0; index < legends.size(); index++) { 107 legends.get(index).setIndex(index); 108 if (legends.get(index).getLegendHeight() == 0) { 109 legends.get(index).setLegendHeight(5); 110 } 111 if (legends.get(index).getLegendWidth() == 0) { 112 legends.get(index).setLegendWidth(12); 113 } 114 } 115 } 116 getLegends()117 public List<Legend> getLegends() { 118 return legends; 119 } 120 setLegends(List<Legend> legends)121 public void setLegends(List<Legend> legends) { 122 this.legends = legends; 123 } 124 getPluginFileName()125 public String getPluginFileName() { 126 return pluginFileName; 127 } 128 setPluginFileName(String pluginFileName)129 public void setPluginFileName(String pluginFileName) { 130 this.pluginFileName = pluginFileName; 131 } 132 getPluginDataName()133 public String getPluginDataName() { 134 return pluginDataName; 135 } 136 setPluginDataName(String pluginDataName)137 public void setPluginDataName(String pluginDataName) { 138 this.pluginDataName = pluginDataName; 139 } 140 getChartType()141 public ChartEnum getChartType() { 142 return chartType; 143 } 144 setChartType(ChartEnum chartType)145 public void setChartType(ChartEnum chartType) { 146 this.chartType = chartType; 147 } 148 getUnit()149 public String getUnit() { 150 return unit; 151 } 152 setUnit(String unit)153 public void setUnit(String unit) { 154 this.unit = unit; 155 } 156 getTitleName()157 public String getTitleName() { 158 return titleName; 159 } 160 setTitleName(String titleName)161 public void setTitleName(String titleName) { 162 this.titleName = titleName; 163 } 164 } 165