Exemplo n.º 1
0
    def get_bbox(self):
        """ recompute and relayout the component and return it's bbox """
        if self.modified:
            new_children = []
            x, y = self.get_location()
            width, height = self.get_size()
            row_labels = self.parent.get_xvalues()
            columns = self.parent.get_series()

            n_columns = len(columns) + 1
            cw = width / n_columns
            ch = height

            rows, cols = self.canvas.to_rowcol(width, height)
            r_height, r_nothing = self.canvas.from_rowcol(1, 1)
            col_width = cols // n_columns

            rlc = row_labels.data.get_column(row_labels.column)

            def pad(s, width):
                if len(s) < width:
                    return s + ' ' * (width - len(s))
                else:
                    return s

            new_children.append(
                display_list.Text(
                    x, y, pad(row_labels.column[0:col_width], col_width),
                    self.canvas.white | curses.A_STANDOUT))
            for idx in range(len(columns)):
                new_children.append(
                    display_list.Text(
                        x + cw + idx * cw, y,
                        pad(columns[idx].column[0:col_width], col_width),
                        self.canvas.white | curses.A_STANDOUT))
            for ridx in range(min(rows - 1, rlc.size())):
                y += r_height
                new_children.append(
                    display_list.Text(
                        x, y, pad(str(rlc.get(ridx))[0:col_width], col_width),
                        self.canvas.white))
                for cidx in range(len(columns)):
                    column = columns[cidx].data.get_column(
                        columns[cidx].column)
                    new_children.append(
                        display_list.Text(
                            x + cw + cidx * cw, y,
                            pad(str(column.get(ridx))[0:col_width], col_width),
                            self.canvas.white))

            self.set_children(new_children)

            return GraphElement.get_bbox(self)
Exemplo n.º 2
0
 def get_bbox(self):
     """ recompute and relayout the component and return it's bbox """
     if self.modified:
         new_children = []
         x, y = self.get_location()
         width, height = self.get_size()
         rows, cols = self.canvas.to_rowcol(width - 4, height)
         r_height, r_width = self.canvas.from_rowcol(1, 1)
         for text, color in self.series_labels:
             new_children.append(
                 display_list.Rect(x, y, x + 1, y + 1, color))
             text = text.strip()
             while text and rows:
                 if len(text) > cols:
                     s_idx = cols
                     while s_idx > 0:
                         if text[s_idx] == ' ':
                             break
                         s_idx -= 1
                     if s_idx <= 0:
                         s_idx = cols
                 else:
                     s_idx = cols
                 new_children.append(
                     display_list.Text(x + 4, y, text[:s_idx],
                                       self.canvas.white))
                 rows -= 1
                 y += r_height
                 text = text[s_idx:].lstrip()
         self.set_children(new_children)
     return GraphElement.get_bbox(self)
Exemplo n.º 3
0
 def get_bbox(self):
     """ recompute and relayout the component and return it's bbox """
     if self.modified:
         new_children = []
         x, y = self.get_location()
         width, height = self.get_size()
         rows, cols = self.canvas.to_rowcol(width, height)
         r_height, r_width = self.canvas.from_rowcol(1, 1)
         text = self.text.strip()
         while text and rows:
             if len(text) > cols:
                 s_idx = cols
                 while s_idx > 0:
                     if text[s_idx] == ' ':
                         break
                     s_idx -= 1
                 if s_idx <= 0:
                     s_idx = cols
             else:
                 s_idx = cols
             new_children.append(
                 display_list.Text(
                     x, y, text[:s_idx], self.canvas.white |
                     (curses.A_STANDOUT
                      if self.is_focus() else curses.A_NORMAL)))
             rows -= 1
             y += r_height
             text = text[s_idx:].lstrip()
         self.set_children(new_children)
     return GraphElement.get_bbox(self)
Exemplo n.º 4
0
 def __init__(self, parent, listoftext=None):
     GraphElement.__init__(self, parent)
     self.series_labels = listoftext
     r_height, r_width = self.canvas.from_rowcol(1, 1)
     x = 0
     y = 0
     for l in self.series_labels:
         self.add_child(display_list.Text(x, y, l, self.canvas.white))
         y += r_height
