Pulling DOM of d3 svg ?

47 views
Skip to first unread message

Brad

unread,
Jul 8, 2014, 2:02:04 AM7/8/14
to js...@googlegroups.com
Trying to access the dom of something like http://bl.ocks.org/mbostock/raw/4061502/ or even a static non-moving version like http://bl.ocks.org/mbostock/raw/3883245/, when I get the dom through jsdom there is no svg node element and I can't see any of the information relating to anything on the screen. Is there any way to do this with jsdom, do I need a different approach or just different code? Thanks in advance.


Tried several different approaches outlined in readme of jsdom, this is an example of something I tried.

var jsdom = require("jsdom");

jsdom.env(
  function (errors, window) {
    console.log(window.$("box").length); //outputs 0
    console.log(window.document.getElementsByClassName("box").length);  //also outputs 0
 }
);

Hubert Grzeskowiak

unread,
Oct 6, 2014, 11:20:22 AM10/6/14
to js...@googlegroups.com
Hi Brad,

this answeŕ might come late, but I just worked width similar topics and strumbled upon this. Your example has a few failing points. First you use "box" as jQuery selector, whereas it should be ".box" (note the dot). Other than that I noticed that d3 has problems finding the current document or any of its elements. For my tests I passed d3.select() an element I got from jsdom and only then d3 could work properly. Here's a snippet that might help you get to speed: https://gist.github.com/nemesis13/0a51f8de44602e9b295e

Good luck
Hubert Grzeskowiak
Reply all
Reply to author
Forward
0 new messages