filter

The filter namespace applies and manages visibility filters — predicates that hide nodes or edges without deleting them from the graph. Active filters compose: an element is visible only when every active filter passes.

Filters are different from style visibility (api.style.setCategoryVisibility): a filter is a named entry on the manager that returns a typed FilterHandle you keep around to update, invert, or remove it later. Filter ids are auto-generated (range-1, range-2, …) but you can supply your own via spec.id.

const ageFilter = api.filter.nodes.range({ property: "age", min: 18 });
// …later
ageFilter.update({ min: 21 });
ageFilter.invert();
ageFilter.remove();

Surface map

The namespace is split into three sub-namespaces (one per element kind plus playback) and a small set of cross-cutting operations.

Surface Purpose
nodes Build node-target filters: range, dateRange, match, predicate, degree.
edges Build edge-target filters: range, dateRange, match, predicate.
playback Animate range / dateRange filters: start, pause, resume, stop, isPlaying, progress.
any / all OR / AND-compose existing handles into a single group.
clear / list / matchCount / onChange Cross-cutting introspection and tear-down.

Targeting

Every filter targets either nodes or edges. Pick the sub-namespace that matches the element kind:

// Hide Person nodes whose age < 18
const adults = api.filter.nodes.range({
  property: "age",
  min: 18,
  on: "Person",   // scope to Person category only (omit for all)
});

// Hide WORKS_AT edges with low weight
const strong = api.filter.edges.range({
  property: "weight",
  min: 5,
  on: "WORKS_AT",
});

When a node is hidden by a filter, its incident edges are coupled hidden automatically (see GraphFilterManager.applyEdgeVisibility). You only need a paired edge filter when you want to hide edges based on their own properties.

Inspecting active filters

list() returns the active FilterHandle instances — handy for a "currently filtered: 3" UI badge with per-filter remove buttons. matchCount() reports the visible / hidden / total counts across all active filters.

Composition

any(handles) and all(handles) snapshot existing handles, detach them from the manager, and register a single group entry in their place. The returned group handle's remove() honours cleanupChildren (default true).

Tear-down

clear() removes every active filter and forgets all tracked handles in one call. Prefer it over looping handle.remove() when resetting the view.

Migration from the legacy API

The previous addRangeFilter / addCategoryFilter / addPredicateFilter / removeFilter / clearFilters / getActiveFilters methods have been replaced by this sugar API:

Legacy method New equivalent
addRangeFilter({ target: "node", property, min, max }) api.filter.nodes.range({ property, min, max })
addCategoryFilter({ target: "node", values }) api.filter.nodes.match({ property: "category", oneOf: values })
addPredicateFilter({ target: "node", predicate }) api.filter.nodes.predicate(fn)
removeFilter(id) handle.remove()
clearFilters() api.filter.clear()
getActiveFilters() api.filter.list()
filterByNeighborhood(id) api.filter.nodes.degree({ min }) — see filterByNeighborhood

Sub-namespaces

The nodes, edges, and playback sub-namespaces are not generated from TypeDoc (they are property-typed references to internal sugar classes that are intentionally not exported from the package entry point). Their pages live as hand-written MDX under content/api/filter/{nodes,edges,playback}/ and are checked into git via the .gitignore whitelist.

Methods