SVG Icons in JS
This example demonstrates how to embed SVG icons directly in JavaScript code as template strings, avoiding the need for separate image files. It displays three icons from heroicons.com—an arrow path, an external link, and a gear—centered in a flexbox layout. Using D3.js, the code maps over the icon keys and injects the SVG markup into div elements via the `.html()` method, then resizes each icon to 250 pixels wide. The approach highlights a clean, dependency-light way to manage icons in web visualizations.
AI-generated descriptionThis is in response to a question in the VizHub Discord on how to put icons in JavaScript and not use a bunch of image files.
This shows some random icons from https://heroicons.com/
Sometimes SVGs are larger than necessary. Try this tool and see if you can reduce the sizes: https://jakearchibald.github.io/svgomg/