Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Data Visualization with D3 and AngularJS

You're reading from  Data Visualization with D3 and AngularJS

Product type Book
Published in Apr 2015
Publisher
ISBN-13 9781784398484
Pages 278 pages
Edition 1st Edition
Languages
Authors (2):
Erik Hanchett Erik Hanchett
Profile icon Erik Hanchett
Christoph Körner Christoph Körner
Profile icon Christoph Körner
View More author details

Table of Contents (16) Chapters

Data Visualization with D3 and AngularJS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Magic of SVG, D3.js, and AngularJS Getting Started with D3.js Manipulating Data Building a Chart Directive Loading and Parsing Data Drawing Curves and Shapes Controlling Transitions and Animations Bringing the Chart to Life with Interactions Building a Real-time Visualization to Monitor Server Logs Index

Interactive filters


Let's switch back to AngularJS for a section. To be precise, let's take a look at filters. Let's implement two filters that compare Date objects and returns the elements of an array that are greater than or equal to a specific date (gte_date) and less than or equal to a specific date (lte_d). First, we need to add a filter via the .filter(name, filter_func) function to the AngularJS chart component. The filter_func argument needs to return a function in the shape of function(arg1, arg2, …), where arg1 is usually the input array that finally returns the filtered array. Okay, let's implement this:

/* src/chart.js */
.filter('gte_date', function(){
  return function(input, raw_date){
    var date = new Date(raw_date);
    return isNaN(date.getTime()) ? input : input.filter(function(d){
      return d.x >= date;
    });
  };
})

.filter('lte_date', function(){
  return function(input, raw_date){
    var date = new Date(raw_date);
    return isNaN(date.getTime()) ? input...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}