Show layer details
Clicking a layer is the natural way to ask for more about it. onSelect tells you which layer was clicked; what you show is up to you.
Click a layer:
Retention 70%
Property quota shareRetention
Retention 70%
Cat XL 1, 10M xs 10M per eventCat XL 2, 30M xs 20M per eventCat XL 3, 50M xs 50M per eventRetention
Risk XL 1, 4M xs 1M per riskRisk XL 2, 5M xs 5M per riskRetention
Retention 65%
Aggregate XL, 20M xs 40M xs 5M aggregateRetention
Whole-account clash XL, 15M xs 10M per event kept by the cedant signed firm orderWidth is share of the risk, height is amount.
Click a layer to see its terms.
Listen for the click
Section titled “Listen for the click”import { useState } from 'react';import { Towers } from '@vinsa/towers';
function ProgramTowers({ response, program }) { const [selected, setSelected] = useState(null);
return ( <div className="layout"> <Towers data={response} onSelect={(key, risk) => setSelected(key ? { key, riskId: risk.riskId } : null)} /> <LayerPanel program={program} selected={selected} /> </div> );}onSelect receives:
key: the layer’slayerRef, or itslayerNameif it has no reference.nullwhen the selection is cleared.risk: the risk the layer belongs to, from the response.
Find the layer in your own data
Section titled “Find the layer in your own data”The response carries what is needed to draw. Premium, reinstatements and the rest are in the request you sent, so look the layer up there with layerKey:
import { formatAmount, layerKey, layerTerms } from '@vinsa/towers';
function LayerPanel({ program, selected }) { if (!selected) return <p>Select a layer to see its terms.</p>;
const risk = program.risks.find((r) => r.riskId === selected.riskId); const contracts = program.contracts.filter((c) => risk?.contractRefs.includes(c.contractRef)); const layers = contracts.flatMap((c) => c.layers); const layer = layers.find((l) => layerKey(l) === selected.key); if (!layer) return null;
return ( <aside> <h2>{layer.layerName}</h2> <p>{layerTerms(layer)}</p> <p>Premium: {layer.premium != null ? formatAmount(layer.premium) : 'not stated'}</p> <ul> {layer.lines?.map((r) => ( <li key={r.reinsurer}> {r.reinsurer}: {r.writtenShare}% ({r.status}) </li> ))} </ul> </aside> );}Give each layer a layerRef when two could share a name. The key is how they are told apart.
Select from outside the chart
Section titled “Select from outside the chart”To highlight a layer from a row in your own table, control the selection: hold the key in state and pass it as selectedKey.
const [selected, setSelected] = useState<string | null>(null);
<Towers data={response} riskId={riskId} selectedKey={selected} onSelect={setSelected} />
<table> {program.contracts.filter((c) => risk.contractRefs.includes(c.contractRef)).flatMap((c) => c.layers).map((l) => ( <tr key={layerKey(l)} onClick={() => setSelected(layerKey(l))}> <td>{l.layerName}</td> </tr> ))}</table>