background preloader

Thinking with Joins

Thinking with Joins
Say you’re making a basic scatterplot using D3, and you need to create some SVG circle elements to visualize your data. You may be surprised to discover that D3 has no primitive for creating multiple DOM elements. Wait, WAT? Sure, there’s the append method, which you can use to create a single element. svg.append("circle") .attr("cx", d.x) .attr("cy", d.y) .attr("r", 2.5); But that’s just a single circle, and you want many circles: one for each data point. svg.selectAll("circle") .data(data) .enter().append("circle") .attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y; }) .attr("r", 2.5); This code does exactly what you need: it creates a circle element for each data point, using the x and y data properties for positioning. Here’s the deal. Data points joined to existing elements produce the update (inner) selection. Now we can unravel the mysterious enter-append sequence through the data join: But why all the trouble? Likewise, to shrink-out: Related:  d3.jsD3.js

D3 Tutorials <div id="js_warning"><strong>JavaScript is turned off, so this page won&rsquo;t be very interactive.</strong> Switch JavaScript back on in your web browser for the full experience.</div> These tutorials have been expanded into a book, Interactive Data Visualization for the Web, published by O’Reilly in March 2013. Purchase the ebook and print editions from O’Reilly. A free, online version includes interactive examples. Election site part 1: Basics with Knockout.js, Bootstrap and d3.js This article shows how you can use knockout.js, Twitter's Bootstrap and d3.js together to create a javascript application that creates visually pleasing graphics and diagrams to your users. This is complete client side solution that only communicates with REST to the server. This is part 1 of a series of articles discussing these concepts. In this first article we'll look at setting up the basic application and we'll demonstrate how to use knockout.js, bootstrap and d3.js. It's a bit too much to show all the javascript in this article. You can find the demo for this version (with a couple more features) at this url: The case In the Netherlands, where I live, we have a tendency of our chosen leaders not serving their terms. Creating an election map These updates, and the way they are presented is kind of interesting. US elections Which tools will we use? Show complete map, with colors representing a specific value Connect all the things

Server Download - Repetier Software | Repetier Software Repetier-Server is a multi-printer multi-connection printer server to handle the communication with 3d printer. Design targets were: Small memory usage. Should run on a Raspberry PI with 256MB RAM. The software is quite new. For linux this is an easy task if you follow the INSTALL.txt instuctions. Versions prior 0.24 had a memory leak. I’m currently in the process of creating an installer for each os. Raspberry PI If you have only 256MB RAM you can not compile the sources. Windows Coming soon. Mac OS X Coming soon. Version 0.22 ASCII mode now works properly.

Nested Selections D3’s selections can be hierarchical, much like the elements and data they join. Consider a table: <table><thead><tr><td> A</td><td> B</td><td> C</td><td> D</td></tr></thead><tbody><tr><td> 0</td><td> 1</td><td> 2</td><td> 3</td></tr><tr><td> 4</td><td> 5</td><td> 6</td><td> 7</td></tr><tr><td> 8</td><td> 9</td><td> 10</td><td> 11</td></tr><tr><td> 12</td><td> 13</td><td> 14</td><td> 15</td></tr></tbody></table> How would you select only the body cells? var td = d3.selectAll("tbody td"); Alternatively, select the tbody element first, then select the td elements within: var td = d3.select("tbody").selectAll("td"); This produces the same result because selectAll, for each element in the current selection, selects the matching descendants. #Nesting and Index If you select the td elements using d3.selectAll, you get a flat selection, like so: Flat selections lack hierarchical structure: the table cells are merged into a single array, rather than grouped by parent row. #Nesting and Data

Documentation Learn the basics of D3 with this introductory tutorial, covering the core concepts of selections and data binding. Read me first! Using the example of a no-frills, static bar chart, this guide describes the core D3 concepts, including selections, functional properties, and scales. A continuation of the above introductory tutorial, this guide covers more exciting dynamic aspects of D3, including transitions and data joins. An introduction to D3 for users of Protovis. Eurozone crisis This graphic attempts to visualise how the Eurozone crisis developed over time. Seven key indicators are shown for the Eurozone and each of the original 12 Eurozone members. The outer radius of the ring shows the maximum within the Eurozone for a given month and the inner radius the minimum. The thick blue line shows the median. The scales of the indicators are arranged such that up in the graph means good and down bad. The indicators are as follows. GDP growth. Increase in total economic output. Surplus. Government surplus or deficit. Interest. Interest rate payable on government 10 year bonds. Debt. Total government debt. Unemployment. Overall unemployment rate. Inflation. Change in price levels. Investments. Investments as measured by Gross fixed capital formation. Compared to 2006, the picture at the end of 2011 is different in two main ways. For the purposes of this graph, the Eurozone is always composed of the 12 countries listed on the left.

RaspberryPi Fondles Wii-Nunchuck, Controls LED-Stripe Panel, Plays Snake » shackspace = der hackerspace in stuttgart Allgemein Januar 22nd, 2013 shackspace hacker @4RM4 was looking for something to hack when he visited 29c3. He found someone who was selling RGB-LED stripes with individually addressable LEDs which was (understandably) irresistible and he already had a RaspberryPi to control it with. He improved his snake clone by adding a high-score feature, auto-play bot, support for free dot placement for debugging, and a clock display in idle mode. Playing it got even more fun with a Wii-Nunchuck hooked up to the RasPi which was quite easy since he could use the Pi’s GPIO port to talk to the Nunchuck’s I2C interface. Of course the full code is available on GitHub and there’s some documentation (in German) on the shackspace wiki.

How Selections Work Any sufficiently advanced technology is indistinguishable from magic. –Arthur C. Clarke In the past I have presented simplified descriptions of D3’s selections, providing only enough detail to get started. This article takes a more comprehensive approach; rather than saying how to use selections, I will explain how selections are implemented. This may take longer to read, but it should dispel any magic and help you master data-driven documents. The structure of this article may at first seem arbitrary. D3 is a visualization library, so this article incorporates visual explanations to accompany the text. var array = [42]; Wherever possible, the code that generates the given selection appears immediately above the diagram. Let’s begin. #A Subclass of Array You were probably told that selections are arrays of DOM elements. #Grouping Elements var selection = d3.select("body"); Likewise, d3.selectAll returns a selection with one group and any number of elements: d3.selectAll("h2"); #Null Elements

d3.js experiments in the console | the evolving ultrasaurus d3 (aka Data-Driven Documents) is a great little JavaScript framework for data visualization. It’s got a nice declarative syntax for DOM manipulation that’s quite readable, but takes a bit of effort to understand exactly what it’s doing. Favorite links: UPDATE: Dashing D3.js is an amazing series of tutorials with great conceptual groundingd3 tutorials provide a great conceptual foundationThinking with Joins by d3 creator, Mike Bostick, helps explain the syntax for chaining methodsScott Murray’s d3 tutorial offers a very nice step-by-step, covering a lot of the same ground as my little tutorial below with excellent discussions of the fundamentals. I like to understand stuff by playing with it interactively, so I created a skeleton index.html which just includes d3.js and a style a div where I’ll display some data. UPDATE: blank file below posted here Then in the FireBug console, we can interact with d3, the top-level object that allows us to access all of d3′s goodness. and “Hello d3!”

Transitioning innerRadius of svg.arc - D3.js

Related: