question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recreating D3 example failed

See original GitHub issue

🐛 Bug

I tried to recreate an example for this D3 network graph in PyScript (minimal example here) then came across this error:

Uncaught TypeError: jsargs is not iterable (cannot read property undefined)
    at Proxy.apply (pyproxy.gen.ts:1145:19)
    at Dispatch.call (d3-dispatch.js:58:18)
    at step (d3-force.js:228:13)
    at timerFlush (d3-timer.js:49:15)
    at wake (d3-timer.js:58:5)

To Reproduce

See https://github.com/Cheukting/Cheukting.github.io/blob/master/assets/html/min-network-d3.html

Expected behavior

See https://d3-graph-gallery.com/graph/network_basic.html

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rthcommented, Sep 15, 2022

Thanks for investigating @leriomaggio and @hoodmane for fixing it in #3101!

1reaction
leriomaggiocommented, Sep 14, 2022

Ok so I played with it a little bit and here is what I found.

  1. Re error: the error message is indeed a bit different but the essence is the same.

Expanding a bit about this (with the help of Browser inspector) in d3-dispatch.js (around lines 51-59)

51 call: function(type, that) {
         [...]
57     for (t = this._[type], i = 0, n = t.length; i < n; ++i)
58         t[i].value.apply(that, args);
59  },

L58 gets evaluated because this (the Dispatch) looks like:

this:  Dispatch
    _: 
        end: Array(1)
            0: {name: '', value: Proxy}
            length: 1

args will later be the jargs in question for PyProxy that is indeed undefined as none of the previous lines in call (from d3-dispatch.js) where evaluated.

Therefore, from the Pyodide side, these situations could be potentially accounted for by checking whether jargs is undefined or not and so call the PyObject accordingly.

I don’t know whether that makes any sense, tbh (disclaimer 😅 ), but I think the issue here is perhaps a bit more philosophical (re specific example, see below)

  1. As for the specific example: I sensed the error could’ve been related to Proxy conversion - that is perhaps not the right thing to do here.

TLDR; I replaced create_proxy with create_once_callable for the ticked PyFunction and it works! This function is meant to be called once (on("end"..) in fact) Therefore I thought that a quick to consume PyProxy object is what was more appropriate… and it worked 🎉

More specifically on the issue: I looked carefully at what happens on the call stack when it generates the error.

  • With Porxy, d3-dispatch evaluates immediately pyproxy-gen-ts (L1145) that raises the exception as the object in this is a Proxy (not being available yet from the promise? 🤔 )

  • With Once Callable, this contains directly the wrapper function ready to be invoked by pyodide-asm (L14) which is indeed already the callable we need there 😃

I hope this helps in shading some light on the issue at hand?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recreate D3 Multi-Line Chart on Resize (responsive)
1 Answer 1 · Parse the data, append svg with initial height and width, append X, Y axes just once but move drawBars...
Read more >
D3 chunk fails where D3 js file succeeds when `split ... - GitHub
The D3 file is rendered correctly without an error. Since D3 handles the data correctly, r2d3 in a an R Markdown's d3 chunk...
Read more >
D3.js Tutorial – Data Visualization for Beginners
In this article, I'm going to walk you through how to use D3.js in a step by step and beginner-friendly way. We'll talk...
Read more >
Introduction to D3, Part 1 / UW Interactive Data Lab - Observable
In this notebook, we will gain familiarity with one of the most widely used visualization grammars: D3.js. Let's start by importing the D3...
Read more >
The Big List of D3.js Examples - Christophe Viau
... A KoExtensions example: #d3js KnockoutJS, RavenDB, WebAPI, Bootstrap · A line chart plotting unit sales, colored by price for d3 data visualisations ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found