crossfilter madjs

26
Crossfilter Fast Multidimensional Filtering for Coordinated Views

Upload: ethan-jewett

Post on 22-Apr-2015

1.214 views

Category:

Technology


0 download

DESCRIPTION

Intro to Crossfilter for the Madison Javascript meetup

TRANSCRIPT

Page 1: Crossfilter MadJS

CrossfilterFast Multidimensional Filtering for Coordinated Views

Page 2: Crossfilter MadJS

Data management and visualization consultant !

Project to develop a general purpose collaborative data management, transformation,

and visualization platform (GPCDMTVP for short).

!

You can find me at http://esjewett.com or @esjewett”

Page 3: Crossfilter MadJS

We’ve got problems

Page 4: Crossfilter MadJS

More specifically

We’ve got data

Page 5: Crossfilter MadJS

and filters

Page 6: Crossfilter MadJS

and aggregations

Page 7: Crossfilter MadJS

and speed

Page 8: Crossfilter MadJS

DemoMoritz Stefaner’s “Elastic Lists” experiment

Page 9: Crossfilter MadJS

Demo review

• We control the data

• Many different simultaneous filters

• Aggregation: count

• Data in the browser … in Flash

Page 10: Crossfilter MadJS

What would a general-purpose approach to this

problem look like?Let’s just call it … say … Crossfilter

Page 11: Crossfilter MadJS

Javascript(am I at the right meetup?)

Page 12: Crossfilter MadJS

Data is encapsulated!

var data = [ { date: ‘2014-01-01’,!!! ! ! ! ! ! value: 10,!!! ! ! ! ! ! color: ‘orange’ },!!! ! ! ! { … },!!! ! ! ! ! … ];!!

var transactions = crossfilter(data);!

Page 13: Crossfilter MadJS

and dimensional

!

var dateDim = transactions.dimension( ! function (d) {! return “” + d.date;!! }!);!

Page 14: Crossfilter MadJS

Filter on dimensions!

dateDim.filter(“2014-01-01”);!!

!

!

!

!

!

!

Page 15: Crossfilter MadJS

Filter on dimensions!

dateDim.filter(“2014-01-01”);!dateDim.filter([“2013-01-01”,”2014-01-01”]);!!

!

!

!

!

!

Page 16: Crossfilter MadJS

Filter on dimensions!

dateDim.filter(“2014-01-01”);!dateDim.filter([“2013-01-01”,”2014-01-01”]);!dateDim.filter( ! function (d) {! return d === “2013-06-01”;! }!);!!

Page 17: Crossfilter MadJS

Filter on dimensions!

dateDim.filter(“2014-01-01”);!dateDim.filter([“2013-01-01”,”2014-01-01”]);!dateDim.filter( ! function (d) {! return d === “2013-06-01”;! }!);!dateDim.filterAll();!

Page 18: Crossfilter MadJS

Aggregate on dimensions

!

// Count transactions per day!var dateGroup = dateDim.group();!

Page 19: Crossfilter MadJS

Aggregate on dimensions

!

// Count transactions per month!var monthGroup = dateDim.group(! function (d) {! return d.substr(1,7);! }!);!

Page 20: Crossfilter MadJS

Aggregate on dimensions!

// Sum by value over groups of days!dateGroup.reduceSum(! function (d) {! // “d” is the complete record! return d.value;! }!);!

Page 21: Crossfilter MadJS

“Queries”!// Month with most activity under current filter!monthGroup.top(1);!// { key: “2013-06”, value: 435 }!!// Day with highest value under current filter!dateGroup.top(1);!// { key: “2013-12-24”, value: 143700 }!!// Get all the months values under current filter!monthGroup.all();!// [ { key: “2013-06”, value: 435 },!// { key: “2013-12”, value: 315 },!// { key: “2013-02”, value: 250 }, … ]!

Page 22: Crossfilter MadJS

So what about speed?

Page 23: Crossfilter MadJS

Demo

Page 24: Crossfilter MadJS

Some notes

• Dimension accessors must return naturally ordered values. Cast before returning!

• reduce(add, remove, initial)

• order(ordering)

• groupAll()

Page 25: Crossfilter MadJS

Ethan Jewett!

esjewett.com / coredatra.com

@esjewett

https://github.com/esjewett

Page 26: Crossfilter MadJS

Links

• Crossfilter - http://square.github.io/crossfilter/

• Crossfilter API - https://github.com/square/crossfilter/wiki/API-Reference

• Moritz Stefaner’s Elastic Lists - http://moritz.stefaner.eu/projects/elastic-lists/