gerbil/chart
Types
A bar that can be used in vertical_bars and
horizontal_bar plots.
You can build one using the bar function.
pub opaque type Bar(category, value, message)
A plot is a way to show some data on a chart, there’s many different kinds of plots:
pub opaque type Plot(x, y, message)
Values
pub fn add(
chart: Chart(x, y, message),
plot: Plot(x, y, message),
) -> Chart(x, y, message)
Adds a new plot to the chart. Plots added last will appear on top of earlier ones.
TODO) Examples
pub fn bar(
category category: x,
start start: y,
end end: y,
attributes attributes: List(attribute.Attribute(message)),
) -> Bar(x, y, message)
A bar that can be used in vertical_bars and
horizontal_bar plots.
pub fn horizontal_band(
from from: option.Option(y),
to to: option.Option(y),
attributes attributes: List(attribute.Attribute(message)),
) -> Plot(x, y, message)
Creates an horizontal band starting and ending at the given positions. The start and end positions might not be specified, in that case the band will extend all the way towards the top, or the bottom of the chart.
Styling
- A band is a
<g>element with a.bandclass. - The colour of a band is determined by the
--plot-colourCSS variable
So if I wanted to change the colour of a band I could use the following CSS:
.band {
--plot-colour: #faaff3;
}
pub fn horizontal_bars(
attributes: List(attribute.Attribute(message)),
bars: List(Bar(y, x, message)),
) -> Plot(x, y, message)
A plot displaying a set of horizontal bars.
Styling
- The bars are wrapped in a
<g>container element with a.barsclass. - Each bar is a
<rect>with a.barclass. - The colour of a bar is determined by the
--plot-colourCSS variable.
So if I wanted to change the colour of the bars I could use the following CSS:
.bars {
--plot-colour: #faaff3;
}
pub fn line(
attributes: List(attribute.Attribute(message)),
points: List(Point(x, y, message)),
) -> Plot(x, y, message)
Creates a line plot connecting the given points.
Styling
- The line is a
<path>with a.lineclass. - The colour of the line is determined by the
--plot-colourCSS variable.
So if I wanted to change the colour of the line I could use the following CSS:
.line {
--plot-colour: #faaff3;
}
pub fn new(
x x: axis.Axis(x),
y y: axis.Axis(y),
) -> Chart(x, y, message)
Creates a new empty plane chart with the given axes.
pub fn point(
x x: x,
y y: y,
attributes attributes: List(attribute.Attribute(message)),
) -> Point(x, y, message)
pub fn points(
attributes: List(attribute.Attribute(message)),
points: List(Point(x, y, message)),
) -> Plot(x, y, message)
A plot displaying the given points.
Styling
- The points are wrapped in a
<g>element with a.pointsclass. - Each point is a
<circle>with a.pointclass. - The colour of a point is determined by the
--plot-colourCSS variable.
So if I wanted to change the colour of the points I could use the following CSS:
.points {
--plot-colour: #faaff3;
}
pub fn to_svg(
chart: Chart(x, y, message),
width width: Int,
height height: Int,
) -> element.Element(message)
Turns the given chart into an <svg> element with a .gerbil class.
The width and height are used to express the aspect ratio the generated
chart will have.
Styling
- The chart is an
<svg>element with the.gerbilclass. - The ticks of the x axis have the
xandtickclass. Their colour is determined by the--x-tick-colourcss variable. - The labels of the x axis have the
xandlabelclass. Their colour is determined by the--label-colourcss variable. - The ticks of the y axis have the
yandtickclass. Their colour is determined by the--y-tick-colourcss variable. - The labels of the y axis have the
yandlabelclass. Their colour is determined by the--label-colourcss variable.
So if I wanted to hide one every two labels in the x axis I could use the following CSS:
.gerbil .label.x:nth-of-type(2n) {
display: hidden;
}
pub fn vertical_band(
from from: option.Option(x),
to to: option.Option(x),
attriubutes attributes: List(attribute.Attribute(message)),
) -> Plot(x, y, message)
A vertical band starting and ending at the given positions. The start and end positions might not be specified, in that case the band will extend all the way towards the start, or the end of the chart.
Styling
- A band is a
<g>element with a.bandclass. - The colour of a band is determined by the
--plot-colourCSS variable
So if I wanted to change the colour of a band I could use the following CSS:
.band {
--plot-colour: #faaff3;
}
pub fn vertical_bars(
attributes: List(attribute.Attribute(message)),
bars: List(Bar(x, y, message)),
) -> Plot(x, y, message)
A plot displaying a set of vertical bars.
Styling
- The bars are wrapped in a
<g>container element with a.barsclass. - Each bar is a
<rect>with a.barclass. - The colour of a bar is determined by the
--plot-colourCSS variable.
So if I wanted to change the colour of the bars I could use the following CSS:
.bars {
--plot-colour: #faaff3;
}