-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba633e6
commit 4405238
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters