Skip to content

Commit 05bac54

Browse files
committed
recenter on select, format precision for times
1 parent 7529cc1 commit 05bac54

8 files changed

Lines changed: 47 additions & 14 deletions

File tree

client/src/components/AnnotationList.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
SpectrogramSequenceAnnotation,
1616
} from "../api/api";
1717
import RecordingAnnotations from "./RecordingAnnotations.vue";
18+
import { formatSignificantDigits } from "@use/useUtils";
1819
export default defineComponent({
1920
name: "AnnotationList",
2021
components: {
@@ -107,6 +108,7 @@ export default defineComponent({
107108
annotationState,
108109
annotations,
109110
creationType,
111+
formatSignificantDigits,
110112
sequenceAnnotations,
111113
selectedId,
112114
selectedType,
@@ -191,7 +193,11 @@ export default defineComponent({
191193
>
192194
<span class="pl-2"
193195
><b
194-
>({{ annotation.end_time - annotation.start_time }}ms)</b
196+
>({{
197+
formatSignificantDigits(
198+
annotation.end_time - annotation.start_time,
199+
)
200+
}}ms)</b
195201
></span
196202
>
197203
</v-col>

client/src/components/PulseMetadataTooltip.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { defineComponent, nextTick, type PropType, ref, watch } from "vue";
33
import type { PulseMetadataTooltipData } from "./geoJS/layers/pulseMetadataLayer";
4+
import { formatSignificantDigits } from "@use/useUtils";
45
56
const MIN_WIDTH = 180;
67
@@ -41,7 +42,7 @@ export default defineComponent({
4142
{ immediate: true },
4243
);
4344
44-
return { cardRef, clampedLeft };
45+
return { cardRef, clampedLeft, formatSignificantDigits };
4546
},
4647
});
4748
</script>
@@ -113,7 +114,7 @@ export default defineComponent({
113114
</div> -->
114115
<div class="d-flex align-center">
115116
<span class="text-caption text-medium-emphasis mr-2">Duration</span>
116-
<span>{{ data.durationMs.toFixed(1) }} ms</span>
117+
<span>{{ formatSignificantDigits(data.durationMs) }} ms</span>
117118
</div>
118119
<div class="d-flex align-center">
119120
<span class="text-caption text-medium-emphasis mr-2">Fₘᵢₙ</span>

client/src/components/SpectrogramViewer.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,12 @@ export default defineComponent({
419419
found,
420420
props.spectroInfo,
421421
selectedType.value,
422+
scaledWidth.value,
423+
scaledHeight.value,
422424
);
423-
const bounds = geoJS.getGeoViewer().value.bounds();
424-
if (x < bounds.left || x > bounds.right) {
425-
geoJS.getGeoViewer().value.center({ x, y });
425+
const viewer = geoJS.getGeoViewer().value;
426+
if (viewer && x >= 0 && y >= 0) {
427+
viewer.center({ x, y });
426428
}
427429
}
428430
});

client/src/components/geoJS/geoJSUtils.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,18 +914,30 @@ function spectroToCenter(
914914
annotation: SpectrogramAnnotation | SpectrogramSequenceAnnotation,
915915
spectroInfo: SpectroInfo,
916916
type: "sequence" | "pulse",
917+
scaledWidth = 0,
918+
scaledHeight = 0,
917919
) {
918920
if (type === "pulse") {
919-
const geoJSON = spectroToGeoJSon(
920-
annotation as SpectrogramAnnotation,
921-
spectroInfo,
922-
);
923-
return findPolygonCenter(geoJSON);
921+
const pulse = annotation as SpectrogramAnnotation;
922+
const centerTime = (pulse.start_time + pulse.end_time) / 2;
923+
const x = spectroTimeToX(centerTime, spectroInfo, scaledWidth);
924+
const adjustedHeight =
925+
scaledHeight > spectroInfo.height ? scaledHeight : spectroInfo.height;
926+
const centerFreq = (pulse.low_freq + pulse.high_freq) / 2;
927+
const heightScale =
928+
adjustedHeight / (spectroInfo.high_freq - spectroInfo.low_freq);
929+
const y =
930+
adjustedHeight - (centerFreq - spectroInfo.low_freq) * heightScale;
931+
return [x, y];
924932
}
925933
if (type === "sequence") {
926934
const geoJSON = spectroSequenceToGeoJSon(
927935
annotation as SpectrogramSequenceAnnotation,
928936
spectroInfo,
937+
0,
938+
10,
939+
scaledWidth,
940+
scaledHeight,
929941
);
930942
return findPolygonCenter(geoJSON);
931943
}

client/src/components/geoJS/layers/pulseMetadataLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { PulseMetadata } from "@api/api";
44
import type { LayerStyle, LineData, TextData } from "./types";
55
import BaseTextLayer from "./baseTextLayer";
66
import type { PulseMetadataLabelsMode } from "@use/usePulseMetadata";
7+
import { formatSignificantDigits } from "@use/useUtils";
78

89
/** Point data for char_freq, knee, heel with pixel coords and label. */
910
interface PulsePointData {
@@ -398,7 +399,7 @@ export default class PulseMetadataLayer extends BaseTextLayer<TextData> {
398399

399400
const durationMidX = (bottomLeft.x + bottomRight.x) / 2;
400401
pulseText.push({
401-
text: `${durationMs.toFixed(1)} ms`,
402+
text: `${formatSignificantDigits(durationMs)} ms`,
402403
x: durationMidX,
403404
y: bottomLeft.y + labelOffset,
404405
offsetX: 0,

client/src/components/geoJS/layers/timeLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
spectroSequenceToGeoJSon,
88
spectroToGeoJSon,
99
} from "../geoJSUtils";
10+
import { formatSignificantDigits } from "@use/useUtils";
1011
import BaseTextLayer from "./baseTextLayer";
1112
import type { LayerStyle } from "./types";
1213

@@ -242,7 +243,7 @@ export default class TimeLayer extends BaseTextLayer<TextData> {
242243
const ypos = (ymax + ymin) / 2.0;
243244
// Now we need to create the text Labels
244245
this.textData.push({
245-
text: `${end_time - start_time}ₘₛ`,
246+
text: `${formatSignificantDigits(end_time - start_time)}ₘₛ`,
246247
x: xpos,
247248
y: ypos + lineDist,
248249
});

client/src/use/useUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ function extractDateTimeComponents(dateTimeString: string) {
3030
return { date: dateString, time: timeString };
3131
}
3232

33+
/** Format a numeric value to the given number of significant digits. */
34+
function formatSignificantDigits(value: number, significantDigits = 3): string {
35+
if (!Number.isFinite(value)) return String(value);
36+
if (value === 0) return "0";
37+
return String(Number(value.toPrecision(significantDigits)));
38+
}
39+
3340
function getImageDimensions(
3441
images: HTMLImageElement[],
3542
fallback: { width: number; height: number } = { width: 0, height: 0 },
@@ -96,6 +103,7 @@ function parseRecordingFilename(
96103

97104
export {
98105
DEFAULT_SAMPLE_FRAME_ID,
106+
formatSignificantDigits,
99107
getCurrentTime,
100108
extractDateTimeComponents,
101109
getImageDimensions,

client/src/views/Admin.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ export default defineComponent({
157157
<v-row>
158158
<v-switch
159159
v-model="settings.createPulseAnnotationsFromBatbot"
160-
:color="settings.createPulseAnnotationsFromBatbot ? 'primary' : ''"
160+
:color="
161+
settings.createPulseAnnotationsFromBatbot ? 'primary' : ''
162+
"
161163
label="Create pulse annotations from BatBot on import"
162164
/>
163165
</v-row>

0 commit comments

Comments
 (0)