-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preview for the HCS images (#2489) - Stack panel
- Loading branch information
1 parent
27a8caf
commit 63ea86f
Showing
9 changed files
with
316 additions
and
89 deletions.
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
38 changes: 38 additions & 0 deletions
38
client/src/components/special/hcs-image/hcs-z-position-selector/hcs-z-position-selector.css
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,38 @@ | ||
/* | ||
* Copyright 2017-2022 EPAM Systems, Inc. (https://www.epam.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
.container { | ||
padding: 5px; | ||
overflow: hidden; | ||
} | ||
|
||
.container .slider-container { | ||
max-height: 200px; | ||
padding: 14px 0; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
} | ||
|
||
.container.horizontal .slider-container { | ||
width: 100%; | ||
display: block; | ||
padding: 0 10px; | ||
} | ||
|
||
.title { | ||
font-weight: bold; | ||
} |
146 changes: 146 additions & 0 deletions
146
client/src/components/special/hcs-image/hcs-z-position-selector/index.js
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,146 @@ | ||
/* | ||
* Copyright 2017-2022 EPAM Systems, Inc. (https://www.epam.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import {Slider} from 'antd'; | ||
import {inject, observer} from 'mobx-react'; | ||
|
||
import {MAX_Z_POSITIONS_TO_DISPLAY} from '../utilities/constants'; | ||
import styles from './hcs-z-position-selector.css'; | ||
|
||
const SelectorType = { | ||
vertical: 'vertical', | ||
horizontal: 'horizontal' | ||
}; | ||
|
||
const MAX_HEIGHT_PER_TICK = 45; | ||
|
||
function zPositionSorter (a, b) { | ||
return a.z - b.z; | ||
} | ||
|
||
function HcsZPositionSelector (props) { | ||
const { | ||
className, | ||
type = SelectorType.horizontal, | ||
hcsViewerState | ||
} = props; | ||
if (!hcsViewerState) { | ||
return null; | ||
} | ||
const { | ||
availableZPositions: positions = [], | ||
imageZPosition: value | ||
} = hcsViewerState; | ||
const onChange = z => hcsViewerState.changeGlobalZPosition(z); | ||
if (positions.length > 1) { | ||
const sorted = positions | ||
.slice() | ||
.sort(zPositionSorter); | ||
const tipFormatter = z => { | ||
const item = sorted.find(o => o.z === z); | ||
if (item) { | ||
return item.title; | ||
} | ||
return null; | ||
}; | ||
const [first] = sorted; | ||
const last = sorted[sorted.length - 1]; | ||
const firstTitleLength = (first.title || '').length; | ||
const lastTitleLength = (last.title || '').length; | ||
const getPadding = titleLength => `${Math.ceil(titleLength / 2)}em`; | ||
const max = last.z; | ||
const min = first.z; | ||
let marks = { | ||
[first.z]: first.title, | ||
[last.z]: last.title | ||
}; | ||
if (positions.length <= MAX_Z_POSITIONS_TO_DISPLAY) { | ||
marks = positions.reduce((points, {z, title}) => ({ | ||
...points, | ||
[z]: title | ||
}), {}); | ||
} | ||
const verticalStyle = { | ||
height: positions.length * MAX_HEIGHT_PER_TICK | ||
}; | ||
const horizontalStyle = { | ||
paddingLeft: getPadding(firstTitleLength), | ||
paddingRight: getPadding(lastTitleLength) | ||
}; | ||
return ( | ||
<div | ||
className={ | ||
classNames( | ||
className, | ||
styles.container, | ||
{ | ||
[styles.horizontal]: type === SelectorType.horizontal | ||
} | ||
)} | ||
> | ||
<div | ||
className={styles.title} | ||
> | ||
Z-plane | ||
</div> | ||
<div | ||
className={styles.sliderContainer} | ||
style={ | ||
type === SelectorType.vertical | ||
? verticalStyle | ||
: horizontalStyle | ||
} | ||
> | ||
<Slider | ||
className={'cp-hcs-z-position-slider'} | ||
vertical={type === SelectorType.vertical} | ||
included={false} | ||
dots | ||
value={value} | ||
marks={marks} | ||
max={max} | ||
min={min} | ||
step={1} | ||
onChange={onChange} | ||
tipFormatter={tipFormatter} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
HcsZPositionSelector.propTypes = { | ||
className: PropTypes.string, | ||
type: PropTypes.oneOf([ | ||
SelectorType.vertical, | ||
SelectorType.horizontal | ||
]) | ||
}; | ||
|
||
HcsZPositionSelector.defaultProps = { | ||
type: SelectorType.horizontal | ||
}; | ||
|
||
const selector = inject('hcsViewerState')(observer(HcsZPositionSelector)); | ||
|
||
selector.Type = SelectorType; | ||
|
||
export default selector; |
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
Oops, something went wrong.