Beispiel #1
0
class FreeVizInteractiveViewBox(InteractiveViewBox):
    def __init__(self, graph, enable_menu=False):
        self.mousestate = 0
        self.point_i = None
        self.cursor = QCursor()
        super().__init__(graph, enable_menu)

    def _dragtip_pos(self):
        return 10, 10

    def mouseDragEvent(self, ev, axis=None):
        master = self.graph.master
        if master.data is None:
            super().mouseDragEvent(ev, axis)
            return
        pos = self.childGroup.mapFromParent(ev.pos())
        minradius = master.radius / 100 + 1e-5
        points = master.plotdata.anchors
        mask = np.zeros((len(points)), dtype=bool)
        for i, point in enumerate(points):
            if np.linalg.norm(point) > minradius:
                mask[i] = True
        np_pos = np.array([[pos.x(), pos.y()]])
        distances = distance.cdist(np_pos, points[:, :2])[0]
        is_near = False if not len(
            distances[mask]) else np.min(distances[mask]) < 0.1

        if ev.button() != Qt.LeftButton or (ev.start and not is_near):
            self.mousestate = 2  # finished
        if self.mousestate == 2:
            if ev.finish:
                self.mousestate = 0  # ready for new task
            super().mouseDragEvent(ev, axis)
            return
        ev.accept()
        if ev.start:
            self.cursor.setShape(Qt.ClosedHandCursor)
            self.mousestate = 1  # working
            self.point_i = np.flatnonzero(mask)[np.argmin(distances[mask])]
            master.randomize_indices()
        is_moving = True
        if self.mousestate == 1:
            if ev.finish:
                self.cursor.setShape(Qt.OpenHandCursor)
                self.mousestate = 0
                is_moving = False
            points[self.point_i][0] = pos.x()
            points[self.point_i][1] = pos.y()
            if is_moving:
                master.manual_move_anchor()
            else:
                master.setup_plot(reset_view=False)
            self.graph.show_indicator(point_i=self.point_i)
        self.setCursor(self.cursor)
Beispiel #2
0
class FreeVizInteractiveViewBox(InteractiveViewBox):
    def __init__(self, graph, enable_menu=False):
        self.mousestate = 0
        self.point_i = None
        self.cursor = QCursor()
        super().__init__(graph, enable_menu)

    def _dragtip_pos(self):
        return 10, 10

    def mouseDragEvent(self, ev, axis=None):
        master = self.graph.master
        if master.data is None:
            super().mouseDragEvent(ev, axis)
            return
        pos = self.childGroup.mapFromParent(ev.pos())
        minradius = master.radius / 100 + 1e-5
        points = master.plotdata.anchors
        mask = np.zeros((len(points)), dtype=bool)
        for i, point in enumerate(points):
            if np.linalg.norm(point) > minradius:
                mask[i] = True
        np_pos = np.array([[pos.x(), pos.y()]])
        distances = distance.cdist(np_pos, points[:, :2])[0]
        is_near = False if not len(distances[mask]) else np.min(distances[mask]) < 0.1

        if ev.button() != Qt.LeftButton or (ev.start and not is_near):
            self.mousestate = 2  # finished
        if self.mousestate == 2:
            if ev.finish:
                self.mousestate = 0  # ready for new task
            super().mouseDragEvent(ev, axis)
            return
        ev.accept()
        if ev.start:
            self.cursor.setShape(Qt.ClosedHandCursor)
            self.mousestate = 1  # working
            self.point_i = np.flatnonzero(mask)[np.argmin(distances[mask])]
            master.randomize_indices()
        is_moving = True
        if self.mousestate == 1:
            if ev.finish:
                self.cursor.setShape(Qt.OpenHandCursor)
                self.mousestate = 0
                is_moving = False
            points[self.point_i][0] = pos.x()
            points[self.point_i][1] = pos.y()
            if is_moving:
                master.manual_move_anchor()
            else:
                master.setup_plot(reset_view=False)
            self.graph.show_indicator(point_i=self.point_i)
        self.setCursor(self.cursor)
Beispiel #3
0
class RadvizInteractiveViewBox(InteractiveViewBox):
    def __init__(self, graph, enable_menu=False):
        self.mouse_state = 0
        self.point_i = None
        self.cursor = QCursor()
        super().__init__(graph, enable_menu)

    def _dragtip_pos(self):
        return 10, 10

    def mouseDragEvent(self, ev, axis=None):
        master = self.graph.master
        if master.data is None or master.graph.data is None:
            super().mouseDragEvent(ev, axis)
            return

        pos = self.childGroup.mapFromParent(ev.pos())
        points = master.plotdata.points
        np_pos = np.array([[pos.x(), pos.y()]])
        distances = distance.cdist(np_pos, points[:, :2])
        is_near = np.min(distances) < 0.1

        if ev.button() != Qt.LeftButton or (ev.start and not is_near):
            self.mouse_state = 2
        if self.mouse_state == 2:
            if ev.finish:
                self.mouse_state = 0
            super().mouseDragEvent(ev, axis)
            return

        ev.accept()
        if ev.start:
            self.cursor.setShape(Qt.ClosedHandCursor)
            self.setCursor(self.cursor)
            self.mouse_state = 1
            self.point_i = np.argmin(distances)
            master.randomize_indices()
        if self.mouse_state == 1:
            if ev.finish:
                self.cursor.setShape(Qt.ArrowCursor)
                self.setCursor(self.cursor)
                self.mouse_state = 0
            angle = np.arctan2(pos.y(), pos.x())
            QToolTip.showText(
                QPoint(ev.screenPos().x(), ev.screenPos().y()), "{:.2f}".format(np.rad2deg(angle)))
            points[self.point_i][0] = np.cos(angle)
            points[self.point_i][1] = np.sin(angle)
            if ev.finish:
                master.setup_plot()
                master.commit()
            else:
                master.manual_move()
            self.graph.show_arc_arrow(pos.x(), pos.y())