Merge branch 'master' of git://github.com/danvk/dygraphs into axis-label-font-size
authorRobert Konigsberg <konigsberg@google.com>
Thu, 3 Jan 2013 20:29:20 +0000 (15:29 -0500)
committerRobert Konigsberg <konigsberg@google.com>
Thu, 3 Jan 2013 20:29:20 +0000 (15:29 -0500)
Conflicts:
dygraph-options.js

Makefile
dygraph-options.js
experimental/palette/multi-palette.js
experimental/palette/palette.js

index 1182b5a..e07bc1d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ all: test generate-combined generate-documentation
 clean:
        @echo cleaning...
        @cp .dygraph-combined-clean.js dygraph-combined.js
-       rm docs/options.html
+       rm -f docs/options.html
 
 generate-combined:
        @echo Generating dygraph-combined.js
index dc779b1..87632ff 100644 (file)
@@ -193,7 +193,7 @@ DygraphOptions.prototype.reparseSeries = function() {
 /**
  * Get a global value.
  *
- * @param {String} name the name of the option.
+ * @param {string} name the name of the option.
  */
 DygraphOptions.prototype.get = function(name) {
   var result = this.getGlobalUser_(name);
@@ -224,9 +224,9 @@ DygraphOptions.prototype.getGlobalDefault_ = function(name) {
  * Get a value for a specific axis. If there is no specific value for the axis,
  * the global value is returned.
  *
- * @param {String} name the name of the option.
- * @param {String|number} axis the axis to search. Can be the string representation
- * ("x", "y", "y2") or the y-axis number (0, 1). (x-axis can't be specified by number.)
+ * @param {string} name the name of the option.
+ * @param {string|number} axis the axis to search. Can be the string representation
+ * ("y", "y2") or the axis number (0, 1).
  */
 DygraphOptions.prototype.getForAxis = function(name, axis) {
   var axisIdx;
@@ -280,8 +280,8 @@ DygraphOptions.prototype.getForAxis = function(name, axis) {
  * Get a value for a specific series. If there is no specific value for the series,
  * the value for the axis is returned (and afterwards, the global value.)
  *
- * @param {String} name the name of the option.
- * @param {String|number} series the series to search. Can be the string representation
+ * @param {string} name the name of the option.
+ * @param {string|number} series the series to search. Can be the string representation
  * or 0-offset series number.
  */
 DygraphOptions.prototype.getForSeries = function(name, series) {
index 2307030..ee01a4c 100644 (file)
@@ -130,49 +130,62 @@ MultiPalette.prototype.activate = function(key) {
 MultiPalette.prototype.showHash = function() {
   var hash = this.read();
   var textarea = new TextArea();
-  textarea.cancel.style.display = "none";
-
-  /*
-   * JSON.stringify isn't built to be nice to functions. The following fixes
-   * this.
-   *
-   * First, val.toString only does part of the work, turning it into
-   * "function () {\n  alert(\"p-click!\");\n}",
-   *
-   * {start,end}Marker make the surrounding quotes easy to find, and then
-   * remove them. It also converts the instances of \n and \" so the
-   * result looks like:
-   * function () {
-   *   alert("p-click!");
-   * }",
-   */
-  var startMarker = "<~%!<";
-  var endMarker = ">!%~>";
-  var replacer = function(key, val) {
-    if (typeof val === 'function') {
-      return startMarker + val.toString() + endMarker;
-    }
-    return val;
-  }
-  var text = JSON.stringify(hash, replacer, 2);
-  while(true) {
-    var start = text.indexOf(startMarker);
-    var end = text.indexOf(endMarker); 
-    if (start == -1) {
-      break;
-    }
-    var substring = text.substring(start + startMarker.length, end);
-    while(substring.indexOf("\\n") >= 0) {
-      substring = substring.replace("\\n", "\n");
+
+  var hashToString = function(hash) {
+    /*
+     * JSON.stringify isn't built to be nice to functions. The following fixes
+     * this.
+     *
+     * First, val.toString only does part of the work, turning it into
+     * "function () {\n  alert(\"p-click!\");\n}",
+     *
+     * {start,end}Marker make the surrounding quotes easy to find, and then
+     * remove them. It also converts the instances of \n and \" so the
+     * result looks like:
+     * function () {
+     *   alert("p-click!");
+     * }",
+     */
+    var startMarker = "<~%!<";
+    var endMarker = ">!%~>";
+    var replacer = function(key, val) {
+      if (typeof val === 'function') {
+        return startMarker + val.toString() + endMarker;
+      }
+      return val;
     }
-    while(substring.indexOf("\\\"") >= 0) {
-      substring = substring.replace("\\\"", "\"");
+    var text = JSON.stringify(hash, replacer, 2);
+    while(true) {
+      var start = text.indexOf(startMarker);
+      var end = text.indexOf(endMarker); 
+      if (start == -1) {
+        break;
+      }
+      var substring = text.substring(start + startMarker.length, end);
+      while(substring.indexOf("\\n") >= 0) {
+        substring = substring.replace("\\n", "\n");
+      }
+      while(substring.indexOf("\\\"") >= 0) {
+        substring = substring.replace("\\\"", "\"");
+      }
+      text = text.substring(0, start - 1)
+          + substring
+          + text.substring(end + endMarker.length + 1);
     }
-    text = text.substring(0, start - 1)
-        + substring
-        + text.substring(end + endMarker.length + 1);
+    return text;
   }
+
+  var text = hashToString(hash);
+  var self = this;
   textarea.show("options", text);
+  textarea.okCallback = function(value) {
+    if (value != text) {
+      var newHash;
+      eval("newHash = " + value + ";");
+      self.write(newHash);
+      self.onchange();
+    }
+  };
 }
 
 /**
index d98ab15..514463f 100644 (file)
@@ -215,6 +215,9 @@ Palette.prototype.read = function() {
  * Write to input elements.
  */
 Palette.prototype.write = function(hash) {
+  if (!hash) {
+    return;
+  }
   var results = {};
   for (var opt in this.model) {
     if (this.model.hasOwnProperty(opt)) {