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

« back to all changes in this revision

Viewing changes to enthought/chaco/colormapped_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 ColormappedScatterPlot and ColormappedScatterPlotView classes.
2
2
"""
3
3
 
 
4
from __future__ import with_statement
 
5
 
4
6
# Major library imports
5
7
from numpy import argsort, array, concatenate, nonzero, invert, take, \
6
8
                  isnan, transpose, newaxis, zeros
7
9
 
8
10
# Enthought library imports
9
 
from enthought.kiva import STROKE
 
11
from enthought.kiva.constants import STROKE
10
12
from enthought.traits.api import Dict, Enum, Float, Instance
11
13
from enthought.traits.ui.api import Item, RangeEditor
12
14
 
182
184
        else:
183
185
            method = self.render_method
184
186
 
185
 
        gc.save_state()
186
 
        try:
 
187
        with gc:
187
188
            if method == 'bruteforce' or (not batch_capable):
188
189
                self._render_bruteforce(gc, points)
189
190
            elif method == 'banded':
190
191
                self._render_banded(gc, points)
191
 
        finally:
192
 
            gc.restore_state()
193
192
        return
194
193
 
195
194
 
341
340
        alphas = (zeros(len(colors))+self.fill_alpha)[:, newaxis]
342
341
        colors = concatenate((colors[:, :3], alphas), axis=1)
343
342
 
344
 
        gc.save_state()
345
 
        try:
 
343
        with gc:
346
344
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
347
345
            gc.set_stroke_color(self.outline_color_)
348
346
            gc.set_line_width(self.line_width)
349
347
 
350
 
            marker = self.marker_
 
348
            marker_cls = self.marker_
351
349
            size = self.marker_size
352
 
            mode = marker.draw_mode
 
350
            mode = marker_cls.draw_mode
353
351
 
354
 
            if marker != "custom":
 
352
            if marker_cls != "custom":
355
353
                if (hasattr(gc, "draw_marker_at_points") and self.marker not in ('custom', 'circle', 'diamond')):
356
 
                    draw_func = lambda x, y: gc.draw_marker_at_points([[x,y]], size, marker.kiva_marker)
 
354
                    draw_func = lambda x, y: gc.draw_marker_at_points([[x,y]], size, marker_cls.kiva_marker)
357
355
 
358
356
                elif hasattr(gc, "draw_path_at_points"):
359
357
                    path = gc.get_empty_path()
360
358
                    # turn the class into an instance... we should make add_to_path a
361
359
                    # class method at some point.
362
 
                    marker().add_to_path(path, size)
 
360
                    marker_cls().add_to_path(path, size)
363
361
                    draw_func = lambda x, y: gc.draw_path_at_points([[x,y]], path, mode)
 
362
                else:
 
363
                    m = marker_cls()
 
364
                    def draw_func(x, y):
 
365
                        gc.translate_ctm(x, y)
 
366
                        gc.begin_path()
 
367
                        m.add_to_path(gc, size)
 
368
                        gc.draw_path(mode)
 
369
                        gc.translate_ctm(-x, -y)
364
370
 
365
371
                for i in range(len(x)):
366
372
                    gc.set_fill_color(colors[i])
367
373
                    draw_func(x[i], y[i])
368
374
 
369
375
            else:
370
 
                path = marker.custom_symbol
 
376
                path = marker_cls.custom_symbol
371
377
                for i in range(len(x)):
372
378
                    gc.set_fill_color(colors[i])
373
379
                    gc.draw_path_at_points([[x[i], y[i]]], path, STROKE)
374
380
 
375
 
        finally:
376
 
            gc.restore_state()
377
381
 
378
382
    #------------------------------------------------------------------------
379
383
    # Event handlers