-
Notifications
You must be signed in to change notification settings - Fork 0
/
sjbdvis.html
205 lines (168 loc) · 5.75 KB
/
sjbdvis.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>developerWorks WebGL SceneJS Big Data Visualization Example</title>
<meta charset="utf-8">
<script src="./scenejs.js"></script>
<script>
var mouse = {x: 0, y: 0, updated: false, clicked: false};
var monthLabels = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var yearLabels = ["2004","2005","2006","2007","2008","2009","2010","2011","2012","2013"];
var PeakThreshold = 97;
var HighThreshold = 93;
var data = [];
var node2Data = {};
function initData() {
for (var dim=0; dim<100; dim++) {
var axis = [];
var datacenter = String.fromCharCode(65 + Math.floor(dim /26)) + String.fromCharCode(65 + (dim % 26));
for (var i=0; i<100; i++) {
var val = Math.floor(Math.random() * 100 + 1);
var dpoint = {
location: datacenter,
year: yearLabels[ Math.floor(i /12)],
month: monthLabels[ i % 12],
value: val};
axis.push(dpoint);
}
data.push(axis);
}
}
SceneJS.setConfigs({
pluginPath:"./plugins"
});
var coreScene = {
nodes:[
{
id: "light1",
type:"lights",
lights:[
{
mode:"dir",
color:{ r:1.0, g:1.0, b:1.0 },
diffuse:true,
specular:true,
dir:{ x:-5, y:-2, z:-5 },
space:"view"
}
]
}
]
};
var scene = undefined;
function setUp() {
scene = SceneJS.createScene({
canvasId: "shapecanvas2",
nodes:
[
{ type:"cameras/orbit",
look:{ x: 80, y:0 },
yaw: 0,
pitch: -20,
zoom: 200,
zoomSensitivity:10.0,
nodes: [coreScene]
}
]
});
initData();
scene.getNode("light1", function(light) {
var zpos = 0;
data.forEach(function(dim) {
zpos++;
var xpos = 0;
dim.forEach(function(dpoint) {
var curVal = dpoint["value"];
var curColor = ((curVal > PeakThreshold) ? { r: 1, g:0, b:0} :
((curVal > HighThreshold) ? {r:1, g:1, b:0} : {r:0, g:1, b:0}));
var nodeName = "n" + zpos + "m" + xpos ;
node2Data[nodeName] = dpoint;
light.addNode(
{ type: "name",
name: nodeName,
nodes: [
{
type: "material",
color: curColor,
nodes:[ {
type:"translate",
y: curVal/10,
x: xpos++,
z: zpos,
nodes:[
{
type:"prims/box",
xSize: 1,
ySize: curVal/10,
zSize: 1
}
]
}
]
}
]
}
);
}); // dim.forEach
}); // data.forEach
}); // scene.getNode("light1")
scene.on("pick",
function (hit) {
var name = hit.name;
var datapoint = node2Data[hit.name];
document.getElementById("dmonth").innerHTML = datapoint["month"];
document.getElementById("dyear").innerHTML = datapoint["year"];
document.getElementById("dcenter").innerHTML = datapoint["location"];
if (mouse.clicked) {
//simulate dive into detailed data
alert("Show daily detailed reports for " + datapoint["month"] + ", "
+ datapoint["year"] + " at data center location "
+ datapoint["location"]);
mouse.clicked = false;
}
});
var canvas = scene.getCanvas();
canvas.addEventListener('mousemove',
function(event) {
mouse = {x: event.clientX, y: event.clientY, updated: false, clicked: false};
},
false);
canvas.addEventListener('mousedown',
function(event) {
mouse = {x: event.clientX, y: event.clientY, updated: false, clicked: true};
},
false);
scene.on("tick", function() {
if (!mouse.updated) {
scene.pick(mouse.x, mouse.y);
mouse.updated = true;
}
});
var status = document.createElement('div');
var month = document.createElement('span');
var dcenter = document.createElement('span');
var year = document.createElement('span');
dcenter.innerHTML = "??";
month.innerHTML = "???";
year.innerHTML = "????";
status.style.cssText = "position:absolute;width:300;height:200;color:rgba(255,255,255,0.3);background-color:rgba(0,0,0,0);top:20px;left:150px;font:bold 75px arial,sans-serif";
dcenter.style.cssText = "position:relative;left:5px;top:0px";
month.style.cssText= "position:relative;left:350px;top:0px";
year.style.cssText = "position:relative;left:400px;top:0px";
dcenter.setAttribute("id", "dcenter");
month.setAttribute("id","dmonth");
year.setAttribute("id","dyear");
status.appendChild(dcenter);
status.appendChild(month);
status.appendChild(year);
document.getElementById("container").appendChild(status);
} // setup
</script>
</head>
<body onload="setUp()">
<span id="container" width="1024" height="500">
<canvas id="shapecanvas2" style="border: none;" width="1024" height="500"></canvas>
</span>
<br/>
</body>
</html>