Merge branch 'master' of git://github.com/danvk/dygraphs into highlight3
authorKlaus Weidner <klausw@google.com>
Sun, 26 Feb 2012 00:04:41 +0000 (16:04 -0800)
committerKlaus Weidner <klausw@google.com>
Sun, 26 Feb 2012 00:04:41 +0000 (16:04 -0800)
common/textarea.js
dygraph-options-reference.js
gallery/gallery.css
gallery/gallery.js
gallery/index.html
generate-documentation.py

index d0e1c31..6580d3a 100644 (file)
@@ -101,12 +101,27 @@ TextArea.prototype.show = function(title, content) {
   this.textarea.style.height = (-18 + sums([this.elem], [this.title, this.buttons], "offsetHeight")) + "px";
   this.textarea.style.width = (-16 + sums([this.elem], [ ], "offsetWidth")) + "px";
 
+  var textarea = this;
+
+  this.keyDownListener_ = function(event) {
+    console.log(event);
+    if(event.keyCode == 13) { // enter / return
+      textarea.hide();
+    }
+    if(event.keyCode == 27) { // esc
+      textarea.hide();
+    }
+  }
+
+  Dygraph.addEvent(document, "keydown", this.keyDownListener_);
   this.reposition();
   window.addEventListener('resize', this.reposition, false);
   document.documentElement.addEventListener('onscroll', this.reposition);
 }
 
 TextArea.prototype.hide = function() {
+  Dygraph.removeEvent(document, "keypress", this.keyDownListener_);
+  this.keyDownListener_ = null;
   this.elem.style.display = "none";
   this.background.style.display = "none";
   window.removeEventListener("resize", this.reposition);
index 9217f3d..19becfd 100644 (file)
@@ -41,19 +41,36 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "default": "false",
     "labels": ["Data Line display"],
     "type": "boolean",
-    "description": "Draw a small dot at each point, in addition to a line going through the point. This makes the individual data points easier to see, but can increase visual clutter in the chart. The small dot can be replaced with a custom rendering by supplying a drawPointCallback."
+    "description": "Draw a small dot at each point, in addition to a line going through \
+        the point. This makes the individual data points easier to see, but  \
+        can increase visual clutter in the chart. The small dot can be \
+        replaced with a custom rendering by supplying a \
+        <a href='#drawPointCallback'>drawPointCallback</a>."
   },
   "drawPointCallback": {
     "default": "null",
     "labels": ["Data Line display"],
     "type": "function(g, seriesName, canvasContext, cx, cy, color, pointSize)",
-    "description": "Draw a custom item when drawPoints is enabled. Default is a small dot matching the series color."
+    "parameters": [
+      [ "g" , "the reference graph" ],
+      [ "seriesName" , "the name of the series" ],
+      [ "canvasContext" , "the canvas to draw on" ],
+      [ "cx" , "center x coordinate" ],
+      [ "cy" , "center y coordinate" ],
+      [ "color" , "series color" ],
+      [ "pointSize" , "the radius of the image." ]
+    ],
+    "description": "Draw a custom item when drawPoints is enabled. \
+        Default is a small dot matching the series color. This method \
+        should constrain drawing to within pointSize pixels from (cx, cy). \
+        Also see <a href='#drawHighlightPointCallback'>drawHighlightPointCallback</a>"
   },
   "height": {
     "default": "320",
     "labels": ["Overall display"],
     "type": "integer",
-    "description": "Height, in pixels, of the chart. If the container div has been explicitly sized, this will be ignored."
+    "description": "Height, in pixels, of the chart. If the container div has \
+      been explicitly sized, this will be ignored."
   },
   "zoomCallback": {
     "default": "null",
@@ -64,7 +81,8 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
       [ "maxDate" , "milliseconds since epoch." ],
       [ "yRanges" , "is an array of [bottom, top] pairs, one for each y-axis." ]
     ],
