{"id":293,"date":"2015-09-04T17:17:41","date_gmt":"2015-09-04T14:17:41","guid":{"rendered":"http:\/\/tuijasonkkila.fi\/?p=293"},"modified":"2024-09-20T13:22:04","modified_gmt":"2024-09-20T10:22:04","slug":"logo-of-mikkeli-as-a-d3-learning-object","status":"publish","type":"post","link":"https:\/\/tuijasonkkila.fi\/?p=293","title":{"rendered":"Logo of Mikkeli as a D3 learning object"},"content":{"rendered":"<p>After three weeks of the online course <a href=\"https:\/\/knightcenter.utexas.edu\/blog\/00-16133-sign-popular-knight-center-data-visualization-and-infographics-course-summer\">Data Visualization and Infographics<\/a> by <a href=\"https:\/\/knightcenter.utexas.edu\/\">Knight Center<\/a> I&#8217;m still very happy that I decided to participate. Alberto Cairo and Scott Murray make a good duo. It&#8217;s refreshing to hear Alberto&#8217;s solid, learned opinions, and Scott has this talent of lowering the barriers to learning.<\/p>\n<p>This week, we have mostly been binding data to SVG <a href=\"http:\/\/www.w3.org\/TR\/SVG\/shapes.html#RectElement\">rect<\/a> elements. Related to this, as a side project of my own, I&#8217;ve practised the topic with the logo of the city of <a href=\"http:\/\/www.mikkeli.fi\/\">Mikkeli<\/a>. It&#8217;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<\/p>\n<p><a href=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626-300x187.png\" alt=\"Mikkeli logo header\" class=\"alignnone size-medium wp-image-298\" width=\"300\" height=\"187\" srcset=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626-300x187.png 300w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626-1024x640.png 1024w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626-624x390.png 624w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111626.png 1920w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>and a much bigger one in the footer.<\/p>\n<p><a href=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643-300x187.png\" alt=\"Mikkeli logo footer\" class=\"alignnone size-medium wp-image-299\" width=\"300\" height=\"187\" srcset=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643-300x187.png 300w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643-1024x640.png 1024w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643-624x390.png 624w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-111643.png 1920w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>First, colors. To get values that&#8217;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.<\/p>\n<p><a href=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854-300x187.png\" alt=\"Gimp color picker\" class=\"alignnone size-medium wp-image-301\" width=\"300\" height=\"187\" srcset=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854-300x187.png 300w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854-1024x640.png 1024w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854-624x390.png 624w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-121854.png 1920w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Apologies for the graphic designers of the logo! It may well be that the logo follows the CMYK color model, not RGB at all.<\/p>\n<p>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.<\/p>\n<p>As an example, in the screenshot below, I&#8217;ve highlighted the cells that represent the first greenish block of rectangles, starting from the left.<\/p>\n<p><a href=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246-300x187.png\" alt=\"Typing in color hex values\" class=\"alignnone size-medium wp-image-316\" width=\"300\" height=\"187\" srcset=\"https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246-300x187.png 300w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246-1024x640.png 1024w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246-624x390.png 624w, https:\/\/tuijasonkkila.fi\/wp-content\/uploads\/2015\/09\/Screenshot-from-2015-09-04-171246.png 1920w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>When I had data in CSV, it was time to figure out how to bind them to SVG elements.<\/p>\n<p>It took me quite some time to realize that uploading data with <code>d3.csv()<\/code>, 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 <a href=\"http:\/\/stackoverflow.com\/questions\/31183691\/d3-js-wrong-column-order-in-csv-file\/31186097#31186097\">good advice<\/a>, I reverted to <code>d3.text()<\/code> in uploading, and then parsed data with <code>d3.cvs.parseRows()<\/code> into an array of arrays &#8211; and there is order!<\/p>\n<p>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.<\/p>\n<p>The way the horizontal positioning of rectangles is determined within groups, is explained (much better than I could do) <a href=\"http:\/\/stackoverflow.com\/a\/16919330\">by a helpful StackOverflow member<\/a> like this:<\/p>\n<blockquote><p>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.<\/p><\/blockquote>\n<p>Thank you, Mikkeli! <a href=\"https:\/\/tuijasonkkila.fi\/mikkeli.html\">Here is my take<\/a> on your skyline. All the best!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After three weeks of the online course Data Visualization and Infographics by Knight Center I&#8217;m still very happy that I decided to participate. Alberto Cairo and Scott Murray make a good duo. It&#8217;s refreshing to hear Alberto&#8217;s solid, learned opinions, and Scott has this talent of lowering the barriers to learning. This week, we have &hellip; <a href=\"https:\/\/tuijasonkkila.fi\/?p=293\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Logo of Mikkeli as a D3 learning object<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149],"tags":[77,74,97,96,95],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-diverse-coding","tag-d3-js","tag-data-visualization","tag-logo","tag-mikkeli","tag-svg"],"_links":{"self":[{"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293"}],"version-history":[{"count":20,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":981,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions\/981"}],"wp:attachment":[{"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tuijasonkkila.fi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}