diff --git a/docs/backend/localcsv.html b/docs/backend/localcsv.html index 71f105bf..3c708f28 100644 --- a/docs/backend/localcsv.html +++ b/docs/backend/localcsv.html @@ -51,7 +51,9 @@ thttp://www.uselesscode.org/javascript/csv/

var options = options || {}; var trm = options.trim; var separator = options.separator || ','; - + var delimiter = options.delimiter || '"'; + + var cur = '', // The character we are currently processing. inQuote = false, fieldQuoted = false, @@ -81,13 +83,13 @@ thttp://www.uselesscode.org/javascript/csv/

row = []; }

Flush the field buffer

        field = '';
         fieldQuoted = false;
-      } else {

If it's not a ", add it to the field buffer

        if (cur !== '"') {
+      } else {

If it's not a delimiter, add it to the field buffer

        if (cur !== delimiter) {
           field += cur;
         } else {
           if (!inQuote) {

We are not in a quote, start a quote

            inQuote = true;
             fieldQuoted = true;
-          } else {

Next char is ", this is an escaped "

            if (s.charAt(i + 1) === '"') {
-              field += '"';

Skip the next char

              i += 1;
+          } else {

Next char is delimiter, this is an escaped delimiter

            if (s.charAt(i + 1) === delimiter) {
+              field += delimiter;

Skip the next char

              i += 1;
             } else {

It's not escaping, so end quote

              inQuote = false;
             }
           }
diff --git a/docs/backend/memory.html b/docs/backend/memory.html
index 6304cee6..e1c865a7 100644
--- a/docs/backend/memory.html
+++ b/docs/backend/memory.html
@@ -35,6 +35,7 @@ If not defined (or id not provided) id will be autogenerated.

backend.addDataset(datasetInfo); var dataset = new recline.Model.Dataset({id: metadata.id}, backend); dataset.fetch(); + dataset.query(); return dataset; };

Memory Backend - uses in-memory data

diff --git a/docs/view-graph.html b/docs/view-graph.html index 7e13d54b..e71795ba 100644 --- a/docs/view-graph.html +++ b/docs/view-graph.html @@ -47,22 +47,13 @@ generate the element itself (you can then append view.el to the DOM.

<label>Group Column (x-axis)</label> \ <div class="input editor-group"> \ <select> \ + <option value="">Please choose ...</option> \ {{#fields}} \ <option value="{{id}}">{{label}}</option> \ {{/fields}} \ </select> \ </div> \ <div class="editor-series-group"> \ - <div class="editor-series"> \ - <label>Series <span>A (y-axis)</span></label> \ - <div class="input"> \ - <select> \ - {{#fields}} \ - <option value="{{id}}">{{label}}</option> \ - {{/fields}} \ - </select> \ - </div> \ - </div> \ </div> \ </div> \ <div class="editor-buttons"> \ @@ -74,13 +65,33 @@ generate the element itself (you can then append view.el to the DOM.

</div> \ </form> \ </div> \ - <div class="panel graph"></div> \ + <div class="panel graph"> \ + <div class="js-temp-notice alert alert-block"> \ + <h3 class="alert-heading">Hey there!</h3> \ + <p>There\'s no graph here yet because we don\'t know what fields you\'d like to see plotted.</p> \ + <p>Please tell us by <strong>using the menu on the right</strong> and a graph will automatically appear.</p> \ + </div> \ + </div> \ </div> \ ', + templateSeriesEditor: ' \ + <div class="editor-series js-series-{{seriesIndex}}"> \ + <label>Series <span>{{seriesName}} (y-axis)</span> \ + [<a href="#remove" class="action-remove-series">Remove</a>] \ + </label> \ + <div class="input"> \ + <select> \ + {{#fields}} \ + <option value="{{id}}">{{label}}</option> \ + {{/fields}} \ + </select> \ + </div> \ + </div> \ + ', events: { 'change form select': 'onEditorSubmit', - 'click .editor-add': 'addSeries', + 'click .editor-add': '_onAddSeries', 'click .action-remove-series': 'removeSeries', 'click .action-toggle-help': 'toggleHelp' }, @@ -88,14 +99,19 @@ generate the element itself (you can then append view.el to the DOM.

initialize: function(options) { var self = this; this.el = $(this.el); - _.bindAll(this, 'render', 'redraw');

we need the model.fields to render properly

    this.model.bind('change', this.render);
+    _.bindAll(this, 'render', 'redraw');
+    this.needToRedraw = false;
+    this.model.bind('change', this.render);
     this.model.fields.bind('reset', this.render);
     this.model.fields.bind('add', this.render);
     this.model.currentDocuments.bind('add', this.redraw);
-    this.model.currentDocuments.bind('reset', this.redraw);
+    this.model.currentDocuments.bind('reset', this.redraw);

because we cannot redraw when hidden we may need when becoming visible

    this.bind('view:show', function() {
+      if (this.needToRedraw) {
+        self.redraw();
+      }
+    });
     var stateData = _.extend({
-        group: null,
-        series: [],
+        group: null,

so that at least one series chooser box shows up

        series: [],
         graphType: 'lines-and-points'
       },
       options.state
@@ -105,17 +121,41 @@ generate the element itself (you can then append view.el to the DOM.

}, render: function() { - htmls = $.mustache(this.template, this.model.toTemplateJSON()); - $(this.el).html(htmls);

now set a load of stuff up

    this.$graph = this.el.find('.panel.graph');

for use later when adding additional series -could be simpler just to have a common template!

    this.$seriesClone = this.el.find('.editor-series').clone();
-    this._updateSeries();
+    var self = this;
+    var tmplData = this.model.toTemplateJSON();
+    var htmls = $.mustache(this.template, tmplData);
+    $(this.el).html(htmls);
+    this.$graph = this.el.find('.panel.graph');

set up editor from state

    if (this.state.get('graphType')) {
+      this._selectOption('.editor-type', this.state.get('graphType'));
+    }
+    if (this.state.get('group')) {
+      this._selectOption('.editor-group', this.state.get('group'));
+    }

ensure at least one series box shows up

    var tmpSeries = [""];
+    if (this.state.get('series').length > 0) {
+      tmpSeries = this.state.get('series');
+    }
+    _.each(tmpSeries, function(series, idx) {
+      self.addSeries(idx);
+      self._selectOption('.editor-series.js-series-' + idx, series);
+    });
     return this;
+  },

Private: Helper function to select an option from a select list

  _selectOption: function(id,value){
+    var options = this.el.find(id + ' select > option');
+    if (options) {
+      options.each(function(opt){
+        if (this.value == value) {
+          $(this).attr('selected','selected');
+          return false;
+        }
+      });
+    }
   },
 
   onEditorSubmit: function(e) {
     var select = this.el.find('.editor-group select');
-    $editor = this;
-    var series = this.$series.map(function () {
+    var $editor = this;
+    var $series  = this.el.find('.editor-series select');
+    var series = $series.map(function () {
       return $(this).val();
     });
     var updatedState = {
@@ -127,50 +167,59 @@ could be simpler just to have a common template!

this.redraw(); }, - redraw: function() {

There appear to be issues generating a Flot graph if either: