From 26150d8758f0b392fa9f855e750487127ecaddd7 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 --- data/graphs/ohai.json | 114 ++++++++++++++++++++++++++++++++++++++- 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 ++- 5 files changed, 138 insertions(+), 5 deletions(-) diff --git a/data/graphs/ohai.json b/data/graphs/ohai.json index e765428..224d8d1 100644 --- a/data/graphs/ohai.json +++ b/data/graphs/ohai.json @@ -1 +1,113 @@ -{"options":{"animatedZooms":true,"avoidMinZero":false,"axis":null,"axisLabelColor":"#666666","axisLabelFontSize":11,"axisLabelFormatter":null,"axisLabelWidth":50,"axisLineColor":"#AAAAAA","axisLineWidth":0.3,"axisTickSize":3,"colorSaturation":1,"colorValue":0.5,"colors":["#FF0097","#EF8158","#83BB32","#182B53","#4596FF","#553DC9","#AD3238","#00FFBC","#F1D950"],"connectSeparatedPoints":false,"customBars":false,"dateWindow":null,"delimiter":",","digitsAfterDecimal":2,"displayAnnotations":false,"drawPoints":true,"drawXAxis":true,"drawXGrid":true,"drawYAxis":true,"drawYGrid":true,"errorBars":false,"file":null,"fillAlpha":0.15,"fillGraph":false,"fractions":false,"gridLineColor":"#D8D8D8","gridLineWidth":0.3,"hideOverlayOnMouseOut":false,"highlightCircleSize":4,"includeZero":false,"interactionModel":null,"isZoomedIgnoreProgrammaticZoom":false,"labels":null,"labelsDiv":null,"labelsDivStyles":null,"labelsDivWidth":250,"labelsKMB":true,"labelsKMG2":false,"labelsSeparateLines":true,"labelsShowZeroValues":true,"legend":"always","logscale":true,"maxNumberWidth":30,"panEdgeFraction":null,"pixelsPerLabel":null,"pixelsPerXLabel":null,"pixelsPerYLabel":null,"pointSize":1,"rangeSelectorHeight":40,"rangeSelectorPlotFillColor":"#A7B1C4","rangeSelectorPlotStrokeColor":"#808FAB","rightGap":20,"rollPeriod":1,"showLabelsOnHighlight":true,"showRangeSelector":false,"showRoller":false,"sigFigs":null,"sigma":2,"stackedGraph":false,"stepPlot":false,"strokePattern":null,"strokeWidth":4,"ticker":null,"title":null,"titleHeight":18,"valueFormatter":null,"valueRange":null,"visibility":null,"wilsonInterval":true,"xAxisHeight":null,"xAxisLabelFormatter":null,"xAxisLabelWidth":55,"xLabelHeight":18,"xValueFormatter":null,"xValueParser":null,"xlabel":null,"y2label":null,"yAxisLabelFormatter":null,"yAxisLabelWidth":50,"yLabelWidth":18,"yValueFormatter":null,"ylabel":null},"slug":"ohai","name":"ohai~","desc":"A graph for the testing of great justice.","notes":"","width":"auto","height":250,"chartType":"dygraphs","parents":["root"],"id":"ohai","dataset":"/data/datasources/rc/rc_page_requests.csv","data":{"metrics":[{"source_id":"rc_page_requests","source_col":1,"label":"All Wikipedias (+Mobile)","color":"#E62F74"},{"source_id":"rc_page_requests","source_col":2,"label":"English","color":"#244792"}]}} \ No newline at end of file +{ + "options": { + "animatedZooms": true, + "avoidMinZero": false, + "axis": null, + "axisLabelColor": "#666666", + "axisLabelFontSize": 11, + "axisLabelFormatter": null, + "axisLabelWidth": 50, + "axisLineColor": "#AAAAAA", + "axisLineWidth": 0.3, + "axisTickSize": 3, + "colorSaturation": 1, + "colorValue": 0.5, + "colors": ["#FF0097", "#EF8158", "#83BB32", "#182B53", "#4596FF", "#553DC9", "#AD3238", "#00FFBC", "#F1D950"], + "connectSeparatedPoints": false, + "customBars": false, + "dateWindow": null, + "delimiter": ",", + "digitsAfterDecimal": 2, + "displayAnnotations": false, + "drawPoints": true, + "drawXAxis": true, + "drawXGrid": true, + "drawYAxis": true, + "drawYGrid": true, + "errorBars": false, + "file": null, + "fillAlpha": 0.15, + "fillGraph": false, + "fractions": false, + "gridLineColor": "#D8D8D8", + "gridLineWidth": 0.3, + "hideOverlayOnMouseOut": false, + "highlightCircleSize": 4, + "includeZero": false, + "interactionModel": null, + "isZoomedIgnoreProgrammaticZoom": false, + "labels": null, + "labelsDiv": null, + "labelsDivStyles": null, + "labelsDivWidth": 250, + "labelsKMB": true, + "labelsKMG2": false, + "labelsSeparateLines": true, + "labelsShowZeroValues": true, + "legend": "always", + "logscale": true, + "maxNumberWidth": 30, + "panEdgeFraction": null, + "pixelsPerLabel": null, + "pixelsPerXLabel": null, + "pixelsPerYLabel": null, + "pointSize": 1, + "rangeSelectorHeight": 40, + "rangeSelectorPlotFillColor": "#A7B1C4", + "rangeSelectorPlotStrokeColor": "#808FAB", + "rightGap": 20, + "rollPeriod": 1, + "showLabelsOnHighlight": true, + "showRangeSelector": false, + "showRoller": false, + "sigFigs": null, + "sigma": 2, + "stackedGraph": false, + "stepPlot": false, + "strokePattern": null, + "strokeWidth": 4, + "ticker": null, + "title": null, + "titleHeight": 18, + "valueFormatter": null, + "valueRange": null, + "visibility": null, + "wilsonInterval": true, + "xAxisHeight": null, + "xAxisLabelFormatter": null, + "xAxisLabelWidth": 55, + "xLabelHeight": 18, + "xValueFormatter": null, + "xValueParser": null, + "xlabel": null, + "y2label": null, + "yAxisLabelFormatter": null, + "yAxisLabelWidth": 50, + "yLabelWidth": 18, + "yValueFormatter": null, + "ylabel": null + }, + "slug": "ohai", + "name": "ohai~", + "desc": "A graph for the testing of great justice.", + "notes": "", + "width": "auto", + "height": 250, + "chartType": "dygraphs", + "parents": ["root"], + "id": "ohai", + "dataset": "/data/datasources/rc/rc_page_requests.csv", + "data": { + "metrics": [{ + "source_id": "rc_page_requests", + "source_col": 1, + "label": "All Wikipedias (+Mobile)", + "color": "#E62F74" + }, { + "source_id": "rc_page_requests", + "source_col": 2, + "label": "English", + "color": "#244792" + }] + } +} 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