source: sasview/src/sas/plottools/arrow3d.py @ 2df0b74

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2df0b74 was 2df0b74, checked in by Mathieu Doucet <doucetm@…>, 9 years ago

pylint fixes

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[a9d5684]1"""
2Module that draws multiple arrows in 3D coordinates
3"""
4
5from matplotlib.patches import FancyArrowPatch
6from mpl_toolkits.mplot3d import proj3d
7import time
[2df0b74]8# from matplotlib.artist import allow_rasterization
[a9d5684]9class Arrow3D(FancyArrowPatch):
10    """
11    Draw 3D arrow
12    """
[2df0b74]13
[a9d5684]14    def __init__(self, base, xs, ys, zs, colors, *args, **kwargs):
15        """
16        Init
[2df0b74]17
[a9d5684]18        :Params xs: [[x0, x0+dx0], [x1, x1+dx1], ...]
19        :Params ys: [[y0, y0+dy0], [y1, y1+dy1], ...]
20        :Params zs: [[z0, z0+dz0], [z1, z1+dz1], ...]
[2df0b74]21        :Params colors: [[R0, G0, B0], [R1, G1, B1], ...]
[a9d5684]22        where R, G, B ranges (0,1)
23        """
[2df0b74]24        FancyArrowPatch.__init__(self, (0, 0), (0, 0), *args, **kwargs)
[a9d5684]25        self.leftdown = False
26        self.t_click = 0
27        self._verts3d = xs, ys, zs
28        self.colors = colors
29        self.base = base
[2df0b74]30
[a9d5684]31        if base != None:
32            # To turn the updating off during dragging
[2df0b74]33            base.canvas.mpl_connect('button_press_event', self.on_left_down)
34            base.canvas.mpl_connect('button_release_event', self.on_left_up)
35
36    def on_left_down(self, event):
[a9d5684]37        """
[2df0b74]38            Mouse left-down event
[a9d5684]39        """
40        self.leftdown = True
41        self.t_click = time.time()
[2df0b74]42
43    def on_left_up(self, event):
[a9d5684]44        """
[2df0b74]45            Mouse left up event
[a9d5684]46        """
47        t_up = time.time() - self.t_click
48        # Avoid just clicking
49        if t_up > 0.1:
50            self.leftdown = False
51            self.base.canvas.draw()
[2df0b74]52
[a9d5684]53    def draw(self, renderer, rasterized=True):
54        """
55        Drawing actually happens here
56        """
57        # Draws only when the dragging finished
58        if self.leftdown:
59            return
60        xs3d, ys3d, zs3d = self._verts3d
61        for i in xrange(len(xs3d)):
[2df0b74]62            xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], renderer.M)
63            self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
[a9d5684]64            self.set_color(self.colors[i])
65            FancyArrowPatch.draw(self, renderer)
[2df0b74]66
[a9d5684]67        self.leftdown = False
Note: See TracBrowser for help on using the repository browser.