Exemplo n.º 5
0
    def get_bbox(self):
        """ compute the bounding box """
        if self.modified:
            label_series = self.parent.get_xvalues()
            label_column = label_series.data.get_column(label_series.column)
            data_column = self.series.data.get_column(self.series.column)
            x, y = self.get_location()
            width, height = self.get_size()

            data_idxs = []
            data_total = 0
            for idx in range(0, data_column.size()):
                cell = data_column.get(idx)
                value = cell.get_float_value()
                data_total += value
                data_idxs.append((value, idx, str(label_column.get(idx))))

            data_idxs.sort(reverse=True)

            if data_total > 0:
                total_included = 0
                for idx in range(0, len(data_idxs)):
                    if data_idxs[idx][0] / data_total < 0.02:
                        remaining = len(data_idxs) - idx
                        remaining_idx = data_idxs[idx][1]
                        data_idxs = data_idxs[:idx]
                        data_idxs.append(
                            (data_total - total_included, remaining_idx,
                             "%d < 2%%" % (remaining)))
                        break
                    else:
                        total_included += data_idxs[idx][0]

                total_degrees = 0
                self.set_children([])
                label_children = []
                lcx = x
                lcy = y
                l_height, l_width = self.canvas.from_rowcol(1, 11)
                px = x + l_width
                pw = width - l_width
                py = y + l_height
                ph = height - (l_height * 2)
                for idx in range(0, len(data_idxs)):
                    data_percent = (data_idxs[idx][0] / data_total)
                    data_degrees = round(360.0 * data_percent)
                    slice_color = curses.color_pair(self.canvas.color_min + (
                        30 + (idx * 11) %
                        ((self.canvas.color_max - 30) - self.canvas.color_min))
                                                    )
                    arc = display_list.Arc(px + pw / 2, py + ph / 2,
                                           min(ph, pw) / 2, total_degrees,
                                           total_degrees + data_degrees,
                                           slice_color, True)
                    self.add_child(arc)
                    label = "(%.0f%%) %s" % (data_percent * 100.00,
                                             data_idxs[idx][2][:11])
                    if lcy < y + height:
                        label_children.append(
                            display_list.Text(lcx, lcy, label, slice_color))
                    lcy += l_height
                    total_degrees += data_degrees

                title = self.series.column
                l_height, l_width = self.canvas.from_rowcol(1, len(title))
                lcx = x + width / 2 - l_width / 2
                lcy = y + height - l_height
                label_children.append(
                    display_list.Text(lcx, lcy, title, label_series.color))

                for lc in label_children:
                    self.add_child(lc)

        return GraphElement.get_bbox(self)
Exemplo n.º 6
0
    def get_bbox(self):
        """ compute the bounding box """
        if self.modified:
            new_children = []
            y_values = self.parent.get_series()
            self.range_min = -1
            self.range_max = -1
            self.dy = 0

            if self.parent.is_top():
                top_indexes = self.parent.get_top_indexes()
                for series in y_values:
                    column = series.data.get_column(series.column)
                    for idx in top_indexes:
                        c = column.get(idx)
                        value = c.get_float_value()
                        if self.range_min < 0 or value < self.range_min:
                            self.range_min = value
                        if self.range_max < 0 or value > self.range_max:
                            self.range_max = value
            else:
                for series in y_values:
                    column = series.data.get_column(series.column)
                    for c in data_table.ColumnIterator(column):
                        value = c.get_float_value()
                        if self.range_min < 0 or value < self.range_min:
                            self.range_min = value
                        if self.range_max < 0 or value > self.range_max:
                            self.range_max = value

            if self.range_min <= 0:
                self.range_min = 0
            if self.range_max <= 0:
                self.range_max = 1
            tick_size = max(1.0, (self.range_max - self.range_min)) / 5
            if tick_size > 1:
                tick_size = round(tick_size)
            self.range_max += tick_size
            r_height, r_width = self.canvas.from_rowcol(1, 1)
            width, height = self.get_size()
            ox, oy = self.get_location()
            new_children.append(
                display_list.Rect(ox,
                                  oy,
                                  ox + width,
                                  oy + height,
                                  self.canvas.black,
                                  fill=True))
            oy += height
            ox += (width - 1)
            self.sy = height / max(1.0, (self.range_max - self.range_min))
            x = ox
            y = oy
            points = [(x, y)]
            labels = []
            for data_y in float_range(self.range_min, self.range_max,
                                      tick_size):
                scaled_y = (data_y - self.range_min) * self.sy
                label = data_table.format_float(float(data_y))
                if label.endswith(".00"):
                    label = label[:-3]
                t_x, t_y = self.canvas.round_text_position(
                    x - 3, oy - scaled_y)
                if t_y <= y:
                    l_height, l_width = self.canvas.from_rowcol(
                        1,
                        len(label) + 1)
                    points.append((x, t_y))
                    points.append((t_x, t_y))
                    points.append((x, t_y))
                    labels.append((t_x - l_width, t_y - (l_height / 2), label))
                    y = t_y - l_height

            if points[-1][1] > oy - height:
                points.append((x, oy - height))
            new_children.append(
                display_list.PolyLine(points, self.canvas.green))
            for x, y, label in labels:
                new_children.append(
                    display_list.Text(x, y, label, self.canvas.green))
            self.set_children(new_children)
        return GraphElement.get_bbox(self)
