controller.scatter.test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. describe('Chart.controllers.scatter', function() {
  2. it('should be registered as dataset controller', function() {
  3. expect(typeof Chart.controllers.scatter).toBe('function');
  4. });
  5. it('should test default tooltip callbacks', function() {
  6. var chart = window.acquireChart({
  7. type: 'scatter',
  8. data: {
  9. datasets: [{
  10. data: [{
  11. x: 10,
  12. y: 15
  13. }],
  14. label: 'dataset1'
  15. }],
  16. },
  17. options: {}
  18. });
  19. var point = chart.getDatasetMeta(0).data[0];
  20. jasmine.triggerMouseEvent(chart, 'mousemove', point);
  21. // Title should be empty
  22. expect(chart.tooltip._view.title.length).toBe(0);
  23. expect(chart.tooltip._view.body[0].lines).toEqual(['(10, 15)']);
  24. });
  25. describe('showLines option', function() {
  26. it('should not draw a line if undefined', function() {
  27. var chart = window.acquireChart({
  28. type: 'scatter',
  29. data: {
  30. datasets: [{
  31. data: [{x: 10, y: 15}],
  32. label: 'dataset1'
  33. }],
  34. },
  35. options: {}
  36. });
  37. var meta = chart.getDatasetMeta(0);
  38. spyOn(meta.dataset, 'draw');
  39. spyOn(meta.data[0], 'draw');
  40. chart.update();
  41. expect(meta.dataset.draw.calls.count()).toBe(0);
  42. expect(meta.data[0].draw.calls.count()).toBe(1);
  43. });
  44. it('should draw a line if true', function() {
  45. var chart = window.acquireChart({
  46. type: 'scatter',
  47. data: {
  48. datasets: [{
  49. data: [{x: 10, y: 15}],
  50. showLine: true,
  51. label: 'dataset1'
  52. }],
  53. },
  54. options: {}
  55. });
  56. var meta = chart.getDatasetMeta(0);
  57. spyOn(meta.dataset, 'draw');
  58. spyOn(meta.data[0], 'draw');
  59. chart.update();
  60. expect(meta.dataset.draw.calls.count()).toBe(1);
  61. expect(meta.data[0].draw.calls.count()).toBe(1);
  62. });
  63. });
  64. });