fit(options, initialZoom = false) {
    options = normalizeFitOptions(options, this.body.nodeIndices);

    const canvasWidth = this.canvas.frame.canvas.clientWidth;
    const canvasHeight = this.canvas.frame.canvas.clientHeight;

    let range;
    let zoomLevel;
    if (canvasWidth === 0 || canvasHeight === 0) {
      // There's no point in trying to fit into zero sized canvas. This could
      // potentially even result in invalid values being computed. For example
      // for network without nodes and zero sized canvas the zoom level would
      // end up being computed as 0/0 which results in NaN. In any other case
      // this would be 0/something which is again pointless to compute.
      zoomLevel = 1;

      range = NetworkUtil.getRange(this.body.nodes, options.nodes);
    } else if (initialZoom === true) {
      // check if more than half of the nodes have a predefined position. If so, we use the range, not the approximation.
      let positionDefined = 0;
      for (const nodeId in this.body.nodes) {
        if (Object.prototype.hasOwnProperty.call(this.body.nodes, nodeId)) {
          const node = this.body.nodes[nodeId];
          if (node.predefinedPosition === true) {
            positionDefined += 1;
          }
        }
      }
      if (positionDefined > 0.5 * this.body.nodeIndices.length) {
        this.fit(options, false);
        return;
      }

      range = NetworkUtil.getRange(this.body.nodes, options.nodes);

      const numberOfNodes = this.body.nodeIndices.length;
      zoomLevel = 12.662 / (numberOfNodes + 7.4147) + 0.0964822; // this is obtained from fitting a dataset from 5 points with scale levels that looked good.

      // correct for larger canvasses.
      const factor = Math.min(canvasWidth / 600, canvasHeight / 600);
      zoomLevel *= factor;
    } else {
      this.body.emitter.emit("_resizeNodes");
      range = NetworkUtil.getRange(this.body.nodes, options.nodes);

      const xDistance = Math.abs(range.maxX - range.minX) * 1.1;
      const yDistance = Math.abs(range.maxY - range.minY) * 1.1;

      const xZoomLevel = canvasWidth / xDistance;
      const yZoomLevel = canvasHeight / yDistance;

      zoomLevel = xZoomLevel <= yZoomLevel ? xZoomLevel : yZoomLevel;
    }

    if (zoomLevel > options.maxZoomLevel) {
      zoomLevel = options.maxZoomLevel;
    } else if (zoomLevel < options.minZoomLevel) {
      zoomLevel = options.minZoomLevel;
    }

    const center = NetworkUtil.findCenter(range);
    const animationOptions = {
      position: center,
      scale: zoomLevel,
      animation: options.animation,
    };
    this.moveTo(animationOptions);
  }
This function zooms out to fit all data on screen based on amount of nodes
@param {object} [options={{nodes=Array}}]
@param options
@param {boolean} [initialZoom]  | zoom based on fitted formula or range, true = fitted, default = false;