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
Returns a new instance of GraphVizML.
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 77 |
# File 'lib/graphvizml.rb', line 33 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.
30 31 32 |
# File 'lib/graphvizml.rb', line 30 def css @css end |
#fill ⇒ Object
Returns the value of attribute fill.
30 31 32 |
# File 'lib/graphvizml.rb', line 30 def fill @fill end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
31 32 33 |
# File 'lib/graphvizml.rb', line 31 def g @g end |
#stroke ⇒ Object
Returns the value of attribute stroke.
30 31 32 |
# File 'lib/graphvizml.rb', line 30 def stroke @stroke end |
#text_color ⇒ Object
Returns the value of attribute text_color.
30 31 32 |
# File 'lib/graphvizml.rb', line 30 def text_color @text_color end |
Instance Method Details
#import(obj) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/graphvizml.rb', line 79 def import(obj) s = RXFReader.read(obj).first xml = import_string s puts('graphvizml/import xml: ' + xml.inspect).debug if @debug @g = build_from_nodes Domle.new(xml) self end |
#to_dot ⇒ Object
90 91 92 93 94 |
# File 'lib/graphvizml.rb', line 90 def to_dot() @g.to_dot end |
#to_svg ⇒ Object
returns an SVG blob
99 100 101 102 103 104 105 106 107 |
# File 'lib/graphvizml.rb', line 99 def to_svg() f = Tempfile.new('graphvizml') #jr 26-01-2022 Graphviz::output(@g, format: 'svg', path: f.path) Graphviz.output(@g, path: f.path, format: 'svg') s = File.read f.path #s.sub!('xmlns:xlink="http://www.w3.org/1999/xlink"','') #s.sub!('xlink:','') # not yet implemented because of a local namespace issue s.lines.insert(8, css_code()).join end |