api.pie-spec.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { initChart } from './c3-helper'
  2. describe('c3 api pie', function() {
  3. 'use strict'
  4. var chart, args
  5. args = {
  6. data: {
  7. columns: [
  8. ['data1', 60],
  9. ['data2', 40]
  10. ],
  11. type: 'pie'
  12. },
  13. pie: {
  14. padAngle: 0.5
  15. }
  16. }
  17. beforeEach(function(done) {
  18. chart = initChart(chart, args, done)
  19. })
  20. describe('padAngle', function() {
  21. it('can configure padAngle', function(done) {
  22. expect(chart.pie.padAngle()).toBe(0.5)
  23. const path = chart.internal.main.select('.c3-arc-data1').attr('d')
  24. chart.pie.padAngle(0.2)
  25. setTimeout(function() {
  26. expect(chart.pie.padAngle()).toBe(0.2)
  27. expect(chart.internal.main.select('.c3-arc-data1').attr('d')).not.toBe(
  28. path
  29. )
  30. done()
  31. }, 500)
  32. })
  33. })
  34. describe('load data', function() {
  35. beforeAll(() => {
  36. args = {
  37. data: {
  38. columns: ['r', 'l', 'd'],
  39. type: 'pie',
  40. colors: {
  41. r: 'red',
  42. l: 'green',
  43. d: 'blue'
  44. }
  45. }
  46. }
  47. })
  48. it('can add data point to existing data', () => {
  49. chart.load({
  50. columns: [
  51. ['r', 75],
  52. ['l', 20],
  53. ['d', 5]
  54. ]
  55. })
  56. expect(chart.internal.getTotalDataSum()).toEqual(100)
  57. expect(chart.internal.main.selectAll('.c3-arc').size()).toEqual(3)
  58. })
  59. })
  60. })