Changeset 9290b1a in sasview for src/sas/qtgui/PlotUtilities.py


Ignore:
Timestamp:
Dec 16, 2016 12:43:18 PM (8 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
d3ca363
Parents:
0ba0774
Message:

Added AddText? to plot, enabled legend drag - SASVIEW-378

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/PlotUtilities.py

    rfecfe28 r9290b1a  
    175175 
    176176    return image 
     177 
     178def rescale(lo, hi, step, pt=None, bal=None, scale='linear'): 
     179    """ 
     180    Rescale (lo,hi) by step, returning the new (lo,hi) 
     181    The scaling is centered on pt, with positive values of step 
     182    driving lo/hi away from pt and negative values pulling them in. 
     183    If bal is given instead of point, it is already in [0,1] coordinates. 
     184 
     185    This is a helper function for step-based zooming. 
     186    """ 
     187    # Convert values into the correct scale for a linear transformation 
     188    # TODO: use proper scale transformers 
     189    loprev = lo 
     190    hiprev = hi 
     191    if scale == 'log': 
     192        assert lo > 0 
     193        if lo > 0: 
     194            lo = numpy.log10(lo) 
     195        if hi > 0: 
     196            hi = numpy.log10(hi) 
     197        if pt is not None: 
     198            pt = numpy.log10(pt) 
     199 
     200    # Compute delta from axis range * %, or 1-% if persent is negative 
     201    if step > 0: 
     202        delta = float(hi - lo) * step / 100 
     203    else: 
     204        delta = float(hi - lo) * step / (100 - step) 
     205 
     206    # Add scale factor proportionally to the lo and hi values, 
     207    # preserving the 
     208    # point under the mouse 
     209    if bal is None: 
     210        bal = float(pt - lo) / (hi - lo) 
     211    lo = lo - (bal * delta) 
     212    hi = hi + (1 - bal) * delta 
     213 
     214    # Convert transformed values back to the original scale 
     215    if scale == 'log': 
     216        if (lo <= -250) or (hi >= 250): 
     217            lo = loprev 
     218            hi = hiprev 
     219        else: 
     220            lo, hi = numpy.power(10., lo), numpy.power(10., hi) 
     221    return (lo, hi) 
     222 
Note: See TracChangeset for help on using the changeset viewer.