Rich_Morin

Rich_Morin

Using D3.js with Phoenix LiveView?

In D3.js and Phoenix (2019), @peerreynders provided a way to link up the JS library to Phoenix. I’m wondering whether the state of the art may have progressed since then.

Looking on hex.pm, I don’t see anything listed for ds, ds.js, or dsjs. So, I’ve been speculating on what the interface should be. (ducks)

JS embedding

Although the idea of LiveView is to avoid the hassles and perils of JS, one possible approach would be to accept the JS notation and embed it in the client-side code. For example, it seems like phx-hook could work for this, eg:

<div phx-hook="my-javascript-hook">
  select('.chart').selectAll('div')...
</div>

This approach is simple and direct, so it should be relatively easy to create and maintain. There is also the advantage that D3 code can be used “as-is”, easing the programming burden.

Pipeline Magic

Alternatively, one might might wish for a way to write Elixir pipelines and have them turn into JS dot notation, eg:

foo |> select(".chart") |> selectAll("div") |> ...

I assume that this could be managed using macros and related magic. However, I’m not convinced that it brings much value to the party. For example, is it likely that there are Elixir-side things that one might want to add to a pipeline, etc? Dunno…

Anyway, I thought I’d toss this topic back out for discussion…

-r

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement