]> granicus.if.org Git - graphviz/commitdiff
Add inputscale attribute to mimic the command line flag -s
authorEmden R. Gansner <erg@alum.mit.edu>
Thu, 14 Nov 2013 16:40:50 +0000 (11:40 -0500)
committerEmden R. Gansner <erg@alum.mit.edu>
Thu, 14 Nov 2013 16:40:50 +0000 (11:40 -0500)
doc/info/attrs.html
doc/infosrc/attrs
lib/common/utils.c
lib/common/utils.h
lib/fdpgen/layout.c
lib/gvc.def
lib/neatogen/neatoinit.c

index 459f6dabcce4cca311ad7c8896f2ceb8e0714d8b..15e25227786156f5eb0be53537b27179d21dd2c0 100644 (file)
@@ -229,6 +229,8 @@ This field indicates which graph component uses the attribute.
  <TR><TD><A NAME=a:imagescale HREF=#d:imagescale>imagescale</A>
 </TD><TD>N</TD><TD><A HREF=#k:bool>bool</A>
 <BR>string</TD><TD ALIGN="CENTER">false</TD><TD></TD><TD></TD> </TR>
+ <TR><TD><A NAME=a:inputscale HREF=#d:inputscale>inputscale</A>
+</TD><TD>G</TD><TD>double</TD><TD ALIGN="CENTER">&#60;none&#62;</TD><TD></TD><TD>fdp, neato only</TD> </TR>
  <TR><TD><A NAME=a:label HREF=#d:label>label</A>
 </TD><TD>ENGC</TD><TD><A HREF=#k:lblString>lblString</A>
 </TD><TD ALIGN="CENTER">"&#92;N" (nodes)<BR>"" (otherwise)</TD><TD></TD><TD></TD> </TR>
@@ -1022,6 +1024,17 @@ This field indicates which graph component uses the attribute.
   expansion, if  <TT>imagescale=true</TT>, width and height are
   scaled uniformly.
 
