diff --git a/lib/mosaik/command.rb b/lib/mosaik/command.rb index 56c0fa6..17f25d4 100644 --- a/lib/mosaik/command.rb +++ b/lib/mosaik/command.rb @@ -17,8 +17,8 @@ class Graph < Command defaults file: "mosaik.csv", visualize: false, renderer: "dot", - hide_uncoupled: false, - hide_labels: false, + show_uncoupled: false, + show_labels: false, reduce: false argument "--file FILE", "File for the dependency graph (default: #{defaults[:file]})" @@ -26,8 +26,8 @@ class Graph < Command argument "--visualize", "Enable graph visualization (default: #{defaults[:visualize]})" argument "--renderer RENDERER", "Graph renderer: dot, fdp, sfdp, or neato (default: #{defaults[:renderer]})" - argument("--hide-uncoupled", "Hide uncoupled vertices in the graph (default: #{defaults[:hide_uncoupled]})") { |arg| !arg.nil? } - argument("--hide-labels", "Hide labels in the graph (default: #{defaults[:hide_labels]})") { |arg| !arg.nil? } + argument("--show-uncoupled", "Show uncoupled vertices in the graph (default: #{defaults[:show_uncoupled]})") { |arg| !arg.nil? } + argument("--show-labels", "Show labels in the graph (default: #{defaults[:show_labels]})") { |arg| !arg.nil? } argument "--reduce", "Reduce the graph before visualization (default: #{defaults[:reduce]})" diff --git a/lib/mosaik/graph/visualizer.rb b/lib/mosaik/graph/visualizer.rb index a632564..9b691ad 100644 --- a/lib/mosaik/graph/visualizer.rb +++ b/lib/mosaik/graph/visualizer.rb @@ -36,7 +36,7 @@ def to_dot .clusters .values .filter_map do |cluster| - next if (cluster.vertices.empty? || cluster.vertices.all? { |vertex| vertex.edges.empty? }) && options[:hide_uncoupled] + next if options[:show_uncoupled] || (cluster.vertices.empty? || cluster.vertices.all? { |vertex| vertex.edges.empty? }) [ "subgraph \"#{cluster.id}\" {", @@ -53,7 +53,7 @@ def to_dot .values .map do |vertex| [ - ("\"#{vertex.id}\" [shape=circle, width=1, fixedsize=true, fontsize=12, style=filled, fillcolor=lightblue]" if vertex.in?(coupled_vertices) || !options[:hide_uncoupled]), + ("\"#{vertex.id}\" [shape=circle, width=1, fixedsize=true, fontsize=12, style=filled, fillcolor=lightblue]" if options[:show_uncoupled] || vertex.in?(coupled_vertices)), *vertex .edges .flat_map do |key, edges| @@ -66,7 +66,7 @@ def to_dot "\"#{vertex.id}\" ", graph.directed? ? "->" : "--", " \"#{key}\"", - edge.attributes.any? && !options[:hide_labels] ? " [label=\"#{edge.attributes.map { |ek, ev| "#{ek}: #{ev}" }.join(', ')}\"]" : nil, + options[:show_labels] && edge.attributes.any? ? " [label=\"#{edge.attributes.map { |ek, ev| "#{ek}: #{ev}" }.join(', ')}\"]" : nil, ].compact.join end end, diff --git a/spec/mosaik/graph/visualizer_spec.rb b/spec/mosaik/graph/visualizer_spec.rb index dff761e..e913288 100644 --- a/spec/mosaik/graph/visualizer_spec.rb +++ b/spec/mosaik/graph/visualizer_spec.rb @@ -3,7 +3,7 @@ RSpec.describe MOSAIK::Graph::Visualizer do subject(:visualizer) { described_class.new(options, graph) } - let(:options) { {} } + let(:options) { { show_uncoupled: true, show_labels: true } } let(:graph) { build(:graph) } describe "#to_dot" do @@ -111,7 +111,7 @@ end context "when uncoupled vertices are hidden" do - let(:options) { { hide_uncoupled: true } } + let(:options) { { show_uncoupled: false } } it "returns the graph in DOT format" do graph.add_vertex("vertex1") @@ -130,7 +130,7 @@ end context "when labels are hidden" do - let(:options) { { hide_labels: true } } + let(:options) { { show_labels: false } } it "returns the graph in DOT format" do graph.add_vertex("vertex1")