diff options
Diffstat (limited to 'silx/gui/plot/backends/BackendBase.py')
-rwxr-xr-x[-rw-r--r--] | silx/gui/plot/backends/BackendBase.py | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/silx/gui/plot/backends/BackendBase.py b/silx/gui/plot/backends/BackendBase.py index af37543..75d999b 100644..100755 --- a/silx/gui/plot/backends/BackendBase.py +++ b/silx/gui/plot/backends/BackendBase.py @@ -97,16 +97,15 @@ class BackendBase(object): # Add methods - def addCurve(self, x, y, legend, + def addCurve(self, x, y, color, symbol, linewidth, linestyle, yaxis, - xerror, yerror, z, selectable, - fill, alpha, symbolsize): + xerror, yerror, z, + fill, alpha, symbolsize, baseline): """Add a 1D curve given by x an y to the graph. :param numpy.ndarray x: The data corresponding to the x axis :param numpy.ndarray y: The data corresponding to the y axis - :param str legend: The legend to be associated to the curve :param color: color(s) to be used :type color: string ("#RRGGBB") or (npoints, 4) unsigned byte array or one of the predefined color names defined in colors.py @@ -136,24 +135,21 @@ class BackendBase(object): :param yerror: Values with the uncertainties on the y values :type yerror: numpy.ndarray or None :param int z: Layer on which to draw the cuve - :param bool selectable: indicate if the curve can be selected :param bool fill: True to fill the curve, False otherwise :param float alpha: Curve opacity, as a float in [0., 1.] :param float symbolsize: Size of the symbol (if any) drawn at each (x, y) position. :returns: The handle used by the backend to univocally access the curve """ - return legend + return object() - def addImage(self, data, legend, + def addImage(self, data, origin, scale, z, - selectable, draggable, colormap, alpha): """Add an image to the plot. :param numpy.ndarray data: (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array - :param str legend: The legend to be associated to the image :param origin: (origin X, origin Y) of the data. Default: (0., 0.) :type origin: 2-tuple of float @@ -161,39 +157,34 @@ class BackendBase(object): Default: (1., 1.) :type scale: 2-tuple of float :param int z: Layer on which to draw the image - :param bool selectable: indicate if the image can be selected - :param bool draggable: indicate if the image can be moved :param ~silx.gui.colors.Colormap colormap: Colormap object to use. Ignored if data is RGB(A). :param float alpha: Opacity of the image, as a float in range [0, 1]. :returns: The handle used by the backend to univocally access the image """ - return legend + return object() - def addTriangles(self, x, y, triangles, legend, - color, z, selectable, alpha): + def addTriangles(self, x, y, triangles, + color, z, alpha): """Add a set of triangles. :param numpy.ndarray x: The data corresponding to the x axis :param numpy.ndarray y: The data corresponding to the y axis :param numpy.ndarray triangles: The indices to make triangles as a (Ntriangle, 3) array - :param str legend: The legend to be associated to the curve :param numpy.ndarray color: color(s) as (npoints, 4) array :param int z: Layer on which to draw the cuve - :param bool selectable: indicate if the curve can be selected :param float alpha: Opacity as a float in [0., 1.] :returns: The triangles' unique identifier used by the backend """ - return legend + return object() - def addItem(self, x, y, legend, shape, color, fill, overlay, z, + def addItem(self, x, y, shape, color, fill, overlay, z, linestyle, linewidth, linebgcolor): """Add an item (i.e. a shape) to the plot. :param numpy.ndarray x: The X coords of the points of the shape :param numpy.ndarray y: The Y coords of the points of the shape - :param str legend: The legend to be associated to the item :param str shape: Type of item to be drawn in hline, polygon, rectangle, vline, polylines :param str color: Color of the item @@ -215,22 +206,18 @@ class BackendBase(object): '#FF0000'. It is used to draw dotted line using a second color. :returns: The handle used by the backend to univocally access the item """ - return legend + return object() - def addMarker(self, x, y, legend, text, color, - selectable, draggable, - symbol, linestyle, linewidth, constraint): + def addMarker(self, x, y, text, color, + symbol, linestyle, linewidth, constraint, yaxis): """Add a point, vertical line or horizontal line marker to the plot. :param float x: Horizontal position of the marker in graph coordinates. If None, the marker is a horizontal line. :param float y: Vertical position of the marker in graph coordinates. If None, the marker is a vertical line. - :param str legend: Legend associated to the marker :param str text: Text associated to the marker (or None for no text) :param str color: Color to be used for instance 'blue', 'b', '#FF0000' - :param bool selectable: indicate if the marker can be selected - :param bool draggable: indicate if the marker can be moved :param str symbol: Symbol representing the marker. Only relevant for point markers where X and Y are not None. Value in: @@ -257,13 +244,13 @@ class BackendBase(object): dragging operations or None for no filter. This function is called each time a marker is moved. - This parameter is only used if draggable is True. :type constraint: None or a callable that takes the coordinates of the current cursor position in the plot as input and that returns the filtered coordinates. + :param str yaxis: The Y axis this marker belongs to in: 'left', 'right' :return: Handle used by the backend to univocally access the marker """ - return legend + return object() # Remove methods @@ -307,22 +294,40 @@ class BackendBase(object): """ pass - def pickItems(self, x, y, kinds): - """Get a list of items at a pixel position. + def getItemsFromBackToFront(self, condition=None): + """Returns the list of plot items order as rendered by the backend. + + This is the order used for rendering. + By default, it takes into account overlays, z value and order of addition of items, + but backends can override it. + + :param callable condition: + Callable taking an item as input and returning False for items to skip. + If None (default), no item is skipped. + :rtype: List[~silx.gui.plot.items.Item] + """ + # Sort items: Overlays first, then others + # and in each category ordered by z and then by order of addition + # as content keeps this order. + content = self._plot.getItems() + if condition is not None: + content = [item for item in content if condition(item)] + + return sorted( + content, + key=lambda i: ((1 if i.isOverlay() else 0), i.getZValue())) + + def pickItem(self, x, y, item): + """Return picked indices if any, or None. :param float x: The x pixel coord where to pick. :param float y: The y pixel coord where to pick. - :param List[str] kind: List of item kinds to pick. - Supported kinds: 'marker', 'curve', 'image'. - :return: All picked items from back to front. - One dict per item, - with 'kind' key in 'curve', 'marker', 'image'; - 'legend' key, the item legend. - and for curves, 'xdata' and 'ydata' keys storing picked - position on the curve. - :rtype: list of dict - """ - return [] + :param item: A backend item created with add* methods. + :return: None if item was not picked, else returns + picked indices information. + :rtype: Union[None,List] + """ + return None # Update curve |