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

Commit

Permalink
Hide labels and uncoupled vertices by default
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Apr 24, 2024
1 parent 7e71426 commit 924feca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/mosaik/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ 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]})"

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]})"

Expand Down
6 changes: 3 additions & 3 deletions lib/mosaik/graph/visualizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}\" {",
Expand All @@ -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|
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions spec/mosaik/graph/visualizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 924feca

Please sign in to comment.