-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterface.js
More file actions
123 lines (95 loc) · 2.26 KB
/
interface.js
File metadata and controls
123 lines (95 loc) · 2.26 KB
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
$( function()
{
$("#toolbar li").click( function(e)
{
$(this).blur()
cn = $(this).attr("fn")
for( var i in t )
if( i == cn )
t[i]()
return
for( var i in fns )
if( i == cn )
fns[cn](t,e)
return
})
$("#sidebar").delegate("li b", "click", function()
{
// $(this).parent().children("div").slideToggle(500)
$(this).parent().toggleClass("closed")
})
$("#imex input").click( function()
{
format = $("#imex select").val()
dir = $(this).attr("class")
if( dir == "import-button" )
{
fn = "from" + format
data = $("#imex textarea").val()
w3d = false
if( t.graph.is_3d )
{
t.toggle_2d()
w3d = true
}
t.graph.format[fn](data)
if( w3d ) t.toggle_3d()
}
else
{
fn = "as" + format
$("#imex textarea").val( t.graph.format[fn]() )
}
})
})
var graphs = []
function add_sidebar_box(title, content)
{
id = "b" + Math.ceil(Math.random() * 1000)
if( content.match(/^graph.*/i) ) content = "<span class='stats'></span><div class='graph'></div>";
html = "<li><b>" + title + "</b><div id='"+id+"'>" + content + "</div></li>"
$("#sidebar").append(html)
return "#" + id
}
function register_graph(t, fn, canvas, frameskip)
{
f = function(i)
{
if(t.graph.paused) i += Math.round(Math.random() * 100)
if( i % this.frameskip || t.graph.paused ) return;
if(typeof(t.graph) == "undefined")
return;
if(typeof(t.graph.energy) == "undefined")
t.graph.energy = new Energy(t.graph)
d = t.graph.energy[fn](this.frameskip)
if( !d ) return;
if( $(this.canvas.element).find(":visible").length )
{
for( var i in this.stack )
this.add( this.stack[i][0], this.stack[i][1] )
te = []
for( var i in d )
{
this.add(d[i], i)
te.push( "<b>"+i+"</b><span>"+(Math.round(d[i]*100)/100).toString()+"</span>" )
}
$(this.canvas.element).parent().find(".stats").html(te.join(""))
this.stack = []
this.draw()
}
else
{
for( var i in d )
this.stack.push([ d[i], i ])
}
}
if( typeof(frameskip) == 'undefined' || frameskip == null )
frameskip = 10
if( typeof(t.graph.energy) == "undefined" )
t.graph.energy = new Energy(t.graph)
l = new Linegraph(canvas)
l.auto_draw = false
l.frameskip = frameskip
t.graphs.push([f,l])
t.graph.bind('iteration', f, l)
}