Calculate heights and widths of axes and adjust
    the size of the figure to match the aspect.
545496
def fix_aspect(fig, nrows, ncols, title=None, extra_artists=[],
               vspace=0.2, hspace=0.2):
    
    fig.canvas.draw()
    w, h = fig.get_size_inches()

    # Compute maximum height and width of each row and columns
    rows = resolve_rows([[ax] for ax in fig.axes])
    rs, cs = len(rows), max([len(r) for r in rows])
    heights = [[] for i in range(cs)]
    widths = [[] for i in range(rs)]
    for r, row in enumerate(rows):
        for c, ax in enumerate(row):
            bbox = ax.get_tightbbox(fig.canvas.get_renderer())
            heights[c].append(bbox.height)
            widths[r].append(bbox.width)
    height = (max([sum(c) for c in heights])) + nrows*vspace*fig.dpi
    width = (max([sum(r) for r in widths])) + ncols*hspace*fig.dpi

    # Compute aspect and set new size (in inches)
    aspect = height/width
    offset = 0
    if title and title.get_text():
        offset = title.get_window_extent().height/fig.dpi
    fig.set_size_inches(w, (w*aspect)+offset)

    # Redraw and adjust title position if defined
    fig.canvas.draw()
    if title and title.get_text():
        extra_artists = [a for a in extra_artists
                         if a is not title]
        bbox = get_tight_bbox(fig, extra_artists)
        top = bbox.intervaly[1]
        if title and title.get_text():
            title.set_y((top/(w*aspect)))
808986
def _calcQuadSize(corners, aspectRatio):
        '''
        
        '''
        if aspectRatio > 1:  # x is bigger -> reduce y
            x_length = PerspectiveCorrection._quadXLength(corners)
            y = x_length / aspectRatio
            return x_length, y
        else:  # y is bigger -> reduce x
            y_length = PerspectiveCorrection._quadYLength(corners)
            x = y_length * aspectRatio
            return x, y_length
410571
def pick_orientation(img1, img2, spacing, desired_aspect=1.618):
    
    w1, h1 = img1.size
    w2, h2 = img2.size

    size_a = (w1 + spacing + w2, max(h1, h2, 1))
    size_b = (max(w1, w2, 1), h1 + spacing + h2)

    aspect_a = size_a[0] / size_a[1]
    aspect_b = size_b[0] / size_b[1]

    goodness_a = min(desired_aspect, aspect_a) / max(desired_aspect, aspect_a)
    goodness_b = min(desired_aspect, aspect_b) / max(desired_aspect, aspect_b)

    return 'lr' if goodness_a >= goodness_b else 'tb'
176439
def create_figure(width=20, height=10):
    
    figure = plt.figure(figsize=(width, height))
    axis = figure.add_subplot(1, 1, 1)
    return figure, axis
132144
function (axisModel, api) {
        this._rect = getLayoutRect(
            {
                left: axisModel.get('left'),
                top: axisModel.get('top'),
                right: axisModel.get('right'),
                bottom: axisModel.get('bottom'),
                width: axisModel.get('width'),
                height: axisModel.get('height')
            },
            {
                width: api.getWidth(),
                height: api.getHeight()
            }
        );

        this._adjustAxis();
    }
918789
def size_when_fitting(target, dimensions = get_base_dimensions)
      zoom = [
        dimensions[:width].to_f / target[:width],
        dimensions[:height].to_f / target[:height]
      ].max

      if zoom == 0.0
        width = target[:width]
        height = target[:height]
      else
        width = (dimensions[:width] / zoom).round
        height = (dimensions[:height] / zoom).round
      end

      {width: width.to_i, height: height.to_i}
    end
870377
private void adjustMarkerHeights() {
		double mm = _n[1] - 1.0;
		double mp = _n[1] + 1.0;
		if (_nn[0] >= mp && _n[2] > mp) {
			_q[1] = qPlus(mp, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]);
			_n[1] = mp;
		} else if (_nn[0] <= mm && _n[0] < mm) {
			_q[1] = qMinus(mm, _n[0], _n[1], _n[2], _q[0], _q[1], _q[2]);
			_n[1] = mm;
		}

		mm = _n[2] - 1.0;
		mp = _n[2] + 1.0;
		if (_nn[1] >= mp && _n[3] > mp) {
			_q[2] = qPlus(mp, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]);
			_n[2] = mp;
		} else if (_nn[1] <= mm && _n[1] < mm) {
			_q[2] = qMinus(mm, _n[1], _n[2], _n[3], _q[1], _q[2], _q[3]);
			_n[2] = mm;
		}

		mm = _n[3] - 1.0;
		mp = _n[3] + 1.0;
		if (_nn[2] >= mp && _n[4] > mp) {
			_q[3] = qPlus(mp, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]);
			_n[3] = mp;
		} else if (_nn[2] <= mm && _n[2] < mm) {
			_q[3] = qMinus(mm, _n[2], _n[3], _n[4], _q[2], _q[3], _q[4]);
			_n[3] = mm;
		}
	}
