Files
go-service/cmd/server/web/js/state.js

21 lines
512 B
JavaScript

// state.js (вся логика состояния)
export const state = {
maxPoints: 1000,
signalHistory: [],
smoothValue: 0,
};
// сглаживание
export function smooth(target) {
state.smoothValue += 0.2 * (target - state.smoothValue);
return state.smoothValue;
}
// добавление в историю
export function addSignal(value) {
state.signalHistory.push(value);
if (state.signalHistory.length > state.maxPoints) {
state.signalHistory.shift();
}
}