Version 3.18.1
Show:

File: graphics/js/CanvasPath.js

  1. /**
  2. * <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> implementation of the <a href="Path.html">`Path`</a> class.
  3. * `CanvasPath` is not intended to be used directly. Instead, use the <a href="Path.html">`Path`</a> class.
  4. * If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities but has
  5. * <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> capabilities, the <a href="Path.html">`Path`</a>
  6. * class will point to the `CanvasPath` class.
  7. *
  8. * @module graphics
  9. * @class CanvasPath
  10. * @extends CanvasShape
  11. */
  12. CanvasPath = function()
  13. {
  14. CanvasPath.superclass.constructor.apply(this, arguments);
  15. };
  16. CanvasPath.NAME = "path";
  17. Y.extend(CanvasPath, Y.CanvasShape, {
  18. /**
  19. * Indicates the type of shape
  20. *
  21. * @property _type
  22. * @type String
  23. * @private
  24. */
  25. _type: "path",
  26. /**
  27. * Draws the shape.
  28. *
  29. * @method _draw
  30. * @private
  31. */
  32. _draw: function()
  33. {
  34. this._closePath();
  35. this._updateTransform();
  36. },
  37. /**
  38. * Creates the dom node for the shape.
  39. *
  40. * @method createNode
  41. * @return HTMLElement
  42. * @private
  43. */
  44. createNode: function()
  45. {
  46. var host = this,
  47. node = Y.config.doc.createElement('canvas'),
  48. name = host.name,
  49. concat = host._camelCaseConcat,
  50. id = host.get("id");
  51. host._context = node.getContext('2d');
  52. node.setAttribute("overflow", "visible");
  53. node.setAttribute("pointer-events", "none");
  54. node.style.pointerEvents = "none";
  55. node.style.overflow = "visible";
  56. node.setAttribute("id", id);
  57. id = "#" + id;
  58. host.node = node;
  59. host.addClass(
  60. _getClassName(SHAPE) +
  61. " " +
  62. _getClassName(concat(IMPLEMENTATION, SHAPE)) +
  63. " " +
  64. _getClassName(name) +
  65. " " +
  66. _getClassName(concat(IMPLEMENTATION, name))
  67. );
  68. },
  69. /**
  70. * Completes a drawing operation.
  71. *
  72. * @method end
  73. */
  74. end: function()
  75. {
  76. this._draw();
  77. return this;
  78. }
  79. });
  80. CanvasPath.ATTRS = Y.merge(Y.CanvasShape.ATTRS, {
  81. /**
  82. * Indicates the width of the shape
  83. *
  84. * @config width
  85. * @type Number
  86. */
  87. width: {
  88. getter: function()
  89. {
  90. var offset = this._stroke && this._strokeWeight ? (this._strokeWeight * 2) : 0;
  91. return this._width - offset;
  92. },
  93. setter: function(val)
  94. {
  95. this._width = val;
  96. return val;
  97. }
  98. },
  99. /**
  100. * Indicates the height of the shape
  101. *
  102. * @config height
  103. * @type Number
  104. */
  105. height: {
  106. getter: function()
  107. {
  108. var offset = this._stroke && this._strokeWeight ? (this._strokeWeight * 2) : 0;
  109. return this._height - offset;
  110. },
  111. setter: function(val)
  112. {
  113. this._height = val;
  114. return val;
  115. }
  116. },
  117. /**
  118. * Indicates the path used for the node.
  119. *
  120. * @config path
  121. * @type String
  122. * @readOnly
  123. */
  124. path: {
  125. readOnly: true,
  126. getter: function()
  127. {
  128. return this._path;
  129. }
  130. }
  131. });
  132. Y.CanvasPath = CanvasPath;