Exemplo n.º 7
0
    def get_bbox(self):
        """ compute the bounding box """
        if self.modified:
            new_children = []
            x_values = self.parent.get_xvalues()
            column = x_values.data.get_column(x_values.column)
            type = None

            for c in data_table.ColumnIterator(column):
                if not type or type == data_table.blank_type:
                    type = c.get_type()
                elif type != c.get_type():
                    type = 'mixed'
            self.range_min = -1
            self.range_max = -1
            self.sx = 0
            self.dx = 0
            self.values = []
            if self.parent.is_top():
                top_indexes = self.parent.get_top_indexes()

            if type in [
                    data_table.blank_type, data_table.string_type, 'mixed'
            ]:
                if self.parent.is_top():
                    self.range_min = 0
                    self.range_max = len(top_indexes)
                    ii = 0
                    for ix in top_indexes:
                        c = column.get(ix)
                        self.values.append((ii, str(c)))
                        ii += 1
                else:
                    self.range_min = 0
                    self.range_max = column.size()
                    ix = 0
                    for c in data_table.ColumnIterator(column):
                        self.values.append((ix, str(c)))
                        ix += 1
            else:
                self.range_min = None
                self.range_max = None
                if self.parent.is_top():
                    for ix in top_indexes:
                        c = column.get(ix)
                        value = c.get_float_value()
                        if self.range_min == None or value < self.range_min:
                            self.range_min = value
                        if self.range_max == None or value > self.range_max:
                            self.range_max = value
                        self.values.append((value, str(c)))
                else:
                    for c in data_table.ColumnIterator(column):
                        value = c.get_float_value()
                        if self.range_min == None or value < self.range_min:
                            self.range_min = value
                        if self.range_max == None or value > self.range_max:
                            self.range_max = value
                        self.values.append((value, str(c)))

                    if len(self.values) >= 2:
                        extra_value = self.values[-1][0] + (
                            self.values[-1][0] - self.values[-2][0])
                        self.values.append((extra_value, " "))
                        if extra_value > self.range_max:
                            self.range_max = extra_value

            r_height, r_width = self.canvas.from_rowcol(1, 1)
            width, height = self.get_size()
            ox, oy = self.get_location()
            self.sx = width / max(1.0, (self.range_max - self.range_min))

            x = ox
            y = oy
            new_children.append(
                display_list.Rect(x,
                                  y,
                                  x + width,
                                  y + height,
                                  self.canvas.black,
                                  fill=True))
            points = [(x, y)]
            labels = []
            prev_scaled_x = None
            total_dx = 0
            prev_label = None
            for v, label in self.values:
                if label.endswith(".00"):
                    label = label[:-3]
                force = False
                if prev_label:
                    prev_parts = prev_label.split(' ')
                    cur_parts = label.split(' ')
                    new_label = ''
                    no_match = False
                    idx = 0
                    while idx < min(len(prev_parts), len(cur_parts)):
                        if no_match or prev_parts[idx] != cur_parts[idx]:
                            if idx == 0:
                                force = True
                            new_label += cur_parts[idx] + ' '
                            no_match = True
                        idx += 1
                    while idx < len(cur_parts):
                        new_label += cur_parts[idx] + ' '
                        idx += 1
                    prev_label = label
                    label = new_label
                else:
                    prev_label = label

                scaled_x = (v - self.range_min) * self.sx
                if prev_scaled_x != None:
                    total_dx += (scaled_x - prev_scaled_x)
                prev_scaled_x = scaled_x
                t_x, t_y = self.canvas.round_text_position(
                    ox + scaled_x, y + 1)
                if t_x >= x or force:
                    points.append((t_x, y))
                    points.append((t_x, t_y))
                    points.append((t_x, y))
                    labels.append((t_x, t_y, label))
                    l_height, l_width = self.canvas.from_rowcol(
                        1,
                        len(label) + 1)
                    x = t_x + l_width
            if points[-1][0] < ox + width:
                points.append((ox + width, y))
            self.dx = total_dx / len(self.values)
            new_children.append(
                display_list.PolyLine(points, self.canvas.green))
            for x, y, label in labels:
                new_children.append(
                    display_list.Text(x, y, label, self.canvas.green))
            self.set_children(new_children)
        return GraphElement.get_bbox(self)
