Skip to content

Commit

Permalink
Merge branch 'main' of github.com:alexisthual/brain-cockpit into feat…
Browse files Browse the repository at this point in the history
…ure/toggle_cache
  • Loading branch information
alexisthual committed Feb 12, 2024
2 parents b655d13 + 05f9f39 commit dbd1fdd
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion api/src/brain_cockpit/endpoints/features_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def load_data(df, config_path=None, dataset_path=None):
meshes, subjects, tasks_contrasts, sides = parse_metadata(df)

# ROUTES
# Define a series of enpoints to expose contrasts, meshes, etc
# Define a series of endpoints to expose contrasts, meshes, etc
info_endpoint = f"/datasets/{id}/info"
subjects_endpoint = f"/datasets/{id}/subjects"
contrasts_endpoint = f"/datasets/{id}/contrast_labels"
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/colorbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const Colorbar = ({
<foreignObject
className="unit-container"
x={-margin.right - 25}
y={offset - 5}
y={offset - 15}
width="100"
height="20"
textAnchor="middle"
Expand Down
14 changes: 14 additions & 0 deletions web/src/components/paneControls/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, ButtonGroup, Colors, Icon, Switch } from "@blueprintjs/core";
import { IconName } from "@blueprintjs/icons";
import { Tooltip2 } from "@blueprintjs/popover2";
import { Select2 } from "@blueprintjs/select";
import React from "react";

Expand Down Expand Up @@ -31,6 +32,7 @@ interface PaneControlsInput {
title?: string;
iconLeft?: IconName;
iconRight?: IconName;
tooltip?: string;
}

interface PaneControlsRow {
Expand Down Expand Up @@ -187,6 +189,18 @@ const PaneControls = ({ rows }: IProps) => {
break;
}

if (input.tooltip) {
element = (
<Tooltip2
content={input.tooltip}
placement={"right"}
key={`input-${inputIndex}`}
>
{element}
</Tooltip2>
);
}

return element;
}
)}
Expand Down
1 change: 0 additions & 1 deletion web/src/components/paneControls/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

& .bp4-button,
& .custom-button {
background-color: $light-gray5;
height: 30px;
}

Expand Down
8 changes: 7 additions & 1 deletion web/src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ export interface DatasetDescriptions {
[protocol: string]: {
description: string;
maps: {
[condition: string]: string;
[condition: string]: {
contrast: boolean;
description?: string;
conditions?: {
[condition: string]: number;
};
};
};
};
}
Expand Down
13 changes: 10 additions & 3 deletions web/src/views/surface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ const SurfaceExplorer = ({ datasetId }: SurfaceViewProps) => {
const [meshTypeLabels, setMeshTypeLabels] = useState<string[]>([]);
const [hemiLabels, setHemiLabels] = useState<string[]>([]);
const [unit, setUnit] = useState<string | undefined>(undefined);
const [datasetDescriptions] = useState<any>({});
const [descriptions, setDescriptions] = useState<any>({});

// Load state from url
const [state, setState] = useSurfaceState();

// Initialise all pane state variables
useEffect(() => {
const datasetInfo = server.get<DatasetInfo>(`/datasets/${datasetId}/info`);
const datasetDescriptions = server.get<DatasetInfo>(
`/datasets/${datasetId}/descriptions`
);

datasetInfo.then((value) => {
setSubjectLabels(value.data.subjects);
Expand All @@ -156,10 +159,14 @@ const SurfaceExplorer = ({ datasetId }: SurfaceViewProps) => {
setUnit(value.data.unit);
});

datasetDescriptions.then((value) => {
setDescriptions(value.data);
});

if (state.panes === undefined) {
setState({ panes: {} });
}
}, [datasetId, setState]);
}, [datasetId, setState, state.panes]);

const selectedVoxels = Object.keys(state.panes).map((paneId: any) => [
paneId,
Expand Down Expand Up @@ -543,7 +550,7 @@ const SurfaceExplorer = ({ datasetId }: SurfaceViewProps) => {
meshTypeLabels={meshTypeLabels}
hemiLabels={hemiLabels}
unit={unit}
datasetDescriptions={datasetDescriptions}
datasetDescriptions={descriptions}
filterSurface={filterSurface}
thresholdLow={thresholdLow}
thresholdHigh={thresholdHigh}
Expand Down
49 changes: 27 additions & 22 deletions web/src/views/surface/surfacePane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,31 +479,28 @@ const SurfacePane = ({
newDescriptions.push([task, datasetDescriptions[task]?.description]);
}

// Add contrast / condition description
// Add contrast / conditions description
const contrast = contrastLabels[state.contrast ?? 0]?.contrast;
if (contrast !== undefined) {
newDescriptions.push([
contrast,
datasetDescriptions[task]?.maps[contrast],
]);
}

// If map is contrast, try to add the descriptions
// of all conditions it results from
if (
task !== undefined &&
contrast !== undefined &&
datasetDescriptions[task] !== undefined &&
contrast.indexOf("-") !== -1
) {
const conditions = contrast.split("-");
for (const condition of conditions) {
if (condition in datasetDescriptions[task]?.maps) {
const entry = datasetDescriptions[task]?.maps[contrast];

if (entry !== undefined) {
if (entry.contrast) {
newDescriptions.push([
"This contrast map combines the following conditions:",
]);
for (const condition in entry.conditions) {
newDescriptions.push([
condition,
datasetDescriptions[task]?.maps[condition],
`(${entry.conditions[condition] >= 0 ? "+" : ""}${
entry.conditions[condition]
}) ${condition}`,
datasetDescriptions[task].maps[condition].description,
]);
}
} else {
newDescriptions.push([
contrast,
datasetDescriptions[task]?.maps[contrast].description,
]);
}
}

Expand All @@ -520,7 +517,13 @@ const SurfacePane = ({
{descriptions.map((description: any) => {
return (
<p key={`description-${description[0]}`}>
<strong>{description[0]}:</strong> {description[1]}
{description.length > 1 ? (
<>
<strong>{description[0]}:</strong> {description[1]}
</>
) : (
description[0]
)}
</p>
);
})}
Expand Down Expand Up @@ -620,6 +623,7 @@ const SurfacePane = ({
iconLeft: "person",
iconRight: "people",
title: "Mean across subjects",
tooltip: "Toggle subjects' mean",
},
],
},
Expand Down Expand Up @@ -657,6 +661,7 @@ const SurfacePane = ({
}
},
iconActive: "manual",
tooltip: "Toggle description",
},
],
},
Expand Down

0 comments on commit dbd1fdd

Please sign in to comment.