Skip to content
Open
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
25 changes: 10 additions & 15 deletions examples/HistogramBarChart.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module HistogramBarChart exposing (data, main)

{-| This module shows how to build a simple bar chart.
{-| Examples for the HistogramBar module
-}

import Axis
Expand Down Expand Up @@ -76,6 +76,11 @@ attrs =
]


type alias PreProcessedData =
{ bucket : Float, count : Int }


preProcessedData : List PreProcessedData
preProcessedData =
[ { bucket = 0.8
, count = 10000
Expand Down Expand Up @@ -114,11 +119,7 @@ preProcessedData =
|> List.sortBy .bucket


type alias Data =
Float


data : List Data
data : List Float
data =
[ 0.01
, 0.02
Expand All @@ -140,24 +141,17 @@ data =
, 0.65
, 0.75
, 0.81
, 0.9
, 0.91
, 0.99
]


accessor : data -> data
accessor =
identity


steps : List Float
steps =
[ 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 ]


dataAccessor : Histo.AccessorHistogram Float
dataAccessor =
Histo.dataAccessor steps accessor
Histo.dataAccessor steps identity


histo : Html msg
Expand All @@ -174,6 +168,7 @@ histo =
|> Histo.render ( data, dataAccessor )


preProcessedDataAccessor : Histo.AccessorHistogram PreProcessedData
preProcessedDataAccessor =
Histo.preProcessedDataAccessor
(\d ->
Expand Down
17 changes: 15 additions & 2 deletions src/Chart/HistogramBar.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Chart.HistogramBar exposing
( dataAccessor, preProcessedDataAccessor
( AccessorHistogram, dataAccessor, preProcessedDataAccessor
, init
, render
, Config, RequiredConfig
Expand All @@ -12,10 +12,14 @@ module Chart.HistogramBar exposing

The histogram bar chart can both generate the histogram data automatically or accept preprocessed data.

⚠ This module is still incomplete and does not expose all the flexibility that elm-visialization offers. Histogram generation for now always expects a list of steps in the data accessor and a domain in the config. This will likely change in the future.

⚠ When passing steps one should also explicity pass a domain that matches the steps. This will likely change in the future.


# Data Accessors

@docs dataAccessor, preProcessedDataAccessor
@docs AccessorHistogram, dataAccessor, preProcessedDataAccessor


# Chart Initialization
Expand Down Expand Up @@ -83,6 +87,12 @@ type alias Steps =
List Float


{-| The data accessor for the histogram
-}
type alias AccessorHistogram data =
Type.AccessorHistogram data


{-| The data accessor for generating a histogram.
It takes a config that is separate from the general config,
because it is only used when generating a histogram and not for bucketed pre-processed data.
Expand All @@ -104,9 +114,12 @@ dataAccessor bins acc =
Meaning the data has already been bucketed and counted.
`values` here is not used and always passed as an empty array.

The data must be compatible with the [Bin](https://package.elm-lang.org/packages/gampleman/elm-visualization/latest/Histogram#Bin) data type from elm-visualization.

preProcessedDataAccessor =
Histo.preProcessedDataAccessor
(\d ->
-- This is a Bin data type from elm-visualization
{ x0 = d.bucket
, x1 = d.bucket + 0.1
, values = []
Expand Down