1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
#/*##########################################################################
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__author__ = "V.A. Sole - ESRF Data Analysis"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__doc__ = """
Any plot window willing to accept plugins should implement the methods
defined in this class.
That way the plot will respect the Plot backend interface besides additional
methods:
The plugins will be compatible with any plot window that provides the methods:
- getActiveCurve
- getActiveImage
- getAllCurves
- getCurve
- getImage
- getMonotonicCurves
- hideCurve
- hideImage
- isActiveCurveHandlingEnabled
- isCurveHidden
- isImageHidden
- printGraph
- setActiveCurve
- showCurve
- showImage
The simplest way to achieve that is to inherit from Plot
"""
try:
from numpy import argsort, nonzero, take
except ImportError:
print("WARNING: numpy not present")
from . import PlotBackend
from . import PluginLoader
DEBUG = 0
class PlotBase(PlotBackend.PlotBackend, PluginLoader.PluginLoader):
def __init__(self, parent=None):
# This serves to define the plugins
PluginLoader.PluginLoader.__init__(self)
# And this to complete the interface
PlotBackend.PlotBackend.__init__(self, parent)
self._activeCurveHandling = True
def getActiveCurve(self, just_legend=False):
"""
:param just_legend: Flag to specify the type of output required
:type just_legend: boolean
:return: legend of the active curve or list [x, y, legend, info]
:rtype: string or list
Function to access the graph currently active curve.
It returns None in case of not having an active curve.
Default output has the form:
xvalues, yvalues, legend, dict
where dict is a dictionary containing curve info.
For the time being, only the plot labels associated to the
curve are warranted to be present under the keys xlabel, ylabel.
If just_legend is True:
The legend of the active curve (or None) is returned.
"""
print("PlotBase getActiveCurve not implemented")
if just_legend:
return None
else:
return []
def getActiveImage(self, just_legend=False):
print("PlotBase getActiveImage not implemented")
return None
def getAllCurves(self, just_legend=False):
"""
:param just_legend: Flag to specify the type of output required
:type just_legend: boolean
:return: legend of the curves or list [[x, y, legend, info], ...]
:rtype: list of strings or list of curves
It returns an empty list in case of not having any curve.
If just_legend is False:
It returns a list of the form:
[[xvalues0, yvalues0, legend0, dict0],
[xvalues1, yvalues1, legend1, dict1],
[...],
[xvaluesn, yvaluesn, legendn, dictn]]
or just an empty list.
If just_legend is True:
It returns a list of the form:
[legend0, legend1, ..., legendn]
or just an empty list.
"""
print("PlotBase getAllCurves not implemented")
return []
def getCurve(self, legend):
"""
:param legend: legend associated to the curve
:type legend: boolean
:return: list [x, y, legend, info]
:rtype: list
Function to access the graph specified curve.
It returns None in case of not having the curve.
Default output has the form:
xvalues, yvalues, legend, info
where info is a dictionary containing curve info.
For the time being, only the plot labels associated to the
curve are warranted to be present under the keys xlabel, ylabel.
"""
print("PlotBase getCurve not implemented")
return []
def getImage(self, legend):
"""
:param legend: legend associated to the curve
:type legend: boolean
:return: list [image, legend, info, pixmap]
:rtype: list
Function to access the graph specified image.
It returns None in case of not having that image.
Default output has the form:
image, legend, info, pixmap
where info is a dictionary containing image information.
"""
print("PlotBase getImage not implemented")
return []
def getMonotonicCurves(self):
"""
Convenience method that calls getAllCurves and makes sure that all of
the X values are strictly increasing.
:return: It returns a list of the form:
[[xvalues0, yvalues0, legend0, dict0],
[xvalues1, yvalues1, legend1, dict1],
[...],
[xvaluesn, yvaluesn, legendn, dictn]]
"""
allCurves = self.getAllCurves() * 1
for i in range(len(allCurves)):
curve = allCurves[i]
x, y, legend, info = curve[0:4]
if self.isCurveHidden(legend):
continue
# Sort
idx = argsort(x, kind='mergesort')
xproc = take(x, idx)
yproc = take(y, idx)
# Ravel, Increase
xproc = xproc.ravel()
idx = nonzero((xproc[1:] > xproc[:-1]))[0]
xproc = take(xproc, idx)
yproc = take(yproc, idx)
allCurves[i][0:2] = xproc, yproc
return allCurves
def hideCurve(self, legend, replot=True):
"""
Remove the curve associated to the legend form the graph.
It is still kept in the list of curves.
The graph will be updated if replot is true.
:param legend: The legend associated to the curve to be hidden
:type legend: string or handle
:param replot: Flag to indicate plot is to be immediately updated
:type replot: boolean default True
"""
print("PlotBase hideCurve not implemented")
return
def hideImage(self, legend, replot=True):
"""
Remove the image associated to the supplied legend from the graph.
I is still kept in the list of curves.
The graph will be updated if replot is true.
:param legend: The legend associated to the image to be hidden
:type legend: string or handle
:param replot: Flag to indicate plot is to be immediately updated
:type replot: boolean default True
"""
print("PlotBase hideImage not implemented")
return
def isActiveCurveHandlingEnabled(self):
if self._activeCurveHandling:
return True
else:
return False
def isCurveHidden(self, legend):
"""
:param legend: The legend associated to the curve
:type legend: string or handle
:return: True if the associated curve is hidden
"""
if DEBUG:
print("PlotBase isCurveHidden not implemented")
return False
def isImageHidden(self, legend):
"""
:param legend: The legend associated to the image
:type legend: string or handle
:return: True if the associated image is hidden
"""
if DEBUG:
print("PlotBase isImageHidden not implemented")
return False
def printGraph(self, **kw):
print("PlotBase printGraph not implemented")
def setActiveCurve(self, legend, replot=True):
"""
Funtion to request the plot window to set the curve with the specified legend
as the active curve.
:param legend: The legend associated to the curve
:type legend: string
:param replot: Flag to indicate plot is to be immediately updated
:type replot: boolean default True
"""
print("setActiveCurve not implemented")
return None
def showCurve(self, legend, replot=True):
"""
Show the curve associated to the legend in the graph.
:param legend: The legend associated to the curve
:type legend: string
:param replot: Flag to indicate plot is to be immediately updated
:type replot: boolean default True
"""
print("PlotBase showCurve not implemented")
return False
def showImage(self, legend, replot=True):
"""
Show the image associated to the legend in the graph.
:param legend: The legend associated to the image
:type legend: string
:param replot: Flag to indicate plot is to be immediately updated
:type replot: boolean default True
"""
print("PlotBase showImage not implemented")
return False
|