Class: NetworkDrawer::Element::Layer

Inherits:
NetworkDrawer::Element show all
Defined in:
lib/network_drawer/element/layer.rb

Overview

Replesent of layer

Constant Summary collapse

DEFAULT_STYLE =
{ fontname: 'Helvetica' }

Instance Method Summary collapse

Constructor Details

#initialize(initial_values = {}, style = {}) ⇒ Layer

Returns a new instance of Layer.



9
10
11
12
# File 'lib/network_drawer/element/layer.rb', line 9

def initialize(initial_values = {}, style = {})
  super
  @default_style = DEFAULT_STYLE
end

Instance Method Details

#to_codeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/network_drawer/element/layer.rb', line 14

def to_code
  style = style(self.type).dup
  style.merge!(self.to_hash)
  style.delete(:layers)
  style.delete(:nodes)
  style.delete(:connections)
  label = self.name unless Diagram::TOP_LAYER == self.name

  node_code = ''
  nodes.each { |n| node_code += n.to_code + "\n" } if nodes
  layer_code = ''
  layers.each { |l| layer_code += l.to_code + "\n" } if layers

  code = ''
  if Diagram::TOP_LAYER == self.name
    code = <<-EOF
      global(#{style})
      #{node_code}
      #{layer_code}
    EOF
  else
    code = <<-EOF
      subgraph "cluster_#{self.name}" do
        global label: "#{label}"
        global(#{style})
        #{node_code}
        #{layer_code}
      end
    EOF
  end
  code
end