1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.shuheng.scomputingplatfrom.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.elvishew.xlog.XLog
import com.github.AAChartModel.AAChartCore.AAChartCreator.AAChartModel
import com.github.AAChartModel.AAChartCore.AAChartCreator.AASeriesElement
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartAnimationType
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartFontWeightType
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartLineDashStyleType
import com.github.AAChartModel.AAChartCore.AAChartEnum.AAChartType
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AACrosshair
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AAItemStyle
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AALabels
import com.github.AAChartModel.AAChartCore.AAOptionsModel.AAStyle
import com.github.AAChartModel.AAChartCore.AATools.AAColor
import com.github.AAChartModel.AAChartCore.AATools.AAGradientColor
import com.github.AAChartModel.AAChartCore.AATools.AALinearGradientDirection
import com.shuheng.scomputingplatfrom.bean.PlatBean
import com.shuheng.scomputingplatfrom.databinding.FragmentTaskBinding
import java.util.Arrays
import java.util.Random
class TaskFragment : BaseFragment<FragmentTaskBinding>() {
private var type: Int? =0
companion object{
fun newInstance( type: Int): TaskFragment {
val fragment = TaskFragment()
val args = Bundle()
args.putInt("type", type)
fragment.setArguments(args)
return fragment
}
}
override fun getViewBinding(
inflater: LayoutInflater,
container: ViewGroup?
) = FragmentTaskBinding.inflate(inflater, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
type=arguments?.getInt("type")
XLog.e("TaskFragment initView "+ type)
initChart()
}
var comfyUIArray = arrayOf("0")
fun setData(message: PlatBean) {
val activity = getActivity()
if(activity == null) {
return
}
var platData=message.data
val rnd = Random()
val randomNumber = rnd.nextInt(101) + 100 // 101 是因为需要包含边界200
val rnd1 = Random()
val randomNumber1 = rnd1.nextInt(101) + 100 // 101 是因为需要包含边界200
binding.taskNumTv.text=""+randomNumber
var comfyUIArray1 =platData.comfyUiQueueData
var index=0
if(comfyUIArray.size>0){
var lastNum=comfyUIArray[comfyUIArray.size-1]
var number=lastNum.toInt()
if(number>0) {
index = comfyUIArray1?.indexOf(lastNum) ?: 0
if (index == -1)
index = comfyUIArray.size
else
index = Math.abs(comfyUIArray.size - (index + 1))
}else{
index=0
}
}else{
index=0
}
binding.taskNumAllTv.text=""+randomNumber1
comfyUIArray=comfyUIArray1.toTypedArray()
val aaSeriesElementsArr: Array<AASeriesElement> = configureChartSeriesArray(platData.comfyUiQueueData?.size?.toInt()?:0,index)
binding.taskChartView.aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(
aaSeriesElementsArr,false
)
}
var array: Array<Int>?=null
var array1: Array<Int>?=null
fun initChart(){
binding.taskChartView.setOnTouchListener(View.OnTouchListener { v, event -> // 返回true表明已处理触摸事件,不再传递
true
})
binding.taskChartView.setBackgroundColor(0)
array = arrayOf(0,0,0,0,0,0,0,0,0,0)
array1 = arrayOf(0,0,0,0,0,0,0,0,0,0)
val gradientColorDic = AAGradientColor.linearGradient(
AALinearGradientDirection.ToBottom,
"rgba(249, 199, 79, 0.3)",
"rgba(249, 199, 79, 0.3)"
)
val gradientColorDic1 = AAGradientColor.linearGradient(
AALinearGradientDirection.ToBottom,
"rgba(249, 65, 68, 0.3)",
"rgba(249, 65, 68, 0.3)"
)
val aaChartModel : AAChartModel = AAChartModel()
.chartType(AAChartType.Areaspline)
.backgroundColor("#1E1E1E")
.colorsTheme(arrayOf(AAGradientColor.MysticMauve))
.dataLabelsEnabled(false)
.tooltipEnabled(false)
.markerRadius(3f)
.animationType(AAChartAnimationType.SwingFromTo)
.legendEnabled(true)
.series(arrayOf(
AASeriesElement()
.lineWidth(2)
.name("数量")
.color("#F9C74F")
.fillColor(gradientColorDic)
.data(array),
AASeriesElement()
.lineWidth(2)
.name("吞吐量")
.color("#F94144")
.fillColor(gradientColorDic1)
.data(array1)
)
)
val aaOptions = aaChartModel.aa_toAAOptions()
// aaOptions.plotOptions.series
// .dataLabels(
// AADataLabels()
// .enabled(true)
// .style(
// AAStyle()
// .color(AAColor.White)
// .fontSize(10)
// .fontWeight(AAChartFontWeightType.Thin)
// .textOutline("0px 0px contrast") //文字轮廓描边
// )
// )
val aaCrosshair = AACrosshair()
.dashStyle(AAChartLineDashStyleType.Dash)
.color(AAColor.White)
.width(1)
val aaLabels = AALabels()
.useHTML(true)
.style(
AAStyle()
.fontSize(4.5f)
.color(AAColor.White) //轴文字颜色
)
aaOptions.xAxis
.tickWidth(0) //X轴刻度线宽度
.lineWidth(0) //X轴轴线宽度
.lineColor(AAColor.Gray) //X轴轴线颜色
.gridLineWidth(0.3) //X轴网格线宽度
.crosshair(aaCrosshair)
.gridLineDashStyle(AAChartLineDashStyleType.LongDash)
.labels(aaLabels)
aaOptions.yAxis
.tickWidth(0)
.lineWidth(0) //Y轴轴线颜色
.lineColor(AAColor.Gray) //Y轴轴线颜色
.gridLineWidth(0.3) //Y轴网格线宽度
.gridLineDashStyle(AAChartLineDashStyleType.LongDash)
.crosshair(aaCrosshair)
.labels(aaLabels)
aaOptions.legend
.itemStyle(
AAItemStyle()
.color(AAColor.White) //字体颜色
.fontSize(8) //字体大小
.fontWeight(AAChartFontWeightType.Thin) //字体为细体字
).align("left")
binding.taskChartView.aa_drawChartWithChartOptions(aaOptions)
}
fun configureChartSeriesArray(i:Int,j:Int): Array<AASeriesElement> {
val maxRange = 10
val numberArr = arrayOfNulls<Int>(maxRange)
val numberArr1 = arrayOfNulls<Int>(maxRange)
System.arraycopy(array, 1, numberArr, 0, array!!.size- 1);
System.arraycopy(array1, 1, numberArr1, 0, array1!!.size- 1);
numberArr[numberArr.size - 1] = i;
numberArr1[numberArr1.size - 1] = j;
for(i in 0 until maxRange){
array!![i]= numberArr[i]!!
array1!![i]= numberArr1[i]!!
}
return arrayOf(
AASeriesElement()
.data(numberArr),
AASeriesElement()
.data(numberArr1)
)
}
}