James
James

Reputation: 183

Two colours in one node with graphviz's dot?

I'm wondering if it is possible to split a node into two different colours. I'm using graphviz's dot (http://www.graphviz.org/).

Perhaps a verticle, or diagonal line could split the node into two colours. I want to do this because I have many nodes which belong to two different categories (colours) with some nodes belonging to both.

Many thanks, James

Upvotes: 8

Views: 5786

Answers (3)

ryandesign
ryandesign

Reputation: 1144

Gradient functionality was only added to Graphviz on January 26, 2012; until the new 2.30.0 stable version of Graphviz is released, you'll need to download Graphviz development version 2.29.20120127.0545 or newer.

In addition, gradients seem to only be implemented for the Cairo/Pango renderer so far; in my tests, the Quartz (Mac) and GD renderers fall back to using just the first color. In particular, this means if you're on a Mac and are using the Graphviz.app GUI viewer, you won't see gradients there (yet).

digraph G {
  Gradient [style="filled", fillcolor="orange:yellow"]
}

enter image description here

Upvotes: 15

dgw
dgw

Reputation: 13646

It is possible, if you use the image attribute of a label and provide a suitable background image:

digraph G {
  i1 [shape=none, image="range.png", label=""];
  i2 [shape=none, image="range.png", label="Image w label", imagescale=true];
  i1 -> i2;
}

This gives the following output:

enter image description here

using the range.png file

enter image description here

Upvotes: 1

marapet
marapet

Reputation: 56446

I don't think there is an out-of-the-box solution to have 2 background colors.

The best solution would be to use gradient fills (fillcolor="orange:yellow") - but though this is in the documentation, I wasn't able to make it work on my box.

You could use HTML-like labels as a workaround. You may need to split the label to have it centered, depending on your needs:

a[shape="none", label=<
<table cellpadding="0" cellborder="0" cellspacing="0" border="0">
<tr>
<td bgcolor="orange">abc</td>
<td bgcolor="yellow">def</td>
</tr>
</table>
>]

2 colors

Upvotes: 7

Related Questions