TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Replacing most of D3.js with pure SVG and AngularJS

115 pointsby alexandrosover 11 years ago

10 comments

milrocover 11 years ago
Alexandros,<p>I think you&#x27;re missing a lot of the core concepts around visualisation. d3 aside (for now) you need to consider what visualisation is. Your focus is on charts alone will prevent this from getting any traction. d3 is a framework but it is also in a way, a visualisation kernel. This means that it gives the individual flexibility to create and design interactive information visualisations without being hindered by whatever is enforced by some charting library (only limited by the DOM or whatever scene graph it is working with).<p>d3 can also be viewed as an extension of the concept of &#x27;grammar of graphics&#x27; (for a reference implementation of the grammar of graphics see vega (<a href="http://trifacta.github.io/vega" rel="nofollow">http:&#x2F;&#x2F;trifacta.github.io&#x2F;vega</a>) or ggplot2).<p>If you&#x27;re plan around this is to build a system in which angular handles a lot of the data binding work, I would recommend re-implementing something like vega in angular. Because this would be more compelling than creating yet another charting library that is just built using some combination of d3&#x27;s data manipulation and angular DOM style. nvd3.js, chart.js, yui-chart, etc. all run into this point where the libraries are simple tools for developers to use but do not have the extensibility of a framework like d3 that allows more freedom in the design.<p>Now lets say you create a competitor to vega, the key differentiator would be animation, assuming transitions are trivial as you&#x27;ve explained in this post, I have very minimal experience aside slides and videos in angular to comment. While vega will have: canvas scene graph support, potential to build on top of systems like WebGL, native iOS, or native Android. You will then be tasked to figure out the &#x27;grammar of interactions&#x27; (<a href="https://github.com/trifacta/vega/issues/28" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;trifacta&#x2F;vega&#x2F;issues&#x2F;28</a>) in order to allow attributes to differentiate yourself from vega which is going to be a very hard (but fun!) task.<p>Aside: d3&#x27;s line function isn&#x27;t refreshed as new data is inputed (meaning that you would either have to do this inside of some custom directive (towards the vega style implementation) or do some hack-ish &#x27;tick&#x27; style system (the reason force directed is being updated is due to the fact that it has it&#x27;s own very small physics model which you are leveraging on tick, (also &#x27;ticks&#x27; do not harness angular&#x27;s or d3&#x27;s data binding concept well))).<p>I do think there is space for a true competitor to d3.js that takes a more OOP and stateful approach (what the root of your annoyance with d3 seems to be). While there may be room for this, I also feel (note emotion not backed with fact) like these concepts are also what will build too many limitations that will hinder the project itself. This competitor will likely live within the web components community once it&#x27;s no longer dependent on angular.js, but will likely hit walls (just different walls than the ones you&#x27;re currently frustrated with d3.js) that are going to be hard to get through.<p>I have thought about this stuff in the past (<a href="http://bl.ocks.org/milroc/5519819" rel="nofollow">http:&#x2F;&#x2F;bl.ocks.org&#x2F;milroc&#x2F;5519819</a> <a href="http://youtu.be/Hd2rye9a9kk" rel="nofollow">http:&#x2F;&#x2F;youtu.be&#x2F;Hd2rye9a9kk</a>) and recommended a wrapped directive approach for angular.js (and other MV*) but as I said above the next steps are going to be MUCH more difficult than we expect.<p>Cheers,<p>Miles<p>@milr0c
评论 #6832871 未加载
ricardobeatover 11 years ago
Why would you want to rewrite a stable, complete and extensive visualization framework within your MVC framework? d3 should sit at a lower level, the approach of containing the implementation to a directive looks much sounder.
kayooneover 11 years ago
i love angular but i dont really like the notion of having to reinvent the wheel with it. I read about how one should ditch jquery plugins and rewrite them the &quot;pure angular way&quot; which makes sense for smaller stuff but there are so many very useful jquery plugins that have been around for years with alot of people working on them.<p>D3 is not a jquery plugin but why would i want to rewrite it for use in a specific framework ? When the next framework comes along that rewrite is more or less useless..If Angular is going to be the same standard as jQuery has become this is fine, but with current crop of competitors and the fast moving market i doubt it.
评论 #6829654 未加载
评论 #6830062 未加载
1wheelover 11 years ago
This is interesting, but I&#x27;m not really sure what you get from it.<p>d3 and direct manipulation of SVGs are both so low level that make a decent looking chart requires a bit of boilerplate. That boilerplate should get wrapped inside of a directive and once you&#x27;ve done that, the specifics of how the directive is implemented don&#x27;t matter too much.<p>It would be nice to use one language for data binding; I think angular would end up being a lot more verbose and prevent some of the nice things you can do with .call() and .transition() though. Additionally, I don&#x27;t think &#x27;creating a hole in the DOM&#x27; is necessary a bad thing. Sending graphs only the information that they need separates concerns nicely, resulting in more modular and maintainable code.<p>If you haven&#x27;t read it, <a href="http://bleedingedgepress.com/our-books/developing-a-d3-js-edge/" rel="nofollow">http:&#x2F;&#x2F;bleedingedgepress.com&#x2F;our-books&#x2F;developing-a-d3-js-ed...</a> is pretty good.
评论 #6829100 未加载
jarpinehover 11 years ago
Awesome stuff. I’ve been going through JS libraries looking for better approaches to DOM manipulation. Previous examples of Angular with D3 were hard to use for my needs (though my lack of Angular as well as D3 skills didn’t help). I decided to implement Angular parts by myself (data binding, event bus), since the integration gave me headache with few returns.<p>I saw in twitter that you already got a ping from Rich Harris of Ractive fame. Hopefully you have time to blog about your experience on that front. I really liked working with Ractive, but couldn’t figure out how to combine D3’s functionality with it (like path and axis objects). Your post certainly gave me great pointers. Also, I did not manage to build complex tables with Mustache templates. On that front I hope React from Facebook is even better, but my testing is till ongoing.<p>I’d like to see a library on top of D3 that would use its extensive algorithms without the DOM manipulation. Your approach seems great for Angular use, where I probably shall return also. Still, with Ractive getting visualization going was really easy (not to mention fun) and React promises great performance in addition of strong component structure. D3 however has so much more for visualization at this point (geo module, scales to name a few).
评论 #6829404 未加载
tmcwover 11 years ago
For the opposite: <a href="http://macwright.org/2013/07/07/d3-for-html.html" rel="nofollow">http:&#x2F;&#x2F;macwright.org&#x2F;2013&#x2F;07&#x2F;07&#x2F;d3-for-html.html</a>
coherentponyover 11 years ago
I can&#x27;t seem to play with any of the graphs interactively. Is that intentional? Also, this site completely hi-jacks my &#x27;Back&#x27; button.
评论 #6828504 未加载
almostover 11 years ago
Really cool, I&#x27;m sure there are projects where this would be very helpful (although I don&#x27;t see either of Angular or D3 replacing each other any time soon).<p>The ng-attr-x thing is a neat hack but it&#x27;s a bit unwieldy. How about adding a d3-svg directive that turns itself into an svg element once Angular is done loading. You can hide it with CSS so it doesn&#x27;t flash up random garbage on the screen and within it you can use regular SVG attributes.
beefsackover 11 years ago
I went along the path that using a directive to trigger D3 updates when $scope changes in AngularJS is a much better idea that throwing the baby out with the bathwater. D3 is incredibly powerful for visualisations, and it benefits greatly from simply tying it into the automatic $scope updates in AngularJS.<p><a href="https://github.com/beefsack/angular-d3" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;beefsack&#x2F;angular-d3</a>
dansoover 11 years ago
This is a good detailed guide but I think I&#x27;m missing something here. I can&#x27;t quite formalize it but it has something to do with this:<p>&gt; <i>You may be wondering how we&#x27;ll go about adding Axises to our graph, but here be dragons, so I&#x27;ll leave that aside for the moment.</i><p>Uh, OK...having axes (and labels) is pretty integral to many charts and is pretty trivial in D3. If Angular is to replace much of the data-binding in D3, as the OP proposes, then I think there has to be less ad hoc hacking of Angular things to do what&#x27;s relatively easy in D3. This reads more like a guide of how to get D3 (or rather, SVG charts) in a situation in which you cannot really use D3.
评论 #6828524 未加载
评论 #6828568 未加载