summaryrefslogtreecommitdiff
path: root/util/normalizeLinkEnds.ts
blob: 43eee9c8cb13159616f4fd718ca16f17402c16f1 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
import { OrgRoamLink } from '../api'
import { LinkObject } from 'force-graph'

export function normalizeLinkEnds(link: OrgRoamLink | LinkObject): [string, string] {
  // we need to cover both because force-graph modifies the original data
  // but if we supply the original data on each render, the graph will re-render sporadically
  const sourceId =
    typeof link.source === 'object' ? (link.source.id! as string) : (link.source as string)
  const targetId =
    typeof link.target === 'object' ? (link.target.id! as string) : (link.target as string)
  return [sourceId, targetId]
}