From: Joan Pau Beltran Date: Thu, 30 Oct 2014 12:44:19 +0000 (-0400) Subject: Switch to full year in date tick labels. X-Git-Tag: v1.1.0~31^2~10 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=128f6d5460fc0c544f4ee40a3f972fdcdbb5fdaf;p=dygraphs.git Switch to full year in date tick labels. Use the full year in date tick labels ('Apr 2008'), instead of only the last two digits ('Apr 08'). Adapt the date ticker test suite for the new label format. --- diff --git a/auto_tests/tests/date_ticker.js b/auto_tests/tests/date_ticker.js index a23a326..e30a4ff 100644 --- a/auto_tests/tests/date_ticker.js +++ b/auto_tests/tests/date_ticker.js @@ -79,11 +79,11 @@ DateTickerTestCase.prototype.testAllDateTickers = function() { assertEquals([{"v":-1577923200000,"label":"1920"},{"v":-1262304000000,"label":"1930"},{"v":-946771200000,"label":"1940"},{"v":-631152000000,"label":"1950"},{"v":-315619200000,"label":"1960"},{"v":0,"label":"1970"},{"v":315532800000,"label":"1980"},{"v":631152000000,"label":"1990"},{"v":946684800000,"label":"2000"}], Dygraph.dateTicker(-1797552000000, 1255561200000, 800, options)); assertEquals([{"v":-5364662400000,"label":"1800"},{"v":-2208988800000,"label":"1900"}], Dygraph.dateTicker(-6122044800000, 189302400000, 480, options)); assertEquals([{"v":1041120000000,"label":"29Dec"},{"v":1041724800000,"label":"05Jan"},{"v":1042329600000,"label":"12Jan"},{"v":1042934400000,"label":"19Jan"},{"v":1043539200000,"label":"26Jan"},{"v":1044144000000,"label":"02Feb"},{"v":1044748800000,"label":"09Feb"},{"v":1045353600000,"label":"16Feb"}], Dygraph.dateTicker(1041120000000, 1045353600000, 640, options)); - assertEquals([{"v":1041379200000,"label":"Jan 03"},{"v":1072915200000,"label":"Jan 04"},{"v":1104537600000,"label":"Jan 05"},{"v":1136073600000,"label":"Jan 06"},{"v":1167609600000,"label":"Jan 07"},{"v":1199145600000,"label":"Jan 08"},{"v":1230768000000,"label":"Jan 09"},{"v":1262304000000,"label":"Jan 10"},{"v":1293840000000,"label":"Jan 11"}], Dygraph.dateTicker(1041120000000, 1307833200000, 800, options)); + assertEquals([{"v":1041379200000,"label":"Jan 2003"},{"v":1072915200000,"label":"Jan 2004"},{"v":1104537600000,"label":"Jan 2005"},{"v":1136073600000,"label":"Jan 2006"},{"v":1167609600000,"label":"Jan 2007"},{"v":1199145600000,"label":"Jan 2008"},{"v":1230768000000,"label":"Jan 2009"},{"v":1262304000000,"label":"Jan 2010"},{"v":1293840000000,"label":"Jan 2011"}], Dygraph.dateTicker(1041120000000, 1307833200000, 800, options)); assertEquals([{"v":1159660800000,"label":"01Oct"},{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"}], Dygraph.dateTicker(1159657200000, 1162252800000, 480, options)); assertEquals([{"v":1159660800000,"label":"01Oct"},{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"}], Dygraph.dateTicker(1159657200000, 1162252800000, 640, options)); assertEquals([{"v":1159660800000,"label":"01Oct"},{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"},{"v":1162684800000,"label":"05Nov"},{"v":1163289600000,"label":"12Nov"},{"v":1163894400000,"label":"19Nov"},{"v":1164499200000,"label":"26Nov"}], Dygraph.dateTicker(1159657200000, 1164758400000, 1150, options)); - assertEquals([{"v":1159660800000,"label":"Oct 06"},{"v":1162339200000,"label":"Nov 06"}], Dygraph.dateTicker(1159657200000, 1164758400000, 400, options)); + assertEquals([{"v":1159660800000,"label":"Oct 2006"},{"v":1162339200000,"label":"Nov 2006"}], Dygraph.dateTicker(1159657200000, 1164758400000, 400, options)); assertEquals([{"v":1159660800000,"label":"01Oct"},{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"},{"v":1162684800000,"label":"05Nov"},{"v":1163289600000,"label":"12Nov"},{"v":1163894400000,"label":"19Nov"},{"v":1164499200000,"label":"26Nov"}], Dygraph.dateTicker(1159657200000, 1164758400000, 500, options)); assertEquals([{"v":1159660800000,"label":"01Oct"},{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"},{"v":1162684800000,"label":"05Nov"},{"v":1163289600000,"label":"12Nov"},{"v":1163894400000,"label":"19Nov"},{"v":1164499200000,"label":"26Nov"}], Dygraph.dateTicker(1159657200000, 1164758400000, 600, options)); assertEquals([{"v":1160265600000,"label":"08Oct"},{"v":1160870400000,"label":"15Oct"},{"v":1161475200000,"label":"22Oct"},{"v":1162080000000,"label":"29Oct"},{"v":1162684800000,"label":"05Nov"},{"v":1163289600000,"label":"12Nov"}], Dygraph.dateTicker(1160243979962, 1163887694248, 600, options)); @@ -93,20 +93,20 @@ DateTickerTestCase.prototype.testAllDateTickers = function() { assertEquals([{"v":1161561600000,"label":"23Oct"},{"v":1161583200000,"label":"06:00"},{"v":1161604800000,"label":"12:00"},{"v":1161626400000,"label":"18:00"}], Dygraph.dateTicker(1161557878860, 1161642991675, 600, options)); assertEquals([{"v":1161756000000,"label":"06:00"},{"v":1161759600000,"label":"07:00"},{"v":1161763200000,"label":"08:00"},{"v":1161766800000,"label":"09:00"},{"v":1161770400000,"label":"10:00"},{"v":1161774000000,"label":"11:00"},{"v":1161777600000,"label":"12:00"}], Dygraph.dateTicker(1161752537840, 1161777663332, 600, options)); assertEquals([{"v":1167609600000,"label":"01Jan"},{"v":1167696000000,"label":"02Jan"},{"v":1167782400000,"label":"03Jan"},{"v":1167868800000,"label":"04Jan"},{"v":1167955200000,"label":"05Jan"},{"v":1168041600000,"label":"06Jan"},{"v":1168128000000,"label":"07Jan"},{"v":1168214400000,"label":"08Jan"},{"v":1168300800000,"label":"09Jan"}], Dygraph.dateTicker(1167609600000, 1168300800000, 480, options)); - assertEquals([{"v":1167609600000,"label":"Jan 07"}], Dygraph.dateTicker(1167609600000, 1199059200000, 100, options)); - assertEquals([{"v":1167609600000,"label":"Jan 07"},{"v":1175385600000,"label":"Apr 07"},{"v":1183248000000,"label":"Jul 07"},{"v":1191196800000,"label":"Oct 07"}], Dygraph.dateTicker(1167609600000, 1199059200000, 300, options)); - assertEquals([{"v":1167609600000,"label":"Jan 07"},{"v":1175385600000,"label":"Apr 07"},{"v":1183248000000,"label":"Jul 07"},{"v":1191196800000,"label":"Oct 07"}], Dygraph.dateTicker(1167609600000, 1199059200000, 480, options)); - assertEquals([{"v":1167609600000,"label":"Jan 07"},{"v":1175385600000,"label":"Apr 07"},{"v":1183248000000,"label":"Jul 07"},{"v":1191196800000,"label":"Oct 07"}], Dygraph.dateTicker(1167609600000, 1199059200000, 600, options)); + assertEquals([{"v":1167609600000,"label":"Jan 2007"}], Dygraph.dateTicker(1167609600000, 1199059200000, 100, options)); + assertEquals([{"v":1167609600000,"label":"Jan 2007"},{"v":1175385600000,"label":"Apr 2007"},{"v":1183248000000,"label":"Jul 2007"},{"v":1191196800000,"label":"Oct 2007"}], Dygraph.dateTicker(1167609600000, 1199059200000, 300, options)); + assertEquals([{"v":1167609600000,"label":"Jan 2007"},{"v":1175385600000,"label":"Apr 2007"},{"v":1183248000000,"label":"Jul 2007"},{"v":1191196800000,"label":"Oct 2007"}], Dygraph.dateTicker(1167609600000, 1199059200000, 480, options)); + assertEquals([{"v":1167609600000,"label":"Jan 2007"},{"v":1175385600000,"label":"Apr 2007"},{"v":1183248000000,"label":"Jul 2007"},{"v":1191196800000,"label":"Oct 2007"}], Dygraph.dateTicker(1167609600000, 1199059200000, 600, options)); assertEquals([{"v":1160870400000,"label":"15Oct"}], Dygraph.dateTicker(1160521200000, 1161298800000, 480, options)); - assertEquals([{"v":1167609600000,"label":"Jan 07"},{"v":1170288000000,"label":"Feb 07"},{"v":1172707200000,"label":"Mar 07"},{"v":1175385600000,"label":"Apr 07"},{"v":1177977600000,"label":"May 07"},{"v":1180656000000,"label":"Jun 07"},{"v":1183248000000,"label":"Jul 07"},{"v":1185926400000,"label":"Aug 07"},{"v":1188604800000,"label":"Sep 07"},{"v":1191196800000,"label":"Oct 07"},{"v":1193875200000,"label":"Nov 07"},{"v":1196467200000,"label":"Dec 07"}], Dygraph.dateTicker(1167609600000, 1199059200000, 800, options)); + assertEquals([{"v":1167609600000,"label":"Jan 2007"},{"v":1170288000000,"label":"Feb 2007"},{"v":1172707200000,"label":"Mar 2007"},{"v":1175385600000,"label":"Apr 2007"},{"v":1177977600000,"label":"May 2007"},{"v":1180656000000,"label":"Jun 2007"},{"v":1183248000000,"label":"Jul 2007"},{"v":1185926400000,"label":"Aug 2007"},{"v":1188604800000,"label":"Sep 2007"},{"v":1191196800000,"label":"Oct 2007"},{"v":1193875200000,"label":"Nov 2007"},{"v":1196467200000,"label":"Dec 2007"}], Dygraph.dateTicker(1167609600000, 1199059200000, 800, options)); - assertEquals([{"v":1293840000000,"label":"Jan 11"},{"v":1296518400000,"label":"Feb 11"},{"v":1298937600000,"label":"Mar 11"},{"v":1301616000000,"label":"Apr 11"},{"v":1304208000000,"label":"May 11"},{"v":1306886400000,"label":"Jun 11"},{"v":1309478400000,"label":"Jul 11"},{"v":1312156800000,"label":"Aug 11"}], Dygraph.dateTicker(1293753600000, 1312844400000, 727, options)); + assertEquals([{"v":1293840000000,"label":"Jan 2011"},{"v":1296518400000,"label":"Feb 2011"},{"v":1298937600000,"label":"Mar 2011"},{"v":1301616000000,"label":"Apr 2011"},{"v":1304208000000,"label":"May 2011"},{"v":1306886400000,"label":"Jun 2011"},{"v":1309478400000,"label":"Jul 2011"},{"v":1312156800000,"label":"Aug 2011"}], Dygraph.dateTicker(1293753600000, 1312844400000, 727, options)); assertEquals([{"v":1201824000000,"label":"01Feb"},{"v":1201910400000,"label":"02Feb"},{"v":1201996800000,"label":"03Feb"},{"v":1202083200000,"label":"04Feb"},{"v":1202169600000,"label":"05Feb"},{"v":1202256000000,"label":"06Feb"}], Dygraph.dateTicker(1201824000000, 1202256000000, 700, options)); assertEquals([{"v":1210118400000,"label":"07May"},{"v":1210140000000,"label":"06:00"},{"v":1210161600000,"label":"12:00"},{"v":1210183200000,"label":"18:00"},{"v":1210204800000,"label":"08May"},{"v":1210226400000,"label":"06:00"},{"v":1210248000000,"label":"12:00"},{"v":1210269600000,"label":"18:00"},{"v":1210291200000,"label":"09May"}], Dygraph.dateTicker(1210114800000, 1210291200000, 480, options)); assertEquals([{"v":1210118400000,"label":"07May"},{"v":1210204800000,"label":"08May"},{"v":1210291200000,"label":"09May"},{"v":1210377600000,"label":"10May"},{"v":1210464000000,"label":"11May"}], Dygraph.dateTicker(1210114800000, 1210464000000, 480, options)); assertEquals([{"v":1210118400000,"label":"07May"},{"v":1210204800000,"label":"08May"},{"v":1210291200000,"label":"09May"},{"v":1210377600000,"label":"10May"},{"v":1210464000000,"label":"11May"},{"v":1210550400000,"label":"12May"}], Dygraph.dateTicker(1210114800000, 1210550400000, 480, options)); assertEquals([{"v":1214870400000,"label":"01Jul"},{"v":1214872200000,"label":"00:30"},{"v":1214874000000,"label":"01:00"},{"v":1214875800000,"label":"01:30"}], Dygraph.dateTicker(1214870400000, 1214877599000, 600, options)); - assertEquals([{"v":1214870400000,"label":"Jul 08"},{"v":1217548800000,"label":"Aug 08"},{"v":1220227200000,"label":"Sep 08"}], Dygraph.dateTicker(1214866800000, 1222747200000, 600, options)); + assertEquals([{"v":1214870400000,"label":"Jul 2008"},{"v":1217548800000,"label":"Aug 2008"},{"v":1220227200000,"label":"Sep 2008"}], Dygraph.dateTicker(1214866800000, 1222747200000, 600, options)); assertEquals([{"v":1215820800000,"label":"12Jul"},{"v":1215842400000,"label":"06:00"},{"v":1215864000000,"label":"12:00"},{"v":1215885600000,"label":"18:00"},{"v":1215907200000,"label":"13Jul"},{"v":1215928800000,"label":"06:00"},{"v":1215950400000,"label":"12:00"},{"v":1215972000000,"label":"18:00"}], Dygraph.dateTicker(1215817200000, 1215989940000, 600, options)); assertEquals([{"v":1246752000000,"label":"05Jul"},{"v":1247356800000,"label":"12Jul"},{"v":1247961600000,"label":"19Jul"}], Dygraph.dateTicker(1246402800000, 1248217200000, 600, options)); assertEquals([{"v":1246752000000,"label":"05Jul"},{"v":1247356800000,"label":"12Jul"},{"v":1247961600000,"label":"19Jul"},{"v":1248566400000,"label":"26Jul"},{"v":1249171200000,"label":"02Aug"}], Dygraph.dateTicker(1246402800000, 1249340400000, 600, options)); @@ -118,7 +118,7 @@ DateTickerTestCase.prototype.testAllDateTickers = function() { assertEquals([{"v":1259625600000,"label":"01Dec"},{"v":1259712000000,"label":"02Dec"},{"v":1259798400000,"label":"03Dec"},{"v":1259884800000,"label":"04Dec"},{"v":1259971200000,"label":"05Dec"},{"v":1260057600000,"label":"06Dec"},{"v":1260144000000,"label":"07Dec"}], Dygraph.dateTicker(1259625600000, 1260144000000, 480, options)); assertEquals([{"v":1259625600000,"label":"01Dec"},{"v":1259712000000,"label":"02Dec"},{"v":1259798400000,"label":"03Dec"},{"v":1259884800000,"label":"04Dec"},{"v":1259971200000,"label":"05Dec"},{"v":1260057600000,"label":"06Dec"},{"v":1260144000000,"label":"07Dec"}], Dygraph.dateTicker(1259625600000, 1260144000000, 600, options)); assertEquals([{"v":1260057600000,"label":"06Dec"},{"v":1260662400000,"label":"13Dec"},{"v":1261267200000,"label":"20Dec"},{"v":1261872000000,"label":"27Dec"},{"v":1262476800000,"label":"03Jan"},{"v":1263081600000,"label":"10Jan"},{"v":1263686400000,"label":"17Jan"},{"v":1264291200000,"label":"24Jan"}], Dygraph.dateTicker(1260057600000, 1264291200000, 640, options)); - assertEquals([{"v":1262304000000,"label":"Jan 10"},{"v":1264982400000,"label":"Feb 10"},{"v":1267401600000,"label":"Mar 10"},{"v":1270080000000,"label":"Apr 10"}], Dygraph.dateTicker(1262304000000, 1270857600000, 640, options)); + assertEquals([{"v":1262304000000,"label":"Jan 2010"},{"v":1264982400000,"label":"Feb 2010"},{"v":1267401600000,"label":"Mar 2010"},{"v":1270080000000,"label":"Apr 2010"}], Dygraph.dateTicker(1262304000000, 1270857600000, 640, options)); assertEquals([{"v":1288915200000,"label":"05Nov"},{"v":1288936800000,"label":"06:00"},{"v":1288958400000,"label":"12:00"},{"v":1288980000000,"label":"18:00"},{"v":1289001600000,"label":"06Nov"},{"v":1289023200000,"label":"06:00"},{"v":1289044800000,"label":"12:00"},{"v":1289066400000,"label":"18:00"},{"v":1289088000000,"label":"07Nov"},{"v":1289109600000,"label":"06:00"},{"v":1289131200000,"label":"12:00"},{"v":1289152800000,"label":"18:00"},{"v":1289174400000,"label":"08Nov"},{"v":1289196000000,"label":"06:00"},{"v":1289217600000,"label":"12:00"},{"v":1289239200000,"label":"18:00"},{"v":1289260800000,"label":"09Nov"}], Dygraph.dateTicker(1288911600000, 1289260800000, 1024, options)); assertEquals([{"v":1291161600000,"label":"01Dec"},{"v":1291248000000,"label":"02Dec"},{"v":1291334400000,"label":"03Dec"},{"v":1291420800000,"label":"04Dec"},{"v":1291507200000,"label":"05Dec"},{"v":1291593600000,"label":"06Dec"},{"v":1291680000000,"label":"07Dec"},{"v":1291766400000,"label":"08Dec"},{"v":1291852800000,"label":"09Dec"}], Dygraph.dateTicker(1291161600000, 1291852800000, 600, options)); assertEquals([{"v":1294358400000,"label":"07Jan"},{"v":1294444800000,"label":"08Jan"},{"v":1294531200000,"label":"09Jan"},{"v":1294617600000,"label":"10Jan"},{"v":1294704000000,"label":"11Jan"},{"v":1294790400000,"label":"12Jan"},{"v":1294876800000,"label":"13Jan"},{"v":1294963200000,"label":"14Jan"}], Dygraph.dateTicker(1294358400000, 1294963200000, 480, options)); @@ -246,5 +246,5 @@ DateTickerTestCase.prototype.testAllDateTickers = function() { assertEquals([{"v":1307908020000,"label":"19:47"},{"v":1307908050000,"label":"19:47:30"},{"v":1307908080000,"label":"19:48"},{"v":1307908110000,"label":"19:48:30"},{"v":1307908140000,"label":"19:49"},{"v":1307908170000,"label":"19:49:30"}], Dygraph.dateTicker(1307908000112, 1307908171258, 800, options)); assertEquals([{"v":1307908020000,"label":"19:47"},{"v":1307908050000,"label":"19:47:30"},{"v":1307908080000,"label":"19:48"},{"v":1307908110000,"label":"19:48:30"},{"v":1307908140000,"label":"19:49"},{"v":1307908170000,"label":"19:49:30"}], Dygraph.dateTicker(1307908000112, 1307908172259, 800, options)); assertEquals([{"v":1307908020000,"label":"19:47"},{"v":1307908050000,"label":"19:47:30"},{"v":1307908080000,"label":"19:48"},{"v":1307908110000,"label":"19:48:30"},{"v":1307908140000,"label":"19:49"},{"v":1307908170000,"label":"19:49:30"}], Dygraph.dateTicker(1307908000112, 1307908173260, 800, options)); - assertEquals([{"v":978307200000,"label":"Jan 01"},{"v":986083200000,"label":"Apr 01"},{"v":993945600000,"label":"Jul 01"},{"v":1001894400000,"label":"Oct 01"}], Dygraph.dateTicker(978307200000, 1001894400000, 400, options)); + assertEquals([{"v":978307200000,"label":"Jan 2001"},{"v":986083200000,"label":"Apr 2001"},{"v":993945600000,"label":"Jul 2001"},{"v":1001894400000,"label":"Oct 2001"}], Dygraph.dateTicker(978307200000, 1001894400000, 400, options)); }; diff --git a/dygraph.js b/dygraph.js index 06d899a..2f17faa 100644 --- a/dygraph.js +++ b/dygraph.js @@ -233,9 +233,8 @@ Dygraph.dateAxisLabelFormatter = function(date, granularity, opts) { if (granularity >= Dygraph.DECADAL) { return '' + year; } else if (granularity >= Dygraph.MONTHLY) { - return Dygraph.SHORT_MONTH_NAMES_[month] + ' ' + Dygraph.zeropad(year % 100); + return Dygraph.SHORT_MONTH_NAMES_[month] + ' ' + Dygraph.zeropad(year); } else { - // 1e-3 factor on millis missing in original implementation var frac = hours * 3600 + mins * 60 + secs + 1e-3 * millis; if (frac === 0 || granularity >= Dygraph.DAILY) { // e.g. '21Jan' (%d%b)