2023-07-23 09:58:23 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import * as d3 from 'd3';
|
|
|
|
|
import { sgg } from 'ml-savitzky-golay-generalized';
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
import './TestAnalyticsPie.css';
|
2023-07-31 17:24:07 +05:30
|
|
|
import constants from '../constants';
|
2023-07-23 09:58:23 +05:30
|
|
|
|
|
|
|
|
class TestAnalyticsPie extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { data: this.props.data, show: this.props.show };
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.drawChart(this.state.data);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
drawChart(data) {
|
|
|
|
|
if (!data) return;
|
2023-07-27 10:31:15 +05:30
|
|
|
|
2023-07-31 17:24:07 +05:30
|
|
|
var margin = { top: 30, right: 10, bottom: 15, left: 25 },
|
|
|
|
|
width = 480 - margin.left - margin.right,
|
|
|
|
|
height = 250 - margin.top - margin.bottom,
|
2023-07-26 17:52:50 +05:30
|
|
|
radius = Math.min(width, height) / 2;
|
2023-07-23 09:58:23 +05:30
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
var svg = d3.select("#category-diagram").append('svg')
|
2023-07-23 09:58:23 +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 17:52:50 +05:30
|
|
|
|
|
|
|
|
var g = svg.append("g")
|
|
|
|
|
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
2023-07-23 09:58:23 +05:30
|
|
|
|
|
|
|
|
var color = d3.scaleOrdinal(['#4daf4a', '#377eb8', '#ff7f00', '#984ea3', '#e41a1c']);
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
var pie = d3.pie().value(function (d) {
|
|
|
|
|
return d.count;
|
|
|
|
|
});
|
2023-07-23 09:58:23 +05:30
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
var path = d3.arc()
|
|
|
|
|
.outerRadius(radius - 10)
|
|
|
|
|
// .innerRadius(0);
|
2023-07-31 17:24:07 +05:30
|
|
|
.innerRadius(50);
|
2023-07-23 09:58:23 +05:30
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
var label = d3.arc()
|
|
|
|
|
.outerRadius(radius)
|
2023-07-31 17:24:07 +05:30
|
|
|
.innerRadius(radius - 40);
|
2023-07-26 17:52:50 +05:30
|
|
|
|
|
|
|
|
var arc = g.selectAll(".arc")
|
2023-07-23 09:58:23 +05:30
|
|
|
.data(pie(data))
|
2023-07-26 17:52:50 +05:30
|
|
|
.enter().append("g")
|
|
|
|
|
.attr("class", "arc");
|
|
|
|
|
|
2023-07-27 10:31:15 +05:30
|
|
|
var tooltip = d3.select("#category-diagram")
|
|
|
|
|
.append("div")
|
|
|
|
|
.style("position", "absolute")
|
|
|
|
|
.style("z-index", "10")
|
|
|
|
|
.style("visibility", "hidden")
|
|
|
|
|
.style("background", "#fff")
|
|
|
|
|
.text("a simple tooltip");
|
|
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
arc.append("path")
|
|
|
|
|
.attr("d", path)
|
2023-07-27 10:31:15 +05:30
|
|
|
.attr("fill", function (d) { return color(d.data.category); })
|
2023-07-31 17:24:07 +05:30
|
|
|
.on('mouseover', (event, d) => {
|
|
|
|
|
tooltip.text(`${d.data.category}: ${d.data.count}`);
|
|
|
|
|
return tooltip
|
|
|
|
|
.style("visibility", "visible")
|
|
|
|
|
.style("font-size", "0.75em")
|
|
|
|
|
.style("z-index", "9999")
|
|
|
|
|
.style("width", "200px")
|
|
|
|
|
.style("height", "50px")
|
|
|
|
|
.style("display", "flex")
|
|
|
|
|
.style("align-items", "center")
|
|
|
|
|
.style("justify-content", "center")
|
|
|
|
|
.style("border-radius", "3px")
|
|
|
|
|
.style("box-shadow", "1px 1px 1px 1px #888888");
|
|
|
|
|
})
|
|
|
|
|
.on('mouseout', (event, d) => {
|
|
|
|
|
return tooltip
|
|
|
|
|
.style("visibility", "hidden");
|
|
|
|
|
});
|
2023-07-27 10:31:15 +05:30
|
|
|
|
2023-07-26 17:52:50 +05:30
|
|
|
arc.append("text")
|
|
|
|
|
.attr("transform", function (d) {
|
|
|
|
|
return "translate(" + label.centroid(d) + ")";
|
2023-07-23 09:58:23 +05:30
|
|
|
})
|
2023-07-31 17:24:07 +05:30
|
|
|
.style("font-size", "0.75em")
|
|
|
|
|
.text(function (d) { return constants.categoryshortname[d.data.category]; });
|
2023-07-26 17:52:50 +05:30
|
|
|
|
|
|
|
|
// svg.append("g")
|
|
|
|
|
// .attr("transform", "translate(" + (width / 2 - 170) + "," + 1 + ")")
|
|
|
|
|
// .append("text")
|
|
|
|
|
// .text("category counts per day")
|
|
|
|
|
// .attr("class", "title")
|
2023-07-23 09:58:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className='graph-card'>
|
2023-07-26 17:52:50 +05:30
|
|
|
<div id="category-diagram" style={{ margin: '1em' }}>
|
2023-07-23 09:58:23 +05:30
|
|
|
</div>
|
2023-07-26 17:52:50 +05:30
|
|
|
<div className='graph-title'>category data on daily basis</div>
|
2023-07-23 09:58:23 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
export default TestAnalyticsPie;
|