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

Listen for events


Interactions in JavaScript are based on the concept of events and event listeners. This concept works like this: first, one defines an event listener on an element. Then, it waits for a specific event of the element to occur, for example, this could be a click event. Every time the event occurs (the element is clicked on), a callback function is executed. Having said that, we can attach listeners to any element of the DOM and trigger functions as soon as the event occurs.

In D3.js, we can attach listeners directly to Selections via the .on(event, callback) method. Whenever D3.js handles an event, the d3.event variable stores all the information of the currently triggered event. Let's look at a simple example:

svg.on('click', function(){

  var e = d3.event;

  // Get relative cursor position
  var xpos = (e.offsetX==undefined) ? e.layerX : e.offsetX;
  var ypos = (e.offsetY==undefined) ? e.layerY : e.offsetY;

  svg.append("circle")
    .attr("cx", xpos)
    .attr("cy", ypos...
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}