# Add a grid to your graphs

**URL:** <https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402>\
**Category:** Show and Tell\
**Created:** [August 18, 2024, 8:39pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402 "2024-08-18T20:39:05Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [August 18, 2024, 8:39pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/1 "2024-08-18T20:39:05Z")

</div>

addGrid.gvpr - a postprocessor that will add a grid to your Graphviz graph.  
 ![unix.Ranks](https://global.discourse-cdn.com/graphviz/original/2X/8/89597d365ed9d0cd89abf40bad5479c625e60aaa.png)  
Find it [here](https://gist.github.com/steveroush/325b594e0547e2abbc79c5106d8e8db3)  
It can do horizontal, vertical, or both; edge styles, (multiple) colors, fixed increment or centered on ranks.  
Mostly a toy, but probably useful on larger graphs.  
Example command line:

```auto
dot myFile.gv | gvpr -a 'size=rank Gcolor=green,purple,red grid=horizontal' -cf addGrid.gvpr |neato -n2 ...

```

Enjoy

---

<div class="post-metadata">

**Author:** ![Vithanco](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/vithanco/32/292_2.png) [@Vithanco](https://forum.graphviz.org/u/Vithanco)\
**Post date:** [August 26, 2024, 6:30am UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/2 "2024-08-26T06:30:48Z")

</div>

Hi Steve,

this is pretty impressive and it made me think.

I even had a look at the manual: [gvpr | Graphviz](https://graphviz.org/docs/cli/gvpr/)  
but I don’t think it provided the answer to this question: what is the output of gvpr?  
I thought it was a tool dot → dot, but these lines aren’t part of the dot language afaik.  
So, what is the outcome? Or which tool is the output formatter?

Cheers,  
Klaus

---

<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:** [August 26, 2024, 2:00pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/3 "2024-08-26T14:00:53Z")

</div>

Simple answer: the output of **gvpr** is the **Graphviz** / **dot** language. The grid lines are a result of adding new nodes around the periphery of the graph and then adding (straight) edges connecting the nodes.

More complete answer: **gvpr** is a complete language and could probably be used to write a (very simple) compiler. (Not on my TODO list). Here is a [_lint_](https://forum.graphviz.org/t/a-lint-program-for-graphviz-files/2209/3) program written in **GVPR**. No **dot** output, just text.

For an example of the breadth of **gvpr** , here is a [radial layout engine](https://forum.graphviz.org/t/a-radial-graphviz-engine-pre-processor/1271) written in **gvpr**. Legal **dot** input and legal **dot** output.

 ![radialTest103](https://global.discourse-cdn.com/graphviz/original/2X/d/d6ba6c6cb23e5209bb22c7e5926dd4a32e2f63b2.png)

---

<div class="post-metadata">

**Author:** ![Vithanco](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/vithanco/32/292_2.png) [@Vithanco](https://forum.graphviz.org/u/Vithanco)\
**Post date:** [October 28, 2024, 8:29am UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/4 "2024-10-28T08:29:25Z")

</div>

I needed to come back and read this again. Impressive. Well done!  
Do you have somewhere a list of “documented” gvpr use cases? I see it here mentioned every now and then. But do you have a systematic list of examples?

---

<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:** [October 29, 2024, 12:39am UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/5 "2024-10-29T00:39:17Z")

</div>

Nope, nothing systematic about any of my efforts. I am slowly working on documenting the more interesting programs, if I can figure out what they do.  
Note that some are posted [here](https://gist.github.com/steveroush).

---

<div class="post-metadata">

**Author:** ![somms](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/somms/32/1839_2.png) [@somms](https://forum.graphviz.org/u/somms)\
**Post date:** [February 14, 2025, 6:03pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/6 "2025-02-14T18:03:25Z")

</div>

Moving the conversation to this thread from [Simulate Y axis and horizontal strips - #5 by somms](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/5)

I get an error that may be related to your code (or most probably to my inexperience)

When I try to add any parameter using the -a option, I always get an empty output and a “gvpr: gvpr” message:

```auto
$ dot input.dot | gvpr -a 'size=rank' -cf addGrid.gvpr
// SIZE start: 72pt delta: 0
// SIZE end: 72pt size: 72 delta: 0
// ARG >size=rank<
// type: s
gvpr: gvpr

```

The “offending line” is

187 Val=substr(ARGV[i],Indx);

After adding some prints to debug, the problem is that Indx value is -3.

---

<div class="post-metadata">

**Author:** ![somms](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/somms/32/1839_2.png) [@somms](https://forum.graphviz.org/u/somms)\
**Post date:** [February 14, 2025, 6:26pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/7 "2025-02-14T18:26:10Z")

</div>

BIngo. It seems that there is a bug in my gvpr version (2.48.0) and index returns the value of rindex. I have substituted

```auto
Indx=1+index(ARGV[i],"=");

```

by

```auto
Indx = length(ARGV[i]) - rindex(ARGV[i], "=") + 1;

```

And it works well now.

---

<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:** [February 14, 2025, 6:44pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/8 "2025-02-14T18:44:30Z")

</div>

Are you saying that gvpr has a mistake in its implementation of index. That is possible.

---

<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:** [February 14, 2025, 9:57pm UTC](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402/9 "2025-02-14T21:57:12Z")

</div>

Yep, here are two _closed_ Issues that mention gvpr & index  
[#2211](https://gitlab.com/graphviz/graphviz/-/issues/2211)  
[#2138](https://gitlab.com/graphviz/graphviz/-/issues/2138)
