Get Started with SmilesDrawer
masterTo draw a SMILES string to a canvas, you need to:
- Include the
smiles-drawerlibrary. - Include the
Droid Sansfont from Google Fonts for consistent rendering. - Initialize a
SmilesDrawer.Drawer(for Canvas) orSmilesDrawer.SvgDrawer(for SVG). - Use
SmilesDrawer.parse()to convert a SMILES string into a parse tree. - Call the
.draw()method on your drawer instance using the parse tree.
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://fonts.googleapis.com/css?family=Droid+Sans:400,700" rel="stylesheet" />
<script src="https://unpkg.com/smiles-drawer@2/dist/smiles-drawer.min.js"></script>
</head>
<body>
<input id="example-input" />
<canvas id="example-canvas" width="500" height="500"></canvas>
<script>
let input = document.getElementById("example-input");
let smilesDrawer = new SmilesDrawer.Drawer({});
input.addEventListener("input", function() {
SmilesDrawer.parse(input.value, function(tree) {
smilesDrawer.draw(tree, "example-canvas", "light", false);
});
});
</script>
</body>
</html>