Stability | experimental |
---|---|
Maintainer | Sebastian Fischer <mailto:sebf@informatik.uni-kiel.de> |
This library provides functions and data type for generating bar charts, for example, from CSV files. If the functionality provided by the command-line program is insufficient for your needs, you can use the API provided by this library to draw custom bar charts.
The library provides high-level functions to generate bar-chart values from different types but also exports the underlying datatype and all functions used for rendering such that you have access to all internal details.
- writeMultiBarChart :: Config -> FilePath -> [Label] -> IO ()
- writeIntervalChart :: Config -> FilePath -> IO ()
- writeMultiBarIntervalChart :: Config -> FilePath -> [Label] -> IO ()
- data Config = Config {}
- type Label = String
- multiBarChart :: (Measurable a, Read a) => [Label] -> CSV -> BarChart a
- intervalChart :: (Measurable a, Read a) => CSV -> BarChart a
- multiBarIntervalChart :: (Measurable a, Read a) => [Label] -> CSV -> BarChart a
- class Num a => Measurable a where
- data MultiBars a = MultiBars [Label] [(Label, [a])]
- parseMultiBars :: Read a => [Label] -> CSV -> MultiBars a
- drawMultiBars :: Measurable a => MultiBars a -> BarChart a
- newtype Intervals a = Intervals [(Label, (a, a, a))]
- parseIntervals :: Read a => CSV -> Intervals a
- drawIntervals :: Measurable a => Intervals a -> BarChart a
- data MultiBarIntervals a = MBIntervals [Label] [(Label, [(a, a, a)])]
- parseMultiBarIntervals :: Read a => [Label] -> CSV -> MultiBarIntervals a
- drawMultiBarIntervals :: Measurable a => MultiBarIntervals a -> BarChart a
- mergeIntervals :: Num a => [(Label, Intervals a)] -> MultiBarIntervals a
- flipMultiBarIntervals :: MultiBarIntervals a -> MultiBarIntervals a
- data BarChart a = BarChart {
- block_labels :: [Label]
- bars :: [Bar a]
- data Bar a = Bar {}
- data Block a
- render :: Measurable a => BarChart a -> IO ()
- renderWith :: Measurable a => Config -> BarChart a -> IO ()
- conf :: Config
- diagram :: Measurable a => Config -> BarChart a -> Diagram
- writeCriterionChart :: Config -> FilePath -> IO ()
- writeComparisonChart :: Bool -> Config -> [FilePath] -> IO ()
- criterionChart :: CSV -> BarChart RunTime
- comparisonChart :: Bool -> [(Label, CSV)] -> BarChart RunTime
- newtype RunTime = RunTime Double
- writeProgressionChart :: Bool -> Config -> FilePath -> [Label] -> IO ()
- progressionChart :: Bool -> [Label] -> CSV -> BarChart Ratio
- newtype Ratio = Ratio Double
Reading from CSV files
There are three different modes for parsing simple CSV files: treating different values in one row as blocks of one bar, treating them as deviations from a mean value, or both.
Writing images
The following three functions implement these modes parsing the input from a CSV file and producing output in an image file.
:: Config | where and how to draw the bar chart |
-> FilePath | CSV file to read |
-> [Label] | if non-empty, used as legend for blocks |
-> IO () |
The first column of the CSV file is parsed as names of the bars. The height of each bar corresponds to the sum of all subsequent entries. If there is more than one entry, the bars are split into blocks.
The first column of the CSV file is parsed as names of the bars. Three entries following each bar name are parsed as mean, minimum, and maximum value and depicted using an interval next to the bar.
writeMultiBarIntervalChartSource
:: Config | where and how to draw the bar chart |
-> FilePath | CSV file to read |
-> [Label] | legend for blocks |
-> IO () |
The first column of the CSV file is parsed as names of the bars. The entries following each bar name are parsed as triples of mean, minimum, and maximum value and depicted using an interval next to the bar. The number of subsequent entries must be a multiple of three and each bar is divided into a corresponding number of blocks.
Specifies how bar charts are rendered
Config | |
|
Creating bar charts
The previous functions use the following helper functions to
create a BarChart
from a CSV file.
:: (Measurable a, Read a) | |
=> [Label] | legend for blocks |
-> CSV | comma separated values to depict |
-> BarChart a |
Used by writeMultiBarChart
to create a BarChart
from a CSV file.
:: (Measurable a, Read a) | |
=> CSV | comma separated values to depict |
-> BarChart a |
Used by writeIntervalChart
to create a BarChart
from a CSV file.
:: (Measurable a, Read a) | |
=> [Label] | legend for blocks |
-> CSV | comma separated values to depict |
-> BarChart a |
Used by writeMultiBarIntervalChart
to create a BarChart
from
| a CSV file.
class Num a => Measurable a whereSource
Instances of this class can be depicted in bar charts.
Bar chart representations
The three different parsing modes are reflected by three data types that can be parsed from a CSV file.
Values of this type are drawn as charts where each bar may consist of multiple blocks.
parseMultiBars :: Read a => [Label] -> CSV -> MultiBars aSource
Converts a CSV file to be drawn as a chart where each bar may consist of multiple blocks.
drawMultiBars :: Measurable a => MultiBars a -> BarChart aSource
Converts bars with multiple blocks into their BarChart
representation.
Values of this type are drawn as charts where each bar has an associated deviation depicted as an interval next to the bar.
parseIntervals :: Read a => CSV -> Intervals aSource
Converts a CSV file to be drawn as a chart where each bar has an attached deviation depicted as an interval next to the bar.
drawIntervals :: Measurable a => Intervals a -> BarChart aSource
Converts bars with associated deviation into their BarChart
representation.
data MultiBarIntervals a Source
Values of this type are drawn as charts where each bar may be divided into multiple blocks with an associated deviation depicted as intervals next to them.
MBIntervals [Label] [(Label, [(a, a, a)])] |
Show a => Show (MultiBarIntervals a) |
parseMultiBarIntervals :: Read a => [Label] -> CSV -> MultiBarIntervals aSource
Converts a CSV file to be drawn as a chart where each bar may consist of multiple blocks which have an attached deviation depicted as an interval next to them.
drawMultiBarIntervals :: Measurable a => MultiBarIntervals a -> BarChart aSource
Converts bars with multiple blocks and associated deviations into
their BarChart
representation.
When you have multiple CSV files representing an interval chart, you can merge them to a single multi-bar interval chart. Such charts can be flipped such that bars and blocks change their roles.
mergeIntervals :: Num a => [(Label, Intervals a)] -> MultiBarIntervals aSource
Merges several interval charts into a chart where each bar has multiple blocks that represent the different interval charts.
flipMultiBarIntervals :: MultiBarIntervals a -> MultiBarIntervals aSource
Swaps bars and blocks of a chart that contains both and associated deviations.
Bar charts are represented as values of type BarChart
a
.
Bar charts consist of a (possibly empty) list of labels for the diferent blcks of bars and the bars themselves.
BarChart | |
|
Represents one bar of a bar chart.
Bocks either have a single associated value or a mean value along with minimum and maximum deviation.
Rendering
Values of type BarChart
a
can be rendered to PNG, SVG, PDF,
and PS files.
render :: Measurable a => BarChart a -> IO ()Source
Renders a bar chart as barchart.png
according to the default
configuration conf
.
renderWith :: Measurable a => Config -> BarChart a -> IO ()Source
Renders a bar chart according to a custom configuration.
The default configuration generates a PNG file with a chart of size 600x300 pixels. The output file is left unspecified and you should provide one if you use a cstom configuration.
Creating diagrams
Bar charts are rendered by conversion into Diagram
s.
diagram :: Measurable a => Config -> BarChart a -> DiagramSource
This function can be used to embed bar charts into bigger
Diagram
s.
Benchmarking visualisation
There are special functions for parsing data generated by the benchmarking tools criterion and progression.
Criterion
writeCriterionChart :: Config -> FilePath -> IO ()Source
Reads a summary file generated by criterion and writes a corresponding bar chart.
writeComparisonChart :: Bool -> Config -> [FilePath] -> IO ()Source
Reads multiple summary files generated by criterion and creates a
bar chart to compare them. If the first argument is True
the
chart is flipped such that the bars represent different
benchmarks rather than summaries.
criterionChart :: CSV -> BarChart RunTimeSource
Used by writeCriterionChart
to generate a bar chart from
criterion's summary file.
comparisonChart :: Bool -> [(Label, CSV)] -> BarChart RunTimeSource
Used by writeComparisonChart
to generate a bar chart from
multiple summary files generated by criterion.
Progression
writeProgressionChart :: Bool -> Config -> FilePath -> [Label] -> IO ()Source
Reads the plot.csv
file generated by progression and creates a
corresponding bar chart.
progressionChart :: Bool -> [Label] -> CSV -> BarChart RatioSource
Used by writeProgressionChart
to generate a bar chart from
progression's plot.csv
file.