Skip to content

Commit

Permalink
ADDED: cliopatria:bag_shape/3 hook that allows for controlling bags of
Browse files Browse the repository at this point in the history
resources in the context graph.
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Apr 17, 2015
1 parent b5ce9f9 commit b38ac34
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
16 changes: 14 additions & 2 deletions applications/browse.pl
Expand Up @@ -1692,12 +1692,14 @@
wrap_url(resource_link),
graph_attributes([ rankdir('RL')
]),
shape_hook(shape(URI, GraphOption))
shape_hook(shape(URI, GraphOption)),
bag_shape_hook(bag_shape(GraphOption))
])
]).

:- public
shape/4.
shape/4,
bag_shape/3.

%% shape(+Start, +Options, +URI, -Shape) is semidet.
%
Expand All @@ -1709,6 +1711,16 @@
shape(Start, _Options, Start,
[ shape(tripleoctagon),style(filled),fillcolor('#ff85fd'),id(start) ]).

%% bag_shape(+Options, +Members, -Shape) is semidet.
%
% Compute properties for a bag

bag_shape(Options, Members, Shape) :-
cliopatria:bag_shape(Members, Shape, Options), !.
bag_shape(_, _, []).



%% context_graph(+URI, -Triples, +Options) is det.
%
% Triples is a graph that describes the environment of URI.
Expand Down
1 change: 1 addition & 0 deletions components/graphviz.pl
Expand Up @@ -156,6 +156,7 @@

is_meta(wrap_url).
is_meta(shape_hook).
is_meta(bag_shape_hook).

has_graphviz_renderer(Renderer) :-
process:exe_options(ExeOptions),
Expand Down
18 changes: 17 additions & 1 deletion hooks.pl
Expand Up @@ -85,7 +85,8 @@
context_graph/2, % +R, -RDF
context_graph/3, % +R, -RDF, +Options
context_predicate/2, % +R, -Pred
node_shape/3. % +R, -Shape, +Options
node_shape/3, % +R, -Shape, +Options
bag_shape/3. % +Members, -Shape, +Options


/*******************************
Expand Down Expand Up @@ -269,3 +270,18 @@
% context node for the resource StartURI.
% @see http://www.graphviz.org/doc/info/shapes.html

%% node_shape(+Bag, -Shape, +Options) is semidet.
%
% Compute the desired properties for a table used to display a bag
% of resources. Shape options include:
%
% - max(Max)
% Only show the first Max members of the bag. Default is 5.
% - shape(Shape)
% Basic shape
% - style(Style)
% Style options
% - max_label_length(Chars)
% Truncate labels that have more then Chars characters.
%
% @param Bag is a list of member resources
34 changes: 28 additions & 6 deletions lib/semweb/rdf_graphviz.pl
Expand Up @@ -3,8 +3,8 @@
Author: Jan Wielemaker
E-mail: J.Wielemaker@cs.vu.nl
WWW: http://www.swi-prolog.org
Copyright (C): 2007-2010, University of Amsterdam,
VU University Amsterdam
Copyright (C): 2007-2015, University of Amsterdam,
VU University Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -98,6 +98,11 @@
% Shape). Shape is a list of Name(Value) terms. See
% shape/3.
%
% * bag_shape_hook(:Goal)
% Called to define the shape parameters for a bag (Table).
% called as call(Goal, Members, Shape) Shape is a list of
% Name(Value) terms.
%
% * label_hook(:Goal)
% Called to define the label of a resource as call(Goal, URI,
% Language, MaxLength, Label). Label is an atom.
Expand Down Expand Up @@ -126,6 +131,7 @@

is_meta(wrap_url).
is_meta(shape_hook).
is_meta(bag_shape_hook).
is_meta(label_hook).

%% write_graph_attributes(+List, +Out)
Expand Down Expand Up @@ -248,15 +254,20 @@
get_assoc(R, Bags, Members), !,
Members = [First|_],
shape(First, MemberShape0, Options),
bag_shape(Members, BagShape0, Options),
exclude(no_bag_option, MemberShape0, MemberShape),
option(bags(merge(BagShape, Max)), Options,
option(bags(merge(BagShape1, Max0)), Options,
merge([ shape(box),
style('rounded,filled,bold'),
fillcolor('#ffff80')
], 5)),
merge_options(BagShape, MemberShape, Shape),
bag_label(Members, Max, Label, Options),
write_attributes([html(Label)|Shape], Stream).
select_option(max(Max), BagShape0, BagShape2, Max0),
partition(label_option, BagShape2, LabelOptions0, BagShape2a),
merge_options(BagShape1, MemberShape, BagShape3),
merge_options(BagShape2a, BagShape3, BagShape),
merge_options(LabelOptions0, Options, LabelOptions),
bag_label(Members, Max, Label, LabelOptions),
write_attributes([html(Label)|BagShape], Stream).
write_node_attributes(R, Stream, Options) :-
rdf_is_resource(R), !,
shape(R, Shape, Options),
Expand Down Expand Up @@ -292,6 +303,8 @@
no_bag_option(label(_)).
no_bag_option(border(_)).

label_option(max_label_length(_)).

%% bag_label(+Members, +Max, -Label, +Options) is det.
%
% Create an HTML description for describing a bag of objects.
Expand Down Expand Up @@ -523,6 +536,15 @@
wrap_url(URL, URL, _).


%% bag_shape(+Members, -BagShape, +Options) is det.
%
% Compute parameters for a bag of resources.

bag_shape(Members, Shape, Options) :-
option(bag_shape_hook(Hook), Options),
call(Hook, Members, Shape), !.
bag_shape(_, [], _).

%% shape(+Resource, -Attributes, +Options) is det.
%
% Shape is the shape of the node to use for Resource. Shapes
Expand Down

0 comments on commit b38ac34

Please sign in to comment.