最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

graphviz - Fixed position in the first column for the nodes, not in the others - Stack Overflow

matteradmin3PV0评论

I want a table of 2 columns with graphviz. Within the first columns I would like to have fixed positions for the nodes (x and Y). The other nodes can be freely positioned by graphviz within the assigned (other) column, i.e. the Y position does not matter. The positions within the first columns should not change, regardless of the connections to the nodes in the other columns

    digraph G {
      rankdir=LR;
      node [shape=box];
      
      subgraph cluster_0 {
        label = "Spalte 1";
        a [pos="0,2!"];
        b [pos="0,1!"];
        c [pos="0,0!"];
      }
    
      subgraph cluster_1 {
        label = "Spalte 2";
        d;
        e;
        f;
      }
    
  a-> e;
  a -> f;
    
    }

Currently the column slides up instead of the nodes within the column. Just change a-> to somethig to see it.

I want a table of 2 columns with graphviz. Within the first columns I would like to have fixed positions for the nodes (x and Y). The other nodes can be freely positioned by graphviz within the assigned (other) column, i.e. the Y position does not matter. The positions within the first columns should not change, regardless of the connections to the nodes in the other columns

    digraph G {
      rankdir=LR;
      node [shape=box];
      
      subgraph cluster_0 {
        label = "Spalte 1";
        a [pos="0,2!"];
        b [pos="0,1!"];
        c [pos="0,0!"];
      }
    
      subgraph cluster_1 {
        label = "Spalte 2";
        d;
        e;
        f;
      }
    
  a-> e;
  a -> f;
    
    }

Currently the column slides up instead of the nodes within the column. Just change a-> to somethig to see it.

Share Improve this question edited Nov 18, 2024 at 19:11 eshirvana 24.7k3 gold badges27 silver badges42 bronze badges asked Nov 18, 2024 at 19:10 ozzozz 1831 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

packmode (https://www.graphviz./docs/attr-types/packMode/) seems to accomplish your goal.
Note that nodes are in first-in-last-out order.

digraph G {
      rankdir=LR;
      packmode="array_ic2"  // the two clusters must not be connected (no edges)
      // packmode works best with recent (~2024 and later) releases of Graphviz
      node [shape=box];
      
      subgraph cluster_0 {
        label = "Spalte 1";
        a [pos="0,2!"];  // fyi, dot ignores all pos attributes
        b [pos="0,1!"];
        c [pos="0,0!"];
      }
    
      subgraph cluster_1 {
        label = "Spalte 2";
        d;
        e;
        f;
      }
    
// packmode requires no edges between the clusters to be "packed"
//  a-> e;  
//  a -> f;
    
    }

Giving:

Post a comment

comment list (0)

  1. No comments so far