Changeset 8278:6c0d8244450d in orange


Ignore:
Timestamp:
05/26/11 14:10:34 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
e4b9afe759c6ecbb41e1085a7d0687e384f1991d
Message:

Calculate the area for the plot before mapping the data coordinates, leaving enough room for axes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/QtGraph.py

    r8274 r8278  
    2626    .. method clear() 
    2727        Removes all curves from the graph 
     28         
     29    .. method graph_area_rect() 
     30        Return the QRectF of the area where data is plotted (without axes) 
    2831""" 
    2932 
     
    6467        self.setScene(self.canvas) 
    6568         
     69        self.axes = [xBottom, yLeft] 
     70        self.axis_margin = 150 
    6671        self.XaxisTitle = None 
    6772        self.YLaxisTitle = None 
     
    97102            self.legend.hide() 
    98103            self.legend = None 
     104             
     105    def graph_area_rect(self): 
     106        rect = self.childrenRect() 
     107        if xBottom in self.axes: 
     108            rect.setBottom(rect.bottom() - self.axis_margin) 
     109        if yLeft in self.axes: 
     110            rect.setLeft(rect.left() + self.axis_margin) 
     111        return rect 
    99112         
    100113    def map_to_graph_cart(self, point, axes=None): 
     
    104117        min_x, max_x = self.data_range[axes[0]] 
    105118        min_y, max_y = self.data_range[axes[1]] 
    106         # TODO: Adjust the childrenRect for axis, labels and legends 
    107         rx = (px - min_x) * self.childrenRect().width() / (max_x - min_x) 
    108         ry = -(py - min_y) * self.childrenRect().height() / (max_y - min_y) 
     119        rect = self.graph_area_rect() 
     120        rx = (px - min_x) * rect.width() / (max_x - min_x) 
     121        ry = -(py - min_y) * rect.height() / (max_y - min_y) 
    109122        return (rx, ry) 
    110123         
     
    115128        min_x, max_x = self.data_range[axes[0]] 
    116129        min_y, max_y = self.data_range[axes[1]] 
    117         # TODO: Adjust the childrenRect for axis, labels and legends 
    118         rect = self.childrenRect() 
     130        rect = self.graph_area_rect() 
    119131        rx = (px - rect.left()) / rect().width() * (max_x - min_x) 
    120132        ry = -(py - rect.bottom()) / rect.height() * (max_y - min_y) 
Note: See TracChangeset for help on using the changeset viewer.