-
Notifications
You must be signed in to change notification settings - Fork 4
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
Toggle crosshair and perspective background #1153
Open
fsdavid
wants to merge
11
commits into
dev
Choose a base branch
from
dev_view_settings
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bdc30c5
Add viewer tab on settings
fsdavid 4e63a85
Merge pull request #1152 from FZJ-INM1-BDA/dev_viewer_settings
fsdavid f3cc185
Review fixes
fsdavid 8d37973
Make PR fixes for hide axis line
fsdavid 70f5946
Fix lint
fsdavid 1808483
Fix by PR comments
fsdavid 138e503
Fix viewer settings issues
fsdavid 7faf9d8
Add confg component store
fsdavid 17eb9d5
Add toggle slice background to quick menu
fsdavid 0eb69b5
Fix tests
fsdavid 4b04ee2
Add tests for config
fsdavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import {ConfigComponent} from "src/ui/config/configCmp/config.component"; | ||
import {ComponentFixture, TestBed} from "@angular/core/testing"; | ||
import {Observable, of} from "rxjs"; | ||
import {AngularMaterialModule} from "src/sharedModules"; | ||
import {PluginModule} from "src/plugin"; | ||
import {LayoutModule} from "src/layouts/layout.module"; | ||
import {ConfigStore} from "src/ui/config/configCmp/config.store"; | ||
import {Action, StoreModule} from "@ngrx/store"; | ||
import {HttpClientModule} from "@angular/common/http"; | ||
import {provideMockActions} from "@ngrx/effects/testing"; | ||
import {MockStore, provideMockStore} from "@ngrx/store/testing"; | ||
import {BS_ENDPOINT} from "src/util/constants"; | ||
import {HarnessLoader} from "@angular/cdk/testing"; | ||
import {TestbedHarnessEnvironment} from "@angular/cdk/testing/testbed"; | ||
import {MatSlideToggleHarness} from "@angular/material/slide-toggle/testing"; | ||
import { | ||
ngViewerSelectorPanelMode, | ||
ngViewerSelectorPanelOrder | ||
} from "src/services/state/ngViewerState/selectors"; | ||
import {PANELS} from "src/services/state/ngViewerState/constants"; | ||
import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; | ||
import {PureContantService} from "src/util"; | ||
|
||
|
||
fdescribe('config.component.ts', () => { | ||
let component: ConfigComponent | ||
let fixture: ComponentFixture<ConfigComponent> | ||
|
||
const mockConfigStore = jasmine.createSpyObj( | ||
'ConfigStore', | ||
['setState', | ||
'setAxisLineVisible', | ||
'setSliceBackground', | ||
'setBackgroundVisibility'], | ||
{ sliceBackgroundRgb$: of('#CCCCCC'), | ||
axisLineVisible$: of(false), | ||
togglePerspectiveViewSubstrate$: of(true)}) | ||
|
||
const MOCK_BS_ENDPOINT = `http://localhost:1234` | ||
const actions$: Observable<Action> = of({type: 'TEST'}) | ||
let mockStore: MockStore | ||
let loader: HarnessLoader; | ||
|
||
|
||
|
||
beforeEach((async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ ConfigComponent, ], | ||
imports: [ | ||
StoreModule.forRoot({}), | ||
AngularMaterialModule, | ||
BrowserAnimationsModule, | ||
HttpClientModule, | ||
PluginModule, | ||
LayoutModule | ||
], | ||
providers: [ | ||
provideMockActions(() => actions$), | ||
provideMockStore({ | ||
initialState: { | ||
viewerConfigState: { | ||
gpuLimit: 1e9, | ||
animation: true | ||
} | ||
} | ||
}), | ||
{ | ||
provide: BS_ENDPOINT, | ||
useValue: MOCK_BS_ENDPOINT | ||
}, | ||
{ | ||
provide: PureContantService, | ||
useFactory: () => { | ||
return { | ||
getViewerConfig: jasmine.createSpy('getViewerConfig') | ||
} | ||
} | ||
} | ||
], | ||
}).compileComponents() | ||
|
||
await TestBed.overrideProvider(ConfigStore, { useValue: mockConfigStore }) | ||
|
||
mockStore = await TestBed.inject(MockStore) | ||
await mockStore.overrideSelector(ngViewerSelectorPanelMode, PANELS.FOUR_PANEL) | ||
await mockStore.overrideSelector(ngViewerSelectorPanelOrder, '0123') | ||
|
||
fixture = await TestBed.createComponent(ConfigComponent) | ||
await fixture.detectChanges() | ||
loader = await TestbedHarnessEnvironment.loader(fixture); | ||
component = await fixture.componentInstance | ||
|
||
|
||
})) | ||
|
||
describe('Viewer config', () => { | ||
|
||
beforeEach(async () => { | ||
const configEl: HTMLElement = fixture.nativeElement; | ||
const tabGroup = configEl.querySelector('mat-tab-group')! | ||
const tabEl = tabGroup.querySelector('[aria-label="viewer-tab"]')! | ||
|
||
const event = await new MouseEvent('click', {bubbles: true}) | ||
tabEl.dispatchEvent(event); | ||
}) | ||
|
||
describe('set axlisLineVisible visibility', () => { | ||
|
||
it('axisLine toggle should false by default', async () => { | ||
const axisLineEl = await loader.getAllHarnesses( | ||
MatSlideToggleHarness.with({ | ||
name: 'axis-line-toggle', | ||
}) | ||
) | ||
const isChecked = await axisLineEl[0].isChecked() | ||
expect(isChecked).toBeFalse() | ||
}) | ||
|
||
it('toggle axis line element should call mockConfigStore -> setAxisLineVisible', async () => { | ||
const axisLineEl = await loader.getAllHarnesses( | ||
MatSlideToggleHarness.with({ | ||
name: 'axis-line-toggle', | ||
}) | ||
) | ||
await axisLineEl[0].toggle() | ||
expect(mockConfigStore.setAxisLineVisible).toHaveBeenCalledWith(true); | ||
}) | ||
|
||
}); | ||
|
||
describe('set background visibility', () => { | ||
|
||
it('togglePerspectiveViewSubstrate toggle should false by default', async () => { | ||
const persBgEl = await loader.getAllHarnesses( | ||
MatSlideToggleHarness.with({ | ||
name: 'perspective-background-toggle', | ||
}) | ||
) | ||
const isChecked = await persBgEl[0].isChecked() | ||
expect(isChecked).toBeTrue() | ||
}) | ||
|
||
it('Bg color toggle should call mockConfigStore -> setBackgroundVisibility', async () => { | ||
const persBgEl = await loader.getAllHarnesses( | ||
MatSlideToggleHarness.with({ | ||
name: 'perspective-background-toggle', | ||
}) | ||
) | ||
await persBgEl[0].toggle() | ||
expect(mockConfigStore.setBackgroundVisibility).toHaveBeenCalledWith(false); | ||
}) | ||
|
||
it('backgroundColorPicker default value should be correct', async () => { | ||
const persBgEl = await loader.getAllHarnesses( | ||
MatSlideToggleHarness.with({ | ||
name: 'perspective-background-toggle', | ||
}) | ||
) | ||
await persBgEl[0].toggle() | ||
const colorPicker = await fixture.nativeElement.querySelector('[name="backgroundColorPicker"]')! | ||
expect(colorPicker.value).toEqual('#cccccc') | ||
}) | ||
|
||
}); | ||
|
||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {ConfigStore} from "src/ui/config/configCmp/config.store"; | ||
|
||
describe('> config.store.ts', () => { | ||
describe('> Viewer config', () => { | ||
|
||
let configStore | ||
beforeEach(() => { | ||
configStore = new ConfigStore() | ||
configStore.setState({ | ||
sliceBackground: [], | ||
axisLineVisible: false, | ||
togglePerspectiveViewSubstrate: false | ||
}) | ||
}) | ||
|
||
it('set axlisLineVisible visibility', (done) => { | ||
configStore.setAxisLineVisible(true) | ||
configStore.state$.subscribe((state) => { | ||
expect(state.axisLineVisible).toBeTrue() | ||
done() | ||
}) | ||
|
||
}) | ||
|
||
describe('set slice background color', () => { | ||
it('set background with hex string', (done) => { | ||
configStore.setSliceBackground('#32a852') | ||
configStore.state$.subscribe((state) => { | ||
expect(state.sliceBackground).toEqual([50, 168, 82, 0.2]) | ||
done() | ||
}) | ||
}) | ||
it('set background with rgb', (done) => { | ||
configStore.setSliceBackground([50, 50, 50]) | ||
configStore.state$.subscribe((state) => { | ||
expect(state.sliceBackground).toEqual([50, 50, 50, 0.2]) | ||
done() | ||
}) | ||
}) | ||
it('set background with rgba', (done) => { | ||
configStore.setSliceBackground([0, 0, 0, 1]) | ||
configStore.state$.subscribe((state) => { | ||
expect(state.sliceBackground).toEqual([0, 0, 0, 1]) | ||
done() | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
it('set background visibility', (done) => { | ||
configStore.setBackgroundVisibility(true) | ||
configStore.state$.subscribe((state) => { | ||
expect(state.togglePerspectiveViewSubstrate).toBeTrue() | ||
done() | ||
}) | ||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {Injectable} from "@angular/core"; | ||
import {Observable} from "rxjs"; | ||
import {ComponentStore} from "@ngrx/component-store"; | ||
import {take} from "rxjs/operators"; | ||
export interface ConfigState { | ||
sliceBackground: any[] | ||
axisLineVisible: boolean | ||
togglePerspectiveViewSubstrate: boolean | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ConfigStore extends ComponentStore<ConfigState> { | ||
|
||
private get viewer(){ | ||
return (window as any).viewer | ||
} | ||
|
||
private get nehubaViewer(){ | ||
return (window as any).nehubaViewer | ||
} | ||
|
||
constructor() { | ||
super({ | ||
sliceBackground: [], | ||
axisLineVisible: false, | ||
togglePerspectiveViewSubstrate: false | ||
}) | ||
|
||
// ToDo find better way to get nehubaviewer containing cofig | ||
setTimeout(() => { | ||
if (this.nehubaViewer && this.nehubaViewer.config) { | ||
this.setSliceBackground( | ||
this.nehubaViewer.config.layout.useNehubaPerspective.drawSubstrates.color | ||
.map((v, i) => i === 3 ? v : Math.floor(v * 255)) | ||
) | ||
this.select(state => state.sliceBackground).pipe(take(1)).subscribe(background => { | ||
this.setBackgroundVisibility(background.length && background[3] > 0) | ||
}) | ||
this.setAxisLineVisible((window as any).viewer.showAxisLines.value ? true : false) | ||
} | ||
}) | ||
} | ||
|
||
readonly sliceBackground$: Observable<any[]> = this.select(state => state.sliceBackground) | ||
readonly sliceBackgroundRgb$: Observable<string> = this.select(state => { | ||
const color = state.sliceBackground | ||
return color.length? '#' + [color[0], color[1], color[2]].map(x => x.toString(16).length === 1 ? '0' + x.toString(16) : x.toString(16)).join('') : '' | ||
}) | ||
readonly axisLineVisible$: Observable<boolean> = this.select(state => state.axisLineVisible) | ||
readonly togglePerspectiveViewSubstrate$: Observable<boolean> = this.select(state => state.togglePerspectiveViewSubstrate) | ||
|
||
|
||
readonly setAxisLineVisible = this.updater((state, value: boolean) => { | ||
if (this.viewer) this.viewer.showAxisLines.restoreState(value) | ||
return { | ||
...state, | ||
axisLineVisible: value | ||
} | ||
}) | ||
|
||
readonly setSliceBackground = this.updater((state, value: any) => { | ||
if (typeof value === 'string') value = this.hexToRgb(value) | ||
value = value.length === 4 ? value : [...value, 0.2] | ||
|
||
if (this.nehubaViewer) { | ||
this.nehubaViewer.config.layout.useNehubaPerspective.drawSubstrates.color = value.map((v, i) => i === 3 ? v : v / 255.0) | ||
this.nehubaViewer.redraw() | ||
} | ||
|
||
return { | ||
...state, | ||
sliceBackground: value | ||
} | ||
}) | ||
|
||
readonly setBackgroundVisibility = this.updater((state, value: boolean) => { | ||
|
||
if (this.nehubaViewer) { | ||
this.nehubaViewer.config.layout.useNehubaPerspective.drawSubstrates.color[3] = value ? 0.2 : 0 | ||
this.nehubaViewer.redraw() | ||
} | ||
|
||
return { | ||
...state, | ||
togglePerspectiveViewSubstrate: value | ||
} | ||
}) | ||
|
||
public hexToRgb(hex) : any[] { | ||
return hex.match(/\w\w/g).map(x => parseInt(x, 16)) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xgui3783 on my local machine
viewerCtrlCmp.component.ts > ViewerCtrlCmp > toggleParcVsbl > if _flagDelin is false > calls schedulRedraw FAILED
test is failing? (it was not failed here, but I think potentially it could) could it be caused bysetTimeout
? if it is, would you have any idea how to get nehubaviewer containingconfig
on to set initial values?