svg.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div>
  3. <canvas :id="id" width="800px" height="400px"></canvas>
  4. </div>
  5. </template>
  6. <script lang="ts">
  7. import { SGraphScene, SGraphSvgItem, SGraphView } from "@persagy-web/graph/lib";
  8. import { Component, Vue } from "vue-property-decorator";
  9. import { v1 as uuid } from "uuid";
  10. /**
  11. * SVG 图
  12. *
  13. * @author 郝洁 <haojie@persagy.com>
  14. */
  15. @Component
  16. export default class SvgCanvas extends Vue {
  17. id: string = uuid();
  18. view: SGraphView | undefined;
  19. svgData = {
  20. // https://desk-fd.zol-img.com.cn/t_s2560x1600c5/g6/M00/0B/0E/ChMkKV9N5U2IfX_aAA-zeHRQZW8AABvcADsv-0AD7OQ688.jpg
  21. // Url: 'https://cdn-img.easyicon.net/image/2019/panda-search.svg',
  22. url: require('../../../public/assets/img/1.svg'),
  23. x: 100,
  24. y: 100,
  25. width: 200,
  26. height: 200
  27. };
  28. /**
  29. * 页面挂载
  30. */
  31. private mounted(): void {
  32. this.init()
  33. };
  34. init(): void {
  35. this.view = new SGraphView(this.id);
  36. const scene = new SGraphScene();
  37. this.view.scene = scene;
  38. const item = new SGraphSvgItem(null, this.svgData);
  39. scene.addItem(item);
  40. // setInterval(() => {
  41. // item.width+=10;
  42. // item.height+=10;
  43. // },500)
  44. // this.view.fitSceneToView();
  45. };
  46. }
  47. </script>