fix axis scaling of stale data

This commit is contained in:
2024-12-05 20:58:12 -08:00
parent a353585d47
commit cd3e15d9e9

View File

@@ -57,14 +57,43 @@ const memo = shallowRef<TelemetryDataItem[]>([]);
watch([value], ([val]) => {
const min_x = toValue(graph_data.min_x);
if (val) {
const val_t = Date.parse(val.timestamp);
if (val_t >= min_x) {
// TODO: Insert this in the right spot in memo
const new_memo = [val].concat(memo.value);
while (
new_memo.length > 2 &&
Date.parse(new_memo[new_memo.length - 2].timestamp) < min_x
) {
new_memo.pop();
const item_val = val.value[data.value!.data_type] as number;
if (item_val < min.value) {
min.value = item_val;
}
if (item_val > max.value) {
max.value = item_val;
}
memo.value = new_memo;
}
}
});
watch([graph_data.min_x, graph_data.max_x], ([min_x, max_x]) => {
let memo_changed = false;
const new_memo = ([] as TelemetryDataItem[]).concat(memo.value);
if (min_x) {
while (
new_memo.length > 2 &&
Date.parse(new_memo[new_memo.length - 2].timestamp) < toValue(min_x)
) {
new_memo.pop();
memo_changed = true;
}
}
if (max_x) {
while (
new_memo.length > 2 &&
Date.parse(new_memo[1].timestamp) > toValue(max_x)
) {
new_memo.shift();
memo_changed = true;
}
}
if (memo_changed) {
let min_val = Infinity;
let max_val = -Infinity;
for (const item of new_memo) {
@@ -72,6 +101,7 @@ watch([value], ([val]) => {
min_val = Math.min(min_val, item_val);
max_val = Math.max(max_val, item_val);
}
memo.value = new_memo;
max.value = max_val;
min.value = min_val;
}
@@ -160,7 +190,8 @@ const current_value = computed(() => {
:x="graph_data.x_map(toValue(graph_data.max_x)) + text_offset"
:y="axis_data.y_map(current_value)"
>
{{ current_value.toFixed(2) }}
{{ max.toFixed(2) }}
{{ min.toFixed(2) }}
</text>
</template>
</g>