X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2Fto_dom_coords.js;h=e5bda3b1918d654e76c51b73161195cf35bd7dde;hb=cf61aeb77cda5e2638b1f00588dcd90394afd24c;hp=abbe332112697bb962cbe4acaf43e015c6465632;hpb=3123ca57f71d145bb5bcc4a2f754d3dff3225346;p=dygraphs.git diff --git a/auto_tests/tests/to_dom_coords.js b/auto_tests/tests/to_dom_coords.js index abbe332..e5bda3b 100644 --- a/auto_tests/tests/to_dom_coords.js +++ b/auto_tests/tests/to_dom_coords.js @@ -3,20 +3,17 @@ * * @author danvk@google.com (Dan Vanderkam) */ +import Dygraph from '../../src/dygraph'; +import * as utils from '../../src/dygraph-utils'; + +import Proxy from './Proxy'; +import CanvasAssertions from './CanvasAssertions'; +import {assertDeepCloseTo} from './custom_asserts'; describe("to-dom-coords", function() { -var origFunc = Dygraph.getContext; -beforeEach(function() { - document.body.innerHTML = "
"; - Dygraph.getContext = function(canvas) { - return new Proxy(origFunc(canvas)); - } -}); - -afterEach(function() { - Dygraph.getContext = origFunc; -}); +cleanupAfterEach(); +useProxyCanvas(utils, Proxy); // Checks that toDomCoords and toDataCoords are inverses of one another. var checkForInverses = function(g) { @@ -34,14 +31,14 @@ var checkForInverses = function(g) { it('testPlainChart', function() { var opts = { - axes : { - x : { + axes: { + x: { drawAxis : false, - drawGrid : false, + drawGrid : false }, - y : { + y: { drawAxis : false, - drawGrid : false, + drawGrid : false } }, rightGap: 0, @@ -49,7 +46,8 @@ it('testPlainChart', function() { dateWindow: [0, 100], width: 400, height: 400, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -69,12 +67,12 @@ it('testPlainChart', function() { it('testChartWithAxes', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, drawAxis: true, }, - y : { + y: { drawGrid: false, drawAxis: true, axisLabelWidth: 100 @@ -87,7 +85,8 @@ it('testChartWithAxes', function() { dateWindow: [0, 100], width: 500, height: 450, - colors: ['#ff0000'] + colors: ['#ff0000'], + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -103,16 +102,16 @@ it('testChartWithAxes', function() { it('testChartWithAxesAndLabels', function() { var opts = { - axes : { - x : { + axes: { + x: { drawGrid: false, drawAxis: true, }, - y : { + y: { drawGrid: false, drawAxis: true, axisLabelWidth: 100 - } + }, }, xAxisHeight: 50, axisTickSize: 0, @@ -126,7 +125,8 @@ it('testChartWithAxesAndLabels', function() { xlabel: 'This is the x-axis', xLabelHeight: 25, title: 'This is the title of the chart', - titleHeight: 25 + titleHeight: 25, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -148,7 +148,8 @@ it('testYAxisLabelWidth', function() { valueRange: [0, 100], dateWindow: [0, 100], width: 500, - height: 500 + height: 500, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -172,7 +173,8 @@ it('testAxisTickSize', function() { valueRange: [0, 100], dateWindow: [0, 100], width: 500, - height: 500 + height: 500, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -204,7 +206,8 @@ it('testChartLogarithmic_YAxis', function() { drawAxis: false, logscale: true } - } + }, + labels: ['X', 'Y'] } var graph = document.getElementById("graph"); @@ -222,6 +225,20 @@ it('testChartLogarithmic_YAxis', function() { assert.deepEqual([400, 0], g.toDomCoords(10, 4)); assert.deepEqual([400, 400], g.toDomCoords(10, 1)); assert.deepEqual([400, 200], g.toDomCoords(10, 2)); + + // Verify that the margins are adjusted appropriately for yRangePad. + g.updateOptions({yRangePad: 40}); + assertDeepCloseTo([0, 4], g.toDataCoords(0, 40), epsilon); + assertDeepCloseTo([0, 1], g.toDataCoords(0, 360), epsilon); + assertDeepCloseTo([10, 4], g.toDataCoords(400, 40), epsilon); + assertDeepCloseTo([10, 1], g.toDataCoords(400, 360), epsilon); + assertDeepCloseTo([10, 2], g.toDataCoords(400, 200), epsilon); + + assertDeepCloseTo([0, 40], g.toDomCoords(0, 4), epsilon); + assertDeepCloseTo([0, 360], g.toDomCoords(0, 1), epsilon); + assertDeepCloseTo([400, 40], g.toDomCoords(10, 4), epsilon); + assertDeepCloseTo([400, 360], g.toDomCoords(10, 1), epsilon); + assertDeepCloseTo([400, 200], g.toDomCoords(10, 2), epsilon); }); it('testChartLogarithmic_XAxis', function() { @@ -242,7 +259,8 @@ it('testChartLogarithmic_XAxis', function() { drawGrid: false, drawAxis: false } - } + }, + labels: ['X', 'Y'] } var graph = document.getElementById("graph");