Skip to content

Commit bb50fa5

Browse files
authored
Merge pull request MetaCell#164 from MetaCell/feature/VFB-202
MetaCell#202 Use colors for 3d meshes and slice viewer images
2 parents d7b6a94 + 4e04c7f commit bb50fa5

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

applications/virtual-fly-brain/client/src/reducers/InstancesReducer.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { getGlobalTypes } from "./actions/types/GlobalTypes";
22
import { getInstancesTypes } from "./actions/types/getInstancesTypes";
33
import {
44
SELECTED_COLOR,
5-
DESELECTED_COLOR,
65
TEMPLATE_COLOR,
76
SKELETON,
87
CYLINDERS,
@@ -22,6 +21,7 @@ export const initialStateInstancesReducer = {
2221
error: false,
2322
errorMessage: undefined,
2423
cameraEvent: {},
24+
selectedInstancesCount: 1,
2525
};
2626

2727
const getMappedCanvasData = (loadedInstances) => {
@@ -74,7 +74,8 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
7474
newInstance.userSetColor = TEMPLATE_COLOR;
7575
newInstance.stackInstance = true;
7676
} else {
77-
newInstance.color = DESELECTED_COLOR;
77+
newInstance.color = getNextColor(state.selectedInstancesCount);
78+
newInstance.colorIndex = state.selectedInstancesCount;
7879
}
7980

8081
let launchTemplate = state.launchTemplate;
@@ -104,7 +105,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
104105
focused.color = SELECTED_COLOR;
105106
loadedInstances?.forEach((i) => {
106107
if (i.metadata?.Id !== focused.metadata?.Id) {
107-
i.color = i.userSetColor || DESELECTED_COLOR;
108+
i.color = i.userSetColor || getNextColor(i.colorIndex || 0);
108109
i.selected = false;
109110
}
110111
});
@@ -114,6 +115,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
114115
allLoadedInstances: loadedInstances,
115116
launchTemplate: launchTemplate,
116117
focusedInstance: focused,
118+
selectedInstancesCount: newInstance.metadata?.IsTemplate ? state.selectedInstancesCount : state.selectedInstancesCount + 1,
117119
event: {
118120
action: getInstancesTypes.ADD_INSTANCE,
119121
id: response.payload.Id,
@@ -324,6 +326,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
324326
});
325327
}
326328
case getInstancesTypes.SELECT_INSTANCE: {
329+
const selectedInstancesCount = state.selectedInstancesCount;
327330
const allLoadedInstances = [...state.allLoadedInstances];
328331
const findInstance = allLoadedInstances?.find(
329332
(i) => i.metadata?.Id === response.payload.id
@@ -334,12 +337,12 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
334337
findInstance.color = SELECTED_COLOR;
335338
allLoadedInstances?.forEach((i) => {
336339
if (i.metadata?.Id !== findInstance.metadata?.Id) {
337-
i.color = i.userSetColor || DESELECTED_COLOR;
340+
i.color = i.userSetColor || getNextColor(i.colorIndex);
338341
i.selected = false;
339342
}
340343
});
341344
} else {
342-
findInstance.color = findInstance.userSetColor || DESELECTED_COLOR;
345+
findInstance.color = findInstance.userSetColor || getNextColor(findInstance.colorIndex);
343346
}
344347
}
345348

@@ -351,14 +354,19 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
351354
matchObject.selected = !matchObject.selected;
352355
if (matchObject.selected) matchObject.color = SELECTED_COLOR;
353356
else {
354-
matchObject.color = DESELECTED_COLOR;
357+
const instance = allLoadedInstances.find(i => i.metadata?.Id === response.payload.id);
358+
matchObject.color = getNextColor(instance?.colorIndex);
355359
}
356360
}
357361

362+
// Only increment the counter if we're selecting a new instance
363+
const newCount = findInstance && !findInstance.selected ? selectedInstancesCount + 1 : selectedInstancesCount;
364+
358365
return Object.assign({}, state, {
359366
allLoadedInstances: allLoadedInstances,
360367
threeDObjects: threeDObjects,
361368
mappedCanvasData: getMappedCanvasData(allLoadedInstances),
369+
selectedInstancesCount: newCount,
362370
event: {
363371
action: getInstancesTypes.UPDATE_INSTANCES,
364372
id: response.payload.id,
@@ -650,7 +658,7 @@ const InstancesReducer = (state = initialStateInstancesReducer, response) => {
650658
newInstance.color = { ...TEMPLATE_COLOR, a: 0.4 };
651659
} else {
652660
// For other instances, use next color from palette with opacity 0.3
653-
newInstance.color = getNextColor(0.3);
661+
newInstance.color = getNextColor(0, 0.3);
654662
// Store original color with full opacity for potential skeleton use
655663
newInstance.fullOpacityColor = { ...newInstance.color, a: 1.0 };
656664
}

applications/virtual-fly-brain/client/src/utils/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export const COLOR_PALETTE = [
3636
];
3737

3838
// Index to track the current color in the palette
39-
let colorIndex = 0;
39+
// let colorIndex = 0;
4040

4141
// Function to get the next color in the sequence
42-
export const getNextColor = (opacity = 0.3) => {
42+
export const getNextColor = (colorIndex = 0, opacity = 0.3) => {
4343
const hexColor = COLOR_PALETTE[colorIndex];
4444
// Increment and loop back to beginning if needed
4545
colorIndex = (colorIndex + 1) % COLOR_PALETTE.length;
@@ -49,7 +49,7 @@ export const getNextColor = (opacity = 0.3) => {
4949
const g = parseInt(hexColor.substring(4, 6), 16) / 255;
5050
const b = parseInt(hexColor.substring(6, 8), 16) / 255;
5151

52-
return { r, g, b, a: opacity };
52+
return { r, g, b, a: 0.3 };
5353
}
5454

5555
// Convert hex to RGBA for existing functions

0 commit comments

Comments
 (0)