demo D266
Parallel coordinates in React
One line per row across several axes at once, coloured by group to surface a pattern
type: 'parallel', columns, colourBy
This draws one line per row across several axes at once, coloured by group, so a pattern across many measures surfaces. It shows how records with many attributes cluster or differ, which a pair of axes cannot.
This is the React version. The grid mounts through the createLatticeGrid adapter, which takes its configuration as ordinary props and hands back the live grid through a ref. The grid below is the same one every other tab runs.
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.min.css">
<div id="app"></div>
<script type="module">
import React from 'https://esm.sh/react@18';
import { createRoot } from 'https://esm.sh/react-dom@18/client';
import { createGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/lattice-grid.esm.min.js';
import { createLatticeReact } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/react.esm.min.js';
import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/charts.esm.min.js';
import 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/chart-parallel.esm.min.js'; // opt in to the parallel type
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const columns = [
{ field: 'symbol', title: 'Symbol' },
{ field: 'desk', title: 'Desk', filter: { type: 'set' } },
{ field: 'price', title: 'Price', type: 'number', format: { decimals: 4 } },
{ field: 'bid', title: 'Bid', type: 'number', format: { decimals: 4 } },
{ field: 'ask', title: 'Ask', type: 'number', format: { decimals: 4 } },
{ field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
{ field: 'notional', title: 'Notional', type: 'number', format: { style: 'currency', currency: 'USD' }, total: 'sum' },
];
const rows = [/* instruments: symbol, desk, price, bid, ask, volume, notional */];
function App() {
const [grid, setGrid] = React.useState(null);
// columns draws one axis per measure and one line per row; colourBy tints
// the lines by a category, so a pattern per desk shows.
return (
<>
{grid && (
<LatticeChart grid={grid} type="parallel" columns={['price', 'bid', 'ask', 'volume']} colourBy="desk" title="Instruments across four measures" style={{ height: '340px' }} />
)}
<LatticeGrid rowKey="id" columns={columns} rows={rows} onGridReady={setGrid} style={{ height: '340px', marginTop: '14px' }} />
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>