Scripts/Real-time Plot

From J Wiki
Jump to: navigation, search

Rtplot.gif

This script shows how to make real-time plot updated at regular intervals using the timer event. Download script: rtplot.ijs

NB. rtplot - Real-time Plot
NB. 11/05/2007 Oleg Kobchenko

require 'jzplot strings'
coclass 'prtplot'

F=: 0 : 0
pc f;pn "Real-time Plot";
xywh 250 4 44 12;cc toggle button leftmove rightmove;cn "Start";
xywh 250 38 44 12;cc speed trackbar tbs_both tbs_noticks leftmove rightmove;
xywh 250 27 44 10;cc s1 static leftmove rightmove;cn "Speed";
xywh 250 69 44 12;cc count trackbar tbs_both tbs_noticks leftmove rightmove;
xywh 250 58 44 10;cc s2 static leftmove rightmove;cn "Count";
xywh 250 100 44 12;cc range trackbar tbs_both tbs_noticks leftmove rightmove;
xywh 250 89 44 10;cc s3 static leftmove rightmove;cn "Range";
xywh 4 4 240 160;cc plot isigraph rightmove bottommove;
pas 4 4;pcenter;
rem form end;
)

f_run=: 3 : 0
  if. IFJAVA do. F=: F rplc 'tbs_noticks ';'' end.
  wd F
  plot=: conew 'jzplot'             NB. create plot object
  PForm__plot=: 'f'                 NB. define PForm in loc
  PFormhwnd__plot=: wd 'qhwndp'     NB. define PFormhwnd in loc
  PId__plot=: 'plot'                NB. define PId in loc

  init''
  show''
  wd 'set speed 0 5 10 2 1'
  wd 'set count 0 5 10 2 1'
  wd 'set range 0 5 10 2 1'
  wd 'pshow;'
)

f_close=: 3 : 0
  wd 'timer 0'
  destroy__plot''
  wd'pclose'
)

f_plot_paint=: 3 : 0
  pd__plot 'show'
)

Data model Download script: rtplot.ijs

'COUNT RANGE DELAY'=: 100 100 100
init=: 3 : 0
  ON=: 0
  DATA=: ?.COUNT#RANGE
)

update=: 3 : 0
  DATA=: (}.DATA),?RANGE
)

show=: 3 : 0
  plot__plot DATA
)

Event handling Download script: rtplot.ijs

f_toggle_button=: 3 : 0
  ON=: -.ON
  wd 'timer ',":DELAY*ON
  wd 'setcaption toggle ',ON{::;:'Start Stop'
)

f_speed_button=: 3 : 0
  DELAY=: 1+20*10-0".speed
  wd 'timer ',":DELAY*ON
)

f_count_button=: 3 : 0
  COUNT=: 2+20*0".count
  DATA=: COUNT{.DATA
)

f_range_button=: 3 : 0
  RANGE=: 2+20*0".range
)

sys_timer=: 3 : 0
  update''
  show''
)

Global definitions Download script: rtplot.ijs

sys_timer_z_=: sys_timer_prtplot_
rtplot_z_=: f_run_prtplot_

Note 'Run'
  rtplot''
)


Contributed by Oleg Kobchenko