X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=auto_tests%2Ftests%2Faxis_labels.js;h=0af808522547baa440bb810bdccb5ee00abcbdc6;hb=91bd611cb031bf1f3d39650e3109135fd0e78791;hp=89959ac9fe08240e5a98dfdb55d391f742447569;hpb=dc910fcebc0da0a621cf16073ebedabcff32fb12;p=dygraphs.git diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index 89959ac..0af8085 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -3,14 +3,16 @@ * * @author dan@dygraphs.com (Dan Vanderkam) */ -describe("axis-labels", function() { -beforeEach(function() { - document.body.innerHTML = "
"; -}); +import Dygraph from '../../src/dygraph'; +import * as utils from '../../src/dygraph-utils'; +import DEFAULT_ATTRS from '../../src/dygraph-default-attrs'; +import Util from './Util'; +import {assertDeepCloseTo} from './custom_asserts'; -afterEach(function() { -}); +describe("axis-labels", function() { + +cleanupAfterEach(); var simpleData = "X,Y,Y2\n" + @@ -125,7 +127,8 @@ it('testSmallRangeAwayFromZero', function() { it('testXAxisTimeLabelFormatter', function() { var opts = { width: 480, - height: 320 + height: 320, + labels: ['X', 'Y1'] }; var data = [[5.0,0],[5.1,1],[5.2,2],[5.3,3],[5.4,4],[5.5,5],[5.6,6],[5.7,7],[5.8,8],[5.9,9]]; var graph = document.getElementById("graph"); @@ -203,7 +206,7 @@ it('testDateAxisLabelFormatter', function() { x : { pixelsPerLabel: 60, axisLabelFormatter : function(x, granularity, opts, dg) { - assert.isTrue(Dygraph.isDateLike(x)); + assert.isTrue(utils.isDateLike(x)); assert.equal('number', typeof(granularity)); assert.equal('function', typeof(opts)); assert.equal('[Dygraph graph]', dg.toString()); @@ -619,11 +622,64 @@ it('testLabelKMG2_top', function() { Util.getYLabels()); }); +it('testSmallLabelKMB', function() { + var data = []; + data.push([0, 0]); + data.push([1, 1e-6]); + data.push([2, 2e-6]); + + var g = new Dygraph( + document.getElementById("graph"), + data, + { + labels: [ 'X', 'bar' ], + axes : { + y: { + labelsKMB: true + } + } + } + ); + + // TODO(danvk): use prefixes here (e.g. m, µ, n) + assert.deepEqual(['0', '5.00e-7', '1.00e-6', '1.50e-6', '2.00e-6'], + Util.getYLabels()); +}); + +it('testSmallLabelKMG2', function() { + var data = []; + data.push([0, 0]); + data.push([1, 1e-6]); + data.push([2, 2e-6]); + + var g = new Dygraph( + document.getElementById("graph"), + data, + { + labels: [ 'X', 'bar' ], + axes : { + y: { + labelsKMG2: true + } + } + } + ); + + // TODO(danvk): this is strange--the values aren't on powers of two, and are + // these units really used for powers of two in <1? See issue #571. + assert.deepEqual(['0', '0.48u', '0.95u', '1.43u', '1.91u'], + Util.getYLabels()); +}); + /** * Verify that log scale axis range is properly specified. */ it('testLogScale', function() { - var g = new Dygraph("graph", [[0, 5], [1, 1000]], { logscale : true }); + var g = new Dygraph("graph", + [[0, 5], [1, 1000]], { + logscale: true, + labels: ['X', 'Y'] + }); var nonEmptyLabels = Util.getYLabels().filter(function(x) { return x.length > 0; }); assert.deepEqual(["5","10","20","50","100","200","500","1000"], nonEmptyLabels); @@ -635,7 +691,11 @@ it('testLogScale', function() { * Verify that include zero range is properly specified. */ it('testIncludeZero', function() { - var g = new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero : true }); + var g = new Dygraph("graph", + [[0, 500], [1, 1000]], { + includeZero: true, + labels: ['X', 'Y1'] + }); assert.deepEqual(['0','200','400','600','800','1000'], Util.getYLabels()); g.updateOptions({ includeZero : false }); @@ -647,23 +707,23 @@ it('testAxisLabelFontSize', function() { var g = new Dygraph(graph, simpleData, {}); // Be sure we're dealing with a 14-point default. - assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize); + assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize); var assertFontSize = function(selector, expected) { Util.assertStyleOfChildren(selector, "font-size", expected); } - + assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "14px"); - assertFontSize(document.querySelectorAll(".dygraph-axis-label-y") , "14px"); + assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px"); - g.updateOptions({ axisLabelFontSize : 8}); + g.updateOptions({axisLabelFontSize : 8}); assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "8px"); assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "8px"); g.updateOptions({ axisLabelFontSize : null, - axes : { - x : { axisLabelFontSize : 5 }, + axes: { + x: { axisLabelFontSize : 5 }, } }); @@ -671,8 +731,8 @@ it('testAxisLabelFontSize', function() { assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px"); g.updateOptions({ - axes : { - y : { axisLabelFontSize : 20 }, + axes: { + y: { axisLabelFontSize : 20 }, } }); @@ -680,11 +740,11 @@ it('testAxisLabelFontSize', function() { assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "20px"); g.updateOptions({ - series : { - Y2 : { axis : "y2" } // copy y2 series to y2 axis. + series: { + Y2: { axis : "y2" } // copy y2 series to y2 axis. }, - axes : { - y2 : { axisLabelFontSize : 12 }, + axes: { + y2: { axisLabelFontSize : 12 }, } }); @@ -705,7 +765,7 @@ it('testAxisLabelFontSizeNull', function() { }; // Be sure we're dealing with a 14-point default. - assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize); + assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize); assertFontSize(document.querySelectorAll(".dygraph-axis-label-x"), "14px"); assertFontSize(document.querySelectorAll(".dygraph-axis-label-y"), "14px"); @@ -716,7 +776,7 @@ it('testAxisLabelColor', function() { var g = new Dygraph(graph, simpleData, {}); // Be sure we're dealing with a black default. - assert.equal("black", Dygraph.DEFAULT_ATTRS.axisLabelColor); + assert.equal("black", DEFAULT_ATTRS.axisLabelColor); var assertColor = function(selector, expected) { Util.assertStyleOfChildren(selector, "color", expected); @@ -774,7 +834,7 @@ it('testAxisLabelColorNull', function() { } // Be sure we're dealing with a 14-point default. - assert.equal(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize); + assert.equal(14, DEFAULT_ATTRS.axisLabelFontSize); assertColor(document.querySelectorAll(".dygraph-axis-label-x"), "rgb(0, 0, 0)"); assertColor(document.querySelectorAll(".dygraph-axis-label-y"), "rgb(0, 0, 0)");