From 147d1abaf870243f2a7d77164640d28b22674e19 Mon Sep 17 00:00:00 2001 From: Sergey Savelyev Date: Wed, 25 Dec 2024 12:32:36 -0500 Subject: [PATCH] improves performance --- frontend/src/components/GraphAxis.vue | 2 +- frontend/src/components/SvgGraph.vue | 61 +++--------------- frontend/src/components/TelemetryLine.vue | 47 +++----------- frontend/src/components/TimeText.vue | 78 +++++++++++++++++++++++ frontend/src/components/ValueLabel.vue | 62 ++++++++++++++++++ frontend/src/views/HomeView.vue | 47 ++++++++++---- 6 files changed, 193 insertions(+), 104 deletions(-) create mode 100644 frontend/src/components/TimeText.vue create mode 100644 frontend/src/components/ValueLabel.vue diff --git a/frontend/src/components/GraphAxis.vue b/frontend/src/components/GraphAxis.vue index 9b588cb..66cde27 100644 --- a/frontend/src/components/GraphAxis.vue +++ b/frontend/src/components/GraphAxis.vue @@ -282,7 +282,7 @@ const lines = computed(() => { } .middle_text { - alignment-baseline: middle; + dominant-baseline: middle; font-family: variables.$text-font; } diff --git a/frontend/src/components/SvgGraph.vue b/frontend/src/components/SvgGraph.vue index 8872e12..5e2aef3 100644 --- a/frontend/src/components/SvgGraph.vue +++ b/frontend/src/components/SvgGraph.vue @@ -2,6 +2,7 @@ import { computed, provide, ref } from 'vue'; import { useNow } from '@/composables/ticker'; import { GRAPH_DATA, type GraphData } from '@/graph/graph'; +import TimeText from '@/components/TimeText.vue'; const props = defineProps<{ width: number; @@ -82,7 +83,7 @@ provide(GRAPH_DATA, { const duration = computed(() => { const diff_x = max_x.value - min_x.value; - return time_lines.find((duration) => diff_x / duration >= 3)!; + return time_lines.find((duration) => diff_x / duration >= 2)!; }); const lines = computed(() => { @@ -97,54 +98,6 @@ const lines = computed(() => { } return result; }); - -function getDateString(date: Date) { - const year = props.utc ? date.getUTCFullYear() : date.getFullYear(); - const month = ( - (props.utc ? date.getMonth() : date.getMonth()) + 1 - ).toLocaleString('en-US', { - minimumIntegerDigits: 2, - useGrouping: false, - maximumFractionDigits: 0, - }); - const day = (props.utc ? date.getUTCDate() : date.getDate()).toLocaleString( - 'en-US', - { - minimumIntegerDigits: 2, - useGrouping: false, - maximumFractionDigits: 0, - }, - ); - const hour = ( - props.utc ? date.getUTCHours() : date.getHours() - ).toLocaleString('en-US', { - minimumIntegerDigits: 2, - useGrouping: false, - maximumFractionDigits: 0, - }); - const minute = ( - props.utc ? date.getUTCMinutes() : date.getMinutes() - ).toLocaleString('en-US', { - minimumIntegerDigits: 2, - useGrouping: false, - maximumFractionDigits: 0, - }); - const second = ( - props.utc ? date.getUTCSeconds() : date.getSeconds() - ).toLocaleString('en-US', { - minimumIntegerDigits: 2, - useGrouping: false, - maximumFractionDigits: 0, - }); - const milliseconds = ( - props.utc ? date.getUTCMilliseconds() : date.getMilliseconds() - ).toLocaleString('en-US', { - minimumIntegerDigits: 3, - useGrouping: false, - maximumFractionDigits: 0, - }); - return `${year}/${month}/${day} ${hour}:${minute}:${second}${duration.value < 1000 ? `.${milliseconds}` : ''}${props.utc ? 'Z' : ''}`; -} @@ -198,7 +153,7 @@ function getDateString(date: Date) { .bottom_edge { text-anchor: middle; - alignment-baseline: text-before-edge; + dominant-baseline: hanging; font-family: variables.$text-font; } diff --git a/frontend/src/components/TelemetryLine.vue b/frontend/src/components/TelemetryLine.vue index e70ecb8..81895e7 100644 --- a/frontend/src/components/TelemetryLine.vue +++ b/frontend/src/components/TelemetryLine.vue @@ -9,7 +9,6 @@ import { shallowRef, type ShallowRef, toValue, - useTemplateRef, watch, } from 'vue'; import { @@ -19,6 +18,7 @@ import { } from '@/composables/websocket'; import { GRAPH_DATA, type GraphData } from '@/graph/graph'; import { AXIS_DATA, type AxisData } from '@/graph/axis'; +import ValueLabel from '@/components/ValueLabel.vue'; const props = defineProps<{ data: string; @@ -28,7 +28,6 @@ const props = defineProps<{ const smoothing_distance = 0.15 * 1000; const text_offset = computed(() => 10); -const background_offset = computed(() => 5); const { data } = useTelemetry(() => props.data); const websocket = inject>(WEBSOCKET_SYMBOL)!; @@ -127,6 +126,7 @@ watch( }, ); +// This function is somewhat slow const points = computed(() => { let points = ''; if (memo.value.length == 0 || data.value == null) { @@ -156,7 +156,6 @@ const points = computed(() => { return points; }); -const labelRef = useTemplateRef('label-ref'); const current_value = computed(() => { const val = value.value; if (val) { @@ -173,27 +172,13 @@ const current_value = computed(() => { clip-path="url(#content)" :points="points" > - + + @@ -204,18 +189,4 @@ polyline { stroke-width: 1px; stroke: var(--indexed-color); } - -rect { - fill: variables.$background-color; - stroke-width: 1px; - stroke: var(--indexed-color); -} - -text { - alignment-baseline: middle; - font-family: variables.$text-font; - text-anchor: start; - stroke: var(--indexed-color); - fill: var(--indexed-color); -} diff --git a/frontend/src/components/TimeText.vue b/frontend/src/components/TimeText.vue new file mode 100644 index 0000000..de86ceb --- /dev/null +++ b/frontend/src/components/TimeText.vue @@ -0,0 +1,78 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/components/ValueLabel.vue b/frontend/src/components/ValueLabel.vue new file mode 100644 index 0000000..63780b3 --- /dev/null +++ b/frontend/src/components/ValueLabel.vue @@ -0,0 +1,62 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index 6af2e12..9e26264 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -12,24 +12,47 @@ provide(WEBSOCKET_SYMBOL, websocket);