render method

  1. @override
void render(
  1. SwiftTimeChart chart,
  2. CanvasRenderingContext2D ctx
)
override

Implementation

@override
void render(SwiftTimeChart chart, CanvasRenderingContext2D ctx) {
  //shadow!
  if (shadowColor != null) {
    ctx.beginPath();
    ctx.fillStyle = shadowColor!.toJS;
    ({double x, double y, bool isActive})? previous;
    double? firstX, lastX;
    for (var point in transformedPoints(chart)) {
      firstX ??= point.x;
      lastX = point.x;
      if (previous == null) {
        ctx.moveTo(point.x, point.y);
      } else {
        if (smoothing > 0) {
          Point cp1 = Point((previous.x + point.x) / 2, previous.y);
          Point cp2 = Point((previous.x + point.x) / 2, point.y);
          ctx.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y);
        } else {
          ctx.lineTo(point.x, point.y);
        }
      }
      previous = point;
    }
    // close down to the baseline and back
    if (lastX != null && firstX != null) {
      ctx.lineTo(lastX, chart._topMargin + chart.chartHeight);
      ctx.lineTo(firstX, chart._topMargin + chart.chartHeight);
    }
    ctx.closePath();
    ctx.fill();
  }

  ctx.beginPath();
  ctx.strokeStyle = color.toJS;
  ctx.fillStyle = color.toJS;
  ctx.lineWidth = lineWidth;

  ({double x, double y, bool isActive})? previous;
  for (var point in transformedPoints(chart)) {
    if (previous == null) {
      ctx.moveTo(point.x, point.y);
    } else {
      if (smoothing > 0) {
        Point cp1 = Point((previous.x + point.x) / 2, previous.y);
        Point cp2 = Point((previous.x + point.x) / 2, point.y);

        ctx.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, point.x, point.y);
      } else {
        ctx.lineTo(point.x, point.y);
      }
    }
    previous = point;
  }
  ctx.stroke();

  for (var point in transformedPoints(chart)) {
    ctx.beginPath();
    if (point.isActive) {
      ctx.arc(point.x, point.y, hoverPointRadius ?? (pointRadius + 2), 0, 2 * pi);
    } else {
      ctx.arc(point.x, point.y, pointRadius, 0, 2 * pi);
    }
    ctx.stroke();
    ctx.fill();
  }
}