signoz/frontend/src/components/usage/UsageExplorer.tsx

79 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-01-18 02:18:49 +05:30
import React, { useEffect } from "react";
import { Bar } from "react-chartjs-2";
import { Card } from "antd";
import { connect } from "react-redux";
2021-01-03 18:15:44 +05:30
2021-01-18 02:18:49 +05:30
import { getUsageData, GlobalTime, usageDataItem } from "../../actions";
import { StoreState } from "../../reducers";
2021-01-03 18:15:44 +05:30
interface UsageExplorerProps {
2021-01-18 02:18:49 +05:30
usageData: usageDataItem[];
getUsageData: Function;
globalTime: GlobalTime;
2021-01-03 18:15:44 +05:30
}
const _UsageExplorer = (props: UsageExplorerProps) => {
2021-01-18 02:18:49 +05:30
useEffect(() => {
props.getUsageData(props.globalTime);
}, [props.globalTime]);
2021-01-03 18:15:44 +05:30
2021-01-18 02:18:49 +05:30
const data = {
labels: props.usageData.map((s) => new Date(s.timestamp / 1000000)),
datasets: [
{
label: "Span Count",
data: props.usageData.map((s) => s.count),
backgroundColor: "rgba(255, 99, 132, 0.2)",
borderColor: "rgba(255, 99, 132, 1)",
borderWidth: 2,
},
],
};
2021-01-03 18:15:44 +05:30
2021-01-18 02:18:49 +05:30
const options = {
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
fontSize: 10,
},
},
],
xAxes: [
{
type: "time",
// distribution: 'linear', // Bar graph doesn't take lineardistribution type?
ticks: {
beginAtZero: true,
fontSize: 10,
},
},
],
},
legend: {
display: false,
},
};
return (
<React.Fragment>
{/* PNOTE - TODO - Keep it in reponsive row column tab */}
<Card style={{ width: "50%", margin: 20 }} bodyStyle={{ padding: 20 }}>
<Bar data={data} options={options} />
</Card>
</React.Fragment>
);
};
2021-01-03 18:15:44 +05:30
2021-01-18 02:18:49 +05:30
const mapStateToProps = (
state: StoreState,
): { usageData: usageDataItem[]; globalTime: GlobalTime } => {
return { usageData: state.usageDate, globalTime: state.globalTime };
2021-01-03 18:15:44 +05:30
};
export const UsageExplorer = connect(mapStateToProps, {
2021-01-18 02:18:49 +05:30
getUsageData: getUsageData,
})(_UsageExplorer);