Exemplo n.º 8
0
 def __init__(self, parent, text=None):
     GraphElement.__init__(self, parent)
     self.text = text
     self.add_child(display_list.Text(0, 0, self.text, self.canvas.white))
Exemplo n.º 9
0
        def main(stdscr):
            screen_size(40, 100)
            stdscr.clear()
            stdscr.refresh()

            python_path = os.path.dirname(os.path.dirname(request.fspath))
            c = canvas.Canvas(stdscr)
            max_x, max_y = c.get_maxxy()
            d = display_list.DisplayList(canvas=c)
            r = 1
            for ix in range(5):
                for iy in range(5):
                    x = ix * 11
                    y = iy * 11
                    d.add_child(
                        display_list.Rect(x, y, x + 10, y + 10,
                                          curses.color_pair(8 + r * 5), True))
                    r = r + 1
            d.render()
            dashboard_test_case(stdscr, "dl_rect", python_path)
            c.clear()
            r = 1
            for ix in range(5):
                for iy in range(5):
                    x = 65 + (ix * (11 * 1.5)) + 5
                    y = (iy * 11) + 5
                    d.add_child(
                        display_list.Circle(x, y, 5,
                                            curses.color_pair(8 + r * 5),
                                            True))
                    r = r + 1
            d.render()
            dashboard_test_case(stdscr, "dl_circle", python_path)
            c.clear()
            a = 0
            ia = [20, 15, 40, 110, 45, 25, 80, 25]
            r = 1
            for ac in ia:
                d.add_child(
                    display_list.Arc(100, 40, 40, a, a + ac,
                                     curses.color_pair(8 * r * 5), True))
                a = a + ac
                r = r + 1
            d.render()
            dashboard_test_case(stdscr, "dl_arc", python_path)
            c.clear()
            r = 0
            for ix in range(5):
                for iy in range(5):
                    d.add_child(
                        display_list.Text(ix * 10, (iy * 10) + (ix * 2),
                                          "Text %d,%d" % (ix, iy),
                                          curses.color_pair(8 * r * 5)))
                    r = r + 1
            d.render()
            dashboard_test_case(stdscr, "dl_text", python_path)
            c.clear()

            points = []
            for a in range(0, 360, 72):
                points.append(angle_point(0, 0, a, 20))
                points.append(angle_point(0, 0, a + 36, 10))
            points.append(points[0])

            r = 50
            d.add_child(
                display_list.PolyLine([(x + 100, y + 40) for x, y in points],
                                      curses.color_pair(8 + r * 8)))
            d.render()
            dashboard_test_case(stdscr, "dl_polyline", python_path)
            c.clear()
            r += 25
            d.add_child(
                display_list.Polygon([(x + 102, y + 42) for x, y in points],
                                     curses.color_pair(8 + r * 8), True))
            d.render()
            dashboard_test_case(stdscr, "dl_polygon", python_path)
            c.clear()