question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

image node attribute that refers to dynamically generated SVG (data URL)?

See original GitHub issue

I’ve been using the style="wedged" node attribute value to render nodes as pie charts.

The results are okay, but I’d like more functionality in the pie charts: for example, slice-specific tooltips. That’s not possible with the Graphviz-generated SVG: the resulting <path> elements for each slice don’t contain any attribute that identifies their field name.

So I’ve been considering alternative ways to render nodes as pie charts.

One idea is to dynamically, in the browser, create an SVG pie chart (the XML; the SVG “source”), and then specify that SVG as a data URL in the image node attribute.

So far, this is only an idea. I’ve only got as far as reading the Images section in the d3-graphviz documentation, and realizing I need to specify the image path—in my case, the data URL—in both an addImage call and the DOT.

I’m wondering whether that—the combination of addImage and image node attribute value—would even work for a data URL.

I’ll try it first thing tomorrow, but I thought I’d create this issue now to perhaps save me a day, in case someone responds overnight (I’m in Perth, Western Australia, UTC+8).

I’m thinking something like this:

digraph G {

hello [image="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KPHBhdGggZD0iTTUwLDNsMTIsMzZoMzhsLTMwLDIybDExLDM2bC0zMS0yMWwtMzEsMjFsMTEtMzZsLTMwLTIyaDM4eiIKZmlsbD0iI0ZGMCIgc3Ryb2tlPSIjRkMwIiBzdHJva2Utd2lkdGg9IjIiLz4KPC9zdmc+Cg=="]

}

where the original unencoded SVG is:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<path d="M50,3l12,36h38l-30,22l11,36l-31-21l-31,21l11-36l-30-22h38z"
fill="#FF0" stroke="#FC0" stroke-width="2"/>
</svg>

(a five-pointed yellow star; a placeholder example until I decide what to use to generate bespoke pie chart SVG)

but I fear that addImage will barf at that long “path”.

I’ll report back tomorrow on my progress.

Advice, suggestions welcome.

(Another idea: post-render, dynamically replace the node’s <g> element in the SVG DOM with a bespoke pre-generated SVG group for a pie chart. But there are positioning issues there that I’ve not even begun to look into.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
GrahamHanningtoncommented, Jun 19, 2019

Hi @magjac,

I still hope to one day publish that “showcase” repo I promised ages ago, but for now I’m told my work remains inhouse. For web-based graph visualizations that involve clusters (compound nodes)—doubtless, other use cases, too, but this is my specific area of interest—d3-graphviz remains the best solution that I know of. Thanks again for providing this library. I’m frankly mystified why it appears not to have the higher profile I think it deserves.

Re:

you probably also could use the order of the path elements

Yes, good point. That occurred to me, too, although I never got around to confirming the drawing order. I chose to match based on color because not every chart has the same number of slices; I don’t draw “zero-size” slices. That’s not a showstopper—in the same way I know the slice colors, I also know which slices each chart has—but the color-based matching code, insensitive to the absence or presence of particular slices, was slightly easier to write. Conceptually, I prefer your suggestion: relying on the drawing order, and knowing the number of slices, feels like a more elegant solution than matching color values. I might yet rewrite my code to do that.

0reactions
magjaccommented, Jun 18, 2019

Nice to hear from you again @GrahamHannington and even nicer to see that your still using the library 😎.

Glad you solved it. Thanks for sharing your findings. Instead of using the color, you probably also could use the order of the path elements, knowing that they are drawn in order starting from 0 degrees and counter clockwise (I think).

Read more comments on GitHub >

github_iconTop Results From Across the Web

09: SVG with Data URIs - CSS-Tricks
I'm unsure what the advantages are when using data:image/svg+xml;utf8 compared to using just an inline SVG? ... One potential thing is DOM weight....
Read more >
<image> - SVG: Scalable Vector Graphics - MDN Web Docs
The <image> SVG element includes images inside SVG documents. It can display raster image files or other SVG files. The only image formats ......
Read more >
setting background image to dynamic svg data? - Stack Overflow
backgroundImage = "url(data:image/svg+xml;utf8," + svgCode + ")"; ... so i just set it to the background-image of whatever i would like.
Read more >
Creating dynamic SVG elements with JavaScript - Motion Tricks
In this tutorial, we'll take a look at creating dynamic SVG elements. ... This applies to presentation attributes, not positioning.
Read more >
How to create svg elements with Javascript
svg file format. While other common formats, such as .png , are based on a grid of pixels, svgs consist out of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found