domain-spec.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. describe('c3 chart domain', function () {
  2. 'use strict';
  3. var chart;
  4. var args = {
  5. data: {
  6. columns: [
  7. ['data1', 30, 200, 100, 400, 150, 250],
  8. ['data2', 50, 20, 10, 40, 15, 25]
  9. ]
  10. },
  11. axis: {
  12. y: {},
  13. y2: {}
  14. }
  15. };
  16. beforeEach(function (done) {
  17. chart = window.initChart(chart, args, done);
  18. });
  19. describe('axis.y.min', function () {
  20. describe('should change axis.y.min to -100', function () {
  21. beforeAll(function(){
  22. args.axis.y.min = -100;
  23. });
  24. it('should be set properly when smaller than max of data', function () {
  25. var domain = chart.internal.y.domain();
  26. expect(domain[0]).toBe(-150);
  27. expect(domain[1]).toBe(450);
  28. });
  29. });
  30. describe('should change axis.y.min to 500', function () {
  31. beforeAll(function(){
  32. args.axis.y.min = 500;
  33. });
  34. it('should be set properly when bigger than max of data', function () {
  35. var domain = chart.internal.y.domain();
  36. expect(domain[0]).toBe(499);
  37. expect(domain[1]).toBe(511);
  38. });
  39. });
  40. afterAll(function(){
  41. args.axis.y.min = undefined;
  42. });
  43. });
  44. describe('axis.y.max', function () {
  45. describe('should change axis.y.max to 1000', function () {
  46. beforeAll(function(){
  47. args.axis.y.max = 1000;
  48. });
  49. it('should be set properly when bigger than min of data', function () {
  50. var domain = chart.internal.y.domain();
  51. expect(domain[0]).toBe(-89);
  52. expect(domain[1]).toBe(1099);
  53. });
  54. });
  55. describe('should change axis.y.max to 0', function () {
  56. beforeAll(function(){
  57. args.axis.y.max = 0;
  58. });
  59. it('should be set properly when smaller than min of data', function () {
  60. var domain = chart.internal.y.domain();
  61. expect(domain[0]).toBe(-11);
  62. expect(domain[1]).toBe(1);
  63. });
  64. });
  65. });
  66. describe('axis.y.padding', function () {
  67. describe('should change axis.y.max to 1000', function () {
  68. beforeAll(function(){
  69. args = {
  70. data: {
  71. columns: [
  72. ['data1', 10, 20, 10, 40, 15, 25],
  73. ['data2', 50, 40, 30, 45, 25, 45]
  74. ]
  75. },
  76. axis: {
  77. y: {
  78. padding: 200,
  79. }
  80. }
  81. };
  82. });
  83. it('should be set properly when bigger than min of data', function () {
  84. var domain = chart.internal.y.domain();
  85. expect(domain[0]).toBeCloseTo(-9, -1);
  86. expect(domain[1]).toBeCloseTo(69, -1);
  87. });
  88. });
  89. describe('should change axis.y.max to 1000 with top/bottom padding', function () {
  90. beforeAll(function(){
  91. args = {
  92. data: {
  93. columns: [
  94. ['data1', 10, 20, 10, 40, 15, 25],
  95. ['data2', 50, 40, 30, 45, 25, 45]
  96. ]
  97. },
  98. axis: {
  99. y: {
  100. padding: {
  101. top: 200,
  102. bottom: 200
  103. }
  104. }
  105. }
  106. };
  107. });
  108. it('should be set properly when bigger than min of data', function () {
  109. var domain = chart.internal.y.domain();
  110. expect(domain[0]).toBeCloseTo(-9, -1);
  111. expect(domain[1]).toBeCloseTo(69, -1);
  112. });
  113. });
  114. });
  115. });