1 ! Copyright (C) 2011 Alex Vondrak.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors fry generic generic.parser generic.standard
4 kernel present quotations sequences slots words
14 ! GENERIC# =attr 1 ( graphviz-obj val -- graphviz-obj' )
16 ! present over attributes>> attr<< ;
18 ! <graph-attributes> swap present >>attr add ;
19 ! M: edge/node/graph-attributes =attr
22 : =attr-generic ( name -- generic )
23 "=" prepend "graphviz.notation" 2dup lookup-word
26 1 <standard-combination>
27 ( graphviz-obj val -- graphviz-obj' )
31 : =attr-method ( class name -- method name )
32 [ =attr-generic create-method-in ] keep ;
34 : sub/graph-=attr ( attr -- )
35 [ graph subgraph ] dip [
37 setter-word 1quotation
38 '[ <graph-attributes> swap present @ add ]
42 : edge/node-=attr ( class attr -- )
44 writer-word 1quotation '[ present over attributes>> @ ]
47 : graph-obj-=attr ( class attr -- )
49 [ nip sub/graph-=attr ]
50 [ edge/node-=attr ] if ;
52 : attrs-obj-=attr ( class attr -- )
54 setter-word 1quotation '[ present @ ]
57 : define-=attrs ( base-class attrs-class -- )
58 dup "slots" word-prop [
60 [ attrs-obj-=attr ] keep
66 graph graph-attributes define-=attrs
67 edge edge-attributes define-=attrs
68 node node-attributes define-=attrs
77 ALIAS: [graph <graph-attributes>
78 ALIAS: [node <node-attributes>
79 ALIAS: [edge <edge-attributes>
81 ALIAS: [add-node <node>
82 ALIAS: [add-edge <edge>
88 ! Can't really do add-path[ & add-nodes[ this way, since they
89 ! involve multiple objects.