-
Notifications
You must be signed in to change notification settings - Fork 71
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
Bug: PNG drawer does work in version 2.1.7 as a React component #167
Comments
Thanks for writing this out - I've been so confused. |
const source = 'CC(=O)Nc1ccccc1C(=O)O'
const targetImg = container.createEl('img') as HTMLImageElement // container is a HTMLDivElement, decleared previously
const theme = 'dark'
let drawer = new SmilesDrawer.SmiDrawer();
drawer.draw(source, targetImg, theme) These lines are able to generate a PNG file in v2.1.7. |
If that is the case, the documentation really needs to be updated to reflect that a canvas element no longer works |
Here's a React example that yields png const imgRef = useRef<HTMLImageElement>(null);
const drawer = new SmilesDrawer.SmiDrawer(options); // options is a param
useEffect(() => {
drawer.draw(smilesStr, imgRef.current, 'light');
});
return (
<div>
<img ref={imgRef} width={300}></img>
</div>
); |
2.1.7 smiles-drawer still works with canvas. Example: codesandbox link look at the files SmilesDrawer.tsx and App.js |
I am using React in Next.js.
I created a React component to render a chemical structure and I found when using
SmilesDrawer.Drawer
, the canvas is not updated and no structure is drawn. UsingSmilesDrawer.SvgDrawer
does work. After a bit of experimentation I found this appears to be a bug with version 2.1.7. Rolling back to earlier 2.1.x versions resulted in an import error. Rolling back to version 2.0.3 theSmilesDrawer.Drawer
class does work.Also, it would be very helpful if the documentation showed how to use
smiles-drawer
with React as it is not immediately obvious.Summary of issues:
SmilesDrawer.Drawer
does not render PNG image in version 2.1.7.SmilesDrawer.SvgDrawer
works correctly in 2.1.7.SyntaxError: Cannot use import statement outside a module
when importing.SmilesDrawer.Drawer
works correctly in version 2.0.3.Example code
This code is for a component to render a structure either as PNG or SVG.
The text was updated successfully, but these errors were encountered: