From 43235471cb764314807406876811cef98553be49 Mon Sep 17 00:00:00 2001 From: "JARACO\\jaraco" Date: Mon, 9 Jan 2006 20:41:39 +0000 Subject: [PATCH] Added the ability to add a constant line to a plot. --- Plot.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Plot.py b/Plot.py index a8fb62f..6832c97 100644 --- a/Plot.py +++ b/Plot.py @@ -228,6 +228,7 @@ class Plot( SVG.Graph ): def draw_data( self ): self.load_transform_parameters() + self._draw_constant_lines( ) for line, data in izip( count(1), self.data ): x_start, y_start = self.transform_output_coordinates( ( data['data'][self.x_data_index][0], @@ -249,6 +250,31 @@ class Plot( SVG.Graph ): self.draw_data_points( line, data_points, graph_points ) del self.__transform_parameters + def add_constant_line( self, value, label = None, style = None ): + self.constant_lines = getattr( self, 'constant_lines', [] ) + self.constant_lines.append( ( value, label, style ) ) + + def _draw_constant_lines( self ): + if hasattr( self, 'constant_lines' ): + map( self.__draw_constant_line, self.constant_lines ) + + def __draw_constant_line( self, ( value, label, style ) ): + "Draw a constant line on the y-axis with the label" + start = self.transform_output_coordinates( ( 0, value ) )[1] + stop = self.graph_width + path = self._create_element( 'path', { + 'd': 'M 0 %(start)s h%(stop)s' % vars(), + 'class': 'constantLine' } ) + if style: + path['style'] = style + self.graph.appendChild( path ) + text = self._create_element( 'text', { + 'x': str( 2 ), + 'y': str( start - 2 ), + 'class': 'constantLine' } ) + text.appendChild( self._doc.createTextNode( label ) ) + self.graph.appendChild( text ) + def load_transform_parameters( self ): "Cache the parameters necessary to transform x & y coordinates" x_min, x_max, x_div = self.x_range() @@ -479,4 +505,11 @@ class Plot( SVG.Graph ): fill: #9966FF; stroke: none; stroke-width: 1px; -}""" \ No newline at end of file +} +.constantLine{ + color: navy; + stroke: navy; + stroke-width: 1px; + stroke-dasharray: 9 1 1; +} +""" \ No newline at end of file