npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@phbalance/d3-tooltip

v1.0.1

Published

Small library for generating svg tooltips using foreignObject.

Downloads

5

Readme

A tooltip library for D3

Add tooltips to your D3 charts. Implemented using TypeScript.

Version 0.1.2 is the last version that supports D3 versions 1 through 5 (i.e. version that use d3-selection@1). Versions 1.0.1+ supports D3 versions 6+.

Getting Started

Installation

npm install --save @phbalance/d3-tooltip

Prior to version 1.0 you needed to install the peer d3-selection yourself although NPM 7 does this for you now.

npm install --save @phbalance/d3-tooltip
npm install --save d3-selection # peer dependency of a library

Use

import { ITooltipConfig, Tooltip } from "@phbalance/d3-tooltip";

...

// Setup your d3 selection to have the data.tooltip property. It should be sufficient
// to have your datum to contain the tooltip property and then make sure you're doing
// a join. Something like this:
const svg = create("svg");
const selection = svg
    .selectAll("rect")
    .data(yourData);

const tooltipConfig: ITooltipConfig<IFlexibleBarChartDatum> = {
    rounded: true,
    bubbleWidth: bubbleWidth,
    bubbleHeight: -1,
    bubbleStroke: "red",
    bubbleStrokeWidth: bubbleWidth / 150,
    bubbleTip: {tipOffset: (3 / 4 * bubbleWidth / 9), h: 10, edgeOffset: bubbleWidth / 9},
    chartWidth: width,
    chartHeight: width,
    backgroundColour: "#F8F8F8",
    backgroundOpacity: 0.9,
    getData: (d: IFlexibleBarChartDatum) => d.tooltip,
};

const tooltip = new Tooltip<IFlexibleBarChartDatum>(svg, tooltipConfig);
const tooltipMouseover = tooltip.mouseoverHandler();
const tooltipMouseout = tooltip.mouseoutHandler();
const tooltipMousemove = tooltip.mousemoveHandler();

// Bind it to the d3 selection(s) that you want to show tooltips.
selection
    .enter()
        .on("mouseover", tooltipMouseover)
        .on("mouseout",  tooltipMouseout)
        .on("mousemove", tooltipMousemove);

API

When creating a new Tooltip you pass in the svg that needs the tooltips. Inside this svg, the Tooltip will create a g element with a class of tooltip-group. Creating Tooltip (i.e. new Tooltip(svg, ...)) more than once is fine with the same svg as it will reuse an already existing g.tooltip-group.

The generated tooltip object contains 3 event handlers. You will want to bind at least the mouseover and mouseout handlers, but if you don't want your tooltip to follow the mouse around inside the selection, you don't need to bind it. If you don't being the mousemove, the tooltip will be pointing to the spot you entered the selection.

When an event handler is called, the getData function that was passed into the tooltipConfig is called to find the tooltip HTML.

Reporting Issues

You can report bugs here. Feel free to make suggestions as well.