From 4b715546fd6eed6c04d67f7cca31e93dff22f2e1 Mon Sep 17 00:00:00 2001 From: dsc Date: Wed, 18 Apr 2012 11:47:15 -0700 Subject: [PATCH] Checkpoint: Graphs now render from their Dataset model --- lib/dataset/dataset-model.co | 11 +++++++++-- lib/dataset/datasource-model.co | 5 +++++ lib/dataset/metric-model.co | 6 ++++++ lib/graph/graph-edit-view.co | 7 +++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/dataset/dataset-model.co b/lib/dataset/dataset-model.co index 47ae0e8..c6767a3 100644 --- a/lib/dataset/dataset-model.co +++ b/lib/dataset/dataset-model.co @@ -58,20 +58,27 @@ DataSet = exports.DataSet = BaseModel.extend do # {{{ next.ok source .seq ~> @ready = true - @trigger 'ready', this @unwait() # terminates the `load` wait + @trigger 'ready', this this # TODO: toJSON() must ensure columns in MetricList are ordered by index # ...in theory, MetricList.comparator now does this + getDates: -> + dates = @metrics.invoke 'getDates' + maxLen = _.max _.pluck dates, 'length' + _.find dates, -> it.length is maxLen /** * @returns {Array} The reified dataset, materialized to an array of data-series arrays. */ getData: -> - '/data/datasources/rc/rc_comscore_region_uv.csv' + _.zip ...[ @getDates() ].concat @metrics.invoke 'getData' + + getLabels: -> + ['Date'].concat @metrics.pluck 'label' newMetric: -> index = @metrics.length diff --git a/lib/dataset/datasource-model.co b/lib/dataset/datasource-model.co index 57fed50..4b13667 100644 --- a/lib/dataset/datasource-model.co +++ b/lib/dataset/datasource-model.co @@ -123,9 +123,14 @@ DataSource = exports.DataSource = BaseModel.extend do # {{{ @trigger 'load-error', this, txtStatus, err + getDates: -> + @data.dateColumn + getData: -> @data.toJSON?() or @data + getColumn: (idx) -> + @data.columns[idx] getColumnName: (idx) -> @get('metrics')?[idx]?.label diff --git a/lib/dataset/metric-model.co b/lib/dataset/metric-model.co index 72e95de..d339283 100644 --- a/lib/dataset/metric-model.co +++ b/lib/dataset/metric-model.co @@ -49,6 +49,12 @@ Metric = exports.Metric = BaseModel.extend do # {{{ @lookupSource() + getDates: -> + @source.getDates() + + getData: -> + @source.getColumn @get 'source_col' + lookupSource: -> if source_id = @get 'source_id' @wait() diff --git a/lib/graph/graph-edit-view.co b/lib/graph/graph-edit-view.co index 6f50b41..30edab8 100644 --- a/lib/graph/graph-edit-view.co +++ b/lib/graph/graph-edit-view.co @@ -237,13 +237,16 @@ GraphEditView = exports.GraphEditView = BaseView.extend do # {{{ # Redraw chart inside viewport. renderChart: -> - data = @model.get 'dataset' - data = data.getData() if typeof data is not 'string' + # data = @model.get 'dataset' + # data = data.getData() if typeof data is not 'string' + dataset = @model.dataset + data = dataset.getData() size = @resizeViewport() # XXX: use @model.changedAttributes() to calculate what to update options = @chartOptions() #import size options import do + labels : dataset.getLabels() labelsDiv : @$el.find '.graph-label' .0 valueFormatter : @numberFormatterHTML axes: -- 1.7.0.4