mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Removing unused chart files (#2238)
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
1f910891bc
commit
6d13f87575
@ -1,42 +0,0 @@
|
||||
import ChartJS from "chart.js";
|
||||
import get from "lodash/get";
|
||||
|
||||
const defaultOptions = {
|
||||
interval: 61,
|
||||
coverBars: 3,
|
||||
borderColor: "#44474A",
|
||||
backgroundColor: "#00000033"
|
||||
};
|
||||
|
||||
export const BackgroundBlock = {
|
||||
options: {},
|
||||
|
||||
getOptions(chart: ChartJS) {
|
||||
return get(chart, "options.plugins.BackgroundBlock");
|
||||
},
|
||||
|
||||
afterInit(chart: ChartJS) {
|
||||
this.options = {
|
||||
...defaultOptions,
|
||||
...this.getOptions(chart)
|
||||
};
|
||||
},
|
||||
|
||||
beforeDraw(chart: ChartJS) {
|
||||
if (!chart.chartArea) return;
|
||||
const { interval, coverBars, borderColor, backgroundColor } = this.options;
|
||||
const { ctx, chartArea } = chart;
|
||||
const { left, right, top, bottom } = chartArea;
|
||||
const blockWidth = (right - left) / interval * coverBars;
|
||||
|
||||
ctx.save();
|
||||
ctx.fillStyle = backgroundColor;
|
||||
ctx.strokeStyle = borderColor;
|
||||
ctx.fillRect(right - blockWidth, top, blockWidth, bottom - top);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(right - blockWidth + 1.5, top);
|
||||
ctx.lineTo(right - blockWidth + 1.5, bottom);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
};
|
||||
@ -1,45 +0,0 @@
|
||||
import moment from "moment";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useInterval } from "../../hooks";
|
||||
|
||||
type IMetricValues = [number, string][];
|
||||
type IChartData = { x: number; y: string }[];
|
||||
|
||||
const defaultParams = {
|
||||
fetchInterval: 15,
|
||||
updateInterval: 5
|
||||
};
|
||||
|
||||
export function useRealTimeMetrics(metrics: IMetricValues, chartData: IChartData, params = defaultParams) {
|
||||
const [index, setIndex] = useState(0);
|
||||
const { fetchInterval, updateInterval } = params;
|
||||
const rangeMetrics = metrics.slice(-updateInterval);
|
||||
const steps = fetchInterval / updateInterval;
|
||||
const data = [...chartData];
|
||||
|
||||
useEffect(() => {
|
||||
setIndex(0);
|
||||
}, [metrics]);
|
||||
|
||||
useInterval(() => {
|
||||
if (index < steps + 1) {
|
||||
setIndex(index + steps - 1);
|
||||
}
|
||||
}, updateInterval * 1000);
|
||||
|
||||
if (data.length && metrics.length) {
|
||||
const lastTime = data[data.length - 1].x;
|
||||
const values = [];
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
values[i] = moment.unix(lastTime).add(i + 1, "m").unix();
|
||||
}
|
||||
data.push(
|
||||
{ x: values[0], y: "0" },
|
||||
{ x: values[1], y: parseFloat(rangeMetrics[index][1]).toFixed(3) },
|
||||
{ x: values[2], y: "0" }
|
||||
);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user