fix: dont render graphs on every poll

This commit is contained in:
2026-10-06 21:01:37 +02:00
parent e151ab4f26
commit 98a71e3114
17 changed files with 783 additions and 659 deletions
@@ -0,0 +1,73 @@
import { memo, useCallback, useMemo } from 'react';
import { logSpace } from '../../utils/graph/curve';
import { drawCurves } from '../../utils/graph/draw';
import { GRAPH_X_MIN, GRAPH_X_MAX, GRAPH_Y_MIN, GRAPH_Y_MAX, GEQ_CURVE_Q } from '../../constants';
import { DiscreteFrequency } from '../../types';
import { GEQ_BANDS_LABEL } from '../../constants';
import LinearGraph from '../../../../components/LinearGraph/LinearGraph';
import { getGeqCurvePoints } from '../../utils/graph/geq';
import { LiveBands } from './GeqSection';
const GEQ_FREQS = logSpace(GRAPH_X_MIN, GRAPH_X_MAX, 1000);
export const GeqGraph = memo(function GeqGraph({
title,
gains,
bypass,
liveBands,
}: {
title: string;
gains: Record<DiscreteFrequency, number>;
bypass: boolean;
liveBands: LiveBands | undefined;
}) {
const curvePoints = useMemo(() => {
const values = GEQ_BANDS_LABEL.map(
({ frequency }) => liveBands?.[frequency] ?? gains[frequency] ?? 0
);
return getGeqCurvePoints({ freqs: GEQ_FREQS, values, q: GEQ_CURVE_Q });
}, [gains, liveBands]);
const draw = useCallback(
({ ctx, toPx }: any) => {
drawCurves({
ctx,
toPx,
xMin: GRAPH_X_MIN,
xMax: GRAPH_X_MAX,
yMin: GRAPH_Y_MIN,
yMax: GRAPH_Y_MAX,
curves: [
{
points: curvePoints,
style: { strokeColor: '#e5e7eb', dimmed: bypass },
},
],
});
},
[curvePoints, bypass]
);
return (
<div className="geq-graph-panel">
<div className="geq-graph-title">{title}</div>
<LinearGraph
xMin={GRAPH_X_MIN}
xMax={GRAPH_X_MAX}
xScale="log"
yMin={GRAPH_Y_MIN}
yMax={GRAPH_Y_MAX}
yStep={3}
xLabel="Band Hz"
yLabel="dB"
showGrid={true}
draw={draw}
/>
{bypass && (
<div className="geq-bypass-overlay">
<span>BYPASSED</span>
</div>
)}
</div>
);
});