Class: GraphVizML
- Inherits:
-
Object
- Object
- GraphVizML
- Defined in:
- lib/graphvizml.rb
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
-
#fill ⇒ Object
Returns the value of attribute fill.
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#stroke ⇒ Object
Returns the value of attribute stroke.
-
#text_color ⇒ Object
Returns the value of attribute text_color.
Instance Method Summary collapse
- #import(obj) ⇒ Object
-
#initialize(obj = nil, debug: false, fill: 'transparent', stroke: '#000', text_color: '#000') ⇒ GraphVizML
constructor
A new instance of GraphVizML.
- #to_dot ⇒ Object
-
#to_svg ⇒ Object
returns an SVG blob.
Constructor Details
#initialize(obj = nil, debug: false, fill: 'transparent', stroke: '#000', text_color: '#000') ⇒ GraphVizML
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/graphvizml.rb', line 32 def initialize(obj=nil, debug: false, fill: 'transparent', stroke: '#000', text_color: '#000') @debug = debug @fill, @stroke, @text_color = fill, stroke, text_color if obj then xml = if obj.is_a? Rexle or obj.is_a? Rexle::Element obj.xml else s = RXFHelper.read(obj).first if s =~ /<\?graphvizml\b/ then import_string s else if @debug then #File.write '/tmp/graphviz.xml', xml puts('graphvizml xml: ' + s.inspect) end s end end @g = build_from_nodes Domle.new(xml) end @css = " .node ellipse {stroke: #{stroke}; fill: #{fill}} .node text {fill: #{text_color}} .edge path {stroke: #{stroke}} .edge polygon {stroke: #{stroke}; fill: #{stroke}} " end |
Instance Attribute Details
#css ⇒ Object
Returns the value of attribute css.
29 30 31 |
# File 'lib/graphvizml.rb', line 29 def css @css end |
#fill ⇒ Object
Returns the value of attribute fill.
29 30 31 |
# File 'lib/graphvizml.rb', line 29 def fill @fill end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
30 31 32 |
# File 'lib/graphvizml.rb', line 30 def g @g end |
#stroke ⇒ Object
Returns the value of attribute stroke.
29 30 31 |
# File 'lib/graphvizml.rb', line 29 def stroke @stroke end |
#text_color ⇒ Object
Returns the value of attribute text_color.
29 30 31 |
# File 'lib/graphvizml.rb', line 29 def text_color @text_color end |
Instance Method Details
#import(obj) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/graphvizml.rb', line 78 def import(obj) s = RXFHelper.read(obj).first xml = import_string s @g = build_from_nodes Domle.new(xml) self end |
#to_dot ⇒ Object
88 89 90 |
# File 'lib/graphvizml.rb', line 88 def to_dot() @g.to_dot end |
#to_svg ⇒ Object
returns an SVG blob
95 96 97 98 99 100 101 |
# File 'lib/graphvizml.rb', line 95 def to_svg() f = Tempfile.new('graphvizml') Graphviz::output(@g, format: 'svg', path: f.path) s = File.read f.path s.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','') s.lines.insert(8, css_code()).join end |