Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.Graphics.Distribution.BarChartDistribution Class Reference

List of all members.

Public Member Functions

def __init__
def draw

Public Attributes

 display_info
 x_axis_title
 y_axis_title
 chart_title
 chart_title_size
 padding_percent

Private Member Functions

def _draw_title
def _determine_position

Detailed Description

Display the distribution of values as a bunch of bars.

Definition at line 134 of file Distribution.py.


Constructor & Destructor Documentation

def Bio.Graphics.Distribution.BarChartDistribution.__init__ (   self,
  display_info = [] 
)
Initialize a Bar Chart display of distribution info.

Class attributes:

o display_info - the information to be displayed in the distribution.
This should be ordered as a list of lists, where each internal list
is a data set to display in the bar chart.

Definition at line 137 of file Distribution.py.

00137 
00138     def __init__(self, display_info = []):
00139         """Initialize a Bar Chart display of distribution info.
00140 
00141         Class attributes:
00142 
00143         o display_info - the information to be displayed in the distribution.
00144         This should be ordered as a list of lists, where each internal list
00145         is a data set to display in the bar chart.
00146         """
00147         self.display_info = display_info
00148 
00149         self.x_axis_title = ""
00150         self.y_axis_title = ""
00151         self.chart_title = ""
00152         self.chart_title_size = 10
00153 
00154         self.padding_percent = 0.15

Here is the caller graph for this function:


Member Function Documentation

def Bio.Graphics.Distribution.BarChartDistribution._determine_position (   self,
  start_x,
  start_y,
  end_x,
  end_y 
) [private]
Calculate the position of the chart with blank space.

This uses some padding around the chart, and takes into account
whether the chart has a title. It returns 4 values, which are,
in order, the x_start, x_end, y_start and y_end of the chart
itself.

Definition at line 211 of file Distribution.py.

00211 
00212     def _determine_position(self, start_x, start_y, end_x, end_y):
00213         """Calculate the position of the chart with blank space.
00214 
00215         This uses some padding around the chart, and takes into account
00216         whether the chart has a title. It returns 4 values, which are,
00217         in order, the x_start, x_end, y_start and y_end of the chart
00218         itself.
00219         """
00220         x_padding = self.padding_percent * (end_x - start_x)
00221         y_padding = self.padding_percent * (start_y - end_y)
00222 
00223         new_x_start = start_x + x_padding
00224         new_x_end = end_x - x_padding
00225 
00226         if self.chart_title:
00227             new_y_start = start_y - y_padding - self.chart_title_size
00228         else:
00229             new_y_start = start_y - y_padding
00230 
00231         new_y_end = end_y + y_padding
00232         
00233         return new_x_start, new_x_end, new_y_start, new_y_end

Here is the caller graph for this function:

def Bio.Graphics.Distribution.BarChartDistribution._draw_title (   self,
  cur_drawing,
  title,
  start_x,
  start_y,
  end_x,
  end_y 
) [private]
Add the title of the figure to the drawing.

Definition at line 199 of file Distribution.py.

00199 
00200     def _draw_title(self, cur_drawing, title, start_x, start_y, end_x, end_y):
00201         """Add the title of the figure to the drawing.
00202         """
00203         x_center = start_x + (end_x - start_x) / 2
00204         y_pos = end_y + (self.padding_percent * (start_y - end_y)) / 2
00205         title_string = String(x_center, y_pos, title)
00206         title_string.fontName = 'Helvetica-Bold'
00207         title_string.fontSize = self.chart_title_size
00208         title_string.textAnchor = "middle"
00209 
00210         cur_drawing.add(title_string)

Here is the caller graph for this function:

def Bio.Graphics.Distribution.BarChartDistribution.draw (   self,
  cur_drawing,
  start_x,
  start_y,
  end_x,
  end_y 
)
Draw a bar chart with the info in the specified range.

Definition at line 155 of file Distribution.py.

00155 
00156     def draw(self, cur_drawing, start_x, start_y, end_x, end_y):
00157         """Draw a bar chart with the info in the specified range.
00158         """
00159         bar_chart = VerticalBarChart()
00160         if self.chart_title:
00161             self._draw_title(cur_drawing, self.chart_title,
00162                              start_x, start_y, end_x, end_y)
00163         # set the position of the bar chart
00164         x_start, x_end, y_start, y_end = \
00165            self._determine_position(start_x, start_y, end_x, end_y)
00166                                           
00167         bar_chart.x = x_start
00168         bar_chart.y = y_start
00169         bar_chart.width = abs(x_start - x_end)
00170         bar_chart.height = abs(y_start - y_end)
00171 
00172         # set the information in the bar chart
00173         bar_chart.data = self.display_info
00174         bar_chart.valueAxis.valueMin = min(self.display_info[0])
00175         bar_chart.valueAxis.valueMax = max(self.display_info[0])
00176         for data_set in self.display_info[1:]:
00177             if min(data_set) < bar_chart.valueAxis.valueMin:
00178                 bar_chart.valueAxis.valueMin = min(data_set)
00179             if max(data_set) > bar_chart.valueAxis.valueMax:
00180                 bar_chart.valueAxis.valueMax = max(data_set)
00181 
00182         # set other formatting options
00183         if len(self.display_info) == 1:
00184             bar_chart.groupSpacing = 0
00185             style = TypedPropertyCollection(BarChartProperties)
00186             style.strokeWidth = 0
00187             style.strokeColor = colors.green
00188             style[0].fillColor = colors.green
00189 
00190             bar_chart.bars = style
00191         
00192 
00193         # set the labels
00194         # XXX labels don't work yet
00195         # bar_chart.valueAxis.title = self.x_axis_title
00196         # bar_chart.categoryAxis.title = self.y_axis_title
00197 
00198         cur_drawing.add(bar_chart)

Here is the call graph for this function:


Member Data Documentation

Definition at line 150 of file Distribution.py.

Definition at line 151 of file Distribution.py.

Definition at line 146 of file Distribution.py.

Definition at line 153 of file Distribution.py.

Definition at line 148 of file Distribution.py.

Definition at line 149 of file Distribution.py.


The documentation for this class was generated from the following file: