Skip to content

Commit 44a0e1c

Browse files
authored
fix: slow ui due to big payload being formatted/colonized + graph title overflow (#84)
* feat: improve code highlighting and tooltip support in UI components - Introduced computed properties and constants for enhanced readability and logic in `CodeHighlight.vue`. - Added truncated raw code display with a max length for performance optimization. - Added tooltips to `LineChartCard.vue` titles, providing better UX for long text. * feat: add tooltips for truncated titles in LineChartCard - Improved UX by adding tooltips to display full text of truncated `dataPath` and `topic`. * fix: improve safety in `CodeHighlight` and tweak text wrapping in `LineChartCard` - Added null-check for `codeTextRef` in `CodeHighlight.vue` to prevent runtime errors. - Refactored truncated raw code logic into a helper function for readability. - Adjusted `LineChartCard.vue` styling to handle long text with better wrapping and breaking behavior.
1 parent c9f26b4 commit 44a0e1c

File tree

3 files changed

+55
-16
lines changed

3 files changed

+55
-16
lines changed

src/renderer/src/App.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<script setup lang="ts">
2+
import { useHighlightTheme } from '@renderer/composables/useHighlightTheme'
23
import { ElectronApi } from '@renderer/assets/js/electron-api'
34
import { onBeforeMount, watch } from 'vue'
45
import { useQuasar } from 'quasar'
56
67
const $q = useQuasar()
78
9+
useHighlightTheme()
10+
811
watch(
912
() => $q.dark.isActive,
1013
(isDark) => ElectronApi.darkMode(isDark)

src/renderer/src/components/graphs/LineChartCard.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const options = computed(() => {
7979
trigger: 'axis',
8080
axisPointer: {
8181
label: {
82-
formatter: (params: any) => moment(params.value).format('HH:mm:ss')
82+
formatter: (params: { value: string }) => moment(params.value).format('HH:mm:ss')
8383
}
8484
}
8585
},
@@ -128,12 +128,29 @@ const defaultDataPathText = '<value>'
128128
<template>
129129
<q-card class="graph-card tw-border tw-p-2" flat :class="[dataGraph.size]">
130130
<q-card-section v-if="showTitle" class="drag-handle tw-cursor-grab tw-p-2">
131-
<div class="tw-h-7 tw-text-xl">{{ dataGraph.dataPath || defaultDataPathText }}</div>
131+
<div class="tw-line-clamp-1 tw-h-7 tw-break-all tw-text-xl">
132+
{{ dataGraph.dataPath || defaultDataPathText }}
133+
134+
<q-tooltip
135+
class="tw-bg-gray-200 tw-text-black dark:tw-bg-neutral-700 dark:tw-text-neutral-200"
136+
:offset="[5, 5]"
137+
>
138+
{{ dataGraph.dataPath || defaultDataPathText }}
139+
</q-tooltip>
140+
</div>
132141
<div
133-
class="color-details tw-line-clamp-1 tw-max-w-full tw-overflow-hidden tw-overflow-ellipsis tw-text-sm"
142+
class="color-details tw-line-clamp-1 tw-max-w-full tw-overflow-hidden tw-overflow-ellipsis tw-break-all tw-text-sm"
134143
:title="dataGraph.topic"
135-
v-text="dataGraph.topic"
136-
/>
144+
>
145+
{{ dataGraph.topic }}
146+
147+
<q-tooltip
148+
class="tw-bg-gray-200 tw-text-black dark:tw-bg-neutral-700 dark:tw-text-neutral-200"
149+
:offset="[5, 5]"
150+
>
151+
{{ dataGraph.topic }}
152+
</q-tooltip>
153+
</div>
137154
</q-card-section>
138155

139156
<div class="tw-h-[200px]">

src/renderer/src/components/tap-topics/CodeHighlight.vue

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<script lang="ts" setup>
2-
import { useHighlightTheme } from '@renderer/composables/useHighlightTheme'
2+
import { ref, watch, nextTick, computed, onMounted } from 'vue'
33
import { formatCode } from '@renderer/assets/js/format-code'
44
import json from 'highlight.js/lib/languages/json'
55
import yaml from 'highlight.js/lib/languages/yaml'
66
import xml from 'highlight.js/lib/languages/xml'
7-
import { ref, watch, nextTick } from 'vue'
87
import hljs from 'highlight.js/lib/core'
98
9+
const MAX_CODE_LENGTH = 8192
10+
const MAX_RAW_CODE_LENGTH = 1024
11+
1012
hljs.registerLanguage('json', json)
1113
hljs.registerLanguage('xml', xml)
1214
hljs.registerLanguage('yaml', yaml)
@@ -18,21 +20,30 @@ type Props = {
1820
1921
const props = defineProps<Props>()
2022
21-
useHighlightTheme()
23+
const messageSize = computed(() => props.code.length)
24+
25+
const showFormatedCode = computed(
26+
() => props.language !== 'raw' && messageSize.value < MAX_CODE_LENGTH
27+
)
2228
23-
const highlighted = ref('')
2429
const codeTextRef = ref<HTMLElement>()
2530
31+
const updateElementHighlight = () => {
32+
if (!props.language || props.language === 'raw') return
33+
34+
const code = formatCode(props.code, props.language)
35+
36+
if (codeTextRef.value) {
37+
codeTextRef.value.innerHTML = hljs.highlight(code, { language: props.language }).value
38+
}
39+
}
40+
2641
watch(
2742
[() => props.code, () => props.language],
2843
() => {
2944
if (!props.language || props.language === 'raw') return
3045
31-
const code = formatCode(props.code, props.language)
32-
33-
highlighted.value = hljs.highlight(code, {
34-
language: props.language
35-
}).value
46+
updateElementHighlight()
3647
3748
nextTick(() => {
3849
if (!codeTextRef.value) return
@@ -49,11 +60,19 @@ watch(
4960
},
5061
{ immediate: true }
5162
)
63+
64+
onMounted(() => updateElementHighlight())
65+
66+
const getRawCode = () => {
67+
if (props.code.length > MAX_RAW_CODE_LENGTH) {
68+
return `${props.code.slice(0, MAX_RAW_CODE_LENGTH)}... (truncated)`
69+
} else return props.code
70+
}
5271
</script>
5372

5473
<template>
55-
<span v-if="language !== 'raw'" ref="codeTextRef" class="code-text" v-html="highlighted" />
56-
<span v-else class="code-text" v-text="code" />
74+
<span v-if="showFormatedCode" ref="codeTextRef" class="code-text" />
75+
<span v-else class="code-text" v-text="getRawCode()" />
5776
</template>
5877

5978
<style scoped lang="less">

0 commit comments

Comments
 (0)