From cc4f9fe53d1469f7629765163eec518ca3a40def Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Tue, 27 Feb 2018 16:35:00 -0500 Subject: [PATCH 1/3] fix(Layout2D): Show/hide slider based on active source --- Sources/layouts/Layout2D.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sources/layouts/Layout2D.js b/Sources/layouts/Layout2D.js index f8a1d811..e0d2a3d5 100644 --- a/Sources/layouts/Layout2D.js +++ b/Sources/layouts/Layout2D.js @@ -13,6 +13,10 @@ export default class Layout2D extends React.Component { constructor(props) { super(props); + this.state = { + sliceSliderVisible: false, + }; + // Setup vtk.js objects this.activeRepresentation = null; this.view = props.proxyManager.createProxy('Views', props.viewType); @@ -42,11 +46,11 @@ export default class Layout2D extends React.Component { this.props.proxyManager.onActiveSourceChange(this.onActiveSourceChange), this.props.proxyManager.onActiveViewChange(this.flush), ]; - - this.onActiveSourceChange(); } componentDidMount() { + this.onActiveSourceChange(); + this.view.setContainer(this.container); this.slider.setContainer(this.sliderContainer); @@ -121,6 +125,11 @@ export default class Layout2D extends React.Component { }); } this.updateSlider(); + + // update slider visibility based on current active source/representation + this.setState({ + sliceSliderVisible: newRep && newRep.getSlice, + }); } updateSlider() { @@ -222,10 +231,7 @@ export default class Layout2D extends React.Component { className={style.sideBar} style={{ background: COLOR_BY_AXIS[this.view.getAxis()], - visibility: - this.activeRepresentation && this.activeRepresentation.getSlice - ? 'visible' - : 'hidden', + visibility: this.state.sliceSliderVisible ? 'visible' : 'hidden', }} ref={(c) => { this.sliderContainer = c; From da47702ff06e95ef23ce636e76edb566bc428713 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Tue, 27 Feb 2018 16:36:55 -0500 Subject: [PATCH 2/3] fix(Layout2D): Remove duplicate onActiveSourceChange call --- Sources/layouts/Layout2D.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/layouts/Layout2D.js b/Sources/layouts/Layout2D.js index e0d2a3d5..255328ae 100644 --- a/Sources/layouts/Layout2D.js +++ b/Sources/layouts/Layout2D.js @@ -156,7 +156,6 @@ export default class Layout2D extends React.Component { reps[i].setSlicingMode('XYZ'[state.axis]); } } - this.onActiveSourceChange(); this.props.proxyManager.modified(); this.view.resetCamera(); this.view.renderLater(); From 8000044cd6650e078a10f19698eb6770c7616324 Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Tue, 27 Feb 2018 16:56:46 -0500 Subject: [PATCH 3/3] fix(Layout2D): Update corner annotations when no active source exists Explicitly set the active representation to newRep even when newRep is undefined/null. This allows other logic to tell if there even is an active representation. --- Sources/layouts/Layout2D.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/layouts/Layout2D.js b/Sources/layouts/Layout2D.js index 255328ae..991806cc 100644 --- a/Sources/layouts/Layout2D.js +++ b/Sources/layouts/Layout2D.js @@ -98,7 +98,6 @@ export default class Layout2D extends React.Component { this.repSubscription = null; } if (newRep) { - this.activeRepresentation = newRep; this.repSubscription = newRep.onModified(() => { if (this.activeRepresentation && this.activeRepresentation.getSlice) { this.slider.setValue(Number(this.activeRepresentation.getSlice())); @@ -118,12 +117,20 @@ export default class Layout2D extends React.Component { }); } + this.activeRepresentation = newRep; + if (this.activeRepresentation && this.activeRepresentation.getColorWindow) { this.view.updateCornerAnnotation({ colorWindow: Math.round(this.activeRepresentation.getColorWindow()), colorLevel: Math.round(this.activeRepresentation.getColorLevel()), }); + } else { + this.view.updateCornerAnnotation({ + colorWindow: '(none)', + colorLevel: '(none)', + }); } + this.updateSlider(); // update slider visibility based on current active source/representation @@ -144,6 +151,10 @@ export default class Layout2D extends React.Component { this.view.updateCornerAnnotation({ slice: Number(this.activeRepresentation.getSlice()).toFixed(2), }); + } else { + this.view.updateCornerAnnotation({ + slice: '(none)', + }); } }