Small change limiting the number of decimal places to 12 digits. (#9298)

Format numbers in the ag-grid so we don't get loads on pointless digits.
![image](https://github.com/enso-org/enso/assets/4699705/0731af47-1e7e-46f5-8bf3-5503ab74a8e3)
This commit is contained in:
James Dunkerley 2024-03-06 14:08:43 +00:00 committed by GitHub
parent c5e4173934
commit d4b2390fc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -72,7 +72,7 @@ import { useAutoBlur } from '@/util/autoBlur'
import { VisualizationContainer } from '@/util/visualizationBuiltins' import { VisualizationContainer } from '@/util/visualizationBuiltins'
import '@ag-grid-community/styles/ag-grid.css' import '@ag-grid-community/styles/ag-grid.css'
import '@ag-grid-community/styles/ag-theme-alpine.css' import '@ag-grid-community/styles/ag-theme-alpine.css'
import { Grid, type ColumnResizedEvent } from 'ag-grid-community' import { Grid, type ColumnResizedEvent, type ICellRendererParams } from 'ag-grid-community'
import type { ColDef, GridOptions, HeaderValueGetterParams } from 'ag-grid-enterprise' import type { ColDef, GridOptions, HeaderValueGetterParams } from 'ag-grid-enterprise'
import { computed, onMounted, onUnmounted, reactive, ref, watchEffect, type Ref } from 'vue' import { computed, onMounted, onUnmounted, reactive, ref, watchEffect, type Ref } from 'vue'
const { LicenseManager } = await import('ag-grid-enterprise') const { LicenseManager } = await import('ag-grid-enterprise')
@ -152,10 +152,12 @@ function escapeHTML(str: string) {
return str.replace(/[&<>"']/g, (m) => mapping[m]!) return str.replace(/[&<>"']/g, (m) => mapping[m]!)
} }
function cellRenderer(params: { value: string | null }) { function cellRenderer(params: ICellRendererParams) {
if (params.value === null) return '<span style="color:grey; font-style: italic;">Nothing</span>' if (params.value === null) return '<span style="color:grey; font-style: italic;">Nothing</span>'
else if (params.value === undefined) return '' else if (params.value === undefined) return ''
else if (params.value === '') return '<span style="color:grey; font-style: italic;">Empty</span>' else if (params.value === '') return '<span style="color:grey; font-style: italic;">Empty</span>'
else if (typeof params.value === 'number')
return params.value.toLocaleString(undefined, { maximumFractionDigits: 12 })
else return escapeHTML(params.value.toString()) else return escapeHTML(params.value.toString())
} }