-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
295 lines (248 loc) · 8.98 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
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Heatmap</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="css/resort.css" />
</head>
<body>
<div id="main-panel">
<div id="vis-panel">
<div class="vis"></div>
</div>
<div id="control-panel">
<h5>Row Height</h5>
<div class="slider-row-height"></div>
<h5>Column Width</h5>
<div class="slider-bar-width"></div>
<h5>Column Spacing</h5>
<div class="slider-column-spacing"></div>
<h5>Group Spacing</h5>
<div class="slider-group-spacing"></div>
<h5>Group-by Row Indices</h5>
<input type="text" id="group-by-list" placeholder="0, 1" value="0, 1">
<button class="btn btn-primary group-samples">Group Samples</button>
</div>
<div id="title-panel">
Stacks demo
<br>
<button class="btn btn-primary draw-heatmap">Render</button>
</div>
</div>
<div id="data" class="well">
<form role="form">
<div class="form-group">
<label for="text_data"><b>Input Data (csv)</b>
</label>
<br>
<label>Rows:</label>
<input type="text" id="number-of-rows" placeholder="Number of Rows" value="20">
<label>Columns:</label>
<input type="text" id="number-of-columns" placeholder="Number of Columns" value="100">
<button class="btn btn-primary shuffle-data">Recreate Data</button>
<br>
<textarea id="text_data" rows="10" class="form-control"></textarea>
</div>
</form>
</div>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script type="text/javascript" src="js/resort.js"></script>
<script type="text/javascript">
var rows = 20;
var columns = 100;
$(document).ready(function() {
activateVisControls();
createTestData(rows, columns);
var data = getTextAreaData();
var rowLabels = getLabels(data);
var heatmapData = getDataRows(data);
createRows(rowLabels);
drawHeatmap(rowLabels, heatmapData);
});
var resort;
var bar_padding = 0,
bar_height = 10,
bar_width = 8,
group_padding = 10;
function appendRowLabelElements() {
d3.selectAll('.data-row .label')
.append('a')
.attr('href','#')
.on('click', function(val) {
resort.groupByRow(val);
return false;
})
.html(function(val) { return val; })
};
function createEvenOddRow(rowLength) {
return ["EVEN_or_ODD"].concat(_.map(_.range(0,rowLength), function(val) {
return (val % 2 == 0) ? "EVEN" : "ODD";
}));
};
function getDataRows(data) {
return data.map(function(row) {
return row.slice(1);
});
}
function getLabels(data) {
return data.map(function(row) {
return row[0];
});
}
function getTextAreaData() {
var txt = $("#text_data").val();
return d3.csv.parseRows(txt, function(row) {
return _.map(row, function(val) {
return _.isFinite(val) ? parseFloat(val) : val;
});
});
}
function drawHeatmap(rowlabels, heatmapData) {
var columnlabels = _.range(0, _.first(heatmapData).length + 1);
resort = new Resort({
"colormap": {
"EVEN": colorbrewer['Set3'][12][0],
"ODD": colorbrewer['Set3'][12][1],
"4": colorbrewer['Set3'][12][2],
"5": colorbrewer['Set3'][12][3],
"6": colorbrewer['Set3'][12][4],
"7": colorbrewer['Set3'][12][5],
"8": colorbrewer['Set3'][12][6],
"9": colorbrewer['Set3'][12][7],
"10": colorbrewer['Set3'][12][8]
},
"value_order": [4, 5, 6, 7, 8, 9, 10, "EVEN", "ODD"],
"row_labels": rowlabels,
"column_labels": columnlabels,
"bar_width": bar_width,
"bar_height": bar_height,
"bar_padding": bar_padding,
"group_padding": group_padding,
"row_selector": ".resort-row",
"enable_hover": true
});
var parentEl = d3.select('.vis').node();
resort.draw(parentEl, heatmapData);
}
function createTestData(rows, columns) {
if (!_.isFinite(rows) || !_.isFinite(columns)) {
return false;
}
var doubledata = _.map(_.range(1, rows), function(i) {
return ["Row_" + i].concat(
_.map(_.range(0, columns), function() {
return (Math.floor(Math.random() * 7) + 4);
}));
});
doubledata.unshift(createEvenOddRow(columns));
var textdata = _.map(doubledata, function(doublerow) {
return doublerow.join(",");
});
$("#text_data").val(textdata.join("\n"));
return true;
};
function activateVisControls() {
$(".group-samples").click(function() {
var rowList = $('#group-by-list').val();
if (rowList.length < 1) {
return;
}
var rowIndices = _.chain(rowList.split(','))
.invoke('trim')
.map(Number)
.filter(function(val) {
return !_.isNaN(val);
})
.value();
resort.groupByRows(rowIndices);
});
$(".draw-heatmap").click(function() {
var data = getTextAreaData();
var rowLabels = getLabels(data);
var heatmapData = getDataRows(data);
drawHeatmap(rowLabels, heatmapData);
return false;
});
$(".shuffle-data").click(function() {
var rowsString = $('#number-of-rows').val();
colsString = $('#number-of-columns').val();
rows = parseInt(rowsString, 10),
cols = parseInt(colsString, 10);
if (_.isFinite(rows) && _.isFinite(cols)) {
createTestData(rows, cols);
}
return false;
});
var setOptions = _.throttle(function(object) {
resort.setOptions(object);
}, 40);
$(".slider-row-height").slider({
value: bar_height,
min: 0,
max: 20,
slide: function(event, ui) {
bar_height = ui.value;
setOptions({
"bar_height": ui.value
});
}
});
$(".slider-bar-width").slider({
value: bar_width,
min: 0,
max: 15,
slide: function(event, ui) {
bar_width = ui.value;
setOptions({
"bar_width": ui.value
});
}
});
$(".slider-column-spacing").slider({
value: bar_padding,
min: 0,
max: 10,
slide: function(event, ui) {
bar_padding = ui.value;
setOptions({
"bar_padding": ui.value
});
}
});
$(".slider-group-spacing").slider({
value: group_padding,
min: 0,
max: 30,
slide: function(event, ui) {
group_padding = ui.value;
setOptions({
"group_padding": ui.value
});
}
});
};
function createRows(rows) {
var resortRows = d3
.select('.vis')
.selectAll('.data-row')
.data(rows)
.enter()
.append('div').attr('class', 'data-row');
resortRows.append('div').attr('class','label');
resortRows.append('div').attr('class','resort-row');
appendRowLabelElements();
}
</script>
</body>
</html>