993552
def inset_sizes(cls, original_width, original_height, target_width, target_height):
        
        if target_width >= original_width and target_height >= original_height:
            target_width = float(original_width)
            target_height = original_height

        elif target_width <= original_width and target_height >= original_height:
            k = original_width / float(target_width)
            target_height = int(original_height / k)

        elif target_width >= original_width and target_height <= original_height:
            k = original_height / float(target_height)
            target_width = int(original_width / k)

        elif target_width < original_width and target_height < original_height:
            k = original_width / float(original_height)
            k_w = original_width / float(target_width)
            k_h = original_height / float(target_height)

            if k_w >= k_h:
                target_height = int(target_width / k)
            else:
                target_width = int(target_height * k)

        return target_width, target_height
821569
def calculate(self, scene, xaxis, yaxis):
        
        # build the grid location
        sceneRect = scene.sceneRect()
        
        # process axis information
        h_lines  = []
        h_alt    = []
        h_labels = []
        v_lines  = []
        v_alt    = []
        v_labels = []
        
        xlabels   = []
        xcount    = 1
        xsections = 1
        xdelta    = 0
        xdeltamin = 0
        
        ylabels   = []
        ycount    = 1
        ysections = 1
        ydeltamin = 0
        ydelta    = 0
        
        axis_lft  = 0
        axis_rht  = 0
        axis_bot  = 0
        axis_top  = 0
        
        # precalculate xaxis information for width changes
        if xaxis and self.showXAxis():
            size = sceneRect.width()
            xdeltamin = xaxis.minimumLabelWidth()
            result = self.calculateAxis(xaxis, size, xdeltamin)
            
            xlabels, xcount, xsections, newWidth, xdelta = result
            if newWidth != size:
                sceneRect.setWidth(newWidth)
        
        # precalculate yaxis information for height changes
        if yaxis and self.showYAxis():
            size = sceneRect.height()
            ydeltamin = yaxis.minimumLabelHeight()
            result = self.calculateAxis(yaxis, size, ydeltamin)
            
            ylabels, ycount, ysections, newHeight, ydelta = result
            if newHeight != size:
                sceneRect.setHeight(newHeight)
        
        # generate the xaxis
        if xaxis and self.showXAxis():
            x        = sceneRect.left() + xdeltamin / 2
            axis_lft = x
            axis_rht = x
            alt      = False
            
            for i in range(xcount):
                v_lines.append(QLineF(x, sceneRect.top(),
                                      x, sceneRect.bottom()))
                
                # store alternate info
                if alt:
                    alt_rect = QRectF(x - xdelta, sceneRect.top(),
                                      xdelta, sceneRect.height())
                    v_alt.append(alt_rect)
                
                # store label information
                v_labels.append((x, xdelta, xlabels[i]))
                axis_rht = x
                
                x += xdelta
                alt = not alt
        
        # generate the yaxis
        if yaxis and self.showYAxis():
            y        = sceneRect.bottom() - ydeltamin / 2
            axis_bot = y
            axis_top = y
            alt      = False
            
            for i in range(ycount):
                h_lines.append(QLineF(sceneRect.left(), y,
                                      sceneRect.right(), y))
                
                # store alternate color
                if alt:
                    alt_rect = QRectF(sceneRect.left(), y,
                                      sceneRect.width(), ydelta)
                    h_alt.append(alt_rect)
                
                # store the vertical information
                h_labels.append((y, ydelta, ylabels[i]))
                axis_top = y
                
                y -= ydelta
                alt = not alt
        
        # assign the build data
        self._buildData['grid_h_lines']  = h_lines
        self._buildData['grid_h_alt']    = h_alt
        self._buildData['grid_h_labels'] = h_labels
        self._buildData['grid_v_lines']  = v_lines
        self._buildData['grid_v_alt']    = v_alt
        self._buildData['grid_v_labels'] = v_labels
        self._buildData['grid_rect']     = sceneRect
        self._buildData['axis_rect']     = QRectF(axis_lft, axis_top,
                                                  axis_rht - axis_lft,
                                                  axis_bot - axis_top)
        
        scene.setSceneRect(sceneRect)
        return sceneRect
