mirror of
https://github.com/plausible/analytics.git
synced 2024-12-27 11:33:31 +03:00
ead4a7d560
* Optimize Dockerfile * Update selfhosting documentation * Remove unnecessary files * Remove internal config stuff * Update config * WIP * Use BASE_URL instead of HOST and SCHEME * Add port to endpoint url config * Make config/config.exs on par with config/releases.exs * Add changelog entry * Document configuration change
58 lines
1.1 KiB
Elixir
58 lines
1.1 KiB
Elixir
defmodule PlausibleWeb.StatsView do
|
|
use PlausibleWeb, :view
|
|
|
|
def admin_email do
|
|
Application.get_env(:plausible, :admin_email)
|
|
end
|
|
|
|
def base_domain do
|
|
PlausibleWeb.Endpoint.host()
|
|
end
|
|
|
|
def plausible_url do
|
|
PlausibleWeb.Endpoint.url()
|
|
end
|
|
|
|
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="bg-<%= color %>-100" style="width: <%= bar_width(count, all) %>%; height: 30px"></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
|