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.08, -0.06, -0.04, -0.02, 0, 0.02, 0.04, 0.06, 0.08],
78 Util
.makeNumbers(Util
.getYLabels()), this.kCloseFloat
);
80 opts
.valueRange
= [-0.05, 0.05];
81 g
.updateOptions(opts
);
82 assertEquals([-0.05, -0.04, -0.03, -0.02, -0.01, 0, 0.01, 0.02, 0.03, 0.04],
83 Util
.makeNumbers(Util
.getYLabels()));
85 opts
.valueRange
= [-0.01, 0.01];
86 g
.updateOptions(opts
);
87 assertEquals([-0.01, -8.00e-3, -6.00e-3, -4.00e-3, -2.00e-3, 0, 2.00e-3, 4.00e-3, 6.00e-3, 8.00e-3],
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","10","10","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','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util
.getYLabels());
195 assertEquals("2: y: 4", Util
.getLegend());
198 AxisLabelsTestCase
.prototype.testDateAxisLabelFormatter
= function () {
204 axisLabelFormatter
: function(x
, granularity
, opts
, dg
) {
205 assertTrue(Dygraph
.isDateLike(x
));
206 assertEquals('number', typeof(granularity
));
207 assertEquals('function', typeof(opts
));
208 assertEquals('[Dygraph graph]', dg
.toString());
209 return 'x' + Util
.formatDate(x
);
213 axisLabelFormatter
: function(y
, granularity
, opts
, dg
) {
214 assertEquals('number', typeof(y
));
215 assertEquals('number', typeof(granularity
));
216 assertEquals('function', typeof(opts
));
217 assertEquals('[Dygraph graph]', dg
.toString());
225 for (var i
= 1; i
< 10; i
++) {
226 data
.push([new Date("2011/01/0" + i
), 2 * i
]);
228 var graph
= document
.getElementById("graph");
229 var g
= new Dygraph(graph
, data
, opts
);
231 assertEquals(["x2011/01/01", "x2011/01/02", "x2011/01/03", "x2011/01/04", "x2011/01/05", "x2011/01/06", "x2011/01/07", "x2011/01/08"], Util
.getXLabels());
232 assertEquals(['y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util
.getYLabels());
235 assertEquals("2011/01/01: y: 2", Util
.getLegend());
238 // This test verifies that when a valueFormatter is set (but not an
239 // axisLabelFormatter), then the valueFormatter is used to format the axis
241 AxisLabelsTestCase
.prototype.testValueFormatter
= function () {
247 valueFormatter
: function(x
, opts
, series_name
, dg
) {
248 assertEquals('number', typeof(x
));
249 assertEquals('function', typeof(opts
));
250 assertEquals('string', typeof(series_name
));
251 assertEquals('[Dygraph graph]', dg
.toString());
256 valueFormatter
: function(y
, opts
, series_name
, dg
) {
257 assertEquals('number', typeof(y
));
258 assertEquals('function', typeof(opts
));
259 assertEquals('string', typeof(series_name
));
260 assertEquals('[Dygraph graph]', dg
.toString());
268 for (var i
= 0; i
< 10; i
++) {
269 data
.push([i
, 2 * i
]);
271 var graph
= document
.getElementById("graph");
272 var g
= new Dygraph(graph
, data
, opts
);
274 // the valueFormatter options do not affect the ticks.
275 assertEquals(['0','2','4','6','8'], Util
.getXLabels());
276 assertEquals(['0','2','4','6','8','10','12','14','16','18'],
279 // they do affect the legend, however.
281 assertEquals("x2: y: y4", Util
.getLegend());
284 AxisLabelsTestCase
.prototype.testDateValueFormatter
= function () {
290 valueFormatter
: function(x
, opts
, series_name
, dg
) {
291 assertEquals('number', typeof(x
));
292 assertEquals('function', typeof(opts
));
293 assertEquals('string', typeof(series_name
));
294 assertEquals('[Dygraph graph]', dg
.toString());
295 return 'x' + Util
.formatDate(x
);
299 valueFormatter
: function(y
, opts
, series_name
, dg
) {
300 assertEquals('number', typeof(y
));
301 assertEquals('function', typeof(opts
));
302 assertEquals('string', typeof(series_name
));
303 assertEquals('[Dygraph graph]', dg
.toString());
312 for (var i
= 1; i
< 10; i
++) {
313 data
.push([new Date("2011/01/0" + i
), 2 * i
]);
315 var graph
= document
.getElementById("graph");
316 var g
= new Dygraph(graph
, data
, opts
);
318 // valueFormatters do not affect ticks.
319 assertEquals(['01Jan','02Jan','03Jan','04Jan','05Jan','06Jan','07Jan','08Jan'], Util
.getXLabels());
320 assertEquals(['2','4','6','8','10','12','14','16','18'], Util
.getYLabels());
322 // the valueFormatter options also affect the legend.
324 assertEquals('x2011/01/03: y: y6', Util
.getLegend());
327 // This test verifies that when both a valueFormatter and an axisLabelFormatter
328 // are specified, the axisLabelFormatter takes precedence.
329 AxisLabelsTestCase
.prototype.testAxisLabelFormatterPrecedence
= function () {
335 valueFormatter
: function(x
) {
338 axisLabelFormatter
: function(x
, granularity
) {
343 valueFormatter
: function(y
) {
346 axisLabelFormatter
: function(y
) {
354 for (var i
= 0; i
< 10; i
++) {
355 data
.push([i
, 2 * i
]);
357 var graph
= document
.getElementById("graph");
358 var g
= new Dygraph(graph
, data
, opts
);
360 assertEquals(['x0','x2','x4','x6','x8'], Util
.getXLabels());
361 assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util
.getYLabels());
364 assertEquals("xvf9: y: yvf18", Util
.getLegend());
367 // This is the same as the previous test, except that options are added
369 AxisLabelsTestCase
.prototype.testAxisLabelFormatterIncremental
= function () {
376 for (var i
= 0; i
< 10; i
++) {
377 data
.push([i
, 2 * i
]);
379 var graph
= document
.getElementById("graph");
380 var g
= new Dygraph(graph
, data
, opts
);
384 valueFormatter
: function(x
) {
393 valueFormatter
: function(y
) {
402 axisLabelFormatter
: function(x
, granularity
) {
411 axisLabelFormatter
: function(y
) {
418 assertEquals(["x0","x2","x4","x6","x8"], Util
.getXLabels());
419 assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], Util
.getYLabels());
422 assertEquals("xvf9: y: yvf18", Util
.getLegend());
425 AxisLabelsTestCase
.prototype.testGlobalFormatters
= function() {
430 valueFormatter
: function(x
) {
433 axisLabelFormatter
: function(x
) {
438 for (var i
= 0; i
< 10; i
++) {
439 data
.push([i
, 2 * i
]);
441 var graph
= document
.getElementById("graph");
442 var g
= new Dygraph(graph
, data
, opts
);
444 assertEquals(['alf0','alf2','alf4','alf6','alf8'], Util
.getXLabels());
445 assertEquals(['alf0','alf2','alf4','alf6','alf8','alf10','alf12','alf14','alf16','alf18'], Util
.getYLabels());
448 assertEquals("vf9: y: vf18", Util
.getLegend());
451 AxisLabelsTestCase
.prototype.testSeriesOrder
= function() {
456 var data
= "x,00,01,10,11\n" +
457 "0,101,201,301,401\n" +
458 "1,102,202,302,402\n" +
459 "2,103,203,303,403\n" +
460 "3,104,204,304,404\n"
463 var graph
= document
.getElementById("graph");
464 var g
= new Dygraph(graph
, data
, opts
);
467 assertEquals('2: 00: 103 01: 203 10: 303 11: 403', Util
.getLegend());
469 // Sanity checks for indexFromSetName
470 assertEquals(0, g
.indexFromSetName("x"));
471 assertEquals(1, g
.indexFromSetName("00"));
472 assertEquals(null, g
.indexFromSetName("abcde"));
474 // Verify that we get the label list back in the right order
475 assertEquals(["x", "00", "01", "10", "11"], g
.getLabels());
478 AxisLabelsTestCase
.prototype.testLabelKMB
= function() {
485 document
.getElementById("graph"),
488 labels
: [ 'X', 'bar' ],
497 assertEquals(["0", "500", "1K", "1.5K", "2K"], Util
.getYLabels());
500 AxisLabelsTestCase
.prototype.testLabelKMG2
= function() {
507 document
.getElementById("graph"),
510 labels
: [ 'X', 'bar' ],
520 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
524 // Same as testLabelKMG2 but specifies the option at the
525 // top of the option dictionary.
526 AxisLabelsTestCase
.prototype.testLabelKMG2_top
= function() {
533 document
.getElementById("graph"),
536 labels
: [ 'X', 'bar' ],
542 ["0","256","512","768","1k","1.25k","1.5k","1.75k","2k"],
547 * Verify that log scale axis range is properly specified.
549 AxisLabelsTestCase
.prototype.testLogScale
= function() {
550 var g
= new Dygraph("graph", [[0, 5], [1, 1000]], { logscale
: true });
551 var nonEmptyLabels
= Util
.getYLabels().filter(function(x
) { return x
.length
> 0; });
552 assertEquals(["6","10","30","60","100","300","600","1000"], nonEmptyLabels
);
554 g
.updateOptions({ logscale
: false });
555 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
559 * Verify that include zero range is properly specified.
561 AxisLabelsTestCase
.prototype.testIncludeZero
= function() {
562 var g
= new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero
: true });
563 assertEquals(['0','200','400','600','800','1000'], Util
.getYLabels());
565 g
.updateOptions({ includeZero
: false });
566 assertEquals(['500','600','700','800','900','1000'], Util
.getYLabels());
569 AxisLabelsTestCase
.prototype.testAxisLabelFontSize
= function() {
570 var graph
= document
.getElementById("graph");
571 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
573 // Be sure we're dealing with a 14-point default.
574 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
576 var assertFontSize
= function(selector
, expected
) {
577 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
580 assertFontSize($(".dygraph-axis-label-x"), "14px");
581 assertFontSize($(".dygraph-axis-label-y") , "14px");
583 g
.updateOptions({ axisLabelFontSize
: 8});
584 assertFontSize($(".dygraph-axis-label-x"), "8px");
585 assertFontSize($(".dygraph-axis-label-y"), "8px");
588 axisLabelFontSize
: null,
590 x
: { axisLabelFontSize
: 5 },
594 assertFontSize($(".dygraph-axis-label-x"), "5px");
595 assertFontSize($(".dygraph-axis-label-y"), "14px");
599 y
: { axisLabelFontSize
: 20 },
603 assertFontSize($(".dygraph-axis-label-x"), "5px");
604 assertFontSize($(".dygraph-axis-label-y"), "20px");
608 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
611 y2
: { axisLabelFontSize
: 12 },
615 assertFontSize($(".dygraph-axis-label-x"), "5px");
616 assertFontSize($(".dygraph-axis-label-y1"), "20px");
617 assertFontSize($(".dygraph-axis-label-y2"), "12px");
620 AxisLabelsTestCase
.prototype.testAxisLabelFontSizeNull
= function() {
621 var graph
= document
.getElementById("graph");
622 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
624 axisLabelFontSize
: null
627 var assertFontSize
= function(selector
, expected
) {
628 Util
.assertStyleOfChildren(selector
, "font-size", expected
);
631 // Be sure we're dealing with a 14-point default.
632 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
634 assertFontSize($(".dygraph-axis-label-x"), "14px");
635 assertFontSize($(".dygraph-axis-label-y"), "14px");
638 AxisLabelsTestCase
.prototype.testAxisLabelColor
= function() {
639 var graph
= document
.getElementById("graph");
640 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
, {});
642 // Be sure we're dealing with a black default.
643 assertEquals("black", Dygraph
.DEFAULT_ATTRS
.axisLabelColor
);
645 var assertColor
= function(selector
, expected
) {
646 Util
.assertStyleOfChildren(selector
, "color", expected
);
649 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
650 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
652 g
.updateOptions({ axisLabelColor
: "red"});
653 assertColor($(".dygraph-axis-label-x"), "rgb(255, 0, 0)");
654 assertColor($(".dygraph-axis-label-y"), "rgb(255, 0, 0)");
657 axisLabelColor
: null,
659 x
: { axisLabelColor
: "blue" },
663 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
664 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
668 y
: { axisLabelColor
: "green" },
672 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
673 assertColor($(".dygraph-axis-label-y"), "rgb(0, 128, 0)");
677 Y2
: { axis
: "y2" } // copy y2 series to y2 axis.
680 y2
: { axisLabelColor
: "yellow" },
684 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 255)");
685 assertColor($(".dygraph-axis-label-y1"), "rgb(0, 128, 0)");
686 assertColor($(".dygraph-axis-label-y2"), "rgb(255, 255, 0)");
689 AxisLabelsTestCase
.prototype.testAxisLabelColorNull
= function() {
690 var graph
= document
.getElementById("graph");
691 var g
= new Dygraph(graph
, AxisLabelsTestCase
.simpleData
,
696 var assertColor
= function(selector
, expected
) {
697 Util
.assertStyleOfChildren(selector
, "color", expected
);
700 // Be sure we're dealing with a 14-point default.
701 assertEquals(14, Dygraph
.DEFAULT_ATTRS
.axisLabelFontSize
);
703 assertColor($(".dygraph-axis-label-x"), "rgb(0, 0, 0)");
704 assertColor($(".dygraph-axis-label-y"), "rgb(0, 0, 0)");
708 * This test shows that the label formatter overrides labelsKMB for all values.
710 AxisLabelsTestCase
.prototype.testLabelFormatterOverridesLabelsKMB
= function() {
712 document
.getElementById("graph"),
719 axisLabelFormatter
: function (v
) {
723 assertEquals(["0:X","500:X","1000:X","1500:X","2000:X"], Util
.getYLabels());
724 assertEquals(["1:X","1.5:X","2:X","2.5:X","3:X","3.5:X"], Util
.getXLabels());
728 * This test shows that you can override labelsKMB on the axis level.
730 AxisLabelsTestCase
.prototype.testLabelsKMBPerAxis
= function() {
732 document
.getElementById("graph"),
740 y2
: { labelsKMB
: true },
741 x
: { labelsKMB
: true }
748 // labelsKMB doesn't apply to the x axis. This value should be different.
749 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
750 assertEquals(["1000", "1500", "2000", "2500", "3000", "3500"], Util
.getXLabels());
751 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
752 assertEquals(["0","500","1K","1.5K","2K"], Util
.getYLabels(2));
756 * This test shows that you can override labelsKMG2 on the axis level.
758 AxisLabelsTestCase
.prototype.testLabelsKMBG2IPerAxis
= function() {
760 document
.getElementById("graph"),
768 y2
: { labelsKMG2
: true },
769 x
: { labelsKMG2
: true }
776 // It is weird that labelsKMG2 does something on the x axis but KMB does not.
777 // Plus I can't be sure they're doing the same thing as they're done in different
779 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
780 assertEquals(["1024","1536","2048","2560","3072","3584"], Util
.getXLabels());
781 assertEquals( ["0","500","1000","1500","2000"], Util
.getYLabels(1));
782 assertEquals(["0","500","1000","1.46k","1.95k"], Util
.getYLabels(2));
786 * This test shows you can override sigFigs on the axis level.
788 AxisLabelsTestCase
.prototype.testSigFigsPerAxis
= function() {
790 document
.getElementById("graph"),
806 // sigFigs doesn't apply to the x axis. This value should be different.
807 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
808 assertEquals(["1000","1500","2000","2500","3000","3500"], Util
.getXLabels());
809 assertEquals(["0.0","5.0e+2","1.0e+3","1.5e+3","2.0e+3"], Util
.getYLabels(1));
810 assertEquals(["0.00000","500.000","1000.00","1500.00","2000.00"], Util
.getYLabels(2));
814 * This test shows you can override digitsAfterDecimal on the axis level.
816 AxisLabelsTestCase
.prototype.testDigitsAfterDecimalPerAxis
= function() {
818 document
.getElementById("graph"),
820 "0.006,0.001,0.008\n" +
821 "0.007,0.002,0.007\n" +
822 "0.008,0.003,0.006\n" +
823 "0.009,0.004,0.005\n", {
824 digitsAfterDecimal
: 1,
831 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 3 }}});
832 assertEquals(["0.001","0.002","0.002","0.003","0.003","0.004","0.004"], Util
.getYLabels(1));
833 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 4 }}});
834 assertEquals(["0.001","0.0015","0.002","0.0025","0.003","0.0035","0.004"], Util
.getYLabels(1));
835 g
.updateOptions({ axes
: { y
: { digitsAfterDecimal
: 5 }}});
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
: null }}});
838 assertEquals(["1e-3","2e-3","2e-3","3e-3","3e-3","4e-3","4e-3"], Util
.getYLabels(1));
840 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 3 }}});
841 assertEquals(["0.005","0.006","0.006","0.007","0.007","0.008","0.008"], Util
.getYLabels(2));
842 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 4 }}});
843 assertEquals(["0.005","0.0055","0.006","0.0065","0.007","0.0075","0.008"], Util
.getYLabels(2));
844 g
.updateOptions({ axes
: { y2
: { digitsAfterDecimal
: 5 }}});
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
: null }}});
847 assertEquals(["5e-3","6e-3","6e-3","7e-3","7e-3","7e-3","8e-3"], Util
.getYLabels(2));
850 // digitsAfterDecimal is ignored for the x-axis.
851 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
852 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 3 }}});
853 assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util
.getXLabels());
854 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 4 }}});
855 assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util
.getXLabels());
856 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: 5 }}});
857 assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util
.getXLabels());
858 g
.updateOptions({ axes
: { x
: { digitsAfterDecimal
: null }}});
859 assertEquals(["0.006","0.006500000000000001","0.007","0.0075","0.008","0.0085"], Util
.getXLabels());
863 * This test shows you can override digitsAfterDecimal on the axis level.
865 AxisLabelsTestCase
.prototype.testMaxNumberWidthPerAxis
= function() {
867 document
.getElementById("graph"),
869 "12401,12601,12804\n" +
870 "12402,12602,12803\n" +
871 "12403,12603,12802\n" +
872 "12404,12604,12801\n", {
879 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 4 }}});
880 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));
881 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: 5 }}});
882 assertEquals(["12601","12601.5","12602","12602.5","12603","12603.5","12604"] , Util
.getYLabels(1));
883 g
.updateOptions({ axes
: { y
: { maxNumberWidth
: null }}});
884 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));
886 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 4 }}});
887 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));
888 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: 5 }}});
889 assertEquals(["12801","12801.5","12802","12802.5","12803","12803.5","12804"], Util
.getYLabels(2));
890 g
.updateOptions({ axes
: { y2
: { maxNumberWidth
: null }}});
891 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));
893 // maxNumberWidth is ignored for the x-axis.
894 // BUG : https://code.google.com/p/dygraphs/issues/detail
?id
=488
895 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 4 }}});
896 assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util
.getXLabels());
897 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: 5 }}});
898 assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util
.getXLabels());
899 g
.updateOptions({ axes
: { x
: { maxNumberWidth
: null }}});
900 assertEquals(["12401","12401.5","12402","12402.5","12403","12403.5"], Util
.getXLabels());
904 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=147
905 // Checks that axis labels stay sane across a DST change.
906 AxisLabelsTestCase.prototype.testLabelsCrossDstChange = function() {
907 // (From tests/daylight-savings.html)
909 document.getElementById("graph"),
910 "Date/Time,Purchases\n" +
911 "2010-11-05 00:00:00,167082\n" +
912 "2010-11-06 00:00:00,168571\n" +
913 "2010-11-07 00:00:00,177796\n" +
914 "2010-11-08 00:00:00,165587\n" +
915 "2010-11-09 00:00:00,164380\n",
919 // Dates and "nice" hours: 6AM/PM and noon, not 5AM/11AM/...
931 var xLabels = Util.getXLabels();
932 for (var i = 0; i < xLabels.length; i++) {
933 assertTrue(okLabels[xLabels[i]]);
936 // This range had issues of its own on tests/daylight-savings.html.
938 dateWindow: [1289109997722.8127, 1289261208937.7659]
940 xLabels = Util.getXLabels();
941 for (var i = 0; i < xLabels.length; i++) {
942 assertTrue(okLabels[xLabels[i]]);
947 // Tests data which crosses a "fall back" at a high enough frequency that you
948 // can see both 1:00 A.M.s.
949 AxisLabelsTestCase.prototype.testLabelsCrossDstChangeHighFreq = function() {
950 // Generate data which crosses the EST/EDT boundary.
952 var base_ms = 1383454200000;
953 for (var x = base_ms; x < base_ms + 1000 * 60 * 80; x += 1000) {
954 dst_data.push([new Date(x), x]);
958 document.getElementById("graph"),
960 { width: 1024, labels: ['Date', 'Value'] }
965 '01:00', '01:05', '01:10', '01:15', '01:20', '01:25',
966 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
967 '01:00', '01:05' // 1 AM number two!
968 ], Util.getXLabels());
970 // Now zoom past the initial 1 AM. This used to cause trouble.
972 dateWindow: [1383454200000 + 15*60*1000, g.xAxisExtremes()[1]]}
975 '01:05', '01:10', '01:15', '01:20', '01:25',
976 '01:30', '01:35', '01:40', '01:45', '01:50', '01:55',
977 '01:00', '01:05' // 1 AM number two!
978 ], Util.getXLabels());
982 // Tests data which crosses a "spring forward" at a low frequency.
983 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=433
984 AxisLabelsTestCase.prototype.testLabelsCrossSpringForward = function() {
986 document.getElementById("graph"),
987 "Date/Time,Purchases\n" +
988 "2011-03-11 00:00:00,167082\n" +
989 "2011-03-12 00:00:00,168571\n" +
990 "2011-03-13 00:00:00,177796\n" +
991 "2011-03-14 00:00:00,165587\n" +
992 "2011-03-15 00:00:00,164380\n",
995 dateWindow: [1299989043119.4365, 1300080693627.4866]
1000 // '02:00': true, // not a real time!
1014 var xLabels = Util.getXLabels();
1015 for (var i = 0; i < xLabels.length; i++) {
1016 assertTrue(okLabels[xLabels[i]]);
1020 AxisLabelsTestCase.prototype.testLabelsCrossSpringForwardHighFreq = function() {
1021 var base_ms_spring = 1299999000000;
1022 var dst_data_spring = [];
1023 for (var x = base_ms_spring; x < base_ms_spring + 1000 * 60 * 80; x += 1000) {
1024 dst_data_spring.push([new Date(x), x]);
1027 var g = new Dygraph(
1028 document.getElementById("graph"),
1030 { width: 1024, labels: ['Date', 'Value'] }
1035 '03:00', '03:05', '03:10', '03:15', '03:20', '03:25',
1036 '03:30', '03:35', '03:40', '03:45', '03:50', '03:55',
1038 ], Util.getXLabels());