def get_coordinates(self): """ return shape coordinates in percentages (left, top, right, bottom) """ (x1, y1), (x2, y2) = self.coordinates drawing_width = pixels_to_EMU(self._chart.drawing.width) drawing_height = pixels_to_EMU(self._chart.drawing.height) plot_width = drawing_width * self._chart.width plot_height = drawing_height * self._chart.height margin_left = self._chart._get_margin_left() * drawing_width xunit = plot_width / self._chart.get_x_units() margin_top = self._chart._get_margin_top() * drawing_height yunit = self._chart.get_y_units() x_start = (margin_left + (float(x1) * xunit)) / drawing_width y_start = ((margin_top + plot_height - (float(y1) * yunit)) / drawing_height) x_end = (margin_left + (float(x2) * xunit)) / drawing_width y_end = ((margin_top + plot_height - (float(y2) * yunit)) / drawing_height) def _norm_pct(pct): """ force shapes to appear by truncating too large sizes """ if pct > 1: pct = 1 elif pct < 0: pct = 0 return pct # allow user to specify y's in whatever order # excel expect y_end to be lower if y_end < y_start: y_end, y_start = y_start, y_end return (_norm_pct(x_start), _norm_pct(y_start), _norm_pct(x_end), _norm_pct(y_end))
def _set_border_width(self, w): self._border_width = pixels_to_EMU(w)
def get_emu_dimensions(self): """ return (x, y, w, h) in EMU """ return (pixels_to_EMU(self.left), pixels_to_EMU(self.top), pixels_to_EMU(self._width), pixels_to_EMU(self._height))
def get_y_units(self): """ calculate one unit for y axis in EMU """ dh = pixels_to_EMU(self.drawing.height) return (dh * self.height) / self.y_axis.max