using webgl(2D) to boost d3js performance

3,085 views
Skip to first unread message

Phyo Arkar Lwin

unread,
May 2, 2013, 3:28:08 PM5/2/13
to d3...@googlegroups.com
Hello D3js!

This is my first post here but  we were using D3js for a few months already , and it works wonders.

From what i see d3js mainly support declarative elements to be manipulated (DOM,Canvas and SVG as speciality)
Have anyone tried combining D3js with javascript object-based libraries ?
What i want to do is to use d3js in a combination with pixijs or cocos2d-html (they are 2D frameworks that uses webgl - for performance and they are multiple times faster than Canvas element which d3 supports well)
What do you think people?

What i want to do is 2d-scatterplot using webgl(2d) frameworks and i want functionalities like zoom/pan and rect selection box.
But d3.svg.brush is specifically SVG so i am not sure its going to work on those libraries.

Thanks a lot for d3js! Looking for your reply!


Phyo.

PS: 

here is my stackoverflow question  with bounty :


here are libraries i mentioned:


David Kim

unread,
May 2, 2013, 4:11:54 PM5/2/13
to d3...@googlegroups.com
Hello, 

This is a very interesting question to me too, and would like to know how as well.

(I was looking at three.js (basically, it is for 3D,though) to see if there's a way to visualize 
millions of images for the Viz module of a content-based image retrieval system, and 
planning to play with it & D3 during this summer.)

---

By the way, (your link to the scatter plot matrix example reminds me of this), 
I could draw this with D3js: each dot represents speech - 163 speeches, and 
each cell chart shows the co-relational points between two topics for the speeches - Tp stands for Topic.
And, as you asked, having Zoom-in/-out functionality will be fantastic especially when the data to plot is big.


David



--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Phyo Arkar

unread,
May 2, 2013, 4:24:56 PM5/2/13
to d3...@googlegroups.com

hey david

nice to have someone in same boat. thanks!
yes we had draw one using  d3js for kmeans clusters using that example including zoom and select box but when reaching 20k plots it slows down in frame rate.
so we planning to change rendering from svg to webgl.

Phyo Arkar

unread,
May 2, 2013, 4:27:12 PM5/2/13
to d3...@googlegroups.com

wow that huge amount of data is what you plot in d3js?or non js lib?how much it slows for you?

On May 3, 2013 2:42 AM, "David Kim" <davi...@gmail.com> wrote:

marc fawzi

unread,
May 2, 2013, 4:35:13 PM5/2/13
to d3...@googlegroups.com
Is Vega open source? I can't recall, but I do remember that it comes with an abstraction layer than makes rendering using X technology possible.

Phyo Arkar

unread,
May 2, 2013, 4:39:20 PM5/2/13
to d3...@googlegroups.com

hi mark

what is vega?js lib?

David Kim

unread,
May 2, 2013, 4:39:18 PM5/2/13
to d3...@googlegroups.com
Yep, nice to see you, Phyo.

It takes 3 seconds on Chrome and Safari, but FF can't finish the process. 
Oh, I had one for k-means for a simple document clustering, and with D3, 
I chose a simple force directed graph instead of the standard scatter plot with centroids ~ : D. 


Phyo Arkar

unread,
May 2, 2013, 4:46:41 PM5/2/13
to d3...@googlegroups.com

3secs means both generation and rendering?how many points in total? i must be doing something wrong. with my graph it is only kmeans document clustering of and scatterplot of 20000 points making browser sluggish.

David Kim

unread,
May 2, 2013, 4:55:31 PM5/2/13
to d3...@googlegroups.com
Mine should have 163*20*20 = 65200 dots. 

3 secs doesn't include the k-means process, though. K-means is done by mahout, and the Viz just imports 
the result data after massaging it~

David Kim

unread,
May 2, 2013, 5:01:02 PM5/2/13
to d3...@googlegroups.com
Oh, the scatter plot matrix is not about k-means. The data is about topic modeling, which is 
done by LDA (Latent Dirichlet Allocation).

marc fawzi

unread,
May 2, 2013, 5:20:39 PM5/2/13
to d3...@googlegroups.com
Vega is a product of the same team that brought us D3 ... google for it, it looks great for standard customizable visualizations

Phyo Arkar

