Skip to content

Commit

Permalink
Fix new test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Dec 20, 2024
1 parent b49dd51 commit ccc83cb
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 167 deletions.
3 changes: 2 additions & 1 deletion girder/girder_large_image/web_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"promise/no-return-in-finally": "error",
"promise/no-return-wrap": "error",
"vue/require-prop-types": "off",
"vue/multiline-html-element-content-newline": "off"
"vue/multiline-html-element-content-newline": "off",
"vue/html-self-closing": "off"
},
"root": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import $ from 'jquery';
import _ from 'underscore';
import Vue from 'vue';

import {wrap} from '@girder/core/utilities/PluginUtils';
import eventStream from '@girder/core/utilities/EventStream';
import ItemView from '@girder/core/views/body/ItemView';
import View from '@girder/core/views/View';

import {restRequest} from '@girder/core/rest';

import largeImageConfig from './configView';
import * as viewers from './imageViewerWidget';

Expand All @@ -15,12 +18,9 @@ import '../stylesheets/imageViewerSelectWidget.styl';
import FrameSelector from '../widgets/FrameSelector.vue';
import DualInput from '../widgets/DualInput.vue';
import CompositeLayers from '../widgets/CompositeLayers.vue';
import HistogramEditor from '../widgets/HistogramEditor.vue'
import colors from '../widgets/colors.json'

import HistogramEditor from '../widgets/HistogramEditor.vue';
import colors from '../widgets/colors.json';
import PresetsMenu from '../vue/components/PresetsMenu.vue';
import {restRequest} from '@girder/core/rest';
import Vue from 'vue';

wrap(ItemView, 'render', function (render) {
// ItemView is a special case in which rendering is done asynchronously,
Expand Down Expand Up @@ -88,15 +88,16 @@ var ImageViewerSelectWidget = View.extend({
url: 'item/' + this.itemId + '/tiles/histogram',
data: params
}).then((response) => {
const frameHistograms = this.vueApp._props.frameHistograms || {}
frameHistograms[params.frame] = response
this.vueApp._props.frameHistograms = Object.assign({}, frameHistograms)
})
}
CompositeLayers.components = { HistogramEditor }
FrameSelector.components = { DualInput, CompositeLayers, HistogramEditor, PresetsMenu };
const component = Vue.extend(FrameSelector);
const vm = new component({
const frameHistograms = this.vueApp._props.frameHistograms || {};
frameHistograms[params.frame] = response;
this.vueApp._props.frameHistograms = Object.assign({}, frameHistograms);
return undefined;
});
};
CompositeLayers.components = {HistogramEditor};
FrameSelector.components = {DualInput, CompositeLayers, HistogramEditor, PresetsMenu};
const Component = Vue.extend(FrameSelector);
const vm = new Component({
el,
propsData: {
currentFrame: 0,
Expand All @@ -106,8 +107,8 @@ var ImageViewerSelectWidget = View.extend({
liConfig: this._liConfig,
frameHistograms: undefined,
getFrameHistogram,
colors,
},
colors
}
});
this.vueApp = vm;
},
Expand Down
27 changes: 15 additions & 12 deletions large_image/tilesource/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
likely lead to crashes. This is only for use in JupyterLab.
"""
import aiohttp
import asyncio
import ast
import asyncio
import importlib.util
import json
import os
import re
import numpy as np
from urllib.parse import urlencode, urlparse, parse_qs, quote
import weakref
from typing import Any, Dict, List, Optional, Tuple, Union, cast
from urllib.parse import parse_qs, quote, urlencode, urlparse

import aiohttp
import numpy as np

from large_image.exceptions import TileSourceXYZRangeError
from large_image.tilesource.utilities import JSONDict
Expand Down Expand Up @@ -266,7 +266,7 @@ def make_map(
ipyleaflet layer, and the center of the tile source.
"""
from ipyleaflet import Map, basemaps, projections
from ipywidgets import IntSlider, VBox
from ipywidgets import VBox

