time_series_specs.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. define([
  2. 'app/core/time_series'
  3. ], function(TimeSeries) {
  4. 'use strict';
  5. describe("TimeSeries", function() {
  6. var points, series;
  7. var yAxisFormats = ['short', 'ms'];
  8. var testData = {
  9. alias: 'test',
  10. datapoints: [
  11. [1,2],[null,3],[10,4],[8,5]
  12. ]
  13. };
  14. describe('when getting flot pairs', function() {
  15. it('with connected style, should ignore nulls', function() {
  16. series = new TimeSeries(testData);
  17. points = series.getFlotPairs('connected', yAxisFormats);
  18. expect(points.length).to.be(3);
  19. });
  20. it('with null as zero style, should replace nulls with zero', function() {
  21. series = new TimeSeries(testData);
  22. points = series.getFlotPairs('null as zero', yAxisFormats);
  23. expect(points.length).to.be(4);
  24. expect(points[1][1]).to.be(0);
  25. });
  26. it('if last is null current should pick next to last', function() {
  27. series = new TimeSeries({
  28. datapoints: [[10,1], [null, 2]]
  29. });
  30. series.getFlotPairs('null', yAxisFormats);
  31. expect(series.stats.current).to.be(10);
  32. });
  33. it('max value should work for negative values', function() {
  34. series = new TimeSeries({
  35. datapoints: [[-10,1], [-4, 2]]
  36. });
  37. series.getFlotPairs('null', yAxisFormats);
  38. expect(series.stats.max).to.be(-4);
  39. });
  40. it('average value should ignore nulls', function() {
  41. series = new TimeSeries(testData);
  42. series.getFlotPairs('null', yAxisFormats);
  43. expect(series.stats.avg).to.be(6.333333333333333);
  44. });
  45. it('with null as zero style, average value should treat nulls as 0', function() {
  46. series = new TimeSeries(testData);
  47. series.getFlotPairs('null as zero', yAxisFormats);
  48. expect(series.stats.avg).to.be(4.75);
  49. });
  50. });
  51. describe('can detect if series contains ms precision', function() {
  52. var fakedata;
  53. beforeEach(function() {
  54. fakedata = testData;
  55. });
  56. it('missing datapoint with ms precision', function() {
  57. fakedata.datapoints[0] = [1337, 1234567890000];
  58. series = new TimeSeries(fakedata);
  59. expect(series.isMsResolutionNeeded()).to.be(false);
  60. });
  61. it('contains datapoint with ms precision', function() {
  62. fakedata.datapoints[0] = [1337, 1236547890001];
  63. series = new TimeSeries(fakedata);
  64. expect(series.isMsResolutionNeeded()).to.be(true);
  65. });
  66. });
  67. describe('series overrides', function() {
  68. var series;
  69. beforeEach(function() {
  70. series = new TimeSeries(testData);
  71. });
  72. describe('fill & points', function() {
  73. beforeEach(function() {
  74. series.alias = 'test';
  75. series.applySeriesOverrides([{ alias: 'test', fill: 0, points: true }]);
  76. });
  77. it('should set fill zero, and enable points', function() {
  78. expect(series.lines.fill).to.be(0.001);
  79. expect(series.points.show).to.be(true);
  80. });
  81. });
  82. describe('series option overrides, bars, true & lines false', function() {
  83. beforeEach(function() {
  84. series.alias = 'test';
  85. series.applySeriesOverrides([{ alias: 'test', bars: true, lines: false }]);
  86. });
  87. it('should disable lines, and enable bars', function() {
  88. expect(series.lines.show).to.be(false);
  89. expect(series.bars.show).to.be(true);
  90. });
  91. });
  92. describe('series option overrides, linewidth, stack', function() {
  93. beforeEach(function() {
  94. series.alias = 'test';
  95. series.applySeriesOverrides([{ alias: 'test', linewidth: 5, stack: false }]);
  96. });
  97. it('should disable stack, and set lineWidth', function() {
  98. expect(series.stack).to.be(false);
  99. expect(series.lines.lineWidth).to.be(5);
  100. });
  101. });
  102. describe('series option overrides, fill below to', function() {
  103. beforeEach(function() {
  104. series.alias = 'test';
  105. series.applySeriesOverrides([{ alias: 'test', fillBelowTo: 'min' }]);
  106. });
  107. it('should disable line fill and add fillBelowTo', function() {
  108. expect(series.fillBelowTo).to.be('min');
  109. });
  110. });
  111. describe('series option overrides, pointradius, steppedLine', function() {
  112. beforeEach(function() {
  113. series.alias = 'test';
  114. series.applySeriesOverrides([{ alias: 'test', pointradius: 5, steppedLine: true }]);
  115. });
  116. it('should set pointradius, and set steppedLine', function() {
  117. expect(series.points.radius).to.be(5);
  118. expect(series.lines.steps).to.be(true);
  119. });
  120. });
  121. describe('override match on regex', function() {
  122. beforeEach(function() {
  123. series.alias = 'test_01';
  124. series.applySeriesOverrides([{ alias: '/.*01/', lines: false }]);
  125. });
  126. it('should match second series', function() {
  127. expect(series.lines.show).to.be(false);
  128. });
  129. });
  130. describe('override series y-axis, and z-index', function() {
  131. beforeEach(function() {
  132. series.alias = 'test';
  133. series.applySeriesOverrides([{ alias: 'test', yaxis: 2, zindex: 2 }]);
  134. });
  135. it('should set yaxis', function() {
  136. expect(series.yaxis).to.be(2);
  137. });
  138. it('should set zindex', function() {
  139. expect(series.zindex).to.be(2);
  140. });
  141. });
  142. });
  143. });
  144. });