polygon.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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: SGraphView | undefined;
  36. item: Expolygon | undefined;
  37. id: string = uuid();
  38. rectData = {
  39. outline: [
  40. [{x: 0, y: 0}, {x: 0, y: 1000}, {x: 700, y: 1500}, {x: 500, y: 1000}, {x: 200, y: 0}],
  41. [{x: 1000, y: 1000}, {x: 1200, y: 1000}, {x: 1200, y: 1200}, {x: 1000, y: 1200}]
  42. ],
  43. style: {
  44. "default": {
  45. "stroke": "#cccccc",
  46. "fill": "SLinearGradient{0,0;0,1000;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  47. "lineWidth": 2,
  48. "effect": {}
  49. },
  50. "selected": {
  51. "stroke": "#66ff66",
  52. "fill": "SRadialGradient{500,500,50;500,500,500;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  53. "lineWidth": 3,
  54. "effect": {}
  55. },
  56. "disabled": {
  57. "stroke": "#333333",
  58. "fill": "#afafaf",
  59. "lineWidth": 1,
  60. "effect": {}
  61. },
  62. }
  63. };
  64. mounted() {
  65. this.init();
  66. };
  67. init() {
  68. this.view = new SGraphView(this.id);
  69. const scene = new SGraphScene();
  70. this.item = new Expolygon(null, this.rectData);
  71. this.item.selectable = true;
  72. scene.addItem(this.item);
  73. this.view.scene = scene;
  74. this.view.fitSceneToView();
  75. this.view.scalable = false;
  76. };
  77. changeEnable() {
  78. if (this.item) {
  79. this.item.enabled = !this.item.enabled;
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. </style>