def update(self, cx, options, width, height, xticks, yticks): self.title.x = options.padding.left self.title.y = options.padding.top self.title.w = width - (options.padding.left + options.padding.right) self.title.h = get_text_extents(cx, options.title, options.titleFont, options.titleFontSize, options.encoding)[1] lookup = dict([(slice.xval, slice) for slice in self.slices]) self.chart.x = self.title.x self.chart.y = self.title.y + self.title.h self.chart.w = self.title.w self.chart.h = height - self.title.h - ( options.padding.top + options.padding.bottom ) centerx = self.chart.x + self.chart.w * 0.5 centery = self.chart.y + self.chart.h * 0.5 self.radius = min(self.chart.w / 2.0, self.chart.h / 2.0) for tick in xticks: slice = lookup.get(tick[0], None) width, height = get_text_extents(cx, tick[1], options.axis.tickFont, options.axis.tickFontSize, options.encoding) angle = slice.getNormalisedAngle() radius = self._get_min_radius(angle, centerx, centery, width, height) self.radius = min(self.radius, radius) # Now that we now the radius we move the ticks as close as we can # to the circle for i, tick in enumerate(xticks): slice = lookup.get(tick[0], None) angle = slice.getNormalisedAngle() self.ticks[i] = self._get_tick_position(self.radius, angle, self.ticks[i], centerx, centery)
def update(self, cx, options, width, height, xticks, yticks): self.title.x = options.padding.left self.title.y = options.padding.top self.title.w = width - (options.padding.left + options.padding.right) self.title.h = get_text_extents(cx, options.title, options.titleFont, options.titleFontSize, options.encoding)[1] self.chart.x = self.title.x self.chart.y = self.title.y + self.title.h self.chart.w = self.title.w self.chart.h = height - self.title.h - (options.padding.top + options.padding.bottom) centerx = self.chart.x + self.chart.w * 0.5 centery = self.chart.y + self.chart.h * 0.5 angle = 0 angle_between =(2 * math.pi) / len(xticks) self.angles = [angle] self.radius = min(self.chart.w / 2.0, self.chart.h / 2.0) for tick in xticks: width, height = get_text_extents(cx, tick[1], options.axis.tickFont, options.axis.tickFontSize, options.encoding) radius = self._get_min_radius(angle, centerx, centery, width, height) self.radius = min(self.radius, radius) angle += angle_between self.angles.append(angle) # Now that we now the radius we move the ticks as close as we can # to the circle for i, tick in enumerate(xticks): self.ticks[i] = self._get_tick_position(self.radius, self.angles[i], self.ticks[i], centerx, centery)
def update(self, cx, options, width, height, xticks, yticks): self.title.x = options.padding.left self.title.y = options.padding.top self.title.w = width - (options.padding.left + options.padding.right) self.title.h = get_text_extents(cx, options.title, options.titleFont, options.titleFontSize, options.encoding)[1] lookup = dict([(slice.xval, slice) for slice in self.slices]) self.chart.x = self.title.x self.chart.y = self.title.y + self.title.h self.chart.w = self.title.w self.chart.h = height - self.title.h - (options.padding.top + options.padding.bottom) centerx = self.chart.x + self.chart.w * 0.5 centery = self.chart.y + self.chart.h * 0.5 self.radius = min(self.chart.w / 2.0, self.chart.h / 2.0) for tick in xticks: slice = lookup.get(tick[0], None) width, height = get_text_extents(cx, tick[1], options.axis.tickFont, options.axis.tickFontSize, options.encoding) angle = slice.getNormalisedAngle() radius = self._get_min_radius(angle, centerx, centery, width, height) self.radius = min(self.radius, radius) # Now that we now the radius we move the ticks as close as we can # to the circle for i, tick in enumerate(xticks): slice = lookup.get(tick[0], None) angle = slice.getNormalisedAngle() self.ticks[i] = self._get_tick_position(self.radius, angle, self.ticks[i], centerx, centery)
def update(self, cx, options, width, height, xticks, yticks): self.title.x = options.padding.left self.title.y = options.padding.top self.title.w = width - (options.padding.left + options.padding.right) self.title.h = get_text_extents(cx, options.title, options.titleFont, options.titleFontSize, options.encoding)[1] self.chart.x = self.title.x self.chart.y = self.title.y + self.title.h self.chart.w = self.title.w self.chart.h = height - self.title.h - (options.padding.top + options.padding.bottom) self.radius = min(self.chart.w / 2.0, self.chart.h / 2.0)
def _renderAxis(self, cx): """Renders the axis for radar charts""" if self.options.axis.x.hide or not self.xticks: return self.xlabels = [] if self.debug: px = max(cx.device_to_user_distance(1, 1)) cx.set_source_rgba(0, 0, 1, 0.5) for x, y, w, h in self.layout.ticks: cx.rectangle(x, y, w, h) cx.stroke() cx.arc(x + w / 2.0, y + h / 2.0, 5 * px, 0, 2 * math.pi) cx.fill() cx.arc(x, y, 2 * px, 0, 2 * math.pi) cx.fill() cx.select_font_face(self.options.axis.labelFont, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) cx.set_font_size(self.options.axis.labelFontSize) cx.set_source_rgb(*hex2rgb(self.options.axis.labelColor)) for i, tick in enumerate(self.xticks): label = tick[1] x, y, w, h = self.layout.ticks[i] xb, yb, width, height, xa, ya = cx.text_extents(label) # draw label with text tick[1] cx.move_to(x - xb, y - yb) cx.show_text(label) self.xlabels.append(label) # Draw y-axis centerx = self.layout.chart.x + self.layout.chart.w * 0.5 centery = self.layout.chart.y + self.layout.chart.h * 0.5 cr = self.layout.radius / float(self.slice) cx.set_line_width(self.options.axis.lineWidth) cx.set_source_rgb(*hex2rgb(self.options.axis.lineColor)) if self.frame == 'circle': for i in range(self.slice): cx.move_to(centerx, centery) cx.arc(centerx, centery, (i+1) * cr, 0, 2*math.pi) else: for i in range(self.slice): for j, angle in enumerate(self.layout.angles): x = centerx + math.cos(angle) * (i+1) * cr y = centery + math.sin(angle) * (i+1) * cr if j: cx.line_to(x, y) else: cx.move_to(x, y) cx.close_path() cx.stroke() cx.select_font_face(self.options.axis.tickFont, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) cx.set_font_size(self.options.axis.tickFontSize) cx.set_source_rgb(*hex2rgb(self.options.axis.labelColor)) for i in range(self.slice): yval = "%.1f" % (self.maxyval / self.slice * (i+1)) tw, th = get_text_extents(cx, yval, self.options.axis.tickFont, self.options.axis.tickFontSize, self.options.encoding) tx = centerx + (i+1) * cr - tw cx.move_to(tx, centery+th) cx.show_text(yval)
def _renderAxis(self, cx): """Renders the axis for radar charts""" if self.options.axis.x.hide or not self.xticks: return self.xlabels = [] if self.debug: px = max(cx.device_to_user_distance(1, 1)) cx.set_source_rgba(0, 0, 1, 0.5) for x, y, w, h in self.layout.ticks: cx.rectangle(x, y, w, h) cx.stroke() cx.arc(x + w / 2.0, y + h / 2.0, 5 * px, 0, 2 * math.pi) cx.fill() cx.arc(x, y, 2 * px, 0, 2 * math.pi) cx.fill() cx.select_font_face(self.options.axis.labelFont, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) cx.set_font_size(self.options.axis.labelFontSize) cx.set_source_rgb(*hex2rgb(self.options.axis.labelColor)) for i, tick in enumerate(self.xticks): label = tick[1] x, y, w, h = self.layout.ticks[i] xb, yb, width, height, xa, ya = cx.text_extents(label) # draw label with text tick[1] cx.move_to(x - xb, y - yb) cx.show_text(label) self.xlabels.append(label) # Draw y-axis centerx = self.layout.chart.x + self.layout.chart.w * 0.5 centery = self.layout.chart.y + self.layout.chart.h * 0.5 cr = self.layout.radius / float(self.slice) cx.set_line_width(self.options.axis.lineWidth) cx.set_source_rgb(*hex2rgb(self.options.axis.lineColor)) if self.frame == 'circle': for i in xrange(self.slice): cx.move_to(centerx, centery) cx.arc(centerx, centery, (i+1) * cr, 0, 2*math.pi) else: for i in xrange(self.slice): for j, angle in enumerate(self.layout.angles): x = centerx + math.cos(angle) * (i+1) * cr y = centery + math.sin(angle) * (i+1) * cr if j: cx.line_to(x, y) else: cx.move_to(x, y) cx.close_path() cx.stroke() cx.select_font_face(self.options.axis.tickFont, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) cx.set_font_size(self.options.axis.tickFontSize) cx.set_source_rgb(*hex2rgb(self.options.axis.labelColor)) for i in xrange(self.slice): yval = "%.1f" % (self.maxyval / self.slice * (i+1)) tw, th = get_text_extents(cx, yval, self.options.axis.tickFont, self.options.axis.tickFontSize, self.options.encoding) tx = centerx + (i+1) * cr - tw cx.move_to(tx, centery+th) cx.show_text(yval)