From d1194503f96bf038a644014230289a9ccfb7ba07 Mon Sep 17 00:00:00 2001 From: David Schoonover Date: Thu, 7 Jun 2012 02:29:41 -0700 Subject: [PATCH] Adds project-to-color mapping for metrics with no color defined. --- lib/data/dataset-model.co | 2 +- lib/data/metric-model.co | 14 ++++++++++++++ lib/data/project-colors.co | 37 +++++++++++++++++++++++++++++++++++++ lib/graph/graph-edit-view.co | 4 ++++ www/modules.yaml | 1 + 5 files changed, 57 insertions(+), 1 deletions(-) create mode 100644 lib/data/project-colors.co diff --git a/lib/data/dataset-model.co b/lib/data/dataset-model.co index e24a6aa..5bc6c25 100644 --- a/lib/data/dataset-model.co +++ b/lib/data/dataset-model.co @@ -151,7 +151,7 @@ DataSet = exports.DataSet = BaseModel.extend do # {{{ getColors: -> return [] unless @ready - @metrics.onlyOk().pluck 'color' + @metrics.onlyOk().invoke 'getColor' # }}} diff --git a/lib/data/metric-model.co b/lib/data/metric-model.co index a5ecd35..3077fd6 100644 --- a/lib/data/metric-model.co +++ b/lib/data/metric-model.co @@ -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 index 0000000..958155a --- /dev/null +++ b/lib/data/project-colors.co @@ -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 + diff --git a/lib/graph/graph-edit-view.co b/lib/graph/graph-edit-view.co index 12ef920..a791be1 100644 --- a/lib/graph/graph-edit-view.co +++ b/lib/graph/graph-edit-view.co @@ -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() diff --git a/www/modules.yaml b/www/modules.yaml index 8e40043..371a1e2 100644 --- a/www/modules.yaml +++ b/www/modules.yaml @@ -113,6 +113,7 @@ dev: - chart-type - index - data: + - project-colors - metric-model - metric-edit-view - datasource-model -- 1.7.0.4