Skip to content
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

Importing d3.js to vscode #16034

Closed
1 of 2 tasks
Marchlak opened this issue Sep 12, 2024 · 1 comment
Closed
1 of 2 tasks

Importing d3.js to vscode #16034

Marchlak opened this issue Sep 12, 2024 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@Marchlak
Copy link

Applies To

  • Notebooks (.ipynb files)
  • Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

So i start my issue with this simple example:
image
As we can see, importing the D3 library failed. At first, I thought it was due to the way it was imported like this: <script src="https://d3js.org/d3.v7.min.js"></script>. However, when I used IPython to add the entire library, D3 was still 'not defined'. So, I opened the D3 code, which starts like this:

// https://d3js.org v7.9.0 Copyright 2010-2023 Mike Bostock
! function(t, n) {
    "object" == typeof exports && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n((t = "undefined" != typeof globalThis ? globalThis : t || self).d3 = t.d3 || {})
}(this, (function(t) {

In VS Code, define === "function" && define.amd is triggered, but it's not possible to assign the global variable d3, which remains 'not defined'. Is there any way to load D3 into VS Code? My visualizations with IPython and D3 work perfectly in Jupyter Notebook, Jupyter Lab in the browser, and other notebooks built on Electron. There must be a way, because while playing with the developer console, my visualization displayed once, but I couldn't replicate it.

VS Code Version

1.93.0

Jupyter Extension Version

v2024.8.1

Jupyter logs

No response

Coding Language and Runtime Version

Python, js

Language Extension Version (if applicable)

No response

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Local

@Marchlak Marchlak added the bug Issue identified by VS Code Team member as probable bug label Sep 12, 2024
@Marchlak
Copy link
Author

Marchlak commented Sep 16, 2024

Okay, I solved it myself if you want use d3 in vscode jupyter using ipython change this

! function(t, n) {
    "object" == typeof exports && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n((t = "undefined" != typeof globalThis ? globalThis : t || self).d3 = t.d3 || {})
}(this, (function(t) {
    "use strict";

to this

!function(t, n) {
    n((t = "undefined" != typeof globalThis ? globalThis : t || self).d3 = t.d3 || {})
}(this, (function(t) {
    "use strict";

to see full solution check https://github.com/mljar/supertree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants