-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcolormaps.html
96 lines (58 loc) · 1.89 KB
/
colormaps.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
<html>
<head>
<title>MathCell - Colormaps</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
button { width: 2in }
.right { text-align: right }
</style>
</head>
<body>
<p>Colormaps can be applied by setting an option of <code>colormap</code> equal to a string name below. A reversed colormap can be used by also setting an option of <code>reverseColormap</code> to <code>true</code>.</p>
<p style="text-align: center">
<button onclick="update()">Natural Order</button>
<button onclick="update(true)">Alphabetical</button>
</p><br/>
<table id="bars"></table>
<script src="../build/mathcell.js"></script>
<script>
update();
function update( sorted=false ) {
bars.innerHTML = '';
// document not fully ready if use one loop...
if ( sorted ) {
var alpha = {};
Object.keys( colormaps ).sort().forEach( k => alpha[k] = colormaps[k] );
Object.keys( alpha ).forEach( cm => addRow(cm) );
Object.keys( alpha ).forEach( cm => addCanvas(cm) );
} else {
Object.keys( matplotlib ).forEach( cm => addRow(cm) );
bars.innerHTML += `
<tr><td> </td></tr>`
Object.keys( mathematica ).forEach( cm => addRow(cm) );
Object.keys( colormaps ).forEach( cm => addCanvas(cm) );
}
}
function addRow( cm ) {
bars.innerHTML += `
<tr><td class="right">${cm}</td><td id="${cm}"></td></tr>
<tr><td> </td></tr>`;
}
function addCanvas( cm ) {
var canvas = document.createElement( 'canvas' );
canvas.width = 500;
canvas.height = 20;
var context = canvas.getContext( '2d' );
var gradient = context.createLinearGradient( 0, 0, 500, 0 );
var f = colormap( cm );
for ( var i = 0 ; i <= 1 ; i += .05 ) {
var c = f(i);
gradient.addColorStop( i, `rgb(${255*c.r},${255*c.g},${255*c.b})` );
}
context.fillStyle = gradient;
context.fillRect( 0, 0, 500, 20 );
document.getElementById( cm ).appendChild( canvas );
}
</script>
</body>
</html>