element.arc.tests.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Test the rectangle element
  2. describe('Arc element tests', function() {
  3. it ('Should be constructed', function() {
  4. var arc = new Chart.elements.Arc({
  5. _datasetIndex: 2,
  6. _index: 1
  7. });
  8. expect(arc).not.toBe(undefined);
  9. expect(arc._datasetIndex).toBe(2);
  10. expect(arc._index).toBe(1);
  11. });
  12. it ('should determine if in range', function() {
  13. var arc = new Chart.elements.Arc({
  14. _datasetIndex: 2,
  15. _index: 1
  16. });
  17. // Make sure we can run these before the view is added
  18. expect(arc.inRange(2, 2)).toBe(false);
  19. expect(arc.inLabelRange(2)).toBe(false);
  20. // Mock out the view as if the controller put it there
  21. arc._view = {
  22. startAngle: 0,
  23. endAngle: Math.PI / 2,
  24. x: 0,
  25. y: 0,
  26. innerRadius: 5,
  27. outerRadius: 10,
  28. };
  29. expect(arc.inRange(2, 2)).toBe(false);
  30. expect(arc.inRange(7, 0)).toBe(true);
  31. expect(arc.inRange(0, 11)).toBe(false);
  32. expect(arc.inRange(Math.sqrt(32), Math.sqrt(32))).toBe(true);
  33. expect(arc.inRange(-1.0 * Math.sqrt(7), Math.sqrt(7))).toBe(false);
  34. });
  35. it ('should get the tooltip position', function() {
  36. var arc = new Chart.elements.Arc({
  37. _datasetIndex: 2,
  38. _index: 1
  39. });
  40. // Mock out the view as if the controller put it there
  41. arc._view = {
  42. startAngle: 0,
  43. endAngle: Math.PI / 2,
  44. x: 0,
  45. y: 0,
  46. innerRadius: 0,
  47. outerRadius: Math.sqrt(2),
  48. };
  49. var pos = arc.tooltipPosition();
  50. expect(pos.x).toBeCloseTo(0.5);
  51. expect(pos.y).toBeCloseTo(0.5);
  52. });
  53. it ('should get the area', function() {
  54. var arc = new Chart.elements.Arc({
  55. _datasetIndex: 2,
  56. _index: 1
  57. });
  58. // Mock out the view as if the controller put it there
  59. arc._view = {
  60. startAngle: 0,
  61. endAngle: Math.PI / 2,
  62. x: 0,
  63. y: 0,
  64. innerRadius: 0,
  65. outerRadius: Math.sqrt(2),
  66. };
  67. expect(arc.getArea()).toBeCloseTo(0.5 * Math.PI, 6);
  68. });
  69. it ('should get the center', function() {
  70. var arc = new Chart.elements.Arc({
  71. _datasetIndex: 2,
  72. _index: 1
  73. });
  74. // Mock out the view as if the controller put it there
  75. arc._view = {
  76. startAngle: 0,
  77. endAngle: Math.PI / 2,
  78. x: 0,
  79. y: 0,
  80. innerRadius: 0,
  81. outerRadius: Math.sqrt(2),
  82. };
  83. var center = arc.getCenterPoint();
  84. expect(center.x).toBeCloseTo(0.5, 6);
  85. expect(center.y).toBeCloseTo(0.5, 6);
  86. });
  87. });