/timeline/ext/geochrono/scripts/labellers.js
JavaScript | 52 lines | 43 code | 5 blank | 4 comment | 4 complexity | 0929b20611d5d653687d753e38412809 MD5 | raw file
1/*================================================== 2 * Geochrono Labeller 3 *================================================== 4 */ 5 6Timeline.GeochronoLabeller = function(locale) { 7 this._locale = locale; 8}; 9 10Timeline.GeochronoLabeller.eonNames = []; 11Timeline.GeochronoLabeller.eraNames = []; 12Timeline.GeochronoLabeller.periodNames = []; 13Timeline.GeochronoLabeller.epochNames = []; 14Timeline.GeochronoLabeller.ageNames = []; 15 16Timeline.GeochronoLabeller.prototype.labelInterval = function(date, intervalUnit) { 17 var n = Timeline.GeochronoUnit.toNumber(date); 18 var dates, names; 19 switch (intervalUnit) { 20 case Timeline.GeochronoUnit.AGE: 21 dates = Timeline.Geochrono.ages; 22 names = Timeline.GeochronoLabeller.ageNames; break; 23 case Timeline.GeochronoUnit.EPOCH: 24 dates = Timeline.Geochrono.epoches; 25 names = Timeline.GeochronoLabeller.epochNames; break; 26 case Timeline.GeochronoUnit.PERIOD: 27 dates = Timeline.Geochrono.periods; 28 names = Timeline.GeochronoLabeller.periodNames; break; 29 case Timeline.GeochronoUnit.ERA: 30 dates = Timeline.Geochrono.eras; 31 names = Timeline.GeochronoLabeller.eraNames; break; 32 case Timeline.GeochronoUnit.EON: 33 dates = Timeline.Geochrono.eons; 34 names = Timeline.GeochronoLabeller.eonNames; break; 35 default: 36 return { text: n, emphasized: false }; 37 } 38 39 for (var i = dates.length - 1; i >= 0; i--) { 40 if (n <= dates[i].start) { 41 return { 42 text: names[this._locale][i].name, 43 emphasized: n == dates[i].start 44 } 45 } 46 } 47 return { text: n, emphasized: false }; 48}; 49 50Timeline.GeochronoLabeller.prototype.labelPrecise = function(date) { 51 return Timeline.GeochronoUnit.toNumber(date) + "ma"; 52};