Merge pull request #465 from danvk/callback-this
authorRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:29:32 +0000 (19:29 -0500)
committerRobert Konigsberg <konigsberg@gmail.com>
Sun, 16 Nov 2014 00:29:32 +0000 (19:29 -0500)
Set "this" to the Dygraph object in all callbacks

auto_tests/tests/missing_points.js
dygraph.js
file-size-stats.sh [deleted file]
generate-combined.sh

index 3a27759..a78e0ac 100644 (file)
@@ -18,7 +18,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 
-/** 
+/**
  * @fileoverview Test cases for drawing lines with missing points.
  *
  * @author konigsberg@google.com (Robert Konigsberg)
@@ -85,7 +85,7 @@ MissingPointsTestCase.prototype.testSeparatedPointsDontDraw_expanded_connected =
   var num_lines = 0;
 
   assertEquals(3, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [[56, 275], [161, 212], [370, 87], [475, 25]],
       { strokeStyle: '#0000ff' });
 };
@@ -114,12 +114,12 @@ MissingPointsTestCase.prototype.testConnectSeparatedPoints = function() {
   var htx = g.hidden_ctx_;
 
   assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [[56, 225], [223, 25], [391, 125]],
       { strokeStyle: '#0000ff' });
 
   assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000'));
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [[140, 275], [307, 125], [475, 225]],
       { strokeStyle: '#ff0000' });
 };
@@ -155,12 +155,12 @@ MissingPointsTestCase.prototype.testConnectSeparatedPointsWithNan = function() {
 
   // Blue's lines are consecutive, however.
   assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [[56, 244], [149, 181], [242, 118]],
       { strokeStyle: '#0000ff' });
 };
 
-/* These lines contain awesome powa!  
+/* These lines contain awesome powa!
   var lines = CanvasAssertions.getLinesDrawn(htx, {strokeStyle: "#0000ff"});
   for (var idx = 0; idx < lines.length; idx++) {
     var line = lines[idx];
@@ -194,9 +194,9 @@ MissingPointsTestCase.prototype.testErrorBarsWithMissingPoints = function() {
   var p1 = g.toDomCoords(data[1][0], data[1][1][0]);
   var p2 = g.toDomCoords(data[3][0], data[3][1][0]);
   var p3 = g.toDomCoords(data[4][0], data[4][1][0]);
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [p0, p1], { strokeStyle: '#ff0000' });
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [p2, p3], { strokeStyle: '#ff0000' });
 };
 
@@ -221,13 +221,13 @@ MissingPointsTestCase.prototype.testErrorBarsWithMissingPointsConnected = functi
   );
 
   var htx = g.hidden_ctx_;
-  
+
   assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000'));
 
   var p1 = g.toDomCoords(data[1][0], data[1][1][0]);
   var p2 = g.toDomCoords(data[3][0], data[3][1][0]);
   var p3 = g.toDomCoords(data[5][0], data[5][1][0]);
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [p1, p2, p3],
       { strokeStyle: '#ff0000' });
 };
@@ -262,7 +262,7 @@ MissingPointsTestCase.prototype.testCustomBarsWithMissingPoints = function() {
   var p0 = g.toDomCoords(data[0][0], data[0][1][1]);
   var p1 = g.toDomCoords(data[1][0], data[1][1][1]);
   CanvasAssertions.assertLineDrawn(htx, p0, p1, { strokeStyle: '#ff0000' });
-  
+
   p0 = g.toDomCoords(data[3][0], data[3][1][1]);
   p1 = g.toDomCoords(data[4][0], data[4][1][1]);
   CanvasAssertions.assertLineDrawn(htx, p0, p1, { strokeStyle: '#ff0000' });
@@ -297,16 +297,17 @@ MissingPointsTestCase.prototype.testCustomBarsWithMissingPointsConnected = funct
   );
 
   var htx = g.hidden_ctx_;
-  
+
   assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000'));
 
   var p1 = g.toDomCoords(data[1][0], data[1][1][1]);
   var p2 = g.toDomCoords(data[3][0], data[3][1][1]);
   var p3 = g.toDomCoords(data[5][0], data[5][1][1]);
-  CanvasAssertions.assertConsecutiveLinesDrawn(htx, 
+  CanvasAssertions.assertConsecutiveLinesDrawn(htx,
       [p1, p2, p3],
       { strokeStyle: '#ff0000' });
 };
+
 MissingPointsTestCase.prototype.testLeftBoundaryWithMisingPoints = function() {
   var data = [
               [1, null, 3],
@@ -336,7 +337,6 @@ MissingPointsTestCase.prototype.testLeftBoundaryWithMisingPoints = function() {
   g.setSelection(closestRow);
   assertEquals(1, g.selPoints_.length);
   assertEquals(1, g.selPoints_[0].yval);
-  
 
   g.setSelection(3);
   assertEquals(2, g.selPoints_.length);
@@ -344,3 +344,27 @@ MissingPointsTestCase.prototype.testLeftBoundaryWithMisingPoints = function() {
   assertEquals(2, g.selPoints_[0].yval);
   assertEquals(1, g.selPoints_[1].yval);
 };
+
+// Regression test for issue #411
+MissingPointsTestCase.prototype.testEmptySeries = function() {
+  var graphDiv = document.getElementById("graph");
+  var g = new Dygraph(
+       graphDiv,
+       "Time,Empty Series,Series 1,Series 2\n" +
+       "1381134460,,0,100\n" +
+       "1381134461,,1,99\n" +
+       "1381134462,,2,98\n" +
+       "1381134463,,3,97\n" +
+       "1381134464,,4,96\n" +
+       "1381134465,,5,95\n" +
+       "1381134466,,6,94\n" +
+       "1381134467,,7,93\n" +
+       "1381134468,,8,92\n" +
+       "1381134469,,9,91\n", {
+           visibility: [true, false, true],
+           dateWindow: [1381134465, 1381134467]
+       });
+
+  g.setSelection(6);
+  assertEquals("1381134466: Series 2: 94", Util.getLegend(graphDiv));
+};
index bc1b216..27b1b36 100644 (file)
@@ -43,6 +43,9 @@
 
  */
 
