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 🙏

© 2026 – Pkg Stats / Ryan Hefner

parlia

v0.2.2

Published

Create SVG parliament diagrams

Readme

Parlia is a browser-based javascript library for building parliament diagrams in SVG format.

It's written in pure javascript with the aim to be minimal with zero dependencies while still offering various settings.

Test it out here.

Installation

Install from npm with npm i parlia or get parlia.js from this repo, put it in your project and include it in your page:

<script src="./parlia.js"></script>

Usage

There are only two mandatory arguments you need to provide to the main method, a reference to a SVG element and the parties data.

let svg = document.getElementById("svg");
let data = [[1, "red", "Party 1", 12], [2, "blue", "Party 2", 12]];

Parlia.drawParliament(svg, data);

This would generate the following diagram:

The data has to be given as an array with items describing each party, either as other arrays, where each one has the following format: [id, color, name, seats]; or objects with properties {id, color, name, seats}; where id is unique number, e.g.:

[... [7, "#f00", "My Party", 56], ...]

// or

[... {id: 7, color: "#f00", name: "My Party", seats: 56}, ...]

Alternatively, you can load from a CSV file:

id,color,name,seats
7,#f00,My Party,56
...

Documentation

Public methods:

  • drawParliament()

Main function, does all the calculations for the given arguments and draws the parliament in the given SVG DOM object.

Returns an object with the total number of seats in the parliament and the number of actually drawn seats. If the proportion values are too extreme, there might not be enough room for all the seats and these two values will not be equal. Instead of throwing an exception, a warning caption is drawn over the parliament.

Parameters

svg - Reference to the SVG DOM object where the parliament is drawn.

data - Array of parties. Parties are represented as either objects with four properties:

`id` - number - unique id

`color` - string - color of party seats, given as a name or hexidecimal value

`name` - string - party name

`seat` - number - number of seats

or arrays with four items, each taking the given properties in the given order.

rInner - A number representing the inner radius of the parliament as a fraction of the total width of the parliament, or the "thickness" of the parliament. E.g. a value of 5 means the inner radius is 1/5 of the parliament width. Defaults to 5.0.

rDenom - A number representing the denominator in the fraction that is the ratio of the side of a square with area equal to each seat's share of the parliament, to the radius of the actual seat. A value of 2.5 means the ratio of side to radius is 1/2.5. Defaults to 2.5.

sortField - A number determining which party property will the parties be sort by in the parliament. 0 for id, 1 for name, 3 for seats. Default is 0.

sortOrder - A number determining the sort order. 0 for ascending, 1 for descending, 2 for alternating. Default is 0.

border - Draw a border around each seat. Default is true.

shadow - Draw a shadow under each seat. Default is true.

background - Parliament background color. Default is #f2f2f2.

padding - Padding between the edge of the SVG element and the parliament in pixels. Default is 12.

centralAngle - A number representing the central angle over which the parliament spans in degrees. Only values between 1 and 180 have effect. Default is 180.

Return value

An object with two properties:

seatsTotal - Sum of seats of all parties in the given data.

seatsDrawn - Total number of seats drawn in the parliament.

  • drawError()

Draw a caption with an error message over the parliament. Called when the arguments of drawParliament() don't allow all the seat to be drawn.

Parameters

svg - Reference to the SVG DOM object where the parliament is drawn.

title - Title of the caption.

subtitle - Subtitle of the caption.

  • downloadParliament()

Download the generated SVG.

Parameters

svg - Reference to the SVG DOM object where the parliament is drawn.

  • parseFromCsv()

Reads from a CSV file and parses to the preferred data format. Throws exceptions if the data is not in the correct format.

Parameters

file - A File object.

  • parseToCsv()

Write the parties to a CSV file.

Parameters

data - An array of parties.

Public properties:

  • selectedParties

A Set of class names for the parties that are currently selected. Selected parties' seats have full opacity. Empty list means everything is selected (default).