UNPKG

@mozaic-ds/chart

Version:

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

38 lines (33 loc) 1.21 kB
export function formatTicks(val: number, unit?: string): string { const fixedValue = parseInt(val.toFixed()); return `${new Intl.NumberFormat().format(fixedValue)}${unit ? ' ' + unit : ''}`; } export function formatWithThousandsSeprators(value: number) { if (Math.abs(Number(value)) >= 1.0e6) { return formatDecimalNumber(value / 1.0e6) + ' M'; } else if (Math.abs(Number(value)) >= 1.0e3) { return formatDecimalNumber(value / 1.0e3) + ' K'; } else { return formatDecimalNumber(value); } } export function formatDecimalNumber(value: number) { return new Intl.NumberFormat( new Intl.NumberFormat().resolvedOptions().locale, { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 } ).format(value); } export function getPatternIndexWithShift( dataSetIndex: number, patternShifting?: number ) { return patternShifting ? (dataSetIndex + patternShifting) % 6 : dataSetIndex; } export function formatValueAndRate(doughnutData: any, dataIndex: number) { const textValue = `${formatWithThousandsSeprators(doughnutData.data[dataIndex].value)} (${formatWithThousandsSeprators(doughnutData.data[dataIndex].rate)}%)`; return textValue; }