I know only a little about D3. You will need to put all the data processing in Elm and just pass the data to the js code that controls D3. This will keep your model reasonable.
You also need to keep track of D3 by mutating the DOM, because Elm will try to refresh the parts of the page for which it is responsible. It would be best to cut the page using elm details and other details using Elm.embed. But you could write Elm the whole page and let D3 mutate the DOM if you use Html.keyed to help Elm keep track of what is in the DOM.
Html.keyed.div "d3node" [ ] [ ... ensure that d3 only touches DOM elements inside this node ... ]
You can pass functions as such through a port, but you can pass json. so you can use elm to create something like
{ function_type: "f1", param1: .... param2: ... }
Then you can do in js
switch (data.function_type) of case "f1: function1 (data.param1, data.param2); ... function1(p1, p2) { // some sort of D3 manipulation var text = g.selectAll(p1) .data(data, p2);
source share