Skip to content

Commit

Permalink
fix(#5): 🐛 Rounded coordinates to one decimal so that they are displa…
Browse files Browse the repository at this point in the history
…yed neatly
  • Loading branch information
gautegf committed Oct 6, 2025
1 parent 33c96be commit 7bc12dd
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/MeasurementControl/measurementsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ window.initMeasurementsPanel = function initMeasurementsPanel(viewer) {
}
}
}
requestAnimationFrame(() => {
roundCoordinates(originalPropertiesPanel)
initCoordObserver()
})
}
function restorePanelToOriginal() {
if (!originalPropertiesPanel || !placeholder || !originalParent) return
Expand All @@ -222,6 +226,58 @@ window.initMeasurementsPanel = function initMeasurementsPanel(viewer) {
targetContainer.appendChild(msg2)
}

// Helper: round only the coordinates table (x,y,z header row) to 1 decimal
let coordRoundObserver = null
function initCoordObserver() {
if (!originalPropertiesPanel || coordRoundObserver) return
coordRoundObserver = new MutationObserver(() => {
requestAnimationFrame(() => roundCoordinates(originalPropertiesPanel))
})
coordRoundObserver.observe(originalPropertiesPanel, {
childList: true,
subtree: true
})
}

function roundCoordinates(rootEl) {
if (!rootEl) return
// Find first table that has a header row with th: x y z
const tables = rootEl.querySelectorAll('table.measurement_value_table')
let coordTable = null
for (const tbl of tables) {
const headerRow = tbl.querySelector('tr')
if (!headerRow) continue
const ths = [...headerRow.querySelectorAll('th')].map(th =>
(th.textContent || '').trim().toLowerCase()
)
if (ths.length >= 3 && ths[0] === 'x' && ths[1] === 'y' && ths[2] === 'z') {
coordTable = tbl
break
}
}
if (!coordTable) return

const dataRows = [...coordTable.querySelectorAll('tr')].slice(1)
dataRows.forEach(row => {
row.querySelectorAll('td').forEach(td => {
if (td.querySelector('button, input, select')) return
const raw = (td.textContent || '').trim()
if (!raw) return
// Allow formats with commas, spaces, possible degree sign, trailing labels
// Extract leading numeric with optional sign & decimal
const cleaned = raw
.replace(/[^\d+.\-]/g, c => (c === ',' ? '' : '')) // clean data
.replace(/,+/g, '')
if (!cleaned || !/[-+]?\d*\.?\d+/.test(cleaned)) return
const num = Number(cleaned)
if (!Number.isFinite(num)) return
const rounded = num.toFixed(1)
if (td.textContent !== rounded) {
td.textContent = rounded
}
})
})
}
// Helper to decide if a uuid is a measurement-like object
function isMeasurementUUID(uuid) {
if (!uuid) return false
Expand Down

0 comments on commit 7bc12dd

Please sign in to comment.