Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loading indicators to graphs #47

Merged
merged 1 commit into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions elm/src/Graph.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type alias GraphReadModel =
{ graphData : List GraphReadData
, currentHover : List (CI.One GraphReadData CI.Dot)
, timeZone : Zone
, isLoading : Bool
}


Expand All @@ -24,6 +25,7 @@ type alias GraphEpaModel =
{ graphData : List GraphEpaData
, currentHover : List (CI.One GraphEpaData CI.Dot)
, timeZone : Zone
, isLoading : Bool
}


Expand Down Expand Up @@ -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
]


Expand Down Expand Up @@ -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
]


Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions elm/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ]
]
]
)
Expand All @@ -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 ]
]
]
)
Expand Down