onCompute method
获取画布宽度和高度 计算当前屏内相对转换后的X轴位置 根据X轴位置,计算屏内起始和结束展示数据的索引 计算最大值和最小值
Implementation
@override
void onCompute(Size size) {
super.onCompute(size);
if (getValues().isNotEmpty) {
List<double> originLows = values.map((e) => e.low).toList();
List<double> lows = originLows.sublist(startIndex, endIndex);
double lowsMin = lows.reduce(math.min);
double lowsMax = lows.reduce(math.max);
if (lowsMax > maxValue) {
maxValue = lowsMax;
_drawMaxIndex = originLows.indexOf(maxValue);
} else {
_drawMaxIndex = getValues().indexOf(maxValue);
}
if (lowsMin < minValue) {
minValue = lowsMin;
_drawMinIndex = originLows.indexOf(minValue);
} else {
_drawMinIndex = getValues().indexOf(minValue);
}
_drawMaxValue = maxValue;
_drawMinValue = minValue;
double abs = (maxValue - minValue).abs() * 1.2;
double mx = minValue + abs;
double mi = maxValue - abs;
maxValue = mx;
minValue = mi;
_radio = contentHeight / (maxValue - minValue);
}
}