'use client'; import { Text, View, XStack } from '@hanzo/gui'; import * as React from 'react'; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- export interface GreeksDisplayProps extends React.HTMLAttributes { readonly delta: number; readonly gamma: number; readonly theta: number; readonly vega: number; readonly rho?: number; readonly iv?: number; readonly compact?: boolean; } // --------------------------------------------------------------------------- // Greek definitions // --------------------------------------------------------------------------- interface GreekDef { key: string; label: string; symbol: string; color: string; barColor: string; decimals: number; maxMagnitude: number; } // A greek is identified by its symbol and its label, never by a hue. Six series // on one achromatic ramp (tokens.css --chart-*, plus --foreground for the sixth), // so the panel obeys the brand atom and reskins with the host. const GREEKS: GreekDef[] = [ { key: 'delta', label: 'Delta', symbol: 'Δ', color: 'var(--foreground)', barColor: 'var(--foreground)', decimals: 4, maxMagnitude: 1 }, { key: 'gamma', label: 'Gamma', symbol: 'Γ', color: 'var(--chart-1)', barColor: 'var(--chart-1)', decimals: 4, maxMagnitude: 0.1 }, { key: 'theta', label: 'Theta', symbol: 'Θ', color: 'var(--chart-4)', barColor: 'var(--chart-4)', decimals: 4, maxMagnitude: 1 }, { key: 'vega', label: 'Vega', symbol: 'ν', color: 'var(--chart-2)', barColor: 'var(--chart-2)', decimals: 4, maxMagnitude: 1 }, { key: 'rho', label: 'Rho', symbol: 'ρ', color: 'var(--chart-3)', barColor: 'var(--chart-3)', decimals: 4, maxMagnitude: 1 }, { key: 'iv', label: 'IV', symbol: 'σ', color: 'var(--chart-5)', barColor: 'var(--chart-5)', decimals: 1, maxMagnitude: 100 }, ]; // --------------------------------------------------------------------------- // GreekItem // --------------------------------------------------------------------------- interface GreekItemProps { readonly def: GreekDef; readonly value: number; readonly compact?: boolean; } function GreekItem({ def, value, compact }: GreekItemProps) { const magnitude = Math.min(Math.abs(value) / def.maxMagnitude, 1); const displayValue = def.key === 'iv' ? `${(value * 100).toFixed(def.decimals)}%` : value.toFixed(def.decimals); return ( { def.symbol } { !compact && ( { def.label } ) } { displayValue } { !compact && ( ) } ); } // --------------------------------------------------------------------------- // GreeksDisplay // --------------------------------------------------------------------------- export const GreeksDisplay = React.forwardRef( function GreeksDisplay(props, ref) { const { delta, gamma, theta, vega, rho, iv, compact = false, className, ...rest } = props; const values: Record = { delta, gamma, theta, vega, rho, iv, }; const activeGreeks = GREEKS.filter((g) => values[g.key] !== undefined); return ( { activeGreeks.map((g) => ( )) } ); }, );