add filter to data

This commit is contained in:
prisar
2023-07-21 08:20:39 +05:30
parent 0f955c4c4a
commit 65d28ad432
6 changed files with 70 additions and 8 deletions

View File

@@ -1,8 +1,10 @@
import React, { Component } from 'react';
import * as d3 from 'd3';
import './DeviceGraph.css';
import { sgg } from 'ml-savitzky-golay-generalized';
import axios from 'axios';
import './DeviceGraph.css';
class AbsorbanceGraph extends Component {
constructor(props) {
super(props);
@@ -25,7 +27,7 @@ class AbsorbanceGraph extends Component {
// define the line
var valueline = d3.line()
.x(function (d) { return x(d.wavelength); })
.y(function (d) { return y(d.calculation); });
.y(function (d) { return y(d.absorbance); });
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
@@ -49,13 +51,25 @@ class AbsorbanceGraph extends Component {
.then(response => response.data.text())
.then((text) => {
const testData = d3.csvParse(text.replaceAll('"', '')).filter(x => { if (x.NM > 390 && x.NM < 650) return x; });;
const options = {
windowSize: 23,
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];
});
testData.forEach(function (d) {
d.wavelength = d.NM;
d.calculation = +d.CA;
d.absorbance = +d.CA;
});
x.domain(d3.extent(testData, function (d) { return d.wavelength; }));
y.domain([0, d3.max(testData, function (d) { return d.calculation; })]);
y.domain([0, d3.max(testData, function (d) { return d.absorbance; })]);
svg.append("path")
.data([testData])
@@ -77,11 +91,11 @@ class AbsorbanceGraph extends Component {
// testData.forEach(function (d) {
// d.wavelength = d.NM;
// d.calculation = +d.CA;
// d.absorbance = +d.CA;
// });
// x.domain(d3.extent(testData, function (d) { return d.wavelength; }));
// y.domain([0, d3.max(testData, function (d) { return d.calculation; })]);
// y.domain([0, d3.max(testData, function (d) { return d.absorbance; })]);
// svg.append("path")
// .data([testData])