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

feat(element): add hide UI attributes #177

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
169 changes: 89 additions & 80 deletions packages/element/src/itk-view-controls-shoelace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ export class ViewControlsShoelace extends LitElement {
@property({ type: String })
view: '2d' | '3d' = '2d';

@property({ type: Boolean })
hideSliceUi: boolean = false;

@property({ type: Boolean })
hideScaleUi: boolean = false;

@property({ type: Boolean })
hideColorUi: boolean = false;

@property({ type: Boolean })
hideTransferFunctionUi: boolean = false;

actor: ViewActor | undefined;
private controls = new ViewControls(this);

Expand Down Expand Up @@ -54,87 +66,80 @@ export class ViewControlsShoelace extends LitElement {
const colorMapOptions = this.controls.colorMapsOptions?.value ?? {};

const componentCount = this.controls.componentCount?.value ?? 1;
const showComponentSelector = componentCount > 1;
const showComponentSelector =
!(this.hideColorUi && this.hideTransferFunctionUi) && componentCount > 1;
const components = Array.from({ length: componentCount }, (_, i) => i);
const colorMap =
this.controls.colorMaps?.value[this.selectedComponent] ?? '';

const isImage3D = imageDimension >= 3;
const showScale = scaleCount >= 2;
const showScale = !this.hideScaleUi && scaleCount >= 2;
const tfEditorHeight = this.view === '2d' ? '2rem' : '8rem';

if (imageDimension === 0) {
return '';
}

return html`
<sl-card>
${
isImage3D && this.view === '2d'
? html`
<sl-range
value=${Number(slice)}
@sl-change="${this.controls.onSlice}"
min="0"
max="1"
step=".01"
label="Slice"
style="min-width: 8rem;"
></sl-range>
<sl-radio-group
label="Slice Axis"
value=${axis}
@sl-change="${this.controls.onAxis}"
>
<sl-radio-button value="I">X</sl-radio-button>
<sl-radio-button value="J">Y</sl-radio-button>
<sl-radio-button value="K">Z</sl-radio-button>
</sl-radio-group>
`
: ''
}
${
showScale
? html`
<sl-radio-group
label="Image Scale"
value=${scale}
@sl-change="${this.controls.onScale}"
>
${scaleOptions.map(
(option) =>
html`<sl-radio-button value=${option}>
${option}
</sl-radio-button>`,
)}
</sl-radio-group>
`
: ''
}
${
showComponentSelector
? html`
<sl-tab-group
style="max-width: 18rem"
value=${this.controls.selectedComponent}
@sl-tab-show="${(e: CustomEvent) => {
const component = Number(e.detail.name);
this.controls.onSelectedComponent(component);
// trigger re-render to update color map value
this.selectedComponent = Number(e.detail.name);
}}"
>
${components.map(
(option) =>
html`<sl-tab panel="${option}" slot="nav">
Component ${option}
</sl-tab>`,
)}
</sl-tab-group>
`
: ''
}

${isImage3D && this.view === '2d' && !this.hideSliceUi
? html`
<sl-range
value=${Number(slice)}
@sl-change="${this.controls.onSlice}"
min="0"
max="1"
step=".01"
label="Slice"
style="min-width: 8rem;"
></sl-range>
<sl-radio-group
label="Slice Axis"
value=${axis}
@sl-change="${this.controls.onAxis}"
>
<sl-radio-button value="I">X</sl-radio-button>
<sl-radio-button value="J">Y</sl-radio-button>
<sl-radio-button value="K">Z</sl-radio-button>
</sl-radio-group>
`
: ''}
${showScale
? html`
<sl-radio-group
label="Image Scale"
value=${scale}
@sl-change="${this.controls.onScale}"
>
${scaleOptions.map(
(option) =>
html`<sl-radio-button value=${option}>
${option}
</sl-radio-button>`,
)}
</sl-radio-group>
`
: ''}
${showComponentSelector
? html`
<sl-tab-group
style="max-width: 18rem"
value=${this.controls.selectedComponent}
@sl-tab-show="${(e: CustomEvent) => {
const component = Number(e.detail.name);
this.controls.onSelectedComponent(component);
// trigger re-render to update color map value
this.selectedComponent = Number(e.detail.name);
}}"
>
${components.map(
(option) =>
html`<sl-tab panel="${option}" slot="nav">
Component ${option}
</sl-tab>`,
)}
</sl-tab-group>
`
: ''}
${this.hideColorUi
? ''
: html`
<sl-dropdown style="padding-top: .4rem; width: 100%">
<sl-button slot="trigger" caret class="color-button">
<sl-tooltip content=${colorMap}>
Expand All @@ -157,14 +162,18 @@ export class ViewControlsShoelace extends LitElement {
)}
</sl-menu>
</sl-dropdown>

