2023-07-21 03:56:24 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import * as d3 from 'd3';
|
2023-07-21 08:20:39 +05:30
|
|
|
import { sgg } from 'ml-savitzky-golay-generalized';
|
2023-07-21 03:56:24 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
|
|
2023-07-21 08:20:39 +05:30
|
|
|
import './DeviceGraph.css';
|
|
|
|
|
|
2023-07-21 03:56:24 +05:30
|
|
|
class AbsorbanceGraph extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { url: this.props.url };
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.drawChart(this.props.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawChart(url) {
|
|
|
|
|
if (!url) return;
|
|
|
|
|
var margin = { top: 20, right: 20, bottom: 30, left: 50 },
|
|
|
|
|
width = 960 - margin.left - margin.right,
|
|
|
|
|
height = 500 - margin.top - margin.bottom;
|
|
|
|
|
|
|
|
|
|
// set the ranges
|
|
|
|
|
var x = d3.scaleTime().range([0, width]);
|
|
|
|
|
var y = d3.scaleLinear().range([height, 0]);
|
|
|
|
|
|
|
|
|
|
// define the line
|
|
|
|
|
var valueline = d3.line()
|
|
|
|
|
.x(function (d) { return x(d.wavelength); })
|
2023-07-21 08:20:39 +05:30
|
|
|
.y(function (d) { return y(d.absorbance); });
|
2023-07-21 03:56:24 +05:30
|
|
|
|
|
|
|
|
// append the svg obgect to the body of the page
|
|
|
|
|
// appends a 'group' element to 'svg'
|
|
|
|
|
// moves the 'group' element to the top left margin
|
|
|
|
|
var svg = d3.select("#wavelength-graph").append("svg")
|
|
|
|
|
.attr("width", width + margin.left + margin.right)
|
|
|
|
|
.attr("height", height + margin.top + margin.bottom)
|
|
|
|
|
.append("g").attr("transform",
|
|
|
|
|
"translate(" + margin.left + "," + margin.top + ")");
|
|
|
|
|
|
|
|
|
|
axios({
|
|
|
|
|
method: 'get',
|
|
|
|
|
url: url,
|
|
|
|
|
withCredentials: false,
|
|
|
|
|
secure: false,
|
|
|
|
|
responseType: 'blob',
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/octet-stream"
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.data.text())
|
|
|
|
|
.then((text) => {
|
2023-07-22 13:21:39 +05:30
|
|
|
const testData = d3.csvParse(text.replaceAll('"', '')).filter(x => {
|
|
|
|
|
if (x.NM > 350 && x.NM < 600 && x.CA !== "-Infinity" && x.CA !== "Infinity") return x;
|
|
|
|
|
});
|
2023-07-21 08:20:39 +05:30
|
|
|
|
|
|
|
|
const options = {
|
2023-07-21 11:00:09 +05:30
|
|
|
windowSize: 65,
|
2023-07-21 08:20:39 +05:30
|
|
|
derivative: 0,
|
|
|
|
|
polynomial: 3,
|
|
|
|
|
};
|
|
|
|
|
const sggResult = sgg(testData.map(x => x.CA), (Math.PI * 2) / testData.length, options);
|
|
|
|
|
testData.forEach(function (d, index) {
|
|
|
|
|
d.NM = d.NM;
|
|
|
|
|
d.CA = sggResult[index];
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-21 03:56:24 +05:30
|
|
|
testData.forEach(function (d) {
|
|
|
|
|
d.wavelength = d.NM;
|
2023-07-21 08:20:39 +05:30
|
|
|
d.absorbance = +d.CA;
|
2023-07-21 03:56:24 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
x.domain(d3.extent(testData, function (d) { return d.wavelength; }));
|
2023-07-21 08:20:39 +05:30
|
|
|
y.domain([0, d3.max(testData, function (d) { return d.absorbance; })]);
|
2023-07-21 03:56:24 +05:30
|
|
|
|
|
|
|
|
svg.append("path")
|
|
|
|
|
.data([testData])
|
|
|
|
|
.attr("class", "line")
|
|
|
|
|
.attr("d", valueline);
|
|
|
|
|
|
|
|
|
|
svg.append("g")
|
|
|
|
|
.attr("transform", "translate(0," + height + ")")
|
|
|
|
|
.call(d3.axisBottom(x));
|
|
|
|
|
|
|
|
|
|
svg.append("g")
|
|
|
|
|
.call(d3.axisLeft(y));
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /* test graph */
|
|
|
|
|
// const testData = require('./testData.json').filter(x => { if (x.NM > 397 && x.NM < 580) return x; });
|
|
|
|
|
|
|
|
|
|
// testData.forEach(function (d) {
|
|
|
|
|
// d.wavelength = d.NM;
|
2023-07-21 08:20:39 +05:30
|
|
|
// d.absorbance = +d.CA;
|
2023-07-21 03:56:24 +05:30
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// x.domain(d3.extent(testData, function (d) { return d.wavelength; }));
|
2023-07-21 08:20:39 +05:30
|
|
|
// y.domain([0, d3.max(testData, function (d) { return d.absorbance; })]);
|
2023-07-21 03:56:24 +05:30
|
|
|
|
|
|
|
|
// svg.append("path")
|
|
|
|
|
// .data([testData])
|
|
|
|
|
// .attr("class", "line")
|
|
|
|
|
// .attr("d", valueline);
|
|
|
|
|
|
|
|
|
|
// svg.append("g")
|
|
|
|
|
// .attr("transform", "translate(0," + height + ")")
|
|
|
|
|
// .call(d3.axisBottom(x));
|
|
|
|
|
|
|
|
|
|
// svg.append("g")
|
|
|
|
|
// .call(d3.axisLeft(y));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className='graph-card'>
|
|
|
|
|
<div id="wavelength-graph" style={{ margin: '1em' }}>
|
|
|
|
|
</div>
|
|
|
|
|
<div className='graph-title'>wavelength vs absorbance</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
export default AbsorbanceGraph;
|