From: Robert Konigsberg Date: Sat, 6 Dec 2014 05:11:35 +0000 (-0500) Subject: Remove old-style series specifications. X-Git-Tag: v2.0.0~83^2~3 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=0a5aa490041ec62b5c7e4951d4d4e7a2fd345fc2;p=dygraphs.git Remove old-style series specifications. --- diff --git a/auto_tests/misc/local.html b/auto_tests/misc/local.html index 6549d66..37bda4e 100644 --- a/auto_tests/misc/local.html +++ b/auto_tests/misc/local.html @@ -35,7 +35,6 @@ - diff --git a/auto_tests/tests/multiple_axes-old.js b/auto_tests/tests/multiple_axes-old.js deleted file mode 100644 index 912b3fd..0000000 --- a/auto_tests/tests/multiple_axes-old.js +++ /dev/null @@ -1,311 +0,0 @@ -/** - * @fileoverview Tests involving multiple y-axes. - * - * @author danvdk@gmail.com (Dan Vanderkam) - */ - -var MultipleAxesOldTestCase = TestCase("multiple-axes-old-tests"); - -MultipleAxesOldTestCase.prototype.setUp = function() { - document.body.innerHTML = "
"; -}; - -MultipleAxesOldTestCase.getData = function() { - var data = []; - for (var i = 1; i <= 100; i++) { - var m = "01", d = i; - if (d > 31) { m = "02"; d -= 31; } - if (m == "02" && d > 28) { m = "03"; d -= 28; } - if (m == "03" && d > 31) { m = "04"; d -= 31; } - if (d < 10) d = "0" + d; - // two series, one with range 1-100, one with range 1-2M - data.push([new Date("2010/" + m + "/" + d), - i, - 100 - i, - 1e6 * (1 + i * (100 - i) / (50 * 50)), - 1e6 * (2 - i * (100 - i) / (50 * 50))]); - } - return data; -}; - -MultipleAxesOldTestCase.prototype.testOldBasicMultipleAxes = function() { - var data = MultipleAxesTestCase.getData(); - - var g = new Dygraph( - document.getElementById("graph"), - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - width: 640, - height: 350, - 'Y3': { - axis: { - // set axis-related properties here - labelsKMB: true - } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - } - } - ); - - assertEquals(["0","20","40","60","80","100"], Util.getYLabels("1")); - assertEquals(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util.getYLabels("2")); -}; - -MultipleAxesOldTestCase.prototype.testOldNewStylePerAxisOptions = function() { - var data = MultipleAxesTestCase.getData(); - - var g = new Dygraph( - document.getElementById("graph"), - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - width: 640, - height: 350, - 'Y3': { - axis: { } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - }, - axes: { - y2: { - labelsKMB: true - } - } - } - ); - - assertEquals(["0","20","40","60","80","100"], Util.getYLabels("1")); - assertEquals(["900K","1.12M","1.34M","1.55M","1.77M","1.99M"], Util.getYLabels("2")); -}; - -MultipleAxesOldTestCase.prototype.testOldMultiAxisLayout = function() { - var data = MultipleAxesTestCase.getData(); - - var el = document.getElementById("graph"); - - var g = new Dygraph( - el, - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - width: 640, - height: 350, - 'Y3': { - axis: { } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - }, - axes: { - y2: { - labelsKMB: true - } - } - } - ); - - // Test that all elements are inside the bounds of the graph, set above - var innerDiv = el.firstChild; - for (var child = innerDiv.firstChild; child != null; child = child.nextSibling) { - assertTrue(child.offsetLeft >= 0); - assertTrue((child.offsetLeft + child.offsetWidth) <= 640); - assertTrue(child.offsetTop >= 0); - // TODO(flooey@google.com): Text sometimes linebreaks, - // causing the labels to appear outside the allocated area. - // assertTrue((child.offsetTop + child.offsetHeight) <= 350); - } -}; - -MultipleAxesOldTestCase.prototype.testOldTwoAxisVisibility = function() { - var data = []; - data.push([0,0,0]); - data.push([1,2,2000]); - data.push([2,4,1000]); - - var g = new Dygraph( - document.getElementById("graph"), - data, - { - labels: [ 'X', 'bar', 'zot' ], - 'zot': { - axis: { - labelsKMB: true - } - } - } - ); - - assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0); - assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0); - - g.setVisibility(0, false); - - assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0); - assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0); - - g.setVisibility(0, true); - g.setVisibility(1, false); - - assertTrue(document.getElementsByClassName("dygraph-axis-label-y").length > 0); - assertTrue(document.getElementsByClassName("dygraph-axis-label-y2").length > 0); -}; - -// verifies that all four chart labels (title, x-, y-, y2-axis label) can be -// used simultaneously. -MultipleAxesOldTestCase.prototype.testOldMultiChartLabels = function() { - var data = MultipleAxesTestCase.getData(); - - var el = document.getElementById("graph"); - el.style.border = '1px solid black'; - el.style.marginLeft = '200px'; - el.style.marginTop = '200px'; - - var g = new Dygraph( - el, - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - width: 640, - height: 350, - 'Y3': { - axis: { } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - }, - xlabel: 'x-axis', - ylabel: 'y-axis', - y2label: 'y2-axis', - title: 'Chart title' - } - ); - - assertEquals(["Chart title", "x-axis", "y-axis", "y2-axis"], - Util.getClassTexts("dygraph-label")); - assertEquals(["Chart title"], Util.getClassTexts("dygraph-title")); - assertEquals(["x-axis"], Util.getClassTexts("dygraph-xlabel")); - assertEquals(["y-axis"], Util.getClassTexts("dygraph-ylabel")); - assertEquals(["y2-axis"], Util.getClassTexts("dygraph-y2label")); - - // TODO(danvk): check relative positioning here: title on top, y left of y2. -}; - -// Check that a chart w/o a secondary y-axis will not get a y2label, even if one -// is specified. -MultipleAxesOldTestCase.prototype.testOldNoY2LabelWithoutSecondaryAxis = function() { - var g = new Dygraph( - document.getElementById("graph"), - MultipleAxesTestCase.getData(), - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - width: 640, - height: 350, - xlabel: 'x-axis', - ylabel: 'y-axis', - y2label: 'y2-axis', - title: 'Chart title' - } - ); - - assertEquals(["Chart title", "x-axis", "y-axis"], - Util.getClassTexts("dygraph-label")); - assertEquals(["Chart title"], Util.getClassTexts("dygraph-title")); - assertEquals(["x-axis"], Util.getClassTexts("dygraph-xlabel")); - assertEquals(["y-axis"], Util.getClassTexts("dygraph-ylabel")); - assertEquals([], Util.getClassTexts("dygraph-y2label")); -}; - -MultipleAxesOldTestCase.prototype.testOldValueRangePerAxisOptions = function() { - var data = MultipleAxesTestCase.getData(); - - g = new Dygraph( - document.getElementById("graph"), - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - 'Y3': { - axis: { - } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - }, - axes: { - y: { - valueRange: [40, 70] - }, - y2: { - // set axis-related properties here - labelsKMB: true - } - }, - ylabel: 'Primary y-axis', - y2label: 'Secondary y-axis', - yAxisLabelWidth: 60 - } - ); - assertEquals(["40", "45", "50", "55", "60", "65"], Util.getYLabels("1")); - assertEquals(["900K","1.1M","1.3M","1.5M","1.7M","1.9M"], Util.getYLabels("2")); - - g.updateOptions( - { - axes: { - y: { - valueRange: [40, 80] - }, - y2: { - valueRange: [1e6, 1.2e6] - } - } - } - ); - assertEquals(["40", "45", "50", "55", "60", "65", "70", "75"], Util.getYLabels("1")); - assertEquals(["1M", "1.02M", "1.05M", "1.08M", "1.1M", "1.13M", "1.15M", "1.18M"], Util.getYLabels("2")); -}; - -MultipleAxesOldTestCase.prototype.testOldDrawPointCallback = function() { - var data = MultipleAxesTestCase.getData(); - - var results = { y : {}, y2 : {}}; - var firstCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) { - results.y[seriesName] = 1; - Dygraph.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius); - - }; - var secondCallback = function(g, seriesName, ctx, canvasx, canvasy, color, radius) { - results.y2[seriesName] = 1; - Dygraph.Circles.DEFAULT(g, seriesName, ctx, canvasx, canvasy, color, radius); - }; - - g = new Dygraph( - document.getElementById("graph"), - data, - { - labels: [ 'Date', 'Y1', 'Y2', 'Y3', 'Y4' ], - drawPoints : true, - pointSize : 3, - 'Y3': { - axis: { - } - }, - 'Y4': { - axis: 'Y3' // use the same y-axis as series Y3 - }, - axes: { - y2: { - drawPointCallback: secondCallback - } - }, - drawPointCallback: firstCallback - } - ); - - assertEquals(1, results.y["Y1"]); - assertEquals(1, results.y["Y2"]); - assertEquals(1, results.y2["Y3"]); - assertEquals(1, results.y2["Y4"]); -}; diff --git a/auto_tests/tests/per_series.js b/auto_tests/tests/per_series.js index 8a7e081..09c3c5c 100644 --- a/auto_tests/tests/per_series.js +++ b/auto_tests/tests/per_series.js @@ -49,20 +49,6 @@ perSeriesTestCase.prototype.testPerSeriesFill = function() { assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5)); }; -perSeriesTestCase.prototype.testOldStyleSeries = function() { - var opts = { - pointSize : 5, - Y: { pointSize : 4 }, - }; - var graph = document.getElementById("graph"); - var data = "X,Y,Z\n1,0,0\n"; - g = new Dygraph(graph, data, opts); - - assertEquals(5, g.getOption("pointSize")); - assertEquals(4, g.getOption("pointSize", "Y")); - assertEquals(5, g.getOption("pointSize", "Z")); -}; - perSeriesTestCase.prototype.testNewStyleSeries = function() { var opts = { pointSize : 5, @@ -79,29 +65,6 @@ perSeriesTestCase.prototype.testNewStyleSeries = function() { assertEquals(5, g.getOption("pointSize", "Z")); }; -perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() { - var opts = { - pointSize : 5, - Z : { pointSize : 6 }, - series : { - Y: { pointSize : 4 } - }, - }; - var graph = document.getElementById("graph"); - var data = "X,Y,Z\n1,0,0\n"; - g = new Dygraph(graph, data, opts); - - assertEquals(5, g.getOption("pointSize")); - assertEquals(4, g.getOption("pointSize", "Y")); - assertEquals(5, g.getOption("pointSize", "Z")); - - // Erase the series object, and Z will become visible again. - g.updateOptions({ series : undefined }); - assertEquals(5, g.getOption("pointSize")); - assertEquals(6, g.getOption("pointSize", "Z")); - assertEquals(5, g.getOption("pointSize", "Y")); -}; - // TODO(konigsberg): move to multiple_axes.js perSeriesTestCase.prototype.testAxisInNewSeries = function() { var opts = { diff --git a/auto_tests/tests/range_tests.js b/auto_tests/tests/range_tests.js index c652af7..051c1e3 100644 --- a/auto_tests/tests/range_tests.js +++ b/auto_tests/tests/range_tests.js @@ -228,45 +228,6 @@ RangeTestCase.prototype.testIncludeZeroPerAxis = function() { assertEquals([44, 116], g.yAxisRange(1)); } - -/** - * Verify that includeZero range is properly specified per axis with old axis options. - */ -RangeTestCase.prototype.testIncludeZeroPerAxisOld = function() { - var g = new Dygraph("graph", - 'X,A,B\n' + - '0,50,50\n' + - '50,110,110\n', - { - drawPoints: true, - pointSize: 5, - - A: { - pointSize: 10 - }, - B: { - axis: {} - }, - axes: { - 'y': { includeZero: true }, - 'y2': { includeZero: false } - } - }); - - assertEquals([0, 121], g.yAxisRange(0)); - assertEquals([44, 116], g.yAxisRange(1)); - - g.updateOptions({ - axes: { - 'y': { includeZero: false }, - 'y2': { includeZero: true } - } - }); - - assertEquals([44, 116], g.yAxisRange(0)); - assertEquals([0, 121], g.yAxisRange(1)); -} - /** * Verify that very large Y ranges don't break things. */ diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index cfcdb79..999d1df 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -831,7 +831,7 @@ Dygraph.OPTIONS_REFERENCE = // "default": "null", "labels": ["Series"], "type": "Object", - "description": "Defines per-series options. Its keys match the y-axis label names, and the values are dictionaries themselves that contain options specific to that series. When this option is missing, it falls back on the old-style of per-series options comingled with global options." + "description": "Defines per-series options. Its keys match the y-axis label names, and the values are dictionaries themselves that contain options specific to that series." }, "plugins": { "default": "[]", diff --git a/dygraph-options.js b/dygraph-options.js index fd6876a..fdd1c44 100644 --- a/dygraph-options.js +++ b/dygraph-options.js @@ -135,16 +135,7 @@ DygraphOptions.prototype.reparseSeries = function() { this.xAxis_ = { options : {} }; this.series_ = {}; - // Traditionally, per-series options were specified right up there with the options. For instance - // { - // labels: [ "X", "foo", "bar" ], - // pointSize: 3, - // foo : {}, // options for foo - // bar : {} // options for bar - // } - // - // Moving forward, series really should be specified in the series element, separating them. - // like so: + // Series are specified in the series element: // // { // labels: [ "X", "foo", "bar" ], @@ -155,67 +146,23 @@ DygraphOptions.prototype.reparseSeries = function() { // } // } // - // So, if series is found, it's expected to contain per-series data, otherwise we fall - // back. - var oldStyleSeries = !this.user_["series"]; - - if (oldStyleSeries) { - var axisId = 0; // 0-offset; there's always one. - // Go through once, add all the series, and for those with {} axis options, add a new axis. - for (var idx = 0; idx < this.labels_.length; idx++) { - var seriesName = this.labels_[idx]; - - var optionsForSeries = this.user_[seriesName] || {}; - - var yAxis = 0; - var axis = optionsForSeries["axis"]; - if (typeof(axis) == 'object') { - yAxis = ++axisId; - this.yAxes_[yAxis] = { series : [ seriesName ], options : axis }; - } - - // Associate series without axis options with axis 0. - if (!axis) { // undefined - this.yAxes_[0].series.push(seriesName); - } - - this.series_[seriesName] = { idx: idx, yAxis: yAxis, options : optionsForSeries }; - } - - // Go through one more time and assign series to an axis defined by another - // series, e.g. { 'Y1: { axis: {} }, 'Y2': { axis: 'Y1' } } - for (var idx = 0; idx < this.labels_.length; idx++) { - var seriesName = this.labels_[idx]; - var optionsForSeries = this.series_[seriesName]["options"]; - var axis = optionsForSeries["axis"]; - - if (typeof(axis) == 'string') { - if (!this.series_.hasOwnProperty(axis)) { - console.error("Series " + seriesName + " wants to share a y-axis with " + - "series " + axis + ", which does not define its own axis."); - return; - } - var yAxis = this.series_[axis].yAxis; - this.series_[seriesName].yAxis = yAxis; - this.yAxes_[yAxis].series.push(seriesName); - } - } - } else { - for (var idx = 0; idx < this.labels_.length; idx++) { - var seriesName = this.labels_[idx]; - var optionsForSeries = this.user_.series[seriesName] || {}; - var yAxis = DygraphOptions.axisToIndex_(optionsForSeries["axis"]); - - this.series_[seriesName] = { - idx: idx, - yAxis: yAxis, - options : optionsForSeries }; - - if (!this.yAxes_[yAxis]) { - this.yAxes_[yAxis] = { series : [ seriesName ], options : {} }; - } else { - this.yAxes_[yAxis].series.push(seriesName); - } + // So, if series is found, it's expected to contain per-series data, otherwise set a + // default. + var series_dict = this.user_.series || {}; + for (var idx = 0; idx < this.labels_.length; idx++) { + var seriesName = this.labels_[idx]; + var optionsForSeries = series_dict[seriesName] || {}; + var yAxis = DygraphOptions.axisToIndex_(optionsForSeries["axis"]); + + this.series_[seriesName] = { + idx: idx, + yAxis: yAxis, + options : optionsForSeries }; + + if (!this.yAxes_[yAxis]) { + this.yAxes_[yAxis] = { series : [ seriesName ], options : {} }; + } else { + this.yAxes_[yAxis].series.push(seriesName); } }