mxActor.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxActor
  7. *
  8. * Extends <mxShape> to implement an actor shape. If a custom shape with one
  9. * filled area is needed, then this shape's <redrawPath> should be overridden.
  10. *
  11. * Example:
  12. *
  13. * (code)
  14. * function SampleShape() { }
  15. *
  16. * SampleShape.prototype = new mxActor();
  17. * SampleShape.prototype.constructor = vsAseShape;
  18. *
  19. * mxCellRenderer.registerShape('sample', SampleShape);
  20. * SampleShape.prototype.redrawPath = function(path, x, y, w, h)
  21. * {
  22. * path.moveTo(0, 0);
  23. * path.lineTo(w, h);
  24. * // ...
  25. * path.close();
  26. * }
  27. * (end)
  28. *
  29. * This shape is registered under <mxConstants.SHAPE_ACTOR> in
  30. * <mxCellRenderer>.
  31. *
  32. * Constructor: mxActor
  33. *
  34. * Constructs a new actor shape.
  35. *
  36. * Parameters:
  37. *
  38. * bounds - <mxRectangle> that defines the bounds. This is stored in
  39. * <mxShape.bounds>.
  40. * fill - String that defines the fill color. This is stored in <fill>.
  41. * stroke - String that defines the stroke color. This is stored in <stroke>.
  42. * strokewidth - Optional integer that defines the stroke width. Default is
  43. * 1. This is stored in <strokewidth>.
  44. */
  45. function mxActor(bounds, fill, stroke, strokewidth)
  46. {
  47. mxShape.call(this);
  48. this.bounds = bounds;
  49. this.fill = fill;
  50. this.stroke = stroke;
  51. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  52. };
  53. /**
  54. * Extends mxShape.
  55. */
  56. mxUtils.extend(mxActor, mxShape);
  57. /**
  58. * Function: paintVertexShape
  59. *
  60. * Redirects to redrawPath for subclasses to work.
  61. */
  62. mxActor.prototype.paintVertexShape = function(c, x, y, w, h)
  63. {
  64. c.translate(x, y);
  65. c.begin();
  66. this.redrawPath(c, x, y, w, h);
  67. c.fillAndStroke();
  68. };
  69. /**
  70. * Function: redrawPath
  71. *
  72. * Draws the path for this shape.
  73. */
  74. mxActor.prototype.redrawPath = function(c, x, y, w, h)
  75. {
  76. var width = w/3;
  77. c.moveTo(0, h);
  78. c.curveTo(0, 3 * h / 5, 0, 2 * h / 5, w / 2, 2 * h / 5);
  79. c.curveTo(w / 2 - width, 2 * h / 5, w / 2 - width, 0, w / 2, 0);
  80. c.curveTo(w / 2 + width, 0, w / 2 + width, 2 * h / 5, w / 2, 2 * h / 5);
  81. c.curveTo(w, 2 * h / 5, w, 3 * h / 5, w, h);
  82. c.close();
  83. };
  84. __mxOutput.mxActor = typeof mxActor !== 'undefined' ? mxActor : undefined;