Skip to content

Helpers

View as Markdown

The package exports the functions its own components use, so the schedule or side panel you build beside a chart can format and name things the same way.

import { assignFills, formatAmount, formatPercent, layerKey, layerTerms, towerTop } from '@vinsa/towers';

Shortens an amount: thousands as K, millions as M, billions as B. Amounts under a thousand stay exact.

formatAmount(2500000); // "2.5M"
formatAmount(750000); // "750K"
formatAmount(480); // "480"
formatPercent(62.5); // "62.5%"

The terms of a layer as an underwriter would write them, or null for a layer type that has none. It accepts a layer from your request or a block from the response.

layerTerms({ layerType: 'XOL', lowerLimit: 2500000, upperLimit: 5000000, accumulateBasis: 'CLM' });
// "2.5M xs 2.5M per claim"

LAYER_TYPE_NAMES, BASIS_NAMES and PROTECTION_NAMES map the API’s codes to words:

LAYER_TYPE_NAMES.XOL; // "Excess of loss"
BASIS_NAMES.EVT; // "per event"
PROTECTION_NAMES.RET; // "Retention only"

The key the components use for selection: the layer’s layerRef, or its layerName when it has none. Use it to match the key from onSelect to a layer in your own data.

const layers = program.contracts.filter((c) => risk.contractRefs.includes(c.contractRef)).flatMap((c) => c.layers);
const layer = layers.find((l) => layerKey(l) === selectedKey);

Returns true for a cedant block that belongs to a Layer in the reinsurer viewpoint, including a Layer drawn entirely as cedant. It returns false for retention fillers.

import { isLayerCedant } from '@vinsa/towers';
const layerBlocks = band.verticalBlocks.filter((block) => !block.isRetention || isLayerCedant(block));

Returns a Map from each colorKey to a fill colour, honouring any colorOverride. Pass the result to several <TowerChart />s, or use it to colour rows of your own table to match.

const fills = assignFills(risk.towers);
fills.get(block.colorKey); // "#cfe0f5"

The highest limit drawn in a tower, or 0 when it holds only unlimited layers. Useful for the upper bound of a loss slider.

towerShapes(tower), layerCaptions(shapes) and blockLines(block) are what <TowerChart /> uses to turn bands and blocks into rectangles and labels. They are exported for anyone drawing towers on a different surface, such as canvas or a PDF.

In the reinsurer viewpoint, blockLines(block) labels anonymous blocks Other reinsurers and includes the status for quoted or indication Lines.