1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889typet={mutablelayout:Layout.t;mutablewidth:float;(* Canvas width in pixels *)mutableheight:float;mutablestart_time:float;(* Time after layout start (ns) *)mutablescroll_y:float;(* Pixels *)mutablepixels_per_ns:float;mutablezoom:float;}leth_margin=4.letv_margin=4.letpixels_per_row=32.letclamp~min:a~max:b(v:float)=maxa(minbv)letx_of_timettime=letx=(time-.t.start_time)*.t.pixels_per_nsinclampx~min:(-.100.)~max:(t.width+.100.)lettime_of_xtx=x/.t.pixels_per_ns+.t.start_timeletwidth_of_timespantts=ts*.t.pixels_per_nslettimespan_of_widthtx=x/.t.pixels_per_nsletgridtx=letgrid_step=(* ns per grid step *)letl=2.5-.log10t.pixels_per_ns|>floorin10.**linletstarting_grid_line=floor(time_of_xtx/.grid_step)inletgrid_step_x=grid_step*.t.pixels_per_nsin(* pixels per grid step *)letgrid_start_x=(starting_grid_line*.grid_step_x)-.t.start_time*.t.pixels_per_nsingrid_step*.1e-9,grid_start_x,grid_step_xletzoom_totz=t.zoom<-clampz~min:(-.15.)~max:2.5;t.pixels_per_ns<-10.**t.zoomletzoomtdelta=zoom_tot(t.zoom+.delta)letset_durationtduration=letppns=(t.width-.2.*.h_margin)/.durationinzoom_tot(logppns/.log10.)letget_durationt=(t.width-.2.*.h_margin)/.t.pixels_per_nsletzoom_to_fit?(start_time=0.0)?durationt=letstart_time=minstart_timet.layout.durationinletduration=Option.valueduration~default:(t.layout.duration-.start_time)inset_durationtduration;t.start_time<-start_time-.timespan_of_widthth_marginletmax_x_scrollt=width_of_timespantt.layout.duration+.h_marginletmax_y_scrollt=floatt.layout.height*.pixels_per_row+.v_marginletscroll_boundst=((-.h_margin,max_x_scrollt+.t.width,t.width,t.start_time*.t.pixels_per_ns),(-.v_margin,max_y_scrollt+.t.height,t.height,t.scroll_y))letset_start_timettime=letmargin_time=timespan_of_widthth_marginint.start_time<-clamptime~min:(-.margin_time)~max:(t.layout.duration+.margin_time);t.start_time*.t.pixels_per_nsletset_scroll_yty=t.scroll_y<-clampy~min:(-.v_margin)~max:(max_y_scrollt);yletset_sizetwidthheight=t.width<-width;t.height<-heightletof_layoutlayout~width~height=lett={layout;width;height;start_time=0.;scroll_y=-.v_margin;pixels_per_ns=0.0;zoom=-3.0}inzoomt0.0;tletset_layouttlayout=t.layout<-layout