This commit is contained in:
bmatthieu3
2025-02-28 17:58:56 +01:00
committed by Matthieu Baumann
parent 35f6037f7f
commit c2dd66c5b3
4 changed files with 75 additions and 90 deletions

View File

@@ -36,7 +36,7 @@
// Colormap config options // Colormap config options
this.colormap = (options && options.colormap) || "native"; this.colormap = (options && options.colormap) || "native";
this.colormap = formatColormap(this.colormap); this.colormap = this.colormap.toLowerCase();
this.stretch = (options && options.stretch) || "linear"; this.stretch = (options && options.stretch) || "linear";
this.stretch = this.stretch.toLowerCase(); this.stretch = this.stretch.toLowerCase();
@@ -102,8 +102,7 @@
} }
ColorCfg.prototype.setOptions = function(options) { ColorCfg.prototype.setOptions = function(options) {
if (options.colormap) this.setColormap(options.colormap, options)
this.setColormap(options.colormap, options)
this.setCuts(options.minCut, options.maxCut) this.setCuts(options.minCut, options.maxCut)
@@ -207,43 +206,20 @@
return this.additiveBlending; return this.additiveBlending;
}; };
var formatColormap = function(colormap) {
/// colormap
// Make it case insensitive
colormap = colormap.toLowerCase();
/*if (!ColorCfg.COLORMAPS.includes(colormap)) {
console.warn("The colormap \'" + colormap + "\' is not supported. You should use one of the following: " + ColorCfg.COLORMAPS + "\n\'grayscale\' has been chosen by default.")
// If the user specify a colormap that is not supported,
// then set it to grayscale
colormap = "grayscale";
}*/
return colormap;
}
// @api // @api
// Optional arguments, // Optional arguments,
ColorCfg.prototype.setColormap = function(colormap = "native", options) { ColorCfg.prototype.setColormap = function(colormap, options) {
if (colormap == null || colormap == undefined)
return;
/// colormap /// colormap
// Make it case insensitive this.colormap = (colormap && colormap.toLowerCase()) || this.colormap;
let cmap = formatColormap(colormap);
/// stretch /// stretch
let stretch = (options && options.stretch) || this.stretch || "linear"; let stretch = (options && options.stretch) || this.stretch || "linear";
stretch = stretch.toLowerCase(); this.stretch = stretch.toLowerCase()
/// reversed /// reversed
let reversed = false; if (options && options.reversed !== undefined) {
if (options && options.reversed === true) { this.reversed = options.reversed;
reversed = true;
} }
this.colormap = cmap;
this.stretch = stretch;
this.reversed = reversed;
} }
// @api // @api

View File

