annotate web/timeline/Note.coffee @ 2404:9cbc93f80b05

cleanup
author drewp@bigasterisk.com
date Fri, 17 May 2024 17:41:22 -0700
parents 4556eebe5d73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2062
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
1 log = debug('timeline')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
2 debug.enable('*')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
3
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
4 Drawing = window.Drawing
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
5 ROW_COUNT = 7
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
6
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
7 # Maintains a pixi object, some adjusters, and inlineattrs corresponding to a note
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
8 # in the graph.
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
9 class Note
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
10 constructor: (@parentElem, @container, @project, @graph, @selection, @uri, @setAdjuster, @song, @viewState, @brickLayout) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
11 @adjusterIds = new Set() # id string
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
12 @updateSoon = _.debounce(@update.bind(@), 30)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
13
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
14 initWatchers: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
15 @graph.runHandler(@update.bind(@), "note update #{@uri.value}")
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
16 ko.computed @update.bind(@)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
17
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
18 destroy: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
19 log('destroy', @uri.value)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
20 @isDetached = true
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
21 @clearAdjusters()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
22 @parentElem.updateInlineAttrs(@uri, null)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
23
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
24 clearAdjusters: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
25 @adjusterIds.forEach (i) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
26 @setAdjuster(i, null)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
27 @adjusterIds.clear()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
28
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
29 getCurvePoints: (subj, curveAttr) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
30 U = (x) => @graph.Uri(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
31 originTime = @graph.floatValue(subj, U(':originTime'))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
32
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
33 for curve in @graph.objects(subj, U(':curve'))
2105
35468f1dcf38 comments
drewp@bigasterisk.com
parents: 2062
diff changeset
34 # todo: maybe shoudl be :effectAttr?
2062
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
35 if @graph.uriValue(curve, U(':attr')).equals(curveAttr)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
36 return @project.getCurvePoints(curve, originTime)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
37 throw new Error("curve #{@uri.value} has no attr #{curveAttr.value}")
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
38
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
39 midPoint: (i0, i1) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
40 p0 = @worldPts[i0]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
41 p1 = @worldPts[i1]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
42 p0.x(.5).add(p1.x(.5))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
43
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
44 _planDrawing: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
45 U = (x) => @graph.Uri(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
46 [pointUris, worldPts] = @getCurvePoints(@uri, U(':strength'))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
47 effect = @graph.uriValue(@uri, U(':effectClass'))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
48
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
49 yForV = @brickLayout.yForVFor(@)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
50 dependOn = [@viewState.zoomSpec.t1(),
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
51 @viewState.zoomSpec.t2(),
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
52 @viewState.width()]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
53 screenPts = (new PIXI.Point(@viewState.zoomInX(pt.e(1)),
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
54 yForV(pt.e(2))) for pt in worldPts)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
55 return {
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
56 yForV: yForV
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
57 worldPts: worldPts
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
58 screenPts: screenPts
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
59 effect: effect
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
60 hover: @uri.equals(@selection.hover())
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
61 selected: @selection.selected().filter((s) => s.equals(@uri)).length
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
62 }
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
63
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
64 onRowChange: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
65 @clearAdjusters()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
66 @updateSoon()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
67
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
68 redraw: (params) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
69 # no observable or graph deps in here
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
70 @container.removeChildren()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
71 @graphics = new PIXI.Graphics({nativeLines: false})
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
72 @graphics.interactive = true
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
73 @container.addChild(@graphics)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
74
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
75 if params.hover
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
76 @_traceBorder(params.screenPts, 12, 0x888888)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
77 if params.selected
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
78 @_traceBorder(params.screenPts, 6, 0xff2900)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
79
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
80 shape = new PIXI.Polygon(params.screenPts)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
81 @graphics.beginFill(@_noteColor(params.effect), .313)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
82 @graphics.drawShape(shape)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
83 @graphics.endFill()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
84
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
85 @_traceBorder(params.screenPts, 2, 0xffd900)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
86
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
87 @_addMouseBindings()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
88
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
89
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
90 update: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
91 if not @parentElem.isActiveNote(@uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
92 # stale redraw call
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
93 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
94
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
95 if @worldPts
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
96 @brickLayout.setNoteSpan(@, @worldPts[0].e(1),
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
97 @worldPts[@worldPts.length - 1].e(1))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
98
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
99 params = @_planDrawing()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
100 @worldPts = params.worldPts
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
101
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
102 @redraw(params)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
103
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
104 curveWidthCalc = () => @project.curveWidth(@worldPts)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
105 @_updateAdjusters(params.screenPts, @worldPts, curveWidthCalc,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
106 params.yForV, @viewState.zoomInX, @song)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
107 @_updateInlineAttrs(params.screenPts, params.yForV)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
108 @parentElem.noteDirty()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
109
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
110 _traceBorder: (screenPts, thick, color) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
111 @graphics.lineStyle(thick, color, 1)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
112 @graphics.moveTo(screenPts[0].x, screenPts[0].y)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
113 for p in screenPts.slice(1)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
114 @graphics.lineTo(p.x, p.y)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
115
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
116 _addMouseBindings: () ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
117 @graphics.on 'mousedown', (ev) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
118 @_onMouseDown(ev)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
119
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
120 @graphics.on 'mouseover', =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
121 if @selection.hover() and @selection.hover().equals(@uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
122 # Hovering causes a redraw, which would cause another
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
123 # mouseover event.
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
124 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
125 @selection.hover(@uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
126
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
127 # mouseout never fires since we rebuild the graphics on mouseover.
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
128 @graphics.on 'mousemove', (ev) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
129 if @selection.hover() and @selection.hover().equals(@uri) and ev.target != @graphics
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
130 @selection.hover(null)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
131
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
132 onUri: ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
133 @graph.runHandler(@update.bind(@), "note updates #{@uri}")
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
134
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
135 patchCouldAffectMe: (patch) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
136 if patch and patch.addQuads # sometimes patch is a polymer-sent value. @update is used as a listener too
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
137 if patch.addQuads.length == patch.delQuads.length == 1
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
138 add = patch.addQuads[0]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
139 del = patch.delQuads[0]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
140 if (add.predicate.equals(del.predicate) and del.predicate.equals(@graph.Uri(':time')) and add.subject.equals(del.subject))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
141 timeEditFor = add.subject
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
142 if @worldPts and timeEditFor not in @pointUris
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
143 return false
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
144 return true
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
145
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
146 xupdate: (patch) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
147 # update our note DOM and SVG elements based on the graph
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
148 if not @patchCouldAffectMe(patch)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
149 # as autodep still fires all handlers on all patches, we just
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
150 # need any single dep to cause another callback. (without this,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
151 # we would no longer be registered at all)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
152 @graph.subjects(@uri, @uri, @uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
153 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
154 if @isDetached?
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
155 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
156
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
157 @_updateDisplay()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
158
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
159 _updateAdjusters: (screenPts, worldPts, curveWidthCalc, yForV, zoomInX, ctx) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
160 # todo: allow offset even on more narrow notes
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
161 if screenPts[screenPts.length - 1].x - screenPts[0].x < 100 or screenPts[0].x > @parentElem.offsetWidth or screenPts[screenPts.length - 1].x < 0
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
162 @clearAdjusters()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
163 else
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
164 @_makeOffsetAdjuster(yForV, curveWidthCalc, ctx)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
165 @_makeCurvePointAdjusters(yForV, worldPts, ctx)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
166 @_makeFadeAdjusters(yForV, zoomInX, ctx, worldPts)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
167
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
168 _updateInlineAttrs: (screenPts, yForV) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
169 w = 280
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
170
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
171 leftX = Math.max(2, screenPts[Math.min(1, screenPts.length - 1)].x + 5)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
172 rightX = screenPts[Math.min(2, screenPts.length - 1)].x - 5
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
173 if screenPts.length < 3
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
174 rightX = leftX + w
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
175
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
176 if rightX - leftX < w or rightX < w or leftX > @parentElem.offsetWidth
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
177 @parentElem.updateInlineAttrs(@uri, null)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
178 return
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
179
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
180 config = {
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
181 uri: @uri,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
182 left: leftX,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
183 top: yForV(1) + 5,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
184 width: w,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
185 height: yForV(0) - yForV(1) - 15,
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
186 }
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
187
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
188 @parentElem.updateInlineAttrs(@uri, config)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
189
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
190 _makeCurvePointAdjusters: (yForV, worldPts, ctx) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
191 for pointNum in [0...worldPts.length]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
192 @_makePointAdjuster(yForV, worldPts, pointNum, ctx)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
193
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
194 _makePointAdjuster: (yForV, worldPts, pointNum, ctx) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
195 U = (x) => @graph.Uri(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
196
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
197 adjId = @uri.value + '/p' + pointNum
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
198 @adjusterIds.add(adjId)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
199 @setAdjuster adjId, =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
200 adj = new AdjustableFloatObject({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
201 graph: @graph
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
202 subj: worldPts[pointNum].uri
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
203 pred: U(':time')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
204 ctx: ctx
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
205 getTargetPosForValue: (value) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
206 $V([@viewState.zoomInX(value), yForV(worldPts[pointNum].e(2))])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
207 getValueForPos: (pos) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
208 origin = @graph.floatValue(@uri, U(':originTime'))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
209 (@viewState.zoomInX.invert(pos.e(1)) - origin)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
210 getSuggestedTargetOffset: () => @_suggestedOffset(worldPts[pointNum]),
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
211 })
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
212 adj._getValue = (=>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
213 # note: don't use originTime from the closure- we need the
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
214 # graph dependency
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
215 adj._currentValue + @graph.floatValue(@uri, U(':originTime'))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
216 )
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
217 adj
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
218
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
219 _makeOffsetAdjuster: (yForV, curveWidthCalc, ctx) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
220 U = (x) => @graph.Uri(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
221
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
222 adjId = @uri.value + '/offset'
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
223 @adjusterIds.add(adjId)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
224 @setAdjuster adjId, =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
225 adj = new AdjustableFloatObject({
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
226 graph: @graph
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
227 subj: @uri
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
228 pred: U(':originTime')
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
229 ctx: ctx
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
230 getDisplayValue: (v, dv) => "o=#{dv}"
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
231 getTargetPosForValue: (value) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
232 # display bug: should be working from pt[0].t, not from origin
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
233 $V([@viewState.zoomInX(value + curveWidthCalc() / 2), yForV(.5)])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
234 getValueForPos: (pos) =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
235 @viewState.zoomInX.invert(pos.e(1)) - curveWidthCalc() / 2
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
236 getSuggestedTargetOffset: () => $V([-10, 0])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
237 })
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
238 adj
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
239
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
240 _makeFadeAdjusters: (yForV, zoomInX, ctx, worldPts) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
241 U = (x) => @graph.Uri(x)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
242 @_makeFadeAdjuster(yForV, zoomInX, ctx, @uri.value + '/fadeIn', 0, 1, $V([-50, -10]))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
243 n = worldPts.length
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
244 @_makeFadeAdjuster(yForV, zoomInX, ctx, @uri.value + '/fadeOut', n - 2, n - 1, $V([50, -10]))
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
245
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
246 _makeFadeAdjuster: (yForV, zoomInX, ctx, adjId, i0, i1, offset) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
247 @adjusterIds.add(adjId)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
248 @setAdjuster adjId, =>
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
249 new AdjustableFade(yForV, zoomInX, i0, i1, @, offset, ctx)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
250
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
251 _suggestedOffset: (pt) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
252 if pt.e(2) > .5
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
253 $V([0, 30])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
254 else
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
255 $V([0, -30])
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
256
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
257 _onMouseDown: (ev) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
258 sel = @selection.selected()
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
259 if ev.data.originalEvent.ctrlKey
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
260 if @uri in sel
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
261 sel = _.without(sel, @uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
262 else
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
263 sel.push(@uri)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
264 else
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
265 sel = [@uri]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
266 @selection.selected(sel)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
267
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
268 _noteColor: (effect) ->
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
269 effect = effect.value
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
270 if effect in ['http://light9.bigasterisk.com/effect/blacklight',
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
271 'http://light9.bigasterisk.com/effect/strobewarm']
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
272 hue = 0
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
273 sat = 100
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
274 else
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
275 hash = 0
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
276 for i in [(effect.length-10)...effect.length]
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
277 hash += effect.charCodeAt(i)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
278 hue = (hash * 8) % 360
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
279 sat = 40 + (hash % 20) # don't conceal colorscale too much
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
280
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
281 return parseInt(tinycolor.fromRatio({h: hue / 360, s: sat / 100, l: .58}).toHex(), 16)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
282
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
283 #elem = @getOrCreateElem(uri+'/label', 'noteLabels', 'text', {style: "font-size:13px;line-height:125%;font-family:'Verana Sans';text-align:start;text-anchor:start;fill:#000000;"})
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
284 #elem.setAttribute('x', curvePts[0].e(1)+20)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
285 #elem.setAttribute('y', curvePts[0].e(2)-10)
d991f7c3485a WIP rough porting of coffee to ts
drewp@bigasterisk.com
parents:
diff changeset
286 #elem.innerHTML = effectLabel