smilesDrawer icon indicating copy to clipboard operation
smilesDrawer copied to clipboard

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

Open panda-byte opened this issue 1 year ago • 2 comments

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.

panda-byte avatar Jun 15 '23 21:06 panda-byte

Deploy Preview for smilesdrawer-doc canceled.

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

netlify[bot] avatar Jun 15 '23 21:06 netlify[bot]

It should also fix #161

njzjz avatar Oct 25 '23 20:10 njzjz