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","x2011/01/04","x2011/01/06","x2011/01/08"], 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
, row
, col
) {
249 assertEquals('number', typeof(x
));
250 assertEquals('function', typeof(opts
));
251 assertEquals('string', typeof(series_name
));
252 assertEquals('[Dygraph graph]', dg
.toString());
253 assertEquals('number', typeof(row
));
254 assertEquals('number', typeof(col
));
259 valueFormatter
: function(y
, opts
, series_name
, dg
, row
, col
) {
260 assertEquals('number', typeof(y
));
261 assertEquals('function', typeof(opts
));
262 assertEquals('string', typeof(series_name
));
263 assertEquals('[Dygraph graph]', dg
.toString());
264 assertEquals('number', typeof(row
));
265 assertEquals('number', typeof(col
));
273 for (var i
= 0; i
< 10; i
++) {
274 data
.push([i
, 2 * i
]);
276 var graph
= document
.getElementById("graph");
277 var g
= new Dygraph(graph
, data
, opts
);
279 // the valueFormatter options do not affect the ticks.
280 assertEquals(['0','2','4','6','8'], Util
.getXLabels());
281 assertEquals(["0","5","10","15"],
284 // they do affect the legend, however.
286 assertEquals("x2: y: y4", Util
.getLegend());
289 AxisLabelsTestCase
.prototype.testDateValueFormatter
= function () {
296 valueFormatter
: function(x
, opts
, series_name
, dg
, row
, col
) {
297 assertEquals('number', typeof(x
));
298 assertEquals('function', typeof(opts
));
299 assertEquals('string', typeof(series_name
));
300 assertEquals('[Dygraph graph]', dg
.toString());
301 assertEquals('number', typeof(row
));
302 assertEquals('number', typeof(col
));
303 return 'x' + Util
.formatDate(x
);
307 valueFormatter
: function(y
, opts
, series_name
, dg
, row
, col
) {
308 assertEquals('number', typeof(y
));
309 assertEquals('function', typeof(opts
));
310 assertEquals('string', typeof(series_name
));
311 assertEquals('[Dygraph graph]', dg
.toString());
312 assertEquals('number', typeof(row
));
313 assertEquals('number', typeof(col
));
322 for (var i
= 1; i
< 10; i
++) {
323 data
.push([new Date("2011/01/0" + i
), 2 * i
]);
325 var graph
= document
.getElementById("graph");
326 var g
= new Dygraph(graph
, data
, opts
);
328 // valueFormatters do not affect ticks.
329 assertEquals(["02 Jan","04 Jan","06 Jan","08 Jan"], Util
.getXLabels());
330 assertEquals(["5","10","15"], Util
.getYLabels());
332 // the valueFormatter options also affect the legend.
334 assertEquals('x2011/01/03: y: y6', Util
.getLegend());
337 // This test verifies that when both a valueFormatter and an axisLabelFormatter
338 // are specified, the axisLabelFormatter takes precedence.
339 AxisLabelsTestCase
.prototype.testAxisLabelFormatterPrecedence
= function () {
345 valueFormatter
: function(x
) {
348 axisLabelFormatter
: function(x
, granularity
) {
353 valueFormatter
: function(y
) {
356 axisLabelFormatter
: function(y
) {
364 for (var i
= 0; i
< 10; i
++) {
365 data
.push([i
, 2 * i
]);
367 var graph
= document
.getElementById("graph");
368 var g
= new Dygraph(graph
, data
, opts
);
370 assertEquals(['x0','x2','x4','x6','x8'], Util
.getXLabels());
371 assertEquals(["y0","y5","y10","y15"], Util
.getYLabels());
374 assertEquals("xvf9: y: yvf18", Util
.getLegend());
377 // This is the same as the previous test, except that options are added
379 AxisLabelsTestCase
.prototype.testAxisLabelFormatterIncremental
= function () {
386 for (var i
= 0; i
< 10; i
++) {
387 data
.push([i
, 2 * i
]);
389 var graph
= document
.getElementById("graph");
390 var g
= new Dygraph(graph
, data
, opts
);
394 valueFormatter
: function(x
) {
403 valueFormatter
: function(y
) {
412 axisLabelFormatter
: function(x
, granularity
) {
421 axisLabelFormatter
: function(y
) {
428 assertEquals(["x0","x2","x4","x6","x8"], Util
.getXLabels());
429 assertEquals(["y0","y5","y10","y15"], Util
.getYLabels());
432 assertEquals("xvf9: y: yvf18", Util
.getLegend());
435 AxisLabelsTestCase
.prototype.testGlobalFormatters
= function() {
440 valueFormatter
: function(x
) {
443 axisLabelFormatter
: function(x
) {
448 for (var i
= 0; i
< 10; i
++) {
449 data
.push([i
, 2 * i
]);
451 var graph
= document
.getElementById("graph");
452 var g
= new Dygraph(graph
, data
, opts
);
454 assertEquals(['alf0','alf2','alf4','alf6','alf8'], Util
.getXLabels());
455 assertEquals(["alf0","alf5","alf10","alf15"], Util
.getYLabels());
458 assertEquals("vf9: y: vf18", Util
.getLegend());
461 AxisLabelsTestCase
.prototype.testValueFormatterParameters
= function() {
463 // change any functions in list to 'fn' -- functions can't be asserted.
464 var killFunctions
= function(list
) {
466 for (var i
= 0; i
< list
.length
; i
++) {
467 if (typeof(list
[i
]) == 'function') {
475 var taggedRecorder
= function(tag
) {
477 calls
.push([tag
].concat(killFunctions(arguments
)));
483 x
: { valueFormatter
: taggedRecorder('x') },
484 y
: { valueFormatter
: taggedRecorder('y') },
485 y2
: { valueFormatter
: taggedRecorder('y2') }
491 labels
: ['x', 'y1', 'y2']
497 var graph
= document
.getElementById('graph');
498 var g
= new Dygraph(graph
, data
, opts
);
500 assertEquals([], calls
);
503 // num or millis, opts, series, dygraph, row, col
504 [ 'x', 0, 'fn', 'x', g
, 0, 0],
505 [ 'y', 1, 'fn', 'y1', g
, 0, 1],
506 ['y2', 2, 'fn', 'y2', g
, 0, 2]
512 [ 'x', 1, 'fn', 'x', g
, 1, 0],
513 [ 'y', 3, 'fn', 'y1', g
, 1, 1],
514 ['y2', 4, 'fn', 'y2', g
, 1, 2]
518 AxisLabelsTestCase
.prototype.testSeriesOrder
= function() {
523 var data
= "x,00,01,10,11\n" +
524 "0,101,201,301,401\n" +
525 "1,102,202,302,402\n" +
526 "2,103,203,303,403\n" +
527 "3,104,204,304,404\n"
530 var graph
= document
.getElementById("graph");
531 var g
= new Dygraph(graph
, data
, opts
);
534 assertEquals('2: 00: 103 01: 203 10: 303 11: 403', Util
.getLegend());
536 // Sanity checks for indexFromSetName
537 assertEquals(0, g
.indexFromSetName("x"));
538 assertEquals(1, g
.indexFromSetName("00"));
539 assertEquals(null, g
.indexFromSetName("abcde"));
541 // Verify that we get the label list back in the right order
542 assertEquals(["x", "00", "01", "10", "11"], g
.getLabels());
545 AxisLabelsTestCase
.prototype.testLabelKMB
= function() {
552 document
.getElementById("graph"),
555 labels
: [ 'X', 'bar' ],
564 assertEquals(["0", "500", "1K", "1.5K", "2K"], Util
.getYLabels());
567 AxisLabelsTestCase
.prototype.testLabelKMG2
= function() {
574 document
.getElementById("graph"),
577 labels
: [ 'X', 'bar' ],
587 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
591 // Same as testLabelKMG2 but specifies the option at the
592 // top of the option dictionary.
593 AxisLabelsTestCase
.prototype.testLabelKMG2_top
= function() {
600 document
.getElementById("graph"),
603 labels
: [ 'X', 'bar' ],
609 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
614 * Verify that log scale axis range is properly specified.
616 AxisLabelsTestCase
.prototype.testLogScale
= function() {
617 var g
= new Dygraph("graph", [[0, 5], [1, 1000]], { logscale
: true });
618 var nonEmptyLabels
= Util
.getYLabels().filter(function(x
) { return x
.length
> 0; });
619 assertEquals(["5","10","20","50","100","200","500","1000"], nonEmptyLabels
);
621 g
.updateOptions({ logscale
: false });
622 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
626 * Verify that include zero range is properly specified.
628 AxisLabelsTestCase
.prototype.testIncludeZero
= function() {
629 var g
= new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero
: true });
630 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
632 g
.updateOptions({ includeZero
: false });
633 assertEquals(['500','600','700','800','900','1000'], Util
.getYLabels());
636 AxisLabelsTestCase
.prototype.testAxisLabelFontSize
= function() {
637 var graph
= document
.getElementById("graph");
638 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
640 // Be sure we're dealing with a 14-point default.
641 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
643 var assertFontSize
= function(selector
, expected
) {
644 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
647 assertFontSize($(".dygraph-axis-label-x"), "14px");
648 assertFontSize($(".dygraph-axis-label-y") , "14px");
650 g
.updateOptions({ axisLabelFontSize
: 8});
651 assertFontSize($(".dygraph-axis-label-x"), "8px");
652 assertFontSize($(".dygraph-axis-label-y"), "8px");
655 axisLabelFontSize
: null,
657 x
: { axisLabelFontSize
: 5 },
661 assertFontSize($(".dygraph-axis-label-x"), "5px");
662 assertFontSize($(".dygraph-axis-label-y"), "14px");
666 y
: { axisLabelFontSize
: 20 },
670 assertFontSize($(".dygraph-axis-label-x"), "5px");
671 assertFontSize($(".dygraph-axis-label-y"), "20px");
675 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
678 y2
: { axisLabelFontSize
: 12 },
682 assertFontSize($(".dygraph-axis-label-x"), "5px");
683 assertFontSize($(".dygraph-axis-label-y1"), "20px");
684 assertFontSize($(".dygraph-axis-label-y2"), "12px");
687 AxisLabelsTestCase
.prototype.testAxisLabelFontSizeNull
= function() {
688 var graph
= document
.getElementById("graph");
689 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
691 axisLabelFontSize
: null
694 var assertFontSize
= function(selector
, expected
) {
695 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
698 // Be sure we're dealing with a 14-point default.
699 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
701 assertFontSize($(".dygraph-axis-label-x"), "14px");
702 assertFontSize($(".dygraph-axis-label-y"), "14px");
705 AxisLabelsTestCase
.prototype.testAxisLabelColor
= function() {
706 var graph
= document
.getElementById("graph");
707 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
709 // Be sure we're dealing with a black default.
710 assertEquals("black", Dygraph
.DEFAULT_ATTRS
.axisLabelColor
);
712 var assertColor
= function(selector
, expected
) {
713 Util
.assertStyleOfChildren(selector
, "color", expected
);
716 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
717 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
719 g
.updateOptions({ axisLabelColor
: "red"});
720 assertColor($(".dygraph-axis-label-x"), "rgb(255, 0, 0)");
721 assertColor($(".dygraph-axis-label-y"), "rgb(255, 0, 0)");
724 axisLabelColor
: null,
726 x
: { axisLabelColor
: "blue" },
730 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
731 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
735 y
: { axisLabelColor
: "green" },
739 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
740 assertColor($(".dygraph-axis-label-y"), "rgb(0, 128, 0)");
744 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
747 y2
: { axisLabelColor
: "yellow" },
751 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
752 assertColor($(".dygraph-axis-label-y1"), "rgb(0, 128, 0)");
753 assertColor($(".dygraph-axis-label-y2"), "rgb(255, 255, 0)");
756 AxisLabelsTestCase
.prototype.testAxisLabelColorNull
= function() {
757 var graph
= document
.getElementById("graph");
758 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
763 var assertColor
= function(selector
, expected
) {
764 Util
.assertStyleOfChildren(selector
, "color", expected
);
767 // Be sure we're dealing with a 14-point default.
768 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
770 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
771 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
775 * This test shows that the label formatter overrides labelsKMB for all values.
777 AxisLabelsTestCase
.prototype.testLabelFormatterOverridesLabelsKMB
= function() {
779 document
.getElementById("graph"),
786 axisLabelFormatter
: function (v
) {
790 assertEquals(["0:X","500:X","1000:X","1500:X","2000:X"], Util
.getYLabels());
791 assertEquals(["1:X","2:X","3:X"], Util
.getXLabels());
795 * This test shows that you can override labelsKMB on the axis level.
797 AxisLabelsTestCase
.prototype.testLabelsKMBPerAxis
= function() {
799 document
.getElementById("graph"),
807 y2
: { labelsKMB
: true },
808 x
: { labelsKMB
: true }
815 // labelsKMB doesn't apply to the x axis. This value should be different.
816 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
817 assertEquals(["1000","2000","3000"], Util
.getXLabels());
818 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
819 assertEquals(["0","500","1K","1.5K","2K"], Util
.getYLabels(2));
823 * This test shows that you can override labelsKMG2 on the axis level.
825 AxisLabelsTestCase
.prototype.testLabelsKMBG2IPerAxis
= function() {
827 document
.getElementById("graph"),
835 y2
: { labelsKMG2
: true },
836 x
: { labelsKMG2
: true, pixelsPerLabel
: 60 }
843 // It is weird that labelsKMG2 does something on the x axis but KMB does not.
844 // Plus I can't be sure they're doing the same thing as they're done in different
846 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
847 assertEquals(["1024","2048","3072"], Util
.getXLabels());
848 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
849 assertEquals(["0","500","1000","1.46k","1.95k"], Util
.getYLabels(2));
853 * This test shows you can override sigFigs on the axis level.
855 AxisLabelsTestCase
.prototype.testSigFigsPerAxis
= function() {
857 document
.getElementById("graph"),
873 // sigFigs doesn't apply to the x axis. This value should be different.
874 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
875 assertEquals(["1000","2000","3000"], Util
.getXLabels());
876 assertEquals(["0.0","5.0e+2","1.0e+3","1.5e+3","2.0e+3"], Util
.getYLabels(1));
877 assertEquals(["0.00000","500.000","1000.00","1500.00","2000.00"], Util
.getYLabels(2));
881 * This test shows you can override digitsAfterDecimal on the axis level.
883 AxisLabelsTestCase
.prototype.testDigitsAfterDecimalPerAxis
= function() {
885 document
.getElementById("graph"),
887 "0.006,0.001,0.008\n" +
888 "0.007,0.002,0.007\n" +
889 "0.008,0.003,0.006\n" +
890 "0.009,0.004,0.005\n", {
891 digitsAfterDecimal
: 1,
898 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 3 }}});
899 assertEquals(["0.001","0.002","0.002","0.003","0.003","0.004","0.004"], Util
.getYLabels(1));
900 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 4 }}});
901 assertEquals(["0.001","0.0015","0.002","0.0025","0.003","0.0035","0.004"], Util
.getYLabels(1));
902 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 5 }}});
903 assertEquals(["0.001","0.0015","0.002","0.0025","0.003","0.0035","0.004"], Util
.getYLabels(1));
904 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: null }}});
905 assertEquals(["1e-3","2e-3","2e-3","3e-3","3e-3","4e-3","4e-3"], Util
.getYLabels(1));
907 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 3 }}});
908 assertEquals(["0.005","0.006","0.006","0.007","0.007","0.008","0.008"], Util
.getYLabels(2));
909 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 4 }}});
910 assertEquals(["0.005","0.0055","0.006","0.0065","0.007","0.0075","0.008"], Util
.getYLabels(2));
911 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 5 }}});
912 assertEquals(["0.005","0.0055","0.006","0.0065","0.007","0.0075","0.008"], Util
.getYLabels(2));
913 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: null }}});
914 assertEquals(["5e-3","6e-3","6e-3","7e-3","7e-3","7e-3","8e-3"], Util
.getYLabels(2));
917 // digitsAfterDecimal is ignored for the x-axis.
918 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
919 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 3 }}});
920 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
921 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 4 }}});
922 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
923 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 5 }}});
924 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
925 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: null }}});
926 assertEquals(["0.006","0.007","0.008"], Util
.getXLabels());
930 * This test shows you can override digitsAfterDecimal on the axis level.
932 AxisLabelsTestCase
.prototype.testMaxNumberWidthPerAxis
= function() {
934 document
.getElementById("graph"),
936 "12401,12601,12804\n" +
937 "12402,12602,12803\n" +
938 "12403,12603,12802\n" +
939 "12404,12604,12801\n", {
946 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 4 }}});
947 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));
948 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 5 }}});
949 assertEquals(["12601","12601.5","12602","12602.5","12603","12603.5","12604"] , Util
.getYLabels(1));
950 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: null }}});
951 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));
953 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 4 }}});
954 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));
955 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 5 }}});
956 assertEquals(["12801","12801.5","12802","12802.5","12803","12803.5","12804"], Util
.getYLabels(2));
957 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: null }}});
958 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));
960 // maxNumberWidth is ignored for the x-axis.
961 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
962 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 4 }}});
963 assertEquals(["12401","12402","12403"], Util
.getXLabels());
964 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 5 }}});
965 assertEquals(["12401","12402","12403"], Util
.getXLabels());
966 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: null }}});
967 assertEquals(["12401","12402","12403"], Util
.getXLabels());
971 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=147
972 // Checks that axis labels stay sane across a DST change.
973 AxisLabelsTestCase.prototype.testLabelsCrossDstChange = function() {
974 // (From tests/daylight-savings.html)
976 document.getElementById("graph"),
977 "Date/Time,Purchases\n" +
978 "2010-11-05 00:00:00,167082\n" +
979 "2010-11-06 00:00:00,168571\n" +
980 "2010-11-07 00:00:00,177796\n" +
981 "2010-11-08 00:00:00,165587\n" +
982 "2010-11-09 00:00:00,164380\n",
986 // Dates and "nice" hours: 6AM/PM and noon, not 5AM/11AM/...
998 var xLabels = Util.getXLabels();
999 for (var i = 0; i < xLabels.length; i++) {
1000 assertTrue(okLabels[xLabels[i]]);
1003 // This range had issues of its own on tests/daylight-savings.html.
1005 dateWindow: [1289109997722.8127, 1289261208937.7659]
1007 xLabels = Util.getXLabels();
1008 for (var i = 0; i < xLabels.length; i++) {
1009 assertTrue(okLabels[xLabels[i]]);
1014 // Tests data which crosses a "fall back" at a high enough frequency that you
1015 // can see both 1:00 A.M.s.
1016 AxisLabelsTestCase.prototype.testLabelsCrossDstChangeHighFreq = function() {
1017 // Generate data which crosses the EST/EDT boundary.
1019 var base_ms = 1383454200000;
1020 for (var x = base_ms; x < base_ms + 1000 * 60 * 80; x += 1000) {
1021 dst_data.push([new Date(x), x]);
1024 var g = new Dygraph(
1025 document.getElementById("graph"),
1027 { width: 1024, labels: ['Date', 'Value'] }
1032 '01:00', '01:05', '01:10', '01:15', '01:20', '01:25',
1033 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
1034 '01:00', '01:05' // 1 AM number two!
1035 ], Util.getXLabels());
1037 // Now zoom past the initial 1 AM. This used to cause trouble.
1039 dateWindow: [1383454200000 + 15*60*1000, g.xAxisExtremes()[1]]}
1042 '01:05', '01:10', '01:15', '01:20', '01:25',
1043 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
1044 '01:00', '01:05' // 1 AM number two!
1045 ], Util.getXLabels());
1049 // Tests data which crosses a "spring forward" at a low frequency.
1050 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=433
1051 AxisLabelsTestCase.prototype.testLabelsCrossSpringForward = function() {
1052 var g = new Dygraph(
1053 document.getElementById("graph"),
1054 "Date/Time,Purchases\n" +
1055 "2011-03-11 00:00:00,167082\n" +
1056 "2011-03-12 00:00:00,168571\n" +
1057 "2011-03-13 00:00:00,177796\n" +
1058 "2011-03-14 00:00:00,165587\n" +
1059 "2011-03-15 00:00:00,164380\n",
1062 dateWindow: [1299989043119.4365, 1300080693627.4866]
1067 // '02:00': true, // not a real time!
1081 var xLabels = Util.getXLabels();
1082 for (var i = 0; i < xLabels.length; i++) {
1083 assertTrue(okLabels[xLabels[i]]);
1087 AxisLabelsTestCase.prototype.testLabelsCrossSpringForwardHighFreq = function() {
1088 var base_ms_spring = 1299999000000;
1089 var dst_data_spring = [];
1090 for (var x = base_ms_spring; x < base_ms_spring + 1000 * 60 * 80; x += 1000) {
1091 dst_data_spring.push([new Date(x), x]);
1094 var g = new Dygraph(
1095 document.getElementById("graph"),
1097 { width: 1024, labels: ['Date', 'Value'] }
1102 '03:00', '03:05', '03:10', '03:15', '03:20', '03:25',
1103 '03:30', '03:35', '03:40', '03:45', '03:50', '03:55',
1105 ], Util.getXLabels());