Allow label function to return svg elements to be rendered as labels e.g. svg:text
See original GitHub issueI would like to create a gauge with an icon in the middle and the value below it. For the icon i have created a webfont and it does seem to render. However my tspans that i would like to use to have 2 lines are not rendered. I can actually see the full string (<tspan…)
testIcon(value: string): string {
return '<tspan x="0" dy="1.2em"></tspan><tspan x="0" dy="1.2em">' + value + '</tspan>';
}
Is there any other way to have 2 lines in the middle of the gauge? Or am i missing something else?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Issue adding multiple text elements to svg elements
The problem is that this works only partially for a reason I can't explain: only one of the text labels can be displayed...
Read more >SVG Labels - Dagre D3 Demo
This allows the user to add any svg elements to the label. ... setDefaultEdgeLabel(function() { return {}; }); // Create the SVG label...
Read more ><text> - SVG: Scalable Vector Graphics - MDN Web Docs
The SVG <text> element draws a graphics element consisting of text. It's possible to apply a gradient, pattern, clipping path, mask, ...
Read more >How to use SVGs in React | Sanity.io guide
JSX supports all SVG tags. We can (almost) paste the SVG directly into our React components! This is the most straightforward method to...
Read more >Text — SVG 2
SVG's 'text ' elements are rendered like other graphics elements. ... For example, a text element that provides a visible label for part...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@naikus I have similar need - I want to have 2 lines in label. I’ve done some research and I was able to pass that text element to function. To be backward compatible I’m checking number of parameters:
so now I can declare gaube like this:
Not perfect but works just fine 😃 Here is my working demo: https://codepen.io/Misiu/pen/oEmVWw
Is there a chance this could be added?
Hi @pzontrop, The label function currently can only return plain text and not elements. The future version may have this functionality. Meanwhile you can label display via CSS and show whatever HTML in a div and place that div in the center of the gauge (e.g. via CSS transforms) and update the div in the label function