Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frame Selector component: ensure that no color can be assigned twice #1387

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ export default {
// Assign colors
this.layers.forEach((layerName) => {
if (!this.compositeLayerInfo[layerName].palette) {
const channelColor = getChannelColor(layerName);
const channelColor = getChannelColor(layerName, usedColors);
if (channelColor) {
this.compositeLayerInfo[layerName].palette = channelColor;
usedColors.push(channelColor);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import Vue from 'vue';

import {getChannelColor} from '../utils/colors';
import {getChannelColor, OTHER_COLORS} from '../utils/colors';

import CompositeLayers from './CompositeLayers.vue';
import DualInput from './DualInput.vue';
Expand Down Expand Up @@ -158,8 +158,10 @@ export default Vue.extend({
} else {
// no style applied yet, create new permutations list
const {bands} = this.metadata;
const usedColors = [];
bands.forEach((b, i) => {
const bandPalette = getChannelColor(b);
let bandPalette = getChannelColor(b, usedColors);
if (!bandPalette) bandPalette = OTHER_COLORS.find((c) => !usedColors.includes(c));
frameDeltas.forEach((framedelta) => {
newBandsArray.push({
band: i + 1,
Expand Down
5 changes: 3 additions & 2 deletions girder/girder_large_image/web_client/vue/utils/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
'^gr[ae]y(|scale)$': '#FFFFFF'
};

export function getChannelColor(name) {
export function getChannelColor(name, usedColors) {

Check warning on line 15 in girder/girder_large_image/web_client/vue/utils/colors.js

View check run for this annotation

Codecov / codecov/patch

girder/girder_large_image/web_client/vue/utils/colors.js#L15

Added line #L15 was not covered by tests
// Search for case-insensitive regex match among known channel-colors
for (const [channelPattern, color] of Object.entries(CHANNEL_COLORS)) {
if (name.match(new RegExp(channelPattern, 'i'))) {
if (!usedColors.includes(color) && name.match(new RegExp(channelPattern, 'i'))) {
usedColors.push(color);

Check warning on line 19 in girder/girder_large_image/web_client/vue/utils/colors.js

View check run for this annotation

Codecov / codecov/patch

girder/girder_large_image/web_client/vue/utils/colors.js#L19

Added line #L19 was not covered by tests
return color;
}
}
Expand Down