1 | <!doctype html>
|
2 | <html>
|
3 | <head>
|
4 | <title>Graph 3D cloud with colored dots</title>
|
5 |
|
6 | <style>
|
7 | body {font: 10pt arial;}
|
8 | </style>
|
9 |
|
10 | <script type="text/javascript" src="../../dist/vis-graph3d.min.js"></script>
|
11 |
|
12 | <script type="text/javascript">
|
13 | var data = null;
|
14 | var graph = null;
|
15 |
|
16 | function onclick(point) {
|
17 | console.log(point);
|
18 | }
|
19 |
|
20 |
|
21 | function drawVisualization() {
|
22 |
|
23 | data = new vis.DataSet();
|
24 |
|
25 |
|
26 | var sqrt = Math.sqrt;
|
27 | var pow = Math.pow;
|
28 | var random = Math.random;
|
29 |
|
30 |
|
31 | var imax = 100;
|
32 | for (var i = 0; i < imax; i++) {
|
33 | var x = pow(random(), 2);
|
34 | var y = pow(random(), 2);
|
35 | var z = pow(random(), 2);
|
36 | var style = (i%2==0) ? sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2)) : "#00ffff";
|
37 |
|
38 | data.add({x:x,y:y,z:z,style:style});
|
39 | }
|
40 |
|
41 |
|
42 | var options = {
|
43 | width: '600px',
|
44 | height: '600px',
|
45 | style: 'dot-color',
|
46 | showPerspective: true,
|
47 | showGrid: true,
|
48 | keepAspectRatio: true,
|
49 | verticalRatio: 1.0,
|
50 | legendLabel: 'distance',
|
51 | onclick: onclick,
|
52 | cameraPosition: {
|
53 | horizontal: -0.35,
|
54 | vertical: 0.22,
|
55 | distance: 1.8
|
56 | }
|
57 | };
|
58 |
|
59 |
|
60 | var container = document.getElementById('mygraph');
|
61 | graph = new vis.Graph3d(container, data, options);
|
62 | }
|
63 | </script>
|
64 |
|
65 | </head>
|
66 |
|
67 | <body onload="drawVisualization()">
|
68 | <div id="mygraph"></div>
|
69 |
|
70 | <div id="info"></div>
|
71 | </body>
|
72 | </html>
|