demo D250
Bubble map in React
Place a value at each point on the map and size the bubble by how large it is
type: 'bubblemap', lon, lat, size
This places a value at each point on a map and sizes the bubble by how large it is. It shows both where something happens and how much of it, so a geographic pattern of magnitude reads in one view.
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-bubblemap.esm.min.js'; // opt in to the bubblemap type
const { LatticeGrid, LatticeChart } = createLatticeReact({ React, createGrid, createChart });
const columns = [
{ field: 'city', title: 'City' },
{ field: 'lon', title: 'Longitude', type: 'number', format: { decimals: 2 } },
{ field: 'lat', title: 'Latitude', type: 'number', format: { decimals: 2 } },
{ field: 'users', title: 'Users (m)', type: 'number', format: { decimals: 1 }, total: 'sum' },
];
const rows = [/* one city a row: city, lon, lat, users */];
function App() {
const [grid, setGrid] = React.useState(null);
return (
<>
{grid && (
<LatticeChart grid={grid} type="bubblemap" lon="lon" lat="lat" size="users" label="city" title="Users by city" style={{ height: '340px' }} />
)}
<LatticeGrid
rowKey="id"
columns={columns}
rows={rows}
onGridReady={setGrid}
style={{ height: '320px', marginTop: '14px' }}
/>
</>
);
}
createRoot(document.getElementById('app')).render(<App />);
</script>