import React from 'react' import Plot from 'react-plotly.js' import { Box, Text, Stack, Title, Group, Badge } from '@mantine/core' import { useXRD } from '../context/XRDContext' const XRDGraph = () => { const { rawData, processedData, MODEL_MIN_2THETA, MODEL_MAX_2THETA } = useXRD() if (!rawData) { return ( No data loaded ) } // Raw data trace const rawTrace = { x: rawData.x, y: rawData.y, type: 'scattergl', mode: 'lines', name: 'Raw Data', line: { color: 'rgba(128, 128, 128, 1)', width: 1.5, }, hovertemplate: '2θ: %{x:.2f}°
Intensity: %{y:.2f}', } // Processed data trace const processedTrace = processedData ? { x: processedData.x, y: processedData.y, type: 'scattergl', mode: 'lines', name: 'Normalized', line: { color: 'rgba(30, 136, 229, 1)', width: 2, }, hovertemplate: '2θ: %{x:.2f}°
Intensity: %{y:.4f}', } : null // Layout for raw data graph const rawLayout = { xaxis: { title: { text: '2θ (degrees)', font: { size: 14, color: '#333', }, standoff: 10, }, gridcolor: 'rgba(128, 128, 128, 0.2)', showline: true, linewidth: 1, linecolor: 'rgba(128, 128, 128, 0.3)', mirror: true, range: [Math.min(...rawData.x) - 0.5, Math.max(...rawData.x) + 0.5], }, yaxis: { title: { text: 'Intensity (a.u.)', font: { size: 14, color: '#333', }, standoff: 10, }, gridcolor: 'rgba(128, 128, 128, 0.2)', showline: true, linewidth: 1, linecolor: 'rgba(128, 128, 128, 0.3)', mirror: true, }, hovermode: 'closest', showlegend: false, margin: { l: 60, r: 40, t: 20, b: 60, }, paper_bgcolor: 'transparent', plot_bgcolor: 'transparent', height: 280, } // Layout for processed data graph const processedLayout = { xaxis: { title: { text: '2θ (degrees)', font: { size: 14, color: '#333', }, standoff: 10, }, gridcolor: 'rgba(128, 128, 128, 0.2)', range: [MODEL_MIN_2THETA - 0.5, MODEL_MAX_2THETA + 0.5], showline: true, linewidth: 1, linecolor: 'rgba(128, 128, 128, 0.3)', mirror: true, }, yaxis: { title: { text: 'Normalized Intensity', font: { size: 14, color: '#333', }, standoff: 10, }, gridcolor: 'rgba(128, 128, 128, 0.2)', range: [-5, 105], showline: true, linewidth: 1, linecolor: 'rgba(128, 128, 128, 0.3)', mirror: true, }, hovermode: 'closest', showlegend: false, margin: { l: 60, r: 40, t: 20, b: 60, }, paper_bgcolor: 'transparent', plot_bgcolor: 'transparent', height: 280, shapes: [ { type: 'rect', xref: 'x', yref: 'paper', x0: MODEL_MIN_2THETA, y0: 0, x1: MODEL_MAX_2THETA, y1: 1, fillcolor: 'rgba(147, 51, 234, 0.05)', line: { width: 0, }, }, ], } // Config for Plotly const config = { responsive: true, displayModeBar: true, displaylogo: false, modeBarButtonsToRemove: ['lasso2d', 'select2d'], } return ( {/* Raw Data Graph */} Original Data {rawData.x.length} points {/* Processed Data Graph */} {processedData && ( Normalized for Model Input {processedData.x.length} points • {MODEL_MIN_2THETA}-{MODEL_MAX_2THETA}° )} ) } export default XRDGraph