axis-spec.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. describe('c3 chart axis', 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. ['data3', 150, 120, 110, 140, 115, 125]
  10. ]
  11. },
  12. axis: {
  13. y: {
  14. tick: {
  15. values: null,
  16. count: undefined
  17. }
  18. },
  19. y2: {
  20. tick: {
  21. values: null,
  22. count: undefined
  23. }
  24. }
  25. }
  26. };
  27. beforeEach(function (done) {
  28. chart = window.initChart(chart, args, done);
  29. });
  30. describe('axis.y.tick.count', function () {
  31. describe('with only 1 tick on y axis', function () {
  32. beforeAll(function(){
  33. args.axis.y.tick.count = 1;
  34. });
  35. it('should have only 1 tick on y axis', function () {
  36. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  37. expect(ticksSize).toBe(1);
  38. });
  39. });
  40. describe('with 2 ticks on y axis', function () {
  41. beforeAll(function(){
  42. args.axis.y.tick.count = 2;
  43. });
  44. it('should have 2 ticks on y axis', function () {
  45. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  46. expect(ticksSize).toBe(2);
  47. });
  48. });
  49. describe('with 3 ticks on y axis', function () {
  50. beforeAll(function(){
  51. args.axis.y.tick.count = 3;
  52. });
  53. it('should have 3 ticks on y axis', function () {
  54. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  55. expect(ticksSize).toBe(3);
  56. });
  57. });
  58. });
  59. describe('axis.y.tick.values', function () {
  60. var values = [100, 500];
  61. describe('with only 2 ticks on y axis', function () {
  62. beforeAll(function(){
  63. args.axis.y.tick.values = values;
  64. });
  65. it('should have only 2 tick on y axis', function () {
  66. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  67. expect(ticksSize).toBe(2);
  68. });
  69. it('should have specified tick texts', function () {
  70. d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) {
  71. var text = d3.select(this).select('text').text();
  72. expect(+text).toBe(values[i]);
  73. });
  74. });
  75. });
  76. });
  77. describe('axis y timeseries', function () {
  78. beforeAll(function () {
  79. args = {
  80. data: {
  81. columns: [
  82. ["times", 60000, 120000, 180000, 240000]
  83. ]
  84. },
  85. axis: {
  86. y: {
  87. type : 'timeseries',
  88. tick: {
  89. time: {
  90. }
  91. }
  92. }
  93. }
  94. };
  95. });
  96. it('should have 7 ticks on y axis', function () {
  97. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  98. expect(ticksSize).toBe(7); // the count starts at initial value and increments by the set interval
  99. });
  100. it('should have specified 30 second intervals', function () {
  101. var prevValue;
  102. d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) {
  103. if (i !== 0) {
  104. var result = d - prevValue;
  105. expect(result).toEqual(30000); // expressed in milliseconds
  106. }
  107. prevValue = d;
  108. });
  109. });
  110. describe('with axis.y.time', function () {
  111. beforeAll(function(){
  112. args.axis.y.tick.time = {
  113. type : d3.timeSecond,
  114. interval : 60
  115. };
  116. });
  117. it('should have 4 ticks on y axis', function () {
  118. var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
  119. expect(ticksSize).toBe(4); // the count starts at initial value and increments by the set interval
  120. });
  121. it('should have specified 60 second intervals', function () {
  122. var prevValue;
  123. d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) {
  124. if (i !== 0) {
  125. var result = d - prevValue;
  126. expect(result).toEqual(60000); // expressed in milliseconds
  127. }
  128. prevValue = d;
  129. });
  130. });
  131. });
  132. });
  133. describe('axis.x.tick.values', function () {
  134. describe('function is provided', function () {
  135. var tickGenerator = function () {
  136. var values = [];
  137. for (var i = 0; i <= 300; i += 50) {
  138. values.push(i);
  139. }
  140. return values;
  141. };
  142. beforeEach(function () {
  143. args.axis.x = {
  144. tick: {
  145. values: tickGenerator
  146. }
  147. };
  148. chart = window.c3.generate(args);
  149. window.generatedTicks = tickGenerator(); // This should be removed from window
  150. });
  151. it('should use function to generate ticks', function () {
  152. d3.select('.c3-axis-x').selectAll('g.tick').each(function (d, i) {
  153. var tick = d3.select(this).select('text').text();
  154. expect(+tick).toBe(window.generatedTicks[i]);
  155. });
  156. });
  157. });
  158. });
  159. describe('axis.x.tick.width', function () {
  160. describe('indexed x axis and y/y2 axis', function () {
  161. describe('not rotated', function () {
  162. beforeAll(function () {
  163. args = {
  164. data: {
  165. columns: [
  166. ['data1', 30, 200, 100, 400, 150, 250],
  167. ['data2', 50, 20, 10, 40, 15, 25]
  168. ],
  169. axes: {
  170. data2: 'y2'
  171. }
  172. },
  173. axis: {
  174. y2: {
  175. show: true
  176. }
  177. }
  178. };
  179. });
  180. it('should construct indexed x axis properly', function () {
  181. var ticks = chart.internal.main.select('.c3-axis-x').selectAll('g.tick'),
  182. expectedX = '0',
  183. expectedDy = '.71em';
  184. expect(ticks.size()).toBe(6);
  185. ticks.each(function (d, i) {
  186. var tspans = d3.select(this).selectAll('tspan');
  187. expect(tspans.size()).toBe(1);
  188. tspans.each(function () {
  189. var tspan = d3.select(this);
  190. expect(tspan.text()).toBe(i + '');
  191. expect(tspan.attr('x')).toBe(expectedX);
  192. expect(tspan.attr('dy')).toBe(expectedDy);
  193. });
  194. });
  195. });
  196. describe('should set axis.x.tick.format', function () {
  197. beforeAll(function(){
  198. args.axis.x = {
  199. tick: {
  200. format: function () {
  201. return 'very long tick text on x axis';
  202. }
  203. }
  204. };
  205. });
  206. it('should split x axis tick text to multiple lines', function () {
  207. var ticks = chart.internal.main.select('.c3-axis-x').selectAll('g.tick'),
  208. expectedTexts = ['very long tick text', 'on x axis'],
  209. expectedX = '0';
  210. expect(ticks.size()).toBe(6);
  211. ticks.each(function () {
  212. var tspans = d3.select(this).selectAll('tspan');
  213. expect(tspans.size()).toBe(2);
  214. tspans.each(function (d, i) {
  215. var tspan = d3.select(this);
  216. expect(tspan.text()).toBe(expectedTexts[i]);
  217. expect(tspan.attr('x')).toBe(expectedX);
  218. if (i === 0) {
  219. expect(tspan.attr('dy')).toBe('.71em');
  220. } else {
  221. expect(tspan.attr('dy')).toBeGreaterThan(8);
  222. }
  223. });
  224. });
  225. });
  226. it('should construct y axis properly', function () {
  227. var ticks = chart.internal.main.select('.c3-axis-y').selectAll('g.tick'),
  228. expectedX = '-9',
  229. expectedDy = '3';
  230. expect(ticks.size()).toBe(9);
  231. ticks.each(function (d) {
  232. var tspans = d3.select(this).selectAll('tspan');
  233. expect(tspans.size()).toBe(1);
  234. tspans.each(function () {
  235. var tspan = d3.select(this);
  236. expect(tspan.text()).toBe(d + '');
  237. expect(tspan.attr('x')).toBe(expectedX);
  238. expect(tspan.attr('dy')).toBe(expectedDy);
  239. });
  240. });
  241. });
  242. it('should construct y2 axis properly', function () {
  243. var ticks = chart.internal.main.select('.c3-axis-y2').selectAll('g.tick'),
  244. expectedX = '9',
  245. expectedDy = '3';
  246. expect(ticks.size()).toBe(9);
  247. ticks.each(function (d) {
  248. var tspans = d3.select(this).selectAll('tspan');
  249. expect(tspans.size()).toBe(1);
  250. tspans.each(function () {
  251. var tspan = d3.select(this);
  252. expect(tspan.text()).toBe(d + '');
  253. expect(tspan.attr('x')).toBe(expectedX);
  254. expect(tspan.attr('dy')).toBe(expectedDy);
  255. });
  256. });
  257. });
  258. });
  259. describe('should set big values in y', function () {
  260. beforeAll(function(){
  261. args.data.columns = [
  262. ['data1', 3000000000000000, 200, 100, 400, 150, 250],
  263. ['data2', 50, 20, 10, 40, 15, 25]
  264. ];
  265. });
  266. it('should not split y axis tick text to multiple lines', function () {
  267. var ticks = chart.internal.main.select('.c3-axis-y2').selectAll('g.tick');
  268. ticks.each(function () {
  269. var tspans = d3.select(this).selectAll('tspan');
  270. expect(tspans.size()).toBe(1);
  271. });
  272. });
  273. });
  274. });
  275. describe('rotated', function () {
  276. beforeAll(function () {
  277. args.axis.rotated = true;
  278. });
  279. it('should split x axis tick text to multiple lines', function () {
  280. var ticks = chart.internal.main.select('.c3-axis-x').selectAll('g.tick'),
  281. expectedTexts = ['very long tick text on', 'x axis'],
  282. expectedX = '-9';
  283. expect(ticks.size()).toBe(6);
  284. ticks.each(function () {
  285. var tspans = d3.select(this).selectAll('tspan');
  286. expect(tspans.size()).toBe(2);
  287. tspans.each(function (d, i) {
  288. var tspan = d3.select(this);
  289. expect(tspan.text()).toBe(expectedTexts[i]);
  290. expect(tspan.attr('x')).toBe(expectedX);
  291. if (i === 0) {
  292. expect(tspan.attr('dy')).toBeLessThan(0);
  293. } else {
  294. expect(tspan.attr('dy')).toBeGreaterThan(9);
  295. }
  296. });
  297. });
  298. });
  299. it('should not split y axis tick text to multiple lines', function () {
  300. var ticks = chart.internal.main.select('.c3-axis-y').selectAll('g.tick'),
  301. expectedTexts = [
  302. '0',
  303. '500000000000000',
  304. '1000000000000000',
  305. '1500000000000000',
  306. '2000000000000000',
  307. '2500000000000000',
  308. '3000000000000000'
  309. ],
  310. expectedX = '0',
  311. expectedDy = '.71em';
  312. expect(ticks.size()).toBe(7);
  313. ticks.each(function (d, i) {
  314. var tspans = d3.select(this).selectAll('tspan');
  315. expect(tspans.size()).toBe(1);
  316. tspans.each(function () {
  317. var tspan = d3.select(this);
  318. expect(tspan.text()).toBe(expectedTexts[i]);
  319. expect(tspan.attr('x')).toBe(expectedX);
  320. expect(tspan.attr('dy')).toBe(expectedDy);
  321. });
  322. });
  323. });
  324. });
  325. });
  326. describe('category axis', function () {
  327. describe('not rotated', function () {
  328. beforeAll(function () {
  329. args = {
  330. data: {
  331. x: 'x',
  332. columns: [
  333. ['x', 'this is a very long tick text on category axis', 'cat1', 'cat2', 'cat3', 'cat4', 'cat5'],
  334. ['data1', 30, 200, 100, 400, 150, 250],
  335. ['data2', 50, 20, 10, 40, 15, 25]
  336. ]
  337. },
  338. axis: {
  339. x: {
  340. type: 'category'
  341. }
  342. }
  343. };
  344. });
  345. it('should locate ticks properly', function () {
  346. var ticks = chart.internal.main.select('.c3-axis-x').selectAll('g.tick');
  347. ticks.each(function (d, i) {
  348. var tspans = d3.select(this).selectAll('tspan'),
  349. expectedX = '0',
  350. expectedDy = '.71em';
  351. if (i > 0) { // i === 0 should be checked in next test
  352. expect(tspans.size()).toBe(1);
  353. tspans.each(function () {
  354. var tspan = d3.select(this);
  355. expect(tspan.attr('x')).toBe(expectedX);
  356. expect(tspan.attr('dy')).toBe(expectedDy);
  357. });
  358. }
  359. });
  360. });
  361. xit('should split tick text properly', function () {
  362. var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
  363. tspans = tick.selectAll('tspan'),
  364. expectedTickTexts = [
  365. 'this is a very long',
  366. 'tick text on category',
  367. 'axis'
  368. ],
  369. expectedX = '0';
  370. expect(tspans.size()).toBe(3);
  371. tspans.each(function (d, i) {
  372. var tspan = d3.select(this);
  373. expect(tspan.text()).toBe(expectedTickTexts[i]);
  374. expect(tspan.attr('x')).toBe(expectedX);
  375. // unable to define pricise number because it differs depends on environment..
  376. if (i === 0) {
  377. expect(tspan.attr('dy')).toBe('.71em');
  378. } else {
  379. expect(tspan.attr('dy')).toBeGreaterThan(8);
  380. }
  381. });
  382. });
  383. });
  384. describe('rotated', function () {
  385. beforeAll(function () {
  386. args.axis.rotated = true;
  387. });
  388. it('should locate ticks on rotated axis properly', function () {
  389. var ticks = chart.internal.main.select('.c3-axis-x').selectAll('g.tick');
  390. ticks.each(function (d, i) {
  391. var tspans = d3.select(this).selectAll('tspan'),
  392. expectedX = '-9',
  393. expectedDy = '3';
  394. if (i > 0) { // i === 0 should be checked in next test
  395. expect(tspans.size()).toBe(1);
  396. tspans.each(function () {
  397. var tspan = d3.select(this);
  398. expect(tspan.attr('x')).toBe(expectedX);
  399. expect(tspan.attr('dy')).toBe(expectedDy);
  400. });
  401. }
  402. });
  403. });
  404. it('should split tick text on rotated axis properly', function () {
  405. var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
  406. tspans = tick.selectAll('tspan'),
  407. expectedTickTexts = [
  408. 'this is a very long',
  409. 'tick text on category',
  410. 'axis'
  411. ],
  412. expectedX = '-9';
  413. expect(tspans.size()).toBe(3);
  414. tspans.each(function (d, i) {
  415. var tspan = d3.select(this);
  416. expect(tspan.text()).toBe(expectedTickTexts[i]);
  417. expect(tspan.attr('x')).toBe(expectedX);
  418. // unable to define pricise number because it differs depends on environment..
  419. if (i === 0) {
  420. expect(tspan.attr('dy')).toBeLessThan(0);
  421. } else {
  422. expect(tspan.attr('dy')).toBeGreaterThan(8);
  423. }
  424. });
  425. });
  426. });
  427. describe('option used', function () {
  428. describe('as null', function () {
  429. beforeAll(function () { //'without split ticks',
  430. args.axis.x.tick = {
  431. multiline: false
  432. };
  433. });
  434. it('should split x tick', function () {
  435. var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
  436. tspans = tick.selectAll('tspan');
  437. expect(tspans.size()).toBe(1);
  438. });
  439. });
  440. describe('as value', function () {
  441. beforeAll(function () { // 'without split ticks',
  442. args.axis.x.tick = {
  443. width: 150
  444. };
  445. });
  446. it('should split x tick to 2 lines properly', function () {
  447. var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
  448. tspans = tick.selectAll('tspan'),
  449. expectedTickTexts = [
  450. 'this is a very long tick text on',
  451. 'category axis'
  452. ],
  453. expectedX = '-9';
  454. expect(tspans.size()).toBe(2);
  455. tspans.each(function (d, i) {
  456. var tspan = d3.select(this);
  457. expect(tspan.text()).toBe(expectedTickTexts[i]);
  458. expect(tspan.attr('x')).toBe(expectedX);
  459. // unable to define pricise number because it differs depends on environment..
  460. if (i === 0) {
  461. expect(tspan.attr('dy')).toBeLessThan(0);
  462. } else {
  463. expect(tspan.attr('dy')).toBeGreaterThan(8);
  464. }
  465. });
  466. });
  467. });
  468. });
  469. });
  470. describe('with axis.x.tick.format', function () {
  471. beforeAll(function () { // 'with axis.x.tick.format',
  472. args.axis.x.tick.format = function () {
  473. return ['this is a very long tick text', 'on category axis'];
  474. };
  475. });
  476. it('should have multiline tick text', function () {
  477. var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
  478. tspans = tick.selectAll('tspan'),
  479. expectedTickTexts = ['this is a very long tick text', 'on category axis'];
  480. expect(tspans.size()).toBe(2);
  481. tspans.each(function (d, i) {
  482. var tspan = d3.select(this);
  483. expect(tspan.text()).toBe(expectedTickTexts[i]);
  484. });
  485. });
  486. });
  487. });
  488. describe('axis.x.tick.rotate', function () {
  489. describe('not rotated', function () {
  490. beforeAll(function () {
  491. args = {
  492. data: {
  493. x: 'x',
  494. columns: [
  495. ['x', 'category 1', 'category 2', 'category 3', 'category 4', 'category 5', 'category 6'],
  496. ['data1', 30, 200, 100, 400, 150, 250],
  497. ['data2', 50, 20, 10, 40, 15, 25]
  498. ]
  499. },
  500. axis: {
  501. x: {
  502. type: 'category',
  503. tick: {
  504. rotate: 60
  505. }
  506. }
  507. }
  508. };
  509. });
  510. it('should rotate tick texts', function () {
  511. chart.internal.main.selectAll('.c3-axis-x g.tick').each(function () {
  512. var tick = d3.select(this),
  513. text = tick.select('text'),
  514. tspan = text.select('tspan');
  515. expect(text.attr('transform')).toBe('rotate(60)');
  516. expect(text.attr('y')).toBe('1.5');
  517. expect(tspan.attr('dx')).toBe('6.928203230275509');
  518. });
  519. });
  520. it('should have automatically calculated x axis height', function () {
  521. var box = chart.internal.main.select('.c3-axis-x').node().getBoundingClientRect(),
  522. height = chart.internal.getHorizontalAxisHeight('x');
  523. expect(box.height).toBeGreaterThan(50);
  524. expect(height).toBeCloseTo(76, -1.3); // @TODO make this test better
  525. });
  526. });
  527. });
  528. describe('axis.y.tick.rotate', function () {
  529. describe('not rotated', function () {
  530. beforeAll(function () {
  531. args = {
  532. data: {
  533. columns: [
  534. ['data1', 30, 200, 100, 400, 150, 250, 100, 600],
  535. ['data2', 50, 20, 10, 40, 15, 25],
  536. ]
  537. },
  538. axis: {
  539. rotated: true,
  540. y: {
  541. tick: {
  542. rotate: 45
  543. }
  544. }
  545. }
  546. };
  547. });
  548. it('should rotate tick texts', function () {
  549. chart.internal.main.selectAll('.c3-axis-y g.tick').each(function () {
  550. var tick = d3.select(this),
  551. text = tick.select('text'),
  552. tspan = text.select('tspan');
  553. expect(text.attr('transform')).toBe('rotate(45)');
  554. expect(text.attr('y')).toBe('4');
  555. expect(tspan.attr('dx')).toBeCloseTo('5.6', 0);
  556. });
  557. });
  558. it('should have automatically calculated y axis width', function () {
  559. var box = chart.internal.main.select('.c3-axis-y').node().getBoundingClientRect();
  560. expect(box.width).toBeCloseTo(590, 1);
  561. });
  562. });
  563. });
  564. describe('axis.x.tick.fit', function () {
  565. describe('axis.x.tick.fit = true', function () {
  566. beforeAll(function () { // 'should set args for indexed data',
  567. args = {
  568. data: {
  569. columns: [
  570. ['data1', 30, 200, 100, 400, 150, 250],
  571. ['data2', 50, 20, 10, 40, 15, 25],
  572. ['data3', 150, 120, 110, 140, 115, 125]
  573. ]
  574. }
  575. };
  576. });
  577. it('should show fitted ticks on indexed data', function () {
  578. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  579. expect(ticks.size()).toBe(6);
  580. });
  581. describe('should set args for x-based data', function () {
  582. beforeAll(function(){
  583. args = {
  584. data: {
  585. x: 'x',
  586. columns: [
  587. ['x', 10, 20, 100, 110, 200, 1000],
  588. ['data1', 30, 200, 100, 400, 150, 250],
  589. ['data2', 50, 20, 10, 40, 15, 25],
  590. ['data3', 150, 120, 110, 140, 115, 125]
  591. ]
  592. }
  593. };
  594. });
  595. it('should show fitted ticks on indexed data', function () {
  596. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  597. expect(ticks.size()).toBe(6);
  598. });
  599. it('should show fitted ticks after hide and show', function () {
  600. chart.hide();
  601. chart.show();
  602. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  603. expect(ticks.size()).toBe(6);
  604. });
  605. });
  606. });
  607. describe('axis.x.tick.fit = false', function () {
  608. describe('should set args for indexed data', function () {
  609. beforeAll(function(){
  610. args = {
  611. data: {
  612. columns: [
  613. ['data1', 30, 200, 100, 400, 150, 250],
  614. ['data2', 50, 20, 10, 40, 15, 25],
  615. ['data3', 150, 120, 110, 140, 115, 125]
  616. ]
  617. },
  618. axis: {
  619. x: {
  620. tick: {
  621. fit: false
  622. }
  623. }
  624. }
  625. };
  626. });
  627. it('should show fitted ticks on indexed data', function () {
  628. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  629. expect(ticks.size()).toBe(11);
  630. });
  631. });
  632. describe('should set args for x-based data', function () {
  633. beforeAll(function(){
  634. args.data = {
  635. x: 'x',
  636. columns: [
  637. ['x', 10, 20, 100, 110, 200, 1000],
  638. ['data1', 30, 200, 100, 400, 150, 250],
  639. ['data2', 50, 20, 10, 40, 15, 25],
  640. ['data3', 150, 120, 110, 140, 115, 125]
  641. ]
  642. };
  643. });
  644. it('should show fitted ticks on indexed data', function () {
  645. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  646. expect(ticks.size()).toBe(10);
  647. });
  648. it('should show fitted ticks after hide and show', function () {
  649. chart.hide();
  650. chart.show();
  651. var ticks = chart.internal.main.selectAll('.c3-axis-x g.tick');
  652. expect(ticks.size()).toBe(10);
  653. });
  654. });
  655. });
  656. });
  657. describe('axis.y.inner', function () {
  658. beforeAll(function () {
  659. args = {
  660. data: {
  661. columns: [
  662. ['data1', 30, 200, 100, 400, 150, 250],
  663. ['data2', 50, 20, 10, 40, 15, 25]
  664. ]
  665. },
  666. axis: {
  667. y: {
  668. inner: false
  669. }
  670. }
  671. };
  672. });
  673. it('should not have inner y axis', function () {
  674. var paddingLeft = chart.internal.getCurrentPaddingLeft(),
  675. tickTexts = chart.internal.main.selectAll('.c3-axis-y g.tick text');
  676. expect(paddingLeft).toBeGreaterThan(19);
  677. tickTexts.each(function () {
  678. expect(+d3.select(this).attr('x')).toBeLessThan(0);
  679. });
  680. });
  681. describe('with inner y axis', function () {
  682. beforeAll(function(){
  683. args.axis.y.inner = true;
  684. });
  685. it('should have inner y axis', function () {
  686. var paddingLeft = chart.internal.getCurrentPaddingLeft(),
  687. tickTexts = chart.internal.main.selectAll('.c3-axis-y g.tick text');
  688. expect(paddingLeft).toBe(1);
  689. tickTexts.each(function () {
  690. expect(+d3.select(this).attr('x')).toBeGreaterThan(0);
  691. });
  692. });
  693. });
  694. });
  695. describe('axis.y2.inner', function () {
  696. beforeAll(function () {
  697. args = {
  698. data: {
  699. columns: [
  700. ['data1', 30, 200, 100, 400, 150, 250],
  701. ['data2', 50, 20, 10, 40, 15, 25]
  702. ]
  703. },
  704. axis: {
  705. y2: {
  706. show: true,
  707. inner: false
  708. }
  709. }
  710. };
  711. });
  712. it('should not have inner y axis', function () {
  713. var paddingRight = chart.internal.getCurrentPaddingRight(),
  714. tickTexts = chart.internal.main.selectAll('.c3-axis-2y g.tick text');
  715. expect(paddingRight).toBeGreaterThan(19);
  716. tickTexts.each(function () {
  717. expect(+d3.select(this).attr('x')).toBeGreaterThan(0);
  718. });
  719. });
  720. describe('with inner y axis', function () {
  721. beforeAll(function(){
  722. args.axis.y2.inner = true;
  723. });
  724. it('should have inner y axis', function () {
  725. var paddingRight = chart.internal.getCurrentPaddingRight(),
  726. tickTexts = chart.internal.main.selectAll('.c3-axis-2y g.tick text');
  727. expect(paddingRight).toBe(2);
  728. tickTexts.each(function () {
  729. expect(+d3.select(this).attr('x')).toBeLessThan(0);
  730. });
  731. });
  732. });
  733. });
  734. });