diff --git a/data/sin_acceleration_example_dcc_WithExampleConformatyStatment.xml b/data/sin_acceleration_example_dcc_WithExampleConformatyStatment.xml index 922a0325049469b4513d4e6d0cd3890dfe23b711..f9918de7637eacb94611204e5550b7529a4adba0 100644 --- a/data/sin_acceleration_example_dcc_WithExampleConformatyStatment.xml +++ b/data/sin_acceleration_example_dcc_WithExampleConformatyStatment.xml @@ -659,8 +659,8 @@ Entsprechend ISO 2041 ist die Phasenverschiebung definiert zu Δφqa = φq - φa <dcc:metaData refType="basic_conformity"> <dcc:convention>customer</dcc:convention> <dcc:conformityXMLList>pass pass pass pass pass pass pass pass pass pass pass - pass pass pass pass pass pass pass pass pass pass pass fail fail fail fail - fail fail fail fail fail</dcc:conformityXMLList> + pass pass pass pass pass pass pass pass pass pass pass pass pass pass pass + pass pass fail fail fail</dcc:conformityXMLList> <dcc:data> <dcc:quantity refType="basic_toleranceLimitLower"> <dcc:name> diff --git a/src/renderers/MeasurementRenderer.js b/src/renderers/MeasurementRenderer.js index 47f6a6c0bca31376d7dc7c1998d71ec1e45a470a..dfa6e7b672b0530cf84139cfc5c42997025efa09 100644 --- a/src/renderers/MeasurementRenderer.js +++ b/src/renderers/MeasurementRenderer.js @@ -1,5 +1,5 @@ import Plotly from 'plotly.js-dist'; -import { DCCRealListQuantity } from '../dccQuantity.js'; +import { DCCRealListQuantity,DCCConformity } from '../dccQuantity.js'; const palette = [ '#1f77b4', @@ -67,9 +67,7 @@ export function renderMeasurementResults(measurementResults, language) { if (Array.isArray(content)) { const match = content.find(item => item.$ && item.$.lang === language) || content[0]; resultName = match._ || match; - } else { - resultName = content._ || content; - } + } else { resultName = content._ || content; } } const tabTitle = document.createElement('h2'); tabTitle.textContent = resultName; @@ -101,6 +99,7 @@ export function renderMeasurementResults(measurementResults, language) { const indexQuantities = []; const dataQuantities = []; + // extraInfo stores { uncertainty, conformity } for each data quantity. const extraInfo = []; quantityJSONs.forEach(q => { if (q.$ && q.$.refType && q.$.refType.match(/basic_tableIndex/)) { @@ -109,31 +108,16 @@ export function renderMeasurementResults(measurementResults, language) { const quantity = new DCCRealListQuantity(q); dataQuantities.push(quantity); let uncertainty = quantity.getUncertainty(); - let comment = ''; let conformity = null; if (q['dcc:measurementMetaData'] && q['dcc:measurementMetaData']['dcc:metaData']) { let md = q['dcc:measurementMetaData']['dcc:metaData']; if (!Array.isArray(md)) { md = [md]; } - md.forEach(item => { - if (item.$ && item.$.refType && item.$.refType.includes('basic_tableRowComment')) { - if (item['dcc:description'] && item['dcc:description']['dcc:content']) { - let desc = item['dcc:description']['dcc:content']; - if (Array.isArray(desc)) { - const match = desc.find(d => d.$ && d.$.lang === language) || desc[0]; - comment = match._ || match; - } else { - comment = desc._ || desc; - } - } - } - if (item.$ && item.$.refType && item.$.refType.includes('basic_conformity')) { - if (item['dcc:conformityXMLList']) { - conformity = item['dcc:conformityXMLList'].trim().split(/\s+/); - } - } - }); + const confMeta = md.find(item => item.$ && item.$.refType && item.$.refType.includes('basic_conformity')); + if (confMeta) { + conformity = new DCCConformity(confMeta, language); + } } - extraInfo.push({ uncertainty, comment, conformity }); + extraInfo.push({ uncertainty, conformity }); } }); @@ -146,6 +130,7 @@ export function renderMeasurementResults(measurementResults, language) { return header; }); + // Create scaling toggles for log axes. const scalingContainer = document.createElement('div'); scalingContainer.innerHTML = '<strong>Scaling:</strong> '; const logXToggle = document.createElement('input'); @@ -222,7 +207,7 @@ export function renderMeasurementResults(measurementResults, language) { if (info.conformity) { headers.push('Conformity'); } dataValues.push(dataQuantities[idx].getValues()); uncertaintiesArray.push(info.uncertainty || []); - conformityArray.push(info.conformity || []); + conformityArray.push(info.conformity ? info.conformity.getConformityValues() : []); }); headers.push('Comments'); @@ -237,11 +222,10 @@ export function renderMeasurementResults(measurementResults, language) { } row.push(cellValue); if (info.conformity) { - row.push(info.conformity[i] || ''); + row.push(conformityArray[idx][i] || ''); } }); - // Comments column remains uncolored - row.push(extraInfo.map(info => info.comment).filter(c => c).join(' ; ')); + row.push(extraInfo.map(info => info.comment || '').filter(c => c).join(' ; ')); tableData.push(row); } renderTable(tableData, headers); @@ -321,8 +305,64 @@ export function renderMeasurementResults(measurementResults, language) { type: logY ? 'log' : 'linear' }, hovermode: 'closest', - margin: { t: 20, b: 40 } + margin: { t: 20, b: 40 }, + shapes: [], + annotations: [] }; + + // Tolerance markings from conformity limits, if enabled. + if (document.getElementById('toleranceToggle').checked) { + group.forEach(trace => { + const confObj = extraInfo[trace.index].conformity; + if (confObj) { + const lower = extraInfo[trace.index].conformity.getLowerLimit(); + const upper = extraInfo[trace.index].conformity.getUpperLimit(); + if (lower && typeof lower.value === 'number') { + layout.shapes.push({ + type: 'line', + x0: Math.min(...xValues), + x1: Math.max(...xValues), + y0: lower.value, + y1: lower.value, + line: { color: '#d62728', width: 2, dash: 'dash' }, + xref: 'x', + yref: 'y' + }); + layout.annotations.push({ + x: Math.min(...xValues), + y: lower.value, + xref: 'x', + yref: 'y', + text: lower.name, + showarrow: false, + font: { color: '#d62728', size: 12 } + }); + } + if (upper && typeof upper.value === 'number') { + layout.shapes.push({ + type: 'line', + x0: Math.min(...xValues), + x1: Math.max(...xValues), + y0: upper.value, + y1: upper.value, + line: { color: '#d62728', width: 2, dash: 'dash' }, + xref: 'x', + yref: 'y' + }); + layout.annotations.push({ + x: Math.min(...xValues), + y: upper.value, + xref: 'x', + yref: 'y', + text: upper.name, + showarrow: false, + font: { color: '#d62728', size: 12 } + }); + } + } + }); + } + Plotly.newPlot(graphDiv, groupTraces, layout).then(() => { const caption = document.createElement('div'); caption.innerHTML = '<b>' + group[0].name + '</b>'; @@ -336,9 +376,7 @@ export function renderMeasurementResults(measurementResults, language) { highlightTableRow(pointIndex); } }); - graphDiv.on('plotly_unhover', function() { - clearTableRowHighlights(); - }); + graphDiv.on('plotly_unhover', function() { clearTableRowHighlights(); }); graphDiv.on('plotly_relayout', function(eventData) { plotDivs.forEach(div => { if (div !== graphDiv && eventData['xaxis.range[0]'] && eventData['xaxis.range[1]']) { @@ -349,7 +387,7 @@ export function renderMeasurementResults(measurementResults, language) { }); } - function renderTable(tableData, headers) { + function renderTable(tableData, headerData) { const tableContainer = document.getElementById('tableContainer'); tableContainer.innerHTML = ''; const table = document.createElement('table'); @@ -392,5 +430,5 @@ export function renderMeasurementResults(measurementResults, language) { radios.forEach(radio => { radio.addEventListener('change', updateVisualization); }); document.getElementById('logXToggle').addEventListener('change', updateVisualization); document.getElementById('logYToggle').addEventListener('change', updateVisualization); - toleranceToggle.addEventListener('change', () => { console.log('Tolerance toggle:', toleranceToggle.checked); }); + toleranceToggle.addEventListener('change', () => { console.log('Tolerance toggle:', toleranceToggle.checked); updateVisualization(); }); }