Quetzal

Quetzal - Analytical web apps, beautiful, fast and easy using Elixir. No Javascript required.

Hex.pm

Quetzal provides easy and fast tools to make analytical web apps with real-time updates.

Quetzal provides the next features:

Example

First, define a module and use Quetzal.LiveView, you don't need mount/2 or render/1, when using the Quetzal Live View all is done:

defmodule AppWeb.PieLive do
  use Quetzal.LiveView
end

With this minimal configuration Quetzal is able to render any component into the view, let's generate a pie graph to render:

defmodule AppWeb.PieLive do
  use Quetzal.LiveView

  @impl Quetzal.LiveView
  def components() do
    Quetzal.Graph.pie [id: "my-pie-graph"], [labels: ["RED", "BLUE"], values: [1, 2]]
  end
end

The callback returns a new graph component and put into the view the necessary items to work with it.

Now, we are going to the real-time cases, let's say we want update our pie graph when an event occurs in the server, so let's define a trigger to make it:

defmodule AppWeb.PieLive
  use Quetzal.LiveView

  @impl Quetzal.LiveView
  def components() do
    Quetzal.Graph.pie [id: "my-pie-graph"], [labels: ["RED", "BLUE"], values: [1, 2]]
  end

  def trigger_update() do
    :timer.sleep(5000)
    r = :rand.uniform(100)
    b = :rand.uniform(100)
    component = Quetzal.Graph.pie [id: "TEST"], [labels: ["RED", "BLUE"], values: [r, b]]
    update_components(component)
    trigger_update()
  end
end

Let's explain the code, first to all, the trigger_update/0 can be called from iex:

iex(1)> AppWeb.PieLive.trigger_update

Then every 5 ms a random numbers will be generated and put into values of the pie graph, and the pie graph will be updated, nice eh?.

To achieve this, Quetzal uses the update_components/1 function to render the new content, also you need configure the javascript hooks, only pass the hooks into the live socket connection:

...
import Quetzal from "quetzal_hooks"
let quetzal = new Quetzal();
...
let liveSocket = new LiveSocket("/live", Socket, {hooks: quetzal.Hooks})  

With this minimal configuration, we able to make a real-time app that updates the graph from the live view server.

Some notes that you should be take:

That's all, we are working to add more examples of components, inputs etc. Enjoy!.

Authors

@zgbjgg Jorge Garrido zgbjgg@gmail.com