api.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Graph } from '@antv/x6'
  2. import { Export } from './index'
  3. declare module '@antv/x6/lib/graph/graph' {
  4. interface Graph {
  5. toSVG: (
  6. callback: Export.ToSVGCallback,
  7. options?: Export.ToSVGOptions,
  8. ) => void
  9. toPNG: (
  10. callback: Export.ToSVGCallback,
  11. options?: Export.ToImageOptions,
  12. ) => void
  13. toJPEG: (
  14. callback: Export.ToSVGCallback,
  15. options?: Export.ToImageOptions,
  16. ) => void
  17. exportPNG: (fileName?: string, options?: Export.ToImageOptions) => void
  18. exportJPEG: (fileName?: string, options?: Export.ToImageOptions) => void
  19. exportSVG: (fileName?: string, options?: Export.ToSVGOptions) => void
  20. }
  21. }
  22. Graph.prototype.toSVG = function (
  23. callback: Export.ToSVGCallback,
  24. options?: Export.ToSVGOptions,
  25. ) {
  26. const instance = this.getPlugin('export') as Export
  27. if (instance) {
  28. instance.toSVG(callback, options)
  29. }
  30. }
  31. Graph.prototype.toPNG = function (
  32. callback: Export.ToSVGCallback,
  33. options?: Export.ToImageOptions,
  34. ) {
  35. const instance = this.getPlugin('export') as Export
  36. if (instance) {
  37. instance.toPNG(callback, options)
  38. }
  39. }
  40. Graph.prototype.toJPEG = function (
  41. callback: Export.ToSVGCallback,
  42. options?: Export.ToImageOptions,
  43. ) {
  44. const instance = this.getPlugin('export') as Export
  45. if (instance) {
  46. instance.toJPEG(callback, options)
  47. }
  48. }
  49. Graph.prototype.exportPNG = function (
  50. fileName?: string,
  51. options?: Export.ToImageOptions,
  52. ) {
  53. const instance = this.getPlugin('export') as Export
  54. if (instance) {
  55. instance.exportPNG(fileName, options)
  56. }
  57. }
  58. Graph.prototype.exportJPEG = function (
  59. fileName?: string,
  60. options?: Export.ToImageOptions,
  61. ) {
  62. const instance = this.getPlugin('export') as Export
  63. if (instance) {
  64. instance.exportJPEG(fileName, options)
  65. }
  66. }
  67. Graph.prototype.exportSVG = function (
  68. fileName?: string,
  69. options?: Export.ToSVGOptions,
  70. ) {
  71. const instance = this.getPlugin('export') as Export
  72. if (instance) {
  73. instance.exportSVG(fileName, options)
  74. }
  75. }