Repository navigation
Releases
v0.8.0
Changed
bar_pngshades each pixel by the share of it a bar covers, as a browser draws thebar_svgoutput at 100% zoom. Before, it rounded every bar edge to the nearest pixel, and since an edge on a half pixel rounded up, a bar whose edges both fell on half pixels moved one column right of the SVG. Edges on half pixels, which the default 1.0 gap gives whenever the width divides evenly by the number of bars, are now drawn as two half shaded columns, and rounded corners are anti-aliased. Edges on whole pixels draw as before.line_pngtakes the height of the area in each column from the centre of the column instead of its left edge, and shades the first and last column by the share the area covers. Before, an area that started or ended on a half pixel, such as with aspot_radiusof 3.5, began one column right of the SVG.blocksgives each of its eight blocks an equal eighth of the range. Before, a value took the nearest of eight evenly spaced levels, so▁and█each covered a fourteenth of the range and the six blocks between covered a seventh. A value can now draw one block lower or higher than before: in[0.0, 7.0, 0.5]the last value is now▁(was▂), and in[0.0, 7.0, 6.2]it is now█(was▇). The maximum is still█, and a constant series is still▄.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.7.0
Breaking
line_svg, line_png, bar_svg and bar_png now check every colour before drawing and return a Result. Before, SVG output wrote any colour string as given while PNG output drew a colour it could not read black, transparent or as a tint of the line, so one theme could mean two different charts.
- The four chart renderers return
Result(String, InvalidColor)orResult(BitArray, InvalidColor).blocksis unchanged. - A colour is
#rgb,#rgba,#rrggbb,#rrggbbaa,noneorcurrentColor, with the keywords in any case. Anything else in the theme or inspot_color, such as"red","rgb(0, 0, 0)"or"", givesError(InvalidColor(field:, value:)), wherefieldis"foreground","background","area","negative"or"spot_color". All four theme colours are checked, including one the chart does not draw. - An empty background or area colour is rejected. Use
"none"for no background andNonefor the default area. nonedraws nothing in both formats, so a foreground ofnonedraws no line, no dot, no default area and no bars at or above zero, and a negative ofnonedraws no bars below zero.currentColoris drawn black in PNG output, which has no surrounding text colour, wherever it is used.- Since every colour that reaches the SVG text has been checked, colours are no longer escaped.
- SVG output writes a colour with alpha (
#rgba,#rrggbbaa, and the default area tint) as#rrggbbwith afill-opacity,stroke-opacityorstop-opacityattribute, because SVG 1.1 renderers do not read the alpha forms. Hex colours without alpha are still written as given.
Before:
let svg = sparklinekit.line_svg(values, options)After:
case sparklinekit.line_svg(values, options) {
Ok(svg) -> svg
Error(sparklinekit.InvalidColor(field:, value:)) -> panic as { field <> ": " <> value }
}Fixed
- The gradient area of a series with values on both sides of zero faded from the top of the chart to the bottom in SVG, so the part below zero was faintest at the line and strongest at zero. Each side now fades towards zero, in SVG and PNG.
- PNG output shaded the gradient area per column, from the line down to the baseline, while SVG shades it by height over the whole area. PNG output now shades it by height too, so both formats draw the same opacity at the same height.
- A gradient area under a
currentColorline, or with an area colour ofcurrentColor, was drawn flat in SVG and as a black gradient in PNG. SVG output now draws it as a gradient ofcurrentColorwithstop-opacity. - Values beyond 1e300 were clamped to 1e300 before scaling, so two different large values, such as
1.0e308and1.7e308, were drawn as a constant series. They are now scaled without overflow up to the largest Float. - On JavaScript, NaN compared as the largest value and was drawn at the top. NaN is now drawn as
0.0, and Infinity as the largest Float, in every renderer. - Each bar kept its gap on its right, so the chart had no margin on the left and a full gap on the right, and a reversed series was not drawn as its mirror image. Each bar is now centred in its share of the width, with half the gap at each edge.
Documentation
- The 0.6.0 notes name a single package that had to follow that release. In general, any code that imports
sparklinekit/line,sparklinekit/bar,sparklinekit/themeorsparklinekit/unicodehas to be rewritten against thesparklinekitmodule when it moves to 0.6.0 or later, as the 0.6.0 Breaking section describes. - README describes the accepted colours, and the README images are drawn again with the new gradient and bar layout.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.6.0
Breaking
The public API is now the single module sparklinekit. The builders and the theme are plain records, so their setters and getters are removed.
sparklinekit/unicode,sparklinekit/line,sparklinekit/barandsparklinekit/themeare removed and their contents move intosparklinekit.unicode.renderissparklinekit.blocks.unicode.render_intsis removed; passlist.map(values, int.to_float).- The opaque
line.Builderandbar.Builderare replaced by the recordsLineOptionsandBarOptionswith the constantsdefault_line_optionsanddefault_bar_options.line.to_svgandline.to_pngareline_svg(values, options)andline_png(values, options), andbar.to_svgandbar.to_pngarebar_svgandbar_png.new,new_ints,with_values,with_int_valuesand everywith_*setter are removed; set the record fields instead (with_sizeiswidthandheight,with_spotisspot_radius,with_bar_gapisgap). with_area_fill,with_area_colorandwith_gradient_areaare replaced by theareafield, which isNoArea,SolidAreaorGradientArea, and the theme'sareacolour.with_color,with_background_colorandwith_negative_colorare replaced by the fields of thetheme, for exampleTheme(..sparklinekit.ocean, foreground: "#22A06B").Themeis a record with the fieldsforeground,background,areaandnegative, so the accessor functions are removed.areais anOption(String);Noneuses the foreground at 22% opacity. The theme functions are constants:theme.ocean()issparklinekit.ocean, andtheme.default()issparklinekit.default_theme.sparklinekit.package_versionis removed.- In PNG output, a foreground or negative colour that is not hex is drawn black. It used to fall back to the colour of the theme set before
with_colororwith_negative_color. - Options out of range (sizes below 1, negative gaps and radii, smoothing outside 0 to 0.5, very large stroke widths and dots) are still clamped, now when the chart is drawn.
Before:
import sparklinekit/line
import sparklinekit/theme
line.new([1.0, 5.0, 3.0, 8.0, 4.0])
|> line.with_theme(theme.ocean())
|> line.with_area_fill(True)
|> line.with_spot(3.0)
|> line.to_svgAfter:
import sparklinekit.{LineOptions}
sparklinekit.line_svg(
[1.0, 5.0, 3.0, 8.0, 4.0],
LineOptions(
..sparklinekit.default_line_options,
theme: sparklinekit.ocean,
area: sparklinekit.GradientArea,
spot_radius: 3.0,
),
)tenbagger uses sparklinekit/line and sparklinekit/theme and needs to follow this change when it updates.
Fixed
- A solid area (
with_gradient_area(False)) under a themed line used a tint of the line colour in SVG and the theme's area colour in PNG. Both now use the theme's area colour. - The dot on the last value kept the colour of the theme it was set with, so after
with_colorit was not the colour of the line, as its documentation said. It now follows the line colour unlessspot_coloris set. - The SVG area gradient under a line that never goes above zero, with at least one value below it, was opaque at the top edge and faded towards the line. It now fades away from the line, as PNG output did.
- The area under a single negative value reached down to the bottom, while two equal negative values filled up to the top. Both now fill up to the top.
- Bars for a constant negative series stood on the bottom edge. They now hang from the top.
- An empty area colour wrote
fill=""into the SVG, which browsers draw black. It now uses the foreground at 22% opacity, asNonedoes. - An area colour of
"none"drew no area in SVG but a tinted one in PNG. PNG output now draws no area either.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.5.0
Changed
- GitHub Releases now attach the Hex package tarball,
checksums.txt, a keyless cosign signature bundle for it and build provenance (*.intoto.jsonl). See "Verifying releases" in the README.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.4.0
Changed
- The minimum Gleam version is now 1.14.0 (was 1.15.0). 1.14.0 builds and tests the package unchanged on both targets, and
gleam_stdlib1.0 already requires it. CI tests that floor alongside the latest Gleam 1.x.
Fixed
sparklinekit.package_version()returned"0.1.0"in 0.2.0 and 0.3.0; it now returns the published version. The test that was meant to catch this compared the constant with a hard-coded string; it now readsgleam.toml.
Documentation
line.to_svg,line.to_png,bar.to_svgandbar.to_pngnow state what an empty, single-value or all-equal series renders, asunicode.renderand the README's edge-case section already did. Tests pin that an empty series gives a blank PNG of the configured size.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.3.0
Fixed
- README: the three sparkline sample images (
sparkline-line.png,sparkline-bar.png,sparkline-mixed-bar.png) now use absoluteraw.githubusercontent.comURLs instead of the relativedocs/images/...paths so they render both on GitHub and on the Hex package page (the relative paths cannot be resolved against the published package archive, which omits thedocs/images/directory). (#7) line.with_area_fill(True)now anchors the area to the zero baseline: all-positive series fill to the viewBox bottom (legacy behaviour, unchanged), all-negative series fill upward to the viewBox top, and mixed-sign series fill toward the SVG y-coordinate that data value0.0maps to — so positive segments tint downward toward zero and negative segments tint upward toward zero. Previously the area always closed at the canvas floor, which made mixed-sign series read visually as all-positive. (#6)
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.2.0
Bug-hunt release. The public API surface is unchanged from 0.1.0;
every visible difference is a defect the v0.1.0 renderer silently
shipped. Two systematic QA rounds (PR #3, PR #4) added ten new
regression tests under test/sparklinekit/qa/ covering each
defect and the property it now satisfies.
Fixed
Behavioural defects
line.with_area_fill(False)no longer destroys a prior
line.with_area_color(c). The toggle is now a pure
enable / disable; the explicit colour survives across a
disable / re-enable round-trip.bar.new(no explicit theme) now honours
theme.default().negative(#EF4444) for negative-bar
fill. Previously the default theme's negative slot was
declared but never applied, leaving mixed-sign charts
visually identical for positives and negatives unless
with_theme(...)was called.- Zero-value bars now render as a 1-pixel hairline at the
baseline instead of collapsing to aheight="0.0"rect.
A reader can distinguish "value was zero here" from
"value missing here". The hairline grows into the
canvas, so it stays inside the viewBox even when the
baseline pins to a canvas edge (all-positive or
all-negative input). line.with_area_color("rgb(255, 0, 0)")(or any non-hex
CSS colour string) no longer gets silently substituted by
the stroke colour or by black when the default gradient is
enabled. The renderer drops the gradient and emits a solid
fill with the user's literal CSS colour.- Default theme (
currentColorstroke) plus
line.with_area_fill(True)now produces an area that
inherits the surrounding CSS colour via
fill="currentColor"andfill-opacity="0.22", instead
of the previous hardcoded black gradient stops.
Totality on adversarial input
unicode.render,line.to_svg, andbar.to_svgno longer
raisearithmetic_error(Erlang) or emitInfinity/
NaNcoordinates (JavaScript) for extremeList(Float)
input.scale.unitclamps to±1.0e300before subtraction
so the intermediatemax - minstays inside the IEEE 754
double range;bar.compute_layoutclamps each per-bar
value the same way.line.with_stroke_width(very_large)is clamped to
≤ 1.0e4at the setter, so the PNG raster's per-pixel
perpendicular sweep cannot stall the renderer. The SVG
side is additionally guarded by a±1.0e6clamp inside
format.coordagainst any other adversarial coordinate.line.with_spot(very_large)is clamped to[0.0, 1.0e4]
at the setter, so the disc fill's bounding-square iteration
cannot stall the PNG path.
Removed
- Deprecated
line.to_string/bar.to_stringaliases for
to_svg. Both were introduced before the first public
release; since v0.1.0 was the first version on Hex there
is no prior caller to stay compatible with.
Documentation
test/sparklinekit/qa/— six modules (property_test,
fuzz_test,metamorphic_test,boundary_test,
snapshot_test,differential_test) plus the two
round-by-round regression suites (deep_test,
deep2_test) bring the QA harness to 219 tests on each
target.
Install
gleam add sparklinekitSee HexDocs for the API
reference.
v0.1.0
Initial public release. Pure Gleam, zero runtime dependencies
beyond gleam_stdlib, runs on both the Erlang and JavaScript
targets, MIT licensed.
Added
Unicode renderer
sparklinekit/unicode— terminal sparklines built from the eight
Unicode block characters▁▂▃▄▅▆▇█. Empty input renders as"";
single-value and all-equal inputs render as the middle block.unicode.render/unicode.render_intsforList(Float)and
List(Int)inputs respectively.
SVG / PNG line renderer
sparklinekit/line— opaque builder that renders to either SVG
strings (line.to_svg) or 8-bit RGBA PNG byte arrays
(line.to_png). PNG strokes use Xiaolin Wu anti-aliasing; SVG
output carriespreserveAspectRatio="none"so charts scale into
any container.- Constructors
line.newandline.new_ints; in-place value
replacement vialine.with_values/line.with_int_values. - Styling helpers:
line.with_color,line.with_background_color,
line.with_size,line.with_stroke_width,line.with_theme. line.with_smoothing(factor)— cubic Bézier smoothing
(0.0–0.5factor, matchingreact-sparklines).line.with_area_fill(enabled)/line.with_area_color(colour)/
line.with_gradient_area(enabled)— tinted area under the line,
rendered as a top-to-baseline gradient by default.line.with_spot(radius)/line.with_spot_color(colour)—
filled circle on the last data point as a "today" marker.- Default viewBox of
240x60, default stroke width2.0,
stroke-width-aware padding so thick strokes are not clipped at
the canvas edge.
SVG / PNG bar renderer
sparklinekit/bar— opaque builder that renders to SVG
(bar.to_svg) or PNG (bar.to_png). Rounded corners are
preserved in the raster output.- Constructors
bar.newandbar.new_ints; in-place value
replacement viabar.with_values/bar.with_int_values. - Styling helpers:
bar.with_color,bar.with_background_color,
bar.with_size,bar.with_bar_gap,bar.with_theme. bar.with_corner_radius(radius)— radius is clamped to half the
smaller side of each bar so the shape stays a rectangle or
capsule rather than collapsing to a circle.bar.with_negative_color(colour)— distinct fill for bars below
the zero baseline; positives and negatives share that baseline.
Themes
sparklinekit/theme— ten bundled colour schemes covering the
common dashboard styles:ocean,forest,sunset,mono,
neon,pastel,crimson,slate,amber,midnight.
Plustheme.default()which inherits the surrounding CSS
currentColor.- Each theme bundles four slots —
foreground,background,
area,negative— exposed viatheme.foreground/1,
theme.background/1,theme.area/1,theme.negative/1. - Apply a theme with
line.with_theme/bar.with_theme; chain
with_color/with_background_color/with_area_color/
with_negative_colorto override individual slots.
Internals
sparklinekit/internal/color— hex colour parsing for#rgb,
#rgba,#rrggbb,#rrggbbaa, plus alpha blending and
channel-wise compositing helpers.sparklinekit/internal/png— PNG encoder using CRC32 +
Adler32 + DEFLATE "store" blocks. Pure Gleam, no FFI.sparklinekit/internal/raster— sparse canvas withdraw_line
(Wu anti-aliased),fill_circle,fill_rounded_rect, and
fill_vertical_gradientprimitives.
Documentation
- README written around runnable samples, each pinned to a test
intest/sparklinekit/readme_test.gleamso the published
snippets cannot drift from the library. - Sample images in
docs/images/covering the SVG / PNG hero
shots, every theme preview, and the edge-case visuals
(single-value, all-equal, negative input).
Install
gleam add sparklinekitSee HexDocs for the API
reference.