c3-helper.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import c3 from '../src';
  2. window.c3 = c3;
  3. window.initDom = function () {
  4. 'use strict';
  5. var div = document.createElement('div');
  6. div.id = 'chart';
  7. div.style.width = '640px';
  8. div.style.height = '480px';
  9. document.body.appendChild(div);
  10. document.body.style.margin = '0px';
  11. };
  12. window.setMouseEvent = function(chart, name, x, y, element) {
  13. 'use strict';
  14. var paddingLeft = chart.internal.main.node().transform.baseVal.getItem(0).matrix.e,
  15. event = document.createEvent("MouseEvents");
  16. event.initMouseEvent(name, true, true, window,
  17. 0, 0, 0, x + paddingLeft, y + 5,
  18. false, false, false, false, 0, null);
  19. if (element) { element.dispatchEvent(event); }
  20. };
  21. window.initChart = function (chart, args, done) {
  22. 'use strict';
  23. if (typeof chart === 'undefined') {
  24. window.initDom();
  25. }
  26. if (args) {
  27. chart = window.c3.generate(args);
  28. window.d3 = chart.internal.d3;
  29. window.d3.select('.jasmine_html-reporter')
  30. .style('position', 'absolute')
  31. .style('width', '640px')
  32. .style('right', 0);
  33. }
  34. window.setTimeout(function () {
  35. done();
  36. }, 10);
  37. return chart;
  38. };