This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
478 lines (415 loc) · 12.7 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<html>
<head>
<title>Color Code Plug-in</title>
<script type="text/javascript" src="./bin/syntaxhighlighter/shCore.js"></script>
<script type="text/javascript" src="./bin/syntaxhighlighter/shBrushJScript.js"></script>
<script type="text/javascript" src="./bin/syntaxhighlighter/shBrushPhp.js"></script>
<script type="text/javascript" src="./bin/syntaxhighlighter/shBrushXml.js"></script>
<link rel="stylesheet" type="text/css" href="./bin/syntaxhighlighter/shCore.css">
<link rel="stylesheet" type="text/css" href="./bin/syntaxhighlighter/shCoreDefault.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="./bin/rainbowvis.js"></script>
<script type="text/javascript" src="jquery.colorCode.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
SyntaxHighlighter.all()
$(".confusion_matrix.after > div > div").colorCode({
colors: ["white", "red"]
});
$(".legend > div").colorCode();
$(".earthquake_row").colorCode({
useDataTag: "mag"
});
$(".survey_answer").colorCode({
colors: ["red", "gray", "orange", "green"],
clearContent: true,
proportional: false
});
$(".survey_answer_prop").colorCode({
colors: ["red", "gray", "orange", "green"],
clearContent: true,
proportional: true
});
});
</script>
<style type="text/css">
body {
background-color: gray;
}
h1 {
margin-bottom: 0;
}
h1, h3 {
text-align: center;
}
h2 {
border-bottom: 1px solid gray;
}
h4 {
margin-bottom: 10px;
border-bottom: 1px dotted black;
}
p {
text-align: justify;
}
p > a {
font-style: italic;
color: orange;
}
li {
text-align: justify;
margin-top: 5px;
}
table {
text-align: center;
width: 100%;
border: 1px solid black;
border-collapse: collapse;
}
table th {
background-color: #CCC;
}
table td, table th {
border-bottom: 1px solid black;
}
table td:first-child, table th:first-child {
text-align: left;
padding-left: 10px;
}
.body_wrapper {
width: 550px;
margin: 50px auto 50px auto;
padding: 20px;
border-radius: 10px;
border: 1px solid black;
background-color: white;
}
.by {
font-style: italic;
text-align: center;
color: #888;
}
.credit {
text-align: center;
color: #888;
font-size: 14px;
}
/* Matrix example css */
.confusion_matix_wrapper {
text-align: center;
}
.confusion_matrix {
display: inline-block;
vertical-align: top;
width: 200px;
height: 200px;
line-height: 40px;
border: 1px solid black;
}
.confusion_matrix:first-child {
margin-right: 20px;
}
.confusion_matrix > div {
height: 20%;
width: 100%;
}
.confusion_matrix > div > div {
display: inline-block;
height: 100%;
width: 20%;
text-align: center;
border: 1px solid black;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
/*Examples: Legend and table*/
.legend {
height: 20px;
width: 100%;
text-align: center;
}
.legend > div {
display: inline-block;
width: 30px;
height: 100%;
border: 1px solid black;
vertical-align: middle;
text-align: center;
line-height: 20px;
}
.legend > span {
vertical-align: middle;
font-weight: bold;
line-height: 20px;
}
.earthquake_table {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="body_wrapper">
<h1>Color Code</h1>
<div class="by">by Joseph Mallah</div>
<p><b>Color Code</b> is a <a target="_blank" href="http://jquery.com">jQuery</a> plug-in that transform numerical tags into color scale. The advantage of color coding is to facilitate the visualization of the data and provide an instant understanding of the values.</p>
<p>The basic usage of <b>Color Code</b> is to parse specific <i>div</i> (or any other tag) and color their background using a color gradient depending on the contained value inside the div.</p>
<p>Here is an example of a <a target="_blank" href="http://en.wikipedia.org/wiki/Confusion_matrix">confusion matrix</a> and how <b>color code</b> can help make it more understandable.</p>
<h3>Confusion matrix before and after</h3>
<div class="confusion_matix_wrapper">
<div class="confusion_matrix before">
<div>
<div>17</div><div>8</div><div>3</div><div>1</div><div>0</div>
</div>
<div>
<div>10</div><div>20</div><div>7</div><div>4</div><div>12</div>
</div>
<div>
<div>4</div><div>6</div><div>15</div><div>2</div><div>11</div>
</div>
<div>
<div>6</div><div>2</div><div>11</div><div>31</div><div>1</div>
</div>
<div>
<div>10</div><div>0</div><div>9</div><div>2</div><div>24</div>
</div>
</div>
<div class="confusion_matrix after">
<div>
<div>17</div><div>8</div><div>3</div><div>1</div><div>0</div>
</div>
<div>
<div>10</div><div>20</div><div>7</div><div>4</div><div>12</div>
</div>
<div>
<div>4</div><div>6</div><div>15</div><div>2</div><div>11</div>
</div>
<div>
<div>6</div><div>2</div><div>11</div><div>31</div><div>1</div>
</div>
<div>
<div>10</div><div>0</div><div>9</div><div>2</div><div>24</div>
</div>
</div>
</div>
<h2>Requirements</h2>
<p>
<b>Color code</b> require the <a target="_blank" href="http://jquery.com/download/">jQuery library</a> version 1.9 and up. In addition to the jQuery library, <b>color code</b> requires the <a target="_blank" href="https://github.com/anomal/RainbowVis-JS">rainbowvis</a> plug-in to generate the color gradients.
</p>
<h2>Installation</h2>
<p>Load the required JavaScripts libraries in the proper order, then load the <b>color code</b> library</p>
<ol>
<li>jQuery library</li>
<li>rainbowvis plug-in</li>
<li>colorCode plug-in</li>
</ol>
<h2>Usage</h2>
<p>To use the plug-in simply call the plug-in on your elements. The value parsed should be an <b>INTEGER</b> otherwise the plug-in will throw an error.</p>
<script type="syntaxhighlighter" class="brush: js">
$("your_elements").colorCode();</script>
<p>To specify more settings, pass them to the function in the options parameter:</p>
<script type="syntaxhighlighter" class="brush: js">
$("your_elements").colorCode({
colors : ["green", "yellow", "red"],
proportional : true,
clearContent : false,
useDataTag : null
});</script>
<h2>Options</h2>
<ul>
<li>
<b>clearContent</b> [true/false]:<br>
Whether to remove the number inside the <i>div</i> after coloring the background or leave the content untouched.<br>
<i>Default: false</i>
</li>
<li>
<b>colors</b> [colour1, colour2 [,colourN]]:<br>
An array of colors to form the gradient. A minimum of two colors are required. Colors can be in the form 'red', 'ff0000', or '#ff0000'.<br>
<i>Default: ["green", "yellow", "red"]</i>
</li>
<li>
<b>proportional</b> [true/false]:<br>
Whether colors are proportional to the numbers. If set to <i>true</i>, an interval of [0, 5, 100] will have a 100 gradient colors, meaning that the number 0 will have the <i>start color</i> and the 100 will have the <i>end color</i>, but the number 5 color will be closer to <i>start color</i> since 5 is closer to 0 than to 100. Otherwise, if set to <i>false</i> the number 5 will have the <i>central color</i> between the starting and ending colors.<br>
<i>Default: true</i>
</li>
<li>
<b>useDataTag</b> [string/null]:<br>
Whether to use the HTML content of the <i>tag</i> or the data contained in a HTML5 <a target="_blank" href="http://html5doctor.com/html5-custom-data-attributes/">data attribute</a>. If the value is <b>null</b>, the HTML content of the tag will be parsed. Otherwise if a string is specified than the content of the data attribute of this string will be used.<br>
<i>Default: null</i>
</li>
</ul>
<h2>Examples</h2>
<h3>Legend and table (Earthquakes)</h3>
<p>In this example we use the data tag to color the full row with the corresponding color</p>
<div class="legend"><span>Low </span><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div><div>7</div><div>8</div><div>9</div><span> High</span></div>
<table class="earthquake_table">
<tr>
<th>Place</th>
<th>Date</th>
<th>Magnitude</th>
</tr>
<tr class="earthquake_row" data-mag="2">
<td>NORTHERN CALIFORNIA</td>
<td>2015-01-23</td>
<td>2</td>
</tr>
<tr class="earthquake_row" data-mag="4">
<td>CAUCASUS REGION, RUSSIA</td>
<td>2015-01-22</td>
<td>4</td>
</tr>
<tr class="earthquake_row" data-mag="5">
<td>SOUTH SANDWICH ISLANDS REGION</td>
<td>2015-01-22</td>
<td>5</td>
</tr>
<tr class="earthquake_row" data-mag="8">
<td>SUMATRA, INDONESIA</td>
<td>2012-04-11</td>
<td>8</td>
</tr>
<tr class="earthquake_row" data-mag="9">
<td>TOHOKU, JAPAN</td>
<td>2011-03-11</td>
<td>9</td>
</tr>
</table>
<h4>HTML Code</h4>
<script type="syntaxhighlighter" class="brush: php; html-script: true">
<div class="legend">
<span>Low </span><div>1</div>...<span> High</span>
</div>
<table class="earthquake_table">
<tr>
<th>Place</th>
<th>Date</th>
<th>Magnitude</th>
</tr>
<tr class="earthquake_row" data-mag="2">
<td>NORTHERN CALIFORNIA</td>
<td>2015-01-23</td>
<td>2</td>
</tr>
<tr class="earthquake_row" data-mag="4">
<td>CAUCASUS REGION, RUSSIA</td>
<td>2015-01-22</td>
<td>4</td>
</tr>
...
</table>
</script>
<h4>JavaScript Code</h4>
<script type="syntaxhighlighter" class="brush: js">
$(".legend > div").colorCode();
$(".earthquake_row").colorCode({
useDataTag: "mag"
});
</script>
<hr>
<h3>Survey Summary</h3>
<p>Here we demonstrate the capability of creating specific colors per number.</p>
<p>In this example we used a number of colors equal to the number of possible data values [No, No answer, Maybe, Yes] => [Red, Gray, Orange, Green] => [-1, 0, 5, 10]. We codified Yes by the number 1, No by number -1 and so on... <i>NB:</i> we also had to set the option <b>proportional</b> to <b>false</b>.</p>
<table>
<tr>
<th>Question</th>
<th>Answer</th>
</tr>
<tr>
<td>Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing</td>
<td class="survey_answer">10</td>
</tr>
<tr>
<td>Sed Auctor Neque Eu</td>
<td class="survey_answer">5</td>
</tr>
<tr>
<td>Duis Aliquet Egestas Purus In</td>
<td class="survey_answer">-1</td>
</tr>
<tr>
<td>Sed Auctor Neque Eu Tellus Rhoncus</td>
<td class="survey_answer">0</td>
</tr>
<tr>
<td>Vivamus Luctus Urna Sed</td>
<td class="survey_answer">10</td>
</tr>
<tr>
<td>Uis Aliquet Purus In</td>
<td class="survey_answer">-1</td>
</tr>
<tr>
<td>Auctor Neque Eu Tellus Rhoncus</td>
<td class="survey_answer">0</td>
</tr>
</table>
<p>If we haven't set the <b>proportional</b> to <b>false</b> we will get different results that are gradients of our specified colors.</p>
<table>
<tr>
<th>Question</th>
<th>Answer</th>
</tr>
<tr>
<td>Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing</td>
<td class="survey_answer_prop">10</td>
</tr>
<tr>
<td>Sed Auctor Neque Eu</td>
<td class="survey_answer_prop">5</td>
</tr>
<tr>
<td>Duis Aliquet Egestas Purus In</td>
<td class="survey_answer_prop">-1</td>
</tr>
<tr>
<td>Sed Auctor Neque Eu Tellus Rhoncus</td>
<td class="survey_answer_prop">0</td>
</tr>
<tr>
<td>Vivamus Luctus Urna Sed</td>
<td class="survey_answer_prop">10</td>
</tr>
<tr>
<td>Uis Aliquet Purus In</td>
<td class="survey_answer_prop">-1</td>
</tr>
<tr>
<td>Auctor Neque Eu Tellus Rhoncus</td>
<td class="survey_answer">0</td>
</tr>
</table>
<h4>HTML Code</h4>
<script type="syntaxhighlighter" class="brush: php; html-script: true">
<table>
<tr>
<th>Question</th>
<th>Answer</th>
</tr>
<tr>
<td>Lorem Ipsum Dolor</td>
<td class="survey_answer">10</td>
</tr>
<tr>
<td>Sed Auctor Neque Eu</td>
<td class="survey_answer">5</td>
</tr>
...
</table>
</script>
<h4>JavaScript Code</h4>
<script type="syntaxhighlighter" class="brush: js">
$(".survey_answer").colorCode({
colors: ["red", "gray", "orange", "green"],
clearContent: true,
proportional: false
});
</script>
<h2>License Agreement</h2>
<p>This content is released under the <a target="_blank" href="http://opensource.org/licenses/mit-license.html">MIT License</a></p>
<p></p>
<h2>Acknowledgments</h2>
<p>Developed and maintained by Joseph Mallah @ <a target="_blank" href="http://josephmallah.com">josephmallah.com</a></p>
<div class="credit">2015 © josephmallah.com</div>
</div>
</body>
</html>