unread,
May 2, 2013, 6:19:31 PM5/2/13
to d3...@googlegroups.com

we are slowing at 20k so something is off . it is just 20k * 1

Phyo Arkar

unread,
May 2, 2013, 6:20:14 PM5/2/13
to d3...@googlegroups.com

i found it but only have canvas vs svg right?from looking from description.webgl is faster tho.

Phyo Arkar

unread,
May 2, 2013, 6:21:54 PM5/2/13
to d3...@googlegroups.com

i am doing with sklearn python. but the prob is serverside

Phyo Arkar

unread,
May 2, 2013, 6:22:47 PM5/2/13
to d3...@googlegroups.com

urhg.i meant browser side not server

Ian Johnson

unread,
May 3, 2013, 2:07:14 AM5/3/13
to d3...@googlegroups.com

A lot of the power of d3 is binding to the DOM, which has performance limits for elements in the hundreds or few thousands. You probably want to avoid this part of d3 for these applications, but you can still use many other powerful pieces of d3 to assist you with webgl.

You can use scales to map your data into spatial and color dimensions. This is pure javascript and shouldn't be slow at those numbers.

You could also use the brush component or zoom behavior, simply layer it over the top of your webgl visualization using the same scales.

D3 is like a toolbelt for making data visualizations with web standards, it is at its most elegant when using SVG, just keep in mind you can mix and match the standards and the tools!

Kai Chang

unread,
May 3, 2013, 2:11:27 AM5/3/13
to d3...@googlegroups.com
The brush doesn't depend on the elements being rendered in SVG. Only the brush itself is SVG.

WebGL-2d test with SVG brushes for parallel coordinates: http://bl.ocks.org/syntagmatic/5023284

WebGL-2d and Scatterplot transitions: http://bl.ocks.org/ZJONSSON/raw/3229856/

Phyo Arkar

unread,
May 3, 2013, 1:47:12 PM5/3/13
to d3...@googlegroups.com
Ah thanks alot  that explains me a lot! I am going to check those out and try abit.

Phyo Arkar

unread,
May 3, 2013, 1:56:52 PM5/3/13
to d3...@googlegroups.com
is there any examples with mapping data to spatial and color dimensions? 

Ian Johnson

unread,
May 3, 2013, 2:05:23 PM5/3/13
to d3...@googlegroups.com
almost every svg based d3 example is about mapping data to spatial or color dimensions.
perhaps some of my videos might help here:
color scales:
brush:

(code examples are linked in the descriptions)


Ian Johnson - 周彦

Phyo Arkar

unread,
May 3, 2013, 2:36:35 PM5/3/13
to d3...@googlegroups.com
ah i understand now. the dimensions are called spatial dimensions

Kai Chang

unread,
May 3, 2013, 4:10:03 PM5/3/13
to d3...@googlegroups.com
The difference with canvas is to "map to a color dimension" actually means to change the canvas style state, then do some rendering.

ctx.fillStyle = "red";
// render your red circle here

ctx.fillStyle = "green";
// render your green circle here

So there's quite a bit more imperative code where execution order matters. You also can't use d3's selections and transitions to change the colors of circles-- you'll need to create custom tweens and transitions and render each frame.

Dave Edelhart

unread,
May 4, 2013, 6:17:07 AM5/4/13
to d3...@googlegroups.com, kai.s...@gmail.com
I would suggest that pairing d3 with a higher level canvas manipulator like Easel might be the way to go. 

Canvases don't have a native persistent library of objects, whereas Easel /kinetic does. 

Phyo Arkar

unread,
May 4, 2013, 6:00:04 PM5/4/13
to d3...@googlegroups.com
Hi dave , 
does Easel support webgl?

Phyo Arkar

unread,
May 4, 2013, 6:48:17 PM5/4/13
to d3...@googlegroups.com
I checked Kinectic and Easel , looks quite cool. What i read so far in kinetic , it have full OO support which i am looking for too.
But i am not sure they have Webgl(2D) backend  , which have far superior performance than Canvas.

Stardrive Engineering

unread,
May 4, 2013, 8:13:58 PM5/4/13
to d3...@googlegroups.com
Fabric has support for SVG path plus a robust scenegraph layer on top of the standard canvas and looking at the different canvas libraries it looks like the best option:


The Fabric roadmap todo list also has WebGL as a next target.

