% blah
svg_debug:-
svg('debug.svg',no,[history,exp,grid]).
svg_history:-
svg('history.svg',anim(4),[history,grid]).
svg(OutFile,Anim,Options):-
open(OutFile,write,Stream),
write(Stream,''), nl(Stream),
write(Stream,''), nl(Stream),
write(Stream,''),
close(Stream).
maxtime([#(h(_,T),_)],T).
maxtime([#(h(_,T),_)|L],TM):-
maxtime(L,TM1),
(TM1 > T -> TM=TM1 ; TM=T).
svg_list(_,[],_,_,_,_).
svg_list(S,[#(h(A,Texp),_)|L],Max,anim(Sec),X1,Options):-
%X2 is X1 + 10,
X2 is X1,
write(S,'H('),
write(S,A),
write(S,','),
write(S,Texp),
write(S,')'),
write(S,''),
write(S,''), nl(S),
rectangle(S,X1,X2,Tmin1,Tmax1,green),
nl(S),
svg_list(S,L,Max,anim(Sec),X2,Options).
svg_list(S,[#(e(A,Texp),_)|L],Max,anim(Sec),X1,Options):-
X0 is X1 - 10,
X2 is X1 + 10,
%X2 is X1,
write(S,'E('),
write(S,A),
write(S,','),
write(S,Texp),
write(S,')'),
%T2 is T*Sec/Max,
%write(S,''),
write(S,''), nl(S),
triangle(S,X0,X2,Tmin1,Tmax1,T1,green),
nl(S),
svg_list(S,L,Max,anim(Sec),X1,Options).
svg_list(S,[#(Atom,_)|L],Max,no,Y1,Options):-
Atom =.. [F,A,Texp],
atom_color(F,Col),
Y2 is Y1 + 20,
Y0 is Y1-20,
(member(grid,Options) -> line(S,0,1000,Y1,Y1,lightgray); true),
write(S,''),
write(S,F),
write(S,'('),
write(S,A),
write(S,','),
write(S,Texp),
write(S,')'),
%write(S,''),
write(S,''), nl(S),
(Tmin1=Tmax1 -> Tmax2 is Tmin1+1; Tmax2 = Tmax1),
fd_dom(Texp,Dom),
dom_rectangle(S,Dom,400,1000,Max,Y0,Y1,Col),
% rectangle(S,Tmin1,Tmax2,Y0,Y1,Col),
nl(S),
svg_list(S,L,Max,no,Y2,Options).
animated_bar(S,anim(Sec)):-
write(S,''),nl(S),
write(S,''),nl(S),
write(S,''), nl(S).
rectangle(S,X1,X2,Y1,Y2,Col):-
write(S,''),nl(S),
% write(S,''),nl(S),
write(S,''), nl(S).
line(S,X1,X2,Y1,Y2,Col):-
write(S,''),nl(S).
atom_color(h,blue).
atom_color(e,green).
dom_rectangle(S,{Dom},Xmin,Xmax,Max,Y0,Y1,Col):-
X is Dom*(Xmax-Xmin)/Max+Xmin,
X1 is X+1,
rectangle(S,X,X1,Y0,Y1,Col).
dom_rectangle(S,A..B,Xmin,Xmax,Max,Y0,Y1,Col):-
X1 is A*(Xmax-Xmin)/Max+Xmin,
X2 is B*(Xmax-Xmin)/Max+Xmin,
rectangle(S,X1,X2,Y0,Y1,Col).
dom_rectangle(S,A\/B,Xmin,Xmax,Max,Y0,Y1,Col):-
dom_rectangle(S,A,Xmin,Xmax,Max,Y0,Y1,Col),
dom_rectangle(S,B,Xmin,Xmax,Max,Y0,Y1,Col).
triangle(S,X1,X2,Tmin1,Tmax1,Texp,Col):-
write(S,''), nl(S).
:- multifile user:debugger_command_hook/2.
user:debugger_command_hook(unknown([115,118,103],_), Actions) :- % Command: svg
Actions = [],
svg('debug.svg',no,[history,exp,grid]).
vert_grid(_,0,_,_):- !.
vert_grid(S,N,Step,Xmin):-
X is N*Step+Xmin,
line(S,X,X,0,1000,lightgray),
write(S,''),
write(S,N), write(S,''), nl(S),
N1 is N-1,
vert_grid(S,N1,Step,Xmin).