From 562ebacccfe6b77f7e6eee9459d2474a1e73e6e0 Mon Sep 17 00:00:00 2001 From: "Hofstetter Benjamin (extern)" Date: Fri, 7 Feb 2025 16:29:04 +0100 Subject: [PATCH] fit view check if there is an update --- src/App.vue | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/App.vue b/src/App.vue index fbd3551..a38d033 100644 --- a/src/App.vue +++ b/src/App.vue @@ -27,15 +27,22 @@ const { fitView, nodeLookup} = useVueFlow() const selectedFormat = ref(rdfFormats.find(f => f.type === RdfSerializationType.Turtle) ?? rdfFormats[0]); const rdfFormatOptions = ref(rdfFormats); const rdfText = ref(''); +let rdfSimpleHash = 0; const currentSerialization = computed(() => selectedFormat.value.type); const dataset = ref(rdfEnvironment.dataset() as unknown as Dataset); const hideEditorSplitterPanel = ref(false); const showSearchPanel = ref(false); - const showAboutDialog = ref(false); function onQuadsChanged(rdfData: RdfData) { + const hash = simpleHash(rdfData.rdfText); + if(hash === rdfSimpleHash) { + // dont update the ui if nothing has changed + return; + } + rdfSimpleHash = hash; + const newDataset = rdfEnvironment.dataset(rdfData.quads) as unknown as Dataset; prefixMap.update(rdfData.prefix); rdfText.value = rdfData.rdfText; @@ -52,13 +59,8 @@ function toggleSearch () { showSearchPanel.value = !showSearchPanel.value; if (showSearchPanel.value) { hideEditorSplitterPanel.value = true; - window.setTimeout(() => { - fitView({ - duration: 1000, // use this if you want a smooth transition to the node - padding: 0.3 // use this for some padding around the node - }) - }) - } + } + } function onFormatChange(rdfSerializationType: RdfSerializationType) { @@ -82,7 +84,22 @@ function onNdeSelected(term: Term) { }) } +function zoomFitView () { + setTimeout(() => { + fitView({ + duration: 1000, // use this if you want a smooth transition to the node + padding: 0.3 // use this for some padding around the node +})}, 100) +} +function simpleHash(str: string): number { + let hash = 0; + for (let i = 0; i < str.length; i++) { + hash = (hash << 5) - hash + str.charCodeAt(i); + hash |= 0; // Convert to 32-bit integer + } + return hash >>> 0; // Convert to unsigned integer +} @@ -102,6 +119,7 @@ function onNdeSelected(term: Term) {