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

Add color picker to select tree color #4907

Merged
merged 12 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- The total length of skeletons can now be measured using the dropdown in the tree list tab. Also, the frontend API received the methods `api.tracing.measureTreeLength` and `api.tracing.measureAllTrees`. [#4898](https://github.com/scalableminds/webknossos/pull/4898)
- Introduced an indeterminate visibility state for groups in the tree tab if not all but only some of the group's children are visible. Before, the visibility of those groups was shown as not visible which made it hard to find the visible trees. [#4897](https://github.com/scalableminds/webknossos/pull/4897)
- Dataset uploads on a specific Datastore can now be restricted to a single organization. [#4892](https://github.com/scalableminds/webknossos/pull/4892)
- Added a button to set the color of a tree in the trees tab view. [#4907](https://github.com/scalableminds/webknossos/pull/4907)

### Changed
- In the tree tab, all groups but the root group are now collapsed instead of expanded when opening a tracing. [#4897](https://github.com/scalableminds/webknossos/pull/4897)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type SetTreeColorIndexAction = {
colorIndex: number,
};
type ShuffleTreeColorAction = { type: "SHUFFLE_TREE_COLOR", treeId?: number };
type SetTreeColorAction = { type: "SET_TREE_COLOR", treeId: number, color: Vector3 };
type ShuffleAllTreeColorsAction = { type: "SHUFFLE_ALL_TREE_COLORS", treeId?: number };
type CreateCommentAction = {
type: "CREATE_COMMENT",
Expand Down Expand Up @@ -148,6 +149,7 @@ export type SkeletonTracingAction =
| MergeTreesAction
| SetTreeNameAction
| SelectNextTreeAction
| SetTreeColorAction
| ShuffleTreeColorAction
| ShuffleAllTreeColorsAction
| SetTreeColorIndexAction
Expand Down Expand Up @@ -196,6 +198,7 @@ export const SkeletonTracingSaveRelevantActions = [
"TOGGLE_TREE_GROUP",
"TOGGLE_ALL_TREES",
"TOGGLE_INACTIVE_TREES",
"SET_TREE_COLOR_INDEX",
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
// Composited actions, only dispatched using `batchActions`
"DELETE_GROUP_AND_TREES",
];
Expand Down Expand Up @@ -418,6 +421,12 @@ export const shuffleTreeColorAction = (treeId: number): ShuffleTreeColorAction =
treeId,
});

export const setTreeColorAction = (treeId: number, color: Vector3): SetTreeColorAction => ({
type: "SET_TREE_COLOR",
treeId,
color,
});

export const shuffleAllTreeColorsAction = (): ShuffleAllTreeColorsAction => ({
type: "SHUFFLE_ALL_TREE_COLORS",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ function SkeletonTracingReducer(state: OxalisState, action: Action): OxalisState
.getOrElse(state);
}

case "SET_TREE_COLOR": {
const { color, treeId } = action;
return getTree(skeletonTracing, treeId)
.map(tree => {
tree = { ...tree, color };
return update(state, {
tracing: { skeleton: { trees: { [tree.treeId]: { $set: tree } } } },
});
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
})
.getOrElse(state);
}

case "SHUFFLE_TREE_COLOR": {
return getTree(skeletonTracing, action.treeId)
.chain(tree => shuffleTreeColor(skeletonTracing, tree))
Expand Down
35 changes: 35 additions & 0 deletions frontend/javascripts/oxalis/view/right-menu/tree_hierarchy_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import SortableTree from "react-sortable-tree";
import _ from "lodash";
import type { Dispatch } from "redux";
import { type Action } from "oxalis/model/actions/actions";
import type { Vector3 } from "oxalis/constants";
import * as Utils from "libs/utils";
import {
MISSING_GROUP_ID,
TYPE_GROUP,
Expand All @@ -28,6 +30,7 @@ import { getMaximumGroupId } from "oxalis/model/reducers/skeletontracing_reducer
import {
setActiveTreeAction,
setActiveGroupAction,
setTreeColorAction,
toggleTreeAction,
toggleTreeGroupAction,
toggleAllTreesAction,
Expand Down Expand Up @@ -56,6 +59,7 @@ type Props = {
onSetActiveGroup: number => void,
onToggleTree: number => void,
onToggleAllTrees: () => void,
onSetTreeColor: (number, Vector3) => void,
onToggleTreeGroup: number => void,
onUpdateTreeGroups: (Array<TreeGroup>) => void,
onBatchActions: (Array<Action>, string) => void,
Expand Down Expand Up @@ -362,6 +366,34 @@ class TreeHierarchyView extends React.PureComponent<Props, State> {
style={{ marginLeft: 9, display: "inline" }}
onClick={this.onSelectTree}
>{`(${tree.nodes.size()}) ${tree.name}`}</div>
<div style={{ position: "relative", display: "inline" }}>
<i
className="fas fa-eye-dropper fa-sm"
style={{
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
cursor: "pointer",
}}
/>
<input
type="color"
MichaelBuessemeyer marked this conversation as resolved.
Show resolved Hide resolved
style={{
position: "absolute",
left: 0,
top: 0,
width: 14,
opacity: 0,
cursor: "pointer",
}}
onChange={event => {
let color = Utils.hexToRgb(event.target.value);
color = Utils.map3(component => component / 255, color);
this.props.onSetTreeColor(tree.treeId, color);
}}
/>
</div>
</div>
);
nodeProps.className = "tree-type";
Expand Down Expand Up @@ -438,6 +470,9 @@ const mapDispatchToProps = (dispatch: Dispatch<*>) => ({
onSetActiveGroup(groupId) {
dispatch(setActiveGroupAction(groupId));
},
onSetTreeColor(treeId, color) {
dispatch(setTreeColorAction(treeId, color));
},
onToggleTree(treeId) {
dispatch(toggleTreeAction(treeId));
},
Expand Down