aboutsummaryrefslogtreecommitdiff
path: root/build/css-slope-graphs/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'build/css-slope-graphs/index.html')
-rw-r--r--build/css-slope-graphs/index.html316
1 files changed, 170 insertions, 146 deletions
diff --git a/build/css-slope-graphs/index.html b/build/css-slope-graphs/index.html
index 0735119..e4e2bd8 100644
--- a/build/css-slope-graphs/index.html
+++ b/build/css-slope-graphs/index.html
@@ -1,70 +1,84 @@
<!doctype html>
-<html lang="en" id="top">
+<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<title>CSS Slope Graphs</title>
- <link href="https://bt.ht/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
- <style>*{box-sizing:border-box;}body{font-family:sans-serif;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{overflow:auto;}table{text-align:left;width:100%;}</style>
+ <link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
+ <link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" />
+<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
</head>
<nav>
- <a href="#menu">Menu &darr;</a>
+ <a href="#menu">Menu &darr;</a>
</nav>
<main>
-<h1>CSS Slope Graphs</h1>
+<h1 id="css-slope-graphs">CSS Slope Graphs</h1>
+
<p>2021-06-07</p>
-<p><em>I am a huge sucker for simplistic and beautifully designed visual data on the web</em>. Most data tends to be graphed via line or bar systems - which is fine - but I think slope graphs are highly underrated. Let's change that, shall we?</p>
-<h2>The Demo</h2>
-<p>I'm basing this demo off the design patterns found in <a href="https://www.edwardtufte.com/tufte/books_vdqi">Edward Tufte's visualization work</a>, specifically his slope graph designs:</p>
+
+<p><em>I am a huge sucker for simplistic and beautifully designed visual data on the web</em>. Most data tends to be graphed via line or bar systems - which is fine - but I think slope graphs are highly underrated. Let&#8217;s change that, shall we?</p>
+
+<h2 id="the-demo">The Demo</h2>
+
+<p>I&#8217;m basing this demo off the design patterns found in <a href="https://www.edwardtufte.com/tufte/books_vdqi">Edward Tufte&#8217;s visualization work</a>, specifically his slope graph designs:</p>
+
<p><a href="https://codepen.io/bradleytaunt/pen/jOBzXMe">Live CodePen Example</a></p>
-<h2>The HTML</h2>
+
+<h2 id="the-html">The HTML</h2>
+
<p>For this concept we will actually be building this graph out of <code>tables</code> - crazy, right? The greatest benefit of rendering all the data inside of a <code>table</code> element is the ability to easily support smaller screens and mobile devices. Larger viewports will get to see the pretty slope graph, while those below a certain threshold will view a simple table.</p>
+
<p>(But more on that in the CSS section)</p>
-<pre><code>&lt;p&gt;Sales of the leading frozen pizza brands of the United States from 2011 to 2017 (in million US dollars) &lt;br&gt;&lt;em&gt;Source: Statisa 2018&lt;/em&gt;&lt;/p&gt;
-&lt;table&gt;
- &lt;thead&gt;
- &lt;tr&gt;
- &lt;th&gt;Pizza Brand&lt;/th&gt;
- &lt;th&gt;2011&lt;/th&gt;
- &lt;th&gt;2017&lt;/th&gt;
- &lt;/tr&gt;
- &lt;/thead&gt;
- &lt;tbody&gt;
- &lt;tr&gt;
- &lt;td data-set=&quot;677.0&quot;&gt;DiGiorno&lt;/td&gt;
- &lt;td&gt;&lt;span&gt;677.0&lt;/span&gt;&lt;/td&gt;
- &lt;td data-name=&quot;DiGiorno&quot;&gt;1014.6&lt;/td&gt;
- &lt;/tr&gt;
- &lt;tr&gt;
- &lt;td data-set=&quot;294.8&quot;&gt;Private Label&lt;/td&gt;
- &lt;td&gt;&lt;span&gt;294.8&lt;/span&gt;&lt;/td&gt;
- &lt;td data-name=&quot;Private Label&quot;&gt;524.8&lt;/td&gt;
- &lt;/tr&gt;
- &lt;tr&gt;
- &lt;td data-set=&quot;286.1&quot;&gt;Red Baron&lt;/td&gt;
- &lt;td&gt;&lt;span&gt;286.1&lt;/span&gt;&lt;/td&gt;
- &lt;td data-name=&quot;Red Baron&quot;&gt;572.3&lt;/td&gt;
- &lt;/tr&gt;
- &lt;tr&gt;
- &lt;td data-set=&quot;257.9&quot;&gt;Tombstone&lt;/td&gt;
- &lt;td&gt;&lt;span&gt;257.9&lt;/span&gt;&lt;/td&gt;
- &lt;td data-name=&quot;Tombstone&quot;&gt;270.6&lt;/td&gt;
- &lt;/tr&gt;
- &lt;tr&gt;
- &lt;td data-set=&quot;164.5&quot;&gt;Totino's Party Pizza&lt;/td&gt;
- &lt;td&gt;&lt;span&gt;164.5&lt;/span&gt;&lt;/td&gt;
- &lt;td data-name=&quot;Totino's Party Pizza&quot;&gt;347.2&lt;/td&gt;
- &lt;/tr&gt;
- &lt;/tbody&gt;
-&lt;/table&gt;
+
+<pre><code>&#60;p&#62;Sales of the leading frozen pizza brands of the United States from 2011 to 2017 (in million US dollars) &#60;br&#62;&#60;em&#62;Source: Statisa 2018&#60;&#47;em&#62;&#60;&#47;p&#62;
+&#60;table&#62;
+ &#60;thead&#62;
+ &#60;tr&#62;
+ &#60;th&#62;Pizza Brand&#60;&#47;th&#62;
+ &#60;th&#62;2011&#60;&#47;th&#62;
+ &#60;th&#62;2017&#60;&#47;th&#62;
+ &#60;&#47;tr&#62;
+ &#60;&#47;thead&#62;
+ &#60;tbody&#62;
+ &#60;tr&#62;
+ &#60;td data-set="677.0"&#62;DiGiorno&#60;&#47;td&#62;
+ &#60;td&#62;&#60;span&#62;677.0&#60;&#47;span&#62;&#60;&#47;td&#62;
+ &#60;td data-name="DiGiorno"&#62;1014.6&#60;&#47;td&#62;
+ &#60;&#47;tr&#62;
+ &#60;tr&#62;
+ &#60;td data-set="294.8"&#62;Private Label&#60;&#47;td&#62;
+ &#60;td&#62;&#60;span&#62;294.8&#60;&#47;span&#62;&#60;&#47;td&#62;
+ &#60;td data-name="Private Label"&#62;524.8&#60;&#47;td&#62;
+ &#60;&#47;tr&#62;
+ &#60;tr&#62;
+ &#60;td data-set="286.1"&#62;Red Baron&#60;&#47;td&#62;
+ &#60;td&#62;&#60;span&#62;286.1&#60;&#47;span&#62;&#60;&#47;td&#62;
+ &#60;td data-name="Red Baron"&#62;572.3&#60;&#47;td&#62;
+ &#60;&#47;tr&#62;
+ &#60;tr&#62;
+ &#60;td data-set="257.9"&#62;Tombstone&#60;&#47;td&#62;
+ &#60;td&#62;&#60;span&#62;257.9&#60;&#47;span&#62;&#60;&#47;td&#62;
+ &#60;td data-name="Tombstone"&#62;270.6&#60;&#47;td&#62;
+ &#60;&#47;tr&#62;
+ &#60;tr&#62;
+ &#60;td data-set="164.5"&#62;Totino&#39;s Party Pizza&#60;&#47;td&#62;
+ &#60;td&#62;&#60;span&#62;164.5&#60;&#47;span&#62;&#60;&#47;td&#62;
+ &#60;td data-name="Totino&#39;s Party Pizza"&#62;347.2&#60;&#47;td&#62;
+ &#60;&#47;tr&#62;
+ &#60;&#47;tbody&#62;
+&#60;&#47;table&#62;
</code></pre>
+
<p>As you can see, nothing too fancy is happpening here. Pay close attention to the <code>data-set</code> and <code>data-name</code> variables though - those will be important for the CSS portion of this design, mainly the rendering of the line elements.</p>
-<h2>The CSS</h2>
-<p>To avoid overwhelming your brain all-at-once, let's break the CSS down into bite-sized chunks, starting with the base styling:</p>
-<pre><code>@import url('https://opentype.netlify.com/et-book/index.css');
+
+<h2 id="the-css">The CSS</h2>
+
+<p>To avoid overwhelming your brain all-at-once, let&#8217;s break the CSS down into bite-sized chunks, starting with the base styling:</p>
+
+<pre><code>@import url(&#39;https:&#47;&#47;opentype.netlify.com&#47;et-book&#47;index.css&#39;);
* {
box-sizing: border-box;
}
@@ -75,7 +89,7 @@ html {
body {
background: #fffff8;
- font-family: &quot;et-book&quot;, serif;
+ font-family: "et-book", serif;
height: 100%;
margin: 0 auto;
max-width: 800px;
@@ -93,115 +107,122 @@ table {
width: 100%;
}
</code></pre>
+
<p>Pretty basic stuff.</p>
-<p>Now we need to design how our slope graph will look on larger screens / desktops. For this instance, we will target these larger devices with a <code>min-width</code> media query of <code>800px</code>. The rest of the CSS might look a little confusing but I assure you it is quite simple.</p>
+
+<p>Now we need to design how our slope graph will look on larger screens &#47; desktops. For this instance, we will target these larger devices with a <code>min-width</code> media query of <code>800px</code>. The rest of the CSS might look a little confusing but I assure you it is quite simple.</p>
+
<ol>
-<li>On larger devices we hide the first <code>thead tr th</code> element with <code>display: none</code></li>
-<li>The first and second <code>td</code> elements inside each <code>tbody</code> row need to be set as <code>position: absolute</code> to avoid duplicate content</li>
-<li>The inner <code>span</code> that we include in our HTML inside the second <code>tbody tr td</code> also needs to be <code>display: none</code></li>
-<li>Remember that <code>data-set</code> variable? We now use that for our <code>:before</code> pseudo element for <code>table tbody tr td:nth-of-type(1)</code></li>
-<li>Remember that <code>data-name</code> variable? We now use that for our <code>:before</code> pseudo element for <code>table tbody tr td:nth-of-type(3)</code></li>
-<li>After that, you can see the simple customization we include to render the angle / position of the slope lines and the corresponding labels</li>
-</ol>
-<pre><code>@media(min-width:800px) {
+<li><p>On larger devices we hide the first <code>thead tr th</code> element with <code>display: none</code></p></li>
+<li><p>The first and second <code>td</code> elements inside each <code>tbody</code> row need to be set as <code>position: absolute</code> to avoid duplicate content</p></li>
+<li><p>The inner <code>span</code> that we include in our HTML inside the second <code>tbody tr td</code> also needs to be <code>display: none</code></p></li>
+<li><p>Remember that <code>data-set</code> variable? We now use that for our <code>:before</code> pseudo element for <code>table tbody tr td:nth-of-type(1)</code></p></li>
+<li><p>Remember that <code>data-name</code> variable? We now use that for our <code>:before</code> pseudo element for <code>table tbody tr td:nth-of-type(3)</code></p></li>
+<li><p>After that, you can see the simple customization we include to render the angle &#47; position of the slope lines and the corresponding labels</p>
+
+<p>@media(min-width:800px) {
table {
display: block;
position: relative;
margin-bottom: 25rem;
- }
+ }</p>
- table thead th {
- border-bottom: 1px solid lightgrey;
- font-size: 24px;
- position: absolute;
- top: -50px;
- width: 45%;
- }
- table thead th:nth-child(1){ display: none; }
- table thead th:nth-child(2){ left: 0; }
- table thead th:nth-child(3){ right: 0; text-align: right; }
+<pre><code>table thead th {
+ border-bottom: 1px solid lightgrey;
+ font-size: 24px;
+ position: absolute;
+ top: -50px;
+ width: 45%;
+}
+table thead th:nth-child(1){ display: none; }
+table thead th:nth-child(2){ left: 0; }
+table thead th:nth-child(3){ right: 0; text-align: right; }
- table tbody tr td:nth-of-type(1),
- table tbody tr td:nth-of-type(2) { position: absolute;}
+table tbody tr td:nth-of-type(1),
+table tbody tr td:nth-of-type(2) { position: absolute;}
- table tbody tr td:nth-of-type(2) span { display: none; }
- table tbody tr td:nth-of-type(1):before {
- content: attr(data-set);
- margin-right: 10px;
- position: relative;
- }
+table tbody tr td:nth-of-type(2) span { display: none; }
+table tbody tr td:nth-of-type(1):before {
+ content: attr(data-set);
+ margin-right: 10px;
+ position: relative;
+}
- table tbody tr td:nth-of-type(2) { padding-left: 10px; }
+table tbody tr td:nth-of-type(2) { padding-left: 10px; }
- table tbody tr td:nth-of-type(3) {
- position: absolute;
- right: 0;
- }
- table tbody tr td:nth-of-type(3):before {
- content: attr(data-name);
- margin-right: 10px;
- position: relative;
- }
+table tbody tr td:nth-of-type(3) {
+ position: absolute;
+ right: 0;
+}
+table tbody tr td:nth-of-type(3):before {
+ content: attr(data-name);
+ margin-right: 10px;
+ position: relative;
+}
- /* Custom individual slopes -- Left */
- tbody tr:nth-child(1) td:nth-child(1),
- tbody tr:nth-child(1) td:nth-child(2) { top: 60px; }
- tbody tr:nth-child(2) td:nth-child(1),
- tbody tr:nth-child(2) td:nth-child(2) { top: 140px; }
- tbody tr:nth-child(3) td:nth-child(1),
- tbody tr:nth-child(3) td:nth-child(2) { top: 165px; }
- tbody tr:nth-child(4) td:nth-child(1),
- tbody tr:nth-child(4) td:nth-child(2) { top: 220px; }
- tbody tr:nth-child(5) td:nth-child(1),
- tbody tr:nth-child(5) td:nth-child(2) { top: 270px; }
-
- /* Custom individual slopes -- Right */
- [data-name=&quot;DiGiorno&quot;] { top: 0; }
- [data-name=&quot;Red Baron&quot;] { top: 65px; }
- [data-name=&quot;Private Label&quot;] { top: 100px; }
- [data-name=&quot;Tombstone&quot;] { top: 180px; }
- [data-name=&quot;Totino's Party Pizza&quot;] { top: 150px; }
-
- /* The custom visual lines */
- tbody tr:after {
- background: black;
- content: '';
- height: 1px;
- left: 14.5%;
- position: absolute;
- width: 70%;
- }
- tbody tr:nth-child(1):after {
- top: 40px;
- transform: rotate(-6deg);
- }
- tbody tr:nth-child(2):after {
- left: 17.5%;
- top: 130px;
- transform: rotate(-4deg);
- width: 65%;
- }
- tbody tr:nth-child(3):after {
- left: 15%;
- top: 125px;
- transform: rotate(-10.25deg);
- width: 70%;
- }
- tbody tr:nth-child(4):after {
- left: 16%;
- top: 210px;
- transform: rotate(-4deg);
- width: 68%;
- }
- tbody tr:nth-child(5):after {
- left: 22%;
- top: 222px;
- transform: rotate(-16deg);
- width: 56%;
- }
+&#47;* Custom individual slopes -- Left *&#47;
+tbody tr:nth-child(1) td:nth-child(1),
+tbody tr:nth-child(1) td:nth-child(2) { top: 60px; }
+tbody tr:nth-child(2) td:nth-child(1),
+tbody tr:nth-child(2) td:nth-child(2) { top: 140px; }
+tbody tr:nth-child(3) td:nth-child(1),
+tbody tr:nth-child(3) td:nth-child(2) { top: 165px; }
+tbody tr:nth-child(4) td:nth-child(1),
+tbody tr:nth-child(4) td:nth-child(2) { top: 220px; }
+tbody tr:nth-child(5) td:nth-child(1),
+tbody tr:nth-child(5) td:nth-child(2) { top: 270px; }
+
+&#47;* Custom individual slopes -- Right *&#47;
+[data-name="DiGiorno"] { top: 0; }
+[data-name="Red Baron"] { top: 65px; }
+[data-name="Private Label"] { top: 100px; }
+[data-name="Tombstone"] { top: 180px; }
+[data-name="Totino&#39;s Party Pizza"] { top: 150px; }
+
+&#47;* The custom visual lines *&#47;
+tbody tr:after {
+ background: black;
+ content: &#39;&#39;;
+ height: 1px;
+ left: 14.5%;
+ position: absolute;
+ width: 70%;
+}
+tbody tr:nth-child(1):after {
+ top: 40px;
+ transform: rotate(-6deg);
+}
+tbody tr:nth-child(2):after {
+ left: 17.5%;
+ top: 130px;
+ transform: rotate(-4deg);
+ width: 65%;
+}
+tbody tr:nth-child(3):after {
+ left: 15%;
+ top: 125px;
+ transform: rotate(-10.25deg);
+ width: 70%;
+}
+tbody tr:nth-child(4):after {
+ left: 16%;
+ top: 210px;
+ transform: rotate(-4deg);
+ width: 68%;
+}
+tbody tr:nth-child(5):after {
+ left: 22%;
+ top: 222px;
+ transform: rotate(-16deg);
+ width: 56%;
}
</code></pre>
-<p>All that's left are some minor styles to make everything look nice on mobile:</p>
+
+<p>}</p></li>
+</ol>
+
+<p>All that&#8217;s left are some minor styles to make everything look nice on mobile:</p>
+
<pre><code>@media(max-width:800px) {
p {
margin: 2rem 0;
@@ -215,8 +236,11 @@ table {
}
}
</code></pre>
-<h2>Not the most practical</h2>
+
+<h2 id="not-the-most-practical">Not the most practical</h2>
+
<p>This slope graph concept is far from perfect for use in real-world situations. The fact that you need to manually render each point of data yourself makes this implementation quite annoying for more in-depth projects.</p>
+
<p>But it was fun to mess around with and create, so who cares!</p>
<footer role="contentinfo">
<h2>Menu Navigation</h2>