Skip to content

Commit

Permalink
aggregation items to ArrayImagePlot
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgar committed Oct 27, 2024
1 parent ed3e275 commit ea0bd4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
23 changes: 2 additions & 21 deletions src/silx/gui/data/DataViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from silx.io.nxdata import get_attr_as_unicode
from silx.gui.colors import Colormap
from silx.gui.dialog.ColormapDialog import ColormapDialog
from silx.gui.plot.actions.image import ImageDataAggregated
from silx.gui.plot.items.image import ImageDataAggregated
from silx.gui.plot.actions.image import AggregationModeAction
from silx._utils import NP_OPTIONAL_COPY

Expand Down Expand Up @@ -1844,26 +1844,7 @@ def createWidget(self, parent):
widget.getPlot().getColormapAction().setColormapDialog(
self.defaultColorDialog()
)
self.__aggregationModeAction = AggregationModeAction(parent=widget)
widget.getPlot().toolBar().addAction(self.__aggregationModeAction)
self.__aggregationModeAction.sigAggregationModeChanged.connect(self._aggregationModeChanged)
return widget

def getAggregationModeAction(self) -> AggregationModeAction:
"""Action toggling the aggregation mode action
"""
return self.__aggregationModeAction

def _aggregationModeChanged(self):
plot = self.getWidget().getPlot()
item = plot._getItem("image")

if item is None:
return

if isinstance(item, ImageDataAggregated):
item.setAggregationMode(self.getAggregationModeAction().getAggregationMode())

def axesNames(self, data, info):
# disabled (used by default axis selector widget in Hdf5Viewer)
return None
Expand Down Expand Up @@ -1906,7 +1887,7 @@ def setData(self, data):
return

if isinstance(item, ImageDataAggregated):
item.setAggregationMode(self.getAggregationModeAction().getAggregationMode())
item.setAggregationMode(self.getWidget().getAggregationModeAction().getAggregationMode())

def getDataPriority(self, data, info):
data = self.normalizeData(data)
Expand Down
29 changes: 24 additions & 5 deletions src/silx/gui/data/NXdataWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from silx.gui.plot import Plot1D, Plot2D, StackView, ScatterView, items
from silx.gui.plot.ComplexImageView import ComplexImageView
from silx.gui.plot.items.image_aggregated import ImageDataAggregated
from silx.gui.plot.actions.image import AggregationModeAction
from silx.gui.colors import Colormap
from silx.gui.widgets.FrameBrowser import HorizontalSliderWithBrowser

Expand Down Expand Up @@ -423,7 +424,25 @@ def __init__(self, parent=None):
layout.addWidget(self._auxSigSlider)

self.setLayout(layout)

self.__aggregationModeAction = AggregationModeAction(parent=self)
self.getPlot().toolBar().addAction(self.__aggregationModeAction)
self.__aggregationModeAction.sigAggregationModeChanged.connect(self._aggregationModeChanged)

def getAggregationModeAction(self) -> AggregationModeAction:
"""Action toggling the aggregation mode action
"""
return self.__aggregationModeAction

def _aggregationModeChanged(self):
item = self.getPlot()._getItem("image")

if item is None:
return

if isinstance(item, ImageDataAggregated):
item.setAggregationMode(self.getAggregationModeAction().getAggregationMode())

def _sliderIdxChanged(self, value):
self._updateImage()

Expand Down Expand Up @@ -556,10 +575,7 @@ def _updateImage(self):
"image",
)
)
imageItem = ImageDataAggregated()
imageItem.setName(legend)
self._plot.addItem(imageItem)


if xcalib.is_affine() and ycalib.is_affine():
# regular image
xorigin, xscale = xcalib(0), xcalib.get_slope()
Expand All @@ -570,11 +586,14 @@ def _updateImage(self):
self._plot.getXAxis().setScale("linear")
self._plot.getYAxis().setScale("linear")

imageItem = ImageDataAggregated()
imageItem.setName(legend)
imageItem.setData(image)
imageItem.setOrigin(origin)
imageItem.setScale(scale)
imageItem.setColormap(self._plot.getDefaultColormap())

imageItem.setAggregationMode(self.getAggregationModeAction().getAggregationMode())
self._plot.addItem(imageItem)
else:
xaxisscale, yaxisscale = self._axis_scales

Expand Down

0 comments on commit ea0bd4c

Please sign in to comment.