3.3.0 โ€ข Published 10 months ago

@visx/annotation v3.3.0

Weekly downloads
10,093
License
MIT
Repository
github
Last release
10 months ago

@visx/annotation

SVG Annotations enable you to label points, thresholds, or regions of a visualization to provide additional context to for your chart consumer. This package is heavily inspired by Susie Lu's react-annotation library.

Each annotation consists of three (optional) parts:

  1. Subject (CircleSubject, LineSubject, more ๐Ÿ”œ) โ€“ what part of a chart is being annotated (point, line, region)

  2. Label โ€“ย the text component for the annotation. Handles SVG text wrapping using @visx/text, and supports title and subtitle customization as well as vertical & horizontal anchors / alignment

  3. Connector โ€“ line connecting a subject and label

The Annotation or EditableAnnotation component wrappers allow you to compose these components and simplify their individual positioning:

<EditableAnnotation
  x={subjectX}
  y={subjectY}
  dx={labelDx} // x offset of label from subject
  dy={labelDy} // y offset of label from subject
  onDragEnd={({ x, y, dx, dy }) => ...}
>
  <Connector />
  <CircleSubject />
  <Label title="Context about this point" subtitle="More deets">
</EditableAnnotation>

Components can also be used in isolation, in which case you must specify exact positions for each item:

() => (
  <g>
    <Connector x={subjectX} y={subjectY} dx={labelDx} dy={labelDy} />
    <CircleSubject x={subjectX} y={subjectY} />
    <Label x={subjectX + labelDx} y={subjectY + labelDy} title="...">
  </g>
)
โš ๏ธ ResizeObserver dependency

The Label component relies on ResizeObservers for auto-sizing. If you need a polyfill, you can either polute the window object or inject it cleanly through props:

import { ResizeObserver } from 'your-favorite-polyfill';

function App() {
  return <Label resizeObserverPolyfill={ResizeObserver} {...} />

Installation

npm install --save @visx/annotation
3.3.0

10 months ago

3.0.1

1 year ago

2.17.0

1 year ago

2.18.0

1 year ago

3.0.0

1 year ago

2.17.0-alpha.0

1 year ago

2.12.2

2 years ago

2.11.1

2 years ago

2.10.0

2 years ago

2.10.0-alpha.0

2 years ago

2.7.0

2 years ago

2.6.0

2 years ago

2.9.0

2 years ago

2.8.0

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.0

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.1-alpha.0

3 years ago

3.0.0-alpha.0

3 years ago

1.18.1

3 years ago

1.17.1

3 years ago

1.15.0

3 years ago

1.16.0

3 years ago

1.14.0

3 years ago

1.12.0

3 years ago

1.11.1

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.4

3 years ago

1.7.2

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.3.0-alpha.0

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.200-alpha.0

4 years ago