The canvas v5 spec has also been out for a while and some of the awesome features should be showing up in browsers soon. The author of Fabric has made following feature test available:


Eventually, hopefully things will speed up. Until then D3 is to slow to run well on mobile platforms!

Thom

Dave Edelhart

unread,
May 4, 2013, 10:29:22 PM5/4/13
to d3...@googlegroups.com
https://github.com/CreateJS/EaselJSRenderers

is the plugin/abstration for webGL -- it looks like they have it but its not actively pursued. 

I used Kinetic for a while. There is ittle practical difference between Kinetic and Easel - you get an abstraction layer in both cases -- but I'd put my money behind Easel as Adobe has a vested interest in maintaining it. 

I think if people expressed a strong interest in that area they might plug it more actively. 

Keep in mind their target audience is Flash refugees who don't have a huge demand on performance -- farms grow slowly :D

Phyo Arkar

unread,
May 5, 2013, 6:36:33 AM5/5/13
to d3...@googlegroups.com
Looks interesting too! Tooo many js Canvas libraries .. would be cool if they join efforts ..

Phyo Arkar

unread,
May 6, 2013, 9:24:40 AM5/6/13
to d3...@googlegroups.com
After a few researches on google i found this , quite interesting performance!


Performance test of Pixijs(WebGL) + D3js! 

Animating 5000 circles goes at 60fps on my laptop!

marc fawzi

unread,
May 7, 2013, 4:34:12 PM5/7/13
to d3...@googlegroups.com
i didn't spot D3 in that example

but Mike (author of D3) has been playing with WebGL per his latest bl.ocks


not to say that the two things are related, but just noting the increasing interest in WebGL overall as the ultimate rendering layer for the web

correct me if I'm wrong but my impression is that mobile implementations remain too slow or non existent

Kai Chang

unread,
May 7, 2013, 5:47:27 PM5/7/13
to d3...@googlegroups.com
GLSL.js is a nice library for getting started with fragment shaders. The intro video assumes no knowledge.


And then Mike's recent examples show you how to combine vertex/fragment shaders without a library.

Phyo Arkar

unread,
May 8, 2013, 11:16:27 AM5/8/13
to d3...@googlegroups.com

yeah sorry it is just comparisons between d3svg vs webgl pixi vs kinetic canvas

Phyo Arkar

unread,
May 15, 2013, 4:27:18 PM5/15/13
to d3...@googlegroups.com

can you give me link of mike's experiment?

Phyo Arkar

unread,
May 15, 2013, 4:32:53 PM5/15/13
to d3...@googlegroups.com

we are testing  with pixijs and threejs
webgl2d with textures implementation of pixi is alot faster than svg but threejs partical system is very fast. we plot 500000 particles without dropping a frame.

karth...@gmail.com

unread,
May 21, 2014, 4:45:26 PM5/21/14
to d3...@googlegroups.com
We are planning to build a high performance visualization using D3 and WebGL - not sure, which type of chart we will use as of yet - parallel coordinates or scatter plot or cluster.
Can you share your code used? We can probably use it as a reference.

Kai Chang

unread,
May 21, 2014, 5:31:18 PM5/21/14
to d3...@googlegroups.com
Here's my experiment with parallel coordinates and WebGL-2d http://bl.ocks.org/syntagmatic/5023284


For more options, visit https://groups.google.com/d/optout.

Message has been deleted

karth...@gmail.com

unread,
May 22, 2014, 10:15:50 AM5/22/14
to d3...@googlegroups.com, kai.s...@gmail.com
Thank you so much!

cheemengs ho

unread,
Sep 8, 2014, 2:34:34 AM9/8/14
to d3...@googlegroups.com, kai.s...@gmail.com
'm trying to use images in d3.js but webgl rendering, following is the code in jsfiddle that shows d3 force layout with simple shapes rendered with webgl. i'm trying to use different images/textures for each of the circles, and i'm lost trying out the shaders/vertexes.

Here is the jsfiddle http://jsfiddle.net/bb4Le5w9/
Message has been deleted

Chris Viau

unread,
Sep 8, 2014, 9:26:38 AM9/8/14
to d3...@googlegroups.com, kai.s...@gmail.com

cheemengs ho

