Module: Draw
- Included in:
- Gviz
- Defined in:
- lib/gviz/draw.rb
Overview
Draw module includes a set of methods for specific shapes. Each methods defines with shape name and its positions.
Instance Method Summary collapse
-
#circle(id, x: 0, y: 0, r: 0.5, **attrs) ⇒ Object
Define a node with circle shape.
-
#ellipse(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with ellipse shape.
-
#line(id, from: [0,0], **attrs) ⇒ Object
Define a line with an edge and two point nodes.
-
#point(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with point shape.
-
#square(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with square shape.
Instance Method Details
#circle(id, x: 0, y: 0, r: 0.5, **attrs) ⇒ Object
Define a node with circle shape.
13 14 15 16 |
# File 'lib/gviz/draw.rb', line 13 def circle(id, x:0, y:0, r:0.5, **attrs) attrs.update(width:r*2, height:r*2) ellipse(id, x:x, y:y, **attrs) end |
#ellipse(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with ellipse shape.
5 6 7 8 9 10 |
# File 'lib/gviz/draw.rb', line 5 def ellipse(id, x:0, y:0, **attrs) draw_init attrs = {label:"", color:"black", fillcolor:"#FFFFFF00"}.merge(attrs) attrs.update(shape:"ellipse", pos:"#{x},#{y}!") node(id, attrs) end |
#line(id, from: [0,0], **attrs) ⇒ Object
Define a line with an edge and two point nodes.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gviz/draw.rb', line 34 def line(id, from:[0,0], **attrs) draw_init unless to = attrs.delete(:to) raise ArgumentError, "Argument 'to' is required" end n1_id, n2_id = [1, 2].map { |i| "#{id}#{i}".to_id } point(n1_id, x:from[0], y:from[1], color:"#FFFFFF00", fillcolor:"#FFFFFF00") point(n2_id, x:to[0], y:to[1], color:"#FFFFFF00", fillcolor:"#FFFFFF00") attrs.update(arrowhead:"none") edge(:"#{n1_id}_#{n2_id}", attrs) end |
#point(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with point shape.
27 28 29 30 31 |
# File 'lib/gviz/draw.rb', line 27 def point(id, x:0, y:0, **attrs) draw_init attrs.update(shape:"point", pos:"#{x},#{y}!") node(id, attrs) end |
#square(id, x: 0, y: 0, **attrs) ⇒ Object
Define a node with square shape.
19 20 21 22 23 24 |
# File 'lib/gviz/draw.rb', line 19 def square(id, x:0, y:0, **attrs) w, h = %i(width height).map { |at| attrs.delete at } size = w || h || 1 attrs.update(width:size, height:size) rect(id, x:x, y:y, **attrs) end |