Skip to content

Rendering ​

The rendering module creates the accessible HTML layer.

Adding Rendering Properties ​

Each node needs:

renderId ​

The DOM element ID:

js
nodes: {
  _0: {
    id: '_0',
    renderId: '_0',
    // ...
  }
}

semantics ​

Accessibility attributes—the label screen readers announce:

js
_0: {
  id: '_0',
  renderId: '_0',
  semantics: {
    label: 'fruit: apple. store: a. cost: 3. Data point.'
  },
  // ...
}

Utility Function

js
import { describeNode } from 'data-navigator/utilities';

const label = describeNode({ fruit: 'apple', store: 'a', cost: 3 }, {});
// "fruit: apple. store: a. cost: 3. Data point."

Creating the Renderer ​

js
import dataNavigator from 'data-navigator';

const renderer = dataNavigator.rendering({
    elementData: structure.nodes,
    defaults: { cssClass: 'dn-manual-focus-node' },
    suffixId: 'fruit-chart',
    root: {
        id: 'chart-wrapper',
        description: 'Fruit cost by store chart. Use arrow keys to navigate.',
        width: '100%',
        height: 0
    },
    entryButton: {
        include: true,
        callbacks: { click: enterChart }
    },
    exitElement: {
        include: true
    }
});

renderer.initialize();

Defaults for every node ​

defaults applies to any node that doesn't set a property itself. Each property is looked up on the node first, then in defaults, then in the built-in defaults.

spatialProperties, semantics, and parentSemantics can be functions. This is useful when the structure builds the nodes for you, as with the dimensions API:

js
import { describeNode } from 'data-navigator/utilities';

const labelFor = node => describeNode(node.data, {});

const renderer = dataNavigator.rendering({
    elementData: structure.nodes,
    defaults: {
        semantics: node => ({ label: labelFor(node) })
    }
    // ...
});

Functions receive the node's render object and the datum passed to render() (the node's data when there is none). With elementData: structure.nodes, the render object is the node itself, so node.data works with any render() call. They can return a partial object: any property they leave out falls back to the built-in default.

Text chat

Text chat doesn't read rendering defaults. Pass the same function as describeNode so both say the same thing:

js
dataNavigator.textChat({ structure, container, describeNode: labelFor });

Key Methods ​

MethodDescription
renderer.initialize()Set up DOM structure
renderer.render(nodeData)Render a node, returns element
renderer.remove(renderId)Remove a rendered node
renderer.clearStructure()Remove all nodes

Generated HTML ​

html
<div id="chart-wrapper" class="dn-root">
    <div
        id="dn-wrapper-fruit-chart"
        role="application"
        aria-label="Fruit cost by store chart. Use arrow keys to navigate."
    >
        <button class="dn-entry-button">Enter navigation area</button>

        <figure id="_0" class="dn-manual-focus-node" tabindex="0">
            <div role="img" aria-label="fruit: apple..."></div>
        </figure>
    </div>

    <div id="dn-exit-fruit-chart" class="dn-exit-position">End of data structure.</div>
</div>

Next Steps ​

Let's put everything together in First Navigable Chart.

Released under the MIT License.