-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.html
209 lines (137 loc) · 4.54 KB
/
home.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
<html>
<head>
<title> Chart 3D - By frenk </title>
<style>
body {
font-family: Monospace;
background-color: #f0f0f0;
margin: 0px;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%
}
</style>
<script src="lib/three.min.js"></script>
<script src="lib/orbitControls.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="lib/plot.js"></script>
<script src="other/TABLE2D.js"></script>
</head>
<body>
<script>
var camera, scene, projector, renderer, raycaster;
var barCh, pieCh, areaCh, base, currentCh;
var config;
var highlighted;
initScene();
initGui();
//--------------------------------------------------------------------
// scene initialization
function initScene() {
raycaster = new THREE.Raycaster();
projector = new THREE.Projector();
// renderer
renderer = new THREE.WebGLRenderer({ antialias : true });
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x333333 );
document.body.appendChild( renderer.domElement );
// camera and controll
camera = new THREE.PerspectiveCamera( 75,
window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 10;
camera.position.y = 10;
controll = new THREE.OrbitControls( camera, renderer.domElement );
controll.addEventListener( 'change', render );
// graphs
barCh = plotBarCh( data, val_x_row );
pieCh = plotPieCh( data.slice(0, val_x_row) );
areaCh = plotAreaCh( data, val_x_row );
currentCh = barCh;
// scene
scene = new THREE.Scene();
scene.add( base = base() );
scene.add( currentCh );
controll.update();
}
//--------------------------------------------------------------------
// gui initialization (dat.gui)
function initGui() {
var Options = function() {
this.graph = 'Bar';
};
config = new Options();
var gui = new dat.GUI();
var subGui = gui.addFolder('Graph type');
subGui.open();
// callbacks
subGui.add( config, 'graph', ['Bar', 'Pie', 'Area'])
.name( 'Graph' )
.onChange(
function( selection ) {
switch ( selection ) {
case 'Bar' :
scene.remove( currentCh );
currentCh = barCh;
scene.add( currentCh );
break;
case 'Pie' :
scene.remove( currentCh );
currentCh = pieCh;
scene.add( currentCh );
break;
case 'Area' :
scene.remove( currentCh );
currentCh = areaCh;
scene.add( currentCh );
break;
}
}
);
};
//--------------------------------------------------------------------
// render function
function render() { renderer.render(scene, camera); };
//--------------------------------------------------------------------
// Callback for zoom in/out whit mouse's wheel
window.onmousewheel =
function ( event ) {
controll.update();
};
//--------------------------------------------------------------------
// Callback for arrange viewport on resize
window.onresize =
function onWindowResize() {
renderer.setSize( window.innerWidth, window.innerHeight );
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
requestAnimationFrame( render );
};
//--------------------------------------------------------------------
// Callback for highlight graph item
window.onmouseup =
function( event ) {
// restore default colors
if ( highlighted !== undefined )
highlighted.ref.material.color =
highlighted.color;
var vector = new THREE.Vector3(
( event.clientX / window.innerWidth ) * 2 - 1,
- ( event.clientY / window.innerHeight ) * 2 + 1, 1);
projector.unprojectVector( vector, camera );
raycaster.set( camera.position, vector.sub( camera.position ).normalize() );
var intersects = raycaster.intersectObjects( currentCh.children );
// highlight and memorize original color
if (intersects.length > 0) {
highlighted = {
ref: intersects[0].object,
color: intersects[0].object.material.color
};
intersects[0].object.material.color = new THREE.Color( 0xffffff );
}
requestAnimationFrame( render );
}
</script>
</body>
</html>