Skip to content

nodeAttribute

method

Back to Helios Network JS/WASM API

Kind
method
Source
src/js/HeliosNetwork.js:5556

Description

Defines or updates one node attribute and returns the network for chaining. Missing attributes are defined from options.type / options.dimension, or inferred from the provided scalar, array-like value, or callback result. Array-like values are indexed by active ordinal by default; pass { indexBy: 'id' } to index them by node id instead.

Signature

nodeAttribute(name, valueOrFn, options = {}) {

Parameters

NameTypeAttributesDefaultDescription
namestringAttribute identifier.
valueOrFn*|function(*, number, number, HeliosNetwork): *Scalar, array-like values, or callback.
optionsAttributeWriteOptionsoptionalOptional type, dimension, and indexing controls.

Returns

This network.

Type HeliosNetwork

Notes

This is the recommended API for normal application code. It performs any needed allocation before writing values, so callers do not need to manage WASM typed-array view lifetime directly. Use withBufferAccess(...) only when you intentionally want the lower-level fast path for very large writes.

Example

net
  .nodeAttribute('weight', 1)
  .nodeAttribute('label', (_current, id) => `node-${id}`, { type: 'string' });