20
23
# Direction to fill. Down is towards the origin, up is towards the max
21
24
fill_direction = Enum("down", "up")
26
# The rendering style of the line plot.
29
# "normal" style (default); each point is connected to subsequent and
30
# prior points by line segments
32
# each point is represented by a line segment parallel to the abscissa
33
# (index axis) and spanning the length between the point and its
36
# like "hold" style, but line segments are drawn at each point of the
37
# plot to connect the hold lines of the prior point and the current
38
# point. Also called a "right angle plot".
39
render_style = Enum("connectedpoints", "hold", "connectedhold")
23
41
def _render(self, gc, points):
24
42
if len(points) == 0:
45
render_method_dict = {
46
"hold": LinePlot._render_hold,
47
"connectedhold": LinePlot._render_connected_hold,
48
"connectedpoints": LinePlot._render_normal
50
render_lines = render_method_dict.get(self.render_style, LinePlot._render_normal)
27
52
if self.fill_direction == 'down':
28
53
ox, oy = self.map_screen([[0,0]])[0]
30
55
ox, oy = self.map_screen([[self.x_mapper.range.high,
31
56
self.y_mapper.range.high]])[0]
35
59
gc.clip_to_rect(self.x, self.y, self.width, self.height)
37
61
# If the fill color is not transparent, then draw the fill polygon first
38
62
face_col = self.face_color_
39
63
if not (len(face_col) == 4 and face_col[-1] == 0):
40
gc.set_fill_color(face_col)
42
startx, starty = points[0]
43
if self.orientation == "h":
44
gc.move_to(startx, oy)
45
gc.line_to(startx, starty)
47
gc.move_to(ox, starty)
48
gc.line_to(startx, starty)
52
endx, endy = points[-1]
53
if self.orientation == "h":
55
gc.line_to(startx, oy)
58
gc.line_to(ox, starty)
64
if self.render_style in ("hold","connectedhold"):
65
# Modify the points array before passing it in to render_polys:
66
# Between every two points, create an intermediate point with
67
# the first point's Y and the second point's X. (For vertical
68
# plots, use the first point's X and the second point's Y.)
69
new_points = empty((points.shape[0]*2-1, 2))
70
new_points[::2] = points
71
if self.orientation == "h":
72
new_points[1::2,0] = points[1:,0]
73
new_points[1::2,1] = points[:-1,1]
75
new_points[1::2,0] = points[:-1,0]
76
new_points[1::2,1] = points[1:,1]
79
self._render_polys(gc, points, ox, oy)
63
81
# If the line color is not transparent, or tha same color
64
82
# as the filled area:
67
85
gc.set_stroke_color(edge_col)
68
86
gc.set_line_width(self.edge_width)
69
87
gc.set_line_dash(self.edge_style_)
71
gc.move_to(*points[0])
88
# Create a list around points because the LinePlot supports
89
# Nans, and its rendering methods expect lists of disjoint arrays.
90
render_lines(gc, [points], self.orientation)
93
def _render_polys(self, gc, points, ox, oy):
94
face_col = self.face_color_
95
gc.set_fill_color(face_col)
97
startx, starty = points[0]
98
if self.orientation == "h":
99
gc.move_to(startx, oy)
100
gc.line_to(startx, starty)
102
gc.move_to(ox, starty)
103
gc.line_to(startx, starty)
107
endx, endy = points[-1]
108
if self.orientation == "h":
110
gc.line_to(startx, oy)
113
gc.line_to(ox, starty)