Desktop

Prolog "chart"

         
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
:- ensure_loaded(library(misc/markup)).
:- ensure_loaded(library(util/sequence)).
:- ensure_loaded(library(tester/plot)).
/*************************************************************/
/* Chart Link */
/*************************************************************/
/**
* chart_link(D, O):
* The predicate succeeds in appending a HTML fragment into the
* directory D. The parameter O is the options list. The report
* generator silently overwrites am already existing HTML page.
*/
% chart_link(+Atom, +List)
chart_link(Dir, Opts) :-
decode_chart_opts(Opts, v(w('',1),w(3,1000),[]), v(w(Locale,_),_,_)),
sys_chart_link(Dir, Locale).
% sys_chart_link(+Atom, +Locale)
sys_chart_link(Dir, L) :-
format_atom('~wpackage.html', [Dir], Name),
setup_once_cleanup(
(open(Name, append, S), dom_output_new(S, T)),
(ir_object_set(S, 'indent', 6),
tag(T, '<h3>'), put_message(T, chart(diagram), L), tag(T, '</h3>'),
tag(T, '<img src="chart.svg" width="500" height="400"/>')),
close(T)).
/*************************************************************/
/* Chart API */
/*************************************************************/
/**
* chart_batch(D, L, O):
* The predicate succeeds in writing SVG summary
* for the tag list L into the directory D. The parameter
* O is the options list. The chart generator silently
* overwrites already existing SVG pages.
*/
% chart_batch(+Atom, +List, +List)
chart_batch(Dir, Tags, Opts) :-
chart_begin(Dir, Opts),
chart_add(Dir, Tags, Opts),
chart_end(Dir, Opts).
/**
* chart_begin(D, O):
* The predicate succeeds in writing a SVG prologue into the directory D.
* The parameter O is the options list. The chart generator silently
* overwrites am already existing SVG page.
*/
% chart_begin(+Atom, +List)
chart_begin(Dir, Opts) :-
decode_chart_opts(Opts, v(w('',1),w(3,1000),[]), v(_,w(MaxX,MaxY),XAxis)),
sys_chart_begin(Dir, MaxX, MaxY, XAxis).
/**
* chart_add(D, L, O):
* The predicate succeeds in appending a SVG summary
* for the tag list L into the directory into the directory D.
* The parameter O is the options list. The chart generator silently
* overwrites already existing SVG pages.
*/
% chart_add(+Atom, +List, +List)
chart_add(Dir, Tags, Opts) :-
decode_chart_opts(Opts, v(w('',1),w(3,1000),[]), v(w(_,Group),w(MaxX,MaxY),_)),
sys_chart_add(Dir, Tags, Group, MaxX, MaxY).
/**
* chart_end(D, O):
* The predicate succeeds in appending a SVG epilogue into the
* directory D. The parameter O is the options list. The chart
* generator silently overwrites am already existing SVG page.
*/
% chart_end(+Atom, +List)
chart_end(Dir, Opts) :-
decode_chart_opts(Opts, v(w('',1),w(3,1000),[]), _),
sys_chart_end(Dir).
/*************************************************************/
/* Chart Page */
/*************************************************************/
% sys_chart_begin(+Atom, +Number, Number, +Map)
sys_chart_begin(Dir, MaxX, MaxY, XAxis) :-
format_atom('~w', [Dir], Dst),
ensure_directory(Dst),
format_atom('~wchart.svg', [Dir], Name),
setup_once_cleanup(
(open(Name, write, S), dom_output_new(S, T)),
plot_begin(T, [css('../../harness/excel.css'), xaxis(XAxis),
minx(0),maxx(MaxX),
miny(0),maxy(MaxY)]),
close(T)).
% sys_chart_add(+Atom, +List, +Integer, +Number, Number)
sys_chart_add(Dir, Tags, Group, MaxX, MaxY) :-
format_atom('~wchart.svg', [Dir], Name),
setup_once_cleanup(
(open(Name, append, S), dom_output_new(S, T)),
(ir_object_set(S, 'indent', 6),
sys_main_chart(Tags, Group, MaxX, MaxY, T)),
close(T)).
% sys_report_end(+Atom)
sys_chart_end(Dir) :-
format_atom('~wchart.svg', [Dir], Name),
setup_once_cleanup(
(open(Name, append, S), dom_output_new(S, T)),
(ir_object_set(S, 'indent', 6),
plot_end(T)),
close(T)).
/*************************************************************/
/* Main Plot */
/*************************************************************/
% sys_main_chart(+List, +Integer, +Number, Number, +Stream)
sys_main_chart(Tags, Group, MaxX, MaxY, T) :-
length(Tags, N),
Offset is (Group-1)*(N+1),
Mark = ['mark','mark2','mark3'|Mark],
findall([X2,Z], (sys_main_data(Tags, X, Z),
X2 is X+Offset), D),
plot_add(T, D,
[render(bars),decor(none),mark(Mark),
minx(0),maxx(MaxX),miny(0),maxy(MaxY)]),
fail.
sys_main_chart(_, _, _, _, _).
% sys_main_data(+List, -Number, -Number)
sys_main_data(Tags, X, Z) :-
call_nth(member(Tag, Tags), N),
X is N-1,
result_summary(Tag, Z).
sys_main_data(Tags, X, 0) :-
length(Tags, X).
/*******************************************************************/
/* Decode Report Options */
/*******************************************************************/
% decode_chart_opts(+List, +Tuple, -Tuple)
decode_chart_opts(V, _, _) :- var(V),
throw(error(instantiation_error,_)).
decode_chart_opts([X|L], I, O) :- !,
decode_chart_opt(X, I, H),
decode_chart_opts(L, H, O).
decode_chart_opts([], H, H) :- !.
decode_chart_opts(L, _, _) :-
throw(error(type_error(list,L),_)).
% decode_chart_opt(+Option, +Tuple, -Tuple)
decode_chart_opt(V, _, _) :- var(V),
throw(error(instantiation_error,_)).
decode_chart_opt(locale(A), v(w(_,Y),Z,T), v(w(A,Y),Z,T)) :- !.
decode_chart_opt(group(B), v(w(X,_),Z,T), v(w(X,B),Z,T)) :- !.
decode_chart_opt(maxx(A), v(X,w(_,Z),T), v(X,w(A,Z),T)) :- !.
decode_chart_opt(maxy(B), v(X,w(Y,_),T), v(X,w(Y,B),T)) :- !.
decode_chart_opt(xaxis(A), v(X,Y,_), v(X,Y,A)) :- !.
decode_chart_opt(O, _, _) :-
throw(error(type_error(report_option,O),_)).
/****************************************************************/
/* Other Texts */
/****************************************************************/
% strings(+Atom, +Atom, -Atom)
:- multifile strings/3.
strings('chart.diagram', de, 'Diagramm').
strings('chart.diagram', '', 'Chart').
Use Privacy (c) 2005-2026 XLOG Technologies AG