add test graphs with device, date and test filters
This commit is contained in:
@@ -1,130 +1,70 @@
|
||||
import React, { Component } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import * as d3 from 'd3';
|
||||
import axios from 'axios';
|
||||
import { query, collection, onSnapshot, getDocs } from 'firebase/firestore';
|
||||
|
||||
import './DeviceGraph.css';
|
||||
import AbsorbanceGraph from './AbsorbanceGraph';
|
||||
import db from '../firebase';
|
||||
|
||||
class DeviceGraph extends Component {
|
||||
function DeviceGraph({url}) {
|
||||
const [devices, setDevices] = useState([]);
|
||||
const [hposTests, setHposTests] = useState(null);
|
||||
|
||||
componentDidMount() {
|
||||
this.drawChart();
|
||||
async function getTests() {
|
||||
try {
|
||||
const testDataCol = collection(db, 'testData');
|
||||
const testDataSnapshot = await getDocs(testDataCol);
|
||||
const testDataList = testDataSnapshot.docs.map(doc => doc.data());
|
||||
console.log(testDataList);
|
||||
// setHposTests(testDataList);
|
||||
return testDataList;
|
||||
} catch (err) {
|
||||
// log error
|
||||
}
|
||||
}
|
||||
|
||||
drawChart() {
|
||||
var margin = { top: 20, right: 20, bottom: 30, left: 50 },
|
||||
width = 960 - margin.left - margin.right,
|
||||
height = 500 - margin.top - margin.bottom;
|
||||
// useEffect(() => {
|
||||
// const q = query(collection(db, "testData"));
|
||||
|
||||
// set the ranges
|
||||
var x = d3.scaleTime().range([0, width]);
|
||||
var y = d3.scaleLinear().range([height, 0]);
|
||||
// const unsub = onSnapshot(q, (querySnapshot) => {
|
||||
// const testDevices = [];
|
||||
// querySnapshot.forEach((document) => {
|
||||
// const hposTestData = document.data();
|
||||
// // testDevices.push(hposTestData);
|
||||
// // const { deviceSerialNo } = hposTestData;
|
||||
// // console.log(document.data());
|
||||
// });
|
||||
// // setDevices(testDevices);
|
||||
// });
|
||||
|
||||
// define the line
|
||||
var valueline = d3.line()
|
||||
.x(function (d) { return x(d.wavelength); })
|
||||
.y(function (d) { return y(d.calculation); });
|
||||
// return () => unsub;
|
||||
// }, []);
|
||||
|
||||
// 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 + ")");
|
||||
// useEffect(() => {
|
||||
// // const q = query(collection(db, "testData"));
|
||||
|
||||
// d3.csv("https://thingproxy.freeboard.io/fetch/https://firebasestorage.googleapis.com/v0/b/hpos-af3cc.appspot.com/o/255668896558B%204DDG%2FHPOSSC_255668896558B%204DDG.csv?alt=media&token=d63d0e5f-0845-4cb6-98c6-cbfb6904cfd7", function (error, data) {
|
||||
// alert(data.length)
|
||||
// // var data = [
|
||||
// // {
|
||||
// // "year": 2006,
|
||||
// // "population": 40
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2008,
|
||||
// // "population": 45
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2010,
|
||||
// // "population": 48
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2012,
|
||||
// // "population": 51
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2014,
|
||||
// // "population": 53
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2016,
|
||||
// // "population": 57
|
||||
// // },
|
||||
// // {
|
||||
// // "year": 2017,
|
||||
// // "population": 62
|
||||
// // }
|
||||
// // ];
|
||||
// // console.log(data);
|
||||
// // // if (error) throw error;
|
||||
// // // format the data
|
||||
// // data.forEach(function (d) {
|
||||
// // d.year = d.year;
|
||||
// // d.population = +d.population;
|
||||
// // });
|
||||
// // const unsub = onSnapshot(q, (querySnapshot) => {
|
||||
// // const testDevices = [];
|
||||
// // querySnapshot.forEach((document) => {
|
||||
// // const hposTestData = document.data();
|
||||
// // // testDevices.push(hposTestData);
|
||||
// // // const { deviceSerialNo } = hposTestData;
|
||||
// // console.log(document.data());
|
||||
// // });
|
||||
// // setDevices(testDevices);
|
||||
// // });
|
||||
|
||||
// // // Scale the range of the data
|
||||
// // x.domain(d3.extent(data, function (d) { return d.year; }));
|
||||
// // y.domain([0, d3.max(data, function (d) { return d.population; })]);
|
||||
// if (hposTests !== null) {
|
||||
// const result = getTests();
|
||||
// setHposTests(result);
|
||||
// }
|
||||
// }, []);
|
||||
|
||||
// // // Add the valueline path.
|
||||
// // svg.append("path")
|
||||
// // .data([data])
|
||||
// // .attr("class", "line")
|
||||
// // .attr("d", valueline);
|
||||
|
||||
// // // Add the X Axis
|
||||
// // svg.append("g")
|
||||
// // .attr("transform", "translate(0," + height + ")")
|
||||
// // .call(d3.axisBottom(x));
|
||||
|
||||
// // // Add the Y Axis
|
||||
// // 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;
|
||||
d.calculation = +d.CA;
|
||||
});
|
||||
|
||||
x.domain(d3.extent(testData, function (d) { return d.wavelength; }));
|
||||
y.domain([0, d3.max(testData, function (d) { return d.calculation; })]);
|
||||
|
||||
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>);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<AbsorbanceGraph url={url} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default DeviceGraph;
|
||||
Reference in New Issue
Block a user