Skip to content

Commit

Permalink
add bare-bones graph (ugly atm)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherKamila committed Mar 13, 2018
1 parent ba633e6 commit 4405238
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions webui/elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"elm-lang/html": "2.0.0 <= v <= 2.0.0",
"elm-lang/http": "1.0.0 <= v <= 1.0.0",
"elm-lang/navigation": "2.1.0 <= v <= 2.1.0",
"juanedi/charty": "2.0.0 <= v < 3.0.0",
"justinmimbs/elm-date-extra": "3.0.0 <= v <= 3.0.0",
"rgrempel/elm-route-url": "4.0.0 <= v <= 4.0.0"
},
Expand Down
37 changes: 37 additions & 0 deletions webui/src/CsvTsdb/Graph.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module CsvTsdb.Graph exposing (..)

import Date
import Time
import List exposing (..)
import List.Extra exposing (..)
import Html exposing (Html)
import Html.Attributes exposing (class)
import Charty.LineChart as LineChart exposing (Dataset)
import Charty.Color

import CsvTsdb.Model exposing (Record)

config = { drawPoints = True
, background = "white"
, colorAssignment = Charty.Color.assignDefaults
, labelPrecision = 0
, drawLabels = True
}

records_to_dataset : List Record -> Dataset
records_to_dataset =
let
grouplabel : List Record -> String
grouplabel = map .label >> head >> Maybe.withDefault "whatever" -- always non-empty
record2datapoint : Record -> LineChart.DataPoint
record2datapoint r = (r.date |> Date.toTime |> Time.inSeconds, r.value)
group2series : List Record -> LineChart.Series
group2series rs = { label = grouplabel rs, data = map record2datapoint rs }
in sortBy .label >> groupWhile (\a b -> a.label == b.label) >> map group2series

view : List Record -> Html m
view = records_to_dataset >>
LineChart.view config >>
List.singleton >>
Html.div [ class "csvtsdb-graph" ]

3 changes: 2 additions & 1 deletion webui/src/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Material.Options as Options exposing (cs, css, div)
import Material.Typography as Typography

import TrackView
import CsvTsdb.Graph

import Model exposing (Model, Msg(..), Tab(..))

Expand Down Expand Up @@ -57,7 +58,7 @@ view_content : Model -> Html Msg
view_content model =
let content = case model.tab of
Track -> TrackView.view model
View -> text "Not Implemented Yet"
View -> CsvTsdb.Graph.view model.data
Explore -> text "Not Implemented Yet"
NotFound -> Options.styled Html.h1
[ cs "mdl-typography--display-4", Typography.center ]
Expand Down

0 comments on commit 4405238

Please sign in to comment.