try:
default_zoom = metadata['levels'] - metadata['sourceLevels']
Expand Down Expand Up @@ -400,19 +400,21 @@ def from_map(self, coordinate: Union[List[float], Tuple[float, float]]) -> Tuple
def update_frame(self, frame, style, **kwargs):
if self._layer:
parsed_url = urlparse(self._layer.url)
scheme, netloc, path, query = parsed_url.scheme, parsed_url.netloc, parsed_url.path, parsed_url.query
scheme = parsed_url.scheme
netloc = parsed_url.netloc
path = parsed_url.path
query = parsed_url.query
query = {k: v[0] for k, v in parse_qs(query).items()}
query.update(dict(
frame=frame,
style=json.dumps(style)
style=json.dumps(style),
))
query_string = urlencode(query, quote_via=quote, safe='{}')
self._layer.url = f'{scheme}://{netloc}{path}?{query_string}'
self._layer.redraw()


def get_frame_histogram(self, params):
frame = params.get("frame")
frame = params.get('frame')
frame_histograms = self.frame_selector.frameHistograms or {}
frame_histograms = frame_histograms.copy()
parsed_url = urlparse(self._layer.url)
Expand All @@ -432,7 +434,8 @@ async def fetch(url):

# used for encoding histogram data
class NumpyEncoder(json.JSONEncoder):
""" Special json encoder for numpy types from https://stackoverflow.com/a/49677241 """
"""Special json encoder for numpy types from https://stackoverflow.com/a/49677241"""

def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
Expand Down Expand Up @@ -483,7 +486,7 @@ class TileSourceHistogramHandler(tornado.web.RequestHandler):
"""REST endpoint to get image metadata."""

