Attributes, Mappers, And Legends
Visual encodings begin with graph attributes. The recommended everyday API is
the chainable attribute writer API from helios-network: use
nodeAttribute(...), edgeAttribute(...), nodeAttributes(...), and
edgeAttributes(...) for normal application code. These helpers define missing
attributes, write values, and bump attribute versions while preserving the
WASM-buffer safety rules internally.
The raw withBufferAccess(...) API still exists and is important for very large
bulk writes or advanced integrations, but it is not the clearest API for most
examples. Use the chainable writers first; drop down to buffer access only when
you need tight control over typed-array views and write loops.
Loading Data With Attributes
This example builds a graph from ordinary application rows. The label attribute
is written with nodeAttribute(...), and the labels behavior is configured to
read from that attribute. The graph rows could come from JSON, CSV parsing, a
database query, or any other loading step.
Mapping Numeric Attributes
This example maps data attributes onto visual channels. The score node
attribute drives node color and size, while the strength edge attribute drives
edge width. Mappers and legends are built-in behaviors, so the code uses
helios.behavior.mappers after the instance is ready rather than manipulating
renderer internals.
The mapper examples deliberately use named graph attributes instead of hard-coded visual arrays. That keeps the graph portable: the same attributes can also be used by selectors, filters, legends, exports, and saved sessions.
{"importMap": {"helios-web": "../vendor/helios/helios-web.es.js", "helios-network": "../vendor/helios/helios-network.js"}, "examples": [{"id": "examples--helios-web--attributes-mappers.md--example-1", "title": "Load Data Into A Network", "render": true, "console": true, "autorun": true, "layout": "split", "width": null, "height": "440px", "headerName": null, "headerCode": "", "bodyName": "helios_web_loading_building", "bodyCode": "import HeliosNetwork from \"helios-network\";\nimport { Helios } from \"helios-web\";\n\nconst nodeRows = ['Ada', 'Grace', 'Katherine', 'Mary', 'Radia', 'Evelyn'];\nconst edgeRows = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0], [0, 3]];\n\nconst network = await HeliosNetwork.create({ directed: false });\nconst nodes = network.addNodes(nodeRows.length);\n\nnetwork.addEdges(edgeRows.map(([source, target]) => [nodes[source], nodes[target]]));\nnetwork.nodeAttribute('label', (_current, _id, ordinal) => nodeRows[ordinal]);\n\nconst helios = new Helios(network, {\n container,\n mode: '2d',\n behaviors: {\n labels: { enabled: true, source: 'label', selectionMode: 'ranked' },\n },\n});\n\nawait helios.ready;\nhelios.frameNetwork({ animate: false });", "headerRefs": [], "bodyRefs": []}, {"id": "examples--helios-web--attributes-mappers.md--example-2", "title": "Map Attributes To Visual Channels", "render": true, "console": true, "autorun": true, "layout": "split", "width": null, "height": "470px", "headerName": null, "headerCode": "", "bodyName": "helios_web_mappers_legends", "bodyCode": "import HeliosNetwork from \"helios-network\";\nimport { Helios } from \"helios-web\";\n\nconst network = await HeliosNetwork.create({ directed: false });\nconst nodes = network.addNodes(18);\nconst edges = network.addEdges(Array.from(nodes).flatMap((node, index) => [\n [node, nodes[(index + 1) % nodes.length]],\n [node, nodes[(index + 5) % nodes.length]],\n]));\n\nnetwork\n .nodeAttribute('score', (_current, _id, ordinal) => ordinal / (nodes.length - 1))\n .edgeAttribute('strength', (_current, _id, ordinal) => 0.25 + (ordinal % 8) / 10);\n\nconst helios = new Helios(network, {\n container,\n mode: '2d',\n behaviors: {\n legends: { showNodeColor: true, showNodeSize: true, showEdgeWidth: true },\n },\n});\n\nawait helios.ready;\nhelios.behavior.mappers.setChannelConfig('node', 'color', {\n type: 'colormap',\n attributes: 'score',\n colormap: 'interpolateViridis',\n domain: [0, 1],\n});\nhelios.behavior.mappers.setChannelConfig('node', 'size', {\n type: 'linear',\n attributes: 'score',\n domain: [0, 1],\n range: [4, 12],\n});\nhelios.behavior.mappers.setChannelConfig('edge', 'width', {\n type: 'linear',\n attributes: 'strength',\n domain: [0, 1],\n range: [0.8, 2.8],\n});\nhelios.frameNetwork({ animate: false });", "headerRefs": [], "bodyRefs": []}]}