Fun with <text>
This demo shows three different SVG techniques for giving `<text>` elements a white outline so they remain readable on varied backgrounds: two stacked text elements with a thick stroke, one text element using the `paint-order` attribute, and a `<filter>` with `feMorphology`, `feColorMatrix`, and `feMerge` effects. A dark green backdrop provides contrast. The D3 v4 code includes zooming and panning via `d3.zoom`, and interactive controls adjust font size, stroke width, rotation, and other text properties. Users can set initial camera position and parameters through URL search parameters.
AI-generated descriptionIf one wants to give a SVG <text> an outline effect, e.g. so it can be
displayed on many different backgrounds (any color, dark, bright, patterns…),
there are various approaches. In this demo three are shown (the first two are
very similar though):
Example 1: Two
<text>elements, the one with white thick stroke behind the other one.Example 2: Similar to the previous example only here is only one
<text>element and instead thepaint-orderattribute is used so the stroke is painted behing the fill. This attribute is not part of SVG 1.1 though and not supported by browsers such as Internet Explorer 11 or Microsoft Edge (as of EdgeHTML version 15).Example 3: A
<filter>with multiple filter effects merged inside in order to achieve the effect.
Panning/Zooming on the map is possible (e.g. using the mouse).
Additionally, there are various controls to test the behaviors especially in very dynamic applications.
A link can be created to start at a certain camera position or with certain default values. How to do it is left as an exercise to the reader.