def get(self) -> None:
kwargs = { k: ast.literal_eval(self.get_argument(k)) for k in self.request.arguments }
kwargs = {k: ast.literal_eval(self.get_argument(k)) for k in self.request.arguments}
histogram = manager.tile_source.histogram(**kwargs).get('histogram', [{}])
self.write(json.dumps(histogram, cls=NumpyEncoder))
self.set_header('Content-Type', 'application/json')
Expand Down
37 changes: 20 additions & 17 deletions large_image/widgets/CompositeLayers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
'layerMap',
'active',
'colors',
'styleUpdate',
'styleUpdate'
],
data() {
return {
Expand Down Expand Up @@ -50,8 +50,8 @@ module.exports = {
}
},
histogramParams() {
this.getFrameHistogram(this.histogramParams)
},
this.getFrameHistogram(this.histogramParams);
}
},
mounted() {
this.initializeLayerInfo();
Expand Down Expand Up @@ -79,7 +79,6 @@ module.exports = {
if (this.active) {
document.addEventListener('keydown', this.keyHandler);
}
},
methods: {
keyHandler(e) {
Expand Down Expand Up @@ -131,19 +130,19 @@ module.exports = {
this.layers.forEach((layerName) => {
if (!this.compositeLayerInfo[layerName].palette) {
let chosenColor;
const unusedColors = OTHER_COLORS.filter(
const unusedColors = this.colors.other.filter(
(color) => !usedColors.includes(color)
);
if (unusedColors.length > 0) {
chosenColor = unusedColors[0];
} else {
chosenColor = OTHER_COLORS[Math.floor(Math.random() * OTHER_COLORS.length)];
chosenColor = this.colors.other[Math.floor(Math.random() * this.colors.other.length)];
}
this.compositeLayerInfo[layerName].palette = chosenColor;
usedColors.push(chosenColor);
}
});
this.getFrameHistogram(this.histogramParams)
this.getFrameHistogram(this.histogramParams);
},
initializeStateFromStyle() {
this.enabledLayers = [];
Expand Down Expand Up @@ -238,11 +237,10 @@ module.exports = {
return Object.values(this.compositeLayerInfo).every(({autoRange}) => autoRange !== undefined);
},
updateLayerColor(layer, event) {
this.compositeLayerInfo[layer].palette = event.target.value;
this.compositeLayerInfo[layer].palette = event.target.value;
this.updateStyle();
},
updateLayerMin(layer, newVal) {
console.log('update min', newVal)
const newMinVal = Number.isFinite(newVal) ? parseFloat(newVal) : undefined;
this.compositeLayerInfo[layer].min = newMinVal;
this.compositeLayerInfo = Object.assign({}, this.compositeLayerInfo); // for reactivity
Expand Down Expand Up @@ -342,7 +340,12 @@ module.exports = {
<th>
<div class="auto-range-col">
<div class="auto-range-label">
<span class="small-text" style="text-align: left">Auto Range</span>
<span
class="small-text"
style="text-align: left"
>
Auto Range
</span>
<label class="switch">
<span
:class="allAutoRange() ? 'onoff-slider checked' : 'onoff-slider'"
Expand Down Expand Up @@ -395,13 +398,13 @@ module.exports = {
{{ layerName }}
</td>
<td class="color-col">
<input
id="color_picker"
class="picker"
type="color"
:value="palette"
@input="(swatch) => {updateLayerColor(layerName, swatch)}"
/>
<input
id="color_picker"
class="picker"
type="color"
:value="palette"
@input="(swatch) => {updateLayerColor(layerName, swatch)}"
/>
</td>
<td class="auto-range-col">
<div class="auto-range-label">
Expand Down
32 changes: 16 additions & 16 deletions large_image/widgets/DualInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ module.exports = {
props: ['label', 'currentValue', 'valueMax', 'sliderLabels', 'maxMerge'],
emits: ['updateValue', 'updateMaxMerge'],
data() {
return {
value: this.currentValue,
merge: this.maxMerge,
};
return {
value: this.currentValue,
merge: this.maxMerge
};
},
watch: {
currentValue(v) {
this.value = v;
},
value(v) {
this.$emit('updateValue', v);
},
maxMerge(v) {
this.merge = v;
},
merge(v) {
this.$emit('updateMaxMerge', v);
}
currentValue(v) {
this.value = v;
},
value(v) {
this.$emit('updateValue', v);
},
maxMerge(v) {
this.merge = v;
},
merge(v) {
this.$emit('updateMaxMerge', v);
}
}
};
</script>
Expand Down
32 changes: 19 additions & 13 deletions large_image/widgets/FrameSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
'liConfig',
'colors',
'getFrameHistogram',
'frameHistograms',
'frameHistograms'
],
data() {
return {
Expand Down Expand Up @@ -68,7 +68,7 @@ module.exports = {
currentModeId() {
this.modesShown[this.currentModeId] = true;
this.update();
},
}
},
mounted() {
this.metadata = Object.assign({}, this.imageMetadata);
Expand Down Expand Up @@ -308,7 +308,7 @@ module.exports = {
}
}
}
},
}
};
</script>

Expand All @@ -318,11 +318,17 @@ module.exports = {
class="image-frame-control-box"
>
<div>{{ debug }}</div>
<div id="current_image_frame" class="invisible">
{{ currentFrame }}
<div
id="current_image_frame"
class="invisible"
>
{{ currentFrame }}
</div>
<div id="current_image_style" class="invisible">
{{ currentStyle }}
<div
id="current_image_style"
class="invisible"
>
{{ currentStyle }}
</div>
<div>
<label for="mode">Image control mode: </label>
Expand Down Expand Up @@ -383,14 +389,14 @@ module.exports = {
:current-frame="currentFrame"
:current-style="style[2]"
:histogram-param-style="histogramParamStyles[2]"
:frameHistograms="frameHistograms"
:getFrameHistogram="getFrameHistogram"
:frame-histograms="frameHistograms"
:get-frame-histogram="getFrameHistogram"
:layers="metadata.channels"
:layer-map="metadata.channelmap"
:active="currentModeId === 2"
:class="currentModeId === 2 ? '' : 'invisible'"
:colors="colors"
:styleUpdate="(style) => updateStyle(2, style)"
:style-update="(style) => updateStyle(2, style)"
/>
<composite-layers
v-if="metadata.bands && modesShown[3]"
Expand All @@ -399,14 +405,14 @@ module.exports = {
:current-frame="currentFrame"
:current-style="style[3]"
:histogram-param-style="histogramParamStyles[3]"
:frameHistograms="frameHistograms"
:getFrameHistogram="getFrameHistogram"
:frame-histograms="frameHistograms"
:get-frame-histogram="getFrameHistogram"
:layers="metadata.bands"
:layer-map="undefined"
:active="currentModeId === 3"
:class="currentModeId === 3 ? '' : 'invisible'"
:colors="colors"
:styleUpdate="(style) => updateStyle(3, style)"
:style-update="(style) => updateStyle(3, style)"
/>
</div>
</div>
Expand Down
Loading

0 comments on commit ccc83cb

Please sign in to comment.