code: function (inner, outer) {
  			each([['x', 'width'], ['y', 'height']], function (dim) {
  				var pos = dim[0],
  					size = dim[1];
  				if (inner[pos] + inner[size] > outer[pos] + outer[size]) { // right overflow
  					if (inner[size] > outer[size]) { // the general size is greater, fit fully to outer
  						inner[size] = outer[size];
  						inner[pos] = outer[pos];
  					} else { // align right
  						inner[pos] = outer[pos] + outer[size] - inner[size];
  					}
  				}
  				if (inner[size] > outer[size]) {
  					inner[size] = outer[size];
  				}
  				if (inner[pos] < outer[pos]) {
  					inner[pos] = outer[pos];
  				}
  				
  			});
  
  			return inner;
  		}
docs: Fit an inner box to an outer. If the inner box overflows left or right, align it to the sides of the
  outer. If it overflows both sides, fit it within the outer. This is a pattern that occurs more places
  in Highcharts, perhaps it should be elevated to a common utility function.