Updates tag tracking.
authordsc <dsc@less.ly>
Thu, 23 Feb 2012 20:26:59 +0000 (12:26 -0800)
committerdsc <dsc@less.ly>
Thu, 23 Feb 2012 20:26:59 +0000 (12:26 -0800)
docs/notes.md
lib/scaffold/model.co
lib/server/server.co
lib/template/graph-option.jade
msc/dygraph-options/data.yaml
package.co
package.json
www/css/colors.styl
www/css/graph.styl

index e69de29..6a9ea45 100644 (file)
@@ -0,0 +1,2 @@
+# notes
+
index a98bd41..af6a85f 100644 (file)
@@ -1,19 +1,55 @@
-_  = require 'kraken/underscore'
-op = require 'kraken/util/op'
+_    = require 'kraken/underscore'
+op   = require 'kraken/util/op'
+Hash = require 'hashish'
 
 
 
 ### Scaffold Models
 
+class exports.Tags extends Array
+    tags : {}
+    
+    (values=[]) ->
+        @tags = {}
+        @add values if values?.length
+    
+    has: (tag) ->
+        @tags[tag]?
+    
+    get: (tag) ->
+        return -1 unless tag
+        unless @tags[tag]?
+            @tags[tag] = @length
+            @push tag
+        @tags[tag]
+    
+    update: (tags) ->
+        is_single = typeof tags is 'string'
+        tags      = [tags] if is_single
+        indices   = ( for tag of tags then @get tag )
+        if is_single then indices[0] else indices
+    
+    toString: -> "Tags(length=#{@length}, values=[\"#{@join '", "'}\"])"
+
+
+KNOWN_TAGS = exports.KNOWN_TAGS = new Tags()
+
 Field = exports.Field = Backbone.Model.extend do # {{{
-    ctorName : 'Field'
+    ctorName    : 'Field'
     idAttribute : 'name'
     
+    
     initialize: ->
         @set 'value', @get('default'), {+silent} if not @has 'value'
         
         # console.log "#this.initialize!"
+        @on 'all', (evt) ~> console.log "#this.trigger(#evt)"
+        
+        # Notify Tag indexer of category when created, to ensure all category-tags
+        # get indices with colors :P
+        KNOWN_TAGS.update @getCategory()
     
+    # Model defaults
     defaults: ->
         {
             name     : ''
@@ -25,6 +61,41 @@ Field = exports.Field = Backbone.Model.extend do # {{{
             examples : []
         }
     
+    # Wrapper to ensure @set('tags') is called, as tags.push()
+    # will not trigger the 'changed:tags' event.
+    addTag: (tag) ->
+        return this unless tag
+        tags = @get('tags', [])
+        tags.push tag
+        @set 'tags', tags
+        this
+    
+    # Wrapper to ensure @set('tags') is called, as tags.push()
+    # will not trigger the 'changed:tags' event.
+    removeTag: (tag) ->
+        return this unless tag
+        tags = @get('tags', [])
+        _.remove tags, tag
+        @set 'tags', tags
+        this
+    
+    # Keep tag list up to date
+    onTagUpdate: ->
+        KNOWN_TAGS.update @get 'tags'
+        this
+    
+    getTagIndex: (tag) ->
+        KNOWN_TAGS.get tag
+    
+    # A field's category is its first tag.
+    getCategory: ->
+        @get('tags', [])[0]
+    
+    getCategoryIndex: ->
+        @getTagIndex @getCategory()
+    
+    
+    
     getParser: (type) ->
         type or= @get 'type'
         t = _ type.toLowerCase()
@@ -44,7 +115,7 @@ Field = exports.Field = Backbone.Model.extend do # {{{
         # TODO: handle 'or' by returning an array of parsers
         parser
     
-    
+        
     getValue: (def) ->
         @getParser() @get 'value', def
     
@@ -62,6 +133,7 @@ Field = exports.Field = Backbone.Model.extend do # {{{
     isDefault: ->
         @get('value') is @get('default')
     
+    
     toJSON: ->
         {id:@id} import do
             _.clone(@attributes) import { value:@getValue(), def:@get('default') }
index d9a6c44..2f7ff0d 100755 (executable)
@@ -85,7 +85,7 @@ app.configure ->
         log_level : LOG_LEVEL
     app.use require('browserify') do
         mount   : '/vendor/browserify.js'
