mxDoubleEllipse.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxDoubleEllipse
  7. *
  8. * Extends <mxShape> to implement a double ellipse shape. This shape is
  9. * registered under <mxConstants.SHAPE_DOUBLE_ELLIPSE> in <mxCellRenderer>.
  10. * Use the following override to only fill the inner ellipse in this shape:
  11. *
  12. * (code)
  13. * mxDoubleEllipse.prototype.paintVertexShape = function(c, x, y, w, h)
  14. * {
  15. * c.ellipse(x, y, w, h);
  16. * c.stroke();
  17. *
  18. * var inset = mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth, Math.min(w / 5, h / 5)));
  19. * x += inset;
  20. * y += inset;
  21. * w -= 2 * inset;
  22. * h -= 2 * inset;
  23. *
  24. * if (w > 0 && h > 0)
  25. * {
  26. * c.ellipse(x, y, w, h);
  27. * }
  28. *
  29. * c.fillAndStroke();
  30. * };
  31. * (end)
  32. *
  33. * Constructor: mxDoubleEllipse
  34. *
  35. * Constructs a new ellipse shape.
  36. *
  37. * Parameters:
  38. *
  39. * bounds - <mxRectangle> that defines the bounds. This is stored in
  40. * <mxShape.bounds>.
  41. * fill - String that defines the fill color. This is stored in <fill>.
  42. * stroke - String that defines the stroke color. This is stored in <stroke>.
  43. * strokewidth - Optional integer that defines the stroke width. Default is
  44. * 1. This is stored in <strokewidth>.
  45. */
  46. function mxDoubleEllipse(bounds, fill, stroke, strokewidth)
  47. {
  48. mxShape.call(this);
  49. this.bounds = bounds;
  50. this.fill = fill;
  51. this.stroke = stroke;
  52. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  53. };
  54. /**
  55. * Extends mxShape.
  56. */
  57. mxUtils.extend(mxDoubleEllipse, mxShape);
  58. /**
  59. * Variable: vmlScale
  60. *
  61. * Scale for improving the precision of VML rendering. Default is 10.
  62. */
  63. mxDoubleEllipse.prototype.vmlScale = 10;
  64. /**
  65. * Function: paintBackground
  66. *
  67. * Paints the background.
  68. */
  69. mxDoubleEllipse.prototype.paintBackground = function(c, x, y, w, h)
  70. {
  71. c.ellipse(x, y, w, h);
  72. c.fillAndStroke();
  73. };
  74. /**
  75. * Function: paintForeground
  76. *
  77. * Paints the foreground.
  78. */
  79. mxDoubleEllipse.prototype.paintForeground = function(c, x, y, w, h)
  80. {
  81. if (!this.outline)
  82. {
  83. var margin = mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth, Math.min(w / 5, h / 5)));
  84. x += margin;
  85. y += margin;
  86. w -= 2 * margin;
  87. h -= 2 * margin;
  88. // FIXME: Rounding issues in IE8 standards mode (not in 1.x)
  89. if (w > 0 && h > 0)
  90. {
  91. c.ellipse(x, y, w, h);
  92. }
  93. c.stroke();
  94. }
  95. };
  96. /**
  97. * Function: getLabelBounds
  98. *
  99. * Returns the bounds for the label.
  100. */
  101. mxDoubleEllipse.prototype.getLabelBounds = function(rect)
  102. {
  103. var margin = (mxUtils.getValue(this.style, mxConstants.STYLE_MARGIN, Math.min(3 + this.strokewidth,
  104. Math.min(rect.width / 5 / this.scale, rect.height / 5 / this.scale)))) * this.scale;
  105. return new mxRectangle(rect.x + margin, rect.y + margin, rect.width - 2 * margin, rect.height - 2 * margin);
  106. };
  107. __mxOutput.mxDoubleEllipse = typeof mxDoubleEllipse !== 'undefined' ? mxDoubleEllipse : undefined;