diff --git a/client/src/components/SpectrogramViewer.vue b/client/src/components/SpectrogramViewer.vue index 119d022..10d4da8 100644 --- a/client/src/components/SpectrogramViewer.vue +++ b/client/src/components/SpectrogramViewer.vue @@ -46,6 +46,8 @@ export default defineComponent({ const geoJS = useGeoJS(); const initialized = ref(false); const cursor = ref(""); + const scaledWidth = ref(0); + const scaledHeight = ref(0); const imageCursorRef: Ref = ref(); const setCursor = (newCursor: string) => { cursor.value = newCursor; @@ -78,20 +80,23 @@ export default defineComponent({ if (!props.spectroInfo) { return; } + const adjustedWidth = scaledWidth.value > props.spectroInfo.width ? scaledWidth.value : props.spectroInfo.width; + const adjustedHeight = scaledHeight.value > props.spectroInfo.height ? scaledHeight.value : props.spectroInfo.height; + const freq = - props.spectroInfo.height - y >= 0 - ? ((props.spectroInfo.height - y) * - (props.spectroInfo.high_freq - props.spectroInfo.low_freq)) / - props.spectroInfo.height / - 1000 + - props.spectroInfo.low_freq / 1000 + adjustedHeight - y >= 0 + ? ((adjustedHeight - y) * + (props.spectroInfo.high_freq - props.spectroInfo.low_freq)) / + adjustedHeight / + 1000 + + props.spectroInfo.low_freq / 1000 : -1; if (!props.spectroInfo.end_times && !props.spectroInfo.start_times) { - if (x >= 0 && props.spectroInfo.height - y >= 0) { + if (x >= 0 && adjustedHeight - y >= 0) { const time = x * - ((props.spectroInfo.end_time - props.spectroInfo.start_time) / props.spectroInfo.width); + ((props.spectroInfo.end_time - props.spectroInfo.start_time) / adjustedWidth); emit("hoverData", { time, freq }); } else { emit("hoverData", { time: -1, freq: -1 }); @@ -102,9 +107,9 @@ export default defineComponent({ props.spectroInfo.end_times ) { // compressed view - if (x >= 0 && props.spectroInfo.height - y >= 0) { + if (x >= 0 && adjustedHeight - y >= 0) { const timeLength = props.spectroInfo.end_time - props.spectroInfo.start_time; - const timeToPixels = props.spectroInfo.width / timeLength; + const timeToPixels = adjustedWidth / timeLength; // find X in the range let offsetAdditive = 0; for (let i = 0; i < props.spectroInfo.start_times.length; i += 1) { @@ -128,6 +133,8 @@ export default defineComponent({ }; watch(containerRef, () => { const { naturalWidth, naturalHeight } = props.image; + scaledWidth.value = naturalWidth; + scaledHeight.value = naturalHeight; if (containerRef.value) geoJS.initializeViewer(containerRef.value, naturalWidth, naturalHeight); geoJS.drawImage(props.image, naturalWidth, naturalHeight); @@ -167,9 +174,9 @@ export default defineComponent({ if (skipNextSelected) { skipNextSelected = false; return; - + } - const found = selectedType.value === 'pulse' ? annotations.value.find((item) => item.id === selectedId.value): temporalAnnotations.value.find((item) => item.id === selectedId.value); + const found = selectedType.value === 'pulse' ? annotations.value.find((item) => item.id === selectedId.value) : temporalAnnotations.value.find((item) => item.id === selectedId.value); if (found && props.spectroInfo) { const center = spectroToCenter(found, props.spectroInfo, selectedType.value); @@ -184,30 +191,23 @@ export default defineComponent({ ); const wheelEvent = (event: WheelEvent) => { - const geoViewerRef = geoJS.getGeoViewer(); - - if (geoViewerRef.value) { - const camera = geoViewerRef.value.camera(); - const view = camera.view; - - console.log(view); - let baseZoomX = view[0]; - let baseZoomY = view[5]; - // view[5] = view[5] * 1.1 - if (event.ctrlKey) { - // Zoom along the X-axis - baseZoomX += event.deltaY * 0.000001; - } else if (event.shiftKey) { - // Zoom along the Y-axis - baseZoomY += event.deltaY * 0.000001; - } - view[0] = baseZoomX; - view[5] = baseZoomY; - camera.view = view; - geoViewerRef.value.draw(); + const geoViewerRef = geoJS.getGeoViewer(); + const { naturalWidth, naturalHeight } = props.image; - } -}; + if (event.ctrlKey) { + scaledWidth.value = scaledWidth.value + event.deltaY * 4; + if (scaledWidth.value < naturalWidth) { + scaledWidth.value = naturalWidth; + } + geoJS.drawImage(props.image, scaledWidth.value, scaledHeight.value, false); + } else if (event.shiftKey) { + scaledHeight.value = scaledHeight.value + event.deltaY * 1; + if (scaledHeight.value < naturalHeight) { + scaledHeight.value = naturalHeight; + } + geoJS.drawImage(props.image, scaledWidth.value, scaledHeight.value, false); + } + }; @@ -223,38 +223,23 @@ export default defineComponent({ imageCursorRef, blackBackground, wheelEvent, + scaledWidth, + scaledHeight, }; }, });