d3-svg-annotation is a D3.js module designed to streamline the process of adding various types of annotations to SVG-based data visualizations. It provides a flexible API for creating notes, connectors, and subjects directly on a D3-rendered chart, offering configurable styling, text wrapping, and dynamic positioning. The current stable version is 2.5.1. The package maintains a release cadence focused on addressing bugs and implementing minor feature enhancements, with significant breaking changes typically reserved for major version bumps. Its primary differentiation lies in its tight integration with the D3 ecosystem, providing a programmatic way to add rich context and explanations to complex charts without needing separate HTML overlays or manual SVG manipulation.
npm install d3-svg-annotationVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a basic D3 SVG container, define annotation data points, configure the annotation generator, and render two different types of annotations on the SVG.
Remove any `<link>` tags or `@import` statements referencing `d3-annotation.css` when upgrading to v2.x. Adjust custom styling to use the library's API or direct CSS for SVG elements.
Upgrade to `d3-svg-annotation@2.3.2` or later to ensure complete and correct TypeScript type definitions for `notePadding`.
Verify the script loading order in your HTML: `<script src="path/to/d3.min.js"></script><script src="path/to/d3-annotation.min.js"></script>`.
Always ensure D3 is a separate dependency and loaded correctly when using versions 1.14.0 or newer. This is typically handled automatically by bundlers like Webpack or Rollup when using NPM imports.
For script tags, ensure D3 loads first. For modules, use `import { annotation } from 'd3-svg-annotation';` and ensure `d3` is also imported or globally available.Update `d3-svg-annotation` to version `2.3.2` or higher to resolve the missing type definition for `notePadding`.
Upgrade `d3-svg-annotation` to version `1.17.0` or later to fix issues related to note label display and whitespace handling.