-        require : <[ events seq ]>
+        require : <[ events seq hashish ]>
     
     # Serve static files
     app.use express.static WWW
index 92fee6e..20494dc 100644 (file)
@@ -1,11 +1,11 @@
 include browser-helpers
 - var option_id    = _.domize('option', id);
 - var value_id     = _.domize('value', id);
-//- - var category_cls = _.domize('category', category);
+- var category_cls = _.domize('category', model.getCategoryIndex()) + ' ' + _.domize('category', model.getCategory());
 - var tags_cls     = tags.map(_.domize('tag')).join(' ');
 - var type_cls     = _.domize('type', type); 
 
-.field.option(id=option_id, class="#{category} #{tags_cls}")
+.field.option(id=option_id, class="#{category_cls} #{tags_cls}")
     a.close &times;
     
     h3.shortname #{_.shortname(name)}
@@ -21,7 +21,7 @@ include browser-helpers
     //- .tags(data-toggle="collapse", data-target="##{option_id} .tags ul"): ul.collapse
     .tags
         for tag in tags
-            span.tag(class=_.domize('tag', tag)) #{tag}
+            span.tag(class=_.domize('tag', tag)+' '+_.domize('category', model.getTagIndex(tag))) #{tag}
             |  
     .examples(data-toggle="collapse", data-target="##{option_id} .examples ul"): ul.collapse
         for example in examples
index 7f7931d..4e3d575 100644 (file)
@@ -4,7 +4,6 @@
     default: 480
     desc: Width, in pixels, of the chart. If the container div has been explicitly sized, this will be
         ignored.
-    category: Overall display
     tags:
     - overall display
 
     default: 320
     desc: Height, in pixels, of the chart. If the container div has been explicitly sized, this will be
         ignored.
-    category: Overall display
     tags:
     - overall display
 
+-   name: file
+    type: String (URL of CSV or CSV), GViz DataTable or 2D Array
+    default: null
+    desc: Sets the data being displayed in the chart. This can only be set when calling updateOptions;
+        it cannot be set from the constructor. For a full description of valid data formats, see the Data
+        Formats page.
+    tags:
+    - data
+    examples:
+    - drawing
+    - dygraph-many-points-benchmark
+
 -   name: annotationClickHandler
     type: function(annotation, point, dygraph, event)
     default: null
     desc: If provided, this function is called whenever the user clicks on an annotation.
-    category: Annotations
     tags:
     - annotations
     - handler
@@ -32,7 +41,6 @@
     type: function(annotation, point, dygraph, event)
     default: null
     desc: If provided, this function is called whenever the user double-clicks on an annotation.
-    category: Annotations
     tags:
     - annotations
     - handler
@@ -43,7 +51,6 @@
     type: function(annotation, point, dygraph, event)
     default: null
     desc: If provided, this function is called whenever the user mouses out of an annotation.
-    category: Annotations
     tags:
     - annotations
     - handler
@@ -54,7 +61,6 @@
     type: function(annotation, point, dygraph, event)
     default: null
     desc: If provided, this function is called whenever the user mouses over an annotation.
-    category: Annotations
     tags:
     - annotations
     - handler
@@ -67,7 +73,6 @@
     desc: Only applies when Dygraphs is used as a GViz chart. Causes string columns following a data series
         to be interpreted as annotations on points in that series. This is the same format used by Google's
         AnnotatedTimeLine chart.
-    category: Annotations
     tags:
     - annotations
     examples:
@@ -80,7 +85,6 @@
         \ of zero is disabled. \nThis is particularly useful for data sets that contain many zero values,\
         \ especially for step plots which may otherwise have lines not visible running along the bottom\
         \ axis."
-    category: Axes
     tags:
     - axes
     examples:
@@ -91,7 +95,6 @@
     default: null
     desc: Set to either an object ({}) filled with options for this axis or to the name of an existing
         data series with its own axis to re-use that axis. See tests for usage.
-    category: Axes
     tags:
     - axes
     examples:
     type: String
     default: black
     desc: Color for x- and y-axis labels. This is a CSS color string.
-    category: Axes
     tags:
     - axes
 
     type: Integer
     default: 14
     desc: Size of the font (in pixels) to use in the axis labels, both x- and y-axis.