+<DT><A NAME=d:inputscale HREF=#a:inputscale><STRONG>inputscale</STRONG></A>
+<DD>  For layout algorithms that support initial input positions (specified by the <A HREF=#d:pos><B>pos</B></A> attribute),
+  this attribute can be used to appropriately scale the values. By default, fdp and neato interpret
+  the x and y values of pos as being in inches. (<B>NOTE</B>: neato -n(2) treats the coordinates as
+  being in points, being the unit used by the layout algorithms for the pos attribute.) Thus, if
+  the graph has pos attributes in points, one should set <TT>inputscale=72</TT>.
+  This can also be set on the command line using the <A HREF=command.html#minusK><TT>-s</TT> flag</A> flag.
+  <P>
+  If not set, no scaling is done and the units on input are treated as inches.
+  A value of 0 is equivalent to <TT>inputscale=72</TT>.
+
 <DT><A NAME=d:label HREF=#a:label><STRONG>label</STRONG></A>
 <DD>  Text label attached to objects.
   If a node's <A HREF=#d:shape>shape</A> is record, then the label can
index 5c12c852407f0027c6374ff6450ab16b42a336b6..61c2fd0f17b3134c15586daaba772cef233c97bf 100644 (file)
@@ -512,6 +512,16 @@ corresponding dimension of the node, that dimension of the
 image is scaled down to fit the node. As with the case of
 expansion, if  <TT>imagescale=true</TT>, width and height are
 scaled uniformly.
+:inputscale:G:double:<none>;  neato,fdp
+For layout algorithms that support initial input positions (specified by the <A HREF=#d:pos><B>pos</B></A> attribute),
+this attribute can be used to appropriately scale the values. By default, fdp and neato interpret
+the x and y values of pos as being in inches. (<B>NOTE</B>: neato -n(2) treats the coordinates as
+being in points, being the unit used by the layout algorithms for the pos attribute.) Thus, if
+the graph has pos attributes in points, one should set <TT>inputscale=72</TT>.
+This can also be set on the command line using the <A HREF=command.html#minusK><TT>-s</TT> flag</A> flag.
+<P>
+If not set, no scaling is done and the units on input are treated as inches.
+A value of 0 is equivalent to <TT>inputscale=72</TT>.
 :K:GC:double:0.3:0;  fdp,sfdp
 Spring constant used in virtual physical model. It roughly corresponds
 to an ideal edge length (in inches), in that increasing K tends to
index 8c9be81b1a5839461bcaf4d93edf961aeaf1c84f..efbb3f49a1115e97a74350b75fadc823883559e0 100644 (file)
@@ -99,6 +99,24 @@ double late_double(void *obj, attrsym_t * attr, double def, double low)
     else return rv;
 }
 
+/* get_inputscale:
+ * Return value for PSinputscale. If this is > 0, it has been set on the
+ * command line and this value is used.
+ * Otherwise, we check the graph's inputscale attribute. If this is not set
+ * or has a bad value, we return -1. 
+ * If the value is 0, we return the default. Otherwise, we return the value.
+ * Set but negative values are treated like 0.
+ */ 
+double get_inputscale (graph_t* g)
+{
+    double d;
+
+    if (PSinputscale > 0) return PSinputscale;  /* command line flag prevails */
+    d = late_double(g, agfindgraphattr(g, "inputscale"), -1, 0);
+    if (d == 0) return POINTS_PER_INCH; 
+    else return d;
+}
+
 char *late_string(void *obj, attrsym_t * attr, char *def)
 {
     if (!attr || !obj)
index 2009018d9440740b4791c24618dd2d95177f2049..a158a835ac331dab3a96d65ab15532c034bc4353 100644 (file)
@@ -65,7 +65,8 @@ extern "C" {
     extern double late_double(void *, Agsym_t *, double, double);
     extern char *late_nnstring(void *, Agsym_t *, char *);
     extern char *late_string(void *, Agsym_t *, char *);
-       extern boolean late_bool(void *, Agsym_t *, int);
+    extern boolean late_bool(void *, Agsym_t *, int);
+    extern double get_inputscale (graph_t* g);
 
     extern Agnode_t *UF_find(Agnode_t *);
     extern Agnode_t *UF_union(Agnode_t *, Agnode_t *);
index 9cb03ba3489b828b3a225aa075610075dcc941e2..0409f27ffd0782bd9bb500bdba23f1dd1c7f7459 100644 (file)
@@ -1121,6 +1121,9 @@ void fdp_layout(graph_t * g)
 {
     /* Agnode_t* n; */
 
+    double save_scale = PSinputscale;
+        
+    PSinputscale = get_inputscale (g);
     fdp_init_graph(g);
     if (setjmp(jbuf)) {
        return;
@@ -1136,4 +1139,5 @@ void fdp_layout(graph_t * g)
     if (EDGE_TYPE(g) != ET_NONE) fdpSplines (g); 
 
     dotneato_postprocess(g);
+    PSinputscale = save_scale;
 }
index bca312b6c619027447f8f72b500498db9c5941e9..15552eb9da64c1de09daf960b0e570eaa86d4e0e 100644 (file)
@@ -116,6 +116,7 @@ getdouble
 getPack    
 getPackMode    
 getsplinepoints    
+get_inputscale
 gmalloc    
 graph_cleanup    
 graph_init    
index fbff4e21bef36592f072a079fa883f0c33eca99c..65b77945d83030af8ac0ff39d5c12b8bf3c4e4a9 100644 (file)
@@ -1475,21 +1475,21 @@ void neato_layout(Agraph_t * g)
     pack_mode mode;
     pack_info pinfo;
     adjust_data am;
+    double save_scale = PSinputscale;
 
     if (Nop) {
-       int save = PSinputscale;
        int ret;
        PSinputscale = POINTS_PER_INCH;
        neato_init_graph(g);
        addZ (g);
        ret = init_nop(g, 1);
-       PSinputscale = save;
        if (ret < 0) {
            agerr(AGPREV, "as required by the -n flag\n");
            return;
        }
        else gv_postprocess(g, !ret);
     } else {
+       PSinputscale = get_inputscale (g);
        neato_init_graph(g);
        layoutMode = neatoMode(g);
        graphAdjustMode (g, &am, 0);
@@ -1564,4 +1564,5 @@ void neato_layout(Agraph_t * g)
        }
        dotneato_postprocess(g);
     }
+    PSinputscale = save_scale;
 }