Skip to content
Latestv1.0.63

Export ​

yh-flow provides comprehensive export functionality, supporting the export of flowcharts to JSON, PNG, SVG and other formats.

Exporting JSON ​

Basic Usage ​

typescript
const flowRef = ref<FlowInstance>()

// Export as JSON string
const json = flowRef.value.exportJson()
console.log(json)

Custom Export Data ​

Use exportFlowData to export complete data including viewport information:

typescript
import { exportFlowData } from '@yh-ui/flow'

const data = exportFlowData(nodes.value, edges.value, { x: 0, y: 0, zoom: 1 })
console.log(data) // JSON string

Exporting Images ​

Export as PNG ​

typescript
const flowRef = ref<FlowInstance>()

// Export as PNG
await flowRef.value.exportImage?.({
  imageType: 'png',
  fileName: 'flow-chart',
  download: true
})

Export as JPEG ​

typescript
await flowRef.value.exportImage?.({
  imageType: 'jpeg',
  imageQuality: 0.9,
  fileName: 'flow-chart',
  download: true
})

Export as SVG ​

SVG export allows exporting the flowchart as vector graphics:

typescript
// Get SVG string
const svgString = await captureFlowAsSvg(flowRef.value.$el)

// Or use plugin method
await flowRef.value.exportImage?.({
  // Future version support
})

Export Options ​

ScreenshotOptions ​

OptionTypeDefaultDescription
mode'viewport' | 'full''viewport'Export scope
imageType'png' | 'jpeg' | 'webp''png'Image format
imageQualitynumber1Image quality (0-1)
pixelRationumber2Device pixel ratio
backgroundColorstring'#ffffff'Background color
fileNamestring'flow-chart'File name
downloadbooleantrueTrigger download
copyToClipboardbooleanfalseCopy to clipboard
fullModePaddingnumber20Full mode padding

Export Modes ​

ModeDescription
viewportOnly export current visible area
fullExport complete flowchart (adjusts viewport automatically)

Complete Example ​

Export Toolbar Demo

Importing Data ​

Importing Data ​

Import from JSON ​

typescript
import { importFlowData } from '@yh-ui/flow'

const loadFromJson = (json: string) => {
  const data = importFlowData(json)
  if (data) {
    nodes.value = data.nodes
    edges.value = data.edges as unknown as Edge[]
    if (data.viewport) {
      viewport.value = data.viewport
    }
  }
}

Best Practices ​

  1. Maintain data persistence: Regularly export JSON as backup for data recovery
  2. Quality settings: Choose appropriate image quality and format based on use case
  3. User feedback: Export operations may take time, consider adding loading state
  4. Clipboard functionality: Use copyToClipboard in supported environments for better UX

TIP

Using mode: 'full' exports the complete flowchart even if the current viewport only shows partial content.

Released under the MIT License.