2 # Copyright 2009 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
23 from grid_plotter_base import grid_plotter_base
28 LEGEND_TEXT_FONT_SIZE = 8
29 LEGEND_BOX_PADDING = 3
30 MIN_PADDING = 0, 0, 0, 70 #top, right, bottom, left
31 #constants for the waveform storage
32 SAMPLES_KEY = 'samples'
33 COLOR_SPEC_KEY = 'color_spec'
34 MARKERY_KEY = 'marker'
35 TRIG_OFF_KEY = 'trig_off'
37 ##################################################
38 # Bar Plotter for histogram waveforms
39 ##################################################
40 class bar_plotter(grid_plotter_base):
42 def __init__(self, parent):
44 Create a new bar plotter.
47 grid_plotter_base.__init__(self, parent, MIN_PADDING)
50 self._color_spec = (0, 0, 0)
52 self._bar_cache = self.new_gl_cache(self._draw_bars)
54 self.register_init(self._init_bar_plotter)
56 def _init_bar_plotter(self):
58 Run gl initialization tasks.
60 GL.glEnableClientState(GL.GL_VERTEX_ARRAY)
64 Draw the vertical bars.
68 if num_bars == 0: return
69 #use scissor to prevent drawing outside grid
70 GL.glEnable(GL.GL_SCISSOR_TEST)
73 self.padding_bottom+1,
74 self.width-self.padding_left-self.padding_right-1,
75 self.height-self.padding_top-self.padding_bottom-1,
79 width = self._bar_width/2
80 for i, bar in enumerate(bars):
88 GL.glColor3f(*self._color_spec)
91 GL.glTranslatef(self.padding_left, self.padding_top, 0)
93 (self.width-self.padding_left-self.padding_right),
94 (self.height-self.padding_top-self.padding_bottom),
97 GL.glTranslatef(0, 1, 0)
98 GL.glScalef(1.0/(num_bars-1), -1.0/(self.y_max-self.y_min), 1)
99 GL.glTranslatef(0, -self.y_min, 0)
101 GL.glVertexPointerf(points)
102 GL.glDrawArrays(GL.GL_QUADS, 0, len(points))
104 GL.glDisable(GL.GL_SCISSOR_TEST)
106 def _populate_point_label(self, x_val, y_val):
108 Get the text the will populate the point label.
109 Give X and Y values for the current point.
110 Give values for the channel at the X coordinate.
111 @param x_val the current x value
112 @param y_val the current y value
113 @return a string with newlines
115 if len(self._bars) == 0: return ''
116 scalar = float(len(self._bars)-1)/(self.x_max - self.x_min)
117 #convert x val to bar #
118 bar_index = scalar*(x_val - self.x_min)
119 #if abs(bar_index - round(bar_index)) > self._bar_width/2: return ''
120 bar_index = int(round(bar_index))
121 bar_start = (bar_index - self._bar_width/2)/scalar + self.x_min
122 bar_end = (bar_index + self._bar_width/2)/scalar + self.x_min
123 bar_value = self._bars[bar_index]
124 return '%s to %s\n%s: %s'%(
125 common.eng_format(bar_start, self.x_units),
126 common.eng_format(bar_end, self.x_units),
127 self.y_label, common.eng_format(bar_value, self.y_units),
130 def set_bars(self, bars, bar_width, color_spec):
133 @param bars a list of bars
134 @param bar_width the fractional width of the bar, between 0 and 1
135 @param color_spec the color tuple
139 self._bar_width = float(bar_width)
140 self._color_spec = color_spec
141 self._bar_cache.changed(True)