From b7a1dc2288585edbeff4591e81e6a0efd2893932 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 17 Oct 2013 22:26:07 -0400 Subject: [PATCH] kberg review --- README | 4 -- auto_tests/tests/Util.js | 16 ++----- docs/legal.html | 6 +-- dygraph-utils.js | 12 ++--- extras/circles.js | 118 ---------------------------------------------- extras/shapes.js | 118 ++++++++++++++++++++++++++++++++++++++++++++++ file-size-stats.sh | 2 - jsTestDriver.conf | 2 - push-to-web.sh | 2 +- tests/custom-circles.html | 2 +- tests/plotters.html | 23 +++++---- 11 files changed, 141 insertions(+), 164 deletions(-) delete mode 100644 extras/circles.js create mode 100644 extras/shapes.js diff --git a/README b/README index ec2e78c..53e19c5 100644 --- a/README +++ b/README @@ -49,8 +49,6 @@ community, please follow the guide at http://dygraphs.com/changes.html. License(s) dygraphs uses: - - rgbcolor.js (Public Domain) - - strftime.js (BSD License) - excanvas.js (Apache License) - YUI compressor (BSD License) - JsDoc Toolkit (MIT license) @@ -64,8 +62,6 @@ automated tests use: Linter uses: - JSHint (modified MIT license; prevents evil) -rgbcolor: http://www.phpied.com/rgb-color-parser-in-javascript/ -strftime: http://tech.bluesmoon.info/2008/04/strftime-in-javascript.html excanvas: http://code.google.com/p/explorercanvas/ yui compressor: http://developer.yahoo.com/yui/compressor/ jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/ diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 207f237..2793cb7 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -133,19 +133,9 @@ Util.overrideXMLHttpRequest = function(data) { /** * Format a date as 2000/01/23 - * @param {number} date_ms Millis since epoch. + * @param {number} dateMillis Millis since epoch. * @return {string} The date formatted as YYYY-MM-DD. */ -Util.formatDate = function(date_ms) { - var zeropad = function(x) { if (x < 10) return "0" + x; else return "" + x; }; - var d = new Date(date_ms); - - // Get the year: - var year = "" + d.getFullYear(); - // Get a 0 padded month string - var month = zeropad(d.getMonth() + 1); //months are 0-offset, sigh - // Get a 0 padded day string - var day = zeropad(d.getDate()); - - return year + "/" + month + "/" + day; +Util.formatDate = function(dateMillis) { + return Dygraph.dateString_(dateMillis).slice(0, 10); // 10 == "YYYY/MM/DD".length }; diff --git a/docs/legal.html b/docs/legal.html index ad0f4b7..3e3d176 100644 --- a/docs/legal.html +++ b/docs/legal.html @@ -7,23 +7,19 @@

dygraphs is available under the MIT license, included in LICENSE.txt.

dygraphs uses:
- - rgbcolor.js (Public Domain)
- - strftime.js (BSD License)
  - excanvas.js (Apache License)
  - YUI compressor (BSD License)
  - JsDoc Toolkit (MIT license)
  - stacktrace.js is public domain
 
 automated tests use:
- - auto_tests/lib/jquery-1.4.2.js (MIT & GPL2)
+ - auto_tests/lib/jquery-1.4.2.js (MIT & GPL2)
  - auto_tests/lib/Asserts.js (Apache 2.0 License)
  - auto-tests/lib/JsTestDriver-1.3.3cjar (Apache 2.0 License
 
 Linter uses:
  - JSHint (modified MIT license; prevents evil)
 
-rgbcolor: http://www.phpied.com/rgb-color-parser-in-javascript/
-strftime: http://tech.bluesmoon.info/2008/04/strftime-in-javascript.html
 excanvas: http://code.google.com/p/explorercanvas/
 yui compressor: http://developer.yahoo.com/yui/compressor/
 jsdoc toolkit: http://code.google.com/p/jsdoc-toolkit/
diff --git a/dygraph-utils.js b/dygraph-utils.js
index d6dfae5..04a5d3a 100644
--- a/dygraph-utils.js
+++ b/dygraph-utils.js
@@ -1012,7 +1012,7 @@ Dygraph.Circles = {
     ctx.arc(canvasx, canvasy, radius, 0, 2 * Math.PI, false);
     ctx.fill();
   }
-  // For more shapes, include extras/stars.js
+  // For more shapes, include extras/shapes.js
 };
 
 /**
@@ -1170,19 +1170,19 @@ Dygraph.setDateSameTZ = function(d, parts) {
 /**
  * Converts any valid CSS color (hex, rgb(), named color) to an RGB tuple.
  *
- * @param {!string} color_str Any valid CSS color string.
+ * @param {!string} colorStr Any valid CSS color string.
  * @return {{r:number,g:number,b:number}} Parsed RGB tuple.
  * @private
  */
