diff --git a/CommonUI/src/Components/Charts/Line/LineChart.tsx b/CommonUI/src/Components/Charts/Line/LineChart.tsx index ebc617bfa18..4fc1cac4aad 100644 --- a/CommonUI/src/Components/Charts/Line/LineChart.tsx +++ b/CommonUI/src/Components/Charts/Line/LineChart.tsx @@ -147,12 +147,14 @@ const LineChart: FunctionComponent = ( return <>; } - return props.getHoverTooltip({ points: data.slice.points.map((point) => { - return { - x: point.data.x as XValue, - y: point.data.y as YValue, - }; - })}); + return props.getHoverTooltip({ + points: data.slice.points.map((point) => { + return { + x: point.data.x as XValue, + y: point.data.y as YValue, + }; + }), + }); }} colors={[Indigo500.toString()]} // Set the line color to purple /> diff --git a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx index 2614a143cda..0c4a2e72c04 100644 --- a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx +++ b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChart.tsx @@ -1,4 +1,3 @@ - import React from 'react'; import OneUptimeDate from 'Common/Types/Date'; import { CheckOn } from 'Common/Types/Monitor/CriteriaFilter'; @@ -7,6 +6,8 @@ import { ChartType, } from 'CommonUI/src/Components/Charts/ChartGroup/ChartGroup'; import { + AxisBottom, + AxisLeft, ChartCurve, LineChartPoint, XScale, @@ -28,6 +29,14 @@ export class MonitorCharts { const charts: Array = checkOns.map( (checkOn: CheckOn, index: number) => { + + const axisBottom: AxisBottom = MonitorCharts.getAxisBottomFor(); + + const axisLeft: AxisLeft = MonitorCharts.getAxisLeftFor({ + checkOn: checkOn, + }); + + return { id: `chart-${index}`, type: ChartType.LINE, @@ -57,21 +66,23 @@ export class MonitorCharts { yScale: MonitorCharts.getYScaleFor({ checkOn: checkOn, }), - axisBottom: { - legend: '', - format: (value: XValue): string => { - return OneUptimeDate.getLocalHourAndMinuteFromDate( - value as Date - ); - }, - }, + axisBottom: axisBottom, curve: MonitorCharts.getCurveFor({ checkOn: checkOn }), - axisLeft: { - legend: '', + axisLeft: axisLeft, + getHoverTooltip: (data: { + points: Array; + }) => { + return ( + + ); }, - getHoverTooltip: (data: { points: Array }) => { - return ; - } }, sync: true, }; @@ -81,6 +92,35 @@ export class MonitorCharts { return charts; } + private static getAxisBottomLegend(): string { + return 'Time' + } + + + public static getAxisLeftLegend(data: { + checkOn: CheckOn; + }): string { + return data.checkOn; + } + + private static getAxisBottomFor(): AxisBottom { + return { + legend: '', + format: (value: XValue): string => { + return OneUptimeDate.getLocalHourAndMinuteFromDate( + value as Date + ); + }, + }; + } + + + private static getAxisLeftFor(data: { checkOn: CheckOn }): AxisLeft { + return { + legend: data.checkOn, + }; + } + private static getCurveFor(data: { checkOn: CheckOn }): ChartCurve { if (data.checkOn === CheckOn.ResponseStatusCode) { return ChartCurve.STEP_AFTER; @@ -132,7 +172,11 @@ export class MonitorCharts { min: 0, max: 600, }; - }else if (data.checkOn === CheckOn.DiskUsagePercent || data.checkOn === CheckOn.MemoryUsagePercent || data.checkOn === CheckOn.CPUUsagePercent) { + } else if ( + data.checkOn === CheckOn.DiskUsagePercent || + data.checkOn === CheckOn.MemoryUsagePercent || + data.checkOn === CheckOn.CPUUsagePercent + ) { return { type: YScaleType.LINEAR, min: 0, diff --git a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChartTooltip.tsx b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChartTooltip.tsx index fde7249b4f6..58d5469fd26 100644 --- a/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChartTooltip.tsx +++ b/Dashboard/src/Components/Monitor/MonitorCharts/MonitorChartTooltip.tsx @@ -1,36 +1,28 @@ import React, { FunctionComponent, ReactElement } from 'react'; -import { LineChartPoint } from 'CommonUI/src/Components/Charts/Line/LineChart'; +import { AxisBottom, AxisLeft, LineChartPoint } from 'CommonUI/src/Components/Charts/Line/LineChart'; export interface ComponentProps { points: Array; - xAxis: { - legend: string; - type: - }; - yAxis: { - legend: string; - }; + axisBottom: AxisBottom; + axisLeft: AxisLeft; } const MonitorChartTooltip: FunctionComponent = ( props: ComponentProps ): ReactElement => { - - - return (
{props.points.map((point: LineChartPoint, index: number) => { return (
-
{props.yAxis.legend}
+
{props.axisLeft.legend}
{point.y.toString()}
-
{props.xAxis.legend}
+
{props.axisBottom.legend}
{point.x.toString()}
diff --git a/Dashboard/src/Pages/Monitor/View/Index.tsx b/Dashboard/src/Pages/Monitor/View/Index.tsx index 2b2695bf1c1..92714bd8eab 100644 --- a/Dashboard/src/Pages/Monitor/View/Index.tsx +++ b/Dashboard/src/Pages/Monitor/View/Index.tsx @@ -183,12 +183,12 @@ const MonitorView: FunctionComponent = ( }); let monitorMetricsByMinute: AnalyticsListResult = - { - data: [], - count: 0, - limit: 0, - skip: 0, - }; + { + data: [], + count: 0, + limit: 0, + skip: 0, + }; if (!item) { setError(`Monitor not found`); @@ -378,7 +378,7 @@ const MonitorView: FunctionComponent = ( color={ ( item[ - 'currentMonitorStatus' + 'currentMonitorStatus' ] as JSONObject )['color'] as Color } @@ -386,7 +386,7 @@ const MonitorView: FunctionComponent = ( text={ ( item[ - 'currentMonitorStatus' + 'currentMonitorStatus' ] as JSONObject )['name'] as string } @@ -416,7 +416,7 @@ const MonitorView: FunctionComponent = ( labels={ BaseModel.fromJSON( (item['labels'] as JSONArray) || - [], + [], Label ) as Array