Skip to content

Commit

Permalink
Enhance the Plot viewer
Browse files Browse the repository at this point in the history
- modified Toolbar and Info plugins so that they can switch GUIs according
  to the active viewer in a channel
  - When viewing a table you can pick columns to plot in the Info bar
    and make a plot that becomes its own Plotable object in the channel
- added methods to access viewers from channel object
- a few improvements to the plot viewer
  • Loading branch information
ejeschke committed Oct 4, 2024
1 parent 3c24161 commit 247886f
Show file tree
Hide file tree
Showing 23 changed files with 2,594 additions and 778 deletions.
8 changes: 6 additions & 2 deletions doc/WhatsNew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ What's New
Ver 5.2.0 (unreleased)
======================
- Substituted puremagic package for python-magic (works better across
platforms)
- Fixed an issue with the mouse wheel event scrolling MDI workspaces
platforms).
- Fixed an issue with the mouse wheel event scrolling MDI workspaces.
- Fixed a spurious warning when moving the cursor in the Pan plugin
window and a table or plot viewer is running in the channel
- Made the enter_focus property default to False
Expand All @@ -17,6 +17,10 @@ Ver 5.2.0 (unreleased)
- Added alternate versions of installed fonts to the default font set
(bold, italic, light)
- Some minor bug fixes for TreeView in Gtk3 backend
- Enhanced Plot viewer can plot 1D images or from tables via Table viewer

- Toolbar and Info (Synopsis) bars change GUIs according to which
viewer is active in the channel

Ver 5.1.0 (2024-05-22)
======================
Expand Down
2 changes: 1 addition & 1 deletion ginga/BaseImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, metadata=None, logger=None, name=None):
self.metadata.setdefault('name', None)

# For callbacks
for name in ('modified', ):
for name in ['modified']:
self.enable_callback(name)

def get_metadata(self):
Expand Down
44 changes: 21 additions & 23 deletions ginga/ImageView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2352,11 +2352,14 @@ def panset_pct(self, pct_x, pct_y):
"""
xy_mn, xy_mx = self.get_limits()
pan_x, pan_y = self.get_pan()[:2]

data_x = (xy_mn[0] + xy_mx[0]) * pct_x
data_y = (xy_mn[1] + xy_mx[1]) * pct_y
if pct_x is not None:
pan_x = (xy_mn[0] + xy_mx[0]) * pct_x
if pct_y is not None:
pan_y = (xy_mn[1] + xy_mx[1]) * pct_y

self.panset_xy(data_x, data_y)
self.panset_xy(pan_x, pan_y)

def calc_pan_pct(self, pad=0, min_pct=0.0, max_pct=0.9):
"""Calculate values for vertical/horizontal panning by percentages
Expand Down Expand Up @@ -2399,34 +2402,32 @@ def calc_pan_pct(self, pad=0, min_pct=0.0, max_pct=0.9):
dtype=float)
x, y = tr.to_(arr).T

rx1, rx2 = np.min(x), np.max(x)
ry1, ry2 = np.min(y), np.max(y)
x_min, x_max = np.min(x), np.max(x)
y_min, y_max = np.min(y), np.max(y)

bbox = self.get_pan_bbox()
arr = np.array(bbox, dtype=float)
x, y = tr.to_(arr).T

qx1, qx2 = np.min(x), np.max(x)
qy1, qy2 = np.min(y), np.max(y)
x_lo, x_hi = np.min(x), np.max(x)
y_lo, y_hi = np.min(y), np.max(y)

# this is the range of X and Y of the entire image
# in the viewer (unscaled)
rng_x, rng_y = abs(rx2 - rx1), abs(ry2 - ry1)
rng_x, rng_y = abs(x_max - x_min), abs(y_max - y_min)

# this is the *visually shown* range of X and Y
abs_x, abs_y = abs(qx2 - qx1), abs(qy2 - qy1)
vis_x, vis_y = abs(x_hi - x_lo), abs(y_hi - y_lo)

