Skip to content

proposal: cmd/modgraphviz: Colorize edges for more clear view on large graphs #73879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abdoeid-eg opened this issue May 27, 2025 · 2 comments
Labels
Proposal ToolProposal Issues describing a requested change to a Go tool or command-line program. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@abdoeid-eg
Copy link

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.

Image

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

Image

Is this an acceptable solution to start working on and open a PR with?

@gopherbot gopherbot added this to the Proposal milestone May 27, 2025
@abdoeid-eg
Copy link
Author

abdoeid-eg commented May 27, 2025

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)

@gabyhelp gabyhelp added the ToolProposal Issues describing a requested change to a Go tool or command-line program. label May 27, 2025
@seankhliao
Copy link
Member

does color help when they all blend together as in your original image?

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal ToolProposal Issues describing a requested change to a Go tool or command-line program. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants