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

« back to all changes in this revision

Viewing changes to enthought/chaco/scatterplot.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-06 19:03:54 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110406190354-rwd55l2ezjecfo41
Tags: 3.4.0-2
d/rules: fix pyshared directory path (Closes: #621116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
""" Defines the ScatterPlot class, and associated Traits UI view and helper
2
2
function.
3
3
"""
 
4
from __future__ import with_statement
4
5
 
5
6
# Major library imports
6
7
from numpy import abs, argmin, around, array, asarray, compress, invert, isnan, \
9
10
# Enthought library imports
10
11
from enthought.enable.api import black_color_trait, ColorTrait, AbstractMarker, \
11
12
        CustomMarker, MarkerNameDict, MarkerTrait
12
 
from enthought.kiva import STROKE
 
13
from enthought.kiva.constants import STROKE
13
14
from enthought.traits.api import Any, Array, Bool, Float, Int, Trait, Callable
14
15
from enthought.traits.ui.api import View, VGroup, Item
15
16
 
75
76
    elif issubclass(marker, AbstractMarker):
76
77
        marker = marker()
77
78
 
78
 
    gc.save_state()
79
 
 
80
 
    gc.set_line_dash(None)
81
 
    if marker.draw_mode == STROKE:
82
 
        # markers with the STROKE draw mode will not be visible
83
 
        # if the line width is zero, so set it to 1
84
 
        if line_width == 0:
85
 
            line_width = 1.0
86
 
        gc.set_stroke_color(color)
87
 
        gc.set_line_width(line_width)
88
 
    else:
89
 
        gc.set_stroke_color(outline_color)
90
 
        gc.set_line_width(line_width)
91
 
        gc.set_fill_color(color)
92
 
 
93
 
    gc.begin_path()
94
 
 
95
 
    # This is the fastest method - use one of the kiva built-in markers
96
 
    if (not debug) and hasattr(gc, "draw_marker_at_points") \
97
 
        and (marker.__class__ != CustomMarker) \
98
 
        and (gc.draw_marker_at_points(points,
99
 
                                      marker_size,
100
 
                                      marker.kiva_marker) != 0):
101
 
            pass
102
 
 
103
 
    # The second fastest method - draw the path into a compiled path, then
104
 
    # draw the compiled path at each point
105
 
    elif hasattr(gc, 'draw_path_at_points'):
106
 
        #if debug:
107
 
        #    import pdb; pdb.set_trace()
108
 
        if marker.__class__ != CustomMarker:
109
 
            path = gc.get_empty_path()
110
 
            marker.add_to_path(path, marker_size)
111
 
            mode = marker.draw_mode
112
 
        else:
113
 
            path = custom_symbol
114
 
            mode = STROKE
115
 
        if not marker.antialias:
116
 
            gc.set_antialias(False)
117
 
        gc.draw_path_at_points(points, path, mode)
118
 
 
119
 
    # Neither of the fast functions worked, so use the brute-force, manual way
120
 
    else:
121
 
        if not marker.antialias:
122
 
            gc.set_antialias(False)
123
 
        if marker.__class__ != CustomMarker:
124
 
            for sx,sy in points:
125
 
                gc.save_state()
126
 
                gc.translate_ctm(sx, sy)
127
 
                # Kiva GCs have a path-drawing interface
128
 
                marker.add_to_path(gc, marker_size)
129
 
                gc.draw_path(marker.draw_mode)
130
 
                gc.restore_state()
131
 
        else:
132
 
            path = custom_symbol
133
 
            for sx,sy in points:
134
 
                gc.save_state()
135
 
                gc.translate_ctm(sx, sy)
136
 
                gc.add_path(path)
137
 
                gc.draw_path(STROKE)
138
 
                gc.restore_state()
139
 
 
140
 
 
141
 
    gc.restore_state()
 
79
    with gc:
 
80
        gc.set_line_dash(None)
 
81
        if marker.draw_mode == STROKE:
 
82
            # markers with the STROKE draw mode will not be visible
 
83
            # if the line width is zero, so set it to 1
 
84
            if line_width == 0:
 
85
                line_width = 1.0
 
86
            gc.set_stroke_color(color)
 
87
            gc.set_line_width(line_width)
 
88
        else:
 
89
            gc.set_stroke_color(outline_color)
 
90
            gc.set_line_width(line_width)
 
91
            gc.set_fill_color(color)
 
92
 
 
93
        gc.begin_path()
 
94
 
 
95
        # This is the fastest method - use one of the kiva built-in markers
 
96
        if (not debug) and hasattr(gc, "draw_marker_at_points") \
 
97
            and (marker.__class__ != CustomMarker) \
 
98
            and (gc.draw_marker_at_points(points,
 
99
                                          marker_size,
 
100
                                          marker.kiva_marker) != 0):
 
101
                pass
 
102
 
 
103
        # The second fastest method - draw the path into a compiled path, then
 
104
        # draw the compiled path at each point
 
105
        elif hasattr(gc, 'draw_path_at_points'):
 
106
            #if debug:
 
107
            #    import pdb; pdb.set_trace()
 
108
            if marker.__class__ != CustomMarker:
 
109
                path = gc.get_empty_path()
 
110
                marker.add_to_path(path, marker_size)
 
111
                mode = marker.draw_mode
 
112
            else:
 
113
                path = custom_symbol
 
114
                mode = STROKE
 
115
            if not marker.antialias:
 
116
                gc.set_antialias(False)
 
117
            gc.draw_path_at_points(points, path, mode)
 
118
 
 
119
        # Neither of the fast functions worked, so use the brute-force, manual way
 
120
        else:
 
121
            if not marker.antialias:
 
122
                gc.set_antialias(False)
 
123
            if marker.__class__ != CustomMarker:
 
124
                with gc:
 
125
                    for sx,sy in points:
 
126
                        gc.translate_ctm(sx, sy)
 
127
                        gc.begin_path()
 
128
                        # Kiva GCs have a path-drawing interface
 
129
                        marker.add_to_path(gc, marker_size)
 
130
                        gc.draw_path(marker.draw_mode)
 
131
                        gc.translate_ctm(-sx, -sy)
 
132
            else:
 
133
                path = custom_symbol
 
134
                with gc:
 
135
                    for sx,sy in points:
 
136
                        gc.translate_ctm(sx, sy)
 
137
                        gc.begin_path()
 
138
                        gc.add_path(path)
 
139
                        gc.draw_path(STROKE)
 
140
                        gc.translate_ctm(-sx, -sy)
 
141
 
142
142
    return
143
143
 
144
144
#------------------------------------------------------------------------------
192
192
    # datasource.
193
193
    #------------------------------------------------------------------------
194
194
 
 
195
    show_selection = Bool(True)
 
196
 
195
197
    selection_marker = MarkerTrait
196
198
 
197
199
    selection_marker_size = Float(4.0)
458
460
                       self.color_, self.line_width, self.outline_color_,
459
461
                       self.custom_symbol)
460
462
 
461
 
        if self._cached_selected_pts is not None and len(self._cached_selected_pts) > 0:
 
463
        if self.show_selection and self._cached_selected_pts is not None and len(self._cached_selected_pts) > 0:
462
464
            sel_pts = self.map_screen(self._cached_selected_pts)
463
465
            self.render_markers_func(gc, sel_pts, self.selection_marker,
464
466
                    self.selection_marker_size, self.selection_color_,