Skip to content
ReferenceVersion 6.0.2

RFlow and useFlow ​

RFlow creates LogicFlow in its own DOM container. FlowGraphData has optional nodes and edges arrays. Both NodeConfig and EdgeConfig require stable IDs, and edge sources and targets must reference existing nodes.

Interactive example ​

View example source
tsx
import { useI18n } from '@/hooks'
import { RFlow, useFlow } from '@ray-template/ui/flow'
import { NButton, NCard, NFlex, NSwitch, NTag } from 'naive-ui'
import DemoPage from './components/DemoPage'
import DemoResult from './components/DemoResult'

export default defineComponent({
  name: 'RFlowDemo',
  setup() {
    const { t } = useI18n('demoDetails')
    const [register, { getFlowInstance }] = useFlow()
    const readonlyMode = ref(false)
    const canvasKey = ref(0)
    const ready = ref(false)
    const output = ref('')
    const graph = () => ({
      nodes: [
        { id: 'review', type: 'rect', x: 100, y: 105, text: t('flow.review') },
        { id: 'done', type: 'circle', x: 235, y: 215, text: t('flow.done') },
      ],
      edges: [
        {
          id: 'review-to-done',
          type: 'polyline',
          sourceNodeId: 'review',
          targetNodeId: 'done',
        },
      ],
    })

    return () => (
      <DemoPage title={t('flow.title')} description={t('flow.intro')}>
        <NCard title={t('flow.canvas')}>
          <div class="r-demo-card-stack">
            <NFlex align="center">
              <NSwitch
                v-model:value={readonlyMode.value}
                aria-label={t('flow.readonly')}
              />
              <NTag bordered={false}>
                {readonlyMode.value ? t('flow.readonly') : t('flow.editable')}
              </NTag>
              <NButton
                disabled={!ready.value}
                onClick={() => getFlowInstance().fitView(24, 24)}
              >
                {t('flow.fit')}
              </NButton>
              <NButton
                disabled={!ready.value}
                onClick={() => {
                  ready.value = false
                  output.value = ''
                  canvasKey.value += 1
                }}
              >
                {t('flow.reset')}
              </NButton>
              <NButton
                type="primary"
                secondary
                disabled={!ready.value}
                onClick={() => {
                  output.value = JSON.stringify(
                    getFlowInstance().getGraphData(),
                    null,
                    2,
                  )
                }}
              >
                {t('flow.inspect')}
              </NButton>
            </NFlex>
            <div class="r-demo-flow-canvas">
              <RFlow
                key={canvasKey.value}
                height={320}
                readonly={readonlyMode.value}
                onRegister={(flow) => {
                  register(flow)
                  flow.render(graph())
                  flow.fitView(24, 24)
                  ready.value = true
                }}
              />
            </div>
            {output.value && (
              <DemoResult label={t('flow.graph')}>
                <pre>{output.value}</pre>
              </DemoResult>
            )}
          </div>
        </NCard>
      </DemoPage>
    )
  },
})
tsx
import { RFlow } from '@/components'
import type LogicFlow from '@logicflow/core'
import { defineComponent } from 'vue'

const graph = {
  nodes: [
    { id: 'start', type: 'rect', x: 100, y: 90, text: 'Start' },
    { id: 'review', type: 'rect', x: 300, y: 90, text: 'Review' },
  ],
  edges: [
    {
      id: 'start-review',
      type: 'polyline',
      sourceNodeId: 'start',
      targetNodeId: 'review',
    },
  ],
} satisfies Parameters<LogicFlow['render']>[0]

export default defineComponent({
  setup: () => () => (
    <RFlow
      height={240}
      readonly
      onRegister={(instance) => instance.render(graph)}
    />
  ),
})
PropDefaultDescription
width / height'100%'Container dimensions. Give it a resolvable height.
dataNoneRenders on mount and when the reference changes. Setting it to undefined clears the graph. In-place nested mutation does not redraw it.
watchDatatrueWatches the supplied data. Disable it for instance-controlled rendering.
readonlyfalseEnables LogicFlow silent mode. Leaving restores the prior interaction and keyboard settings, including anything the caller disabled.
optionsGrid on, partial: false, keyboard onLogicFlow setup for size, background, keyboard, edges, interaction, history, and plugins. The component owns container.
useNoneRegisters the component's LogicFlow global plugins before initialization. LogicFlow deduplicates by name. Use options.plugins for instance-level plugins.
onRegister(instance)NoneProvides LogicFlow after mount. Accepts one callback or an array.

FlowOptions groups these fields by purpose.

  • Canvas and layout include width, height, background, grid, partial, style, and overlapMode.
  • Interaction includes keyboard, adjustEdge, allowRotate, allowResize, isSilentMode, stopScrollGraph, stopZoomGraph, stopMoveGraph, textEdit, textMode, edgeTextMode, nodeTextMode, and guards.
  • Edges and rendering include edgeType, customTrajectory, animation, history, outline, and snapline.
  • Extensions include plugins, pluginsOptions, disabledPlugins, disabledTools, idGenerator, and edgeGenerator.

Use FlowGraphData for the wrapper's props. For direct calls to instance.render, use Parameters<LogicFlow['render']>[0] to retain LogicFlow's required node types, coordinates, and connection fields.

useFlow() returns [register, { getFlowInstance }]. Pass register to onRegister and supply initial data through data. Calling getFlowInstance() before registration or after unmount throws. The component destroys the LogicFlow instance on unmount. Use that instance for programmatic editing, imports, and listeners, and clean up external resources you create.

Implementation · Graph and option types · Instance hook