# Cannot remove padding for Clusters with HTML Labels

**URL:** https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921
**Category:** Uncategorized
**Created:** [November 21, 2021, 3:53am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921 "2021-11-21T03:53:07Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 21, 2021, 3:53am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/1 "2021-11-21T03:53:07Z")

</div>

Hello, I am trying to create a cluster with an HTML (table) label that includes an image and some text. However, despite setting padding and borders to 0 and justification to left the label image has some padding around it which results in a gap. How can I fix this? I have marked these gaps with red arrows here. I want them to be exactly aligned to the corner of of the box instead.

![gaps](https://global.discourse-cdn.com/graphviz/original/1X/9613917cdcfe4bcc22bb3964f4349466277cd5f6.png)

The .dot code is

```auto
subgraph cluster_AWSgroup_42484 {
				graph [center=true fontname="Sans-Serif" fontsize=12 label=<<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="0"><TR><TD><img src="./resource_images/aws/general/aws.png"/></TD><TD>AWS Cloud</TD></TR></TABLE>> labeljust=l margin=100 ordering=in pencolor=black rankdir=LR shape=box style=solid]
			}

```

If this is something that needs to be amended in the C code, please point me to the relevant sections so I can raise a PR. Willing to pay to get this fixed.

Thanks.

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 21, 2021, 7:32pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/2 "2021-11-21T19:32:49Z")

</div>

No C hacks, but here is a post-processing hack that seems to do what you want. The margin/pad around the image seems to have multiple components:

- an invisible table/cell border
- a pad that keeps the label from colliding with the periphery box around the cluster.

This hack uses

- **dot** to determine all the placement positions (dot -Tdot lists all positions)
- **GVPR** ([https://www.graphviz.org/pdf/gvpr.1.pdf](https://www.graphviz.org/pdf/gvpr.1.pdf)) to calculate how much to shift label (to upper left only)
- **neato -n2** ([FAQ | Graphviz](https://graphviz.org/faq/#FaqDotWithCoords)) to produce desired image

(Linux) shell script:

```auto
f=clusterPad2.gv
T=png
F=`basename $f .gv`;dot -Tdot $f |
gvpr -c -f shiftLabel.gvpr |
neato -n2 -T$T >$F.$T

```

Here is shiftLabel.gvpr:

```auto
BEGIN{
  double bbMinX, bbMinY, bbMaxX, bbMaxY, lpX, lpY, lpMinX, lpMaxY, newX, newY;

  // recursive routine, processing from the top (root) down
  graph_t labelShift (graph_t Gr) {
    graph_t thisG;

    for (thisG = fstsubg(Gr); thisG; thisG=nxtsubg(thisG)) {
          thisG = labelShift(thisG);
    }
    //print("// (sub)graph: ", Gr.name);
    if (match(Gr.name,"cluster")==0 ){
      if (hasAttr(Gr, "_shift")){
        sscanf (Gr.bb, "%lf,%lf,%lf,%lf", &bbMinX, &bbMinY, &bbMaxX, &bbMaxY);
	lpX=xOf(Gr.lp);
	lpY=yOf(Gr.lp);
	lpMinX=lpX-((Gr.lwidth*72.)/2.);
	lpMaxY=lpY+((Gr.lheight*72.)/2.);
	//print("// bb: ", Gr.bb, " lpMinX: ", lpMinX, " lpMaxY: ", lpMaxY);
	Gr._oldlp=Gr.lp;
	// 2 fudge factor (maybe nonexistent table border?)
	newX=lpX-(lpMinX-bbMinX)-2;
	newY=lpY+(bbMaxY-lpMaxY)+2;
	Gr.lp=sprintf("%.1f,%.1f", newX, newY);
      }
    }
    return Gr;
  } // end of labelShift
}
BEG_G{
  labelShift($G);
}

```

Result:

 ![clusterPad2.new](https://global.discourse-cdn.com/graphviz/original/1X/471fec1c4393309b5e8b98f0cd07d08ae960d7e6.png)

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 22, 2021, 1:40am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/3 "2021-11-22T01:40:00Z")

</div>

Whoops, forgot to note that you need to add a **\_shift** attribute to the cluster (e.g.  
`graph [_shift=1]`)

---

<div class="post-metadata">

### Author: ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)
#### Post date: [November 23, 2021, 12:52am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/4 "2021-11-23T00:52:28Z")

</div>

Is this dot? We might need a minimum separation of one pixel to avoid degeneracy. It might take more work to hunt down why this is a problem and fix it. The spline router is funny thing and doesn’t like zero-width rectangles.

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 23, 2021, 4:17pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/5 "2021-11-23T16:17:17Z")

</div>

Thank you so much Steve this was an amazing idea and worked like a charm! You’re a genius.

However, I am afraid I am not familiar with gvpr / neato so I need some more guidance.

Could you help me understand and fix the following outer cluster border which seems to be jagged after post processing. When I zoom in there is a ghost outline of sorts as shown in this image

![border](https://global.discourse-cdn.com/graphviz/original/1X/429b63c6e1e5f3fccb4548c35731431d7023d2f9.png)

Many thanks and please let me know if it would be easier to talk directly on E-mail/DM. Let me know how if I can tip you or something 🙂

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 23, 2021, 4:23pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/6 "2021-11-23T16:23:40Z")

</div>

@scnorth Yes this is the dot engine producing .dot files from the python graphviz library.

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 23, 2021, 4:24pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/7 "2021-11-23T16:24:32Z")

</div>

@scnorth @steveroush Thanks for your kind assistance

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 23, 2021, 5:29pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/8 "2021-11-23T17:29:11Z")

</div>

What does

> degeneracy

mean in this context?

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 23, 2021, 5:30pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/9 "2021-11-23T17:30:27Z")

</div>

Does the word “_Shared_” show up anywhere in your graph? That is part of the overlayed text.

---

<div class="post-metadata">

### Author: ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)
#### Post date: [November 23, 2021, 5:56pm UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/10 "2021-11-23T17:56:45Z")

</div>

Degenerate spline constraint polygons- for example where nonconsecutive segments touch.

“[Points in general position](https://en.wikipedia.org/wiki/General_position)” is another bugaboo of geometric algorithms, for example, polygons where two consecutive points are at the same position or segments are collinear can be problematic. It was just a lot of blood, sweat and tears for us to either make algorithms or robust or eliminate that from happening. You can’t just jitter the points because that can create other problems, e.g.self-intersecting polygons are no good.

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 24, 2021, 1:01am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/11 "2021-11-24T01:01:16Z")

</div>

Yes fixed thst thanks, any thoughts about the border?

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 24, 2021, 1:16am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/12 "2021-11-24T01:16:48Z")

