X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fto_dom_coords.js;h=22ee3fef0b330377c4573b231a9c9b39e77fc80a;hb=7f6a719056e1da51c5a27727ac5341d6664de428;hp=c70b704776fe0faaa6a867485dfe2dff75560ae4;hpb=35ca7c9806b81289b52c1d3598f62808361f0cc0;p=dygraphs.git diff --git a/auto_tests/tests/to_dom_coords.js b/auto_tests/tests/to_dom_coords.js index c70b704..22ee3fe 100644 --- a/auto_tests/tests/to_dom_coords.js +++ b/auto_tests/tests/to_dom_coords.js @@ -6,16 +6,16 @@ var ToDomCoordsTestCase = TestCase("to-dom-coords"); -var _origFunc = Dygraph.getContext; +ToDomCoordsTestCase._origFunc = Dygraph.getContext; ToDomCoordsTestCase.prototype.setUp = function() { document.body.innerHTML = "
"; Dygraph.getContext = function(canvas) { - return new Proxy(_origFunc(canvas)); + return new Proxy(ToDomCoordsTestCase._origFunc(canvas)); } }; ToDomCoordsTestCase.prototype.tearDown = function() { - Dygraph.getContext = _origFunc; + Dygraph.getContext = ToDomCoordsTestCase._origFunc; }; // Checks that toDomCoords and toDataCoords are inverses of one another. @@ -34,10 +34,16 @@ ToDomCoordsTestCase.prototype.checkForInverses = function(g) { ToDomCoordsTestCase.prototype.testPlainChart = function() { var opts = { - drawXAxis: false, - drawYAxis: false, - drawXGrid: false, - drawYGrid: false, + axes : { + x : { + drawAxis : false, + drawGrid : false, + }, + y : { + drawAxis : false, + drawGrid : false, + } + }, rightGap: 0, valueRange: [0, 100], dateWindow: [0, 100], @@ -56,6 +62,7 @@ ToDomCoordsTestCase.prototype.testPlainChart = function() { this.checkForInverses(g); + // TODO(konigsberg): This doesn't really belong here. Move to its own test. var htx = g.hidden_ctx_; assertEquals(1, CanvasAssertions.numLinesDrawn(htx, '#ff0000')); } @@ -120,3 +127,79 @@ ToDomCoordsTestCase.prototype.testChartWithAxesAndLabels = function() { this.checkForInverses(g); } + +ToDomCoordsTestCase.prototype.testYAxisLabelWidth = function() { + var opts = { + yAxisLabelWidth: 100, + axisTickSize: 0, + rightGap: 0, + valueRange: [0, 100], + dateWindow: [0, 100], + width: 500, + height: 500 + } + + var graph = document.getElementById("graph"); + g = new Dygraph(graph, [ [0,0], [100,100] ], opts); + + assertEquals([100, 0], g.toDomCoords(0, 100)); + assertEquals([500, 486], g.toDomCoords(100, 0)); + + g.updateOptions({ yAxisLabelWidth: 50 }); + assertEquals([50, 0], g.toDomCoords(0, 100)); + assertEquals([500, 486], g.toDomCoords(100, 0)); +} + +ToDomCoordsTestCase.prototype.testAxisTickSize = function() { + var opts = { + yAxisLabelWidth: 100, + axisTickSize: 0, + rightGap: 0, + valueRange: [0, 100], + dateWindow: [0, 100], + width: 500, + height: 500 + } + + var graph = document.getElementById("graph"); + g = new Dygraph(graph, [ [0,0], [100,100] ], opts); + + assertEquals([100, 0], g.toDomCoords(0, 100)); + assertEquals([500, 486], g.toDomCoords(100, 0)); + + g.updateOptions({ axisTickSize : 50 }); + assertEquals([200, 0], g.toDomCoords(0, 100)); + assertEquals([500, 386], g.toDomCoords(100, 0)); +} + +ToDomCoordsTestCase.prototype.testChartLogarithmic = function() { + var opts = { + drawXAxis: false, + drawYAxis: false, + drawXGrid: false, + drawYGrid: false, + logscale: true, + rightGap: 0, + valueRange: [1, 4], + dateWindow: [0, 10], + width: 400, + height: 400, + colors: ['#ff0000'] + } + + var graph = document.getElementById("graph"); + g = new Dygraph(graph, [ [1,1], [4,4] ], opts); + + var epsilon = 1e-8; + assertEqualsDelta([0, 4], g.toDataCoords(0, 0), epsilon); + assertEqualsDelta([0, 1], g.toDataCoords(0, 400), epsilon); + assertEqualsDelta([10, 4], g.toDataCoords(400, 0), epsilon); + assertEqualsDelta([10, 1], g.toDataCoords(400, 400), epsilon); + assertEqualsDelta([10, 2], g.toDataCoords(400, 200), epsilon); + + assertEquals([0, 0], g.toDomCoords(0, 4)); + assertEquals([0, 400], g.toDomCoords(0, 1)); + assertEquals([400, 0], g.toDomCoords(10, 4)); + assertEquals([400, 400], g.toDomCoords(10, 1)); + assertEquals([400, 200], g.toDomCoords(10, 2)); +}