def getWindow(self): """ Get a window tuple, equivocal to that of a graphing calculator. This duplicates Apple's algorithm from Numbers (rounding the maximum value from the dominant quadrant up to the nearest five if the number is max is less than 100). The resulting tuple is in the format (min value <int or float>, max value <int or float>). """ if self.type == 'independent': # we only pay attention to len return 0 - len(self.negative_data), len(self.positive_data) else: # If num < 100 round up to nearest 5. If num > 100 don't round. p_max = render_utils.safe_max(self.positive_data) if p_max < 100: p_max = render_utils.roundUpToNearest(p_max, 5) p_min = render_utils.safe_min(self.negative_data) if p_min < 100: p_min = 0 - render_utils.roundUpToNearest(abs(p_min), 5) # re-invert if p_min != 0 and p_max != 0: # no need to scale. avoid 0 div errors. if abs(p_min) < p_max: step_value = p_max / self.scheme['format']['steps'] p_min = step_value * round(p_min / step_value) else: step_value = p_min / self.scheme['format']['steps'] p_max = step_value * round(p_max / step_value) return p_min, p_max
def labelMaxDimensions(self, label_scheme, contents, use_cache = True): """ Return the dimensions of the largest string in the contents list. Takes two arguments: label_scheme, and contents - where label_scheme is the scheme to apply to the labels in the contents list or tuple. If the use_cache argument is True (which it is by default), only the height or width will be calculated (shaving ~.004 seconds from proc. time), and the other value will be 0. """ text_dims = label_scheme['font'].dimensions(contents, \ label_scheme['rotation']) if not isinstance(text_dims, list): width, height = text_dims else: width, height = render_utils.safe_max(text_dims) if 'margin-left' in label_scheme.keys(): width += label_scheme['margin-left'] if 'margin-right' in label_scheme.keys(): width += label_scheme['margin-right'] if 'margin-top' in label_scheme.keys(): height += label_scheme['margin-top'] if 'margin-bottom' in label_scheme.keys(): height += label_scheme['margin-bottom'] return (width, height)