Fixes ordering issue with non-default chart-types.
authorDavid Schoonover <dsc@wikimedia.org>
Wed, 20 Jun 2012 15:52:36 +0000 (08:52 -0700)
committerDavid Schoonover <dsc@wikimedia.org>
Wed, 20 Jun 2012 15:52:36 +0000 (08:52 -0700)
lib/graph/graph-display-view.co
lib/graph/graph-edit-view.co
lib/graph/graph-model.co
lib/graph/graph-view.co

index b1ce5d1..868d910 100644 (file)
@@ -38,10 +38,6 @@ GraphDisplayView = exports.GraphDisplayView = GraphView.extend do # {{{
         @chartOptions @model.getOptions(), {+silent}
         @loadData()
     
-    onReady: ->
-        return if @ready
-        @triggerReady()
-        @onSync()
     
     
     
index 2d6867e..97d220d 100644 (file)
@@ -57,9 +57,6 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{
         
         ### Chart Options Tab, Scaffold
         @scaffold = @addSubview new ChartOptionScaffold
-        # @scaffold.collection.reset that if o.graph_spec
-        # @scaffold.on 'change', @onScaffoldChange
-        @chartType.on 'ready', @onChartTypeReady
         
         
         ### Graph Data UI
@@ -78,7 +75,7 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{
         @loadData()
     
     onChartTypeReady: ->
-        @scaffold.collection.reset @chartType.options_ordered
+        @scaffold.collection.reset @model.chartType.options_ordered
         @scaffold.on 'change', @onScaffoldChange
         @chartOptions @model.getOptions(), {+silent}
     
@@ -86,7 +83,7 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{
         return if @ready
         console.log "(#this via GraphEditView).ready!"
         @unwait() # clears `wait()` from `initialize`
-        # @ready = @scaffold.ready = true
+        @model.chartType.on 'ready', @onChartTypeReady
         @triggerReady()
         @scaffold.triggerReady()
         @chartOptions @model.getOptions(), {+silent}
index cd8503d..96e679f 100644 (file)
@@ -88,6 +88,7 @@ Graph = exports.Graph = BaseModel.extend do # {{{
         attributes.options or= {}
         attributes.slug    or= attributes.id if attributes.id?
         @optionCascade = new Cascade attributes.options
+        @on 'change:chartType', ~> @chartType = ChartType.create this
         BaseModel.call this, attributes, opts
     
     
@@ -96,7 +97,6 @@ Graph = exports.Graph = BaseModel.extend do # {{{
         
         @constructor.register this
         @parents = new GraphList
-        @chartType = ChartType.create this
         
         # Insert submodels in place of JSON
         @dataset = new DataSet {id:@id, ...@get 'data'}
index 1d0bbd3..b6dff7d 100644 (file)
@@ -42,7 +42,6 @@ GraphView = exports.GraphView = BaseView.extend do # {{{
     initialize : (o={}) ->
         @model or= new Graph
         @id = @graph_id = _.domize 'graph', (@model.id or @model.get('slug') or @model.cid)
-        @chartType = @model.chartType.withView this
         GraphView.__super__.initialize ...
         
         for name of @__debounce__
@@ -80,15 +79,19 @@ GraphView = exports.GraphView = BaseView.extend do # {{{
         @wait()
         Seq()
             .seq_ (next) ~>
-                @chartType.once 'ready', next.ok
-            .seq_ (next) ~>
                 @model.once 'ready', next.ok .load()
             .seq_ (next) ~>
+                @model.chartType.once 'ready', next.ok
+            .seq_ (next) ~>
                 @model.once 'data-ready', next.ok .loadData()
             .seq ~>
                 @unwait()
                 @onReady()
     
+    onReady: ->
+        return if @ready
+        @triggerReady()
+        @onSync()
     
     ### Persistence {{{
     
@@ -146,7 +149,7 @@ GraphView = exports.GraphView = BaseView.extend do # {{{
         if callout = @model.getCalloutData()
             {year:yoy, month:mom} = callout
             attrs.callout = 
-                latest : @chartType.numberFormatter(callout.latest, 2, false).toString()
+                latest : @model.chartType.numberFormatter(callout.latest, 2, false).toString()
                 year :
                     dates : yoy.dates.map( -> moment(it).format('MMM YY') ).join(' &mdash; ')
                     value : ( 100 * yoy.value[2] / yoy.value[0] ).toFixed(2) + '%'
@@ -167,14 +170,14 @@ GraphView = exports.GraphView = BaseView.extend do # {{{
      * Resize the viewport to the model-specified bounds.
      */
     resizeViewport: ->
-        @chartType.resizeViewport()
+        @model.chartType?.withView(this).resizeViewport()
     
     
     /**
      * Redraw chart inside viewport.
      */
     renderChart: ->
-        @chart = @chartType.render()
+        @chart = @model.chartType?.withView(this).render()
         this
     
     /**