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

odc-d3-svg-legend

v3.0.0

Published

A legend component for d3. Given a d3.scale it can create either a color legend, size legend, or symbol legend. Fork of d3-svg-legend updated to d3.js v7

Downloads

93

Readme

d3-legend

Full documentation: http://d3-legend.susielu.com

Looking for compatibility with d3 v3?

  • You can see the code for the d3 legend that works with d3 v3 in the v3 branch
  • Documentation for the v3 version of the legend

d3-legend v4 updates (npm version 2.0.0 and higher)

  • Flattened naming for accessing functions
    • d3.legend.color => d3.legendColor
    • d3.legend.size => d3.legendSize
    • d3.legend.symbol => d3.legendSymbol
  • NPM package no longer binds to global d3, is now just an object with the three legend functions

Usage

Using just the minified file

You must include the d3 library before including the legend file. Then you can simply add the compiled js file to your website:

  • d3-legend.min.js
  • d3-legend.js (Human readable version)

Using CDN

You can also add the latest version of d3-legend hosted on cdnjs.

Using npm

You can add the d3 legend as a node module by running:

npm i d3-svg-legend -S

To use the version compatible with d3v3 run: npm i [email protected] -S

Using the import syntax import legend from 'd3-svg-legend' gives access to the three legend types as an object. You can also import them independently for example import { legendColor } from 'd3-svg-legend'

var svg = d3.select("#svg-color-quant");

var quantize = d3.scaleQuantize()
    .domain([ 0, 0.15 ])
    .range(d3.range(9).map(function(i) { return "q" + i + "-9"; }));

svg.append("g")
  .attr("class", "legendQuant")
  .attr("transform", "translate(20,20)");

var colorLegend = d3.legendColor()
    .labelFormat(d3.format(".2f"))
    .useClass(true)
    .scale(quantize);

svg.select(".legendQuant")
  .call(colorLegend);

Local development

This project uses npm and grunt, you will also need to run npm install -g grunt-cli for the scripts and watch commands to work.

Feedback

This library is in maintence mode, and I do not plan on adding any additional features.