resize method

void resize(
  1. [bool forceRedraw = false]
)

Resizes the chart to fit the new size of the container.

Implementation

void resize([bool forceRedraw = false]) {
  var w = container.clientWidth;
  var h = container.clientHeight;

  if (w == 0 || h == 0) return;

  if (w != _width || h != _height) {
    _width = w;
    _height = h;
    forceRedraw = true;

    var dpr = window.devicePixelRatio;
    var scaledW = (w * dpr).round();
    var scaledH = (h * dpr).round();

    void setCanvasSize(CanvasRenderingContext2D ctx) {
      // Scale the drawing canvas by [dpr] to ensure sharp rendering on
      // high pixel density displays.
      ctx.canvas
        ..style.width = '${w}px'
        ..style.height = '${h}px'
        ..width = scaledW
        ..height = scaledH;
      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    }

    setCanvasSize(_context);
    setCanvasSize(_axesContext);
    setCanvasSize(_seriesContext);
  }

  if (forceRedraw) {
    _stopAnimation();
    _dataTableChanged();
    _positionLegend();
    update();
  }
}