Spaces:
Sleeping
Sleeping
| import { PO } from './constants.js' | |
| /** Return CSS class for own-price elasticity colouring */ | |
| export function eCls(e) { | |
| if (e < -3) return 'e-high' | |
| if (e < -1.5) return 'e-med' | |
| if (e < 0) return 'e-low' | |
| return 'e-pos' | |
| } | |
| /** Format ₹ value as Cr / L */ | |
| export function fmtCr(v) { | |
| const a = Math.abs(v) | |
| if (a === 0) return '₹0' | |
| if (a >= 1e7) return (v >= 0 ? '+' : '-') + '₹' + (a / 1e7).toFixed(1) + 'Cr' | |
| return (v >= 0 ? '+' : '-') + '₹' + (a / 1e5).toFixed(1) + 'L' | |
| } | |
| /** Format litre volume */ | |
| export function fmtL(v) { | |
| const a = Math.abs(v) | |
| if (a >= 1e6) return (v >= 0 ? '+' : '−') + (a / 1e6).toFixed(2) + 'M L' | |
| if (a >= 1e3) return (v >= 0 ? '+' : '−') + (a / 1e3).toFixed(1) + 'K L' | |
| return (v >= 0 ? '+' : '') + Math.round(v) + 'L' | |
| } | |
| /** Sort grains by a given sort key */ | |
| export function sortModels(data, sortKey) { | |
| return [...data].sort((a, b) => { | |
| if (sortKey === 'vs') return (b.VolSal || 0) - (a.VolSal || 0) | |
| if (sortKey === 'vs2') return (b.ValShare || 0) - (a.ValShare || 0) | |
| if (sortKey === 'elas') return Math.abs(b.OwnE) - Math.abs(a.OwnE) | |
| if (sortKey === 'r2') return (b.AdjR2 || 0) - (a.AdjR2 || 0) | |
| return (PO[a.Pack] || 9) - (PO[b.Pack] || 9) | |
| }) | |
| } | |