Charts

The library that renders statistical charts via the charton engine into an OpenGL texture, for use with KMP/CMP on Aurora OS.

Dependency libraries

  • fontconfig

Features

Charts

  • Chart.js-style config DSL: lineChart { data { ... }; options { ... } }.
  • Line, area and bar charts with the labels/datasets sugar (long-format columns, palette colors, stacking, normalized and floating bars).
  • Point/scatter with layouts: standard, jitter, beeswarm, quasirandom, dodge.
  • Polar charts: pie, donut, rose (Nightingale).
  • Distribution marks: histogram, boxplot, violin, tick, error bar.
  • Smoothed fields: KDE density curves, 2-D density heatmap, contour iso-lines.
  • Geometry marks: path (polylines), polygon (filled regions), rect (heatmap cells).
  • Reference and annotation marks: rule (reference lines), text (per-point labels).
  • Geoshape: map regions (lon/lat) under Equal Earth, Mollweide, Equirectangular or Mercator projections.

Data

  • Columnar typed data: f64, datetime (Unix ns) and string columns.
  • labels/datasets sugar expanded into long format on the fly.
  • Realtime updates: same-length f64 columns update in place (zero-alloc); columns not present in the update are kept.
  • Realtime pacing: updateDataAwait completes when a frame with the new data is rendered.
  • GeoJSON parsing into datasets (lon/lat/path columns plus feature properties).

Options

  • Common Chart.js-style surface: title, axis titles, scales (linear, log, discrete, temporal), domain overrides, legend, grid, faceting (wrap / row-column grid, fixed/free scales).
  • Label formatting (prefix/suffix, precision, thousands separator, compact) and explicit ticks (value, labeled, discrete, timestamp).
  • Per-type tuning: colors, opacity, stroke and dash patterns, interpolation and LOESS smoothing, binning, KDE bandwidth and kernel.
  • Themes: builtin presets (light, dark, mono) and custom themes (colors and font sizes applied over the light preset).

Overlays

  • Line, point and text annotations in data coordinates.
  • Add/replace/remove/clear by caller-defined id.
  • Overlay coordinates take part in scale training (a value outside the data range expands the axes).

Interaction

  • Pan and pinch/double-tap zoom on continuous axes.
  • Tap picking of the nearest data point.
  • Visible domain reporting (getDomain + domainChanged events).

Rendering

  • Event-driven rendering into an OpenGL texture, drawn via Skia; pan/zoom bursts collapse into one render per display frame.
  • Frame size changes in place (the texture is reallocated on the next render pass).
  • Render type switch: auto, gpu, cpu.
  • Headless export to .svg / .png by path extension.

Events

  • chartReady, domainChanged, pointPicked, needRedraw, errors.

Example

class AuroraChartView {
    private val chart = AuroraChart(
        width = 512,
        height = 256,
        config = lineChart {
            data {
                labels("Jan", "Feb", "Mar", "Apr", "May", "Jun")
                dataset("2024", 29.0, 31.0, 37.0, 42.0, 51.0, 60.0)
                dataset("2025", 32.0, 34.0, 40.0, 44.0, 52.0, 61.0)
            }
            options {
                title = "Sales"
                strokeWidth = 2.5
            }
        },
    )

    fun release() {
        chart.release()
    }

    fun resize(width: Int, height: Int) {
        chart.setSize(width, height)
    }

    fun setData(block: ChartDataSpec.() -> Unit) {
        chart.updateData(block)
    }

    fun setTheme(theme: ThemeCode): Boolean {
        return chart.setTheme(theme)
    }

    fun setTheme(theme: ChartTheme) {
        chart.setTheme(theme)
    }

    fun addLimitLine(y: Double): Boolean {
        return chart.addOverlay("limit", overlayLine(0.0, y, 6.0, y))
    }

    fun removeLimitLine(): Boolean {
        return chart.removeOverlay("limit")
    }

    fun onTouch(id: UInt, x: Double, y: Double, phase: TouchPhase) {
        chart.input(id, x, y, phase)
    }

    fun visibleDomain(): ChartDomain {
        return chart.getDomain()
    }

    fun exportImage(path: String): Boolean {
        return chart.export(path)
    }

    fun collectEvents() = runBlocking {
        launch { chart.chartReady.collect { println("chart ready") } }
        launch { chart.domainChanged.collect { domain -> println("domain: $domain") } }
        launch { chart.pointPicked.collect { point -> println("picked: $point") } }
        launch { chart.errors.collect { error -> println("error: $error") } }
    }

    // Drawing: call from a Canvas draw scope on the render thread
    fun draw(canvas: Canvas, x: Float, y: Float, width: Float, height: Float) {
        chart.drawFrame(canvas, x, y, width, height)
    }
}

object ChartSettings {
    fun customTheme(view: AuroraChartView) {
        // colors and font sizes over the light preset
        view.setTheme(ChartTheme.Light.copy(background = "#101018"))
    }

    fun cpuRendering(view: AuroraChartView) {
        view.setRenderType(RenderType.Cpu)
    }

    fun realtime(view: AuroraChartView) = runBlocking {
        // Each await completes when a frame with this data is rendered,
        // pacing the stream at the render loop speed
        repeat(100) { i ->
            view.setData({
                column("x", doubleArrayOf(0.0, 1.0, 2.0, 3.0))
                column("y", doubleArrayOf(i * 1.0, i + 2.0, i + 1.0, i + 3.0))
            })
        }
        // paced form:
        view.updateRealtime {
            column("x", doubleArrayOf(0.0, 1.0, 2.0, 3.0))
            column("y", doubleArrayOf(1.0, 2.0, 1.0, 3.0))
        }
    }
}