-Dygraph.toRGB_ = function(color_str) {
+Dygraph.toRGB_ = function(colorStr) {
   // TODO(danvk): cache color parses to avoid repeated DOM manipulation.
   var div = document.createElement('div');
-  div.style.backgroundColor = color_str;
+  div.style.backgroundColor = colorStr;
   div.style.visibility = 'hidden';
   document.body.appendChild(div);
-  var rgb_str = window.getComputedStyle(div).backgroundColor;
+  var rgbStr = window.getComputedStyle(div).backgroundColor;
   document.body.removeChild(div);
-  var bits = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(rgb_str);
+  var bits = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/.exec(rgbStr);
   return {
     r: parseInt(bits[1], 10),
     g: parseInt(bits[2], 10),
diff --git a/extras/circles.js b/extras/circles.js
deleted file mode 100644
index 097bc5c..0000000
--- a/extras/circles.js
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * @license
- * Copyright 2011 Dan Vanderkam (danvdk@gmail.com)
- * MIT-licensed (http://opensource.org/licenses/MIT)
- */
-
-/**
- * @fileoverview
- * Including this file will add several additional shapes to Dygraph.Circles
- * which can be passed to drawPointCallback.
- * See tests/custom-circles.html for usage.
- */
-
-(function() {
-
-/**
- * @param {!CanvasRenderingContext2D} ctx the canvas context
- * @param {number} sides the number of sides in the shape.
- * @param {number} radius the radius of the image.
- * @param {number} cx center x coordate
- * @param {number} cy center y coordinate
- * @param {number=} rotationRadians the shift of the initial angle, in radians.
- * @param {number=} delta the angle shift for each line. If missing, creates a
- *     regular polygon.
- */
-var regularShape = function(
-    ctx, sides, radius, cx, cy, rotationRadians, delta) {
-  rotationRadians = rotationRadians || 0;
-  delta = delta || Math.PI * 2 / sides;
-
-  ctx.beginPath();
-  var initialAngle = rotationRadians;
-  var angle = initialAngle;
-
-  var computeCoordinates = function() {
-    var x = cx + (Math.sin(angle) * radius);
-    var y = cy + (-Math.cos(angle) * radius);
-    return [x, y];
-  };
-
-  var initialCoordinates = computeCoordinates();
-  var x = initialCoordinates[0];
-  var y = initialCoordinates[1];
-  ctx.moveTo(x, y);
-
-  for (var idx = 0; idx < sides; idx++) {
-    angle = (idx == sides - 1) ? initialAngle : (angle + delta);
-    var coords = computeCoordinates();
-    ctx.lineTo(coords[0], coords[1]);
-  }
-  ctx.fill();
-  ctx.stroke();
-};
-
-/**
- * TODO(danvk): be more specific on the return type.
- * @param {number} sides
- * @param {number=} rotationRadians
- * @param {number=} delta
- * @return {Function}
- * @private
- */
-var shapeFunction = function(sides, rotationRadians, delta) {
-  return function(g, name, ctx, cx, cy, color, radius) {
-    ctx.strokeStyle = color;
-    ctx.fillStyle = "white";
-    regularShape(ctx, sides, radius, cx, cy, rotationRadians, delta);
-  };
-};
-
-Dygraph.update(Dygraph.Circles, {
-  TRIANGLE : shapeFunction(3),
-  SQUARE : shapeFunction(4, Math.PI / 4),
-  DIAMOND : shapeFunction(4),
-  PENTAGON : shapeFunction(5),
-  HEXAGON : shapeFunction(6),
-  CIRCLE : function(g, name, ctx, cx, cy, color, radius) {
-    ctx.beginPath();
-    ctx.strokeStyle = color;
-    ctx.fillStyle = "white";
-    ctx.arc(cx, cy, radius, 0, 2 * Math.PI, false);
-    ctx.fill();
-    ctx.stroke();
-  },
-  STAR : shapeFunction(5, 0, 4 * Math.PI / 5),
-  PLUS : function(g, name, ctx, cx, cy, color, radius) {
-    ctx.strokeStyle = color;
-
-    ctx.beginPath();
-    ctx.moveTo(cx + radius, cy);
-    ctx.lineTo(cx - radius, cy);
-    ctx.closePath();
-    ctx.stroke();
-
-    ctx.beginPath();
-    ctx.moveTo(cx, cy + radius);
-    ctx.lineTo(cx, cy - radius);
-    ctx.closePath();
-    ctx.stroke();
-  },
-  EX : function(g, name, ctx, cx, cy, color, radius) {
-    ctx.strokeStyle = color;
-
-    ctx.beginPath();
-    ctx.moveTo(cx + radius, cy + radius);
-    ctx.lineTo(cx - radius, cy - radius);
-    ctx.closePath();
-    ctx.stroke();
-
-    ctx.beginPath();
-    ctx.moveTo(cx + radius, cy - radius);
-    ctx.lineTo(cx - radius, cy + radius);
-    ctx.closePath();
-    ctx.stroke();
-  }
-});
-
-});
diff --git a/extras/shapes.js b/extras/shapes.js
new file mode 100644
index 0000000..097bc5c
--- /dev/null
+++ b/extras/shapes.js
@@ -0,0 +1,118 @@
+/**
+ * @license
+ * Copyright 2011 Dan Vanderkam (danvdk@gmail.com)
+ * MIT-licensed (http://opensource.org/licenses/MIT)
+ */
+
+/**
+ * @fileoverview
+ * Including this file will add several additional shapes to Dygraph.Circles
+ * which can be passed to drawPointCallback.
+ * See tests/custom-circles.html for usage.
+ */
+
+(function() {
+
+/**
+ * @param {!CanvasRenderingContext2D} ctx the canvas context
+ * @param {number} sides the number of sides in the shape.
+ * @param {number} radius the radius of the image.
+ * @param {number} cx center x coordate
+ * @param {number} cy center y coordinate
+ * @param {number=} rotationRadians the shift of the initial angle, in radians.
+ * @param {number=} delta the angle shift for each line. If missing, creates a
+ *     regular polygon.
+ */
+var regularShape = function(
+    ctx, sides, radius, cx, cy, rotationRadians, delta) {
+  rotationRadians = rotationRadians || 0;
+  delta = delta || Math.PI * 2 / sides;
+
+  ctx.beginPath();
+  var initialAngle = rotationRadians;
+  var angle = initialAngle;
+
+  var computeCoordinates = function() {
+    var x = cx + (Math.sin(angle) * radius);
+    var y = cy + (-Math.cos(angle) * radius);
+    return [x, y];
+  };
+
+  var initialCoordinates = computeCoordinates();
+  var x = initialCoordinates[0];
+  var y = initialCoordinates[1];
+  ctx.moveTo(x, y);
+
+  for (var idx = 0; idx < sides; idx++) {
+    angle = (idx == sides - 1) ? initialAngle : (angle + delta);
+    var coords = computeCoordinates();
+    ctx.lineTo(coords[0], coords[1]);
+  }
+  ctx.fill();
+  ctx.stroke();
+};
+
+/**
+ * TODO(danvk): be more specific on the return type.
+ * @param {number} sides
+ * @param {number=} rotationRadians
+ * @param {number=} delta
+ * @return {Function}
+ * @private
+ */
+var shapeFunction = function(sides, rotationRadians, delta) {
+  return function(g, name, ctx, cx, cy, color, radius) {
+    ctx.strokeStyle = color;
+    ctx.fillStyle = "white";
+    regularShape(ctx, sides, radius, cx, cy, rotationRadians, delta);
+  };
+};
+
+Dygraph.update(Dygraph.Circles, {
+  TRIANGLE : shapeFunction(3),
+  SQUARE : shapeFunction(4, Math.PI / 4),
+  DIAMOND : shapeFunction(4),
+  PENTAGON : shapeFunction(5),
+  HEXAGON : shapeFunction(6),
+  CIRCLE : function(g, name, ctx, cx, cy, color, radius) {
+    ctx.beginPath();
+    ctx.strokeStyle = color;
+    ctx.fillStyle = "white";
+    ctx.arc(cx, cy, radius, 0, 2 * Math.PI, false);
+    ctx.fill();
+    ctx.stroke();
+  },
+  STAR : shapeFunction(5, 0, 4 * Math.PI / 5),
+  PLUS : function(g, name, ctx, cx, cy, color, radius) {
+    ctx.strokeStyle = color;
+
+    ctx.beginPath();
+    ctx.moveTo(cx + radius, cy);
+    ctx.lineTo(cx - radius, cy);
+    ctx.closePath();
+    ctx.stroke();
+
+    ctx.beginPath();
+    ctx.moveTo(cx, cy + radius);
+    ctx.lineTo(cx, cy - radius);
+    ctx.closePath();
+    ctx.stroke();
+  },
+  EX : function(g, name, ctx, cx, cy, color, radius) {
+    ctx.strokeStyle = color;
+
+    ctx.beginPath();
+    ctx.moveTo(cx + radius, cy + radius);
+    ctx.lineTo(cx - radius, cy - radius);
+    ctx.closePath();
+    ctx.stroke();
+
+    ctx.beginPath();
+    ctx.moveTo(cx + radius, cy - radius);
+    ctx.lineTo(cx - radius, cy + radius);
+    ctx.closePath();
+    ctx.stroke();
+  }
+});
+
+});
diff --git a/file-size-stats.sh b/file-size-stats.sh
index 24f1bac..fb81519 100755
--- a/file-size-stats.sh
+++ b/file-size-stats.sh
@@ -12,8 +12,6 @@ dygraph-utils.js \
 dygraph-gviz.js \
 dygraph-interaction-model.js \
 dygraph-tickers.js \
-rgbcolor/rgbcolor.js \
-strftime/strftime-min.js \
 dashed-canvas.js \
 dygraph-plugin-base.js \
 plugins/annotations.js \
diff --git a/jsTestDriver.conf b/jsTestDriver.conf
index 9bedea6..e05fc7a 100644
--- a/jsTestDriver.conf
+++ b/jsTestDriver.conf
@@ -3,8 +3,6 @@ server: http://localhost:9876
 # This list needs to be kept in sync w/ the one in dygraph-dev.js
 # and the one in generate-combined.sh.
 load:
-  - strftime/strftime-min.js
-  - rgbcolor/rgbcolor.js
   - dashed-canvas.js
   - dygraph-layout.js
   - dygraph-canvas.js
diff --git a/push-to-web.sh b/push-to-web.sh
index 77bd91f..47352c5 100755
--- a/push-to-web.sh
+++ b/push-to-web.sh
@@ -30,7 +30,7 @@ if [ -s docs/options.html ] ; then
   find . -path ./.git -prune -o -print | xargs chmod a+rX
 
   # Copy everything to the site.
-  rsync -avzr gallery strftime rgbcolor common tests jsdoc experimental plugins $site \
+  rsync -avzr gallery common tests jsdoc experimental plugins $site \
   && \
   rsync -avzr --copy-links dashed-canvas.js stacktrace.js dygraph*.js gadget.xml excanvas.js thumbnail.png screenshot.png $temp_dir/* $site/
 else
diff --git a/tests/custom-circles.html b/tests/custom-circles.html
index e85581f..0f0ec3c 100644
--- a/tests/custom-circles.html
+++ b/tests/custom-circles.html
@@ -11,7 +11,7 @@
     
     -->
     
-    
+    
 
   
   
diff --git a/tests/plotters.html b/tests/plotters.html
index 9b800ec..30a4fd9 100644
--- a/tests/plotters.html
+++ b/tests/plotters.html
@@ -52,6 +52,15 @@