Adds project-to-color mapping for metrics with no color defined.
authorDavid Schoonover <dsc@wikimedia.org>
Thu, 7 Jun 2012 09:29:41 +0000 (02:29 -0700)
committerDavid Schoonover <dsc@wikimedia.org>
Thu, 7 Jun 2012 09:29:41 +0000 (02:29 -0700)
lib/data/dataset-model.co
lib/data/metric-model.co
lib/data/project-colors.co [new file with mode: 0644]
lib/graph/graph-edit-view.co
www/modules.yaml

index e24a6aa..5bc6c25 100644 (file)
@@ -151,7 +151,7 @@ DataSet = exports.DataSet = BaseModel.extend do # {{{
     
     getColors: ->
         return [] unless @ready
-        @metrics.onlyOk().pluck 'color'
+        @metrics.onlyOk().invoke 'getColor'
     
     # }}}
     
index a5ecd35..3077fd6 100644 (file)
@@ -2,8 +2,13 @@
 } = require 'kraken/util'
 { BaseModel, BaseList,
 } = require 'kraken/base'
+ProjectColors = require 'kraken/data/project-colors'
 DataSource = DataSourceList = null
 
+
+
+
+
 /**
  * @class
  */
@@ -53,6 +58,12 @@ Metric = exports.Metric = BaseModel.extend do # {{{
         @load()
     
     
+    # toJSON: ->
+    #     json = Metric.__super__.toJSON ...
+    #     json.color or= ProjectColors.lookup(json.label) or 'black'
+    #     json
+    
+    
     getDateColumn: ->
         @source.getDateColumn()
     
@@ -71,6 +82,9 @@ Metric = exports.Metric = BaseModel.extend do # {{{
         col = @get 'source_col'
         @source.getColumnName col if @source and col > 0
     
+    getColor: ->
+        @get('color') or ProjectColors.lookup(@get('label')) or 'black'
+    
     
     load: (opts={}) ->
         source_id  = @get 'source_id'
diff --git a/lib/data/project-colors.co b/lib/data/project-colors.co
new file mode 100644 (file)
index 0000000..958155a
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * @fileOverview Applies consistent coloring to language/project Metrics with a null `color` field.
+ */
+
+
+PROJECT_COLORS = exports.PROJECT_COLORS =
+    'target'        : '#cccccc'
+    'total'         : '#182B53'
+    'all projects'  : '#182B53'
+    'world'         : '#182B53'
+    'commons'       : '#d73027'
+    'north america' : '#4596FF'
+    'english'       : '#4596FF'
+    'asia pacific'  : '#83BB32'
+    'japanese'      : '#83BB32'
+    'china'         : '#AD3238'
+    'chinese'       : '#AD3238'
+    'europe'        : '#FF0097'
+    'german'        : '#FF0097'
+    'dutch'         : '#EF8158'
+    'french'        : '#1A9380'
+    'italian'       : '#FF87FF'
+    'portuguese'    : '#B64926'
+    'swedish'       : '#5DD2A4'
+    'russian'       : '#FA0000'
+    'latin america' : '#FFB719'
+    'spanish'       : '#FFB719'
+    'middle east'   : '#00675B'
+    'india'         : '#553DC9'
+
+PROJECT_TESTS = ( { pat://\b#{project.replace(/ /g, '[ _-]')}\b//i, project, color } for project, color in PROJECT_COLORS )
+
+
+lookupColor = exports.lookup = (label) ->
+    for project, {pat, color} in PROJECT_TESTS
+        return color if pat.test label
+
index 12ef920..a791be1 100644 (file)
@@ -33,6 +33,7 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{
         'click    .load-button'                          : 'load'
         'click    .save-button'                          : 'save'
         'click    .done-button'                          : 'done'
+        'keypress .graph-name'                           : 'onNameKeypress'
         'keypress .graph-details input[type="text"]'     : 'onKeypress'
         'keypress .chart-options .value'                 : 'onKeypress'
         'submit   form.graph-details'                    : 'onDetailsSubmit'
@@ -205,6 +206,9 @@ GraphEditView = exports.GraphEditView = GraphView.extend do # {{{
     onKeypress: (evt) ->
         $(evt.target).submit() if evt.keyCode is 13
     
+    onNameKeypress: (evt) ->
+        @$ 'form.graph-details' .submit() if evt.keyCode is 13
+    
     onDetailsSubmit: ->
         console.log "#this.onDetailsSubmit!"
         details = @$ 'form.graph-details' .formData()
index 8e40043..371a1e2 100644 (file)
@@ -113,6 +113,7 @@ dev:
                 - chart-type
                 - index
             - data:
+                - project-colors
                 - metric-model
                 - metric-edit-view
                 - datasource-model