mxPolyline.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxPolyline
  7. *
  8. * Extends <mxShape> to implement a polyline (a line with multiple points).
  9. * This shape is registered under <mxConstants.SHAPE_POLYLINE> in
  10. * <mxCellRenderer>.
  11. *
  12. * Constructor: mxPolyline
  13. *
  14. * Constructs a new polyline shape.
  15. *
  16. * Parameters:
  17. *
  18. * points - Array of <mxPoints> that define the points. This is stored in
  19. * <mxShape.points>.
  20. * stroke - String that defines the stroke color. Default is 'black'. This is
  21. * stored in <stroke>.
  22. * strokewidth - Optional integer that defines the stroke width. Default is
  23. * 1. This is stored in <strokewidth>.
  24. */
  25. function mxPolyline(points, stroke, strokewidth)
  26. {
  27. mxShape.call(this);
  28. this.points = points;
  29. this.stroke = stroke;
  30. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  31. };
  32. /**
  33. * Extends mxShape.
  34. */
  35. mxUtils.extend(mxPolyline, mxShape);
  36. /**
  37. * Function: getRotation
  38. *
  39. * Returns 0.
  40. */
  41. mxPolyline.prototype.getRotation = function()
  42. {
  43. return 0;
  44. };
  45. /**
  46. * Function: getShapeRotation
  47. *
  48. * Returns 0.
  49. */
  50. mxPolyline.prototype.getShapeRotation = function()
  51. {
  52. return 0;
  53. };
  54. /**
  55. * Function: isPaintBoundsInverted
  56. *
  57. * Returns false.
  58. */
  59. mxPolyline.prototype.isPaintBoundsInverted = function()
  60. {
  61. return false;
  62. };
  63. /**
  64. * Function: paintEdgeShape
  65. *
  66. * Paints the line shape.
  67. */
  68. mxPolyline.prototype.paintEdgeShape = function(c, pts)
  69. {
  70. var prev = c.pointerEventsValue;
  71. c.pointerEventsValue = 'stroke';
  72. if (this.style == null || this.style[mxConstants.STYLE_CURVED] != 1)
  73. {
  74. this.paintLine(c, pts, this.isRounded);
  75. }
  76. else
  77. {
  78. this.paintCurvedLine(c, pts);
  79. }
  80. c.pointerEventsValue = prev;
  81. };
  82. /**
  83. * Function: paintLine
  84. *
  85. * Paints the line shape.
  86. */
  87. mxPolyline.prototype.paintLine = function(c, pts, rounded)
  88. {
  89. var arcSize = mxUtils.getValue(this.style, mxConstants.STYLE_ARCSIZE, mxConstants.LINE_ARCSIZE) / 2;
  90. c.begin();
  91. this.addPoints(c, pts, rounded, arcSize, false);
  92. c.stroke();
  93. };
  94. /**
  95. * Function: paintCurvedLine
  96. *
  97. * Paints a curved line.
  98. */
  99. mxPolyline.prototype.paintCurvedLine = function(c, pts)
  100. {
  101. c.begin();
  102. var pt = pts[0];
  103. var n = pts.length;
  104. c.moveTo(pt.x, pt.y);
  105. for (var i = 1; i < n - 2; i++)
  106. {
  107. var p0 = pts[i];
  108. var p1 = pts[i + 1];
  109. var ix = (p0.x + p1.x) / 2;
  110. var iy = (p0.y + p1.y) / 2;
  111. c.quadTo(p0.x, p0.y, ix, iy);
  112. }
  113. var p0 = pts[n - 2];
  114. var p1 = pts[n - 1];
  115. c.quadTo(p0.x, p0.y, p1.x, p1.y);
  116. c.stroke();
  117. };
  118. __mxOutput.mxPolyline = typeof mxPolyline !== 'undefined' ? mxPolyline : undefined;