1
from __future__ import with_statement
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
1
""" The base ScatterPlot class now accepts variable sized markers.
3
This definition remains for backwards compatibility.
5
from chaco.scatterplot import ScatterPlot
8
# TODO: This should be officially deprecated.
8
9
class VariableSizeScatterPlot(ScatterPlot):
11
def _render(self, gc, points, icon_mode=False):
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.
20
gc.clip_to_rect(self.x, self.y, self.width, self.height)
22
render_variable_size_markers(gc, points, self.marker, self.marker_size,
23
self.color_, self.line_width, self.outline_color_,
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_,
34
# Draw the default axes, if necessary
35
self._draw_default_axes(gc)
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
49
The target for rendering the points
50
points : array of (x,y) points
52
marker : string, class, or instance
53
The type of marker to use for the points
55
The size of the markers
57
The color of the markers
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
69
# marker can be string, class, or instance
70
if isinstance(marker, basestring):
71
marker = MarkerNameDict[marker]()
72
elif issubclass(marker, AbstractMarker):
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
82
gc.set_stroke_color(color)
83
gc.set_line_width(line_width)
85
gc.set_stroke_color(outline_color)
86
gc.set_line_width(line_width)
87
gc.set_fill_color(color)
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):
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)
103
for pt,size in zip(points, marker_size):
106
gc.translate_ctm(sx, sy)
107
gc.scale_ctm(size, size)