unread,
Sep 8, 2014, 10:39:08 AM9/8/14
to d3...@googlegroups.com, kai.s...@gmail.com
Thanks Chris!!!!

Phuoc Do

unread,
Sep 10, 2014, 1:03:54 AM9/10/14
to d3...@googlegroups.com, kai.s...@gmail.com
Chris included a link to my d3 force layout example (https://vida.io/documents/N4jSip7n68yQ48DXp). I've used d3 with three.js and x3dom. three.js is very fast. Much faster than x3dom and svg. I generated visualizations with 7k elements. You can make rendering faster if you decrease frame rate.

You can adjust lighting and turn off shading to make objects look like 2D. Clicks are a bit harder to handle than svg, but manageable. Bonus points are you get zoom, pan for free. three.js documentation is also good.

cheemengs ho

unread,
Sep 10, 2014, 3:20:41 AM9/10/14
to d3...@googlegroups.com, kai.s...@gmail.com
Hi Phuoc Do,

Nice work on combining three.js with d3,
just wondering if its possible to do http://bl.ocks.org/mbostock/3231298
with three.js ?

cheemengs ho

unread,
Sep 10, 2014, 4:27:59 AM9/10/14
to d3...@googlegroups.com, kai.s...@gmail.com
I've managed to apply the collision detection plus your three.js implementation.
But its very jittery and doesn't follow the mouse too well,
here's the jsfiddle but its not showing online, any way to make it less jitter?
Message has been deleted

cheemengs ho

unread,
Sep 11, 2014, 11:36:06 PM9/11/14
to d3...@googlegroups.com, kai.s...@gmail.com
here's the jsfiddle link
http://jsfiddle.net/Lgtvnhet/3/

Phuoc Do

unread,
Sep 12, 2014, 2:19:57 AM9/12/14
to d3...@googlegroups.com, kai.s...@gmail.com
Hi cheemengs,

The issue is with coordinate transform from 2D mouse.x, mouse.y to 3D coordinate. You'll need something like this:

        var vector = new THREE.Vector3();
        vector.x = ( event.clientX / WIDTH ) * 2 - 1;
        vector.y = - ( event.clientY / HEIGHT ) * 2 + 1;
        vector.z = 0.5;

        var projector = new THREE.Projector();
        projector.unprojectVector( vector, camera );
        
        var dir = vector.sub( camera.position ).normalize();

        var distance = - camera.position.z / dir.z;

        var pos = camera.position.clone().add( dir.multiplyScalar( distance ) );

        // now pos.x, pos.y are 3D coordinates to use in force layout

Also when translate to force layout position, use x and y scales. For example, x(pos.x) and y(pos.y). See this updated fiddle:


Phuoc

cheemengs

unread,
Sep 12, 2014, 2:54:35 AM9/12/14
to d3...@googlegroups.com, kai.s...@gmail.com
Hi Phuoc,

Wow, awesome work, thank you so much :)

This is actually for in-moderation.com, a social awareness we came up with (www.wunderfauks.com)
just our own in-house project.
--
You received this message because you are subscribed to a topic in the Google Groups "d3-js" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/d3-js/bup6gwrymZE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to d3-js+un...@googlegroups.com.

da...@ayasdi.com

unread,
Jan 18, 2015, 8:57:42 PM1/18/15
to d3...@googlegroups.com, kai.s...@gmail.com
At Ayasdi, we faced a similar constraint with D3 for rendering large networks (thousands of nodes and edges). 

We switched to WebGL using Pixi.js and our own API (github.com/ayasdi/grapher).

You can read more about our results and methods here:
http://dcochran.com/home/107616419392

Eric Forgy

unread,
Jan 19, 2015, 8:35:57 PM1/19/15
to d3...@googlegroups.com, kai.s...@gmail.com
Hi Danny,

Thanks for the heads up. As I was learning d3, the presentation by Josh Lewis on how you guys are using d3 and backbone was pretty inspiration for some things I'm working on, so it is a small bummer to hear you moved away from d3 for the viz (although you still use it for transforms). I'll have a look at Grapher, but, so far, I'm not using node.js server side (I went Spring MVC), but I might set up node for use with Julia. I'm having trouble getting Julia, Java, and d3 to play nice together so may set up a Julia server via node and access it from Java using RESTful API.

Cheers,
Eric
Reply all
Reply to author
Forward
0 new messages