STextMarkerItem.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { SGraphItem, STextItem } from "@saga-web/graph/lib";
  2. import { SPainter, SColor } from "@saga-web/draw";
  3. import { Marker } from '../types/Marker';
  4. import { SLineStyle } from '../enums/SLineStyle';
  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.Soild;
  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.data = data;
  40. this.id = data.ID;
  41. this.name = data.Name;
  42. this.moveTo(data.Pos.X, data.Pos.Y);
  43. if (data.Size) {
  44. this.width = data.Size.Width;
  45. this.height = data.Size.Height;
  46. }
  47. if (data.Properties && data.Properties.Text) {
  48. this.text = data.Properties.Text;
  49. }
  50. } // Constructor
  51. toData(): Marker {
  52. this.data.Pos = {X: this.x, Y: this.y};
  53. this.data.Size = {Width: this.width, Height: this.height};
  54. this.data.Properties.Text = this.text;
  55. return this.data;
  56. }
  57. /**
  58. * Item绘制操作
  59. *
  60. * @param painter 绘画类
  61. */
  62. onDraw(painter: SPainter): void {
  63. // 绘制文本
  64. painter.brush.color = new SColor(this.color);
  65. painter.font = this.font;
  66. if (this.borderStyle == SLineStyle.Dashed) {
  67. painter.pen.lineDash = [
  68. painter.toPx(this.lineWidth * 3),
  69. painter.toPx(this.lineWidth * 7)
  70. ];
  71. } else if (this.borderStyle == SLineStyle.Dotted) {
  72. painter.pen.lineDash = [
  73. painter.toPx(this.lineWidth),
  74. painter.toPx(this.lineWidth)
  75. ];
  76. }
  77. this.drawFormatText(painter);
  78. } // Function onDraw()
  79. } // Class STextMarkerItem