Skip to content

Commit

Permalink
#75 Connect the colour picker to the context neuron data
Browse files Browse the repository at this point in the history
  • Loading branch information
Salam-Dalloul committed Oct 2, 2024
1 parent 04a3f8d commit 0bd70b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Add as AddIcon, DeleteOutlined as DeleteOutlinedIcon, HelpOutline as HelpOutlineIcon } from "@mui/icons-material";
import { Box, FormControlLabel, IconButton, Stack, Tooltip, Typography } from "@mui/material";
import { useState } from "react";
import { ViewerType, type Workspace } from "../../models";
import { vars } from "../../theme/variables.ts";
import CustomSwitch from "./CustomSwitch";
import PickerWrapper from "./PickerWrapper";
Expand All @@ -20,6 +21,7 @@ interface CustomListItemProps {
onSwitchChange?: (id: string, checked: boolean) => void;
onDelete?: (id: string) => void;
deleteTooltipTitle?: string;
workspace: Workspace;
}
const CustomListItem = ({
data,
Expand All @@ -29,6 +31,7 @@ const CustomListItem = ({
onSwitchChange,
onDelete,
deleteTooltipTitle,
workspace,
}: CustomListItemProps) => {
const [anchorEl, setAnchorEl] = useState(null);
const [open, setOpen] = useState(false);
Expand All @@ -55,7 +58,9 @@ const CustomListItem = ({
};

const handleColorChange = (color) => {
setSelectedColor(color.hex);
const hexColor = color.hex;
setSelectedColor(hexColor);
workspace.changeNeuronColorForViewers(data.id, hexColor, [ViewerType.ThreeD, ViewerType.EM]);
};

const handleOnMouseEnter = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const Neurons = ({ children }) => {
onSwitchChange={handleSwitchChange}
onDelete={handleDeleteNeuron}
deleteTooltipTitle="Remove neuron from the workspace"
workspace={currentWorkspace}
/>
))}
<Box display="flex" alignItems="center" justifyContent="space-between" padding=".25rem .5rem">
Expand Down Expand Up @@ -150,6 +151,7 @@ const Neurons = ({ children }) => {
onSwitchChange={handleSwitchChange}
onDelete={() => console.log("delete")}
deleteTooltipTitle="Remove group from the workspace"
workspace={currentWorkspace}
/>
))}
</Stack>
Expand Down
18 changes: 18 additions & 0 deletions applications/visualizer/frontend/src/models/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,22 @@ export class Workspace {
getVisibleNeuronsInThreeD(): string[] {
return Array.from(this.activeNeurons).filter((neuronId) => this.visibilities[neuronId]?.[ViewerType.ThreeD]?.visibility === Visibility.Visible);
}

changeNeuronColorForViewers(neuronId: string, color: string, viewerTypes: ViewerType[] = [ViewerType.ThreeD, ViewerType.EM]): void {
const unsupportedTypes = viewerTypes.filter((type) => type !== ViewerType.ThreeD && type !== ViewerType.EM);

if (unsupportedTypes.length > 0) {
throw new Error(`Unsupported viewer types: ${unsupportedTypes.join(", ")}`);
}

const updated = produce(this, (draft: Workspace) => {
viewerTypes.forEach((viewerType) => {
if (viewerType in draft.visibilities[neuronId]) {
draft.visibilities[neuronId][viewerType].color = color;
}
});
});

this.updateContext(updated);
}
}

0 comments on commit 0bd70b9

Please sign in to comment.