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

d3-parliament

v1.0.1

Published

A parliament chart based on d3

Downloads

31

Readme

d3 Parliament chart

Quick Start

Install with Bower

bower install d3-parliament

Use it!

/* set up the parliament */
var parliament = d3.parliament();
parliament.width(500).height(500).innerRadiusCoef(0.4);
parliament.enter.fromCenter(true).smallToBig(true);
parliament.exit.toCenter(false).bigToSmall(true);

/* register event listeners */
parliament.on("click", function(d) { alert("You clicked on a seat of " + d.party.name); });
parliament.on("mouseover", function(d) { console.log("mouse on " + d.party.name); });
parliament.on("mouseout", function(d) { console.log("mouse out of " + d.party.name); });

/* add the parliament to the page */
d3.json("data.json", function(d) {
    d3.select("svg").datum(d).call(parliament);
});

Documentation

Parameters

You can set up the parameters of the parliament passing the values through the function named as the parameter (see the example):

  • width Number = The max. width of the parliament (which will always be half a circle)
  • height Number = The max. height of the parliament (which will always be half a circle)
  • innerRadiusCoef Number = The coefficient applied to get the free space in the middle (min=0: no space; max=0.99: very few space for the seats)

Events

All the mouse and touch events that can be thrown on the circles that will represent the seats are available : click, dblclick, mousedown, mouseenter, mouseleave, mousemove, mouseout, mouseover, mouseup, touchcancel, touchend, touchmove, touchstart

You can register event listeners calling on. The first parameter given to the event listener is an object containing the following fields:

  • polar Object = The polar coordinates of the seat
    • r Number = radius
    • teta Number = angle
  • cartesian Object = The cartesian coordinates of the seat, origin is centered on the bottom of the chart
    • x Number = number of pixels on x axe from the origin
    • y Number = number of pixels on y axe from the origin
  • party Object = data of a party that you put in the array (see Data)
  • data Object = data of this seat (see Data)

Data

The data given to datum before calling parliament (see example) should be an array of objects, one object per party in the parliament. These objects should contain the fields:

  • id String = the unique id of the party
  • seats Array | Number = if it is a number, it is the number of seats for this party in the parliament ; if it is an Array, one element is a seat (or MP), you can put all you want in it (String, Object...), you will retrieve it as data field in your event listener.

Then, you can add more data if you want to retrieve them in your event listeners.

License

MIT License

TODO

  • Check the data to avoid infinite loop or division by zero
  • Animation enter from / exit to outside of the playground svg
  • Other? Let me know!