UNPKG

@lunit/oui

Version:

Lunit Oncology UI components

46 lines (45 loc) 1.29 kB
/** * Creates an array of data points for the histogram chart. * * @param sourceData - The source data array. * @returns An array of data points for the histogram chart. */ export function makeHistoDataArray(sourceData) { const cappedData = sourceData.slice(0, 10); return cappedData.map((d, i) => ({ x: i * 10, y: d, })); } /** * Returns the border radius for a tab button based on its index and the total number of tabs. * * @param idx - The index of the tab button. * @param max - The total number of tab buttons. * @returns The border radius for the tab button. */ export function doBorderRadius(idx, max) { const BORDER_RADIUS = '6px'; const borderRadiusMap = { 0: `${BORDER_RADIUS} 0 0 0`, 1: `0 ${BORDER_RADIUS} 0 0`, [max - 2]: `0 0 0 ${BORDER_RADIUS}`, [max - 1]: `0 0 ${BORDER_RADIUS} 0`, }; return borderRadiusMap[idx] || '0'; } /** * Calculates the font size for a tab button based on its label. * * @param text - The label of the tab button. * @returns The font size for the tab button. */ export const calculateFontSize = (text) => { if (text.length <= 9) return 14; if (text.length <= 12) return 12; if (text.length <= 15) return 11; return 9; };