2 * @fileoverview Test cases for how axis labels are chosen and formatted.
4 * @author dan@dygraphs.com (Dan Vanderkam)
6 var AxisLabelsTestCase
= TestCase("axis-labels");
8 AxisLabelsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 AxisLabelsTestCase
.prototype.tearDown
= function() {
15 AxisLabelsTestCase
.simpleData
=
22 AxisLabelsTestCase
.prototype.kCloseFloat
= 1.0e-10;
24 AxisLabelsTestCase
.prototype.testMinusOneToOne
= function() {
36 var graph
= document
.getElementById("graph");
37 var g
= new Dygraph(graph
, data
, opts
);
39 // TODO(danvk): would ['-1.0','-0.5','0.0','0.5','1.0'] be better?
40 assertEquals(['-1','-0.5','0','0.5','1'], Util
.getYLabels());
44 g
.updateOptions({file
: data
});
45 assertEquals(['-1','-0.5','0','0.5','1','1.5','2'], Util
.getYLabels());
49 g
.updateOptions({file
: data
});
50 assertEquals(['-2','0','2','4','6','8','10'], Util
.getYLabels());
54 g
.updateOptions({file
: data
});
55 assertEquals(['0','20','40','60','80','100'], Util
.getYLabels());
58 assertEquals('0: Y: -1', Util
.getLegend());
61 AxisLabelsTestCase
.prototype.testSmallRangeNearZero
= function() {
73 opts
.valueRange
= [-0.1, 0.1];
75 var graph
= document
.getElementById("graph");
76 var g
= new Dygraph(graph
, data
, opts
);
77 assertEqualsDelta([-0.1,-0.05,0,0.05],
78 Util
.makeNumbers(Util
.getYLabels()), this.kCloseFloat
);
80 opts
.valueRange
= [-0.05, 0.05];
81 g
.updateOptions(opts
);
82 assertEquals([-0.04,-0.02,0,0.02,0.04],
83 Util
.makeNumbers(Util
.getYLabels()));
85 opts
.valueRange
= [-0.01, 0.01];
86 g
.updateOptions(opts
);
87 assertEquals([-0.01,-0.005,0,0.005],
88 Util
.makeNumbers(Util
.getYLabels()));
91 assertEquals('1: Y: 0', Util
.getLegend());
94 AxisLabelsTestCase
.prototype.testSmallRangeAwayFromZero
= function() {
105 var graph
= document
.getElementById("graph");
107 opts
.valueRange
= [9.9, 10.1];
108 var g
= new Dygraph(graph
, data
, opts
);
109 assertEquals(["9.9","9.92","9.94","9.96","9.98","10","10.02","10.04","10.06","10.08"], Util
.getYLabels());
111 opts
.valueRange
= [9.99, 10.01];
112 g
.updateOptions(opts
);
113 // TODO(danvk): this is bad
114 assertEquals(["9.99","9.99","9.99","10","10","10","10","10","10.01","10.01"], Util
.getYLabels());
116 opts
.valueRange
= [9.999, 10.001];
117 g
.updateOptions(opts
);
118 // TODO(danvk): this is even worse!
119 assertEquals(["10","10","10","10"], Util
.getYLabels());
122 assertEquals('1: Y: 0', Util
.getLegend());
125 AxisLabelsTestCase
.prototype.testXAxisTimeLabelFormatter
= function() {
130 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]];
131 var graph
= document
.getElementById("graph");
132 var g
= new Dygraph(graph
, data
, opts
);
136 axisLabelFormatter
: function (totalMinutes
) {
137 var hours
= Math
.floor( totalMinutes
/ 60);
138 var minutes
= Math
.floor((totalMinutes
- (hours
* 60)));
139 var seconds
= Math
.round((totalMinutes
* 60) - (hours
* 3600) - (minutes
* 60));
141 if (hours
< 10) hours
= "0" + hours
;
142 if (minutes
< 10) minutes
= "0" + minutes
;
143 if (seconds
< 10) seconds
= "0" + seconds
;
145 return hours
+ ':' + minutes
+ ':' + seconds
;
151 assertEquals(["00:05:00","00:05:12","00:05:24","00:05:36","00:05:48"], Util
.getXLabels());
153 // The legend does not use the axisLabelFormatter:
155 assertEquals('5.1: Y1: 1', Util
.getLegend());
158 AxisLabelsTestCase
.prototype.testAxisLabelFormatter
= function () {
164 axisLabelFormatter
: function(x
, granularity
, opts
, dg
) {
165 assertEquals('number', typeof(x
));
166 assertEquals('number', typeof(granularity
));
167 assertEquals('function', typeof(opts
));
168 assertEquals('[Dygraph graph]', dg
.toString());
173 axisLabelFormatter
: function(y
, granularity
, opts
, dg
) {
174 assertEquals('number', typeof(y
));
175 assertEquals('number', typeof(granularity
));
176 assertEquals('function', typeof(opts
));
177 assertEquals('[Dygraph graph]', dg
.toString());
185 for (var i
= 0; i
< 10; i
++) {
186 data
.push([i
, 2 * i
]);
188 var graph
= document
.getElementById("graph");
189 var g
= new Dygraph(graph
, data
, opts
);
191 assertEquals(['x0','x2','x4','x6','x8'], Util
.getXLabels());
192 assertEquals(["y0","y5","y10","y15"], Util
.getYLabels());
195 assertEquals("2: y: 4", Util
.getLegend());
198 AxisLabelsTestCase
.prototype.testDateAxisLabelFormatter
= function () {
205 axisLabelFormatter
: function(x
, granularity
, opts
, dg
) {
206 assertTrue(Dygraph
.isDateLike(x
));
207 assertEquals('number', typeof(granularity
));
208 assertEquals('function', typeof(opts
));
209 assertEquals('[Dygraph graph]', dg
.toString());
210 return 'x' + Util
.formatDate(x
);
214 axisLabelFormatter
: function(y
, granularity
, opts
, dg
) {
215 assertEquals('number', typeof(y
));
216 assertEquals('number', typeof(granularity
));
217 assertEquals('function', typeof(opts
));
218 assertEquals('[Dygraph graph]', dg
.toString());
226 for (var i
= 1; i
< 10; i
++) {
227 data
.push([new Date("2011/01/0" + i
), 2 * i
]);
229 var graph
= document
.getElementById("graph");
230 var g
= new Dygraph(graph
, data
, opts
);
232 assertEquals(["x2011/01/02"], Util
.getXLabels());
233 assertEquals(["y5","y10","y15"], Util
.getYLabels());
236 assertEquals("2011/01/01: y: 2", Util
.getLegend());
239 // This test verifies that when a valueFormatter is set (but not an
240 // axisLabelFormatter), then the valueFormatter is used to format the axis
242 AxisLabelsTestCase
.prototype.testValueFormatter
= function () {
248 valueFormatter
: function(x
, opts
, series_name
, dg
) {
249 assertEquals('number', typeof(x
));
250 assertEquals('function', typeof(opts
));
251 assertEquals('string', typeof(series_name
));
252 assertEquals('[Dygraph graph]', dg
.toString());
257 valueFormatter
: function(y
, opts
, series_name
, dg
) {
258 assertEquals('number', typeof(y
));
259 assertEquals('function', typeof(opts
));
260 assertEquals('string', typeof(series_name
));
261 assertEquals('[Dygraph graph]', dg
.toString());
269 for (var i
= 0; i
< 10; i
++) {
270 data
.push([i
, 2 * i
]);
272 var graph
= document
.getElementById("graph");
273 var g
= new Dygraph(graph
, data
, opts
);
275 // the valueFormatter options do not affect the ticks.
276 assertEquals(['0','2','4','6','8'], Util
.getXLabels());
277 assertEquals(["0","5","10","15"],
280 // they do affect the legend, however.
282 assertEquals("x2: y: y4", Util
.getLegend());
285 AxisLabelsTestCase
.prototype.testDateValueFormatter
= function () {
292 valueFormatter
: function(x
, opts
, series_name
, dg
) {
293 assertEquals('number', typeof(x
));
294 assertEquals('function', typeof(opts
));
295 assertEquals('string', typeof(series_name
));
296 assertEquals('[Dygraph graph]', dg
.toString());
297 return 'x' + Util
.formatDate(x
);
301 valueFormatter
: function(y
, opts
, series_name
, dg
) {
302 assertEquals('number', typeof(y
));
303 assertEquals('function', typeof(opts
));
304 assertEquals('string', typeof(series_name
));
305 assertEquals('[Dygraph graph]', dg
.toString());
314 for (var i
= 1; i
< 10; i
++) {
315 data
.push([new Date("2011/01/0" + i
), 2 * i
]);
317 var graph
= document
.getElementById("graph");
318 var g
= new Dygraph(graph
, data
, opts
);
320 // valueFormatters do not affect ticks.
321 assertEquals(["02 Jan"], Util
.getXLabels());
322 assertEquals(["5","10","15"], Util
.getYLabels());
324 // the valueFormatter options also affect the legend.
326 assertEquals('x2011/01/03: y: y6', Util
.getLegend());
329 // This test verifies that when both a valueFormatter and an axisLabelFormatter
330 // are specified, the axisLabelFormatter takes precedence.
331 AxisLabelsTestCase
.prototype.testAxisLabelFormatterPrecedence
= function () {
337 valueFormatter
: function(x
) {
340 axisLabelFormatter
: function(x
, granularity
) {
345 valueFormatter
: function(y
) {
348 axisLabelFormatter
: function(y
) {
356 for (var i
= 0; i
< 10; i
++) {
357 data
.push([i
, 2 * i
]);
359 var graph
= document
.getElementById("graph");
360 var g
= new Dygraph(graph
, data
, opts
);
362 assertEquals(['x0','x2','x4','x6','x8'], Util
.getXLabels());
363 assertEquals(["y0","y5","y10","y15"], Util
.getYLabels());
366 assertEquals("xvf9: y: yvf18", Util
.getLegend());
369 // This is the same as the previous test, except that options are added
371 AxisLabelsTestCase
.prototype.testAxisLabelFormatterIncremental
= function () {
378 for (var i
= 0; i
< 10; i
++) {
379 data
.push([i
, 2 * i
]);
381 var graph
= document
.getElementById("graph");
382 var g
= new Dygraph(graph
, data
, opts
);
386 valueFormatter
: function(x
) {
395 valueFormatter
: function(y
) {
404 axisLabelFormatter
: function(x
, granularity
) {
413 axisLabelFormatter
: function(y
) {
420 assertEquals(["x0","x2","x4","x6","x8"], Util
.getXLabels());
421 assertEquals(["y0","y5","y10","y15"], Util
.getYLabels());
424 assertEquals("xvf9: y: yvf18", Util
.getLegend());
427 AxisLabelsTestCase
.prototype.testGlobalFormatters
= function() {
432 valueFormatter
: function(x
) {
435 axisLabelFormatter
: function(x
) {
440 for (var i
= 0; i
< 10; i
++) {
441 data
.push([i
, 2 * i
]);
443 var graph
= document
.getElementById("graph");
444 var g
= new Dygraph(graph
, data
, opts
);
446 assertEquals(['alf0','alf2','alf4','alf6','alf8'], Util
.getXLabels());
447 assertEquals(["alf0","alf5","alf10","alf15"], Util
.getYLabels());
450 assertEquals("vf9: y: vf18", Util
.getLegend());
453 AxisLabelsTestCase
.prototype.testSeriesOrder
= function() {
458 var data
= "x,00,01,10,11\n" +
459 "0,101,201,301,401\n" +
460 "1,102,202,302,402\n" +
461 "2,103,203,303,403\n" +
462 "3,104,204,304,404\n"
465 var graph
= document
.getElementById("graph");
466 var g
= new Dygraph(graph
, data
, opts
);
469 assertEquals('2: 00: 103 01: 203 10: 303 11: 403', Util
.getLegend());
471 // Sanity checks for indexFromSetName
472 assertEquals(0, g
.indexFromSetName("x"));
473 assertEquals(1, g
.indexFromSetName("00"));
474 assertEquals(null, g
.indexFromSetName("abcde"));
476 // Verify that we get the label list back in the right order
477 assertEquals(["x", "00", "01", "10", "11"], g
.getLabels());
480 AxisLabelsTestCase
.prototype.testLabelKMB
= function() {
487 document
.getElementById("graph"),
490 labels
: [ 'X', 'bar' ],
499 assertEquals(["0", "500", "1K", "1.5K", "2K"], Util
.getYLabels());
502 AxisLabelsTestCase
.prototype.testLabelKMG2
= function() {
509 document
.getElementById("graph"),
512 labels
: [ 'X', 'bar' ],
522 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
526 // Same as testLabelKMG2 but specifies the option at the
527 // top of the option dictionary.
528 AxisLabelsTestCase
.prototype.testLabelKMG2_top
= function() {
535 document
.getElementById("graph"),
538 labels
: [ 'X', 'bar' ],
544 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
549 * Verify that log scale axis range is properly specified.
551 AxisLabelsTestCase
.prototype.testLogScale
= function() {
552 var g
= new Dygraph("graph", [[0, 5], [1, 1000]], { logscale
: true });
553 var nonEmptyLabels
= Util
.getYLabels().filter(function(x
) { return x
.length
> 0; });
554 assertEquals(["5","10","20","50","100","200","500","1000"], nonEmptyLabels
);
556 g
.updateOptions({ logscale
: false });
557 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
561 * Verify that include zero range is properly specified.
563 AxisLabelsTestCase
.prototype.testIncludeZero
= function() {
564 var g
= new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero
: true });
565 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
567 g
.updateOptions({ includeZero
: false });
568 assertEquals(['500','600','700','800','900','1000'], Util
.getYLabels());
571 AxisLabelsTestCase
.prototype.testAxisLabelFontSize
= function() {
572 var graph
= document
.getElementById("graph");
573 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
575 // Be sure we're dealing with a 14-point default.
576 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
578 var assertFontSize
= function(selector
, expected
) {
579 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
582 assertFontSize($(".dygraph-axis-label-x"), "14px");
583 assertFontSize($(".dygraph-axis-label-y") , "14px");
585 g
.updateOptions({ axisLabelFontSize
: 8});
586 assertFontSize($(".dygraph-axis-label-x"), "8px");
587 assertFontSize($(".dygraph-axis-label-y"), "8px");
590 axisLabelFontSize
: null,
592 x
: { axisLabelFontSize
: 5 },
596 assertFontSize($(".dygraph-axis-label-x"), "5px");
597 assertFontSize($(".dygraph-axis-label-y"), "14px");
601 y
: { axisLabelFontSize
: 20 },
605 assertFontSize($(".dygraph-axis-label-x"), "5px");
606 assertFontSize($(".dygraph-axis-label-y"), "20px");
610 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
613 y2
: { axisLabelFontSize
: 12 },
617 assertFontSize($(".dygraph-axis-label-x"), "5px");
618 assertFontSize($(".dygraph-axis-label-y1"), "20px");
619 assertFontSize($(".dygraph-axis-label-y2"), "12px");
622 AxisLabelsTestCase
.prototype.testAxisLabelFontSizeNull
= function() {
623 var graph
= document
.getElementById("graph");
624 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
626 axisLabelFontSize
: null
629 var assertFontSize
= function(selector
, expected
) {
630 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
633 // Be sure we're dealing with a 14-point default.
634 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
636 assertFontSize($(".dygraph-axis-label-x"), "14px");
637 assertFontSize($(".dygraph-axis-label-y"), "14px");
640 AxisLabelsTestCase
.prototype.testAxisLabelColor
= function() {
641 var graph
= document
.getElementById("graph");
642 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
644 // Be sure we're dealing with a black default.
645 assertEquals("black", Dygraph
.DEFAULT_ATTRS
.axisLabelColor
);
647 var assertColor
= function(selector
, expected
) {
648 Util
.assertStyleOfChildren(selector
, "color", expected
);
651 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
652 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
654 g
.updateOptions({ axisLabelColor
: "red"});
655 assertColor($(".dygraph-axis-label-x"), "rgb(255, 0, 0)");
656 assertColor($(".dygraph-axis-label-y"), "rgb(255, 0, 0)");
659 axisLabelColor
: null,
661 x
: { axisLabelColor
: "blue" },
665 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
666 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
670 y
: { axisLabelColor
: "green" },
674 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
675 assertColor($(".dygraph-axis-label-y"), "rgb(0, 128, 0)");
679 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
682 y2
: { axisLabelColor
: "yellow" },
686 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
687 assertColor($(".dygraph-axis-label-y1"), "rgb(0, 128, 0)");
688 assertColor($(".dygraph-axis-label-y2"), "rgb(255, 255, 0)");
691 AxisLabelsTestCase
.prototype.testAxisLabelColorNull
= function() {
692 var graph
= document
.getElementById("graph");
693 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
698 var assertColor
= function(selector
, expected
) {
699 Util
.assertStyleOfChildren(selector
, "color", expected
);
702 // Be sure we're dealing with a 14-point default.
703 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
705 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
706 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
710 * This test shows that the label formatter overrides labelsKMB for all values.
712 AxisLabelsTestCase
.prototype.testLabelFormatterOverridesLabelsKMB
= function() {
714 document
.getElementById("graph"),
721 axisLabelFormatter
: function (v
) {
725 assertEquals(["0:X","500:X","1000:X","1500:X","2000:X"], Util
.getYLabels());
726 assertEquals(["1:X","2:X","3:X"], Util
.getXLabels());
730 * This test shows that you can override labelsKMB on the axis level.
732 AxisLabelsTestCase
.prototype.testLabelsKMBPerAxis
= function() {
734 document
.getElementById("graph"),
742 y2
: { labelsKMB
: true },
743 x
: { labelsKMB
: true }
750 // labelsKMB doesn't apply to the x axis. This value should be different.
751 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
752 assertEquals(["1000","2000","3000"], Util
.getXLabels());
753 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
754 assertEquals(["0","500","1K","1.5K","2K"], Util
.getYLabels(2));
758 * This test shows that you can override labelsKMG2 on the axis level.
760 AxisLabelsTestCase
.prototype.testLabelsKMBG2IPerAxis
= function() {
762 document
.getElementById("graph"),
770 y2
: { labelsKMG2
: true },
771 x
: { labelsKMG2
: true, pixelsPerLabel
: 60 }
778 // It is weird that labelsKMG2 does something on the x axis but KMB does not.
779 // Plus I can't be sure they're doing the same thing as they're done in different
781 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
782 assertEquals(["1024","2048","3072"], Util
.getXLabels());
783 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
784 assertEquals(["0","500","1000","1.46k","1.95k"], Util
.getYLabels(2));
788 * This test shows you can override sigFigs on the axis level.
790 AxisLabelsTestCase
.prototype.testSigFigsPerAxis
= function() {
792 document
.getElementById("graph"),
808 // sigFigs doesn't apply to the x axis. This value should be different.
809 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
810 assertEquals(["1000","2000","3000"], Util
.getXLabels());
811 assertEquals(["0.0","5.0e+2","1.0e+3","1.5e+3","2.0e+3"], Util
.getYLabels(1));
812 assertEquals(["0.00000","500.000","1000.00","1500.00","2000.00"], Util
.getYLabels(2));
816 * This test shows you can override digitsAfterDecimal on the axis level.
818 AxisLabelsTestCase
.prototype.testDigitsAfterDecimalPerAxis
= function() {
820 document
.getElementById("graph"),
822 "0.006,0.001,0.008\n" +
823 "0.007,0.002,0.007\n" +
824 "0.008,0.003,0.006\n" +
825 "0.009,0.004,0.005\n", {
826 digitsAfterDecimal
: 1,
833 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 3 }}});
834 assertEquals(["0.001","0.002","0.002","0.003","0.003","0.004","0.004"], Util
.getYLabels(1));
835 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 4 }}});
836 assertEquals(["0.001","0.0015","0.002","0.0025","0.003","0.0035","0.004"], Util
.getYLabels(1));
837 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 5 }}});
838 assertEquals(["0.001","0.0015","0.002","0.0025","0.003","0.0035","0.004"], Util
.getYLabels(1));
839 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: null }}});
840 assertEquals(["1e-3","2e-3","2e-3","3e-3","3e-3","4e-3","4e-3"], Util
.getYLabels(1));
842 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 3 }}});
843 assertEquals(["0.005","0.006","0.006","0.007","0.007","0.008","0.008"], Util
.getYLabels(2));
844 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 4 }}});
845 assertEquals(["0.005","0.0055","0.006","0.0065","0.007","0.0075","0.008"], Util
.getYLabels(2));
846 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 5 }}});
847 assertEquals(["0.005","0.0055","0.006","0.0065","0.007","0.0075","0.008"], Util
.getYLabels(2));
848 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: null }}});
849 assertEquals(["5e-3","6e-3","6e-3","7e-3","7e-3","7e-3","8e-3"], Util
.getYLabels(2));
852 // digitsAfterDecimal is ignored for the x-axis.
853 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
854 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 3 }}});
855 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
856 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 4 }}});
857 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
858 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 5 }}});
859 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
860 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: null }}});
861 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
865 * This test shows you can override digitsAfterDecimal on the axis level.
867 AxisLabelsTestCase
.prototype.testMaxNumberWidthPerAxis
= function() {
869 document
.getElementById("graph"),
871 "12401,12601,12804\n" +
872 "12402,12602,12803\n" +
873 "12403,12603,12802\n" +
874 "12404,12604,12801\n", {
881 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 4 }}});
882 assertEquals(["1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4"] , Util
.getYLabels(1));
883 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 5 }}});
884 assertEquals(["12601","12601.5","12602","12602.5","12603","12603.5","12604"] , Util
.getYLabels(1));
885 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: null }}});
886 assertEquals(["1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4","1.26e+4"] , Util
.getYLabels(1));
888 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 4 }}});
889 assertEquals(["1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4"], Util
.getYLabels(2));
890 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 5 }}});
891 assertEquals(["12801","12801.5","12802","12802.5","12803","12803.5","12804"], Util
.getYLabels(2));
892 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: null }}});
893 assertEquals(["1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4","1.28e+4"], Util
.getYLabels(2));
895 // maxNumberWidth is ignored for the x-axis.
896 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
897 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 4 }}});
898 assertEquals(["12401","12402","12403"], Util
.getXLabels());
899 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 5 }}});
900 assertEquals(["12401","12402","12403"], Util
.getXLabels());
901 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: null }}});
902 assertEquals(["12401","12402","12403"], Util
.getXLabels());
906 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=147
907 // Checks that axis labels stay sane across a DST change.
908 AxisLabelsTestCase.prototype.testLabelsCrossDstChange = function() {
909 // (From tests/daylight-savings.html)
911 document.getElementById("graph"),
912 "Date/Time,Purchases\n" +
913 "2010-11-05 00:00:00,167082\n" +
914 "2010-11-06 00:00:00,168571\n" +
915 "2010-11-07 00:00:00,177796\n" +
916 "2010-11-08 00:00:00,165587\n" +
917 "2010-11-09 00:00:00,164380\n",
921 // Dates and "nice" hours: 6AM/PM and noon, not 5AM/11AM/...
933 var xLabels = Util.getXLabels();
934 for (var i = 0; i < xLabels.length; i++) {
935 assertTrue(okLabels[xLabels[i]]);
938 // This range had issues of its own on tests/daylight-savings.html.
940 dateWindow: [1289109997722.8127, 1289261208937.7659]
942 xLabels = Util.getXLabels();
943 for (var i = 0; i < xLabels.length; i++) {
944 assertTrue(okLabels[xLabels[i]]);
949 // Tests data which crosses a "fall back" at a high enough frequency that you
950 // can see both 1:00 A.M.s.
951 AxisLabelsTestCase.prototype.testLabelsCrossDstChangeHighFreq = function() {
952 // Generate data which crosses the EST/EDT boundary.
954 var base_ms = 1383454200000;
955 for (var x = base_ms; x < base_ms + 1000 * 60 * 80; x += 1000) {
956 dst_data.push([new Date(x), x]);
960 document.getElementById("graph"),
962 { width: 1024, labels: ['Date', 'Value'] }
967 '01:00', '01:05', '01:10', '01:15', '01:20', '01:25',
968 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
969 '01:00', '01:05' // 1 AM number two!
970 ], Util.getXLabels());
972 // Now zoom past the initial 1 AM. This used to cause trouble.
974 dateWindow: [1383454200000 + 15*60*1000, g.xAxisExtremes()[1]]}
977 '01:05', '01:10', '01:15', '01:20', '01:25',
978 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
979 '01:00', '01:05' // 1 AM number two!
980 ], Util.getXLabels());
984 // Tests data which crosses a "spring forward" at a low frequency.
985 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=433
986 AxisLabelsTestCase.prototype.testLabelsCrossSpringForward = function() {
988 document.getElementById("graph"),
989 "Date/Time,Purchases\n" +
990 "2011-03-11 00:00:00,167082\n" +
991 "2011-03-12 00:00:00,168571\n" +
992 "2011-03-13 00:00:00,177796\n" +
993 "2011-03-14 00:00:00,165587\n" +
994 "2011-03-15 00:00:00,164380\n",
997 dateWindow: [1299989043119.4365, 1300080693627.4866]
1002 // '02:00': true, // not a real time!
1016 var xLabels = Util.getXLabels();
1017 for (var i = 0; i < xLabels.length; i++) {
1018 assertTrue(okLabels[xLabels[i]]);
1022 AxisLabelsTestCase.prototype.testLabelsCrossSpringForwardHighFreq = function() {
1023 var base_ms_spring = 1299999000000;
1024 var dst_data_spring = [];
1025 for (var x = base_ms_spring; x < base_ms_spring + 1000 * 60 * 80; x += 1000) {
1026 dst_data_spring.push([new Date(x), x]);
1029 var g = new Dygraph(
1030 document.getElementById("graph"),
1032 { width: 1024, labels: ['Date', 'Value'] }
1037 '03:00', '03:05', '03:10', '03:15', '03:20', '03:25',
1038 '03:30', '03:35', '03:40', '03:45', '03:50', '03:55',
1040 ], Util.getXLabels());