Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Extract visualization to superclass
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Apr 20, 2024
1 parent a4501b4 commit 9bf4281
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 38 deletions.
19 changes: 19 additions & 0 deletions lib/mosaik/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ class Graph < Command
def validate
raise OptionError, "unknown renderer: #{options[:renderer]}" unless options[:renderer].in? ["dot", "fdp", "sfdp", "neato"]
end

protected

def visualize
# Write graph to file
File.write(options[:file], graph.to_csv)

info "Dependency graph written to #{options[:file]}"

return unless options[:visualize]

file = File.basename(options[:file], ".*")

# Write visualization to file
debug graph.to_dot(options)
graph.to_svg(file, options)

info "Dependency graph written to #{file}.gv and rendered to #{file}.svg"
end
end
end
end
15 changes: 3 additions & 12 deletions lib/mosaik/commands/evaluate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ def call
debug "Components: #{cluster.vertices.map(&:id).join(', ')}"
end

file = "#{File.basename(options[:file], '.*')}-evaluation"
# Change file name
options[:file] = "#{File.basename(options[:file], '.*')}-evaluation"

# Write graph to file
File.write("#{file}.csv", graph.to_csv)

info "Dependency graph written to #{options[:file]}"

return unless options[:visualize]

# Write visualization to file
debug graph.to_dot(options)
graph.to_png(file, options)

info "Evaluated microservice candidate graph written to #{file}.gv and rendered to #{file}.png"
visualize
end

private
Expand Down
16 changes: 2 additions & 14 deletions lib/mosaik/commands/extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,8 @@ def call
.tap(&:validate)
.call

# Write graph to file
File.write(options[:file], graph.to_csv)

info "Dependency graph written to #{options[:file]}"

return unless options[:visualize]

file = File.basename(options[:file], ".*")

# Write visualization to file
debug graph.to_dot(options)
graph.to_svg(file, options)

info "Dependency graph written to #{file}.gv and rendered to #{file}.svg"
# Write graph to file(s)
visualize
end

private
Expand Down
15 changes: 3 additions & 12 deletions lib/mosaik/commands/identify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,11 @@ def call
end
end

file = "#{File.basename(options[:file], '.*')}-candidates"
# Change file name
options[:file] = "#{File.basename(options[:file], '.*')}-candidates"

# Write graph to file
File.write("#{file}.csv", graph.to_csv)

info "Dependency graph written to #{options[:file]}"

return unless options[:visualize]

# Write visualization to file
debug graph.to_dot(options)
graph.to_svg(file, options)

info "Microservice candidate graph written to #{file}.gv and rendered to #{file}.svg"
visualize
end

private
Expand Down

0 comments on commit 9bf4281

Please sign in to comment.