Class: Build::Dependency::Visualization

Inherits:
Object
  • Object
show all
Defined in:
lib/build/dependency/visualization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVisualization

Returns a new instance of Visualization.



26
27
28
29
30
31
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
# File 'lib/build/dependency/visualization.rb', line 26

def initialize
	@base_attributes = {
		:shape => 'box',
		:style => 'filled',
		:fillcolor => 'white',
		:fontname => 'Monaco',
	}
	
	@provision_attributes = @base_attributes.dup
	
	@alias_attributes = @base_attributes.merge(
		:fillcolor => 'lightgrey',
	)
	
	@dependency_attributes = @base_attributes.merge(
		:fillcolor => 'orange',
	)
	
	@selection_attributes = {
		:fillcolor => 'lightbrown',
	}
	
	@private_edge_attributes = {
		:arrowhead => 'empty',
		:color => '#0000005f'
	}
	
	@provider_attributes = {
		:fillcolor => 'lightblue',
	}
	
	@provider_edge_attributes = {
		:arrowhead => 'none',
	}
end

Instance Attribute Details

#alias_attributesObject (readonly)

Returns the value of attribute alias_attributes.



68
69
70
# File 'lib/build/dependency/visualization.rb', line 68

def alias_attributes
  @alias_attributes
end

#base_attributesObject (readonly)

Returns the value of attribute base_attributes.



62
63
64
# File 'lib/build/dependency/visualization.rb', line 62

def base_attributes
  @base_attributes
end

#dependency_attributesObject (readonly)

Returns the value of attribute dependency_attributes.



70
71
72
# File 'lib/build/dependency/visualization.rb', line 70

def dependency_attributes
  @dependency_attributes
end

#private_edge_attributesObject (readonly)

Returns the value of attribute private_edge_attributes.



72
73
74
# File 'lib/build/dependency/visualization.rb', line 72

def private_edge_attributes
  @private_edge_attributes
end

#provider_attributesObject (readonly)

Returns the value of attribute provider_attributes.



65
66
67
# File 'lib/build/dependency/visualization.rb', line 65

def provider_attributes
  @provider_attributes
end

#provider_edge_attributesObject (readonly)

Returns the value of attribute provider_edge_attributes.



66
67
68
# File 'lib/build/dependency/visualization.rb', line 66

def provider_edge_attributes
  @provider_edge_attributes
end

#provision_attributesObject (readonly)

Returns the value of attribute provision_attributes.



63
64
65
# File 'lib/build/dependency/visualization.rb', line 63

def provision_attributes
  @provision_attributes
end

#selection_attributesObject (readonly)

Returns the value of attribute selection_attributes.



71
72
73
# File 'lib/build/dependency/visualization.rb', line 71

def selection_attributes
  @selection_attributes
end

Instance Method Details

#generate(chain) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/build/dependency/visualization.rb', line 74

def generate(chain)
	graph = Graphviz::Graph.new
	graph.attributes[:ratio] = :auto
	
	dependencies = dependencies_by_name(chain.dependencies)
	
	chain.ordered.each do |resolution|
		provider = resolution.provider
		name = provider.name
		
		# Provider is the dependency that provides the dependency referred to by name.
		node = graph.add_node(name.to_s, @base_attributes.dup)
		
		if dependencies.include?(resolution.dependency.name)
			node.attributes.update(@dependency_attributes)
		elsif chain.selection.include?(provider.name)
			node.attributes.update(@selection_attributes)
		end
		
		# A provision has dependencies...
		provider.dependencies.each do |dependency|
			if dependency_node = graph.nodes[dependency.name.to_s]
				edge = node.connect(dependency_node)
				
				if dependency.private?
					edge.attributes.update(@private_edge_attributes)
				end
			end
		end
		
		# A provision provides other provisions...
		provider.provisions.each do |provision_name, provision|
			next if name == provision_name
			
			provides_node = graph.nodes[provision_name.to_s] || graph.add_node(provision_name.to_s, @provision_attributes)
			
			if provision.alias?
				provides_node.attributes = @alias_attributes
			end
			
			node.attributes.update(@provider_attributes)
			
			unless provides_node.connected?(node)
				edge = provides_node.connect(node)
				
				edge.attributes.update(@provider_edge_attributes)
			end
		end
	end
	
	chain.provisions.each do |provision|
		node = graph.nodes[provision.name.to_s]
		
		node.attributes.update(penwidth: 2.0)
	end
	
	# Put all dependencies at the same level so as to not make the graph too confusingraph.
	done = Set.new
	chain.ordered.each do |resolution|
		provider = resolution.provider
		name = "subgraph-#{provider.name}"
		
		subgraph = graph.nodes[name] || graph.add_subgraph(name, :rank => :same)
		
		provider.dependencies.each do |dependency|
			next if done.include? dependency
			
			done << dependency
			
			if dependency_node = graph.nodes[dependency.name.to_s]
				subgraph.add_node(dependency_node.name)
			end
		end
	end
	
	return graph
end