# calculate the length of the slider arms as a ratio
## min_pct = self.settings.get('pan_min_scroll_thumb_pct', 0.0)
## max_pct = self.settings.get('pan_max_scroll_thumb_pct', 0.9)
xthm_pct = max(min_pct, min(abs_x / (rx2 - rx1), max_pct))
ythm_pct = max(min_pct, min(abs_y / (ry2 - ry1), max_pct))
xthm_pct = max(min_pct, min(vis_x / rng_x, max_pct))
ythm_pct = max(min_pct, min(vis_y / rng_y, max_pct))

# calculate the pan position as a ratio
pct_x = min(max(0.0, abs(0.0 - rx1) / rng_x), 1.0)
pct_y = min(max(0.0, abs(0.0 - ry1) / rng_y), 1.0)
pct_x = min(max(0.0, abs(x_min) / rng_x), 1.0)
pct_y = min(max(0.0, abs(y_min) / rng_y), 1.0)

bnch = Bunch.Bunch(rng_x=rng_x, rng_y=rng_y, vis_x=abs_x, vis_y=abs_y,
bnch = Bunch.Bunch(rng_x=rng_x, rng_y=rng_y, vis_x=vis_x, vis_y=vis_y,
thm_pct_x=xthm_pct, thm_pct_y=ythm_pct,
pan_pct_x=pct_x, pan_pct_y=pct_y)
return bnch
Expand All @@ -2446,9 +2447,6 @@ def pan_by_pct(self, pct_x, pct_y, pad=0):
pad : int (optional, defaults to 0)
a padding amount in pixels to add to the limits when calculating
min_pct : float (optional, range 0.0:1.0, defaults to 0.0)
max_pct : float (optional, range 0.0:1.0, defaults to 0.9)
"""
# Sanity check on inputs
pct_x = np.clip(pct_x, 0.0, 1.0)
Expand All @@ -2468,11 +2466,11 @@ def pan_by_pct(self, pct_x, pct_y, pad=0):
dtype=float)
x, y = tr.to_(arr).T

rx1, rx2 = np.min(x), np.max(x)
ry1, ry2 = np.min(y), np.max(y)
x_min, x_max = np.min(x), np.max(x)
y_min, y_max = np.min(y), np.max(y)

crd_x = rx1 + (pct_x * (rx2 - rx1))
crd_y = ry1 + (pct_y * (ry2 - ry1))
crd_x = x_min + (pct_x * (x_max - x_min))
crd_y = y_min + (pct_y * (y_max - y_min))

pan_x, pan_y = tr.from_((crd_x, crd_y))
self.logger.debug("crd=%f,%f pan=%f,%f" % (
Expand Down
18 changes: 17 additions & 1 deletion ginga/gtk3w/GtkHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,20 @@ def get_scroll_info(event):
return (num_degrees, direction)


def get_icon(iconpath, size=None, adjust_width=True):
def get_image(iconpath, size=None, adjust_width=True):
"""Get a GdkPixbuf that can be used in a button or label.
Parameters
----------
iconpath : str
The path to the file containing the image of the icon
size : tuple of int (width, height) or None, (defaults to (24, 24))
The size of the icon to be returned in pixels
adjust_width : bool, (optional, defaults to True)
If True, adjust width to account for the aspect ratio of the image
"""
if size is not None:
wd, ht = size
else:
Expand All @@ -1744,6 +1757,9 @@ def get_icon(iconpath, size=None, adjust_width=True):
return pixbuf


get_icon = get_image


def get_font(font_family, point_size):
font_family = font_asst.resolve_alias(font_family, font_family)
font = Pango.FontDescription('%s %d' % (font_family, point_size))
Expand Down
3 changes: 2 additions & 1 deletion ginga/gtk3w/ImageViewGtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, logger=None, rgbmap=None, settings=None, render=None):
if render is None:
render = self.t_.get('render_widget', 'widget')
self.wtype = render
self.needs_scrolledview = True
self.surface = None
if self.wtype == 'widget':
imgwin = Gtk.DrawingArea()
Expand Down Expand Up @@ -738,7 +739,7 @@ def __init__(self, viewer, parent=None):

self._adjusting = False
self._scrolling = False
self.pad = 20
self.pad = 0
self.sb_thickness = 20
self.rng_x = 100.0
self.rng_y = 100.0
Expand Down
Loading

0 comments on commit 247886f

Please sign in to comment.