Changeset - 2809a8b732f6
[Not reviewed]
default
0 3 0
Drew Perttula - 9 years ago 2016-06-05 02:04:12
drewp@bigasterisk.com
optimize graph lookup calls during zoom steps
Ignore-this: ab3499a36e5bc2e495fe4abdd2209e35
3 files changed with 26 insertions and 17 deletions:
0 comments (0 inline, 0 general)
light9/web/adjustable.coffee
Show inline comments
 
@@ -94,21 +94,24 @@ class window.AdjustableFloatObject exten
 
    #   pred
 
    #   ctx
 
    #   getTargetTransform(value) -> getTarget result for value
 
    #   getValueForPos
 

	
 
    super(@config)
 

	
 
    
 
  _getValue: () ->
 
    @config.graph.floatValue(@config.subj, @config.pred)
 
    # this is a big speedup- callers use _getValue about 4x as much as
 
    # the graph changes and graph.floatValue is slow
 
    @_currentValue
 

	
 
  getTarget: () ->
 
    @config.getTargetTransform(@_getValue())
 
    
 
  subscribe: (onChange) ->
 
    @config.graph.subscribe @config.subj, @config.pred, null, (patch) =>
 
      @_currentValue = @config.graph.floatValue(@config.subj, @config.pred)
 
      onChange()
 
    
 
  continueDrag: (pos) ->
 
    # pos is vec2 of pixels relative to the drag start
 
    
 
    newValue = @config.getValueForPos(@_editorCoordinates())
light9/web/graph.coffee
Show inline comments
 
log = console.log
 

	
 
# Patch is {addQuads: <quads>, delQuads: <quads>}
 
# <quads> is [{subject: s, ...}, ...]
 

	
 
# partial port of autodepgraphapi.py
 
class GraphWatchers
 
  constructor: ->
light9/web/timeline.coffee
Show inline comments
 
@@ -35,28 +35,32 @@ Polymer
 
  attached: ->
 
    @dia = @$.dia
 

	
 
    ko.computed =>
 
      @debug = ko.toJSON(@viewState)
 

	
 
    ko.computed =>
 
      @fullZoomX = d3.scaleLinear().domain([0, @viewState.zoomSpec.duration()]).range([0, @width()])
 
      @zoomInX = d3.scaleLinear().domain([@viewState.zoomSpec.t1(), @viewState.zoomSpec.t2()]).range([0, @width()])
 
      @dia.setTimeAxis(@width(), @$.zoomed.$.audio.offsetTop, @zoomInX)
 
      @$.adjusters.updateAllCoords()
 
    ko.computed( =>
 
        @fullZoomX = d3.scaleLinear().domain([0, @viewState.zoomSpec.duration()]).range([0, @width()])
 
        @zoomInX = d3.scaleLinear().domain([@viewState.zoomSpec.t1(), @viewState.zoomSpec.t2()]).range([0, @width()])
 
        @dia.setTimeAxis(@width(), @$.zoomed.$.audio.offsetTop, @zoomInX)
 
        @$.adjusters.updateAllCoords()
 
      ).extend({rateLimit: 5})
 

	
 
    ko.computed =>
 
      # zoomInX changing doesn't retrigger this, so I'll do it here
 
      ko.toJS(@viewState.zoomSpec)
 
      
 
      @$.dia.setCursor(@$.audio.offsetTop, @$.audio.offsetHeight,
 
                       @$.zoomed.$.time.offsetTop,
 
                       @$.zoomed.$.time.offsetHeight,
 
                       @fullZoomX, @zoomInX, @viewState.cursor)
 
  
 
    @adjs = @makeZoomAdjs().concat(@persistDemo())
 
    ko.computed( =>
 
        # zoomInX changing doesn't retrigger this, so I'll do it here
 
        ko.toJS(@viewState.zoomSpec)
 
        
 
        @$.dia.setCursor(@$.audio.offsetTop, @$.audio.offsetHeight,
 
                         @$.zoomed.$.time.offsetTop,
 
                         @$.zoomed.$.time.offsetHeight,
 
                         @fullZoomX, @zoomInX, @viewState.cursor)
 
      )
 

	
 
    setTimeout =>
 
        @adjs = @makeZoomAdjs().concat(@persistDemo())
 
      , 2000
 
    @trackMouse()
 
    @bindKeys()
 
    @bindWheelZoom()
 

	
 
  trackMouse: ->
 
    # not just for show- we use the mouse pos sometimes
0 comments (0 inline, 0 general)