STextMarkerItem.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { SGraphItem, STextItem, SLineStyle } from "@saga-web/graph/lib";
  2. import { SPainter, SColor,SFont } from "@saga-web/draw";
  3. import { Marker } from '../types/Marker';
  4. import { ItemOrder } from '@saga-web/big/lib';
  5. /**
  6. * 标识对象Item(文本类型)
  7. *
  8. * * @author 张宇(taohuzy@163.com)
  9. */
  10. export class STextMarkerItem extends STextItem {
  11. /** 标识对象数据 */
  12. data: Marker;
  13. /** 边框宽度 */
  14. private _lineWidth: number = 1;
  15. get lineWidth(): number {
  16. return this._lineWidth;
  17. }
  18. set lineWidth(v: number) {
  19. this._lineWidth = v;
  20. this.update();
  21. }
  22. /** 边框样式 */
  23. private _borderStyle: SLineStyle = SLineStyle.None;
  24. get borderStyle(): SLineStyle {
  25. return this._borderStyle;
  26. }
  27. set borderStyle(v: SLineStyle) {
  28. this._borderStyle = v;
  29. this.update();
  30. }
  31. /**
  32. * 构造函数
  33. *
  34. * @param parent 指向父对象
  35. * @param data 标识对象数据
  36. */
  37. constructor(parent: SGraphItem | null, data: Marker) {
  38. super(parent);
  39. this.zOrder = ItemOrder.textOrder;
  40. this.data = data;
  41. this.id = data.ID;
  42. this.name = data.Name;
  43. this.moveTo(data.Pos.X, data.Pos.Y);
  44. if (data.Size) {
  45. this.width = data.Size.Width;
  46. this.height = data.Size.Height;
  47. }
  48. if (data.Properties && data.Properties.Text) {
  49. this.text = data.Properties.Text;
  50. }
  51. if (data.Properties && data.Properties.Color) {
  52. this.color = data.Properties.Color
  53. }
  54. if (data.Properties && data.Properties.Font) {
  55. this.font = new SFont("sans-serif", data.Properties.Font);;
  56. }
  57. if (data.Properties && data.Properties.BackgroundColor) {
  58. this.backgroundColor = data.Properties.BackgroundColor
  59. }
  60. } // Constructor
  61. toData(): Marker {
  62. this.data.Pos = {X: this.x, Y: this.y};
  63. this.data.Size = {Width: this.width, Height: this.height};
  64. this.data.Properties.Text = this.text;
  65. this.data.Properties.Color = this.color;
  66. this.data.Properties.Font = this.font.size
  67. this.data.Properties.BackgroundColor = this.backgroundColor
  68. return this.data;
  69. }
  70. /**
  71. * Item绘制操作
  72. *
  73. * @param painter 绘画类
  74. */
  75. onDraw(painter: SPainter): void {
  76. // 绘制文本
  77. painter.brush.color = new SColor(this.color);
  78. painter.font = this.font;
  79. this.drawFormatText(painter);
  80. if (this.selected) {
  81. this.borderStyle = SLineStyle.Dashed;
  82. } else {
  83. this.borderStyle = SLineStyle.None;
  84. }
  85. if (this.borderStyle == SLineStyle.Dashed) {
  86. painter.pen.lineDash = [
  87. painter.toPx(this.lineWidth * 3),
  88. painter.toPx(this.lineWidth * 7)
  89. ];
  90. painter.brush.color = SColor.Transparent;
  91. painter.drawRect(this.boundingRect());
  92. } else if (this.borderStyle == SLineStyle.Dotted) {
  93. painter.pen.lineDash = [
  94. painter.toPx(this.lineWidth),
  95. painter.toPx(this.lineWidth)
  96. ];
  97. painter.brush.color = SColor.Transparent;
  98. painter.drawRect(this.boundingRect());
  99. } else if (this.borderStyle == SLineStyle.Soild) {
  100. painter.brush.color = SColor.Transparent;
  101. painter.drawRect(this.boundingRect());
  102. }
  103. } // Function onDraw()
  104. } // Class STextMarkerItem