Skip to content

Commit

Permalink
Fix indent of dot graph
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Apr 10, 2024
1 parent 44b72ee commit 3846fe3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
13 changes: 6 additions & 7 deletions lib/diver_down/web/definition_to_dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,11 @@ def insert_modules(source)
module_names = all_module_names
module_name = module_names[-1]

io.puts %(#{' ' unless head_module_indexes.empty?}subgraph "#{module_label(module_name)}" {), indent: false
io.puts %(subgraph "#{module_label(module_name)}" {)
io.indented do
module_attributes = build_attributes(label: module_name, id: @metadata_store.issue_modules_id(module_names), _wrap: false)
source_attributes = build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))

io.puts %(#{module_attributes} "#{source.source_name}" #{source_attributes})
io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
io.puts %(label="#{module_name}")
io.puts %("#{source.source_name}" #{build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))})
end
io.puts '}'
end
Expand All @@ -241,8 +240,8 @@ def insert_modules(source)

io.puts %(subgraph "#{module_label(module_name)}" {)
io.indented do
attributes = build_attributes(label: module_name, id: @metadata_store.issue_modules_id(module_names), _wrap: false)
io.write attributes
io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
io.puts %(label="#{module_name}")
next_writer.call
end
io.puts '}'
Expand Down
33 changes: 24 additions & 9 deletions spec/diver_down/web/definition_to_dot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ def build_definition(title: 'title', sources: [])
expect(instance.to_s).to eq(<<~DOT)
strict digraph "title" {
subgraph "cluster_A" {
label="A" id="graph_1" subgraph "cluster_B" {
label="B" id="graph_2" "a.rb" [label="a.rb" id="graph_3"]
id="graph_1"
label="A"
subgraph "cluster_B" {
id="graph_2"
label="B"
"a.rb" [label="a.rb" id="graph_3"]
}
}
}
Expand Down Expand Up @@ -199,14 +203,20 @@ def build_definition(title: 'title', sources: [])
strict digraph "title" {
compound=true
subgraph "cluster_A" {
label="A" id="graph_1" "a.rb" [label="a.rb" id="graph_2"]
id="graph_1"
label="A"
"a.rb" [label="a.rb" id="graph_2"]
}
"a.rb" -> "b.rb" [id="graph_3" ltail="cluster_A" lhead="cluster_B" minlen="3"]
subgraph "cluster_B" {
label="B" id="graph_4" "b.rb" [label="b.rb" id="graph_5"]
id="graph_4"
label="B"
"b.rb" [label="b.rb" id="graph_5"]
}
subgraph "cluster_B" {
label="B" id="graph_6" "c.rb" [label="c.rb" id="graph_7"]
id="graph_6"
label="B"
"c.rb" [label="c.rb" id="graph_7"]
}
}
DOT
Expand Down Expand Up @@ -318,14 +328,20 @@ def build_definition(title: 'title', sources: [])
strict digraph "title" {
compound=true
subgraph "cluster_A" {
label="A" id="graph_1" "a.rb" [label="a.rb" id="graph_2"]
id="graph_1"
label="A"
"a.rb" [label="a.rb" id="graph_2"]
}
"a.rb" -> "b.rb" [id="graph_3" ltail="cluster_A" lhead="cluster_B" minlen="3"]
subgraph "cluster_B" {
label="B" id="graph_4" "b.rb" [label="b.rb" id="graph_5"]
id="graph_4"
label="B"
"b.rb" [label="b.rb" id="graph_5"]
}
subgraph "cluster_B" {
label="B" id="graph_6" "c.rb" [label="c.rb" id="graph_7"]
id="graph_6"
label="B"
"c.rb" [label="c.rb" id="graph_7"]
}
}
DOT
Expand Down Expand Up @@ -404,7 +420,6 @@ def build_definition(title: 'title', sources: [])
)
end


it 'returns concentrate digraph if concentrate = true' do
definition = build_definition(
sources: [
Expand Down

0 comments on commit 3846fe3

Please sign in to comment.