Update viewers chart y axis to make more sense. Closes #2806

This commit is contained in:
Gabe Kangas
2023-03-13 15:51:46 -07:00
parent f14aa59663
commit 3ada7182f5
2 changed files with 22 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import {
Tooltip, Tooltip,
Legend, Legend,
LogarithmicScale, LogarithmicScale,
ChartOptions,
} from 'chart.js'; } from 'chart.js';
import { Line } from 'react-chartjs-2'; import { Line } from 'react-chartjs-2';
@@ -40,6 +41,8 @@ export type ChartProps = {
yFlipped?: boolean; yFlipped?: boolean;
yLogarithmic?: boolean; yLogarithmic?: boolean;
dataCollections?: any[]; dataCollections?: any[];
minYValue?: number;
yStepSize?: number;
}; };
function createGraphDataset(dataArray) { function createGraphDataset(dataArray) {
@@ -60,6 +63,8 @@ export const Chart: FC<ChartProps> = ({
dataCollections, dataCollections,
yFlipped, yFlipped,
yLogarithmic, yLogarithmic,
minYValue,
yStepSize = 0,
}) => { }) => {
const renderData = []; const renderData = [];
@@ -94,6 +99,10 @@ export const Chart: FC<ChartProps> = ({
y: { y: {
type: yLogarithmic ? ('logarithmic' as const) : ('linear' as const), type: yLogarithmic ? ('logarithmic' as const) : ('linear' as const),
reverse: yFlipped, reverse: yFlipped,
min: minYValue,
ticks: {
stepSize: yStepSize,
},
title: { title: {
display: true, display: true,
text: unit, text: unit,
@@ -104,7 +113,11 @@ export const Chart: FC<ChartProps> = ({
return ( return (
<div className="line-chart-container"> <div className="line-chart-container">
<Line data={{ datasets: renderData }} options={options} height="70vh" /> <Line
data={{ datasets: renderData }}
options={options as ChartOptions<'line'>}
height="70vh"
/>
</div> </div>
); );
}; };

View File

@@ -151,7 +151,14 @@ export default function ViewersOverTime() {
</button> </button>
</Dropdown> </Dropdown>
{viewerInfo.length > 0 && ( {viewerInfo.length > 0 && (
<Chart title="Viewers" data={viewerInfo} color="#2087E2" unit="viewers" /> <Chart
title="Viewers"
data={viewerInfo}
color="#2087E2"
unit="viewers"
minYValue={0}
yStepSize={1}
/>
)} )}
<ViewerTable data={viewerDetails} /> <ViewerTable data={viewerDetails} />