Skip to content

Commit

Permalink
stretching the thumbnail (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonLewis authored Feb 22, 2024
1 parent 9ad5f94 commit 070907c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 35 deletions.
24 changes: 19 additions & 5 deletions client/src/components/ThumbnailViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default defineComponent({
const containerRef: Ref<HTMLElement | undefined> = ref();
const geoJS = useGeoJS();
const initialized = ref(false);
const clientHeight = ref(0);
const yScale = ref(1);
const polyLayerCreated= ref(false);
let downState: {
state: any,
Expand Down Expand Up @@ -110,12 +112,13 @@ export default defineComponent({
props.parentGeoViewerRef.value.zoom(props.parentGeoViewerRef.value.zoom() - 1);
}
const size = parent.size();
const { top } = parent.bounds();
outlineFeature.style(outlineStyle);
outlineFeature.data([[
parent.displayToGcs({x: 0, y: 0}),
parent.displayToGcs({x: size.width, y: 0}),
parent.displayToGcs({x: size.width, y: size.height}),
parent.displayToGcs({x: 0, y: size.height})
parent.displayToGcs({x: 0, y: top * yScale.value}),
parent.displayToGcs({x: size.width, y: top * yScale.value}),
parent.displayToGcs({x: size.width, y: (size.height * yScale.value) + (top * yScale.value)}),
parent.displayToGcs({x: 0, y: (size.height * yScale.value) + (top * yScale.value)})
]]).draw();
};
onParentPan();
Expand All @@ -125,11 +128,20 @@ export default defineComponent({
};
watch(containerRef, () => {
const { naturalWidth, naturalHeight } = props.image;
if (containerRef.value) {
clientHeight.value = containerRef.value.clientHeight;
}
if (containerRef.value) {
geoJS.initializeViewer(containerRef.value, naturalWidth, naturalHeight, true);
geoJS.drawImage(props.image, naturalWidth, naturalHeight);
const coords = geoJS.getGeoViewer().value.camera().worldToDisplay({x: 0, y:0});
const end = geoJS.getGeoViewer().value.camera().worldToDisplay({x: 0, y:naturalHeight});
const diff = coords.y - end.y;
// How much space to we have to multiply the size of the image
yScale.value = (clientHeight.value *0.5) / diff;
geoJS.drawImage(props.image, naturalWidth, naturalHeight*yScale.value);
initialized.value = true;
nextTick(() => createPolyLayer());

}
});

Expand All @@ -138,6 +150,7 @@ export default defineComponent({
containerRef,
geoViewerRef: geoJS.getGeoViewer(),
initialized,
yScale,
};
},
});
Expand All @@ -157,6 +170,7 @@ export default defineComponent({
:annotations="annotations"
:other-user-annotations="otherUserAnnotations"
:selected-id="selectedId"
:y-scale="yScale"
thumbnail
@selected="$emit('selected',$event)"
/>
Expand Down
14 changes: 10 additions & 4 deletions client/src/components/geoJS/LayerManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default defineComponent({
type: Boolean,
default: false,
},
yScale: {
type: Number,
default: 1,
}
},
emits: ["selected", "update:annotation", "create:annotation", "set-cursor"],
setup(props, { emit }) {
Expand Down Expand Up @@ -298,7 +302,8 @@ export default defineComponent({
annotations,
selectedType.value === 'pulse' ? selectedAnnotationId.value : null,
currentUser.value,
colorScale.value
colorScale.value,
props.yScale,
);
rectAnnotationLayer.redraw();
}
Expand All @@ -307,7 +312,8 @@ export default defineComponent({
temporalAnnotations,
selectedType.value === 'sequence' ? selectedAnnotationId.value : null,
currentUser.value,
colorScale.value
colorScale.value,
props.yScale,
);
temporalAnnotationLayer.redraw();
}
Expand Down Expand Up @@ -387,10 +393,10 @@ export default defineComponent({
if (props.spectroInfo) {
editAnnotationLayer = new EditAnnotationLayer(props.geoViewerRef, event, props.spectroInfo);
rectAnnotationLayer = new RectangleLayer(props.geoViewerRef, event, props.spectroInfo);
rectAnnotationLayer.formatData(localAnnotations.value, selectedAnnotationId.value, currentUser.value, colorScale.value);
rectAnnotationLayer.formatData(localAnnotations.value, selectedAnnotationId.value, currentUser.value, colorScale.value, props.yScale);
rectAnnotationLayer.redraw();
temporalAnnotationLayer = new TemporalLayer(props.geoViewerRef, temporalEvent, props.spectroInfo);
temporalAnnotationLayer.formatData(localTemporalAnnotations.value, selectedAnnotationId.value, currentUser.value, colorScale.value);
temporalAnnotationLayer.formatData(localTemporalAnnotations.value, selectedAnnotationId.value, currentUser.value, colorScale.value, props.yScale);
temporalAnnotationLayer.redraw();
if (!props.thumbnail) {
legendLayer = new LegendLayer(props.geoViewerRef, event, props.spectroInfo);
Expand Down
46 changes: 24 additions & 22 deletions client/src/components/geoJS/geoJSUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ function spectroTemporalToGeoJSon(
annotation: SpectrogramTemporalAnnotation,
spectroInfo: SpectroInfo,
ymin = 0,
ymax = 10
ymax = 10,
yScale = 1,
): GeoJSON.Polygon {
//scale pixels to time and frequency ranges
if (spectroInfo.start_times === undefined || spectroInfo.end_times === undefined) {
Expand All @@ -198,11 +199,11 @@ function spectroTemporalToGeoJSon(
type: "Polygon",
coordinates: [
[
[start_time, ymin],
[start_time, ymax],
[end_time, ymax],
[end_time, ymin],
[start_time, ymin],
[start_time, ymin * yScale],
[start_time, ymax * yScale],
[end_time, ymax * yScale],
[end_time, ymin * yScale],
[start_time, ymin * yScale],
],
],
};
Expand Down Expand Up @@ -239,11 +240,11 @@ function spectroTemporalToGeoJSon(
type: "Polygon",
coordinates: [
[
[start_time, ymin],
[start_time, ymax],
[end_time, ymax],
[end_time, ymin],
[start_time, ymin],
[start_time, ymin * yScale],
[start_time, ymax * yScale],
[end_time, ymax * yScale],
[end_time, ymin * yScale],
[start_time, ymin * yScale],
],
],
};
Expand All @@ -264,7 +265,8 @@ function spectroTemporalToGeoJSon(

function spectroToGeoJSon(
annotation: SpectrogramAnnotation,
spectroInfo: SpectroInfo
spectroInfo: SpectroInfo,
yScale = 1
): GeoJSON.Polygon {
//scale pixels to time and frequency ranges
if (spectroInfo.start_times === undefined || spectroInfo.end_times === undefined) {
Expand All @@ -281,11 +283,11 @@ function spectroToGeoJSon(
type: "Polygon",
coordinates: [
[
[start_time, low_freq],
[start_time, high_freq],
[end_time, high_freq],
[end_time, low_freq],
[start_time, low_freq],
[start_time, low_freq * yScale],
[start_time, high_freq * yScale],
[end_time, high_freq * yScale],
[end_time, low_freq * yScale],
[start_time, low_freq * yScale],
],
],
};
Expand Down Expand Up @@ -327,11 +329,11 @@ function spectroToGeoJSon(
type: "Polygon",
coordinates: [
[
[start_time, low_freq],
[start_time, high_freq],
[end_time, high_freq],
[end_time, low_freq],
[start_time, low_freq],
[start_time, low_freq * yScale],
[start_time, high_freq * yScale],
[end_time, high_freq * yScale],
[end_time, low_freq * yScale],
[start_time, low_freq * yScale],
],
],
};
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/geoJS/layers/rectangleLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ export default class RectangleLayer {
annotationData: SpectrogramAnnotation[],
selectedIndex: number | null,
currentUser: string,
colorScale?: d3.ScaleOrdinal<string, string, never>
colorScale?: d3.ScaleOrdinal<string, string, never>,
yScale = 1,
) {
const arr: RectGeoJSData[] = [];
annotationData.forEach((annotation: SpectrogramAnnotation) => {
const polygon = spectroToGeoJSon(annotation, this.spectroInfo);
const polygon = spectroToGeoJSon(annotation, this.spectroInfo, yScale);
const [xmin, ymin] = polygon.coordinates[0][0];
const [xmax, ymax] = polygon.coordinates[0][2];
// For the compressed view we need to filter out default or NaN numbers
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/geoJS/layers/temporalLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ export default class TemporalLayer {
annotationData: SpectrogramTemporalAnnotation[],
selectedIndex: number | null,
currentUser: string,
colorScale?: d3.ScaleOrdinal<string, string, never>
colorScale?: d3.ScaleOrdinal<string, string, never>,
yScale = 1,
) {
const arr: RectGeoJSData[] = [];
annotationData.forEach((annotation: SpectrogramTemporalAnnotation) => {
const polygon = spectroTemporalToGeoJSon(annotation, this.spectroInfo, -10, -50);
const polygon = spectroTemporalToGeoJSon(annotation, this.spectroInfo, -10, -50,yScale);
const [xmin, ymin] = polygon.coordinates[0][0];
const [xmax, ymax] = polygon.coordinates[0][2];
// For the compressed view we need to filter out default or NaN numbers
Expand Down

0 comments on commit 070907c

Please sign in to comment.