SGraphLineItem.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SColor, SPainter, SPen, SRect } from "@persagy-web/draw";
  27. import { SGraphItem } from "../SGraphItem";
  28. /**
  29. * 线 Item 类
  30. *
  31. * @author 庞利祥 <sybotan@126.com>
  32. */
  33. export class SGraphLineItem extends SGraphItem {
  34. /** 点 1 的 x 坐标 */
  35. x1: number;
  36. /** 点 1 的 y 坐标 */
  37. y1: number;
  38. /** 点 2 的 x 坐标 */
  39. x2: number;
  40. /** 点 2 的 y 坐标 */
  41. y2: number;
  42. /** 线条颜色 */
  43. color: SColor = SColor.Black;
  44. /** 线条宽度 */
  45. width: number = 1;
  46. /**
  47. * 构造函数
  48. *
  49. * @param x1 线的起始 x 坐标
  50. * @param y1 线的起始 y 坐标
  51. * @param x2 线的终止 x 坐标
  52. * @param y2 线的终止 y 坐标
  53. * @param width 线的宽度
  54. * @param color 线的颜色
  55. * @param parent 是否为虚线
  56. */
  57. constructor(
  58. parent: SGraphItem | null,
  59. x1: number,
  60. y1: number,
  61. x2: number,
  62. y2: number,
  63. color: SColor = SColor.Black,
  64. width: number = 1
  65. ) {
  66. super(parent);
  67. this.x1 = x1;
  68. this.y1 = y1;
  69. this.x2 = x2;
  70. this.y2 = y2;
  71. } // Constructor()
  72. /**
  73. * Item 对象边界区域
  74. *
  75. * @return 边界区域
  76. */
  77. boundingRect(): SRect {
  78. let minX = Math.min(this.x1, this.x2);
  79. let minY = Math.min(this.y1, this.y2);
  80. let maxX = Math.max(this.x1, this.x2);
  81. let maxY = Math.max(this.y1, this.y2);
  82. return new SRect(
  83. minX - this.width / 2,
  84. minY - this.width / 2,
  85. maxX - minX + this.width,
  86. maxY - minY + this.width
  87. );
  88. } // Function boundingRect()
  89. /**
  90. * 绘制 Item
  91. *
  92. * @param painter 绘制对象
  93. */
  94. onDraw(painter: SPainter): void {
  95. painter.pen = new SPen(this.color, this.width);
  96. painter.drawLine(this.x1, this.y1, this.x2, this.y2);
  97. } // Function onDraw()
  98. } // Class SGraphLineItem