abstract-canvas-element.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Implements abstract vector canvas.
  3. * @constructor
  4. * @param {HTMLElement} container Container to put element to.
  5. * @param {Number} width Width of canvas.
  6. * @param {Number} height Height of canvas.
  7. */
  8. jvm.AbstractCanvasElement = function(container, width, height){
  9. this.container = container;
  10. this.setSize(width, height);
  11. this.rootElement = new jvm[this.classPrefix+'GroupElement']();
  12. this.node.appendChild( this.rootElement.node );
  13. this.container.appendChild(this.node);
  14. }
  15. /**
  16. * Add element to the certain group inside of the canvas.
  17. * @param {HTMLElement} element Element to add to canvas.
  18. * @param {HTMLElement} group Group to add element into or into root group if not provided.
  19. */
  20. jvm.AbstractCanvasElement.prototype.add = function(element, group){
  21. group = group || this.rootElement;
  22. group.add(element);
  23. element.canvas = this;
  24. }
  25. /**
  26. * Create path and add it to the canvas.
  27. * @param {Object} config Parameters of path to create.
  28. * @param {Object} style Styles of the path to create.
  29. * @param {HTMLElement} group Group to add path into.
  30. */
  31. jvm.AbstractCanvasElement.prototype.addPath = function(config, style, group){
  32. var el = new jvm[this.classPrefix+'PathElement'](config, style);
  33. this.add(el, group);
  34. return el;
  35. };
  36. /**
  37. * Create circle and add it to the canvas.
  38. * @param {Object} config Parameters of path to create.
  39. * @param {Object} style Styles of the path to create.
  40. * @param {HTMLElement} group Group to add circle into.
  41. */
  42. jvm.AbstractCanvasElement.prototype.addCircle = function(config, style, group){
  43. var el = new jvm[this.classPrefix+'CircleElement'](config, style);
  44. this.add(el, group);
  45. return el;
  46. };
  47. /**
  48. * Add group to the another group inside of the canvas.
  49. * @param {HTMLElement} group Group to add circle into or root group if not provided.
  50. */
  51. jvm.AbstractCanvasElement.prototype.addGroup = function(parentGroup){
  52. var el = new jvm[this.classPrefix+'GroupElement']();
  53. if (parentGroup) {
  54. parentGroup.node.appendChild(el.node);
  55. } else {
  56. this.node.appendChild(el.node);
  57. }
  58. el.canvas = this;
  59. return el;
  60. };