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

D3.js plugin to simplify the grouping and processing of data by allowing you to quickly filter, combine then reduce a data-set in a single operation.

License

Notifications You must be signed in to change notification settings

lachlanmcdonald/d3-group

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

d3-group

D3.js plugin to simplify grouping and processing data.

Example

The following will loop over the input, grouping together objects with a value less than 30. Matching elements will be removed from the input, replaced with a new element that combines the value of all of the matches.

var a = [
	{name: 'A', value: 16},
	{name: 'B', value: 10},
	{name: 'C', value: 38},
	{name: 'D', value: 44},
	{name: 'E', value: 40},
	{name: 'F', value: 29},
	{name: 'G', value: 25}
];
var output = d3.group()
	.entries(a)
	.on(function(d) {
		return d.value < 30;
	})
	.by(function(matches) {
		var sum = d3.sum(matches, function(d) {
			return d.value;
		});
		return {
			name: 'Other',
			value: sum
		};
	});

output will contain:

[
  {name: 'C', value: 38},
  {name: 'D', value: 44},
  {name: 'E', value: 40},
  {name: 'Other', value: 80}
]

About

D3.js plugin to simplify the grouping and processing of data by allowing you to quickly filter, combine then reduce a data-set in a single operation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published