add graph cursor

This commit is contained in:
2025-01-04 11:45:09 -05:00
parent 35603c98a4
commit c69022448f
5 changed files with 139 additions and 39 deletions

View File

@@ -152,8 +152,8 @@ watch([graph_data.min_x, graph_data.max_x], ([min_x, max_x]) => {
if (min_x) {
while (
memo.value.data.length > 2 &&
memo.value.data[1].x < toValue(min_x)
memo.value.data.length > 1 &&
memo.value.data[0].x < toValue(min_x)
) {
memo.value.data.shift();
memo_changed = true;
@@ -161,8 +161,8 @@ watch([graph_data.min_x, graph_data.max_x], ([min_x, max_x]) => {
}
if (max_x) {
while (
memo.value.data.length > 2 &&
memo.value.data[memo.value.data.length - 2].x > toValue(max_x)
memo.value.data.length > 1 &&
memo.value.data[memo.value.data.length - 1].x > toValue(max_x)
) {
memo.value.data.pop();
memo_changed = true;
@@ -221,10 +221,9 @@ watch([recompute_points], () => {
return '';
}
const future_number =
toValue(graph_data.max_x) + toValue(graph_data.max_update_rate);
let last_x = graph_data.x_map(future_number) + smoothing_distance_x;
let last_x = graph_data.x_map(
memo.value.data[memo.value.data.length - 1].x,
);
old_max.value = toValue(graph_data.max_x);
for (let i = memo.value.data.length - 1; i >= 0; i--) {
@@ -247,12 +246,22 @@ watch([recompute_points], () => {
points.value = new_points;
});
const current_value = computed(() => {
const val = value.value;
if (val) {
return val.value[telemetry_data.value!.data_type] as number;
const current_data_point = computed(() => {
if (memo.value.data.length == 0) {
return undefined;
}
return undefined;
const cursor_time = toValue(graph_data.cursor_time);
const index = Math.max(memo.value.find_index(cursor_time) - 1, 0);
return memo.value.data[index];
});
const current_data_point_line = computed(() => {
if (!current_data_point.value) {
return '';
}
const x = current_data_point.value.x;
const y = axis_data.y_map(current_data_point.value.y);
return `${graph_data.x_map(x)},${y} ${graph_data.x_map(toValue(graph_data.max_x))},${y}`;
});
const legend_x = computed(() => {
@@ -319,12 +328,13 @@ function onCloseLegend() {
:transform="group_transform"
:points="points"
></polyline>
<polyline fill="none" :points="current_data_point_line"> </polyline>
</g>
<ValueLabel
v-if="current_value"
v-if="current_data_point"
:x="graph_data.x_map(toValue(graph_data.max_x)) + text_offset"
:y="axis_data.y_map(current_value)"
:value="current_value"
:y="axis_data.y_map(current_data_point.y)"
:value="current_data_point.y"
>
</ValueLabel>
<template v-if="toValue(graph_data.legend_enabled)">