fix axis scaling of stale data
This commit is contained in:
@@ -57,14 +57,43 @@ const memo = shallowRef<TelemetryDataItem[]>([]);
|
|||||||
watch([value], ([val]) => {
|
watch([value], ([val]) => {
|
||||||
const min_x = toValue(graph_data.min_x);
|
const min_x = toValue(graph_data.min_x);
|
||||||
if (val) {
|
if (val) {
|
||||||
const new_memo = [val].concat(memo.value);
|
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);
|
||||||
|
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 (
|
while (
|
||||||
new_memo.length > 2 &&
|
new_memo.length > 2 &&
|
||||||
Date.parse(new_memo[new_memo.length - 2].timestamp) < min_x
|
Date.parse(new_memo[new_memo.length - 2].timestamp) < toValue(min_x)
|
||||||
) {
|
) {
|
||||||
new_memo.pop();
|
new_memo.pop();
|
||||||
|
memo_changed = true;
|
||||||
}
|
}
|
||||||
memo.value = new_memo;
|
}
|
||||||
|
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 min_val = Infinity;
|
||||||
let max_val = -Infinity;
|
let max_val = -Infinity;
|
||||||
for (const item of new_memo) {
|
for (const item of new_memo) {
|
||||||
@@ -72,6 +101,7 @@ watch([value], ([val]) => {
|
|||||||
min_val = Math.min(min_val, item_val);
|
min_val = Math.min(min_val, item_val);
|
||||||
max_val = Math.max(max_val, item_val);
|
max_val = Math.max(max_val, item_val);
|
||||||
}
|
}
|
||||||
|
memo.value = new_memo;
|
||||||
max.value = max_val;
|
max.value = max_val;
|
||||||
min.value = min_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"
|
:x="graph_data.x_map(toValue(graph_data.max_x)) + text_offset"
|
||||||
:y="axis_data.y_map(current_value)"
|
:y="axis_data.y_map(current_value)"
|
||||||
>
|
>
|
||||||
{{ current_value.toFixed(2) }}
|
{{ max.toFixed(2) }}
|
||||||
|
{{ min.toFixed(2) }}
|
||||||
</text>
|
</text>
|
||||||
</template>
|
</template>
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
Reference in New Issue
Block a user