mxRhombus.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxRhombus
  7. *
  8. * Extends <mxShape> to implement a rhombus (aka diamond) shape.
  9. * This shape is registered under <mxConstants.SHAPE_RHOMBUS>
  10. * in <mxCellRenderer>.
  11. *
  12. * Constructor: mxRhombus
  13. *
  14. * Constructs a new rhombus shape.
  15. *
  16. * Parameters:
  17. *
  18. * bounds - <mxRectangle> that defines the bounds. This is stored in
  19. * <mxShape.bounds>.
  20. * fill - String that defines the fill color. This is stored in <fill>.
  21. * stroke - String that defines the stroke color. This is stored in <stroke>.
  22. * strokewidth - Optional integer that defines the stroke width. Default is
  23. * 1. This is stored in <strokewidth>.
  24. */
  25. function mxRhombus(bounds, fill, stroke, strokewidth)
  26. {
  27. mxShape.call(this);
  28. this.bounds = bounds;
  29. this.fill = fill;
  30. this.stroke = stroke;
  31. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  32. };
  33. /**
  34. * Extends mxShape.
  35. */
  36. mxUtils.extend(mxRhombus, mxShape);
  37. /**
  38. * Function: isRoundable
  39. *
  40. * Adds roundable support.
  41. */
  42. mxRhombus.prototype.isRoundable = function()
  43. {
  44. return true;
  45. };
  46. /**
  47. * Function: paintVertexShape
  48. *
  49. * Generic painting implementation.
  50. */
  51. mxRhombus.prototype.paintVertexShape = function(c, x, y, w, h)
  52. {
  53. var hw = w / 2;
  54. var hh = h / 2;
  55. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  56. c.begin();
  57. this.addPoints(c, [new mxPoint(x + hw, y), new mxPoint(x + w, y + hh), new mxPoint(x + hw, y + h),
  58. new mxPoint(x, y + hh)], this.isRounded, arcSize, true);
  59. c.fillAndStroke();
  60. };
  61. __mxOutput.mxRhombus = typeof mxRhombus !== 'undefined' ? mxRhombus : undefined;