PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/timeline/ext/geochrono/scripts/labellers.js

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