diff --git a/src/lib/components/impacts_view/test_cases_view/test_case_selected/graph/TestCaseGraph.svelte b/src/lib/components/impacts_view/test_cases_view/test_case_selected/graph/TestCaseGraph.svelte
index 3b1ae1b8b9a057db4af83155edc46e7f7f13b052..adaa1cfbb955121f00ac4aa2fea4c5ec1e98f547 100644
--- a/src/lib/components/impacts_view/test_cases_view/test_case_selected/graph/TestCaseGraph.svelte
+++ b/src/lib/components/impacts_view/test_cases_view/test_case_selected/graph/TestCaseGraph.svelte
@@ -534,6 +534,8 @@
const initialMin = domain.x[0] ?? slider.min
const initialMax = domain.x[1] ?? slider.max
let updatedStepValue = Math.round((initialMax - initialMin) / 100)
+ let updatedMin = initialMin
+ let updatedMax = initialMax
const value = getSituationVariableValue(
situation,
@@ -541,17 +543,25 @@
slider.id,
year,
) as number
-
- const offsetFromMin = value - initialMin
let vectorIndex = Math.max(
0,
- Math.min(100, Math.round(offsetFromMin / updatedStepValue)),
+ Math.min(100, Math.round(value / updatedStepValue)),
)
- let updatedMin = value - vectorIndex * updatedStepValue
- vectorIndex = updatedMin < 0 ? vectorIndex - 1 : vectorIndex
- updatedMin = updatedMin < 0 ? updatedMin + updatedStepValue : updatedMin
- const updatedMax = updatedMin + updatedStepValue * 100
+ const isValueOutOfRange =
+ value > initialMax || value < initialMin ? true : false
+
+ if (!isValueOutOfRange) {
+ const offsetFromMin = value - initialMin
+ let updatedMin = value - vectorIndex * updatedStepValue
+ vectorIndex = updatedMin < 0 ? vectorIndex - 1 : vectorIndex
+ updatedMin = updatedMin < 0 ? updatedMin + updatedStepValue : updatedMin
+ updatedMax = updatedMin + updatedStepValue * 100
+ vectorIndex = Math.max(
+ 0,
+ Math.min(100, Math.round(offsetFromMin / updatedStepValue)),
+ )
+ }
// Update situation
// setSituationVariableValue(
// entityByKey,