# d3tooltip

> A highly configurable tooltip for d3

Latest version **4.0.0** (published 2024-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install d3tooltip
pnpm add d3tooltip
yarn add d3tooltip
bun add d3tooltip
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-04-07 |
| First published | 2015-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14367 |
| Author | romseguy |
| Maintainers | timdorr, romseguy, zalmoxisus, methuselah96 |
| Keywords | d3, tooltip |

## Links

- npm: https://www.npmjs.com/package/d3tooltip
- Repository: https://github.com/reduxjs/redux-devtools
- Homepage: https://github.com/reduxjs/redux-devtools/tree/master/packages/d3tooltip
- Issues: https://github.com/reduxjs/redux-devtools/issues
- npm.io page: https://npm.io/package/d3tooltip

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2024-04-07
- 3.0.1 — 2023-12-09
- 3.0.0 — 2023-01-05
- 2.1.0 — 2022-01-25
- 2.0.0 — 2022-01-10
- 1.3.2 — 2022-01-08
- 1.3.1 — 2021-11-06
- 1.3.0 — 2021-03-06
- 1.2.3 — 2020-08-14
- 1.2.2 — 2016-01-11
- 1.2.1 — 2016-01-11
- 1.2.0 — 2016-01-11
- 1.0.2 — 2015-09-15

## README

# d3tooltip

This tooltip aims for a minimal yet highly configurable API. It has a long way to go, but the essentials are there.
It was created by [@romseguy](https://github.com/romseguy) and merged from [`romseguy/d3tooltip`](https://github.com/romseguy/d3tooltip).

## Installation

`npm install d3-state-visualizer`

## Quick usage

```javascript
import * as d3 from 'd3';
import { tooltip } from 'd3tooltip';

const DOMNode = document.getElementById('chart');
const root = d3.select(DOMNode);
const vis = root.append('svg');

const options = {
  offset: { left: 30, top: 10 },
  styles: { 'min-width': '50px', 'border-radius': '5px' },
};

vis
  .selectAll('circle')
  .data(someData)
  .enter()
  .append('circle')
  .attr('r', 10)
  .call(
    d3tooltip('tooltipClassName', {
      ...options,
      text: (d) => toStringOrHtml(d),
    }),
  )
  .on('mouseover', function () {
    d3.select(this).style('fill', 'skyblue');
  })
  .on('mouseout', function () {
    d3.select(this).style('fill', 'black');
  });
```

## API

| Option   | Type               | Default             | Description                                                                                                                                                      |
| -------- | ------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `root`   | DOM.Element        | `body`              | The tooltip will be added as a child of that element. You can also use a D3 [selection](https://github.com/mbostock/d3/wiki/Selections#d3_select).               |
| `left`   | Number             | `undefined`         | Sets the tooltip `x` absolute position instead of the mouse `x` position, relative to the `root` element.                                                        |
| `top`    | Number             | `undefined`         | Sets the tooltip `y` absolute position instead of the mouse `y` position, relative to the `root` element.                                                        |
| `offset` | Object             | `{left: 0, top: 0}` | Sets the distance, starting from the cursor position, until the tooltip is rendered. **Warning**: only applicable if you don't provide a `left` or `top` option. |
| `styles` | Object             | `{}`                | Sets the styles of the tooltip element.                                                                                                                          |
| `text`   | String or Function | `''`                | Sets the text of the tooltip. Can be a constant `string` or a function that takes the datum and returns a `string`.                                              |

---
_Source: https://npm.io/package/d3tooltip · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
