Proposal Details
Problem
Description
When using modgraphiz
on large codebases, it generates edges colored black which makes it very hard to differentiate between edges when they blend in one big edge like the following.
Proposed solution
We can add a color property to the edge struct; we then populate this property with the same color for all nodes that depend on the current node.
Example
Dot Code
digraph gomodgraph {
node [ shape=rectangle fontsize=12 ]
A -> B [color="red"]
A -> C [color="red"]
A -> D [color="red"]
B -> E [color="blue"]
B -> F [color="blue"]
}
Output
Is this an acceptable solution to start working on and open a PR with?
Comment From: abdoeid-eg
I use this python script to do so till this is implemented
import random
def random_color():
# Generate a random hex color
return '#{:06x}'.format(random.randint(0, 0xFFFFFF))
def process_dot_file(input_path, output_path):
color_map = {}
last_key = None
with open(input_path, 'r') as infile, open(output_path, 'w') as outfile:
for line in infile:
stripped = line.rstrip('\n')
# Skip empty lines
if not stripped.strip():
outfile.write(line)
continue
# Skip lines ending with {, }, or ]
if stripped.endswith('{') or stripped.endswith('}') or stripped.endswith(']'):
outfile.write(line)
continue
# Find the key before ' -> '
if '->' in stripped:
key = stripped.split('->', 1)[0].strip()
if key != last_key:
color = random_color()
color_map[key] = color
last_key = key
else:
color = color_map.get(key, random_color())
# Append color attribute
if '[' in stripped:
# Already has attributes, append color
new_line = stripped.rstrip(']') + f', color=\"{color}\"]\n'
else:
new_line = stripped + f' [color=\"{color}\"]\n'
outfile.write(new_line)
else:
outfile.write(line)
if __name__ == "__main__":
import sys
# Usage: python converter.py [input_file] [output_file]
input_file = sys.argv[1] if len(sys.argv) > 1 else "../graph.dot"
output_file = sys.argv[2] if len(sys.argv) > 2 else "../graph_colored.dot"
process_dot_file(input_file, output_file)
Comment From: seankhliao
does color help when they all blend together as in your original image?
Comment From: gopherbot
Timed out in state WaitingForInfo. Closing.
(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)