drawDate method

  1. @override
void drawDate(
  1. Canvas canvas,
  2. Size size
)
override

Implementation

@override
void drawDate(Canvas canvas, Size size) {
  if (datas == null) return;

  double columnSpace = size.width / mGridColumns;
  double startX = getX(mStartIndex) - mPointWidth / 2;
  double stopX = getX(mStopIndex) + mPointWidth / 2;
  double x = 0.0;
  double y = 0.0;
  for (var i = 0; i <= mGridColumns; ++i) {
    double translateX = xToTranslateX(columnSpace * i);

    if (translateX >= startX && translateX <= stopX) {
      int index = indexOfTranslateX(translateX);

      if (datas?[index] == null) continue;
      TextPainter tp = getTextPainter(getDate(datas![index].time), null);
      y = size.height - (mBottomPadding - tp.height) / 2 - tp.height;
      x = columnSpace * i - tp.width / 2;
      // Prevent date text out of canvas
      if (x < 0) x = 0;
      if (x > size.width - tp.width) x = size.width - tp.width;
      tp.paint(canvas, Offset(x, y));
    }
  }

//    double translateX = xToTranslateX(0);
//    if (translateX >= startX && translateX <= stopX) {
//      TextPainter tp = getTextPainter(getDate(datas[mStartIndex].id));
//      tp.paint(canvas, Offset(0, y));
//    }
//    translateX = xToTranslateX(size.width);
//    if (translateX >= startX && translateX <= stopX) {
//      TextPainter tp = getTextPainter(getDate(datas[mStopIndex].id));
//      tp.paint(canvas, Offset(size.width - tp.width, y));
//    }
}