polygon.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div style="margin-top: 10px;">
  3. <el-button size="small" @click="changeEnable">切换item1禁用状态</el-button>
  4. <canvas :id="id" width="740" height="400"/>
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { SGraphPolyGroupItem, SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  9. import { SSize } from "@persagy-web/draw/lib";
  10. import { Component, Vue } from "vue-property-decorator";
  11. import { v1 as uuid } from "uuid";
  12. /**
  13. * 多边形组
  14. *
  15. * @author 郝洁 <haojie@persagy.com>
  16. */
  17. class Expolygon extends SGraphPolyGroupItem {
  18. resize(old: SSize, newS: SSize): void {
  19. const xs = newS.width / old.width;
  20. const ys = newS.height / old.height;
  21. // @ts-ignore
  22. this.pointList = this.pointList.map(t => {
  23. // @ts-ignore
  24. return t.map(item => {
  25. item.x = item.x * xs;
  26. item.y = item.y * ys;
  27. return item
  28. })
  29. });
  30. // console.log(this.pointList)
  31. }
  32. }
  33. @Component
  34. export default class ZoneCanvas extends Vue {
  35. /** 实例化 view */
  36. view: SGraphView | undefined;
  37. item: Expolygon | undefined;
  38. /** 图 id */
  39. id: string = uuid();
  40. rectData = {
  41. outline: [
  42. [{x: 0, y: 0}, {x: 0, y: 1000}, {x: 700, y: 1500}, {x: 500, y: 1000}, {x: 200, y: 0}],
  43. [{x: 1000, y: 1000}, {x: 1200, y: 1000}, {x: 1200, y: 1200}, {x: 1000, y: 1200}]
  44. ],
  45. style: {
  46. "default": {
  47. "stroke": "#cccccc",
  48. "fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  49. "lineWidth": 2,
  50. "effect": {}
  51. },
  52. "selected": {
  53. "stroke": "#66ff66",
  54. "fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  55. "lineWidth": 3,
  56. "effect": {}
  57. },
  58. "disabled": {
  59. "stroke": "#333333",
  60. "fill": "#afafaf",
  61. "lineWidth": 1,
  62. "effect": {}
  63. },
  64. }
  65. };
  66. /**
  67. * 页面挂载
  68. */
  69. mounted() {
  70. this.init();
  71. };
  72. /**
  73. * 初始化加载
  74. */
  75. init() {
  76. this.view = new SGraphView(this.id);
  77. const scene = new SGraphScene();
  78. this.item = new Expolygon(null, this.rectData);
  79. this.item.selectable = true;
  80. scene.addItem(this.item);
  81. this.view.scene = scene;
  82. this.view.fitSceneToView();
  83. this.view.scalable = false;
  84. };
  85. changeEnable() {
  86. if (this.item) {
  87. this.item.enabled = !this.item.enabled;
  88. }
  89. }
  90. }
  91. </script>
  92. <style scoped>
  93. </style>