Ejemplo n.º 1
0
    def _adjust_scale(attributes, points, max_width, diff, attr_inds,
                      log_reg_cont_data_extremes, cls_index):
        if not diff:
            return max_width

        def offset(name, point):
            text_ = QGraphicsTextItem(name).boundingRect()
            return scale * point + text_.width() / 2

        lr = log_reg_cont_data_extremes
        scale = max_width / diff
        names = list(chain.from_iterable(
            [_get_labels(a, lr and lr[i] and lr[i][0] and lr[i][cls_index],
                         OWNomogram.get_ruler_values(p.min(), p.max(),
                                                     scale * p.ptp(), False))
             for i, a, p in zip(attr_inds, attributes, points)]))
        points = list(chain.from_iterable(points))

        old_scale = scale + 1
        while old_scale > scale:
            old_scale = scale
            offsets = [offset(n, p) for n, p in zip(names, points)]
            most_right_name = names[np.argmax(offsets)]
            text = QGraphicsTextItem(most_right_name).boundingRect()
            scale = (max_width - text.width() / 2) / diff
        return scale
Ejemplo n.º 2
0
 def offset(name, point):
     text_ = QGraphicsTextItem(name).boundingRect()
     return scale * point + text_.width() / 2