House shape wider than necessary (cf. to rect)

Using dot/graphviz 2.47.0
Running ubuntu 20.04.2 LTS on oracle virtual box 6.1 hosted on windows 10.
Command line: dot -T jpg house-shape-width.gv > house-shape-width.jpg

Using dot; I have found that when I choose shape=house for a node the node is quite a bit wider than if I use rectangle. I have tried setting margin and it does not seem to help. At first I though it was because the first line of text was projecting into the triangle part of the house shape, but I no longer think that is the problem because the excess width is greater when there are two lines rather than just one line. Adding a top line with a single character line &-n-b-s-p-; (non-breaking space) does not seem to help.

Any advice ?

.jpg attached (but same result using .pdf)

strict digraph "house-shape-width"
{
   TITLE [fontsize=16,
          label=<House Shape Width<br/>10 Apr 2021>
          shape=ellipse
          peripheries=2]
          
   newrank=true
  
   edge [arrowhead=none]
   node [shape=rect]
   graph [ranksep=0.4]
      
   "h1-line" [shape=house label=<the quick brown fox A>];
   "h2-line" [shape=house label=<the quick brown fox A<br/>B>];

   "ih1-line" [shape=invhouse label=<the quick brown fox A>];
   "ih2-line" [shape=invhouse label=<the quick brown fox A<br/>B>];

   "r1-line" [shape=rect label=<the quick brown fox A>];
   "r2-line" [shape=rect label=<the quick brown fox A<br/>B>];

    "h1-line" -> "r1-line"
    "r1-line" -> "ih1-line"
    "ih1-line" -> "r2-line"
    "r2-line" -> "h2-line" 
    "h2-line" -> "ih2-line"
    
}

1 Like

Yep, fat nodes. I looked quickly in shapes.c, but saw nothing.
I fooled around trying to find a work-around and eventually found that explicitly setting width & height of the node and setting fixedsize=true produced skinnier nodes.
For testing, I set height & width manually, but then I produced this (Linux) script to size the houses automatically:

  • using GVPR, change shapes from house/invhouse to rect, saving orig. shape as xshape

  • run that thru dot -Tdot to place nodes & edges

  • run that back thru GVPR to change node shapes back to orig. & add “fixedsize=true”

  • run that thru neato -Tpng -n to produce final output format without repositioning any nodes

    f=wideHouse0.gv; T=png; F=basename $f .gv;
    gvpr -c ‘N[.shape=="house"||.shape==“invhouse”]{.xshape=.shape;$.shape=“rect”;}’ f | dot -Tdot | gvpr -c 'N[.xshape!=""]{.shape=.xshape;$.fixedsize=“true”;}’|
    neato -n -T$T >$F.$T

producing:

2 Likes

There are so many new techniques and tools here, I will have to study it.
I had not heard of gvpr previously. I feel compelled to learn how to use it.
Thanks for this lesson.

@tmoog I think there are many tools to do this type of work. But thanks for sharing these techniques with us. Some other times i will check this. And then i will give you it’s feedback. :slightly_smiling_face:

My earlier answer was somewhat terse. Here is some more info:

  • yes, there is a bug/suboptimal condition in the house/invhouse code
  • a work-around fix is to explicitly set the dimensions (height & width) of these nodes (and fixedsize=true)
  • the question is set the height & width to what?
  • my previous posting presented a convoluted, but fully automatic, method of setting the dimensions.
  • here is a more manual method of achieving the same goal (GVPR not needed):
    • copy your file (myfile.gv) to temp.gv (or some such)
    • also copy myfile.gv to backup.gv - just in case things get messed up
    • using your editor, edit temp.gv and change all the shape=house or shape=invhouse to shape=rect
    • run dot -Tdot temp.gv >tempX.gv
    • edit your original myfile.gv in one window & tempX.gv in another window
    • for every node in myfile.gv that has shape=house or shape=invhouse,
      • copy the height & width attribute lines in tempX.gv to myfile.gv
      • add fixedsize=true attribute to these nodes
    • run dot -Tpng myfile.gv >myfile.png - your nodes should be nicely sized

Thanks very much for the additional information. This is the kind of thing I was thinking about,
but did not have the details you’ve specified clearly.

I've been distracted by another project the past week or so. I will try this when it is finished in a couple of weeks.

I recognize the similarity of gvpr to awk. I used to use xml/xsl quite a bit, so pattern matching and actions are not foreign.

I haven’t closely followed this thread, but if there is something to be fixed please open a Gitlab issue.

Issue: house and invhouse nodes with labels are excessively wide (#2055) ¡ Issues ¡ graphviz / graphviz ¡ GitLab

1 Like