~kolmis/cairoplot/speedup

« back to all changes in this revision

Viewing changes to trunk/cairoplot.py

  • Committer: Karel Kolman
  • Date: 2009-10-06 16:52:25 UTC
  • Revision ID: kolmis@gmail.com-20091006165225-7emgwfcrimp9zzm0
- make ScatterPlot store the rotation matrix for horizontal labels, apply the matrix for each label instead of multiple rotate() calls
- move set_source_rgba() calls outside a loop in render_vert_labels/render_horz_labels

Show diffs side-by-side

added added

removed removed

Lines of Context:
544
544
        cr = self.context
545
545
        step = float( self.plot_width ) / ( len( self.labels[HORZ] ) - 1 )
546
546
        x = self.borders[HORZ]
 
547
        y = self.dimensions[VERT] - self.borders[VERT] + 5
 
548
        
 
549
        # store rotation matrix
 
550
        cr.rotate(self.x_label_angle)
 
551
        rotation_matrix = cr.get_matrix()
 
552
        
 
553
        cr.identity_matrix()
 
554
        cr.set_source_rgba(*self.label_color)
 
555
 
547
556
        for item in self.labels[HORZ]:
548
 
            cr.set_source_rgba(*self.label_color)
549
557
            width = cr.text_extents(item)[2]
550
 
            cr.move_to(x, self.dimensions[VERT] - self.borders[VERT] + 5)
551
 
            cr.rotate(self.x_label_angle)
 
558
            cr.move_to(x, y)
 
559
            cr.set_matrix(rotation_matrix)
552
560
            cr.show_text(item)
553
 
            cr.rotate(-self.x_label_angle)
 
561
            cr.identity_matrix()
554
562
            x += step
555
563
    
556
564
    def render_vert_labels(self):
557
565
        cr = self.context
558
566
        step = ( self.plot_height ) / ( len( self.labels[VERT] ) - 1 )
559
567
        y = self.plot_top
 
568
        cr.set_source_rgba(*self.label_color)
560
569
        for item in self.labels[VERT]:
561
 
            cr.set_source_rgba(*self.label_color)
562
570
            width = cr.text_extents(item)[2]
563
571
            cr.move_to(self.borders[HORZ] - width - 5,y)
564
572
            cr.show_text(item)