scale(vertices) {
    // Figure out the final size of the image
    let maxX = -Number.MAX_VALUE;
    let maxY = -Number.MAX_VALUE;
    let minX = Number.MAX_VALUE;
    let minY = Number.MAX_VALUE;

    for (var i = 0; i < vertices.length; i++) {
      if (!vertices[i].value.isDrawn) {
        continue;
      }

      let p = vertices[i].position;
      if (maxX < p.x) maxX = p.x;
      if (maxY < p.y) maxY = p.y;
      if (minX > p.x) minX = p.x;
      if (minY > p.y) minY = p.y;
    } // Add padding


    var padding = this.opts.padding;
    maxX += padding;
    maxY += padding;
    minX -= padding;
    minY -= padding;
    this.drawingWidth = maxX - minX;
    this.drawingHeight = maxY - minY;
    var scaleX = this.canvas.offsetWidth / this.drawingWidth;
    var scaleY = this.canvas.offsetHeight / this.drawingHeight;
    var scale = scaleX < scaleY ? scaleX : scaleY;
    this.ctx.scale(scale, scale);
    this.offsetX = -minX;
    this.offsetY = -minY; // Center

    if (scaleX < scaleY) {
      this.offsetY += this.canvas.offsetHeight / (2.0 * scale) - this.drawingHeight / 2.0;
    } else {
      this.offsetX += this.canvas.offsetWidth / (2.0 * scale) - this.drawingWidth / 2.0;
    }
  }
Scale the canvas based on vertex positions.

@param {Vertex[]} vertices An array of vertices containing the vertices associated with the current molecule.