Created
April 18, 2017 11:35
-
-
Save RadLikeWhoa/75343a2a9d4841620e842d3e27ba57da to your computer and use it in GitHub Desktop.
Life In Weeks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Skydancer — A Life in Weeks</title> | |
| <link rel="stylesheet" href="style.css" /> | |
| <link rel="stylesheet" href="//fonts.googleapis.com/css?family=Kaushan+Script" /> | |
| </head> | |
| <body> | |
| <h1> | |
| <span class="title">Skydancer</span> | |
| <span class="sub">A Life in Weeks</span> | |
| </h1> | |
| <svg /> | |
| <script src="//d3js.org/d3.v4.min.js"></script> | |
| <script src="main.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const data = [] | |
| for (let i = 0; i < 343; i++) { | |
| data[i] = { | |
| color: '#3583ea', | |
| label: 'The Beginning' | |
| } | |
| } | |
| for (let i = 343; i < 604; i++) { | |
| data[i] = { | |
| color: '#3b8deb', | |
| label: 'Primary School' | |
| } | |
| } | |
| for (let i = 604; i < 812; i++) { | |
| data[i] = { | |
| color: '#4098ec', | |
| label: 'Bez' | |
| } | |
| } | |
| for (let i = 812; i < 968; i++) { | |
| data[i] = { | |
| color: '#46a2ed', | |
| label: 'IMS' | |
| } | |
| } | |
| for (let i = 968; i < 1042; i++) { | |
| data[i] = { | |
| color: '#4baded', | |
| label: 'Manor' | |
| } | |
| } | |
| for (let i = 1042; i < 1077; i++) { | |
| data[i] = { | |
| color: '#51b7ee', | |
| label: 'Break Year' | |
| } | |
| } | |
| for (let i = 1077; i < 1235; i++) { | |
| data[i] = { | |
| color: '#56c2ef', | |
| label: 'FHNW' | |
| } | |
| } | |
| for (let i = 1235; i < 4680; i++) { | |
| data[i] = { | |
| color: '#E5E5BE', | |
| label: 'The Great Unknown' | |
| } | |
| } | |
| data[272] = data[656] = { | |
| color: '#fff', | |
| label: 'Canary' | |
| } | |
| data[320] = { | |
| color: '#e0e0ff', | |
| label: 'Garfield' | |
| } | |
| data[378] = { | |
| color: '#e0e0ff', | |
| label: 'Filou' | |
| } | |
| data[438] = { | |
| color: '#e0e0ff', | |
| label: 'Mini + Maxi' | |
| } | |
| data[518] = data[572] = data[623] = { | |
| color: '#fff', | |
| label: 'Lenk' | |
| } | |
| data[748] = data[749] = { | |
| color: '#fff', | |
| label: 'California' | |
| } | |
| data[803] = data[1064] = data[1117] = data[1168] = { | |
| color: '#ffffe0', | |
| label: 'Greenfield' | |
| } | |
| data[845] = data[846] = data[924] = data[925] = { | |
| color: '#fff', | |
| label: 'NYC' | |
| } | |
| data[860] = data[913] = { | |
| color: '#ffffe0', | |
| label: 'Gurten' | |
| } | |
| data[863] = { | |
| color: '#ffe0e0', | |
| label: 'GF #1' | |
| } | |
| data[874] = data[990] = { | |
| color: '#fff', | |
| label: 'Austria' | |
| } | |
| data[885] = { | |
| color: '#fff', | |
| label: 'Fiss' | |
| } | |
| data[955] = { | |
| color: '#ffe0e0', | |
| label: 'GF #2' | |
| } | |
| data[1011] = { | |
| color: '#ffffe0', | |
| label: 'Rock im Park' | |
| } | |
| data[1015] = data[1016] = data[1017] = data[1018] = { | |
| color: '#fff', | |
| label: 'France' | |
| } | |
| data[1120] = data[1121] = data[1122] = data[1123] = data[1124] = { | |
| color: '#fff', | |
| label: 'Canada' | |
| } | |
| data[1156] = { | |
| color: '#ffe0e0', | |
| label: 'GF #3' | |
| } | |
| data[1180] = { | |
| color: '#e0ffe0', | |
| label: 'Move' | |
| } | |
| const width = 1040 | |
| const height = 630 | |
| const expectancy = 90 | |
| const svg = d3.select('svg') | |
| .attr('height', height + 40) | |
| .attr('width', width + 40) | |
| const vis = svg.append('g') | |
| .attr('transform', 'translate(20, 20)') | |
| const wrapper = vis.append('g') | |
| .attr('class', 'wrapper') | |
| const xScale = d3.scaleLinear() | |
| .domain([ 0, 52 ]) | |
| .range([ 0, width ]) | |
| const yScale = d3.scaleLinear() | |
| .domain([ 0, expectancy ]) | |
| .range([ 0, height ]) | |
| const title = d3.select('.title') | |
| const sub = d3.select('.sub') | |
| const rects = wrapper.selectAll('rect') | |
| .data(data) | |
| .enter() | |
| .append('rect') | |
| .attr('x', (d, i) => xScale(i % 52)) | |
| .attr('y', (d, i) => yScale(Math.floor(i / 52))) | |
| .attr('width', width / 52) | |
| .attr('height', height / expectancy) | |
| .attr('fill', d => d.color) | |
| .on('mouseover', (d, i, nodes) => { | |
| title.text(d.label) | |
| sub.text(`Y${Math.floor(i / 52)} / W${i % 52 + 1}`) | |
| d3.select(nodes[i]) | |
| .style('fill', '#0d3b78') | |
| }) | |
| .on('mouseleave', (d, i, nodes) => { | |
| title.text('Skydancer') | |
| sub.text('A Life in Weeks') | |
| d3.select(nodes[i]) | |
| .style('fill', d.color) | |
| }) | |
| vis.append('g').call(d3.axisTop(xScale)).selectAll("path").attr("stroke-opacity", 0) | |
| vis.append('g').call(d3.axisLeft(yScale)).selectAll("path").attr("stroke-opacity", 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body { | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| flex-direction: column; | |
| margin: 0; | |
| background-color: #fffff2; | |
| min-height: 100vh; | |
| } | |
| svg { | |
| display: block; | |
| margin: 0 0 1.5em; | |
| max-width: 100%; | |
| height: auto; | |
| } | |
| h1 { | |
| position: relative; | |
| display: block; | |
| width: 1040px; | |
| color: #d98054; | |
| font-family: "Kaushan Script"; | |
| margin: 1em auto; | |
| font-size: 1.5em; | |
| line-height: 1; | |
| } | |
| h1::after { | |
| content: ""; | |
| display: table; | |
| clear: both; | |
| } | |
| .title { | |
| display: inline-block; | |
| float: left; | |
| min-width: 10em; | |
| padding-left: 0.375em; | |
| } | |
| .sub { | |
| display: inline-block; | |
| float: right; | |
| min-width: 10em; | |
| font-size: 0.75em; | |
| line-height: 1.5; | |
| text-align: right; | |
| padding-right: 0.5em; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment