diff --git a/js/ds.js b/js/ds.js
index c60d3e6..7934403 100644
--- a/js/ds.js
+++ b/js/ds.js
@@ -135,7 +135,11 @@ DataSpace.renderReport = async function (report, archesJson, images)
const spectra = report.resource['Analysis Spectra'][0];
const rawData = await this.fetchFileUrl(spectra['Spectrum Raw Data']);
- plot([[1, 2, 3, 4, 5], [1, 2, 4, 8, 16]], 'plot');
+ plot(
+ await fetch(rawData).then(res => res.text()),
+ spectra['Spectrum Technique'],
+ 'plot'
+ );
}
}
@@ -179,13 +183,11 @@ DataSpace.renderAnalysisReport = async function (resource, type)
if (photos[key] !== '') {
const imgUrl = await this.fetchFileUrl(photos[key]);
html += `
-
-
${key.replace('Analysis Photos', '')}
-
-
+
+
${key.replace('Analysis Photos', '')}
-
+
`;
}
}
@@ -197,7 +199,7 @@ DataSpace.renderAnalysisReport = async function (resource, type)
`;
html += `
-
+
`;
diff --git a/js/plot.js b/js/plot.js
index 8be3753..d09df66 100644
--- a/js/plot.js
+++ b/js/plot.js
@@ -1,35 +1,59 @@
-const spectra = {
- 'XRD' : processXRD,
+'use strict';
+// ********************************
+// NOTE: expects plotly.js to be
+// included via script tag in HTML
+// ********************************
+
+const processXRD = rawData => {
+ const sep = rawData.includes('\r') ? '\r': '\n';
+ const axes = rawData.split(sep)
+ .map(r => r.replace('\n', '')
+ .split(/[\s,]+/));
+
+ let x = [], y = [];
+
+ for (const value of axes) {
+ x.push(value[0]);
+ y.push(value[1]);
+ }
+
+ return [x, y];
+};
+
+const processXRF = rawData => {
+ // Do stuff...
+};
+
+const techniques = {
+ 'XRD' : {
+ process : processXRD,
+ plot_type : 'XRD Diffractometer',
+ x_title : '2Theta (°)',
+ y_title : 'Intensity (Counts)',
+ },
'XRF' : processXRF,
};
/**
* @todo process rawData and check spectrum type?
* @param {string} rawData
- * @param {HTMLDivElement} container
+ * @param {string} technique XRD, XRF
+ * @param {string} containerId
*
* @returns {void}
*/
-export function plot(rawData, containerId)
+export function plot(rawData, technique, containerId)
{
let container = document.querySelector(`#${containerId}`);
-
- console.log(rawData[1]);
+ const spectrumType = techniques[technique];
+ const processed = spectrumType.process(rawData);
Plotly.newPlot(container,
[{
- x: rawData[0],
- y: rawData[1],
+ x: processed[0],
+ y: processed[1],
}],
{
margin: {t: 0}
}
);
}
-
-const processXRD = rawData => {
- // Do stuff...
-};
-
-const processXRF = rawData => {
- // Do stuff...
-};