diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2018-07-31 16:22:25 +0200 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2018-07-31 16:22:25 +0200 |
commit | 159ef14fb9e198bb0066ea14e6b980f065de63dd (patch) | |
tree | bc37c7d4ba09ee59deb708897fa0571709aec293 /silx/gui/plot/Colors.py | |
parent | 270d5ddc31c26b62379e3caa9044dd75ccc71847 (diff) |
New upstream version 0.8.0+dfsg
Diffstat (limited to 'silx/gui/plot/Colors.py')
-rw-r--r-- | silx/gui/plot/Colors.py | 122 |
1 files changed, 12 insertions, 110 deletions
diff --git a/silx/gui/plot/Colors.py b/silx/gui/plot/Colors.py index 2d44d4d..277e104 100644 --- a/silx/gui/plot/Colors.py +++ b/silx/gui/plot/Colors.py @@ -28,120 +28,22 @@ from __future__ import absolute_import __authors__ = ["V.A. Sole", "T. Vincent"] __license__ = "MIT" -__date__ = "15/05/2017" +__date__ = "14/06/2018" +import silx.utils.deprecation -from silx.utils.deprecation import deprecated -import logging -import numpy +silx.utils.deprecation.deprecated_warning("Module", + name="silx.gui.plot.Colors", + reason="moved", + replacement="silx.gui.colors", + since_version="0.8.0", + only_once=True, + skip_backtrace_count=1) -from .Colormap import Colormap +from ..colors import * # noqa -_logger = logging.getLogger(__name__) - - -COLORDICT = {} -"""Dictionary of common colors.""" - -COLORDICT['b'] = COLORDICT['blue'] = '#0000ff' -COLORDICT['r'] = COLORDICT['red'] = '#ff0000' -COLORDICT['g'] = COLORDICT['green'] = '#00ff00' -COLORDICT['k'] = COLORDICT['black'] = '#000000' -COLORDICT['w'] = COLORDICT['white'] = '#ffffff' -COLORDICT['pink'] = '#ff66ff' -COLORDICT['brown'] = '#a52a2a' -COLORDICT['orange'] = '#ff9900' -COLORDICT['violet'] = '#6600ff' -COLORDICT['gray'] = COLORDICT['grey'] = '#a0a0a4' -# COLORDICT['darkGray'] = COLORDICT['darkGrey'] = '#808080' -# COLORDICT['lightGray'] = COLORDICT['lightGrey'] = '#c0c0c0' -COLORDICT['y'] = COLORDICT['yellow'] = '#ffff00' -COLORDICT['m'] = COLORDICT['magenta'] = '#ff00ff' -COLORDICT['c'] = COLORDICT['cyan'] = '#00ffff' -COLORDICT['darkBlue'] = '#000080' -COLORDICT['darkRed'] = '#800000' -COLORDICT['darkGreen'] = '#008000' -COLORDICT['darkBrown'] = '#660000' -COLORDICT['darkCyan'] = '#008080' -COLORDICT['darkYellow'] = '#808000' -COLORDICT['darkMagenta'] = '#800080' - - -def rgba(color, colorDict=None): - """Convert color code '#RRGGBB' and '#RRGGBBAA' to (R, G, B, A) - - It also convert RGB(A) values from uint8 to float in [0, 1] and - accept a QColor as color argument. - - :param str color: The color to convert - :param dict colorDict: A dictionary of color name conversion to color code - :returns: RGBA colors as floats in [0., 1.] - :rtype: tuple - """ - if colorDict is None: - colorDict = COLORDICT - - if hasattr(color, 'getRgbF'): # QColor support - color = color.getRgbF() - - values = numpy.asarray(color).ravel() - - if values.dtype.kind in 'iuf': # integer or float - # Color is an array - assert len(values) in (3, 4) - - # Convert from integers in [0, 255] to float in [0, 1] - if values.dtype.kind in 'iu': - values = values / 255. - - # Clip to [0, 1] - values[values < 0.] = 0. - values[values > 1.] = 1. - - if len(values) == 3: - return values[0], values[1], values[2], 1. - else: - return tuple(values) - - # We assume color is a string - if not color.startswith('#'): - color = colorDict[color] - - assert len(color) in (7, 9) and color[0] == '#' - r = int(color[1:3], 16) / 255. - g = int(color[3:5], 16) / 255. - b = int(color[5:7], 16) / 255. - a = int(color[7:9], 16) / 255. if len(color) == 9 else 1. - return r, g, b, a - - -_COLORMAP_CURSOR_COLORS = { - 'gray': 'pink', - 'reversed gray': 'pink', - 'temperature': 'pink', - 'red': 'green', - 'green': 'pink', - 'blue': 'yellow', - 'jet': 'pink', - 'viridis': 'pink', - 'magma': 'green', - 'inferno': 'green', - 'plasma': 'green', -} - - -def cursorColorForColormap(colormapName): - """Get a color suitable for overlay over a colormap. - - :param str colormapName: The name of the colormap. - :return: Name of the color. - :rtype: str - """ - return _COLORMAP_CURSOR_COLORS.get(colormapName, 'black') - - -@deprecated(replacement='silx.gui.plot.Colormap.applyColormap') +@silx.utils.deprecation.deprecated(replacement='silx.gui.colors.Colormap.applyColormap') def applyColormapToData(data, name='gray', normalization='linear', @@ -178,7 +80,7 @@ def applyColormapToData(data, return colormap.applyToData(data) -@deprecated(replacement='silx.gui.plot.Colormap.getSupportedColormaps') +@silx.utils.deprecation.deprecated(replacement='silx.gui.colors.Colormap.getSupportedColormaps') def getSupportedColormaps(): """Get the supported colormap names as a tuple of str. |