<div style="padding-top: 0.4rem;">
${this.view === '2d' ? 'Color Range' : 'Opacity and Color'}
</div>
<div
${ref(this.transferFunctionContainerChanged)}
style=${`width: 100%; min-width: 12rem; height: ${tfEditorHeight};`}
></div>
`}
${this.hideTransferFunctionUi
? ''
: html`
<div style="padding-top: 0.4rem;">
${this.view === '2d' ? 'Color Range' : 'Opacity and Color'}
</div>
<div
${ref(this.transferFunctionContainerChanged)}
style=${`width: 100%; min-width: 12rem; height: ${tfEditorHeight};`}
></div>
`}
</sl-card>
`;
}
Expand Down
18 changes: 17 additions & 1 deletion packages/element/src/itk-viewer-2d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LitElement, css, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { customElement, property } from 'lit/decorators.js';
import { Ref, createRef, ref } from 'lit/directives/ref.js';
import './itk-viewer-element.js';
import { ItkViewer } from './itk-viewer-element.js';
Expand All @@ -16,6 +16,18 @@ export class ItkViewer2d extends LitElement {
view: Ref<ItkView2d> = createRef();
controls: Ref<ViewControlsShoelace> = createRef();

@property({ type: Boolean })
hideSliceUi: boolean = false;

@property({ type: Boolean })
hideScaleUi: boolean = false;

@property({ type: Boolean })
hideColorUi: boolean = false;

@property({ type: Boolean })
hideTransferFunctionUi: boolean = false;

getActor() {
return this.viewer.value?.getActor();
}
Expand All @@ -29,6 +41,10 @@ export class ItkViewer2d extends LitElement {
<itk-view-controls-shoelace
view="2d"
${ref(this.controls)}
?hideSliceUi="${this.hideSliceUi}"
?hideScaleUi="${this.hideScaleUi}"
?hideColorUi="${this.hideColorUi}"
?hideTransferFunctionUi="${this.hideTransferFunctionUi}"
></itk-view-controls-shoelace>
</div>
<itk-view-2d ${ref(this.view)} class="fill">
Expand Down
14 changes: 13 additions & 1 deletion packages/element/src/itk-viewer-3d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LitElement, css, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { customElement, property } from 'lit/decorators.js';
import { Ref, createRef, ref } from 'lit/directives/ref.js';
import './itk-viewer-element.js';
import { ItkViewer } from './itk-viewer-element.js';
Expand All @@ -16,6 +16,15 @@ export class ItkViewer3d extends LitElement {
view: Ref<ItkView3d> = createRef();
controls: Ref<ViewControlsShoelace> = createRef();

@property({ type: Boolean })
hideScaleUi: boolean = false;

@property({ type: Boolean })
hideColorUi: boolean = false;

@property({ type: Boolean })
hideTransferFunctionUi: boolean = false;

getActor() {
return this.viewer.value?.getActor();
}
Expand All @@ -29,6 +38,9 @@ export class ItkViewer3d extends LitElement {
<itk-view-controls-shoelace
view="3d"
${ref(this.controls)}
?hideScaleUi="${this.hideScaleUi}"
?hideColorUi="${this.hideColorUi}"
?hideTransferFunctionUi="${this.hideTransferFunctionUi}"
></itk-view-controls-shoelace>
</div>
<itk-view-3d ${ref(this.view)} class="fill">
Expand Down