def _compute_y_labels(self): y_pos = compute_scale( self.min_, self.max_, self.logarithmic, self.order_min, self.min_scale, self.max_scale ) if self.y_labels: self._y_labels = [] for i, y_label in enumerate(self.y_labels): if isinstance(y_label, dict): pos = self._adapt(y_label.get('value')) title = y_label.get('label', self._y_format(pos)) elif is_str(y_label): pos = self._adapt(y_pos[i]) title = y_label else: pos = self._adapt(y_label) title = self._y_format(pos) self._y_labels.append((title, pos)) self.min_ = min(self.min_, min(cut(self._y_labels, 1))) self.max_ = max(self.max_, max(cut(self._y_labels, 1))) self._box.set_polar_box( 0, 1, self.min_, self.max_) else: self._y_labels = list(zip(map(self._y_format, y_pos), y_pos))
def positive(x): """Return zero if value is negative""" if x is None: return if is_str(x): return x if x < 0: return 0 return x
def time_to_seconds(x): """Convert a time in a seconds sum""" if isinstance(x, time): return ((((x.hour * 60) + x.minute) * 60 + x.second) * 10 ** 6 + x.microsecond) / 10 ** 6 if is_str(x): return x # Clamp to valid time return x and max(0, min(x, 24 * 3600 - 10 ** -6))
def time_to_seconds(x): """Convert a time in a seconds sum""" if isinstance(x, time): return ((((x.hour * 60) + x.minute) * 60 + x.second) * 10**6 + x.microsecond) / 10**6 if is_str(x): return x # Clamp to valid time return x and max(0, min(x, 24 * 3600 - 10**-6))
def _compute_x_labels(self): x_pos = compute_scale(self._box.xmin, self._box.xmax, self.logarithmic, self.order_min, self.min_scale, self.max_scale) if self.x_labels: self._x_labels = [] for i, x_label in enumerate(self.x_labels): if isinstance(x_label, dict): pos = self._x_adapt(x_label.get('value')) title = x_label.get('label', self._x_format(pos)) elif is_str(x_label): pos = self._x_adapt(x_pos[i % len(x_pos)]) title = x_label else: pos = self._x_adapt(x_label) title = self._x_format(pos) self._x_labels.append((title, pos)) self._box.xmin = min(self._box.xmin, min(cut(self._x_labels, 1))) self._box.xmax = max(self._box.xmax, max(cut(self._x_labels, 1))) else: self._x_labels = list(zip(map(self._x_format, x_pos), x_pos))
def _compute_x_labels(self): x_pos = compute_scale( self._box.xmin, self._box.xmax, self.logarithmic, self.order_min, self.min_scale, self.max_scale ) if self.x_labels: self._x_labels = [] for i, x_label in enumerate(self.x_labels): if isinstance(x_label, dict): pos = self._x_adapt(x_label.get('value')) title = x_label.get('label', self._x_format(pos)) elif is_str(x_label): pos = self._x_adapt(x_pos[i % len(x_pos)]) title = x_label else: pos = self._x_adapt(x_label) title = self._x_format(pos) self._x_labels.append((title, pos)) self._box.xmin = min(self._box.xmin, min(cut(self._x_labels, 1))) self._box.xmax = max(self._box.xmax, max(cut(self._x_labels, 1))) else: self._x_labels = list(zip(map(self._x_format, x_pos), x_pos))
def _x_label_format_if_value(self, label): if not is_str(label): return self._x_format(label) return label
def adapt_code(self, area_code): """ Convert the postcode to lower case. """ if is_str(area_code): return area_code.lower() return super(Postcodes, self).adapt_code(area_code)