Hacker News new | ask | show | jobs
by jarpineh 4577 days ago
I have been reading Grammar of Graphics, but it’s a slow going. I don’t yet see where the connection is with D3 and the Grammar, though (probably since I lack knowledge of the Grammar and don’t yet grasp the whole of D3). D3 works best with SVG constructs, where elements and attributes are manipulated based on what functions return. These functions then react to data, but D3 doesn’t really know what is in the data. It merely binds it to element’s __data__ attribute implicitly so it can know what to change when node gets selected. It’s the developer’s job to choose the right elements and attributes where results should be placed. Resulting graphic is an SVG document, which can look as a cohesive graph if developer gets the parameters right. This structure is often hard coded into script and not done with specific grammar that could calculate the graphic parameters consistently and reliably. This might be since D3 is intentionally low-level, but then there are parts that try to do more abstract things (like axes, that generate SVG directly). I feel this contributes to the lack of reusability.

Popularity of frameworks like Angular and the recent appearance of Ractive and React, as well as Fastdom (not to mention ClojureScript) suggests to me, that easy, efficient and reusable DOM manipulation is a hard problem and there can be many solutions. Its because of this I’d like to keep using D3’s great functionality (for me the scales and geo module) without its use of selections and W3C DOM API. There are other ways to declare a graphic and bind it to data, but calculating points for lines should not be coupled to a particular style of DOM manipulation. I like D3 a lot for discrete visualizations, but creating many interdependent graphics (like map and bar chart from the same data with interactivity between them) is not as easy as with, say, Ractive.

What I understand of Vega is that it works as a kind of grammar for graphics, but one that completely encapsulates the DOM manipulation. This allows it to support other render target, like canvas. I feel that this is opposite of what Alexandros is suggesting, that is to use D3 where it is good, but not parts which clash with Angular’s view of the DOM. If Vega makes it easier to use its functionality without the renderer, that would be great, but I don’t know how well it supports D3’s great functionality. This is on my study list, though.