Making a Legend/Key in GraphViz

前端 未结 6 1425
失恋的感觉
失恋的感觉 2020-12-12 12:28

I’d like to include a legend or key in my GraphViz diagram. I’m having trouble figuring out what code to use, though. I also want to put it in a corner, but the only coord I

6条回答
  •  无人及你
    2020-12-12 13:10

    I'm trying to do the same. I have been using a subgraph to make a key of node types:

    digraph G {
    
        rankdir=RL;
        graph [fontsize=10 fontname="Verdana"];
    
        node [style=filled height=0.55 fontname="Verdana" fontsize=10];
        subgraph cluster_key {
            label="Key";
            progress [fillcolor="wheat" label="In progress"];
            todo [label="To do"];
            done [fillcolor=palegreen3 label="Done"];
            not_our [fillcolor=none label="Not our\nteam"];
            numbers [color=none label="Numbers\nrepresent\nperson\ndays"];
            progress -> done [style=invis];
            todo -> progress [style=invis];
            not_our -> todo [style=invis];
            numbers -> not_our [style=invis];
        }
        mappings [fillcolor=palegreen3];
        identifiers [fillcolor=palegreen3];
        hyperwarp [fillcolor=wheat];
        ghost [fillcolor=none]
        UI [fillcolor=none]
        events [fillcolor=wheat];
        flag [fillcolor=palegreen3];
        groups [fillcolor=wheat];
        types [fillcolor=wheat];
        instances [];
        resources [];
        optimize [];
        remove_flag [];
        persist [];
        approval [];
    
        edge [style="" dir=forward fontname="Verdana" fontsize=10];
        types -> flag;
        groups -> events;
        events -> {flag mappings identifiers};
        ghost -> hyperwarp;
        UI -> ghost;
        resources -> identifiers;
        optimize -> groups;
        hyperwarp -> flag;
        instances -> {ghost UI types events hyperwarp flag};
        resources -> {groups flag};
        remove_flag -> approval;
        persist -> approval;
        approval -> {types resources instances};
    }
    

    which results in

    But on reflection, seeing the difficulty I'm having to position the legend alongside the main graph, the way the position of node rankings in the main graph affects those in the legend, and the complication in the source that this introduces, I'm tempted to try a different approach (see my other answer, use a separate graph for the key)

提交回复
热议问题