Lattice Grid Buy a licence

demo D169

Values on a map in React

Continents and countries from ISO codes

type: 'geomap', code, y

This plots values on a map of continents and countries, keyed by ISO codes on your rows. It turns a table of places into a map you read at a glance, so regional patterns stand out geographically rather than as rows.

Building…
Loading a live grid…

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';
  // A geometry pack registers itself on import; shapes: { pack: id } names it.
  import { pack } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.71.0/modules/geo-world-110m.esm.min.js';

  const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });

  const columns = [
    { field: 'country', title: 'ISO code', layout: { pin: 'start', width: 140 } },
    { field: 'revenue', title: 'Revenue', type: 'number', format: { style: 'currency', currency: 'USD' }, total: 'sum' },
  ];
  const rows = [/* country revenue: id, country (ISO alpha-2, or ZZ), revenue */];

  function App() {
    const [grid, setGrid] = React.useState(null);

    return (
      <>
        <LatticeGrid rowKey="id" columns={columns} rows={rows} onGridReady={setGrid} style={{ height: '300px' }} />
        {grid && (
          <LatticeChart grid={grid} type="geomap" code="country" y={{ col: 'revenue', fn: 'sum' }} shapes={{ pack: pack.id }} title="Revenue by country" style={{ height: '380px', marginTop: '12px' }} />
        )}
      </>
    );
  }

  createRoot(document.getElementById('app')).render(<App />);
</script>