mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Setting up line colors
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
d733dc4b66
commit
3dd3f08f56
@ -20,6 +20,10 @@
|
|||||||
flex: 1.0;
|
flex: 1.0;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
|
|
||||||
|
.metrics {
|
||||||
|
--metric-color: var(--blue);
|
||||||
|
}
|
||||||
|
|
||||||
.LineProgress {
|
.LineProgress {
|
||||||
color: var(--blue);
|
color: var(--blue);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import { eventStore } from "../+events/event.store";
|
|||||||
import { makeObservable, observable } from "mobx";
|
import { makeObservable, observable } from "mobx";
|
||||||
import isEmpty from "lodash/isEmpty";
|
import isEmpty from "lodash/isEmpty";
|
||||||
import { KubeObjectAge } from "../kube-object/age";
|
import { KubeObjectAge } from "../kube-object/age";
|
||||||
|
import { MetricBar } from "../metric-bar";
|
||||||
|
|
||||||
enum columnId {
|
enum columnId {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -96,7 +97,8 @@ export class NodesRoute extends React.Component {
|
|||||||
const [usage, capacity] = metrics;
|
const [usage, capacity] = metrics;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LineProgress
|
<MetricBar
|
||||||
|
className="metrics"
|
||||||
max={capacity}
|
max={capacity}
|
||||||
value={usage}
|
value={usage}
|
||||||
tooltip={{
|
tooltip={{
|
||||||
|
|||||||
@ -4,7 +4,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.metricBar {
|
.metricBar {
|
||||||
|
--metric-color: gray;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
label {
|
||||||
|
color: var(--textColorTertiary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar {
|
||||||
|
--line-color: var(--metric-color);
|
||||||
|
|
||||||
|
&.warning {
|
||||||
|
--line-color: salmon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -5,39 +5,34 @@
|
|||||||
|
|
||||||
import styles from "./metric-bar.module.scss";
|
import styles from "./metric-bar.module.scss";
|
||||||
|
|
||||||
import React, { HTMLAttributes, ReactNode, useEffect, useRef, useState } from "react";
|
import React, { HTMLAttributes, ReactNode } from "react";
|
||||||
import { cssNames, cssVar } from "../../utils";
|
|
||||||
import { VerticalBar } from "../vertical-bar";
|
import { VerticalBar } from "../vertical-bar";
|
||||||
|
import { TooltipDecoratorProps, withTooltip } from "../tooltip";
|
||||||
|
import { cssNames } from "../../utils";
|
||||||
|
|
||||||
interface BarProps extends HTMLAttributes<HTMLDivElement> {
|
interface BarProps extends HTMLAttributes<HTMLDivElement>, TooltipDecoratorProps {
|
||||||
value: number;
|
value: number;
|
||||||
max: number;
|
max: number;
|
||||||
min?: number;
|
min?: number;
|
||||||
tooltip?: ReactNode;
|
|
||||||
showPercent?: ReactNode;
|
showPercent?: ReactNode;
|
||||||
changeColorOnWarning?: boolean;
|
changeColorOnWarning?: boolean;
|
||||||
warningPercentage?: number;
|
warningPercentage?: number;
|
||||||
metricName?: "cpu" | "memory" | "disk"; // Used for color setting
|
|
||||||
customColor?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function MetricBar(props: BarProps) {
|
export const MetricBar = withTooltip((props: BarProps) => {
|
||||||
const elem = useRef<HTMLDivElement>();
|
const { max, min = 0, showPercent = true, changeColorOnWarning = true, warningPercentage = 85, value } = props;
|
||||||
const { max, min, tooltip, showPercent, changeColorOnWarning = true, warningPercentage = 85, value, metricName, customColor } = props;
|
|
||||||
const percents = Math.min(100, value / (max - min) * 100);
|
const percents = Math.min(100, value / (max - min) * 100);
|
||||||
const [metricColor, setMetricColor] = useState("var(--colorVague)");
|
const percentsRounded = +percents.toFixed(2);
|
||||||
const color = (percents > warningPercentage && changeColorOnWarning) ? "pink" : customColor || metricColor;
|
const warning = percents > warningPercentage;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const cssVars = cssVar(elem.current);
|
|
||||||
|
|
||||||
setMetricColor(cssVars.get(`--color-${metricName}`).toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames(styles.metricBar)} data-testid="metric-bar" ref={elem}>
|
<div className={cssNames(styles.metricBar, props.className)} data-testid="metric-bar">
|
||||||
<VerticalBar color={color} value={percents} />
|
<VerticalBar
|
||||||
{showPercent && <label>{percents}%</label>}
|
value={percentsRounded}
|
||||||
|
className={cssNames(styles.bar, { [styles.warning]: warning && changeColorOnWarning })}
|
||||||
|
/>
|
||||||
|
{showPercent && <label>{percentsRounded}%</label>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.verticalBar {
|
.verticalBar {
|
||||||
|
--line-color: gray;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
@ -15,6 +17,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.value {
|
.value {
|
||||||
background-color: gray;
|
background-color: var(--line-color);
|
||||||
transition: all 0.2s ease-in-out;
|
transition: all 0.2s ease-in-out;
|
||||||
}
|
}
|
||||||
@ -9,14 +9,13 @@ import React, { HTMLAttributes } from "react";
|
|||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
|
|
||||||
interface BarProps extends HTMLAttributes<HTMLDivElement> {
|
interface BarProps extends HTMLAttributes<HTMLDivElement> {
|
||||||
color: string;
|
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VerticalBar({ color, className, value }: BarProps) {
|
export function VerticalBar({ className, value, ...rest }: BarProps) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.verticalBar} data-testid="vertical-bar">
|
<div className={styles.verticalBar} data-testid="vertical-bar" {...rest}>
|
||||||
<div className={cssNames(styles.value, className)} style={{ backgroundColor: color, height: `${value}%` }}></div>
|
<div className={cssNames(styles.value, className)} style={{ blockSize: `${value}%` }}></div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user