2
0

interaction-spec.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. describe('c3 chart interaction', function () {
  2. 'use strict';
  3. var chart, args;
  4. beforeEach(function (done) {
  5. chart = window.initChart(chart, args, done);
  6. });
  7. describe('generate event rects', function () {
  8. describe('custom x', function () {
  9. beforeAll(function () {
  10. args = {
  11. data: {
  12. x: 'x',
  13. columns: [
  14. ['x', 0, 1000, 3000, 10000],
  15. ['data', 10, 10, 10, 10]
  16. ],
  17. type: 'bar'
  18. }
  19. };
  20. });
  21. it('should have only 1 event rect properly', function () {
  22. var eventRects = d3.selectAll('.c3-event-rect');
  23. expect(eventRects.size()).toBe(1);
  24. eventRects.each(function () {
  25. var box = d3.select(this).node().getBoundingClientRect();
  26. expect(box.left).toBeCloseTo(40.5, -2);
  27. expect(box.width).toBeCloseTo(598, -2);
  28. });
  29. });
  30. describe('should generate bar chart with only one data', function () {
  31. beforeAll(function(){
  32. args = {
  33. data: {
  34. x: 'x',
  35. columns: [
  36. ['x', 0],
  37. ['data', 10]
  38. ],
  39. type: 'bar'
  40. }
  41. };
  42. });
  43. it('should have 1 event rects properly', function () {
  44. var eventRects = d3.selectAll('.c3-event-rect');
  45. expect(eventRects.size()).toBe(1);
  46. eventRects.each(function () {
  47. var box = d3.select(this).node().getBoundingClientRect();
  48. expect(box.left).toBeCloseTo(40.5, -2);
  49. expect(box.width).toBeCloseTo(598, -2);
  50. });
  51. });
  52. });
  53. });
  54. describe('timeseries', function () {
  55. beforeAll(function () {
  56. args = {
  57. data: {
  58. x: 'x',
  59. columns: [
  60. ['x', '20140101', '20140201', '20140210', '20140301'],
  61. ['data', 10, 10, 10, 10]
  62. ]
  63. }
  64. };
  65. });
  66. it('should have only 1 event rect properly', function () {
  67. var eventRects = d3.selectAll('.c3-event-rect');
  68. expect(eventRects.size()).toBe(1);
  69. eventRects.each(function () {
  70. var box = d3.select(this).node().getBoundingClientRect();
  71. expect(box.left).toBeCloseTo(40.5, -2);
  72. expect(box.width).toBeCloseTo(598, -2);
  73. });
  74. });
  75. describe('should generate line chart with only 1 data timeseries', function () {
  76. beforeAll(function(){
  77. args = {
  78. data: {
  79. x: 'x',
  80. columns: [
  81. ['x', '20140101'],
  82. ['data', 10]
  83. ]
  84. }
  85. };
  86. });
  87. it('should have 1 event rects properly', function () {
  88. var eventRects = d3.selectAll('.c3-event-rect');
  89. expect(eventRects.size()).toBe(1);
  90. eventRects.each(function () {
  91. var box = d3.select(this).node().getBoundingClientRect();
  92. expect(box.left).toBeCloseTo(40.5, -2);
  93. expect(box.width).toBeCloseTo(598, -2);
  94. });
  95. });
  96. });
  97. });
  98. });
  99. });