api.x-spec.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { d3, initChart } from './c3-helper'
  2. describe('c3 api.x', function() {
  3. 'use strict'
  4. var chart
  5. var args = {
  6. data: {
  7. x: 'x',
  8. columns: [
  9. ['x', 10, 30, 45, 50, 70, 100],
  10. ['data1', 30, 200, 100, 400, 150, 250],
  11. ['data2', 20, 180, 240, 100, 190]
  12. ]
  13. }
  14. }
  15. beforeEach(function(done) {
  16. chart = initChart(chart, args, done)
  17. })
  18. it('should return initial ticks for axis x', function() {
  19. var expectedValues = [10, 30, 45, 50, 70, 100]
  20. d3.select('.c3-axis-x')
  21. .selectAll('g.tick')
  22. .each(function(d, i) {
  23. var text = d3
  24. .select(this)
  25. .select('text')
  26. .text()
  27. expect(+text).toBe(expectedValues[i])
  28. })
  29. })
  30. it('should return new ticks for axis x after calling chart.x', function() {
  31. var expectedValues = [16, 26, 55, 60, 75, 90]
  32. chart.x(expectedValues)
  33. d3.select('.c3-axis-x')
  34. .selectAll('g.tick')
  35. .each(function(d, i) {
  36. var text = d3
  37. .select(this)
  38. .select('text')
  39. .text()
  40. expect(+text).toBe(expectedValues[i])
  41. })
  42. })
  43. })
  44. describe('c3 api.xs', function() {
  45. 'use strict'
  46. var chart
  47. var args = {
  48. data: {
  49. xs: {
  50. data1: 'x1',
  51. data2: 'x2'
  52. },
  53. columns: [
  54. ['x1', 10, 30, 50, 70, 90, 110],
  55. ['x2', 20, 40, 60, 80, 100],
  56. ['data1', 30, 200, 100, 400, 150, 250],
  57. ['data2', 20, 180, 240, 100, 190]
  58. ]
  59. }
  60. }
  61. beforeEach(function(done) {
  62. chart = initChart(chart, args, done)
  63. })
  64. it('should return initial ticks for axis x', function() {
  65. var expectedValues = [
  66. '10',
  67. '20',
  68. '30',
  69. '40',
  70. '50',
  71. '60',
  72. '70',
  73. '80',
  74. '90',
  75. '100',
  76. '110'
  77. ]
  78. d3.select('.c3-axis-x')
  79. .selectAll('g.tick')
  80. .each(function(d, i) {
  81. var text = d3
  82. .select(this)
  83. .select('text')
  84. .text()
  85. expect(text).toBe(expectedValues[i])
  86. })
  87. })
  88. it('should return new ticks for axis x after calling chart.xs', function() {
  89. var expectedValues = [
  90. '15',
  91. '25',
  92. '35',
  93. '45',
  94. '55',
  95. '65',
  96. '75',
  97. '85',
  98. '95',
  99. '105',
  100. '115'
  101. ]
  102. chart.xs({
  103. data1: [15, 35, 55, 75, 95, 115],
  104. data2: [25, 45, 65, 85, 105]
  105. })
  106. d3.select('.c3-axis-x')
  107. .selectAll('g.tick')
  108. .each(function(d, i) {
  109. var text = d3
  110. .select(this)
  111. .select('text')
  112. .text()
  113. expect(text).toBe(expectedValues[i])
  114. })
  115. })
  116. })