mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-21 12:53:11 +01:00
assume minimum for sparklines is always zero
This commit is contained in:
parent
269caabd5e
commit
80d3cb5cd1
1 changed files with 2 additions and 4 deletions
|
@ -38,9 +38,7 @@ defmodule PhilomenaWeb.ProfileView do
|
||||||
|
|
||||||
def sparkline_data(data) do
|
def sparkline_data(data) do
|
||||||
# Normalize range
|
# Normalize range
|
||||||
{min, max} = Enum.min_max(data)
|
max = max(Enum.max(data), 0)
|
||||||
max = max(max, 0)
|
|
||||||
min = max(min, 0)
|
|
||||||
|
|
||||||
content_tag :svg, width: "100%", preserveAspectRatio: "none", viewBox: "0 0 90 20" do
|
content_tag :svg, width: "100%", preserveAspectRatio: "none", viewBox: "0 0 90 20" do
|
||||||
for {val, i} <- Enum.with_index(data) do
|
for {val, i} <- Enum.with_index(data) do
|
||||||
|
@ -48,7 +46,7 @@ defmodule PhilomenaWeb.ProfileView do
|
||||||
calc = max(val, 0)
|
calc = max(val, 0)
|
||||||
|
|
||||||
# Lerp or 0 if not present
|
# Lerp or 0 if not present
|
||||||
height = zero_div((calc - min) * 20, max - min)
|
height = zero_div(calc * 20, max)
|
||||||
|
|
||||||
# In SVG coords, y grows down
|
# In SVG coords, y grows down
|
||||||
y = 20 - height
|
y = 20 - height
|
||||||
|
|
Loading…
Reference in a new issue