-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.coffee
124 lines (98 loc) · 3.07 KB
/
script.coffee
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
GLOBAL = exports ? this
GLOBAL.inventingOnPrinciple =
Models: {}
Collections: {}
Views: {}
Routers: {}
Templates: {}
Options:
max: 200
init: ->
@model = new inventingOnPrinciple.Models.ApplicationModel()
@view = new inventingOnPrinciple.Views.ApplicationView
el: '#main'
model: @model
getTemplate: (templateName) ->
inventingOnPrinciple.Templates[templateName]
$ ->
inventingOnPrinciple.init()
try
inventingOnPrinciple.codeEditor = CodeMirror.fromTextArea(document.getElementById('code'),
lineNumbers: true
matchBrackets: true
)
inventingOnPrinciple.codeEditor.on('scroll', (editor) ->
inventingOnPrinciple.view.scrollVars editor.getScrollInfo()
)
inventingOnPrinciple.codeEditor.on('cursorActivity', (editor) ->
inventingOnPrinciple.view.trackCursor editor
)
inventingOnPrinciple.codeEditor.on('change', (editor, changeInfo) ->
inventingOnPrinciple.view.parse editor, changeInfo
)
filename = util.getParameterByName('f') ? 'source4'
$.get "/scripts/#{filename}.txt", (source) ->
inventingOnPrinciple.codeEditor.setValue source
, 'text'
# inventingOnPrinciple.outputcode = CodeMirror.fromTextArea(document.getElementById('outputcode'),
# mode: 'javascript'
# lineNumbers: true
# readOnly: true
# )
# inventingOnPrinciple.stateView = new inventingOnPrinciple.Views.StateView
# el: '#stateContainer'
catch e
console.log e
console.log 'CodeMirror failed to initialize'
inventingOnPrinciple.view.parse()
$console = $('#console')
window.log = (message) ->
# DO MESSAGE HERE.
text = $console.html()
text += (message + ' ')
$console.html text
$console.scrollTop ($console[0].scrollHeight - $console.height())
window.genTangle 'span[data-container=max]', inventingOnPrinciple.Options, ->
inventingOnPrinciple.Options.max = @max
inventingOnPrinciple.view.parse()
#Width and height
w = h = 450
svg = d3.select('#tab_d3')
.append('svg')
.attr('width', w)
.attr('height', h)
window.initD3 = _.once((data) ->
xs = _.pluck(data, '0');
ys = _.pluck(data, '1');
radius = w / data.length / 2
margin = radius * 4
xscale = d3.scale.linear().domain([_.min(xs), _.max(xs)]).range([margin, w - margin])
yscale = d3.scale.linear().domain([_.min(ys), _.max(ys)]).range([margin, h - margin])
window.xf = (d) -> xscale(d[0])
window.yf = (d) -> yscale(d[1])
svg.selectAll('circle')
.data(data)
.enter()
.append('circle')
.attr('cx', xf)
.attr('cy', yf)
.attr 'r', radius
svg.selectAll('text')
.data(data)
.text((d) -> "(#{d[0]},#{d[1]})")
.attr('x', xf)
.attr('y', yf)
)
window.updateD3 = (data) ->
window.initD3 data
svg.selectAll('circle')
.data(data)
# .transition().duration(50)
.attr('cx', xf)
.attr('cy', yf)
svg.selectAll('text')
.data(data)
# .transition().duration(50)
.text((d) -> "(#{d[0]},#{d[1]})")
.attr('x', xf)
.attr('y', yf)