]> granicus.if.org Git - graphviz/commitdiff
Add (undocumented) prototype implementation of edge labels that align
authorEmden R. Gansner <erg@alum.mit.edu>
Thu, 17 Apr 2014 14:19:12 +0000 (10:19 -0400)
committerEmden R. Gansner <erg@alum.mit.edu>
Thu, 17 Apr 2014 14:19:12 +0000 (10:19 -0400)
with the edge. This only works with ordinary labels; only in svg; there
is no handling of space or geometry issues.

lib/common/emit.c
lib/common/labels.c
lib/gvc/gvcjob.h
plugin/core/gvrender_core_svg.c

index a87fdecce0eff71d64822ab6a26e8e675470d768..d29533776707759a1cde21a5a6ec74ef0ca45dbe 100644 (file)
@@ -2461,6 +2461,8 @@ static void emit_begin_edge(GVJ_t * job, edge_t * e, char** styles)
     obj->type = EDGE_OBJTYPE;
     obj->u.e = e;
     obj->emit_state = EMIT_EDRAW;
+    if (ED_label(e) && !ED_label(e)->html && mapBool(agget(e,"labelaligned"),FALSE))
+       obj->labeledgealigned = TRUE;
 
     /* We handle the edge style and penwidth here because the width
      * is needed below for calculating polygonal image maps
index 157ec2dbd9f2228fc8dad4462ba527c6448995cc..78e34622185955fc8f34e4b79732ba498b4b5e36 100644 (file)
@@ -255,6 +255,8 @@ void emit_label(GVJ_t * job, emit_state_t emit_state, textlabel_t * lp)
            p.y = lp->pos.y + lp->dimen.y / 2.0 - lp->fontsize;
            break;
     }
+    if (obj->labeledgealigned)
+       p.y -= lp->pos.y;
     for (i = 0; i < lp->u.txt.nspans; i++) {
        switch (lp->u.txt.span[i].just) {
        case 'l':
index cc317c9553ad574d3cefbcc044ed17c7522bbc79..c58ae79f5ade73c2498e1c6a9968ada0fb6ad4d5 100644 (file)
@@ -241,6 +241,7 @@ extern "C" {
        int explicit_edgetarget:1;
        int explicit_tailurl:1;
        int explicit_headurl:1;
+       int labeledgealigned:1;
 
        /* primary mapped region - node shape, edge labels */
        map_shape_t url_map_shape; 
index 68502c97e89f73c9f711897a2823ad2906604e80..85d8247fd141d6f6572619bc05c0b28eb6ee5393 100644 (file)
@@ -57,12 +57,22 @@ static void svg_bzptarray(GVJ_t * job, pointf * A, int n)
     char c;
 
     c = 'M';                   /* first point */
-    for (i = 0; i < n; i++) {
-       gvprintf(job, "%c%g,%g", c, A[i].x, -A[i].y);
-       if (i == 0)
-           c = 'C';            /* second point */
-       else
-           c = ' ';            /* remaining points */
+    if (A[0].x <= A[n-1].x) {
+       for (i = 0; i < n; i++) {
+           gvprintf(job, "%c%g,%g", c, A[i].x, -A[i].y);
+           if (i == 0)
+               c = 'C';                /* second point */
+           else
+               c = ' ';                /* remaining points */
+       }
+    } else {
+       for (i = n-1; i >= 0; i--) {
+           gvprintf(job, "%c%g,%g", c, A[i].x, -A[i].y);
+           if (i == 0)
+               c = 'C';                /* second point */
+           else
+               c = ' ';                /* remaining points */
+       }
     }
 }
 
@@ -364,7 +374,8 @@ static void svg_textspan(GVJ_t * job, pointf p, textspan_t * span)
        break;
     }
     p.y += span->yoffset_centerline;
-    gvprintf(job, " x=\"%g\" y=\"%g\"", p.x, -p.y);
+    if (!obj->labeledgealigned)
+       gvprintf(job, " x=\"%g\" y=\"%g\"", p.x, -p.y);
     pA = span->font->postscript_alias;
     if (pA) {
        switch (GD_fontnames(job->gvc->g)) {
@@ -440,7 +451,13 @@ static void svg_textspan(GVJ_t * job, pointf p, textspan_t * span)
        assert(0);              /* internal error */
     }
     gvputs(job, ">");
+    if (obj->labeledgealigned) {
+       gvprintf (job, "<textPath xlink:href=\"#%s_p\" startOffset=\"50%%\">", xml_string(obj->id));
+       gvprintf (job, "<tspan x=\"0\" dy=\"%g\">", -p.y);
+    }
     gvputs(job, xml_string0(span->str, TRUE));
+    if (obj->labeledgealigned)
+       gvprintf (job, "</tspan></textPath>");
     gvputs(job, "</text>\n");
 }
 
@@ -558,7 +575,8 @@ static void
 svg_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
           int arrow_at_end, int filled)
 {
-  int gid = 0;
+    int gid = 0;
+    obj_state_t *obj = job->obj;
   
     if (filled == GRADIENT) {
        gid = svg_gradstyle(job, A, n);
@@ -566,6 +584,11 @@ svg_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
        gid = svg_rgradstyle(job, A, n);
     }
     gvputs(job, "<path");
+    if (obj->labeledgealigned) {
+       gvputs(job, " id=\"");
+       gvputs(job, xml_string(obj->id));
+       gvputs(job, "_p\" ");
+    } 
     svg_grstyle(job, filled, gid);
     gvputs(job, " d=\"");
     svg_bzptarray(job, A, n);