Skip to content

Commit

Permalink
#3019 - Initial changes to logic for showing labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoblit committed Aug 18, 2023
1 parent c69c4d4 commit 5ab69af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
18 changes: 2 additions & 16 deletions packages/ketcher-core/src/application/render/restruct/reatom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,35 +574,21 @@ function shouldDisplayStereoLabel(
ignoreChiralFlag,
flag: StereoFlag | undefined,
): boolean {
if (!stereoLabel) {
if (!stereoLabel || ignoreChiralFlag) {
return false;
}
const stereoLabelType = stereoLabel.match(/\D+/g)[0];

const stereoLabelTypeWithChiralFlag = ignoreChiralFlag
? StereoLabel.Abs
: stereoLabelType;

if (stereoLabelTypeWithChiralFlag === StereoLabel.Abs) {
return false;
}
if (stereoLabelTypeWithChiralFlag === StereoLabel.And) {
return true;
}
const stereoLabelType = stereoLabel.match(/\D+/g)[0];

switch (labelStyle) {
// Off
case StereLabelStyleType.Off:
return false;
// On
case StereLabelStyleType.On:
return true;
// Classic
case StereLabelStyleType.Classic:
return !!(
flag === StereoFlag.Mixed || stereoLabelType === StereoLabel.Or
);
// IUPAC
case StereLabelStyleType.IUPAC:
return !!(
flag === StereoFlag.Mixed && stereoLabelType !== StereoLabel.Abs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ class ReEnhancedFlag extends ReObject {
show(restruct: ReStruct, fragmentId: number, options: any): void {
const render = restruct.render;
const fragment = restruct.molecule.frags.get(fragmentId);
if (!fragment?.enhancedStereoFlag) return;
const stereoFlag = fragment?.enhancedStereoFlag;

if (!stereoFlag) {
return;
}

// We don't want to show the ovarall label (flag) in case there are different types
// of stereo labels inside the structure ("mixed" and "or" stereo flags indicate that)
if (stereoFlag === StereoFlag.Mixed || stereoFlag === StereoFlag.Or) {
return;
}

const position = fragment.stereoFlagPosition
? fragment.stereoFlagPosition
Expand All @@ -75,13 +85,7 @@ class ReEnhancedFlag extends ReObject {

if (options.showStereoFlags && !options.ignoreChiralFlag) {
this.#path = paper
.text(
ps.x,
ps.y,
fragment.enhancedStereoFlag
? stereoFlagMap[fragment.enhancedStereoFlag]
: '',
)
.text(ps.x, ps.y, stereoFlag ? stereoFlagMap[stereoFlag] : '')
.attr({
font: options.font,
'font-size': options.fontsz,
Expand Down

0 comments on commit 5ab69af

Please sign in to comment.