def _process_svg(self, document, properties, attributes): root = document.getroot() if self._menu.selected is not None: needle = self.page.theme.get_element("needle", root = root) needle_center = self.page.theme.get_element("needle_center", root = root) val = float(self._menu.selected.sensor.value) """ The title contains the bounds for the gauge, in the format lower_val,upper_val,middle_val,lower_deg,upper_deg """ gauge_data = needle_center.get("title").split(",") lower_val = float(gauge_data[0]) upper_val = float(gauge_data[1]) middle_val = float(gauge_data[2]) lower_deg = float(gauge_data[3]) upper_deg = float(gauge_data[4]) # Clamp the value val = min(upper_val, max(lower_val, val)) # Ratio of gauge bounds to rotate by ratio = val / ( upper_val - lower_val ) """ Work out total number of degrees in the bounds """ total_deg = upper_deg + ( 360 - lower_deg ) # Work out total number of degress to rotate rot_degrees = total_deg * ratio # degr = lower_deg degr += rot_degrees """ This is a bit weak. It doesn't take transformations into account, so care is needed in the SVG. """ center_bounds = g15svg.get_bounds(needle_center) needle.set("transform", "rotate(%f,%f,%f)" % (degr, center_bounds[0], center_bounds[1]) )
def get_bounds(element): return g15svg.get_bounds(element)