Skip to content

Commit aa308d1

Browse files
committed
Support max_active_channels
1 parent b4102d4 commit aa308d1

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

src/app/context.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ export default class Context {
191191
*/
192192
luts = new Map();
193193

194+
/**
195+
* max active channels
196+
*
197+
* // TODO: make the default configurable.
198+
*
199+
* @memberof Context
200+
* @type {number}
201+
*/
202+
max_active_channels = 20;
203+
194204
/**
195205
* the lookup png
196206
*
@@ -243,6 +253,9 @@ export default class Context {
243253
// set up luts
244254
this.setUpLuts();
245255

256+
// load max active channels
257+
this.loadMaxActiveChannels();
258+
246259
// initialize Open_with
247260
OpenWith.initOpenWith();
248261

@@ -344,6 +357,27 @@ export default class Context {
344357
});
345358
}
346359

360+
loadMaxActiveChannels() {
361+
// query microservice endpoint...
362+
let url = this.server + "/omero_ms_image_region/";
363+
console.log(url);
364+
fetch(url, {method: "OPTIONS"})
365+
.then(r => r.json())
366+
.then(data => {
367+
console.log('data', data);
368+
if (Number.isInteger(data.options?.maxActiveChannels)) {
369+
this.max_active_channels = data.options.maxActiveChannels;
370+
// in case the images loaded already (this query took longer than
371+
// expected), let's update them...
372+
for (let [id, conf] of this.image_configs) {
373+
conf.image_info.applyMaxActiveChannels(this.max_active_channels);
374+
}
375+
}
376+
}).catch(() => {
377+
console.log("failed to load omero_ms_image_region info");
378+
});
379+
}
380+
347381
/**
348382
* Depending on what received as the inital parameters
349383
* (image(s), dataset, etc) we continue to create and add

src/model/image_info.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ export default class ImageInfo {
458458
// If we've viewed this image before, apply cached settings
459459
this.applyCachedSettings(response);
460460

461+
// enforce max_active_channels
462+
this.applyMaxActiveChannels(this.context.max_active_channels);
463+
461464
// signal that we are ready
462465
this.ready = true;
463466
this.tmp_data = response;
@@ -470,6 +473,26 @@ export default class ImageInfo {
470473
this.requestDeltaT();
471474
}
472475

476+
applyMaxActiveChannels(max_active_channels) {
477+
// let conf = this.context.getImageConfig(this.config_id);
478+
console.log("applyMaxActiveChannels", max_active_channels, this.channels);
479+
if (this.channels == null) {
480+
return;
481+
}
482+
let channels = this.channels;
483+
let activeCount = 0;
484+
485+
for (let i=0;i<channels.length;i++) {
486+
let c = channels[i];
487+
if (c.active) {
488+
activeCount += 1;
489+
}
490+
if (activeCount > max_active_channels && c.active) {
491+
c.active = false;
492+
};
493+
};
494+
}
495+
473496
/**
474497
* Gets cached image settings from context and updates our settings
475498
*

src/settings/channel-range.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import Context from '../app/context';
2020
import Misc from '../utils/misc';
21+
import Ui from '../utils/ui';
2122
import {
2223
CHANNEL_SETTINGS_MODE, FLOATING_POINT_PRECISION, URI_PREFIX
2324
} from '../utils/constants';
@@ -543,6 +544,14 @@ export default class ChannelRange {
543544
if (imgConf.image_info.model === 'greyscale' &&
544545
this.channel.active) return;
545546

547+
// don't allow to exceed max_active_channels
548+
let maxActive = this.context.max_active_channels;
549+
let activeCount = imgConf.image_info.channels.reduce((count, ch) => count + (ch.active ? 1 : 0), 0);
550+
if (!this.channel.active && activeCount >= maxActive) {
551+
Ui.showModalMessage(`The maximum number of active channels is ${maxActive}.`, "OK");
552+
return;
553+
}
554+
546555
let history = [];
547556

548557
// toggle channel active state

src/settings/channel-settings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
// js
2020
import Context from '../app/context';
21-
import Misc from '../utils/misc';
2221
import {inject, customElement, bindable, BindingEngine} from 'aurelia-framework';
2322
import {CHANNEL_SETTINGS_MODE, WEBGATEWAY} from '../utils/constants';
2423
import {

0 commit comments

Comments
 (0)