area.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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: string = uuid();
  18. view: SGraphView | undefined;
  19. areaData = {
  20. outline: [
  21. [
  22. [{x: 0, y: 0}, {x: 0, y: 1000}, {x: 1000, y: 1000}, {x: 1000, y: 0}],
  23. [{x: 200, y: 200}, {x: 800, y: 200}, {x: 800, y: 800}, {x: 200, y: 800}]
  24. ],
  25. [
  26. [{x: 1000, y: 1000}, {x: 1200, y: 1000}, {x: 1200, y: 1200}, {x: 1000, y: 1200}]
  27. ]
  28. ],
  29. style: {
  30. "default": {
  31. "stroke": "#cccccc",
  32. "fill": "SLinearGradient{0,0;0,1200;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  33. "lineWidth": 2,
  34. "effect": {}
  35. },
  36. "selected": {
  37. "stroke": "#66ff66",
  38. "fill": "SRadialGradient{500,500,50;500,500,800;0,#ff483bff;0.5,#04ff00ff;1,#3d4effff;}",
  39. "lineWidth": 3,
  40. "effect": {}
  41. },
  42. "disabled": {
  43. "stroke": "#333333",
  44. "fill": "#afafaf",
  45. "lineWidth": 1,
  46. "effect": {}
  47. },
  48. }
  49. };
  50. mounted() {
  51. this.init();
  52. };
  53. init() {
  54. this.view = new SGraphView(this.id);
  55. const scene = new SGraphScene();
  56. const item = new SGraphAreaGroupItem(null, this.areaData);
  57. item.selectable = true;
  58. item._resizeable = false;
  59. scene.addItem(item);
  60. this.view.scene = scene;
  61. this.view.fitSceneToView();
  62. this.view.scalable = false;
  63. }
  64. }
  65. </script>
  66. <style scoped>
  67. </style>