Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

A simple D3.js plugin that ensures an array of numbers, when rounded down, sum to 100 (or some other arbitrary number) whilst retaining the original element order.

License

Notifications You must be signed in to change notification settings

lachlanmcdonald/d3-apportionment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

d3-apportionment

d3-apportionment is a simple D3.js plugin to ensures that an array of numbers, when rounded down, sum to 100 (or some other arbitrary number) whilst retaining the original element order. Implementation of the "Largest Remainder" method (the Hare-Niemeyer method).

Usage

d3.apportion(input, total)

  • input must be an array of numbers.
  • total defaults to 100 if not omitted.
d3.apportion([49.1, 24.9, 12.5, 12.4]); // [50, 25, 13, 12]
d3.apportion([24.9, 12.5, 12.4], 50);   // [25, 13, 12]

About

A simple D3.js plugin that ensures an array of numbers, when rounded down, sum to 100 (or some other arbitrary number) whilst retaining the original element order.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published