~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to chaco/variable_size_scatterplot.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import with_statement
2
 
 
3
 
from chaco.api import ScatterPlot, render_markers
4
 
from enable.api import MarkerNameDict, CustomMarker, AbstractMarker
5
 
from kiva.constants import STROKE
6
 
from traits.api import Array
7
 
 
 
1
""" The base ScatterPlot class now accepts variable sized markers.
 
2
 
 
3
This definition remains for backwards compatibility.
 
4
"""
 
5
from chaco.scatterplot import ScatterPlot
 
6
 
 
7
 
 
8
# TODO: This should be officially deprecated.
8
9
class VariableSizeScatterPlot(ScatterPlot):
9
 
    marker_size = Array
10
 
 
11
 
    def _render(self, gc, points, icon_mode=False):
12
 
        """
13
 
        This same method is used both to render the scatterplot and to
14
 
        draw just the iconified version of this plot, with the latter
15
 
        simply requiring that a few steps be skipped.
16
 
        """
17
 
 
18
 
        if not icon_mode:
19
 
            gc.save_state()
20
 
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
21
 
 
22
 
        render_variable_size_markers(gc, points, self.marker, self.marker_size,
23
 
                       self.color_, self.line_width, self.outline_color_,
24
 
                       self.custom_symbol)
25
 
 
26
 
        if self._cached_selected_pts is not None and len(self._cached_selected_pts) > 0:
27
 
            sel_pts = self.map_screen(self._cached_selected_pts)
28
 
            render_markers(gc, sel_pts, self.selection_marker,
29
 
                    self.selection_marker_size, self.selection_color_,
30
 
                    self.selection_line_width, self.selection_outline_color_,
31
 
                    self.custom_symbol)
32
 
 
33
 
        if not icon_mode:
34
 
            # Draw the default axes, if necessary
35
 
            self._draw_default_axes(gc)
36
 
            gc.restore_state()
37
 
 
38
 
def render_variable_size_markers(gc, points, marker, marker_size,
39
 
                   color, line_width, outline_color,
40
 
                   custom_symbol=None, debug=False):
41
 
    """ Helper function for a PlotComponent instance to render a
42
 
    set of (x,y) points onto a graphics context.  Currently, it makes some
43
 
    assumptions about the attributes on the plot object; these may be factored
44
 
    out eventually.
45
 
 
46
 
    Parameters
47
 
    ----------
48
 
    gc : GraphicsContext
49
 
        The target for rendering the points
50
 
    points : array of (x,y) points
51
 
        The points to render
52
 
    marker : string, class, or instance
53
 
        The type of marker to use for the points
54
 
    marker_size : number
55
 
        The size of the markers
56
 
    color : RGB(A) color
57
 
        The color of the markers
58
 
    line_width : number
59
 
        The width, in pixels, of the marker outline
60
 
    outline_color : RGB(A) color
61
 
        The color of the marker outline
62
 
    custom_symbol : CompiledPath
63
 
        If the marker style is 'custom', this is the symbol
64
 
    """
65
 
 
66
 
    if len(points) == 0:
67
 
        return
68
 
 
69
 
    # marker can be string, class, or instance
70
 
    if isinstance(marker, basestring):
71
 
        marker = MarkerNameDict[marker]()
72
 
    elif issubclass(marker, AbstractMarker):
73
 
        marker = marker()
74
 
 
75
 
    with gc:
76
 
        gc.set_line_dash(None)
77
 
        if marker.draw_mode == STROKE:
78
 
            # markers with the STROKE draw mode will not be visible
79
 
            # if the line width is zero, so set it to 1
80
 
            if line_width == 0:
81
 
                line_width = 1.0
82
 
            gc.set_stroke_color(color)
83
 
            gc.set_line_width(line_width)
84
 
        else:
85
 
            gc.set_stroke_color(outline_color)
86
 
            gc.set_line_width(line_width)
87
 
            gc.set_fill_color(color)
88
 
 
89
 
        gc.begin_path()
90
 
 
91
 
        if not marker.antialias:
92
 
            gc.set_antialias(False)
93
 
        if not isinstance(marker, CustomMarker):
94
 
            for pt,size in zip(points, marker_size):
95
 
                sx, sy = pt
96
 
                with gc:
97
 
                    gc.translate_ctm(sx, sy)
98
 
                    # Kiva GCs have a path-drawing interface
99
 
                    marker.add_to_path(gc, size)
100
 
                    gc.draw_path(marker.draw_mode)
101
 
        else:
102
 
            path = custom_symbol
103
 
            for pt,size in zip(points, marker_size):
104
 
                sx, sy = pt
105
 
                with gc:
106
 
                    gc.translate_ctm(sx, sy)
107
 
                    gc.scale_ctm(size, size)
108
 
                    gc.add_path(path)
109
 
                    gc.draw_path(STROKE)
110
 
 
111
 
    return
 
10
    pass