:- module(tag_cloud, [ html_tag_cloud//2 ]). :- use_module(library(http/http_dispatch)). :- use_module(library(http/html_write)). :- use_module(library(yaz_util)). %% html_tag_cloud(+Pairs:count-tag, +Options) % % Emit an HTML tag cloud. html_tag_cloud([], _) --> !. html_tag_cloud(Tags, Options) --> { maplist(tag_term_pair, Tags, TagsByLabel), keysort(TagsByLabel, Sorted), pairs_values(Sorted, TagTerms), pairs_keys(Tags, Counts), max_list(Counts, Max), min_list(Counts, Min) }, html_tag_cloud(TagTerms, Min, Max, Options). html_tag_cloud([], _, _, _) --> !. html_tag_cloud([tag(_Term, Label, Count)|T], Min, Max, Options) --> { http_link_to_id(isearch_page, [q(Label)|Options], Link), Size0 is (log((20*max((Count-Min),1)) / max((Max-Min),5))) * 10, Size is max(10, Size0) }, html([' ', a([title(Count), href(Link), style('font-size:'+Size+'px')], Label), ' ']), html_tag_cloud(T, Min, Max, Options). tag_term_pair(Count-Tag, Label-tag(Term, Label, Count)) :- tag_term_label(Tag, Term, Label).