499956
function setSizes(){
  
    // Put the scatter plot on the left.
    scatterPlot.box = {
      x: 0,
      y: 0,
      width: div.clientWidth / 2,
      height: div.clientHeight
    };

    // Put the bar chart on the right.
    barChart.box = {
      x: div.clientWidth / 2,
      y: 0,
      width: div.clientWidth / 2,
      height: div.clientHeight
    };
  }
447430
function(corner, size, scale) {
		scale = scale || 1;
		size = size || this.size;

		var width = size[0] * scale,
			height = size[1] * scale,
			width2 = Math.ceil(width / 2), height2 = Math.ceil(height / 2),

		// Define tip coordinates in terms of height and width values
		tips = {
			br:	[0,0,		width,height,	width,0],
			bl:	[0,0,		width,0,		0,height],
			tr:	[0,height,	width,0,		width,height],
			tl:	[0,0,		0,height,		width,height],
			tc:	[0,height,	width2,0,		width,height],
			bc:	[0,0,		width,0,		width2,height],
			rc:	[0,0,		width,height2,	0,height],
			lc:	[width,0,	width,height,	0,height2]
		};

		// Set common side shapes
		tips.lt = tips.br; tips.rt = tips.bl;
		tips.lb = tips.tr; tips.rb = tips.tl;

		return tips[ corner.abbrev() ];
	}
242484
def do_size(self, w, h):
        """"""
        if (w is None):
            self.logger.debug("size: no scaling (nop)")
        else:
            self.logger.debug("size: scaling to (%d,%d)" % (w, h))
            self.image = self.image.resize((w, h))
            self.width = w
            self.height = h
501266
def resize(self, width, height):
        
        if self.example:
            self.example.resize(width, height)
385419
def _fits_surface(self, width, height):
        
        assert(width > 0 and height > 0)
        if self.rot and (width > self.width or height > self.height):
            width, height = height, width

        if width > self.width or height > self.height:
            return False
        else:
            return True
297364
function() {
    var self = this;

    // Calculate the scale of our window from "full" size.
    var scale = window.innerWidth / 3600;

    // Resize and reposition the sprite overlays.
    var keys = Object.keys(self._spriteMap);
    for (var i=0; i<keys.length; i++) {
      var sprite = window[keys[i]];
      sprite.style.width = Math.round(self._width[i] * scale) + 'px';
      if (self._left[i]) {
        sprite.style.left = Math.round(self._left[i] * scale) + 'px';
      }
    }
  }
1262546
def _scale(self, image, width, height):
        
        image['options']['scale'] = '%sx%s!' % (width, height)
        image['size'] = (width, height)  # update image size
        return image
565353
private void calculate(final int WIDTH, final int HEIGHT) {
        // Set start and stop values
        start = DATA_LIST.getFirst().getValue();
        stop = DATA_LIST.getLast().getValue();

        // Find min and max values
        lo = DATA_LIST.getFirst().getValue();
        hi = DATA_LIST.getFirst().getValue();
        loIndex = 0;
        hiIndex = 0;
        final int SIZE = DATA_LIST.size();
        double y;
        for (int index = 0; index < SIZE; index++) {
            y = DATA_LIST.get(index).getValue();
            calcHiLoValues(y, index);
        }

        // Calculate the range from min to max
        rangeY = hi - lo;

        // Calculate the offset between the graph and the border
        //offset = (double) HEIGHT * OFFSET_FACTOR;

        // Calculate the scaling in x- and y-direction
        scaleY = rangeY / ((double) HEIGHT - (offset * 2));

        // Fill the pointlist with smoothing if possible
        pointList.clear();
        if (DATA_LIST.size() > 5 && smoothing) {
            smoothData();
        } else {
            for (int index = 0; index < SIZE; index++) {
                pointList.add(new Point2D.Double((DATA_LIST.get(index).getTimeStamp() - DATA_LIST.getFirst().getTimeStamp()) * pixelResolution, ((DATA_LIST.get(index).getValue() - lo) * (1 / scaleY) + offset)));
            }
        }

        // Calculate average and normal area if one of them is visible
        if (averageVisible || normalAreaVisible) {
            final double AVERAGE = (getAverage() - lo) * (1 / scaleY) + offset;
            final double STANDARD_DEVIATION = (getStandardDeviation() * (1 / scaleY));
            NORMAL_AREA.setRect(INNER_BOUNDS.x, AVERAGE - STANDARD_DEVIATION, INNER_BOUNDS.width, 2 * STANDARD_DEVIATION);
            AVERAGE_LINE.setLine(INNER_BOUNDS.x, AVERAGE, INNER_BOUNDS.x + INNER_BOUNDS.width, AVERAGE);
        }
    }