Tree Chart of an Approval Hierarchy
If you are the finance admin who keeps the approval rules, the question you get asked is not how many approvers there are. It is who signs off a purchase of a given size, and who that person passes it up to when it is too big for them.
A tree chart answers that. Each approver is a node, each line runs to the person they report to, and the colour of a node is the limit they can approve. The chart above is bound to the grid beneath it, one row per approver, so filtering the rows redraws the chart. Filter the Limit column to the larger limits and the junior approvers leave the picture. Click a node to fold its branch, and click again to open it.
Why a tree and not an indented list
An indented list of approvers shows the order but not the shape: you cannot see at a glance that one director has six people under them and another has two. A tree lays each level out in a row and keeps siblings apart, so the width of a branch is how many approvers it holds, and the path from any node up to the board is a line you can follow with your eye.
The chart over a grid
Each row names its parent by that parent’s key, so the tree is read from the rows themselves and not from grouping. The row with no parent is the root, and a row whose parent is unknown hangs off it, so one bad row costs its place in the tree and never the drawing. Tree is an opt-in chart type, so you import its module once after the charts module. Here is the example in plain JavaScript, with a few sample rows inline in place of your own.
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-tree';
const rows = [
{ node: 'board', parent: '', approver: 'Board', limit: 1000000 },
{ node: 'cfo', parent: 'board', approver: 'Chief Financial Officer', limit: 500000 },
{ node: 'fd', parent: 'cfo', approver: 'Finance Director', limit: 100000 },
{ node: 'fc', parent: 'fd', approver: 'Financial Controller', limit: 25000 },
{ node: 'ap', parent: 'fc', approver: 'Accounts Payable Lead', limit: 5000 },
{ node: 'pay', parent: 'fc', approver: 'Payroll Manager', limit: 5000 },
];
const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '420px';
document.body.append(gridEl, chartEl);
const grid = createGrid(gridEl, {
rowKey: 'node', rows,
columns: [
{ field: 'approver', title: 'Approver' },
{ field: 'parent', title: 'Parent' },
{ field: 'limit', title: 'Limit', type: 'number', filter: { type: 'set' } },
],
});
createChart({ grid, container: chartEl, type: 'tree', parentId: 'parent',
label: 'approver', colourBy: 'limit', title: 'Who approves what' });
The same thing in React
The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.
import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-tree';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
{ node: 'board', parent: '', approver: 'Board', limit: 1000000 },
{ node: 'cfo', parent: 'board', approver: 'Chief Financial Officer', limit: 500000 },
{ node: 'fd', parent: 'cfo', approver: 'Finance Director', limit: 100000 },
{ node: 'fc', parent: 'fd', approver: 'Financial Controller', limit: 25000 },
{ node: 'ap', parent: 'fc', approver: 'Accounts Payable Lead', limit: 5000 },
];
const columns = [
{ field: 'approver', title: 'Approver' },
{ field: 'parent', title: 'Parent' },
{ field: 'limit', title: 'Limit', type: 'number', filter: { type: 'set' } },
];
export function ApprovalTree() {
const gridRef = useRef(null);
const chartRef = useRef(null);
useEffect(() => {
const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
type: 'tree', parentId: 'parent', label: 'approver', colourBy: 'limit' });
return () => chart.destroy();
}, []);
return (<>
<LatticeGrid ref={gridRef} rowKey="node" columns={columns} rows={rows} style={{ height: 200 }} />
<div ref={chartRef} style={{ height: 360 }} />
</>);
}
The options used
These are the rows of the charts reference for the options in the listings above.
| Option | Type | What it does |
|---|---|---|
grid |
Grid | Required. The grid to read. |
container |
Element or string | Required. Where to draw. |
type |
string | 'tree' here, a tidy node-link tree. |
parentId |
string | The column that names each row’s parent by that parent’s key. A row with no parent, an unknown parent or a parent that leads back to itself hangs off the root. |
label |
string | The column that names each node, here the approver. |
colourBy |
'depth' or string |
How a node is coloured: by depth, the default, or by a column, here the limit, with a legend naming the values. |
title |
string | Drawn above the plot. |
Three more options are worth knowing. expandDepth sets how many levels start open, with deeper branches folded until clicked, orientation runs the levels 'top-down', 'left-right' or 'radial', and linkShape draws the lines 'straight', 'elbow' or 'curved'. A tree too big for the plot is drawn to fit, and the wheel and the plus and minus keys zoom it.
Reading the tree
Follow a line up from any node to see the chain a request travels. In the example, an order of 500 is signed by a buyer or a service desk lead, an order of 20,000 needs a manager, and anything above 100,000 goes to an officer, with the board holding the largest limit. Filter the Limit column to one value to see every approver who holds exactly that limit, and clear it to bring the whole chain back.
Next
See the tree beside the other part-to-whole charts in the part-to-whole family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.