From 475f7420e0ec216995edb9db860a005273a97894 Mon Sep 17 00:00:00 2001 From: Klaus Weidner Date: Sat, 25 Feb 2012 11:37:14 -0800 Subject: [PATCH] cleanups as requested in kberg's review --- auto_tests/tests/callback.js | 77 +++++++++++++++++++++++--------------------- dygraph-options-reference.js | 10 +++--- dygraph.js | 43 +++++++++++++------------ 3 files changed, 68 insertions(+), 62 deletions(-) diff --git a/auto_tests/tests/callback.js b/auto_tests/tests/callback.js index 9643da5..6281b92 100644 --- a/auto_tests/tests/callback.js +++ b/auto_tests/tests/callback.js @@ -15,47 +15,50 @@ CallbackTestCase.prototype.setUp = function() { CallbackTestCase.prototype.tearDown = function() { }; - - var data = "X,a\,b,c\n" + + +var data = "X,a\,b,c\n" + "10,-1,1,2\n" + "11,0,3,1\n" + "12,1,4,2\n" + "13,0,2,3\n"; - - - /** - * This tests that when the function idxToRow_ returns the proper row and the onHiglightCallback - * is properly called when the first series is hidden (setVisibility = false) - * - */ - CallbackTestCase.prototype.testHighlightCallbackIsCalled = function() { - var h_row; - var h_pts; - - var highlightCallback = function(e, x, pts, row) { - h_row = row; - h_pts = pts; - }; - - - - var graph = document.getElementById("graph"); - var g = new Dygraph(graph, data, - { - width: 100, - height : 100, - visibility: [false, true, true], - highlightCallback : highlightCallback - }); - - DygraphOps.dispatchMouseMove(g, 13, 10); - - //check correct row is returned - assertEquals(3, h_row); - //check there are only two points (because first series is hidden) - assertEquals(2, h_pts.length); - }; + +/** + * This tests that when the function idxToRow_ returns the proper row and the onHiglightCallback + * is properly called when the first series is hidden (setVisibility = false) + * + */ +CallbackTestCase.prototype.testHighlightCallbackIsCalled = function() { + var h_row; + var h_pts; + + var highlightCallback = function(e, x, pts, row) { + h_row = row; + h_pts = pts; + }; + + var graph = document.getElementById("graph"); + var g = new Dygraph(graph, data, + { + width: 100, + height: 100, + visibility: [false, true, true], + highlightCallback: highlightCallback + }); + + DygraphOps.dispatchMouseMove(g, 13, 10); + + //check correct row is returned + assertEquals(3, h_row); + //check there are only two points (because first series is hidden) + assertEquals(2, h_pts.length); +}; + +/** + * Test the closest-series highlighting methods for normal and stacked modes. + * Also pass in line widths for plain and highlighted lines for easier visual + * confirmation that the highlighted line is drawn on top of the others. + */ var runClosestTest = function(isStacked, widthNormal, widthHighlighted) { var h_row; var h_pts; @@ -65,7 +68,7 @@ var runClosestTest = function(isStacked, widthNormal, widthHighlighted) { var g = new Dygraph(graph, data, { width: 600, - height : 400, + height: 400, visibility: [false, true, true], stackedGraph: isStacked, strokeWidth: widthNormal, diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 62dc2c3..15c1507 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -93,10 +93,10 @@ Dygraph.OPTIONS_REFERENCE = // "type": "number", "description": "When nonzero, dim the background while highlighting series. 0=fully visible, 1=hidden" }, - "highlightSeriesAnimated": { + "highlightSeriesAnimate": { "default": "false", "labels": ["Interactive Elements"], - "type": "Object", + "type": "boolean", "description": "Animate the background dimming for nonzero highlightSeriesBackgroundFade." }, "includeZero": { @@ -277,7 +277,7 @@ Dygraph.OPTIONS_REFERENCE = // "strokeWidth": { "default": "1.0", "labels": ["Data Line display"], - "type": "integer", + "type": "float", "example": "0.5, 2.0", "description": "The width of the lines connecting data points. This can be used to increase the contrast or some graphs." }, @@ -291,8 +291,8 @@ Dygraph.OPTIONS_REFERENCE = // "strokeBorderWidth": { "default": "null", "labels": ["Data Line display"], - "type": "integer", - "example": "0.5, 2.0", + "type": "float", + "example": "1.0", "description": "Draw a border around graph lines to make crossing lines more easily distinguishable. Useful for graphs with many lines." }, "strokeBorderColor": { diff --git a/dygraph.js b/dygraph.js index 735be8c..616dfe9 100644 --- a/dygraph.js +++ b/dygraph.js @@ -461,14 +461,16 @@ Dygraph.prototype.attr_ = function(name, seriesName) { var sources = []; sources.push(this.attrs_); - if (this.user_attrs_) sources.push(this.user_attrs_); - if (this.user_attrs_ && seriesName) { - if (this.user_attrs_.hasOwnProperty(seriesName)) { - sources.push(this.user_attrs_[seriesName]); - } - if (seriesName === this.highlightSet_ && - this.user_attrs_.hasOwnProperty('highlightSeriesOpts')) { - sources.push(this.user_attrs_['highlightSeriesOpts']); + if (this.user_attrs_) { + sources.push(this.user_attrs_); + if (seriesName) { + if (this.user_attrs_.hasOwnProperty(seriesName)) { + sources.push(this.user_attrs_[seriesName]); + } + if (seriesName === this.highlightSet_ && + this.user_attrs_.hasOwnProperty('highlightSeriesOpts')) { + sources.push(this.user_attrs_['highlightSeriesOpts']); + } } } @@ -1855,18 +1857,19 @@ Dygraph.prototype.animateSelection_ = function(direction) { var thisId = ++this.animateId; var that = this; - Dygraph.repeatAndCleanup(function(n) { - // ignore simultaneous animations - if (that.animateId != thisId) return; - - that.fadeLevel += direction; - if (that.fadeLevel === 0) { - that.clearSelection(); - } else { - that.updateSelection_(that.fadeLevel / totalSteps); - } - }, - steps, millis, function() {}); + Dygraph.repeatAndCleanup( + function(n) { + // ignore simultaneous animations + if (that.animateId != thisId) return; + + that.fadeLevel += direction; + if (that.fadeLevel === 0) { + that.clearSelection(); + } else { + that.updateSelection_(that.fadeLevel / totalSteps); + } + }, + steps, millis, function() {}); }; /** -- 2.7.4