2023-07-23 02:42:53 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import * as d3 from 'd3';
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
import './TestAnalyticsGraph.css';
|
2023-07-23 02:42:53 +05:30
|
|
|
|
|
|
|
|
class TestAnalyticsGraph extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { data: this.props.data, show: this.props.show };
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.drawChart(this.state.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawChart(data) {
|
|
|
|
|
if (!data) 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(moment(d.date)); })
|
|
|
|
|
.y(function (d) { return y(d.count); });
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
var svg = d3.select("#tests-count-graph").append("svg")
|
2023-07-23 02:42:53 +05:30
|
|
|
.attr("width", width + margin.left + margin.right)
|
|
|
|
|
.attr("height", height + margin.top + margin.bottom)
|
|
|
|
|
.append("g").attr("transform",
|
|
|
|
|
"translate(" + margin.left + "," + margin.top + ")");
|
2023-07-26 15:35:17 +05:30
|
|
|
// var g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
2023-07-23 02:42:53 +05:30
|
|
|
|
|
|
|
|
// const options = {
|
|
|
|
|
// windowSize: 5,
|
|
|
|
|
// derivative: 0,
|
|
|
|
|
// polynomial: 3,
|
|
|
|
|
// };
|
|
|
|
|
// const sggResult = sgg(data.map(x => x.CA), (Math.PI * 2) / data.length, options);
|
|
|
|
|
|
|
|
|
|
// data.forEach(function (d, index) {
|
|
|
|
|
// d.NM = d.NM;
|
|
|
|
|
// d.CA = sggResult[index];
|
|
|
|
|
// });
|
|
|
|
|
// data.forEach(function (d) {
|
|
|
|
|
// d.date = d.date;
|
|
|
|
|
// d.count = +d.count;
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
x.domain(d3.extent(data, function (d) { return moment(d.date); }));
|
|
|
|
|
y.domain([0, d3.max(data, function (d) { return d.count; })]);
|
|
|
|
|
|
|
|
|
|
svg.append("path")
|
|
|
|
|
.data([data])
|
|
|
|
|
.attr("class", "line")
|
|
|
|
|
.attr("d", valueline);
|
|
|
|
|
|
|
|
|
|
svg.append("g")
|
|
|
|
|
.attr("transform", "translate(0," + height + ")")
|
|
|
|
|
.call(d3.axisBottom(x))
|
|
|
|
|
.append("text")
|
|
|
|
|
// .attr("transform", "rotate(-90)")
|
|
|
|
|
.attr("x", 400)
|
|
|
|
|
.attr("y", 30)
|
|
|
|
|
.attr("dx", "0.71em")
|
|
|
|
|
.attr("fill", "#000")
|
|
|
|
|
.text("Test time");
|
|
|
|
|
|
|
|
|
|
svg.append("g")
|
|
|
|
|
.call(d3.axisLeft(y))
|
|
|
|
|
.append("text")
|
|
|
|
|
.attr("transform", "rotate(-90)")
|
2023-07-23 09:58:23 +05:30
|
|
|
.attr("x", -160)
|
|
|
|
|
.attr("y", -36)
|
2023-07-23 02:42:53 +05:30
|
|
|
.attr("dy", "0.71em")
|
|
|
|
|
.attr("fill", "#000")
|
|
|
|
|
.text("Tests Count");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2023-07-26 17:52:50 +05:30
|
|
|
<div className='tests-count-card'>
|
|
|
|
|
<div id="tests-count-graph" style={{ margin: '1em' }}>
|
2023-07-23 02:42:53 +05:30
|
|
|
</div>
|
2023-07-23 09:58:23 +05:30
|
|
|
<div className='graph-title'>test counts per day</div>
|
2023-07-23 02:42:53 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
export default TestAnalyticsGraph;
|