mxLine.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxLine
  7. *
  8. * Extends <mxShape> to implement a horizontal line shape.
  9. * This shape is registered under <mxConstants.SHAPE_LINE> in
  10. * <mxCellRenderer>.
  11. *
  12. * Constructor: mxLine
  13. *
  14. * Constructs a new line shape.
  15. *
  16. * Parameters:
  17. *
  18. * bounds - <mxRectangle> that defines the bounds. This is stored in
  19. * <mxShape.bounds>.
  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 mxLine(bounds, stroke, strokewidth, vertical)
  26. {
  27. mxShape.call(this);
  28. this.bounds = bounds;
  29. this.stroke = stroke;
  30. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  31. this.vertical = (vertical != null) ? vertical : this.vertical;
  32. };
  33. /**
  34. * Extends mxShape.
  35. */
  36. mxUtils.extend(mxLine, mxShape);
  37. /**
  38. * Function: vertical
  39. *
  40. * Whether to paint a vertical line.
  41. */
  42. mxLine.prototype.vertical = false;
  43. /**
  44. * Function: paintVertexShape
  45. *
  46. * Redirects to redrawPath for subclasses to work.
  47. */
  48. mxLine.prototype.paintVertexShape = function(c, x, y, w, h)
  49. {
  50. c.begin();
  51. if (this.vertical)
  52. {
  53. var mid = x + w / 2;
  54. c.moveTo(mid, y);
  55. c.lineTo(mid, y + h);
  56. }
  57. else
  58. {
  59. var mid = y + h / 2;
  60. c.moveTo(x, mid);
  61. c.lineTo(x + w, mid);
  62. }
  63. c.stroke();
  64. };
  65. __mxOutput.mxLine = typeof mxLine !== 'undefined' ? mxLine : undefined;