analytics/lib/plausible_web/views/stats_view.ex
Uku Taht e8f20e67cc
React (#17)
* Load dashboard with react

* Rename stast2 to dashboard

* Save timeframe on the frontend

* Implement current visitors

* Implement comparisons

* React to route changes

* Add modals

* Show number of visitors on hover

* Show 'Today' for today

* Add 30 days

* Show referrer drilldown

* Arrow keys to go back and forward

* Improve comparisons UI

* Fix dropdown when clicking on it

* Verify API access in a memoized fashion

* Test API access

* Test stats through controller

* Move map formatting from stats controller to stats

* Remove unused code

* Remove dead code from query

* Remove dead code from stats templates

* Add stats view test back in

* Render modal inside the modal component

* Implement google search terms

* Add explanation for screen sizes

* Separate dashboard JS from the app js
2019-11-19 12:30:42 +08:00

42 lines
961 B
Elixir

defmodule PlausibleWeb.StatsView do
use PlausibleWeb, :view
def large_number_format(n) do
cond do
n >= 1_000 && n < 1_000_000 ->
thousands = trunc(n / 100) / 10
if thousands == trunc(thousands) || n >= 100_000 do
"#{trunc(thousands)}k"
else
"#{thousands}k"
end
n >= 1_000_000 && n < 100_000_000 ->
millions = trunc(n / 100_000) / 10
if millions == trunc(millions) do
"#{trunc(millions)}m"
else
"#{millions}m"
end
true ->
Integer.to_string(n)
end
end
def bar(count, all, color \\ :blue) do
~E"""
<div class="bar">
<div class="bar__fill bg-<%= color %>" style="width: <%= bar_width(count, all) %>%;"></div>
</div>
"""
end
defp bar_width(count, all) do
max = Enum.max_by(all, fn
{_, count} -> count
{_, count, _} -> count
end) |> elem(1)
count / max * 100
end
end