Skip to content

Commit

Permalink
Merge pull request #26 from floryst/layout2d_fixes
Browse files Browse the repository at this point in the history
Layout2d fixes
  • Loading branch information
floryst authored Feb 28, 2018
2 parents b2e63c0 + 8000044 commit 4255b7c
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions Sources/layouts/Layout2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -94,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()));
Expand All @@ -114,13 +117,26 @@ 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
this.setState({
sliceSliderVisible: newRep && newRep.getSlice,
});
}

updateSlider() {
Expand All @@ -135,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)',
});
}
}

Expand All @@ -147,7 +167,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();
Expand Down Expand Up @@ -222,10 +241,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;
Expand Down

0 comments on commit 4255b7c

Please sign in to comment.