Skip to content
3 changes: 3 additions & 0 deletions python/neuroglancer/viewer_config_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ class ConfigState(JsonObjectWrapper):
show_panel_borders = showPanelBorders = wrapped_property(
"showPanelBorders", optional(bool, True)
)
show_all_dimension_plot_bounds = showAllDimensionPlotBounds = wrapped_property(
"showAllDimensionPlotBounds", optional(bool, True)
)
scale_bar_options = scaleBarOptions = wrapped_property(
"scaleBarOptions", ScaleBarOptions
)
Expand Down
2 changes: 2 additions & 0 deletions src/layer_group_viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface LayerGroupViewerOptions {
showLayerPanel: WatchableValueInterface<boolean>;
showViewerMenu: boolean;
showLayerHoverValues: WatchableValueInterface<boolean>;
showAllPlotBounds?: WatchableValueInterface<boolean>;
}

export const viewerDragType = "neuroglancer-layer-group-viewer";
Expand Down Expand Up @@ -536,6 +537,7 @@ export class LayerGroupViewer extends RefCounted {
this,
() => this.layout.toJSON(),
this.options.showLayerHoverValues,
this.options.showAllPlotBounds,
));
if (options.showViewerMenu) {
layerPanel.registerDisposer(makeViewerMenu(layerPanel.element, this));
Expand Down
1 change: 1 addition & 0 deletions src/layer_groups_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ function makeComponent(container: LayoutComponentContainer, spec: any) {
showLayerPanel: viewer.uiControlVisibility.showLayerPanel,
showViewerMenu: true,
showLayerHoverValues: viewer.uiControlVisibility.showLayerHoverValues,
showAllPlotBounds: viewer.uiConfiguration.showAllDimensionPlotBounds,
},
);
try {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/layer_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export class LayerBar extends RefCounted {
public layerGroupViewer: LayerGroupViewer,
public getLayoutSpecForDrag: () => any,
public showLayerHoverValues: WatchableValueInterface<boolean>,
public showAllPlotBounds?: WatchableValueInterface<boolean>,
) {
super();
this.positionWidget = this.registerDisposer(
Expand All @@ -225,6 +226,7 @@ export class LayerBar extends RefCounted {
{
velocity: this.viewerNavigationState.velocity.velocity,
getToolBinder: () => this.layerGroupViewer.toolBinder,
showAllPlotBounds: showAllPlotBounds,
},
),
);
Expand Down
2 changes: 2 additions & 0 deletions src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const VIEWER_UI_CONFIG_OPTIONS = [
"showTopBar",
"showUIControls",
"showPanelBorders",
"showAllDimensionPlotBounds",
] as const;

export type ViewerUIOptions = {
Expand Down Expand Up @@ -699,6 +700,7 @@ export class Viewer extends RefCounted implements ViewerState {
{
velocity: this.velocity,
getToolBinder: () => this.toolBinder,
showAllPlotBounds: this.uiConfiguration.showAllDimensionPlotBounds,
},
),
);
Expand Down
24 changes: 24 additions & 0 deletions src/widget/position_plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getDisplayLowerUpperBounds,
} from "#src/coordinate_transform.js";
import type { Position } from "#src/navigation_state.js";
import type { WatchableValueInterface } from "#src/trackable_value.js";
import { WatchableValue } from "#src/trackable_value.js";
import { animationFrameDebounce } from "#src/util/animation_frame_debounce.js";
import { filterArrayInplace } from "#src/util/array.js";
Expand Down Expand Up @@ -106,6 +107,7 @@ export class PositionPlot extends RefCounted {
constructor(
public position: Position,
public dimensionId: DimensionId,
private showAllBounds?: WatchableValueInterface<boolean>,
public orientation: "row" | "column" = "column",
) {
super();
Expand Down Expand Up @@ -177,6 +179,25 @@ export class PositionPlot extends RefCounted {
this.visible = false;
return;
}
if (this.showAllBounds?.value === false) {
let minLowerBound = Infinity;
let maxUpperBound = -Infinity;

for (const {
lower,
upper,
} of normalizedDimensionBounds.normalizedBounds) {
if (lower < minLowerBound) minLowerBound = lower;
if (upper > maxUpperBound) maxUpperBound = upper;
}

normalizedDimensionBounds.normalizedBounds = [
{
lower: isFinite(minLowerBound) ? minLowerBound : 0,
upper: isFinite(maxUpperBound) ? maxUpperBound : 1,
},
];
}
this.element.style.display = "";
this.visible = true;

Expand Down Expand Up @@ -282,6 +303,9 @@ export class PositionPlot extends RefCounted {
animationFrameDebounce(updateView),
);
this.registerDisposer(this.position.changed.add(scheduleUpdateView));
if (this.showAllBounds !== undefined) {
this.registerDisposer(this.showAllBounds.changed.add(scheduleUpdateView));
}
const getPositionFromMouseEvent = (
event: MouseEvent,
): number | undefined => {
Expand Down
19 changes: 17 additions & 2 deletions src/widget/position_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export class PositionWidget extends RefCounted {
private allowFocus: boolean;
private showPlayback: boolean;
private showDropdown: boolean;
private showAllPlotBounds: WatchableValueInterface<boolean> | undefined;

private dimensionWidgets = new Map<DimensionId, DimensionWidget>();
private dimensionWidgetList: DimensionWidget[] = [];
Expand Down Expand Up @@ -332,7 +333,7 @@ export class PositionWidget extends RefCounted {
}

const plot = dropdownOwner.registerDisposer(
new PositionPlot(this.position, widget.id),
new PositionPlot(this.position, widget.id, this.showAllPlotBounds),
);
dropdown.appendChild(plot.element);

Expand Down Expand Up @@ -1040,6 +1041,7 @@ export class PositionWidget extends RefCounted {
allowFocus = true,
showPlayback = true,
showDropdown = true,
showAllPlotBounds = undefined,
}: {
copyButton?: boolean;
velocity?: CoordinateSpacePlaybackVelocity;
Expand All @@ -1048,6 +1050,7 @@ export class PositionWidget extends RefCounted {
allowFocus?: boolean;
showPlayback?: boolean;
showDropdown?: boolean;
showAllPlotBounds?: WatchableValueInterface<boolean>;
} = {},
) {
super();
Expand All @@ -1058,6 +1061,7 @@ export class PositionWidget extends RefCounted {
this.allowFocus = allowFocus;
this.showPlayback = showPlayback;
this.showDropdown = showDropdown;
this.showAllPlotBounds = showAllPlotBounds;
this.registerDisposer(
position.coordinateSpace.changed.add(
this.registerCancellable(
Expand Down Expand Up @@ -1360,6 +1364,7 @@ interface SupportsDimensionTool<ToolContext extends object = object> {
velocity: CoordinateSpacePlaybackVelocity;
coordinateSpaceCombiner: CoordinateSpaceCombiner;
toolBinder: LocalToolBinder<ToolContext>;
showAllDimensionPlotBounds: WatchableValueInterface<boolean>;
}

const TOOL_INPUT_EVENT_MAP = EventActionMap.fromObject({
Expand Down Expand Up @@ -1452,12 +1457,18 @@ class DimensionTool<Viewer extends object> extends Tool<Viewer> {
allowFocus: inPalette,
showPlayback: false,
showDropdown: false,
showAllPlotBounds: viewer.showAllDimensionPlotBounds,
},
);
positionWidget.element.style.userSelect = "none";
content.appendChild(activation.registerDisposer(positionWidget).element);
const plot = activation.registerDisposer(
new PositionPlot(viewer.position, this.dimensionId, "row"),
new PositionPlot(
viewer.position,
this.dimensionId,
viewer.showAllDimensionPlotBounds,
"row",
),
);
plot.element.style.flex = "1";
content.appendChild(plot.element);
Expand Down Expand Up @@ -1659,6 +1670,8 @@ export function registerDimensionToolForViewer(contextType: typeof Viewer) {
coordinateSpaceCombiner:
viewer.layerSpecification.coordinateSpaceCombiner,
toolBinder: viewer.toolBinder,
showAllDimensionPlotBounds:
viewer.uiConfiguration.showAllDimensionPlotBounds,
},
obj,
),
Expand All @@ -1679,6 +1692,7 @@ export function registerDimensionToolForUserLayer(
velocity: layer.localVelocity,
coordinateSpaceCombiner: layer.localCoordinateSpaceCombiner,
toolBinder: layer.toolBinder,
showAllDimensionPlotBounds: new WatchableValue(true),
},
obj,
),
Expand All @@ -1698,6 +1712,7 @@ export function registerDimensionToolForLayerGroupViewer(
coordinateSpaceCombiner:
layerGroupViewer.layerSpecification.root.coordinateSpaceCombiner,
toolBinder: layerGroupViewer.toolBinder,
showAllDimensionPlotBounds: new WatchableValue(true),
},
obj,
),
Expand Down
Loading