Topology and channels¶
Use this guide when adapting real network data to @latkit/network.
Topology arrays¶
Topology is the CPU-side graph shape passed to network.load().
Field |
Length |
Meaning |
|---|---|---|
|
|
Number of logical graph vertices |
|
|
Interleaved |
|
|
Endpoint vertex indices as |
|
|
Offset table into |
|
|
Optional bend points for edge polylines |
For straight edges with no bend points, use a zero-filled polylineStart with edgeCount + 1 entries:
const topology: Topology = {
vertexCount: 4,
vertexCoords: new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]),
edges: new Uint32Array([0, 1, 1, 2, 2, 3]),
polylineStart: new Uint32Array([0, 0, 0, 0]),
};
For a bent edge, place the intermediate points in polylinePoints and use polylineStart to mark the range for each edge:
const topology: Topology = {
vertexCount: 2,
vertexCoords: new Float32Array([-96, 30, -94, 31]),
edges: new Uint32Array([0, 1]),
polylineStart: new Uint32Array([0, 2]),
polylinePoints: new Float32Array([-95.5, 30.8, -94.8, 31.1]),
};
Projection support¶
Flat and tilt projections accept arbitrary coordinates. Globe projection is available only when loaded bounds look geographic: longitude in [-180, 180], latitude in [-90, 90], a non-trivial geographic span, and a characteristic length small enough for globe rendering.
Read support after load():
network.load(topology);
if (network.projections.globe) {
network.setProjection('globe');
}
Channel arrays¶
Channels bind scalar values to vertices or edges after a topology is loaded.
Channel |
Length |
Effect |
|---|---|---|
|
|
Colors vertices through the active colormap |
|
|
Raises vertices and height poles |
|
|
Scales vertex billboards |
|
|
Colors edges through the active colormap |
|
|
Enables per-edge dash pattern values |
network.load(topology);
network.setChannel('vertexColor', vertexLoad, [0, 1]);
network.setChannel('edgeColor', edgeStress, [0, 100]);
network.setChannel('vertexHeight', vertexLoad, [0, 1], [0, 0.8]);
The third argument is the input domain. Pass null to auto-scan height values. The fourth argument is the output height range and only applies to vertexHeight.
Validation failures¶
network.load() throws if lengths, endpoints, or polyline offsets are invalid. setChannel() throws if no topology is loaded or the channel length does not match the current topology.