Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2043: Thumbnail images are not readable in Template Dialog #2098

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/ketcher-core/src/application/render/raphaelRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ Render.prototype.update = function (force = false, viewSz = null) {
.transform(Scale.obj2scaled, this.options)
.translate(this.options.offset || new Vec2())

if (!this.options.autoScale) {
if (this.options.downScale) {
this.ctab.molecule.rescale()
}

const isAutoScale = this.options.autoScale || this.options.downScale
if (!isAutoScale) {
const ext = Vec2.UNIT.scaled(sf)
const eb = bb.sz().length() > 0 ? bb.extend(ext, ext) : bb
const vb = new Box2Abs(
Expand Down Expand Up @@ -237,7 +242,12 @@ Render.prototype.update = function (force = false, viewSz = null) {
let rescale =
this.options.rescaleAmount ||
Math.max(sz1.x / (csz.x - 2 * marg), sz1.y / (csz.y - 2 * marg))
if (this.options.maxBondLength / rescale > 1.0) rescale = 1.0

const isForceDownscale = this.options.downScale && rescale < 1
const isBondsLengthFit = this.options.maxBondLength / rescale > 1
if (isBondsLengthFit || isForceDownscale) {
rescale = 1
}
const sz2 = sz1.add(mv.scaled(2 * rescale))
/* eslint-disable no-mixed-operators */
this.paper.setViewBox(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface TemplateLibProps {
mode: string
tab: number
saltsAndSolvents: Template[]
renderOptions?: any
}

interface TemplateLibCallProps {
Expand Down Expand Up @@ -283,6 +284,7 @@ const TemplateDialog: FC<Props> = (props) => {
selected={props.selected}
onDelete={props.onDelete}
onAttach={props.onAttach}
renderOptions={props.renderOptions}
/>
</AccordionDetails>
</Accordion>
Expand All @@ -303,6 +305,7 @@ const TemplateDialog: FC<Props> = (props) => {
templates={filteredFG}
onSelect={(templ) => select(templ)}
selected={props.selected}
renderOptions={props.renderOptions}
/>
</div>
) : (
Expand All @@ -319,6 +322,7 @@ const TemplateDialog: FC<Props> = (props) => {
templates={filteredSaltsAndSolvents}
onSelect={(templ) => select(templ)}
selected={props.selected}
renderOptions={props.renderOptions}
/>
</div>
) : (
Expand Down Expand Up @@ -350,6 +354,7 @@ export default connect(
(store) => ({
...omit(['attach'], (store as any).templates),
initialTab: (store as any).modal?.prop?.tab || TemplateTabs.TemplateLibrary,
renderOptions: (store as any).editor?.render?.options,
epam-nikolai-iakushchenko marked this conversation as resolved.
Show resolved Hide resolved
functionalGroups: functionalGroupsSelector(store),
saltsAndSolvents: saltsAndSolventsSelector(store)
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Struct } from 'ketcher-core'
import StructRender from '../../component/structrender'
import classes from './TemplateTable.module.less'
import { greekify } from '../../utils'
import { useSelector } from 'react-redux'
import Icon from 'src/script/ui/component/view/icon'

export interface Template {
Expand All @@ -41,9 +40,9 @@ interface TemplateTableProps {
onDelete?: (tmpl: Template) => void
onAttach?: (tmpl: Template) => void
titleRows?: 1 | 2
renderOptions?: any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to add a type shape for a renderOptions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have one now, I think we can add that as a separate refactor ticket for the future

}

const getSettingsSelector = (state) => state.options.settings
const isSaltOrSolventTemplate = (template) =>
template.props.group === 'Salts and Solvents'
const isFunctionalGroupTemplate = (template) =>
Expand Down Expand Up @@ -71,8 +70,13 @@ const RenderTmpl: FC<{
return (
<StructRender
struct={tmpl.struct}
options={{ ...options, autoScaleMargin: 15 }}
{...props}
options={{
...options,
autoScaleMargin: 10,
cachePrefix: 'templates',
downScale: true
epam-nikolai-iakushchenko marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
)
}
Expand All @@ -84,9 +88,9 @@ const TemplateTable: FC<TemplateTableProps> = (props) => {
onSelect,
onDelete,
onAttach,
titleRows = 2
titleRows = 2,
renderOptions
} = props
const options = useSelector((state) => getSettingsSelector(state))

return (
<div
Expand All @@ -112,7 +116,7 @@ const TemplateTable: FC<TemplateTableProps> = (props) => {
>
<RenderTmpl
tmpl={tmpl}
options={options}
options={renderOptions}
className={classes.struct}
/>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ const prerenderPartOfStructures = (saltsAndSolvents: Struct[], settings) => {
div.style.height = '100px'
div.style.display = 'none'
document.body.appendChild(div)
RenderStruct.render(div, struct, { ...settings, autoScaleMargin: 15 })
RenderStruct.render(div, struct, {
...settings,
autoScaleMargin: 10,
cachePrefix: 'saltsAndSolvents',
downScale: true
})
div.remove()
})
}
Expand Down