jquery.flot.largeNumbers.Test.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. describe('flot with large numbers', function() {
  2. var placeholder, plot;
  3. beforeEach(function() {
  4. placeholder = setFixtures('<div id="test-container" style="width: 600px;height: 400px">')
  5. .find('#test-container');
  6. });
  7. describe('on linear axis', function() {
  8. it('should work with large negative and positive numbers', function () {
  9. plot = $.plot(placeholder, [[[0, 1e308], [1, -1e308]]], {});
  10. var yaxis = plot.getAxes().yaxis;
  11. expect(yaxis.max).toBeGreaterThan(1e308);
  12. expect(yaxis.min).toBeLessThan(-1e308);
  13. expect(yaxis.ticks.length).toBeGreaterThan(2);
  14. yaxis.ticks.forEach(function(tick) {
  15. expect(isFinite(tick.v)).toBe(true);
  16. });
  17. });
  18. it('should work with Number.MAX_VALUE and -Number.MAX_VALUE', function () {
  19. plot = $.plot(placeholder, [[[0, Number.MAX_VALUE], [1, -Number.MAX_VALUE]]], {});
  20. var yaxis = plot.getAxes().yaxis;
  21. expect(yaxis.ticks.length).toBeGreaterThan(2);
  22. yaxis.ticks.forEach(function(tick) {
  23. expect(isFinite(tick.v)).toBe(true);
  24. });
  25. });
  26. it('should work with large numbers and large navigation offsets', function () {
  27. plot = $.plot(placeholder, [[[0, 1e308], [1, -1e308]]], {
  28. yaxes: [{
  29. offset: {below: -1e308, above: 1e308}
  30. }]
  31. });
  32. var yaxis = plot.getAxes().yaxis;
  33. expect(yaxis.max).toBeGreaterThan(1e308);
  34. expect(yaxis.min).toBeLessThan(-1e308);
  35. expect(yaxis.ticks.length).toBeGreaterThan(2);
  36. yaxis.ticks.forEach(function(tick) {
  37. expect(isFinite(tick.v)).toBe(true);
  38. });
  39. });
  40. });
  41. describe('on logaritmic axis', function() {
  42. it('should work with large positive numbers', function () {
  43. plot = $.plot(placeholder, [[[0, 1.1e308], [1, 0]]], {
  44. yaxis: {mode: 'log'}});
  45. var yaxis = plot.getAxes().yaxis;
  46. expect(yaxis.max).toBeGreaterThan(1e308);
  47. expect(yaxis.ticks.length).toBeGreaterThan(2);
  48. yaxis.ticks.forEach(function(tick) {
  49. expect(isFinite(tick.v)).toBe(true);
  50. });
  51. });
  52. it('should work with Number.MAX_VALUE', function () {
  53. plot = $.plot(placeholder, [[[0, Number.MAX_VALUE], [1, 0]]], {
  54. yaxis: {mode: 'log'}});
  55. var yaxis = plot.getAxes().yaxis;
  56. expect(yaxis.ticks.length).toBeGreaterThan(2);
  57. yaxis.ticks.forEach(function(tick) {
  58. expect(isFinite(tick.v)).toBe(true);
  59. });
  60. });
  61. it('should work with large numbers and large navigation offsets', function () {
  62. plot = $.plot(placeholder, [[[0, 1e308], [1, 0]]], {
  63. yaxes: [{
  64. offset: {below: -1e308, above: 1e308},
  65. mode: 'log'
  66. }]
  67. });
  68. var yaxis = plot.getAxes().yaxis;
  69. expect(yaxis.max).toBeGreaterThan(1e308);
  70. expect(yaxis.min).toEqual(0.1);
  71. expect(yaxis.ticks.length).toBeGreaterThan(2);
  72. yaxis.ticks.forEach(function(tick) {
  73. expect(isFinite(tick.v)).toBe(true);
  74. });
  75. });
  76. });
  77. });