@@ -604,7 +604,8 @@ export let HiPS = (function () {
* *
* @memberof HiPS * @memberof HiPS
* *
* @param {string} [colormap="grayscale"] - The colormap label to use. See {@link https://matplotlib.org/stable/users/explain/colors/colormaps.html|here} for more info about colormaps. * @param {string} [colormap] - The colormap label to use. See {@link https://matplotlib.org/stable/users/explain/colors/colormaps.html|here} for more info about colormaps.
* If null or undefined, the colormap type is not changed.
* Possible values are: * Possible values are:
* <br>"blues" * <br>"blues"
* <br>"cividis" * <br>"cividis"
@@ -765,6 +766,12 @@ export let HiPS = (function () {
*/ */
HiPS.prototype.setOptions = function(options) { HiPS.prototype.setOptions = function(options) {
this.colorCfg.setOptions(options); this.colorCfg.setOptions(options);
// FIXME, change api of setColormap to take an option object having a name field
if (options.colormap == null || options.colormap == undefined) {
delete options.colormap;
}
this.options = {...this.options, ...options}; this.options = {...this.options, ...options};
this._updateMetadata(); this._updateMetadata();

View File

@@ -49,7 +49,7 @@ import { Form } from "../Widgets/Form.js";
monochrome: true, monochrome: true,
url: luminosityIconUrl url: luminosityIconUrl
}, },
tooltip: {content: 'Luminosity sliders', position: {direction: 'bottom'}}, tooltip: {content: 'Contrast', position: {direction: 'bottom'}},
action: (e) => { action: (e) => {
const content = Layout.vertical({ const content = Layout.vertical({
layout: [self.selector, self.luminositySettingsContent] layout: [self.selector, self.luminositySettingsContent]
@@ -63,7 +63,7 @@ import { Form } from "../Widgets/Form.js";
monochrome: true, monochrome: true,
url: opacityIconUrl url: opacityIconUrl
}, },
tooltip: {content: 'Opacity slider', position: {direction: 'bottom'}}, tooltip: {content: 'Opacity', position: {direction: 'bottom'}},
action: (e) => { action: (e) => {
const content = Layout.vertical({layout: [self.selector, self.opacitySettingsContent]}); const content = Layout.vertical({layout: [self.selector, self.opacitySettingsContent]});
self.update({content}) self.update({content})
@@ -86,7 +86,7 @@ import { Form } from "../Widgets/Form.js";
monochrome: true, monochrome: true,
url: pixelHistIconUrl url: pixelHistIconUrl
}, },
tooltip: {content: 'Pixel cutouts', position: {direction: 'bottom'}}, tooltip: {content: 'Cutouts', position: {direction: 'bottom'}},
action: (e) => { action: (e) => {
const content = Layout.vertical({layout: [self.selector, self.pixelSettingsContent]}); const content = Layout.vertical({layout: [self.selector, self.pixelSettingsContent]});
self.update({content}) self.update({content})
@@ -236,15 +236,30 @@ import { Form } from "../Widgets/Form.js";
let colorSettingsContent = new Form({ let colorSettingsContent = new Form({
subInputs: [{ subInputs: [{
label: 'colormap:', label: 'colormap:',
type: 'select', type: 'select',
name: 'cmap', name: 'cmap',
value: 'native', value: 'native',
options: aladin.getListOfColormaps(), options: aladin.getListOfColormaps(),
change: (e, cmapSelector) => { change: (e) => {
self.options.layer.setColormap(e.target.value) self.options.layer.setColormap(e.target.value)
},
}, },
}] {
label: 'reverse:',
type: 'checkbox',
name: 'reverse',
cssStyle: {
// so that it takes as much space as it can
flex: "0 0 1",
},
checked: false,
change: (e) => {
let checked = colorSettingsContent.getInput("reverse").checked
self.options.layer.setColormap(null, {reversed: checked})
}
},
]
}); });
super({ super({
@@ -265,31 +280,37 @@ import { Form } from "../Widgets/Form.js";
this.luminositySettingsContent = luminositySettingsContent; this.luminositySettingsContent = luminositySettingsContent;
} }
_update(layer) {
let colorCfg = layer.getColorCfg();
let stretch = colorCfg.stretch;
let colormap = colorCfg.getColormap();
let reversed = colorCfg.getReversed();
let [minCut, maxCut] = colorCfg.getCuts();
this.pixelSettingsContent.set('mincut', +minCut.toFixed(4))
this.pixelSettingsContent.set('maxcut', +maxCut.toFixed(4))
this.pixelSettingsContent.set('stretch', stretch)
let fmtInput = this.pixelSettingsContent.getInput('fmt')
fmtInput.innerHTML = '';
for (const option of layer.formats) {
fmtInput.innerHTML += "<option>" + option + "</option>";
}
fmtInput.value = layer.imgFormat;
this.colorSettingsContent.set('cmap', colormap);
this.colorSettingsContent.set('reverse', reversed);
this.opacitySettingsContent.set('opacity', layer.getOpacity());
this.luminositySettingsContent.set('brightness', colorCfg.getBrightness());
this.luminositySettingsContent.set('contrast', colorCfg.getContrast());
this.luminositySettingsContent.set('gamma', colorCfg.getGamma());
this.luminositySettingsContent.set('saturation', colorCfg.getSaturation());
}
update(options) { update(options) {
if (options.layer) { if (options.layer) {
let hips = options.layer; this._update(options.layer)
let colorCfg = hips.getColorCfg();
let stretch = colorCfg.stretch;
let colormap = colorCfg.getColormap();
let [minCut, maxCut] = colorCfg.getCuts();
this.pixelSettingsContent.set('mincut', +minCut.toFixed(4))
this.pixelSettingsContent.set('maxcut', +maxCut.toFixed(4))
this.pixelSettingsContent.set('stretch', stretch)
let fmtInput = this.pixelSettingsContent.getInput('fmt')
fmtInput.innerHTML = '';
for (const option of hips.formats) {
fmtInput.innerHTML += "<option>" + option + "</option>";
}
fmtInput.value = hips.imgFormat;
this.colorSettingsContent.set('cmap', colormap);
this.opacitySettingsContent.set('opacity', hips.getOpacity());
this.luminositySettingsContent.set('brightness', colorCfg.getBrightness());
this.luminositySettingsContent.set('contrast', colorCfg.getContrast());
this.luminositySettingsContent.set('gamma', colorCfg.getGamma());
this.luminositySettingsContent.set('saturation', colorCfg.getSaturation());
} }
super.update(options) super.update(options)
@@ -300,28 +321,7 @@ import { Form } from "../Widgets/Form.js";
const hips = e.detail.layer; const hips = e.detail.layer;
let selectedLayer = this.options.layer; let selectedLayer = this.options.layer;
if (selectedLayer && hips.layer === selectedLayer.layer) { if (selectedLayer && hips.layer === selectedLayer.layer) {
let colorCfg = hips.getColorCfg(); this._update(hips)
let stretch = colorCfg.stretch;
let colormap = colorCfg.getColormap();
let [minCut, maxCut] = colorCfg.getCuts();
this.pixelSettingsContent.set('mincut', +minCut.toFixed(4))
this.pixelSettingsContent.set('maxcut', +maxCut.toFixed(4))
this.pixelSettingsContent.set('stretch', stretch)
let fmtInput = this.pixelSettingsContent.getInput('fmt')
fmtInput.innerHTML = '';
for (const option of hips.formats) {
fmtInput.innerHTML += "<option>" + option + "</option>";
}
fmtInput.value = hips.imgFormat;
this.colorSettingsContent.set('cmap', colormap);
this.opacitySettingsContent.set('opacity', hips.getOpacity());
this.luminositySettingsContent.set('brightness', colorCfg.getBrightness());
this.luminositySettingsContent.set('contrast', colorCfg.getContrast());
this.luminositySettingsContent.set('gamma', colorCfg.getGamma());
this.luminositySettingsContent.set('saturation', colorCfg.getSaturation());
} }
}); });

View File

@@ -73,9 +73,11 @@ export class Input extends DOMElement {
this.el.checked = this.options.checked; this.el.checked = this.options.checked;
if (this.options.click) { // for checkbox widgets, we authorize calling the callback name click or change
let action = this.options.click || this.options.change;
if (action) {
this.el.removeEventListener('click', this.action); this.el.removeEventListener('click', this.action);
this.action = this.options.click; this.action = action;
this.el.addEventListener('click', this.action); this.el.addEventListener('click', this.action);
} }