From 80d3cb5cd10a5a9995cb2d74be61df30add8472d Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Sun, 9 May 2021 19:51:17 -0400 Subject: [PATCH] assume minimum for sparklines is always zero --- lib/philomena_web/views/profile_view.ex | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/philomena_web/views/profile_view.ex b/lib/philomena_web/views/profile_view.ex index 682d853e..2a9fe461 100644 --- a/lib/philomena_web/views/profile_view.ex +++ b/lib/philomena_web/views/profile_view.ex @@ -38,9 +38,7 @@ defmodule PhilomenaWeb.ProfileView do def sparkline_data(data) do # Normalize range - {min, max} = Enum.min_max(data) - max = max(max, 0) - min = max(min, 0) + max = max(Enum.max(data), 0) content_tag :svg, width: "100%", preserveAspectRatio: "none", viewBox: "0 0 90 20" do for {val, i} <- Enum.with_index(data) do @@ -48,7 +46,7 @@ defmodule PhilomenaWeb.ProfileView do calc = max(val, 0) # 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 y = 20 - height