svg.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 */
  18. id: string = uuid();
  19. /** 实例化 view */
  20. view: SGraphView | undefined;
  21. svgData = {
  22. // https://desk-fd.zol-img.com.cn/t_s2560x1600c5/g6/M00/0B/0E/ChMkKV9N5U2IfX_aAA-zeHRQZW8AABvcADsv-0AD7OQ688.jpg
  23. // Url: 'https://cdn-img.easyicon.net/image/2019/panda-search.svg',
  24. url: require('../../../public/assets/img/1.svg'),
  25. x: 100,
  26. y: 100,
  27. width: 200,
  28. height: 200
  29. };
  30. /**
  31. * 页面挂载
  32. */
  33. private mounted(): void {
  34. this.init()
  35. };
  36. /**
  37. * 初始化加载
  38. */
  39. init(): void {
  40. this.view = new SGraphView(this.id);
  41. const scene = new SGraphScene();
  42. this.view.scene = scene;
  43. const item = new SGraphSvgItem(null, this.svgData);
  44. scene.addItem(item);
  45. // setInterval(() => {
  46. // item.width+=10;
  47. // item.height+=10;
  48. // },500)
  49. // this.view.fitSceneToView();
  50. };
  51. }
  52. </script>