mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 11:39:04 +08:00
feat: handle linear to exponential conversion for logs, services and hosts
This commit is contained in:
parent
42ac9ab6fe
commit
44f41c55f9
@ -31,6 +31,18 @@ const linearToExponential = (
|
|||||||
return Math.round(expValue);
|
return Math.round(expValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const exponentialToLinear = (
|
||||||
|
expValue: number,
|
||||||
|
min: number,
|
||||||
|
max: number,
|
||||||
|
): number => {
|
||||||
|
const expMin = Math.log10(min);
|
||||||
|
const expMax = Math.log10(max);
|
||||||
|
const linearValue =
|
||||||
|
((Math.log10(expValue) - expMin) / (expMax - expMin)) * 100;
|
||||||
|
return Math.round(linearValue); // Round to get a whole number within the 0-100 range
|
||||||
|
};
|
||||||
|
|
||||||
interface OptimiseSignozNeedsProps {
|
interface OptimiseSignozNeedsProps {
|
||||||
optimiseSignozDetails: OptimiseSignozDetails;
|
optimiseSignozDetails: OptimiseSignozDetails;
|
||||||
setOptimiseSignozDetails: (details: OptimiseSignozDetails) => void;
|
setOptimiseSignozDetails: (details: OptimiseSignozDetails) => void;
|
||||||
@ -84,6 +96,22 @@ function OptimiseSignozNeeds({
|
|||||||
optimiseSignozDetails?.services || 0,
|
optimiseSignozDetails?.services || 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Internal state for the linear slider
|
||||||
|
const [sliderValues, setSliderValues] = useState({
|
||||||
|
logsPerDay: 0,
|
||||||
|
hostsPerDay: 0,
|
||||||
|
services: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSliderValues({
|
||||||
|
logsPerDay: exponentialToLinear(logsPerDay, logsMin, logsMax),
|
||||||
|
hostsPerDay: exponentialToLinear(hostsPerDay, hostsMin, hostsMax),
|
||||||
|
services: exponentialToLinear(services, servicesMin, servicesMax),
|
||||||
|
});
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOptimiseSignozDetails({
|
setOptimiseSignozDetails({
|
||||||
logsPerDay,
|
logsPerDay,
|
||||||
@ -129,15 +157,7 @@ function OptimiseSignozNeeds({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal state for the linear slider
|
|
||||||
const [sliderValues, setSliderValues] = useState({
|
|
||||||
logsPerDay: 0,
|
|
||||||
hostsPerDay: 0,
|
|
||||||
services: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSliderChange = (key: string, value: number): void => {
|
const handleSliderChange = (key: string, value: number): void => {
|
||||||
console.log('value', value);
|
|
||||||
setSliderValues({
|
setSliderValues({
|
||||||
...sliderValues,
|
...sliderValues,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
@ -145,13 +165,13 @@ function OptimiseSignozNeeds({
|
|||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'logsPerDay':
|
case 'logsPerDay':
|
||||||
setLogsPerDay(value);
|
setLogsPerDay(linearToExponential(value, logsMin, logsMax));
|
||||||
break;
|
break;
|
||||||
case 'hostsPerDay':
|
case 'hostsPerDay':
|
||||||
setHostsPerDay(value);
|
setHostsPerDay(linearToExponential(value, hostsMin, hostsMax));
|
||||||
break;
|
break;
|
||||||
case 'services':
|
case 'services':
|
||||||
setServices(value);
|
setServices(linearToExponential(value, servicesMin, servicesMax));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user