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:

Adding an SVG Element | DashingD3js.com Basic Example In the last example you added a p HTML element to the DOM. In this example, you will use D3.js to add an SVG element to a basic webpage. Per our previous SVG examples , you will add an SVG circle to the webpage. Start with a basic HTML webpage: 1<! Recall that an SVG circle can be created as such: 1<svg width="50" height="50">2 <circle cx="25" cy="25" r="25" fill="purple" />3</svg> Next open the Developer Tools (Webkit Inspector). 1d3.select("body").append("svg").attr("width", 50).attr("height", 50).append("circle").attr("cx", 25).attr("cy", 25).attr("r", 25).style("fill", "purple"); This will give you the following: Congratulations - you've added an SVG element to the DOM using D3.js! D3.js Legibility As you progress further into D3.js, the code that you write will go from a few lines to potentially a couple hundred lines. It is hard to follow what is happening all the way through. JavaScript, much like HTML, does not care about white spaces or new line breaks. D3.js Chain Syntax

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

From Shapefile to GeoJSON - Jim Vallandingham A method for editing, merging, simplifying, and converting Shapefiles to GeoJSON D3.js supports cartographic visualizations by being able to display lines, polygons, and other geometry objects . It uses GeoJSON as the storage format for this type of visualization. Likewise, map tiling libraries like Leaflet can use GeoJSON to create map layers . You can find some GeoJSON files around, like in D3’s choropleth example , but sooner or later you will want to visualize a more specific portion of the world. Specifically, I am interested in visualizing census data for my hometown: Kansas City. Below is how I created a small GeoJSON file of just the KC metro from census shapefiles. WARNING: I am not an expert in GIS or cartography in general. Tools I’m using a mix of different applications to perform this conversion: Quantum GIS is used to deal with shapefiles. brew install gdal Initially I did run into an issue with homebrew when it was installing the geos prerequisite. Getting the Data And presto!

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

Setup Last updated 2014 February 22 Downloading D3 Start by creating a new folder for your project. Within that folder, I recommend creating a sub-folder called d3. Then download the latest version of d3.v3.js into that sub-folder. As of this writing, the current version of D3 is 3.4.2. D3 is also provided in a “minified” version, d3.v3.min.js, from which whitespace has been removed for smaller file sizes and faster load times. A third option is to download the entire D3 repository, which gives you not just the JavaScript files, but also all of the component source code. Referencing D3 Create a simple HTML page within your project folder named index.html. project-folder/ d3/ d3.v3.js d3.v3.min.js (optional) index.html Now paste the following into your HTML file, so it references D3 in the head and provides room for your JavaScript code: <! Viewing Your Page In some cases, you can just open your HTML file in a web browser to view it. Next up: Adding elements →

Ceramic Hotend - Part 1 Finally one of the first posts about the DLP printer. For more then one year now we are discovering the DLP printer and testing it to it's limits. A superb way of printing, high quality and well detailed prints you can make. Here are some images of things we have printed with our DLP printer. For more images have a look at: And watch our youtube channel: to be continued arrays - PHP array_filter with arguments The world’s top 50 billionaires: A demographic breakdown. Top 50 Billionaire Breakdown If you asked anyone to picture the wealthiest person in the world at any given time, you could bet on some common denominators: probably a man; probably somehow attached to the words “multinational” or “conglomerate”; probably on a yacht off a private island. With Slate’s Top 50 Billionaire Breakdown, we attempt to visualize the richest of the rich by paring them into demographic categories: age, location, industry, source of wealth, education, and religious affiliation. Some of the sortings are heartening: There are more self-made men than born-rich kids in the top 50, and the self-made billionaires’ total wealth is bigger. A note on methodology: To determine rankings for the top 50, we first consulted the most recent Forbes World's Billionaires List, but then switched to the Bloomberg Billionaires list, which updates daily and is a typically snazzy and info-dense product of Bloomberg Visual Data.

Related: