User:Andrew Nikitin/plotscroll

From J Wiki
Jump to navigation Jump to search

This script is intended to help zoom in and scroll though a time series data displayed in simple 2d plot. It works with standard plot class and uses default plot window (named jwplot) as its target.

Form

[{{#file: "plotscroll.ijs"}} Download script: plotscroll.ijs ]

PLOTSCROLL=: 0 : 0
pc plotscroll;
xywh 5 5 30 10;cc ccstatic static;cn "Y-range";
xywh 35 5 50 10;cc yrange edit ws_disabled;
xywh 5 25 30 10;cc ccstatic static;cn "step (0..1)";
xywh 35 25 21 10;cc xstep edit;
xywh 5 45 30 10;cc ccstatic static;cn "X-range";
xywh 35 45 50 10;cc xrange edit;
xywh 10 60 30 10;cc left button;cn "<<";
xywh 40 60 30 10;cc show button;cn "[]";
xywh 70 60 30 10;cc right button;cn ">>";
pas 6 6;pcenter;
rem form end;
)

plotscroll_run=: 3 : 0
wd PLOTSCROLL
NB. initialize form here
wd 'set yrange *<TODO>'
wd 'set xstep 1'
wd 'set xrange *'
wd 'pshow;'
)

plotscroll_close=: 3 : 0
wd'pclose'
)

Form contains edit fields for x axis range and step. X axis range is 2 numbers separated by space, which mean low and high value of X to display. Step is single number -- a fraction of x range. 1 means that steps will be performed in increments of current range.

At some point I thought that I might want to change the y range too, but I need it so seldom that typing pd 'yrange ....' does not feel like a big burden.

There are also 3 buttons: to move backwards, forward or display manually entered value of x range.

User must enter initial value of a range. If field is left empty, buttons will do nothing.

Change/set xrange

[{{#file: "plotscroll.ijs"}} Download script: plotscroll.ijs ]

nox=:3 : 0
  xr=:0".xrange
  if. 2=$xr do.
    xr=:xr+y*-~/xr
    wd 'set xrange *',":xr
    i=.(<'xrange') i:~ {."1 PCmd_jwplot_
    if. i>:#PCmd_jwplot_ do.
      pd 'xrange ',(":xr)
    else.
      PCmd_jwplot_=:(<":xr) (<i;1)} PCmd_jwplot_
    end.
    pd 'show'
  end.
)

y=range increment in units of step. Can be meaningfully _1 (backwards), 0 (redisplay/set) or 1 (forward). This calculates new value of xrange and either replaces the plot option with new value, or (if xrange command hasn't been issued yet) issues pd 'xrange ...' command.

GUI event handlers

[{{#file: "plotscroll.ijs"}} Download script: plotscroll.ijs ]

plotscroll_left_button=: 3 : 0
  nox -1".xstep
)
plotscroll_show_button=: 3 : 0
  nox 0
)
plotscroll_right_button=: 3 : 0
  nox 1".xstep
)

Plot issues

The following plot options interfere with plot's ability to display only the requested x range:

  • xticpos
  • xlabel