0
votes

I'm working with Graphviz API, Visual C++. Before I call gvLayout to calculate node coordinates, I have to set node width and height (for each node in the graph). The problem is, ND_width and ND_height macro approach, just does not seem to have affect, while setting same values with agsafeset works as expected. I just don't want to use string-based APIs like agsafeset, because I'm processing bunch of nodes in a loop, and prefer to set width and height values with ND_width(pNode) and ND_height(pNode) (or directly as pNode->u.width and pNode->u.height). What am I doing wrong?

Following code does not work (does not have any effect):

const DWORD dwPixelsPerInch = 96;

ND_width(pGvzNode) = (double)dwWidthInPixels / dwPixelsPerInch;
ND_height(pGvzNode) = (double)dwHeightInPixels / dwPixelsPerInch;

While following code works:

CStringA csaValue;

csaValue.Format("%f", (double)dwWidthInPixels / dwPixelsPerInch);
agsafeset(pGvzNode, "width", csaValue.GetBuffer(), "");

csaValue.Format("%f", (double)dwHeightInPixels / dwPixelsPerInch);
agsafeset(pGvzNode, "height", csaValue.GetBuffer(), "");

P.S.: I use Graphviz solely for layout, I do custom rendering, so all I need is calculation of nodes' and edges' coordinates (in pixels) given nodes' width and height (in pixels). I'm setting these values just before calling gvLayout (for "dot"). I'm setting agsafeset(pGvzNode, "fixedsize", "1", "") as well.

1

1 Answers

1
votes

agsafeset sets the node attributes, which are used by gvLayout to calculate the layout information, while ND_width and ND_height are used to get the layout size. Before gvLayout is called, the ND_width and ND_height can set the values, but the values you have set will be overwritten by gvLayout. So you must use agsafeset, the ND_width and ND_height cannot work.