source: orange/Orange/OrangeWidgets/plot/owcurve.py @ 10854:e1100b7b4761

Revision 10854:e1100b7b4761, 9.8 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Fixed imports of orangeqt

Line 
1'''
2##############################
3Curve (``owcurve``)
4##############################
5
6.. class:: OWPlotItem
7
8    This class represents a base for any item than can be added to a plot.
9   
10    .. method:: attach(plot)
11   
12        Attaches this item to ``plot``. The Plot takes the ownership of this item.
13   
14        :param plot: the plot to which to add this item
15        :type plot: :obj:`.OWPlot`
16       
17        :seealso: :meth:`.OWPlot.add_item`.
18       
19    .. method:: detach()
20       
21        Removes this item from its plot. The item's ownership is returned to Python.
22       
23    .. method:: plot()
24   
25        :returns: The plot this item is attached to. If the item is not attached to any plot, ``None`` is returned.
26        :rtype: :obj:`.OWPlot`
27       
28    .. method:: data_rect()
29       
30        Returns the bounding rectangle of this item in data coordinates. This method is used in autoscale calculations.
31       
32    .. method:: set_data_rect(rect)
33       
34        :param rect: The new bounding rectangle in data coordinates
35        :type rect: :obj:`.QRectF`
36       
37    .. method:: set_graph_transform(transform)
38   
39        Sets the graph transform (the transformation that maps from data to plot coordinates) for this item.
40       
41    .. method:: graph_transform()
42   
43        :returns: The current graph transformation.
44        :rtype: QTransform
45       
46    .. method:: set_zoom_transform(transform)
47   
48        Sets the zoom transform (the transformation that maps from plot to scene coordinates) for this item.
49       
50    .. method:: zoom_transform()
51   
52        :returns: The current zoom transformation.
53        :rtype: QTransform
54       
55    .. method:: set_axes(x_axis, y_axis)
56   
57        Sets the pair of axes used for positioning this item.
58       
59    .. method:: axes()
60       
61        :returns: The item's pair of axes
62        :rtype: tuple of int int
63       
64    .. method:: update_properties()
65   
66        Called by the plot, this function is supposed to updates the item's internal state to match its settings.
67       
68        The default implementation does nothing and shold be reimplemented by subclasses.
69       
70    .. method:: register_points()
71       
72        If this item constains any points (of type :obj:`.OWPoint`), add them to the plot in this function.
73       
74        The default implementation does nothing.
75       
76    .. method:: set_in_background(background)
77   
78        If ``background`` is ``True``, the item is moved to be background of this plot, behind other items and axes.
79        Otherwise, it's brought to the front, in front of axes.
80       
81        The default in ``False``, so that items apper in front of axes.
82       
83    .. method:: is_in_background()
84   
85        Returns if item is in the background, set with :meth:`set_in_background`.
86       
87    **Subclassing**
88   
89        Often you will want to create a custom curve class that inherits from OWCurve.
90        For this purpose, OWPlotItem provides two virtual methods: :meth:`paint` and :meth:`update_properties`.
91       
92        * ``update_properties()`` is called whenever a curve or the plot is changed and needs to be updated.
93          In this method, child items and other members should be recalculated and updated.
94          The OWCurve even provides a number of methods for asynchronous (threaded) updating.
95         
96        * `paint()` is called whenever the item needs to be painted on the scene.
97          This method is called more often, so it's advisable to avoid long operation in the method.
98         
99        Most provided plot items, including :obj:`OWCurve`, :obj:`OWMultiCurve` and utility curves in :mod:`.owtools`
100        only reimplement the first method, because they are optimized for performance with large data sets.
101       
102.. autoclass:: OWCurve
103   
104.. class:: OWMultiCurve
105
106    A multi-curve is a curve in which each point can have its own properties.
107    The point coordinates can be set by calling :meth:`.OWCurve.set_data`, just like in a normal curve.
108   
109    In addition, OWMultiCurve provides methods for setting properties for individual points.
110    Each of this methods take a list as a parameter. If the list has less elements that the curve's data,
111    the first element is used for all points.
112   
113    .. method:: set_point_colors(lst)
114       
115        :param lst: The list of colors to assign to points
116        :type lst: list of QColor
117       
118        .. seealso:: :meth:`.OWPoint.set_color`
119       
120    .. method:: set_point_sizes(lst)
121       
122        :param lst: The list of sizes to assign to points
123        :type lst: list of int
124       
125        .. seealso:: :meth:`.OWPoint.set_size`
126   
127    .. method:: set_point_symbols(lst)
128       
129        :param lst: The list of symbols to assign to points
130        :type lst: list of int
131       
132        .. seealso:: :meth:`.OWPoint.set_symbol`
133   
134'''
135
136from OWBaseWidget import *
137from owconstants import *
138from Orange import orangeqt
139from Orange.utils import deprecated_members
140
141OWPlotItem = orangeqt.PlotItem
142
143@deprecated_members({
144    "setYAxis" : "set_y_axis",
145    "setData" : "set_data"
146})
147class OWCurve(orangeqt.Curve):
148    """
149        This class represents a curve on a plot.
150        It is essentially a plot item with a series of data points or a continuous line.
151       
152        :param xData: list of x coordinates
153        :type xData: list of float
154       
155        :param yData: list of y coordinates
156        :type yData: list of float
157       
158        :param x_axis_key: The x axis of this curve
159        :type x_axis_key: int
160       
161        :param y_axis_key: The y axis of this curve
162        :type y_axis_key: int
163       
164        :param tooltip: The curve's tooltip
165        :type tooltip: str
166       
167        .. note::
168           
169            All the points or line segments in an OWCurve have the same properties.
170            Different points in one curve are supported by the :obj:`.OWMultiCurve` class.
171       
172           
173        .. method:: point_item(x, y, size=0, parent=None)
174       
175            Returns a single point with this curve's properties.
176            It is useful for representing the curve, for example in the legend.
177           
178            :param x: The x coordinate of the point.
179            :type x: float
180           
181            :param y: The y coordinate of the point.
182            :type y: float
183           
184            :param size: If nonzero, this argument determines the size of the resulting point.
185                         Otherwise, the point is created with the curve's :meth:`OWCurve.point_size`
186            :type size: int
187                         
188            :param parent: An optional parent for the returned item.
189            :type parent: :obj:`.QGraphicsItem`
190           
191        .. attribute:: name
192
193            The name of the curve, used in the legend or in tooltips.
194           
195        .. method:: set_data(x_data, y_data)
196       
197            Sets the curve's data to a list of coordinates specified by ``x_data`` and ``y_data``.
198           
199        .. method:: data()
200           
201            :returns: The curve's data as a list of data points.
202            :rtype: list of tuple of float float
203           
204        .. method:: set_style(style)
205       
206            Sets the curve's style to ``style``.
207           
208            The following values are recognized by OWCurve:
209           
210            ===================  ===============================================
211            Value                Result
212            ===================  ===============================================
213            OWCurve.Points       Only points are shown, no lines
214            OWCurve.Lines        A continuous line is shown, no points
215            OWCurve.LinesPoints  Both points and lines between them are shown
216            OWCurve.Dots         A dotted line is shown, no points
217            OWCurve.NoCurve      Deprecated, same as ``OWCurve.Points``
218            ===================  ===============================================
219           
220            Curve subclasses can use this value for different drawing modes.
221            Values up to OWCurve.UserCurve are reserved, so use only higher numbers, like the following example::
222           
223                class MyCurve(OWCurve):
224                    PonyStyle = OWCurve.UserCurve + 42
225                   
226                    def draw_ponies()
227                        # Draw type-specific things here
228                   
229                    def update_properties(self):
230                        if self.style() == PonyStyle:
231                            self.draw_ponies()
232                        else:
233                            OWCurve.update_properties(self)
234           
235        .. method:: style()
236       
237            :return: The curve's style, set with :meth:`set_style`
238            :rtype: int
239           
240        .. method:: cancel_all_updates()
241       
242            Cancel all pending threaded updates and block until they are finished.
243            This is usually called before starting a new round of updates.
244           
245        .. method:: update_number_of_items()
246       
247            Resizes the point list so that it matches the number of data points in :meth:`data`
248           
249        .. method:: update_point_coordinates()
250       
251            Sets the coordinates of each point to match :meth:`data`.
252           
253        .. method:: update_point_positions()
254       
255            Sets the scene positions of the points to match their data coordinates.
256    """
257    NoCurve = orangeqt.Curve.Points
258   
259    def __init__(self, xData=[], yData=[], x_axis_key=xBottom, y_axis_key=yLeft, tooltip=None):
260        orangeqt.Curve.__init__(self, xData, yData)
261        self.set_axes(x_axis_key, y_axis_key)
262        if tooltip:
263            self.setToolTip(tooltip)
264        self.name = ''
265       
266OWMultiCurve = orangeqt.MultiCurve
267
268           
Note: See TracBrowser for help on using the repository browser.