-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatmaps.js
71 lines (48 loc) · 1.18 KB
/
heatmaps.js
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
var csv2json = require('csvjson-csv2json');
var data = csv2json(s2Data);
var Plotly = require('plotly.js-dist')
let dataArray = [];
for (let i = 0; i < data.length; i++) {
dataArray.push([data[i]["x"], data[i]["y"]])
}
function generateHeatmap(dataArray, precision){
var precision = 50;
var y = [];
var x = [];
for (let point of dataArray){
x.push(point[0]);
y.push(point[1]);
}
var yMax = Math.max(...y)*1.1;
var xMax = Math.max(...x)*1.1;
var yMin = Math.min(...y)*.91;
var xMin = Math.min(...x)*.91;
var grid = [];
for (let i = 0; i < precision; i++){
grid.push([]);
for (let j = 0; j < precision; j++){
grid[i].push(0);
}
}
for (let point of dataArray){
let xIndex = Math.floor((point[0]-xMin)*precision/(xMax-xMin));
let yIndex = Math.floor((point[1]-yMin)*precision/(yMax-yMin));
grid[yIndex][xIndex]++;
}
var heatmapData = [
{
z: grid,
type: 'heatmap'
}
];
TESTER1 = document.getElementById('tester1');
Plotly.newPlot(TESTER1, heatmapData);
TESTER2 = document.getElementById('tester2');
var trace1 = [{
x: x,
y: y,
mode: 'markers',
type: 'scatter'
}];
Plotly.newPlot(TESTER2, trace1)
}