handleMouseMove method

void handleMouseMove(
  1. MouseEvent event
)

Implementation

void handleMouseMove(MouseEvent event) {
  var rect = (event.target as Element).getBoundingClientRect();
  var x = event.clientX - rect.left; //x position within the element.
  var y = event.clientY - rect.top; //y position within the element.
  final offset = 25;
  if (x > rect.width / 2) {
    canvasTip.style.left = "auto";
    canvasTip.style.right = "${rect.width - x + offset}px";
  } else {
    canvasTip.style.left = "${x + offset}px";
    canvasTip.style.right = "auto";
  }
  if (y > rect.height / 2) {
    canvasTip.style.bottom = "${rect.height - y + offset}px";
    canvasTip.style.top = "auto";
  } else {
    canvasTip.style.bottom = "auto";
    canvasTip.style.top = "${y + offset}px";
  }
  int? newCurrentTime;
  double? minDistance;
  String? label;
  if (x > _leftMargin && x < _leftMargin + chartWidth && y > _topMargin && y < _topMargin + chartHeight) {
    for (var tx in xToTime.keys) {
      var thisDistance = (x - tx).abs();
      if (minDistance == null || minDistance > thisDistance) {
        minDistance = thisDistance;
        newCurrentTime = xToTime[tx]!;
        label = timeTooltips[newCurrentTime]!;
      }
    }
  }
  if (newCurrentTime != currentTime) {
    currentTime = newCurrentTime;
    if (currentTime != null) {
      canvasTip.innerHTML = label!.toJS;
      if (showTip) {
        canvasTip.style.display = 'block';
      }
    } else {
      canvasTip.style.display = 'none';
    }
    renderPoints();
  }
}