area.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div style="margin-top: 10px;">
  3. <canvas :id="id" width="740" height="400"/>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { SGraphAreaGroupItem, SGraphScene, SGraphView } from "@persagy-web/graph/lib";
  8. import { Component, Vue } from "vue-property-decorator";
  9. import { v1 as uuid } from "uuid";
  10. /**
  11. * 区域组
  12. *
  13. * @author 郝洁 <haojie@persagy.com>
  14. */
  15. @Component
  16. export default class AreaCanvas extends Vue {
  17. /** 图 id */
  18. id: string = uuid();
  19. /** 实例化 view */
  20. view: SGraphView | undefined;
  21. areaData = {
  22. outline: [
  23. [
  24. [{x: 0, y: 0}, {x: 0, y: 1000}, {x: 1000, y: 1000}, {x: 1000, y: 0}],
  25. [{x: 200, y: 200}, {x: 800, y: 200}, {x: 800, y: 800}, {x: 200, y: 800}]
  26. ],
  27. [
  28. [{x: 1000, y: 1000}, {x: 1200, y: 1000}, {x: 1200, y: 1200}, {x: 1000, y: 1200}]
  29. ]
  30. ],
  31. style: {
  32. "default": {
  33. "stroke": "#cccccc",
  34. "fill": "SLinearGradient{0,0;0,1200;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  35. "lineWidth": 2,
  36. "effect": {}
  37. },
  38. "selected": {
  39. "stroke": "#66ff66",
  40. "fill": "SRadialGradient{500,500,50;500,500,800;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  41. "lineWidth": 3,
  42. "effect": {}
  43. },
  44. "disabled": {
  45. "stroke": "#333333",
  46. "fill": "#afafaf",
  47. "lineWidth": 1,
  48. "effect": {}
  49. },
  50. }
  51. };
  52. /**
  53. * 页面挂载
  54. */
  55. mounted() {
  56. this.init();
  57. };
  58. /**
  59. * 初始化加载
  60. */
  61. init() {
  62. this.view = new SGraphView(this.id);
  63. const scene = new SGraphScene();
  64. const item = new SGraphAreaGroupItem(null, this.areaData);
  65. item.selectable = true;
  66. item._resizeable = false;
  67. scene.addItem(item);
  68. this.view.scene = scene;
  69. this.view.fitSceneToView();
  70. this.view.scalable = false;
  71. }
  72. }
  73. </script>
  74. <style scoped>
  75. </style>