reymond-group / smilesDrawer

A small, highly performant JavaScript component for parsing and drawing SMILES strings. Released under the MIT license.
https://smilesdrawer.rocks
MIT License
416 stars 66 forks source link

Pass default value `weights = null` to `SvgDrawer.draw()` #175

Open panda-byte opened 1 year ago

panda-byte commented 1 year ago

Resolves #171. Although the weights parameter was added to SvgDrawer.draw() in f3693b3, the method call in Drawer.draw() wasn't updated correspondingly. Drawer.draw() could be amended to also take a weights argument, which it would pass to SvgDrawer.draw(), but this might break existing code even more and would require an update of the documentation of the README.

Example to reproduce:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="dist/smiles-drawer.js"></script>
</head>
<body>
<canvas id="canvas" style="width: 200px; height: 200px; background-color: lightgrey"></canvas>

<script>
    SmilesDrawer.parse(
        "CCCNC",
        tree => {
            (new SmilesDrawer.Drawer()).draw(tree, 'canvas');
        },
        alert
    );
</script>
</body>
</html>

Before the proposed change, this gives an error (TypeError: this.svgWrapper is null). With the proposed change, the error is resolved and the structure is displayed correctly.

netlify[bot] commented 1 year ago

Deploy Preview for smilesdrawer-doc canceled.

Name Link
Latest commit 2c5d7abf02e8af167738945b068dcdfd0ba0f4cd
Latest deploy log https://app.netlify.com/sites/smilesdrawer-doc/deploys/648b7fc33f4a60000840defc
njzjz commented 8 months ago

It should also fix #161