-    category: Axes
     tags:
     - axes
 
         (for a date axis). The second argument specifies how fine-grained the axis is. For date axes,
         this is a reference to the time granularity enumeration, defined in dygraph-tickers.js, e.g. Dygraph.WEEKLY.
         opts is a function which provides access to various options on the dygraph, e.g. opts('labelsKMB').
-    category: Axes
     tags:
     - axes
     examples:
     default: 50
     desc: Width (in pixels) of the containing divs for x- and y-axis labels. For the y-axis, this also
         controls
-    category: Axes
     tags:
     - axes
     - labels
     default: black
     desc: Color of the x- and y-axis lines. Accepts any value which the HTML canvas strokeStyle attribute
         understands, e.g. 'black' or 'rgb(0, 100, 255)'.
-    category: Axes
     tags:
     - axes
     examples:
     type: Float
     default: 0.3
     desc: Thickness (in pixels) of the x- and y-axis lines.
-    category: Axes
     tags:
     - axes
 
     type: Number
     default: '3.0'
     desc: The size of the line to display next to each tick mark on x- or y-axes.
-    category: Axes
     tags:
     - axes
 
     desc: Initially zoom in on a section of the graph. Is of the form [earliest, latest], where earliest/latest
         are milliseconds since epoch. If the data for the x-axis is numeric, the values in dateWindow
         must also be numbers. By default, the full range of the input is shown.
-    category: Axes
     tags:
     - axes
     examples:
     default: true
     desc: Whether to draw the x-axis. Setting this to false also prevents x-axis ticks from being drawn
         and reclaims the space for the chart grid/lines.
-    category: Axes
     tags:
     - axes
     examples:
     default: true
     desc: Whether to draw the y-axis. Setting this to false also prevents y-axis ticks from being drawn
         and reclaims the space for the chart grid/lines.
-    category: Axes
     tags:
     - axes
     examples:
     desc: Usually, dygraphs will use the range of the data plus some padding to set the range of the y-axis.
         If this option is set, the y-axis will always include zero, typically as the lowest value. This
         can be used to avoid exaggerating the variance in the data
-    category: Axes
     tags:
     - axes
     examples:
     desc: When set for a y-axis, the graph shows that axis in log scale. Any values less than or equal
         to zero are not displayed. Not compatible with showZero, and ignores connectSeparatedPoints. 
         Also, showing log scale with valueRanges that are less than zero will result in an unviewable graph.
-    category: Axes
     tags:
     - axes
     examples:
     desc: A value representing the farthest a graph may be panned, in percent of the display. For example,
         a value of 0.1 means that the graph can only be panned 10% pased the edges of the displayed values.
         null means no bounds.
-    category: Axes
     tags:
     - axes
     - interactive elements
     default: null
     desc: Number of pixels to require between each x- and y-label. Larger values will yield a sparser
         axis with fewer ticks. This is set on a per-axis basis. By default, values are 60 (x-axis) or 30 (y-axes).
-    category: Axes
     tags:
     - axes
     - grid
         tick marks so, if you set this option, you'll most likely want to call one of them and modify
         the result. By default, uses Dygraph.dateTicker or Dygraph.numericTicks, but see
         dygraph-tickers.js for an extensive discussion. This is set on a per-axis basis.
-    category: Axes
     tags:
     - axes
 
     default: null
     desc: Explicitly set the vertical range of the graph to [low, high]. This may be set on a per-axis
         basis to define each y-axis separately. By default, the full range of the input is shown.
-    category: Axes
     tags:
     - axes
     examples:
     default: null
     desc: Height, in pixels, of the x-axis. If not set explicitly, this is computed based on axisLabelFontSize
         and axisTickSize.
-    category: Axes
     tags:
     - axes
 
     type: Integer
     default: 50
     desc: Width, in pixels, of the x-axis labels.
-    category: Axes
     tags:
     - axes
     examples:
     default: 50
     desc: Width, in pixels, of the y-axis labels. This also affects the amount of space available for
         a y-axis chart label.
-    category: Axes
     tags:
     - axes
     examples:
     default: ','
     desc: The delimiter to look for when separating fields of a CSV file. Setting this to a tab is not
         usually necessary, since tab-delimited data is auto-detected.
-    category: CSV parsing
     tags:
     - csv parsing
 
         
         * Dygraphs is slightly more accepting in the dates which it will parse. See code for
         details.
