diff --git a/examples/HistogramBarChart.elm b/examples/HistogramBarChart.elm index a43dd10..13bf06f 100644 --- a/examples/HistogramBarChart.elm +++ b/examples/HistogramBarChart.elm @@ -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 @@ -76,6 +76,11 @@ attrs = ] +type alias PreProcessedData = + { bucket : Float, count : Int } + + +preProcessedData : List PreProcessedData preProcessedData = [ { bucket = 0.8 , count = 10000 @@ -114,11 +119,7 @@ preProcessedData = |> List.sortBy .bucket -type alias Data = - Float - - -data : List Data +data : List Float data = [ 0.01 , 0.02 @@ -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 @@ -174,6 +168,7 @@ histo = |> Histo.render ( data, dataAccessor ) +preProcessedDataAccessor : Histo.AccessorHistogram PreProcessedData preProcessedDataAccessor = Histo.preProcessedDataAccessor (\d -> diff --git a/src/Chart/HistogramBar.elm b/src/Chart/HistogramBar.elm index a74e8e4..ac053e0 100644 --- a/src/Chart/HistogramBar.elm +++ b/src/Chart/HistogramBar.elm @@ -1,5 +1,5 @@ module Chart.HistogramBar exposing - ( dataAccessor, preProcessedDataAccessor + ( AccessorHistogram, dataAccessor, preProcessedDataAccessor , init , render , Config, RequiredConfig @@ -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 @@ -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. @@ -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 = []