Checkpoint: Graphs now render from their Dataset model
authordsc <dsc@wikimedia.org>
Wed, 18 Apr 2012 18:47:15 +0000 (11:47 -0700)
committerdsc <dsc@wikimedia.org>
Wed, 18 Apr 2012 18:47:15 +0000 (11:47 -0700)
data/graphs/ohai.json
lib/dataset/dataset-model.co
lib/dataset/datasource-model.co
lib/dataset/metric-model.co
lib/graph/graph-edit-view.co

index e765428..224d8d1 100644 (file)
@@ -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"
+        }]
+    }
+}
index 47ae0e8..c6767a3 100644 (file)
@@ -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
index 57fed50..4b13667 100644 (file)
@@ -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
index 72e95de..d339283 100644 (file)
@@ -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()
index 6f50b41..30edab8 100644 (file)
@@ -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: