From 5b8256be871e6b3dc70e4288003f1561ae2224a0 Mon Sep 17 00:00:00 2001 From: Tim Orme Date: Sat, 3 Jun 2023 14:35:28 -0700 Subject: [PATCH] Add loading indicators to graphs --- elm/src/Graph.elm | 37 +++++++++++++++++++++++++++++++++++++ elm/src/Main.elm | 10 +++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/elm/src/Graph.elm b/elm/src/Graph.elm index 70e837b..97bf6dc 100644 --- a/elm/src/Graph.elm +++ b/elm/src/Graph.elm @@ -15,6 +15,7 @@ type alias GraphReadModel = { graphData : List GraphReadData , currentHover : List (CI.One GraphReadData CI.Dot) , timeZone : Zone + , isLoading : Bool } @@ -24,6 +25,7 @@ type alias GraphEpaModel = { graphData : List GraphEpaData , currentHover : List (CI.One GraphEpaData CI.Dot) , timeZone : Zone + , isLoading : Bool } @@ -80,6 +82,19 @@ getReadChart graphModel onHover = ] [ CA.fontSize 12 -- Change font size ] + , htmlIf + (C.htmlAt .max + .max + -50 + 0 + [ style "border" "1px solid gray" + , style "padding" "5px" + , style "font-size" "0.75em" + , style "background" "white" + ] + [ text "Loading..." ] + ) + graphModel.isLoading ] @@ -118,6 +133,19 @@ getEpaChart graphModel onHover = ] [ CA.fontSize 12 -- Change font size ] + , htmlIf + (C.htmlAt .max + .max + -50 + 0 + [ style "border" "1px solid gray" + , style "padding" "5px" + , style "font-size" "0.75em" + , style "background" "white" + ] + [ text "Loading..." ] + ) + graphModel.isLoading ] @@ -247,3 +275,12 @@ monthToString month = Dec -> "12" + + +htmlIf : C.Element data msg -> Bool -> C.Element data msg +htmlIf el cond = + if cond then + el + + else + C.none diff --git a/elm/src/Main.elm b/elm/src/Main.elm index ed7977d..f9b08e5 100644 --- a/elm/src/Main.elm +++ b/elm/src/Main.elm @@ -208,14 +208,14 @@ update msg model = -- On Data received case result of Ok data -> - ( { model | allReads = data.reads, allEpas = data.epas, errorData = { hasError = False, errorTitle = "", errorMessage = "" } }, Cmd.none ) + ( { model | allReads = data.reads, allEpas = data.epas, dataLoading = False, errorData = { hasError = False, errorTitle = "", errorMessage = "" } }, Cmd.none ) Err e -> - ( { model | errorData = { hasError = True, errorTitle = "Failed to retrieve read data", errorMessage = errorToString e } }, Cmd.none ) + ( { model | dataLoading = False, errorData = { hasError = True, errorTitle = "Failed to retrieve read data", errorMessage = errorToString e } }, Cmd.none ) FetchData newTime -> -- Data requested - ( { model | currentTime = Just newTime }, getData model.windowDuration ) + ( { model | currentTime = Just newTime, dataLoading = True }, getData model.windowDuration ) GetTimeZone timeZone -> ( { model | timeZone = timeZone }, Cmd.none ) @@ -365,7 +365,7 @@ view model = (Grid.row [ Row.attrs [ style "padding-top" "1em", style "padding-bottom" "3em" ], Row.centerMd ] [ Grid.col [ Col.lg ] [ div [ style "height" "400px" ] - [ G.getEpaChart { graphData = model.allEpas, currentHover = model.hoveringEpas, timeZone = model.timeZone } OnEpaHover ] + [ G.getEpaChart { graphData = model.allEpas, currentHover = model.hoveringEpas, timeZone = model.timeZone, isLoading = model.dataLoading } OnEpaHover ] ] ] ) @@ -374,7 +374,7 @@ view model = (Grid.row [ Row.attrs [ style "padding-top" "1em", style "padding-bottom" "3em" ], Row.centerMd ] [ Grid.col [ Col.lg ] [ div [ style "height" "400px" ] - [ G.getReadChart { graphData = model.allReads, currentHover = model.hoveringReads, timeZone = model.timeZone } OnReadHover ] + [ G.getReadChart { graphData = model.allReads, currentHover = model.hoveringReads, timeZone = model.timeZone, isLoading = model.dataLoading } OnReadHover ] ] ] )