From: Matthew Fernandez Date: Sat, 27 Aug 2022 22:17:09 +0000 (-0700) Subject: fix 'id' attribute in SVG output omitting input graph id X-Git-Tag: 6.0.1~23^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=465cef702370966f17d27d455093cf69a651af9c;p=graphviz fix 'id' attribute in SVG output omitting input graph id When using an ID attribute on the input graph,¹ this attribute would only be propagated to some output elements. In particular, generated `linearGradient` and `radialGradient` elements in SVGs would be missing the ID. Gitlab: fixes #2258 ¹ https://graphviz.org/docs/attrs/id/ --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 259669a9f..5ab3b3dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Accuracy of the bounding boxes printed by the `showboxes` feature have been improved. +### Fixed + +- Id attribute is not used in linearGradient. #2258 + ### Removed - The `$GV_FILE_PATH` sandboxing mechanism has been removed #2257 diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index d77532c80..363ef2985 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -553,8 +553,12 @@ static int svg_gradstyle(GVJ_t * job, pointf * A, int n) G[0].x = G[0].y = G[1].x = G[1].y = 0.; get_gradient_points(A, G, n, angle, 0); //get points on gradient line - gvprintf(job, - "\n\nid != NULL) { + gvputs_xml(job, obj->id); + gvputc(job, '_'); + } + gvprintf(job, "l_%d\" gradientUnits=\"userSpaceOnUse\" ", id); gvputs(job, "x1=\""); gvprintdouble(job, G[0].x); gvputs(job, "\" y1=\""); @@ -589,8 +593,12 @@ static int svg_rgradstyle(GVJ_t * job) ifx = round(50 * (1 + cos(angle))); ify = round(50 * (1 - sin(angle))); } - gvprintf(job, - "\n\nid != NULL) { + gvputs_xml(job, obj->id); + gvputc(job, '_'); + } + gvprintf(job, "r_%d\" cx=\"50%%\" cy=\"50%%\" r=\"75%%\" " "fx=\"%.0f%%\" fy=\"%.0f%%\">\n", id, ifx, ify); diff --git a/tests/test_regression.py b/tests/test_regression.py index 548e7bd6a..5f73a04da 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -1928,7 +1928,6 @@ def test_2257(): with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(["dot", "-Tsvg", input, "-o", os.devnull], env=env) -@pytest.mark.xfail(strict=True) def test_2258(): """ 'id' attribute should be propagated to all graph children in output