示例#1
0
 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))
示例#2
0
文件: gauge.py 项目: aroraumang/pygal
 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))
示例#3
0
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
示例#4
0
文件: time.py 项目: madaiz11/pygal
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))
示例#5
0
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))
示例#6
0
文件: dual.py 项目: sjourdois/pygal
    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))
示例#7
0
文件: dual.py 项目: madaiz11/pygal
    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))
示例#8
0
文件: graph.py 项目: doofinder/pygal
 def _x_label_format_if_value(self, label):
     if not is_str(label):
         return self._x_format(label)
     return label
示例#9
0
 def _x_label_format_if_value(self, label):
     if not is_str(label):
         return self._x_format(label)
     return label
示例#10
0
 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)