Graph Rendering API

Use case or problem

I would like to develop a plugin which relabels nodes in the graph to use their alias(es) instead of the file name so that I can use zettlecasten-style names and still have a graph that makes sense (plus, aliases allow me to use symbols which file systems don’t like).

However, there does not appear to be an API to interact with the graph.

Proposed solution

I imagine that the existing solution has a worker which loads the notes, filters them based on what the user has selected in the “Filters” menu, and then passes them to PIXI for rendering.

I think a relatively simple solution would be to add hooks that the developer could override to add additional filters and transformations. For example:


function customTransform(node) { // defaults to a no-op, (i.e. "return node")
  node.title = node.meta.alias || node.title;
}

function customFilter(node) { // defaults to a no-op, (i.e. "return true")
  return true;
}

const nodes = worker.loadData()
                    .filter(byDefaultFilters)
                    .filter(customFilter)
                    .map(customTransform);
view.render(nodes);

Current workaround (optional)

I haven’t been able to find one so far.

Related feature requests (optional)

This need has been raised a few times in the Developers & API section:

Graph view is a very complicated plugin internally, which is why there is no API currently, and there might never be one.