Skip to content

Commit

Permalink
#3923 refactor and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlaStarla committed Feb 9, 2024
1 parent 9532851 commit c31322a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
27 changes: 15 additions & 12 deletions packages/ketcher-core/src/application/render/raphaelRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,6 @@ export class Render {
}
}

private getViewSize(viewSz: Vec2 | null) {
viewSz =
viewSz ||
new Vec2(
this.clientArea.clientWidth || 100,
this.clientArea.clientHeight || 100,
);
return viewSz;
}

calculateRescale(viewSz: Vec2 | null = null) {
const marg = this.options.autoScaleMargin;
viewSz = this.getViewSize(viewSz);
Expand All @@ -260,8 +250,11 @@ export class Render {
boundingBoxSize.x / (viewSz.x - 2 * marg),
boundingBoxSize.y / (viewSz.y - 2 * marg),
);
if (this.ctab.molecule.minPreviewRescale) {
rescale = Math.min(this.ctab.molecule.minPreviewRescale, rescale);
if (
this.ctab.molecule.minPreviewRescale &&
rescale > this.ctab.molecule.minPreviewRescale
) {
rescale = this.ctab.molecule.minPreviewRescale;
}
const isForceDownscale = this.options.downScale && rescale < 1;
const isBondsLengthFit = this.options.maxBondLength / rescale > 1;
Expand All @@ -271,6 +264,16 @@ export class Render {
return rescale;
}

private getViewSize(viewSz: Vec2 | null) {
viewSz =
viewSz ||
new Vec2(
this.clientArea.clientWidth || 100,
this.clientArea.clientHeight || 100,
);
return viewSz;
}

private getBoundingBox() {
return this.ctab
.getVBoxObj()
Expand Down
4 changes: 2 additions & 2 deletions packages/ketcher-core/src/application/render/renderStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class RenderStruct {
options: any = {},
originalStruct: Struct,
update = false,
monomerConnectionMode = false,
needRescale = false,
) {
if (el && struct) {
const { cachePrefix = '', needCache = true } = options;
Expand Down Expand Up @@ -90,7 +90,7 @@ export class RenderStruct {

preparedStruct.rescale();
rnd.setMolecule(preparedStruct);
if (monomerConnectionMode) {
if (needRescale) {
const rescale = rnd.calculateRescale();
if (update) {
originalStruct.previewRescale = rescale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,15 @@ const MonomerConnection = ({
const [secondSelectedAttachmentPoint, setSecondSelectedAttachmentPoint] =
useState<string | null>(getDefaultAttachmentPoint(secondMonomer));
const [modalExpanded, setModalExpanded] = useState(false);

const [rescaleForMonomers, setRescaleForMonomers] = useState<number | null>(
null,
);
const [commonRescale, setCommonRescale] = useState<number | null>(null);

useEffect(() => {
if (modalExpanded) {
const rescale = Math.max(
firstMonomer.monomerItem.struct.previewRescale,
secondMonomer.monomerItem.struct.previewRescale,
);
setRescaleForMonomers(rescale);
setCommonRescale(rescale);
}
}, [
firstMonomer.monomerItem.struct.previewRescale,
Expand Down Expand Up @@ -134,7 +131,7 @@ const MonomerConnection = ({

const handleExpanded = (expand: boolean) => {
setModalExpanded(expand);
setRescaleForMonomers(null);
setCommonRescale(null);
};

return (
Expand All @@ -158,7 +155,7 @@ const MonomerConnection = ({
selectedAttachmentPoint={firstSelectedAttachmentPoint}
onSelectAttachmentPoint={setFirstSelectedAttachmentPoint}
expanded={modalExpanded}
rescaleForMonomers={rescaleForMonomers}
commonRescale={commonRescale}
/>
<span />
<ConnectionSymbol />
Expand All @@ -172,7 +169,7 @@ const MonomerConnection = ({
selectedAttachmentPoint={secondSelectedAttachmentPoint}
onSelectAttachmentPoint={setSecondSelectedAttachmentPoint}
expanded={modalExpanded}
rescaleForMonomers={rescaleForMonomers}
commonRescale={commonRescale}
/>
</AttachmentPointsRow>
</ModalContent>
Expand Down Expand Up @@ -200,16 +197,16 @@ interface AttachmentPointSelectionPanelProps {
monomer: BaseMonomer;
selectedAttachmentPoint: string | null;
onSelectAttachmentPoint: (attachmentPoint: string) => void;
commonRescale: number | null;
expanded?: boolean;
rescaleForMonomers: number | null;
}

function AttachmentPointSelectionPanel({
monomer,
selectedAttachmentPoint,
onSelectAttachmentPoint,
expanded = false,
rescaleForMonomers,
commonRescale,
}: AttachmentPointSelectionPanelProps): React.ReactElement {
const [bonds, setBonds] = useState(monomer.attachmentPointsToBonds);
const [connectedAttachmentPoints, setConnectedAttachmentPoints] = useState(
Expand Down Expand Up @@ -264,10 +261,10 @@ function AttachmentPointSelectionPanel({
labelInMonomerConnectionsModal: true,
needCache: false,
autoScaleMargin: 1,
rescaleAmount: rescaleForMonomers,
rescaleAmount: commonRescale,
}}
update={expanded}
monomerConnectionMode={true}
needRescale={true}
isExpanded={expanded}
/>
<AttachmentPointList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const StructRender = ({
options,
className,
update,
monomerConnectionMode,
needRescale,
}: IStructRenderProps) => {
const renderRef = useRef<HTMLDivElement>(null);
useEffect(() => {
Expand All @@ -57,10 +57,10 @@ const StructRender = ({
options,
struct,
update,
monomerConnectionMode,
needRescale,
);
}
}, [struct, options, update]);
}, [struct, options, update, needRescale]);

return <Container ref={renderRef} className={className}></Container>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export interface IStructRenderProps {
options?: (RenderOptions & CasheOptions) | CasheOptions;
className?: string;
update?: boolean;
monomerConnectionMode?: boolean;
needRescale?: boolean;
}

0 comments on commit c31322a

Please sign in to comment.