From 2c26f72d50871539be274a87d6363479b6723b2d Mon Sep 17 00:00:00 2001 From: wass3rw3rk <49894298+wass3rw3rk@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:37:57 -0600 Subject: [PATCH] address PR feedback --- src/elm/Components/BarChart.elm | 20 ++++++++++---------- src/elm/Pages/Org_/Repo_/Insights.elm | 2 +- src/elm/Utils/Helpers.elm | 12 ++++++++++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/elm/Components/BarChart.elm b/src/elm/Components/BarChart.elm index 254b34896..45f76044b 100644 --- a/src/elm/Components/BarChart.elm +++ b/src/elm/Components/BarChart.elm @@ -92,7 +92,7 @@ type BarChartConfig } -{-| newBarChart: creates a new BarChart configuration with default values. +{-| newBarChartConfig : creates a new BarChart configuration with default values. -} newBarChartConfig : BarChartConfig newBarChartConfig = @@ -107,56 +107,56 @@ newBarChartConfig = } -{-| withWidth: override the width of the chart (in pixels). +{-| withWidth : override the width of the chart (in pixels). -} withWidth : Float -> BarChartConfig -> BarChartConfig withWidth v (BarChartConfig config) = BarChartConfig { config | width = v } -{-| withHeight: override the height of the chart (in pixels). +{-| withHeight : override the height of the chart (in pixels). -} withHeight : Float -> BarChartConfig -> BarChartConfig withHeight v (BarChartConfig config) = BarChartConfig { config | height = v } -{-| withPadding: override the padding of the chart (in pixels). +{-| withPadding : override the padding of the chart (in pixels). -} withPadding : Float -> BarChartConfig -> BarChartConfig withPadding v (BarChartConfig config) = BarChartConfig { config | padding = v } -{-| withTitle: override the title of the chart. +{-| withTitle : override the title of the chart. -} withTitle : String -> BarChartConfig -> BarChartConfig withTitle v (BarChartConfig config) = BarChartConfig { config | title = v } -{-| withTitle: set the data for the chart. +{-| withData : set the data for the chart. -} withData : List ( Time.Posix, Float ) -> BarChartConfig -> BarChartConfig withData v (BarChartConfig config) = BarChartConfig { config | data = v } -{-| withTitle: override the max y-axis value (default value is inferred based on dataset). +{-| withMaxY : override the max y-axis value (default value is inferred based on dataset). -} withMaxY : Float -> BarChartConfig -> BarChartConfig withMaxY v (BarChartConfig config) = BarChartConfig { config | maybeMaxY = Just v } -{-| withPercentUnit: override unit for the values in the dataset to be percentages (default is time values). +{-| withPercentUnit : override unit for the values in the dataset to be percentages (default is time values). -} withPercentUnit : BarChartConfig -> BarChartConfig withPercentUnit (BarChartConfig config) = BarChartConfig { config | unit = percent } -{-| withNumberUnit: override unit for the values in the dataset to be plain number format +{-| withNumberUnit : override unit for the values in the dataset to be plain number format with the given decimal places. -} withNumberUnit : Int -> BarChartConfig -> BarChartConfig @@ -168,7 +168,7 @@ withNumberUnit v (BarChartConfig config) = -- VIEW -{-| view: takes title, width (optional), height (optional), data, optional maximum y-axis value, +{-| view : takes title, width (optional), height (optional), data, optional maximum y-axis value, unit as string, and returns a chart. -} view : BarChartConfig -> Html msg diff --git a/src/elm/Pages/Org_/Repo_/Insights.elm b/src/elm/Pages/Org_/Repo_/Insights.elm index 2b6b08e69..af658fa40 100644 --- a/src/elm/Pages/Org_/Repo_/Insights.elm +++ b/src/elm/Pages/Org_/Repo_/Insights.elm @@ -85,7 +85,7 @@ init shared route () = Time.posixToMillis shared.time // 1000 sevenDaysInSeconds = - 7 * 24 * 60 * 60 + 7 * Helpers.oneDaySeconds timeMinusSevenDaysInSeconds : Int timeMinusSevenDaysInSeconds = diff --git a/src/elm/Utils/Helpers.elm b/src/elm/Utils/Helpers.elm index 6ae9b0436..cb5db125a 100644 --- a/src/elm/Utils/Helpers.elm +++ b/src/elm/Utils/Helpers.elm @@ -219,14 +219,22 @@ noSomeSecondsAgo _ = "just now" +{-| formatTimeFromFloat : takes a float (seconds) and passes it to formatTime +for a string representation. the value is floored since we don't measure +at sub-second accuraacy. +-} formatTimeFromFloat : Float -> String formatTimeFromFloat number = number |> floor - |> max 0 |> formatTime +{-| formatTime : takes an int (seconds) and converts it to a string representation. + +example: 4000 -> 1h 6m 40s + +-} formatTime : Int -> String formatTime totalSeconds = let @@ -256,7 +264,7 @@ formatTime totalSeconds = else "" in - if totalSeconds == 0 then + if totalSeconds < 1 then "0s" else