Skip to content
Snippets Groups Projects
Commit ada55f9a authored by Paul McCarthy's avatar Paul McCarthy
Browse files

All plot panels use the same initial plot colour for a given overlay.

parent b765f82a
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,6 @@ import fsl.utils.dialog as fsldlg
import fsl.fsleyes.plotting.histogramseries as histogramseries
import fsl.fsleyes.controls.histogramcontrolpanel as histogramcontrolpanel
import fsl.fsleyes.controls.plotlistpanel as plotlistpanel
import fsl.fsleyes.colourmaps as fslcm
import plotpanel
......@@ -172,7 +171,7 @@ class HistogramPanel(plotpanel.OverlayPlotPanel):
strings.messages[self, 'calcHist'].format(overlay.name),
loadHs).Run()
hs.colour = fslcm.randomDarkColour()
hs.colour = self.getOverlayPlotColour(overlay)
hs.alpha = 1
hs.lineWidth = 1
hs.lineStyle = '-'
......
......@@ -29,9 +29,10 @@ import matplotlib.pyplot as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
import props
import viewpanel
import fsl.data.strings as strings
import props
import viewpanel
import fsl.data.strings as strings
import fsl.fsleyes.colourmaps as fslcm
log = logging.getLogger(__name__)
......@@ -775,7 +776,18 @@ class OverlayPlotPanel(PlotPanel):
``none`` Only the ``DataSeries`` that are in the
:attr:`.PlotPanel.dataSeries` list will be plotted.
=========== =====================================================
"""
"""
plotColours = {}
"""This dictionary is used to store a collection of ``{overlay : colour}``
mappings. It is shared across all ``OverlayPlotPanel`` instances, so that
the same (initial) colour is used for the same overlay, across multiple
plots.
Sub-classes should use the :meth:`getOverlayPlotColour` method to retrieve
the initial colour to use for a given overlay.
"""
def __init__(self, *args, **kwargs):
......@@ -853,12 +865,34 @@ class OverlayPlotPanel(PlotPanel):
specified overlay, or ``None`` if there is no ``DataSeries`` instance.
"""
return self.__dataSeries.get(overlay)
def getOverlayPlotColour(self, overlay):
"""Returns an initial colour to use for plots associated with the
given overlay. If a colour is present in the :attr:`plotColours`
dictionary, it is returned. Otherwise a random colour is generated,
added to ``plotColours``, and returned.
"""
colour = self.plotColours.get(overlay)
if colour is None:
colour = fslcm.randomDarkColour()
self.plotColours[overlay] = colour
return colour
def createDataSeries(self, overlay):
"""This method must be implemented by sub-classes. It must create and
return a :class:`.DataSeries` instance for the specified overlay.
.. note:: Sub-class implementations should set the
:attr:`.DataSeries.colour` property to that returned by
the :meth:`getOverlayPlotColour` method.
Different ``DataSeries`` types need to be re-drawn when different
properties change. For example, a :class:`.TimeSeries`` instance needs
to be redrawn when the :attr:`.DisplayContext.location` property
......
......@@ -21,7 +21,6 @@ import plotpanel
import fsl.fsleyes.plotting.powerspectrumseries as psseries
import fsl.fsleyes.controls.powerspectrumcontrolpanel as pscontrol
import fsl.fsleyes.controls.plotlistpanel as plotlistpanel
import fsl.fsleyes.colourmaps as fslcm
import fsl.data.image as fslimage
import fsl.data.melodicimage as fslmelimage
......@@ -179,7 +178,7 @@ class PowerSpectrumPanel(plotpanel.OverlayPlotPanel):
else:
return None, None, None
ps.colour = fslcm.randomDarkColour()
ps.colour = self.getOverlayPlotColour(overlay)
ps.alpha = 1.0
ps.lineWidth = 1
ps.lineStyle = '-'
......
......@@ -19,7 +19,6 @@ import plotpanel
import fsl.data.featimage as fslfeatimage
import fsl.data.melodicimage as fslmelimage
import fsl.data.image as fslimage
import fsl.fsleyes.colourmaps as fslcmaps
import fsl.fsleyes.plotting as plotting
import fsl.fsleyes.controls.timeseriescontrolpanel as timeseriescontrolpanel
import fsl.fsleyes.controls.plotlistpanel as plotlistpanel
......@@ -243,7 +242,7 @@ class TimeSeriesPanel(plotpanel.OverlayPlotPanel):
targets = [self._displayCtx]
propNames = ['location']
ts.colour = fslcmaps.randomDarkColour()
ts.colour = self.getOverlayPlotColour(overlay)
ts.alpha = 1
ts.lineWidth = 1
ts.lineStyle = '-'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment