def draw_greytrack(self, track): """ draw_greytrack(self) -> ([element, element,...], [element, element,...]) o track Track object Put in a grey background to the current track in all fragments, if track specifies that we should """ greytrack_bgs = [] # Holds grey track backgrounds greytrack_labels = [] # Holds grey foreground labels if not track.greytrack: # No greytrack required, return early return [], [] # Get track location btm, ctr, top = self.track_offsets[self.current_track_level] # Add greytrack to all fragments for this track for fragment in range(self.fragments): tbtm = btm + self.fragment_lines[fragment][0] tctr = ctr + self.fragment_lines[fragment][0] ttop = top + self.fragment_lines[fragment][0] box = draw_box( (self.x0, tbtm), (self.xlim, ttop), # Grey track bg colors.Color(0.96, 0.96, 0.96)) # is just a box greytrack_bgs.append(box) if track.greytrack_labels: # If labels are required labelstep = ( self.pagewidth ) / track.greytrack_labels # how far apart should they be? label = String( 0, 0, track.name, # label contents fontName=track.greytrack_font, fontSize=track.greytrack_fontsize, fillColor=track.greytrack_fontcolor) # Create a new labelgroup at each position the label is required for x in range(int(self.x0), int(self.xlim), int(labelstep)): labelgroup = Group(label) rotation = angle2trig(track.greytrack_font_rotation) labelgroup.transform = (rotation[0], rotation[1], rotation[2], rotation[3], x, tbtm) if not self.xlim - x <= labelstep: # Don't overlap the end of the track greytrack_labels.append(labelgroup) return greytrack_bgs, greytrack_labels
def draw_greytrack(self, track): """ draw_greytrack(self) -> ([element, element,...], [element, element,...]) o track Track object Put in a grey background to the current track in all fragments, if track specifies that we should """ greytrack_bgs = [] # Holds grey track backgrounds greytrack_labels = [] # Holds grey foreground labels if not track.greytrack: # No greytrack required, return early return [], [] # Get track location btm, ctr, top = self.track_offsets[self.current_track_level] # Add greytrack to all fragments for this track for fragment in range(self.fragments): tbtm = btm + self.fragment_lines[fragment][0] tctr = ctr + self.fragment_lines[fragment][0] ttop = top + self.fragment_lines[fragment][0] box = draw_box((self.x0, tbtm), (self.xlim, ttop), # Grey track bg colors.Color(0.98,0.98, 0.98)) # is just a box greytrack_bgs.append(box) if track.greytrack_labels: # If labels are required labelstep = (self.pagewidth)/track.greytrack_labels # how far apart should they be? label = String(0, 0, track.name, # label contents fontName=track.greytrack_font, fontSize=track.greytrack_fontsize, fillColor=track.greytrack_fontcolor) # Create a new labelgroup at each position the label is required for x in range(int(self.x0), int(self.xlim), int(labelstep)): labelgroup = Group(label) rotation = angle2trig(track.greytrack_font_rotation) labelgroup.transform = (rotation[0], rotation[1], rotation[2], rotation[3], x, tbtm) if not self.xlim-x <= labelstep: # Don't overlap the end of the track greytrack_labels.append(labelgroup) return greytrack_bgs, greytrack_labels
def draw_bar_graph(self, graph): """ draw_bar_graph(self, graph) -> [element, element,...] o graph Graph object Returns a list of drawable elements for a bar graph of the passed Graph object """ #print '\tdraw_bar_graph' # At each point contained in the graph data, we draw a vertical bar # from the track center to the height of the datapoint value (positive # values go up in one color, negative go down in the alternative # color). bar_elements = [] # Holds drawable elements for the graph # Set the number of pixels per unit for the data data_quartiles = graph.quartiles() minval, maxval = data_quartiles[0],data_quartiles[4] btm, ctr, top = self.track_offsets[self.current_track_level] trackheight = 0.5*(top-btm) datarange = maxval - minval if datarange == 0: datarange = trackheight data = graph[self.start:self.end] # midval is the value at which the x-axis is plotted, and is the # central ring in the track if graph.center is None: midval = (maxval + minval)/2. else: midval = graph.center # Convert data into 'binned' blocks, covering half the distance to the # next data point on either side, accounting for the ends of fragments # and tracks newdata = intermediate_points(self.start, self.end, graph[self.start:self.end]) # Whichever is the greatest difference: max-midval or min-midval, is # taken to specify the number of pixel units resolved along the # y-axis resolution = max((midval-minval), (maxval-midval)) if resolution == 0: resolution = trackheight # Create elements for the bar graph based on newdata for pos0, pos1, val in newdata: fragment0, x0 = self.canvas_location(pos0) fragment1, x1 = self.canvas_location(pos1) x0, x1 = self.x0 + x0, self.x0 + x1 # account for margin barval = trackheight*(val-midval)/resolution if barval >=0: # Different colors for bars that extend above... barcolor = graph.poscolor else: # ...or below the axis barcolor = graph.negcolor # Draw bar if fragment0 == fragment1: # Box is contiguous if pos1 >= self.fragment_limits[fragment0][1]: x1 = self.xlim tctr = ctr + self.fragment_lines[fragment0][0] barval += tctr bar_elements.append(draw_box((x0, tctr), (x1, barval), color=barcolor)) else: # Box is split over two or more fragments fragment = fragment0 #if pos0 >= self.fragment_limits[fragment0][0]: # fragment += 1 start = x0 while self.fragment_limits[fragment][1] < pos1: tctr = ctr + self.fragment_lines[fragment][0] thisbarval = barval + tctr bar_elements.append(draw_box((start, tctr), (self.xlim, thisbarval), color=barcolor)) fragment += 1 start = self.x0 tctr = ctr + self.fragment_lines[fragment1][0] barval += tctr # Add the last part of the bar bar_elements.append(draw_box((self.x0, tctr), (x1, barval), color=barcolor)) return bar_elements
def draw_heat_graph(self, graph): """ draw_heat_graph(self, graph) -> [element, element,...] o graph Graph object Returns a list of drawable elements for the heat graph """ #print '\tdraw_heat_graph' # At each point contained in the graph data, we draw a box that is the # full height of the track, extending from the midpoint between the # previous and current data points to the midpoint between the current # and next data points heat_elements = [] # Holds drawable elements for the graph # Get graph data and information data_quartiles = graph.quartiles() minval, maxval = data_quartiles[0],data_quartiles[4] midval = (maxval + minval)/2. # mid is the value at the X-axis btm, ctr, top = self.track_offsets[self.current_track_level] trackheight = (top-btm) #print self.start, self.end newdata = intermediate_points(self.start, self.end, graph[self.start:self.end]) #print newdata # Create elements on the graph, indicating a large positive value by # the graph's poscolor, and a large negative value by the graph's # negcolor attributes for pos0, pos1, val in newdata: fragment0, x0 = self.canvas_location(pos0) fragment1, x1 = self.canvas_location(pos1) x0, x1 = self.x0 + x0, self.x0 + x1 # account for margin #print 'x1 before:', x1 # Calculate the heat color, based on the differential between # the value and the median value heat = colors.linearlyInterpolatedColor(graph.poscolor, graph.negcolor, maxval, minval, val) # Draw heat box if fragment0 == fragment1: # Box is contiguous on one fragment if pos1 >= self.fragment_limits[fragment0][1]: x1 = self.xlim ttop = top + self.fragment_lines[fragment0][0] tbtm = btm + self.fragment_lines[fragment0][0] #print 'equal', pos0, pos1, val #print pos0, pos1, fragment0, fragment1 heat_elements.append(draw_box((x0, tbtm), (x1, ttop), color=heat, border=None)) else: # box is split over two or more fragments #if pos0 >= self.fragment_limits[fragment0][0]: # fragment0 += 1 fragment = fragment0 start = x0 while self.fragment_limits[fragment][1] <= pos1: #print pos0, self.fragment_limits[fragment][1], pos1 ttop = top + self.fragment_lines[fragment][0] tbtm = btm + self.fragment_lines[fragment][0] heat_elements.append(draw_box((start, tbtm), (self.xlim, ttop), color=heat, border=None)) fragment += 1 start = self.x0 ttop = top + self.fragment_lines[fragment][0] tbtm = btm + self.fragment_lines[fragment][0] # Add the last part of the bar #print 'x1 after:', x1, '\n' heat_elements.append(draw_box((self.x0, tbtm), (x1, ttop), color=heat, border=None)) return heat_elements
def draw_heat_graph(self, graph): """ draw_heat_graph(self, graph) -> [element, element,...] o graph Graph object Returns a list of drawable elements for the heat graph """ #print '\tdraw_heat_graph' # At each point contained in the graph data, we draw a box that is the # full height of the track, extending from the midpoint between the # previous and current data points to the midpoint between the current # and next data points heat_elements = [] # Holds drawable elements for the graph # Get graph data and information data_quartiles = graph.quartiles() minval, maxval = data_quartiles[0], data_quartiles[4] midval = (maxval + minval) / 2. # mid is the value at the X-axis btm, ctr, top = self.track_offsets[self.current_track_level] trackheight = (top - btm) #print self.start, self.end newdata = intermediate_points(self.start, self.end, graph[self.start:self.end]) #print newdata # Create elements on the graph, indicating a large positive value by # the graph's poscolor, and a large negative value by the graph's # negcolor attributes for pos0, pos1, val in newdata: fragment0, x0 = self.canvas_location(pos0) fragment1, x1 = self.canvas_location(pos1) x0, x1 = self.x0 + x0, self.x0 + x1 # account for margin #print 'x1 before:', x1 # Calculate the heat color, based on the differential between # the value and the median value heat = colors.linearlyInterpolatedColor(graph.poscolor, graph.negcolor, maxval, minval, val) # Draw heat box if fragment0 == fragment1: # Box is contiguous on one fragment if pos1 >= self.fragment_limits[fragment0][1]: x1 = self.xlim ttop = top + self.fragment_lines[fragment0][0] tbtm = btm + self.fragment_lines[fragment0][0] #print 'equal', pos0, pos1, val #print pos0, pos1, fragment0, fragment1 heat_elements.append( draw_box((x0, tbtm), (x1, ttop), color=heat, border=None)) else: # box is split over two or more fragments #if pos0 >= self.fragment_limits[fragment0][0]: # fragment0 += 1 fragment = fragment0 start = x0 while self.fragment_limits[fragment][1] <= pos1: #print pos0, self.fragment_limits[fragment][1], pos1 ttop = top + self.fragment_lines[fragment][0] tbtm = btm + self.fragment_lines[fragment][0] heat_elements.append( draw_box((start, tbtm), (self.xlim, ttop), color=heat, border=None)) fragment += 1 start = self.x0 ttop = top + self.fragment_lines[fragment][0] tbtm = btm + self.fragment_lines[fragment][0] # Add the last part of the bar #print 'x1 after:', x1, '\n' heat_elements.append( draw_box((self.x0, tbtm), (x1, ttop), color=heat, border=None)) return heat_elements
def draw_bar_graph(self, graph): """ draw_bar_graph(self, graph) -> [element, element,...] o graph Graph object Returns a list of drawable elements for a bar graph of the passed Graph object """ #print '\tdraw_bar_graph' # At each point contained in the graph data, we draw a vertical bar # from the track center to the height of the datapoint value (positive # values go up in one color, negative go down in the alternative # color). bar_elements = [] # Holds drawable elements for the graph # Set the number of pixels per unit for the data data_quartiles = graph.quartiles() minval, maxval = data_quartiles[0], data_quartiles[4] btm, ctr, top = self.track_offsets[self.current_track_level] trackheight = 0.5 * (top - btm) datarange = maxval - minval if datarange == 0: datarange = trackheight data = graph[self.start:self.end] # midval is the value at which the x-axis is plotted, and is the # central ring in the track if graph.center is None: midval = (maxval + minval) / 2. else: midval = graph.center # Convert data into 'binned' blocks, covering half the distance to the # next data point on either side, accounting for the ends of fragments # and tracks newdata = intermediate_points(self.start, self.end, graph[self.start:self.end]) # Whichever is the greatest difference: max-midval or min-midval, is # taken to specify the number of pixel units resolved along the # y-axis resolution = max((midval - minval), (maxval - midval)) if resolution == 0: resolution = trackheight # Create elements for the bar graph based on newdata for pos0, pos1, val in newdata: fragment0, x0 = self.canvas_location(pos0) fragment1, x1 = self.canvas_location(pos1) x0, x1 = self.x0 + x0, self.x0 + x1 # account for margin barval = trackheight * (val - midval) / resolution if barval >= 0: # Different colors for bars that extend above... barcolor = graph.poscolor else: # ...or below the axis barcolor = graph.negcolor # Draw bar if fragment0 == fragment1: # Box is contiguous if pos1 >= self.fragment_limits[fragment0][1]: x1 = self.xlim tctr = ctr + self.fragment_lines[fragment0][0] barval += tctr bar_elements.append( draw_box((x0, tctr), (x1, barval), color=barcolor)) else: # Box is split over two or more fragments fragment = fragment0 #if pos0 >= self.fragment_limits[fragment0][0]: # fragment += 1 start = x0 while self.fragment_limits[fragment][1] < pos1: tctr = ctr + self.fragment_lines[fragment][0] thisbarval = barval + tctr bar_elements.append( draw_box((start, tctr), (self.xlim, thisbarval), color=barcolor)) fragment += 1 start = self.x0 tctr = ctr + self.fragment_lines[fragment1][0] barval += tctr # Add the last part of the bar bar_elements.append( draw_box((self.x0, tctr), (x1, barval), color=barcolor)) return bar_elements