code: def _box_size(points, width=None, height=None, padding=0.0):
      """Given a series of points, calculate an appropriate box size.
  
      Parameters
      ----------
      points : array, shape (n_points, 2)
          The centers of the axes as a list of (x, y) coordinate pairs. Normally
          these are points in the range [0, 1] centered at 0.5.
      width : float | None
          An optional box width to enforce. When set, only the box height will be
          calculated by the function.
      height : float | None
          An optional box height to enforce. When set, only the box width will be
          calculated by the function.
      padding : float
          Portion of the box to reserve for padding. The value can range between
          0.0 (boxes will touch, default) to 1.0 (boxes consist of only padding).
  
      Returns
      -------
      width : float
          Width of the box
      height : float
          Height of the box
      """
  
      def xdiff(a, b):
          return np.abs(a[0] - b[0])
  
      def ydiff(a, b):
          return np.abs(a[1] - b[1])
  
      points = np.asarray(points)
      all_combinations = list(combinations(points, 2))
  
      if width is None and height is None:
          if len(points) <= 1:
              # Trivial case first
              width = 1.0
              height = 1.0
          else:
              # Find the closest two points A and B.
              a, b = all_combinations[np.argmin(pdist(points))]
  
              # The closest points define either the max width or max height.
              w, h = xdiff(a, b), ydiff(a, b)
              if w > h:
                  width = w
              else:
                  height = h
  
      # At this point, either width or height is known, or both are known.
      if height is None:
          # Find all axes that could potentially overlap horizontally.
          hdist = pdist(points, xdiff)
          candidates = [
              all_combinations[i]
              for i, d in enumerate(hdist)
              if d < width
          ]
  
          if len(candidates) == 0:
              # No axes overlap, take all the height you want.
              height = 1.0
          else:
              # Find an appropriate height so all none of the found axes will
              # overlap.
              height = np.min([ydiff(*c) for c in candidates])
  
      elif width is None:
          # Find all axes that could potentially overlap vertically.
          vdist = pdist(points, ydiff)
          candidates = [
              all_combinations[i]
              for i, d in enumerate(vdist)
              if d < height
          ]
  
          if len(candidates) == 0:
              # No axes overlap, take all the width you want.
              width = 1.0
          else:
              # Find an appropriate width so all none of the found axes will
              # overlap.
              width = np.min([xdiff(*c) for c in candidates])
  
      # Add a bit of padding between boxes
      width *= 1 - padding
      height *= 1 - padding
  
      return width, height
  
imports: import logging
  from collections import defaultdict
  from itertools import combinations
  from pathlib import Path
  import numpy
  from scipy.spatial.distance import pdist, squareform
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import _FNIRS_CH_TYPES_SPLIT, _picks_to_idx, pick_types
  from ..transforms import _cart_to_sph, _pol_to_cart
  from ..utils import _check_ch_locs, _check_fname, _check_option, _check_sphere, _clean_names, fill_doc, logger, warn
  from ..viz.topomap import plot_layout
  from .channels import _get_ch_info
label_desc: Use image node_id 8 for calling a global function with example usage: _box_size(points, width, height, padding) and returns: width,  height, np, np