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

« back to all changes in this revision

Viewing changes to enthought/chaco/multi_line_plot.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 MultiLinePlot class.
2
2
"""
3
3
 
 
4
from __future__ import with_statement
 
5
 
4
6
# Standard library imports
5
7
import warnings
6
8
from math import ceil, floor
40
42
        These are the 'y' coordinates.
41
43
    
42
44
    value : instance of a MultiArrayDataSource
43
 
        Note that the `scale`, `offset` and `amplitude` attributes of the
 
45
        Note that the `scale`, `offset` and `normalized_amplitude` attributes of the
44
46
        MultiArrayDataSource control the projection of the traces into the (x,y)
45
 
        plot.  In simplest case, `scale=1` and `offset=0`, and `amplitude` controls
46
 
        the scaling of the traces relative to their base y value.
47
 
 
48
 
    amplitude : Float
 
47
        plot.  In simplest case, `scale=1` and `offset=0`, and `normalized_amplitude`
 
48
        controls the scaling of the traces relative to their base y value.
 
49
 
 
50
    global_min, global_max : float
 
51
        The minimum and maximum values of the data in `value`.  For large
 
52
        arrays, computing these could take excessive time, so they must be
 
53
        provided when an instance is created.
 
54
 
 
55
    normalized_amplitude : Float
49
56
 
50
57
    color : ColorTrait
51
58
 
137
144
    #------------------------------------------------------------------------
138
145
 
139
146
    # The projected 2D numpy array.
140
 
    _trace_data = Property(Array, depends_on=['index', 'value', 'yindex',
141
 
                                                'amplitude', 'scale', 'offset'])
 
147
    _trace_data = Property(Array, depends_on=['index', 'index.data_changed',
 
148
        'value', 'value.data_changed', 'yindex', 'yindex.data_changed',
 
149
        'amplitude', 'scale', 'offset'])
142
150
 
143
151
    # Cached list of non-NaN arrays of (x,y) data-space points; regardless of
144
152
    # self.orientation, this is always stored as (index_pt, value_pt).  This is
193
201
    def _get_amplitude_scale(self):
194
202
        """
195
203
        If the amplitude is set to this value, the largest trace deviation from
196
 
        is base y coordinates will be equal to the y coordinate spacing.
 
204
        its base y coordinate will be equal to the y coordinate spacing.
197
205
        """
198
206
        # Note: Like the rest of the current code, this ignores the `scale` attribute.
199
207
 
380
388
        if len(line_points) == 0:
381
389
            return
382
390
 
383
 
        gc.save_state()
384
 
        gc.set_antialias(True)
385
 
        gc.clip_to_rect(self.x, self.y, self.width, self.height)
386
 
 
387
 
        render = self._render_normal
388
 
 
389
 
        if selected_points is not None:
390
 
            gc.set_stroke_color(self.selected_color_)
391
 
            gc.set_line_width(self.line_width+10.0)
392
 
            gc.set_line_dash(self.selected_line_style_)
393
 
            render(gc, selected_points)
394
 
 
395
 
        if self.color_func is not None:
396
 
            # Existence of self.color_func overrides self.color.
397
 
            color_func = self.color_func
398
 
        else:
399
 
            color_func = lambda k: self.color_
400
 
 
401
 
        tmp = list(enumerate(line_points))
402
 
        # Note: the list is reversed for testing with _render_filled.
403
 
        for k, points in reversed(tmp):
404
 
            color = color_func(k)
405
 
            gc.set_stroke_color(color)
406
 
            gc.set_line_width(self.line_width)
407
 
            gc.set_line_dash(self.line_style_)
408
 
            render(gc, points)
409
 
 
410
 
        # Draw the default axes, if necessary
411
 
        self._draw_default_axes(gc)
412
 
 
413
 
        gc.restore_state()
 
391
        with gc:
 
392
            gc.set_antialias(True)
 
393
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
 
394
 
 
395
            render = self._render_normal
 
396
 
 
397
            if selected_points is not None:
 
398
                gc.set_stroke_color(self.selected_color_)
 
399
                gc.set_line_width(self.line_width+10.0)
 
400
                gc.set_line_dash(self.selected_line_style_)
 
401
                render(gc, selected_points)
 
402
 
 
403
            if self.color_func is not None:
 
404
                # Existence of self.color_func overrides self.color.
 
405
                color_func = self.color_func
 
406
            else:
 
407
                color_func = lambda k: self.color_
 
408
 
 
409
            tmp = list(enumerate(line_points))
 
410
            # Note: the list is reversed for testing with _render_filled.
 
411
            for k, points in reversed(tmp):
 
412
                color = color_func(k)
 
413
                gc.set_stroke_color(color)
 
414
                gc.set_line_width(self.line_width)
 
415
                gc.set_line_dash(self.line_style_)
 
416
                render(gc, points)
 
417
 
 
418
            # Draw the default axes, if necessary
 
419
            self._draw_default_axes(gc)
414
420
 
415
421
    def _render_normal(self, gc, points):
416
422
        for ary in points:
422
428
 
423
429
 
424
430
    def _render_icon(self, gc, x, y, width, height):
425
 
        gc.save_state()
426
 
        gc.set_stroke_color(self.color_)
427
 
        gc.set_line_width(self.line_width)
428
 
        gc.set_line_dash(self.line_style_)
429
 
        gc.set_antialias(0)
430
 
        gc.move_to(x, y+height/2)
431
 
        gc.line_to(x+width, y+height/2)
432
 
        gc.stroke_path()
433
 
        gc.restore_state()
434
 
        return
435
 
 
 
431
        with gc:
 
432
            gc.set_stroke_color(self.color_)
 
433
            gc.set_line_width(self.line_width)
 
434
            gc.set_line_dash(self.line_style_)
 
435
            gc.set_antialias(0)
 
436
            gc.move_to(x, y+height/2)
 
437
            gc.line_to(x+width, y+height/2)
 
438
            gc.stroke_path()
436
439
 
437
440
 
438
441
    def _alpha_changed(self):