-    "description": "A function to call when the zoom window is changed (either by zooming in or out)."
+    "description": "A function to call when the zoom window is changed (either \
+      by zooming in or out)."
   },
   "pointClickCallback": {
     "snippet": "function(e, point){<br>&nbsp;&nbsp;alert(point);<br>}",
@@ -107,7 +125,19 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "default": "null",
     "labels": ["Data Line display"],
     "type": "function(g, seriesName, canvasContext, cx, cy, color, pointSize)",
-    "description": "Draw a custom item when a point is highlighted. Default is a small dot matching the series color."
+    "parameters": [
+      [ "g" , "the reference graph" ],
+      [ "seriesName" , "the name of the series" ],
+      [ "canvasContext" , "the canvas to draw on" ],
+      [ "cx" , "center x coordinate" ],
+      [ "cy" , "center y coordinate" ],
+      [ "color" , "series color" ],
+      [ "pointSize" , "the radius of the image." ]
+    ],
+    "description": "Draw a custom item when a point is highlighted. \
+        Default is a small dot matching the series color. This method \
+        should constrain drawing to within pointSize pixels from (cx, cy) \
+        Also see <a href='#drawPointCallback'>drawPointCallback</a>"
   },
   "highlightSeriesOpts": {
     "default": "null",
index e7a343e..7bd3510 100644 (file)
@@ -1,5 +1,3 @@
-@import url("../common/textarea.css");
-
 body {
   font-family: Helvetica Neue, Arial, Helvetica, sans-serif;
   font-size: 90%;
index 0c0034c..b735693 100644 (file)
@@ -24,6 +24,7 @@ Gallery.start = function() {
   Gallery.workareaChild = Gallery.create("div", Gallery.workarea);
   Gallery.demotitle = document.getElementById("demotitle");
   Gallery.textarea = new TextArea();
+  Gallery.textarea.cancel.style.display = "none";
   Gallery.textarea.width = 600;
   Gallery.textarea.height = 400;
 
@@ -48,22 +49,51 @@ Gallery.start = function() {
         }
       }
       Gallery.subtitle.innerHTML = "";
-      var codeLink = Gallery.create("a", Gallery.subtitle);
-      codeLink.textContent = "code";
-      codeLink.href = "#";
+
       Gallery.demotitle.textContent = demo.title ? demo.title : "";
       demo.innerDiv.className = "selected";
+
+      var htmlLink = Gallery.create("a", Gallery.subtitle);
+      htmlLink.textContent = "HTML";
+      htmlLink.href = "#";
+
+      Gallery.subtitle.appendChild(document.createTextNode(" "));
+
+      var javascriptLink = Gallery.create("a", Gallery.subtitle);
+      javascriptLink.textContent = "Javascript";
+      javascriptLink.href = "#";
+
+      Gallery.subtitle.appendChild(document.createTextNode(" "));
+
+      var css = getCss(id);
+      if (css) {
+        var cssLink = Gallery.create("a", Gallery.subtitle);
+        cssLink.textContent = "CSS";
+        cssLink.href = "#";
+      }
+
       Gallery.workareaChild.id = id;
       location.hash = "g/" + id;
+
       Gallery.workareaChild.innerHTML='';
       if (demo.setup) {
         demo.setup(Gallery.workareaChild);
       }
+
       var html = Gallery.workareaChild.innerHTML;
-      codeLink.onclick = function() {
-        var javascript = demo.run.toString();
-        Gallery.textarea.show("Code", "HTML\n\n" + html + "\n\njavascript\n\n" + javascript);
+
+      htmlLink.onclick = function() {
+        Gallery.textarea.show("HTML", html);
       };
+
+      javascriptLink.onclick = function() {
+        Gallery.textarea.show("Javascript", demo.run.toString());
+      };
+
+      cssLink.onclick = function() {
+        Gallery.textarea.show("CSS", css);
+      };
+
       demo.run(Gallery.workareaChild);
       Gallery.runningDemo = demo;
     }; }(demo, id);
@@ -74,6 +104,32 @@ Gallery.start = function() {
   window.onhashchange = Gallery.setHash;("hashchange", Gallery.hashChange, false);
 };
 
+var getCss = function(id) {
+  for (var i = 0; i < document.styleSheets.length; i++) {
+    var ss = document.styleSheets[i];
+    if (ss.title == "gallery") {
+      try {
+        var rules = ss.rules || ss.cssRules;
+        if (rules) {
+          var arry = [];
+          for (var j = 0; j < rules.length; j++) {
+            var rule = rules[j];
+            var cssText = rule.cssText;
+            var key = "#workarea #" + id + " ";
+            if (cssText.indexOf(key) == 0) {
+              arry.push(cssText.substr(key.length));
+            }
+          }
+          return arry.join("\n\n");
+        }
+      } catch(e) { // security error
+        console.log(e);
+      }
+    }
+  }
+  return "not found";
+}
+
 Gallery.register = function(id, demo) {
   if (Gallery.entries[id]) {
     throw id + " already registered";
index 0f573e8..311427e 100644 (file)
@@ -47,7 +47,8 @@
     <script src="annotation-gviz.js"></script>
     <script src="annotation-native.js"></script>
     -->
-    <link rel="stylesheet" type="text/css" href="gallery.css" />
+    <link rel="stylesheet" type="text/css" href="../common/textarea.css"></link>
+    <link title="gallery" rel="stylesheet" type="text/css" href="gallery.css"></link>
   </head>
   <body>
     <table>
index 0614bef..613dec7 100755 (executable)
@@ -21,6 +21,8 @@ for line in file('dygraph-options-reference.js'):
   elif '</JSON>' in line:
     in_json = False
   elif in_json:
+    if line.endswith("\\\n"): # hacked in line continuation support with trailing \.
+      line = line[:-2]
     js += line
 
 # TODO(danvk): better errors here.