This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·136 lines (129 loc) · 3.54 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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>K-means clustering visualization for ab initio materials data</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<style>
body{margin:0;padding:0;overflow:hidden;}
html, body{height:100%;}
#plot3d{width:100%;height:100%;}
</style>
<script type="text/javascript" src="plotly.min.js"></script>
</head>
<body>
<div id="plot3d"></div>
<script type="text/javascript">
var points = {}, clusters = [], total_downloads = 2, colors = ['#396', '#06f', '#9c6', '#6cf', '#f90', '#90c', '#f00', '#300', '#fc6', '#c00'];
function unpack(rows, key, verbatim){
if (verbatim) return rows.map(function(row) { return row[key] });
else return rows.map(function(row) { return parseFloat(row[key]) });
}
function shake(rows){
return rows.map(function(row) { return row + ((Math.random() < 0.5) ? -0.1 : 0.1) });
}
function gen_shake(){
return Math.floor(Math.random()*25) * ((Math.floor(Math.random()*2) == 1) ? 0.01 : -0.01);
}
Plotly.d3.csv('points.csv', function(err, rows){
window.points = {
x: unpack(rows, 'x'),
y: unpack(rows, 'y'),
z: unpack(rows, 'z'),
text: unpack(rows, 'label', true),
mode: 'markers',
type: 'scatter3d',
hoverinfo: 'text',
marker: {
color: '#f00',
size: 3}
}
if (!--total_downloads) render_all();
});
Plotly.d3.csv('clusters.csv', function(err, rows){
var container = [], cnt = 0;
for (var i=0; i<rows.length; i++){
if (rows[i].x=="-" && rows[i].y=="-" && rows[i].z=="-"){
// for too small clusters
if (container.length < 5){
for (var j=0, todo=5-container.length; j<todo; j++){
container.push({
x:parseFloat(container[0].x)+gen_shake(),
y:parseFloat(container[0].y)+gen_shake(),
z:parseFloat(container[0].z)+gen_shake()
});
}
}
window.clusters.push({
type: 'mesh3d',
alphahull: 1,
x: shake(unpack(container, 'x')),
y: shake(unpack(container, 'y')),
z: unpack(container, 'z'),
opacity: 0.075,
color: window.colors[cnt] || '#000',
hoverinfo: 'none'
});
container = [];
cnt++;
} else container.push(rows[i]);
}
if (!--total_downloads) render_all();
});
function render_all(){
var layout = {
autosize: true,
width: document.body.clientWidth,
height: document.body.clientHeight,
scene: {
aspectratio: {
x: 1,
y: 1,
z: 1
},
camera: {
center: {
x: 0,
y: 0,
z: 0
},
eye: {
x: 1.25,
y: 1.25,
z: 1.25
},
up: {
x: 0,
y: 0,
z: 1
}
},
xaxis: {
title: 'Group',
dtick: 1.0,
type: 'linear',
zeroline: false
},
yaxis: {
title: 'Group',
dtick: 1.0,
type: 'linear',
zeroline: false
},
zaxis: {
title: 'Band gap, eV',
type: 'linear',
zeroline: false
}
}
}
var data = [window.points];
//console.log(window.clusters);
for (var i=0; i<window.clusters.length; i++){
data.push(window.clusters[i]);
}
Plotly.newPlot('plot3d', data, layout);
}
</script>
</body>
</html>