+// For "production" code, this gets set to false by uglifyjs.
+if (typeof(DEBUG) === 'undefined') DEBUG=true;
+
 /*jshint globalstrict: true */
 /*global DygraphLayout:false, DygraphCanvasRenderer:false, DygraphOptions:false, G_vmlCanvasManager:false,ActiveXObject:false */
 "use strict";
@@ -665,16 +668,16 @@ Dygraph.prototype.toString = function() {
  * @return { ... } The value of the option.
  */
 Dygraph.prototype.attr_ = function(name, seriesName) {
-// <REMOVE_FOR_COMBINED>
-  if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
-    console.error('Must include options reference JS for testing');
-  } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
-    console.error('Dygraphs is using property ' + name + ', which has no ' +
-                  'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
-    // Only log this error once.
-    Dygraph.OPTIONS_REFERENCE[name] = true;
-  }
-// </REMOVE_FOR_COMBINED>
+  if (DEBUG) {
+    if (typeof(Dygraph.OPTIONS_REFERENCE) === 'undefined') {
+      console.error('Must include options reference JS for testing');
+    } else if (!Dygraph.OPTIONS_REFERENCE.hasOwnProperty(name)) {
+      console.error('Dygraphs is using property ' + name + ', which has no ' +
+                    'entry in the Dygraphs.OPTIONS_REFERENCE listing.');
+      // Only log this error once.
+      Dygraph.OPTIONS_REFERENCE[name] = true;
+    }
+  }
   return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
 };
 
diff --git a/file-size-stats.sh b/file-size-stats.sh
deleted file mode 100755 (executable)
index fb81519..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-# Reports compressed file sizes for each JS file in dygraphs.
-
-# This list needs to be kept in sync w/ the one in dygraph-dev.js
-# and the one in jsTestDriver.conf.
-for file in \
-dygraph-layout.js \
-dygraph-canvas.js \
-dygraph.js \
-dygraph-utils.js \
-dygraph-gviz.js \
-dygraph-interaction-model.js \
-dygraph-tickers.js \
-dashed-canvas.js \
-dygraph-plugin-base.js \
-plugins/annotations.js \
-plugins/axes.js \
-plugins/range-selector.js \
-plugins/chart-labels.js \
-plugins/grid.js \
-plugins/legend.js \
-dygraph-plugin-install.js \
-; do
-  base_size=$(cat $file | wc -c)
-  cat $file \
-    | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,' \
-    > /tmp/dygraph.js
-  min_size=$(java -jar yuicompressor-2.4.2.jar /tmp/dygraph.js | gzip -c | wc -c)
-
-  echo "$min_size ($base_size) $file"
-done
index 30c0a7e..a224156 100755 (executable)
@@ -33,8 +33,7 @@ GetSources () {
 # Pack all the JS together.
 CatSources () {
   GetSources \
-  | xargs cat \
-  | perl -ne 'print unless m,REMOVE_FOR_COMBINED,..m,/REMOVE_FOR_COMBINED,'
+  | xargs cat 
 }
 
 Copyright () {
@@ -42,10 +41,13 @@ Copyright () {
 }
 
 CatCompressed () {
-  Copyright
-  CatSources \
-  | grep -v '"use strict";' \
-  | node_modules/uglify-js/bin/uglifyjs -c warnings=false -m
+  node_modules/uglify-js/bin/uglifyjs \
+    $(GetSources | xargs) \
+    --compress warnings=false \
+    --mangle \
+    --define DEBUG=false \
+    --preamble "$(Copyright)" \
+    $*
 }
 
 ACTION="${1:-update}"
@@ -61,8 +63,9 @@ compress*|cat_compress*)
   CatCompressed
   ;;
 update)
-  CatCompressed > dygraph-combined.js
-  chmod a+r dygraph-combined.js
+  CatCompressed --source-map dygraph-combined.js.map \
+    > dygraph-combined.js
+  chmod a+r dygraph-combined.js dygraph-combined.js.map
   ;;
 *)
   echo >&2 "Unknown action '$ACTION'"