2023-07-20 12:50:51 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import * as d3 from 'd3';
|
|
|
|
|
import './DeviceGraph.css';
|
|
|
|
|
|
|
|
|
|
class DeviceGraph extends Component {
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.drawChart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawChart() {
|
|
|
|
|
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); })
|
|
|
|
|
.y(function (d) { return y(d.calculation); });
|
|
|
|
|
|
|
|
|
|
// 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 + ")");
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// // });
|
|
|
|
|
|
|
|
|
|
// // // 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; })]);
|
|
|
|
|
|
|
|
|
|
// // // 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));
|
2023-07-20 09:17:22 +05:30
|
|
|
|
2023-07-20 12:50:51 +05:30
|
|
|
// // // 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>);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-20 09:17:22 +05:30
|
|
|
export default DeviceGraph;
|