-
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.
[HCS images] Ability to lock ranges of the channels (#2528)
- Loading branch information
1 parent
f263901
commit ac0dc51
Showing
15 changed files
with
174 additions
and
25 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
82 changes: 82 additions & 0 deletions
82
hcs-image-viewer/src/lib/state/viewer-state/lock-channels-state.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,82 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
const EMPTY_ARRAY = []; | ||
|
||
export default function lockChannelsState(state, channelsInfo) { | ||
const { | ||
lockChannels = false, | ||
channels: currentChannels = EMPTY_ARRAY, | ||
colors: currentColors = EMPTY_ARRAY, | ||
domains: currentDomains = EMPTY_ARRAY, | ||
contrastLimits: currentContrastLimits = EMPTY_ARRAY, | ||
channelsVisibility: currentChannelsVisibility = EMPTY_ARRAY, | ||
} = state || {}; | ||
const { | ||
channels = EMPTY_ARRAY, | ||
colors = EMPTY_ARRAY, | ||
domains = EMPTY_ARRAY, | ||
contrastLimits = EMPTY_ARRAY, | ||
...rest | ||
} = channelsInfo || {}; | ||
if (!lockChannels) { | ||
return { | ||
...rest, | ||
channels, | ||
colors, | ||
domains, | ||
contrastLimits, | ||
realDomains: domains.slice(), | ||
channelsVisibility: channels.map(() => true), | ||
}; | ||
} | ||
const currentChannelNames = currentChannels.slice(); | ||
const lockedChannels = []; | ||
for (let c = 0; c < channels.length; c += 1) { | ||
const currentChannelIndex = currentChannelNames.indexOf(channels[c]); | ||
if (currentChannelIndex === -1) { | ||
lockedChannels.push({ | ||
channel: channels[c], | ||
color: colors[c], | ||
domain: domains[c], | ||
realDomain: domains[c].slice(), | ||
contrastLimits: contrastLimits[c], | ||
visibility: true, | ||
}); | ||
} else { | ||
currentChannelNames.splice(currentChannelIndex, 1, undefined); | ||
lockedChannels.push({ | ||
channel: channels[c], | ||
color: currentColors[currentChannelIndex] || colors[c], | ||
domain: currentDomains[currentChannelIndex] || domains[c], | ||
realDomain: domains[c].slice(), | ||
contrastLimits: currentContrastLimits[currentChannelIndex] || contrastLimits[c], | ||
visibility: currentChannelsVisibility[currentChannelIndex] === undefined | ||
? true | ||
: currentChannelsVisibility[currentChannelIndex], | ||
}); | ||
} | ||
} | ||
return { | ||
...rest, | ||
channels: lockedChannels.map((o) => o.channel), | ||
colors: lockedChannels.map((o) => o.color), | ||
domains: lockedChannels.map((o) => o.domain), | ||
realDomains: lockedChannels.map((o) => o.realDomain), | ||
contrastLimits: lockedChannels.map((o) => o.contrastLimits), | ||
channelsVisibility: lockedChannels.map((o) => o.visibility), | ||
}; | ||
} |
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