</div>

The fudge factors need to be adjusted. Do you want the image just inside the periphery (the box surrounding the cluster) or on top of the periphery?

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 24, 2021, 2:59am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/13 "2021-11-24T02:59:37Z")

</div>

@steveroush I’m not sure what a fudge factor is

I’d like the image just inside if possible, although any other similar outcome overlapping on top to give the same effect is fine too since the border will be same color as the background of the image in most cases.

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [November 24, 2021, 3:36am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/14 "2021-11-24T03:36:46Z")

</div>

Fudge factor ([Fudge factor - Wikipedia](https://en.wikipedia.org/wiki/Fudge_factor)).  
The above GVPR program shifted an “extra” 2 pixels in both X & Y directions (the fudge factors). I think I know why they are needed, but not worth the detective work to figure out exactly why they are needed.  
The modified version (below) only shifts Y by 1 pixel. It also allows you to set X & Y fudge factors like this `_shift="3,2.2"` (it triggers if the value contains a comma)  
So try this new version of shiftLabel.gvpr:

```auto
BEGIN{
  double bbMinX, bbMinY, bbMaxX, bbMaxY, lpX, lpY, lpMinX, lpMaxY, newX, newY;
  double fudgeX, fudgeY;
  string fld[int];
  
  // recursive routine, processing from the top (root) down
  graph_t labelShift (graph_t Gr) {
    graph_t thisG;

    for (thisG = fstsubg(Gr); thisG; thisG=nxtsubg(thisG)) {
          thisG = labelShift(thisG);
    }
    if (match(Gr.name,"cluster")==0 ){
      if (hasAttr(Gr, "_shift") && Gr._shift!=""){
        fudgeX=2.; // aim for just inside periphery - increase to shift left
        fudgeY=1.; // aim for just inside periphery - increase to shift up
	if (index(Gr._shift,",")>0){
	  split(Gr._shift,fld,",");
	  print("// flds : ", fld[0]," ",fld[1]);
	  fudgeX=(double)fld[0];
	  fudgeY=(double)fld[1];
	}
        sscanf (Gr.bb, "%lf,%lf,%lf,%lf", &bbMinX, &bbMinY, &bbMaxX, &bbMaxY);
	lpX=xOf(Gr.lp);
	lpY=yOf(Gr.lp);
	lpMinX=lpX-((Gr.lwidth*72.)/2.);
	lpMaxY=lpY+((Gr.lheight*72.)/2.);
	print("// bb: ", Gr.bb, " lpMinX: ", lpMinX, " lpMaxY: ", lpMaxY);
	Gr._oldlp=Gr.lp;
	// fudge factors set below (maybe nonexistent table border?)
        print("// fudge : ", fudgeX, " ",fudgeY);
	newX=lpX-(lpMinX-bbMinX)-fudgeX;
	newY=lpY+(bbMaxY-lpMaxY)+fudgeY;
	Gr.lp=sprintf("%.1f,%.1f", newX, newY);
      }
    }
    return Gr;
  } // end of labelShift
}
BEG_G{
  labelShift($G);
}

```

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 27, 2021, 1:08am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/15 "2021-11-27T01:08:56Z")

</div>

Thanks Steve - works like magic!

---

<div class="post-metadata">

### Author: ![neogeno](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/neogeno/32/542_2.png) [@neogeno](https://forum.graphviz.org/u/neogeno)
#### Post date: [November 27, 2021, 1:13am UTC](https://forum.graphviz.org/t/cannot-remove-padding-for-clusters-with-html-labels/921/17 "2021-11-27T01:13:48Z")

</div>

Please ignore my previous question.
