-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
executable file
·101 lines (83 loc) · 4.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!doctype html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>chartjunk: a font for quickly making sparklines in your page</title>
<meta name="description" content="chartjunk is a font and small javascript for adding sparklines to your webpage">
<meta name="author" content="Marcos Ojeda">
<meta name="viewport" content="width=device-width,initial-scale=1">
<!-- CSS concatenated and minified via ant build script-->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/chartjunk.css">
<style type="text/css" media="screen">
body { font-size:16px; padding-left: 100px; padding-bottom:200px; width:800px; }
h2 { margin-top: 3em; }
.junkjunk{
font-family:chartjunk-web; color:#444;
}
</style>
<!-- end CSS-->
</head>
<body>
<div id="container">
<header>
</header>
<div id="main" role="main">
<h1>Chartjunk</h1>
<p>Chartjunk is a <a href="https://github.com/nsfmc/chartjunk/tree/master/css">webfont</a>, a small piece of javascript to <a href="#junkify">junkify</a> inline data-series, and an actual <a href="https://github.com/nsfmc/chartjunk/tree/master/chartjunk.ufo">ufo</a>/<a href="https://github.com/nsfmc/chartjunk/blob/master/chartjunk.otf?raw=true">otf</a> file you can extend or do whatever you'd like.
<p>If you're <a href="http://www.youtube.com/watch?v=pY8jaGs7xJ0">into it</a>, you could <a href="https://github.com/nsfmc/chartjunk/fork_select">fork this project</a> on <a href="https://github.com/nsfmc/chartjunk">github</a>
<p>You don't need to use this, i don't know your life, but if this is something you're into then <em>by all means.</em>
<div class="demo">
<h2>obligatory demo</h2>
<p>Stocks rose sharply in trading today... <span class="prechartjunk">1,2,4,1,9,42,53,2,45,16,2,3,15,0</span> becomes <span class="chartjunk">1,2,4,1,9,42,53,2,45,16,2,3,15,0</span> (the sparkline has a title attribute with the original data)
<p>I did pretty well this week at the range: <span class="prechartjunk">+++==-++-+++==-++++=+</span> becomes <span class="junkjunk">+++==-++-+++==-++++=+</span>
</div>
<div id="junkify">
<h2>the javascript</h2>
<p>The code that performs the transformations above is pretty straightforward, you can probably even implement it yourself in a smarter way. The code as it stands requires <a href="http://documentcloud.github.com/underscore/">underscore.js</a>, but you can probably rewrite it not even need that (it uses <code>_.uniq, _.map, _.max, _.min, _.range</code>). it's your call</p>
<script src="https://gist.github.com/2038321.js?file=junkify.js"></script>
</div>
<div class="license">
<h2>license</h2>
<p>All this bizness is © marcos.andres.ojeda, 2012</p>
<p>The code is licensed under the <a href="http://www.json.org/license.html">json license</a> while the font is licensed under an <a href="scripts.sil.org/OFL">ofl license</a>. Please have fun and do good things.
</div>
</div>
<footer>
</footer>
</div> <!--! end of #container -->
<script src="js/libs/underscore-min.js"></script>
<script>
var junkify = function( someClass ){
// requires underscore.js
var sparks = document.getElementsByClassName( someClass );
_(sparks).each(function(e,i){
var range = 16;
var origContent = e.innerHTML;
e.title = "data: "+ origContent;
var d = origContent.split(","),
max = _.max(d), min = _.min(d),
dataRange = max-min;
// an array like ["0","1",...,"e","f,","g"]
var cj = _.range(17).map(function(e){return e.toString(17)})
// remap data to start at "0" and end at "g"
var rescaled = _(d).map(function(e){
var idx = Math.ceil((e - min) * (range / dataRange) );
return cj[idx]
})
// reassemble the string and add chartjunk's junkjunk classname
var graphText = rescaled.join("")
e.innerHTML = graphText;
var cns = _.uniq( (e.className + " junkjunk").split(" ") ).join(" ")
e.className = cns;
})
}
junkify("chartjunk");
</script>
<!-- end scripts-->
</body>
</html>