Skip to content

Suoritin III

Search
  • About

Monthly Archives: September 2015

Diverse coding | Kaikenlaista koodailua

Logo of Mikkeli as a D3 learning object

September 4, 2015 Tuija

After three weeks of the online course Data Visualization and Infographics by Knight Center I’m still very happy that I decided to participate. Alberto Cairo and Scott Murray make a good duo. It’s refreshing to hear Alberto’s solid, learned opinions, and Scott has this talent of lowering the barriers to learning.

This week, we have mostly been binding data to SVG rect elements. Related to this, as a side project of my own, I’ve practised the topic with the logo of the city of Mikkeli. It’s a delightfully colourful skyline, built from rectangles of the same size, with a color palette size of 8. The logo appears on the web site in two places: a tiny one in the header

Mikkeli logo header

and a much bigger one in the footer.

Mikkeli logo footer

First, colors. To get values that’d be at least to the right direction, I took a screenshot of the page, uploaded it to Gimp, and copied the hex values that the color picker tool returned.

Gimp color picker

Apologies for the graphic designers of the logo! It may well be that the logo follows the CMYK color model, not RGB at all.

Next, data. I pasted the hex values to a spreadsheet, reflecting the 5 x 32 rectangle structure of the logo. Background of the final web page would be ghostwhite (#f8f8ff) so I choose the same to fill the sky behind the skyline, although Mikkeli has #ffffff on their page. Sorry about that, too.

As an example, in the screenshot below, I’ve highlighted the cells that represent the first greenish block of rectangles, starting from the left.

Typing in color hex values

When I had data in CSV, it was time to figure out how to bind them to SVG elements.

It took me quite some time to realize that uploading data with d3.csv(), the way we had done in the course so far, and which seemed legit in my case here too, does not in fact preserve the order of the original spreadsheet columns. The result is an array of objects, but the order of them is not defined. Thanks to good advice, I reverted to d3.text() in uploading, and then parsed data with d3.cvs.parseRows() into an array of arrays – and there is order!

After this step, the rest was relatively easy. Note, relatively. I had reasoned though, that I better wrap every row of rects inside a group, so that I could define new coordinates for them in one go. First row would start from x=0 y=0, second from x=0 y=[height of rect], third x=0, y=[height of 1+1 rect], etc.

The way the horizontal positioning of rectangles is determined within groups, is explained (much better than I could do) by a helpful StackOverflow member like this:

Then, for each group, you can add the rectangles, adjusting the horizontal position only (the vertical position was already set in the containing group). Here, you need to bind the inner array elements to each rectangle.

Thank you, Mikkeli! Here is my take on your skyline. All the best!

D3.jsdata visualizationlogoMikkeliSVG

avoin data Borneo Costa Rica D3.js data visualization Europeana Facebook Finland force-directed graph Gephi Google Calendar Google Docs Google Refine Google Visualisation API HelMet API Helsinki Helsinki open data iCal JavaScript jQuery JSON(P) kalenterit kirjastoluokitus Kulosaari leaflet network graph open data Peru Python R RSS Shiny solita soRvi SPARQL tekoäly tekstinlouhinta Travel trees Twitter Twitter API Wikidata XSLT2 Yahoo Pipes YQL

  • Diverse coding | Kaikenlaista koodailua
  • History | Historiaa
  • Travel | Matkajuttuja

Stories about coding, travels, and history | Koodailua, matkoja ja historiaa

Recent Posts

  • Huomioita tekoälyn käytöstä sovelluskehityksessä, tapaus Solita. Osa 2 September 22, 2025
  • Kaupunkipyörä May 30, 2025
  • Madeira 2024 May 28, 2025
  • Sattui ja tapahtui February 22, 2025
  • Alkulauseita January 21, 2025

Archives

  • September 2025
  • May 2025
  • February 2025
  • January 2025
  • November 2024
  • October 2024
  • September 2024
  • January 2023
  • November 2022
  • October 2022
  • May 2021
  • April 2020
  • June 2019
  • January 2019
  • January 2018
  • June 2017
  • June 2016
  • January 2016
  • November 2015
  • September 2015
  • March 2015
  • January 2015
  • April 2014
  • March 2014
  • January 2014
  • March 2013
  • February 2013
  • July 2012
  • June 2012
  • March 2012
  • June 2011
  • May 2011
  • June 2010
  • May 2010
  • April 2010

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress