From b1efb549ab8b52178d07ebabd57178b716f827ce Mon Sep 17 00:00:00 2001 From: David Schoonover Date: Wed, 20 Jun 2012 08:52:36 -0700 Subject: [PATCH] Fixes ordering issue with non-default chart-types. --- lib/graph/graph-display-view.co | 4 ---- lib/graph/graph-edit-view.co | 7 ++----- lib/graph/graph-model.co | 2 +- lib/graph/graph-view.co | 15 +++++++++------ 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/graph/graph-display-view.co b/lib/graph/graph-display-view.co index b1ce5d1..868d910 100644 --- a/lib/graph/graph-display-view.co +++ b/lib/graph/graph-display-view.co @@ -38,10 +38,6 @@ GraphDisplayView = exports.GraphDisplayView = GraphView.extend do # {{{ @chartOptions @model.getOptions(), {+silent} @loadData() - onReady: -> - return if @ready - @triggerReady() - @onSync() diff --git a/lib/graph/graph-edit-view.co b/lib/graph/graph-edit-view.co index 2d6867e..97d220d 100644 --- a/lib/graph/graph-edit-view.co +++ b/lib/graph/graph-edit-view.co @@ -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} diff --git a/lib/graph/graph-model.co b/lib/graph/graph-model.co index cd8503d..96e679f 100644 --- a/lib/graph/graph-model.co +++ b/lib/graph/graph-model.co @@ -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'} diff --git a/lib/graph/graph-view.co b/lib/graph/graph-view.co index 1d0bbd3..b6dff7d 100644 --- a/lib/graph/graph-view.co +++ b/lib/graph/graph-view.co @@ -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(' — ') 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 /** -- 1.7.0.4