-    category: CSV parsing
     tags:
     - csv parsing
 
         \ data coordinates of the point (with dates/times as millis since epoch) \n * canvasx/canvasy:\
         \ The canvas coordinates at which the point is drawn. \n name: The name of the data series to\
         \ which the point belongs"
-    category: Callbacks
     tags:
     - callbacks
     examples:
     desc: When set, this callback gets called every time the dygraph is drawn. This includes the initial
         draw, after zooming and repeatedly while panning. The first parameter is the dygraph being drawn.
         The second is a boolean value indicating whether this is the initial draw.
-    category: Callbacks
     tags:
     - callbacks
     examples:
     desc: 'When set, this callback gets called every time a new point is highlighted. The parameters are
         the JavaScript mousemove event, the x-coordinate of the highlighted points and an array of highlighted
         points: [ {name: ''series'', yval: y-value}, ... ]'
-    category: Callbacks
     tags:
     - callbacks
     examples:
     type: function(canvas, area, dygraph)
     default: null
     desc: When set, this callback gets called before the chart is drawn. It details on how to use this.
-    category: Callbacks
     tags:
     - callbacks
     examples:
     default: null
     desc: When set, this callback gets called every time the user stops highlighting any point by mousing
         out of the graph.  The parameter is the mouseout event.
-    category: Callbacks
     tags:
     - callbacks
     examples:
     desc: A function to call when the zoom window is changed (either by zooming in or out). minDate and
         maxDate are milliseconds since epoch. yRanges is an array of [bottom, top] pairs, one for each
         y-axis.
-    category: Callbacks
     tags:
     - callbacks
     examples:
     default: null
     desc: Text to display above the chart. You can supply any HTML for this value, not just text. If you
         wish to style it using CSS, use the 'dygraph-label' or 'dygraph-title' classes.
-    category: Chart labels
     tags:
     - chart labels
     examples:
     desc: Height of the chart title, in pixels. This also controls the default font size of the title.
         If you style the title on your own, this controls how much space is set aside above the chart
         for the title's div.
-    category: Chart labels
     tags:
     - chart labels
     examples:
     desc: Height of the x-axis label, in pixels. This also controls the default font size of the x-axis
         label. If you style the label on your own, this controls how much space is set aside below the
         chart for the x-axis label's div.
-    category: Chart labels
     tags:
     - chart labels
 
     default: null
     desc: Text to display below the chart's x-axis. You can supply any HTML for this value, not just text.
         If you wish to style it using CSS, use the 'dygraph-label' or 'dygraph-xlabel' classes.
-    category: Chart labels
     tags:
     - chart labels
     examples:
         a secondary y-axis is present. See this test for an example of how to do this. The comments for
         the 'ylabel' option generally apply here as well. This label gets a 'dygraph-y2label' instead
         of a 'dygraph-ylabel' class.
-    category: Chart labels
     tags:
     - chart labels
     examples:
     default: 18
     desc: Width of the div which contains the y-axis label. Since the y-axis label appears rotated 90
         degrees, this actually affects the height of its div.
-    category: Chart labels
     tags:
     - chart labels
 
         the y-axis tick labels using the yAxisLabelWidth option. If you need a wider div for the y-axis
         label, either style it that way with CSS (but remember that it's rotated, so width is controlled
         by the 'height' property) or set the yLabelWidth option.
-    category: Chart labels
     tags:
     - chart labels
     examples:
     - temperature-sf-ny
     - two-axes-vr
 
--   name: file
-    type: String (URL of CSV or CSV), GViz DataTable or 2D Array
-    default: null
-    desc: Sets the data being displayed in the chart. This can only be set when calling updateOptions;
-        it cannot be set from the constructor. For a full description of valid data formats, see the Data
-        Formats page.
-    category: Data
-    tags:
-    - data
-    examples:
-    - drawing
-    - dygraph-many-points-benchmark
-
 -   name: connectSeparatedPoints
     type: Boolean
     default: false
         gap and draws it as such. If, instead, the missing values represents an x-value for which only
         a different series has data, then you'll want to connect the dots by setting this to true. To
         explicitly include a gap with this option set, use a value of NaN.
-    category: Data Line display
     tags:
     - data line display
     examples:
     default: false
     desc:&n