densa_arrow/lib.rs
1//! Apache Arrow tables in densa's data grid.
2//!
3//! [`ArrowTable`] holds Arrow [`RecordBatch`](arrow_array::RecordBatch)es (from Parquet,
4//! DataFusion, DuckDB, a Flight stream or your own code) and formats their values into
5//! grid cells; [`ArrowTable::view`] turns it into a `densa_grid::GridSource` scrolled to
6//! a row, which `GridPainter` draws. Arrays are shared with the batches, never copied, so a
7//! table of millions of rows costs no more to show than its visible rows, and drawing a
8//! frame allocates nothing.
9//!
10//! For live data, [`LiveModel`] makes a `densa_data::LiveTable` the model of the grid widget
11//! (`densa_widgets::DataGrid`): sorted by a click, filtered by the app, its selection kept on
12//! a row as the row moves. [`LiveGrid`] paints a view of one with `GridPainter` directly,
13//! and [`LiveSeries`] reads two of its numeric columns as a `densa_chart` series (a price
14//! over time), so a chart follows the same live data.
15//!
16//! ```
17//! use std::sync::Arc;
18//! use arrow_array::{ArrayRef, Float64Array, RecordBatch, StringArray};
19//! use densa_arrow::ArrowTable;
20//! use densa_grid::{CellText, GridSource, Palette};
21//!
22//! let batch = RecordBatch::try_from_iter([
23//! ("sensor", Arc::new(StringArray::from(vec!["a-1", "b-2"])) as ArrayRef),
24//! ("celsius", Arc::new(Float64Array::from(vec![21.5, 80.25])) as ArrayRef),
25//! ])?;
26//! let mut table = ArrowTable::from_batches([batch])?;
27//! table.set_decimals(1, Some(1))?;
28//!
29//! let columns = table.columns(); // for `GridPainter::new`
30//! let view = table.view(0, &Palette::new()); // each frame: `painter.paint(&view, &mut canvas)`
31//! let mut text = CellText::new();
32//! view.cell(1, 1, &mut text);
33//! assert_eq!(text.as_str(), "80.2");
34//! # Ok::<(), Box<dyn std::error::Error>>(())
35//! ```
36
37//! The API takes and returns [`arrow_array`] and [`arrow_schema`] types, re-exported here so
38//! applications use the same Arrow version: a major Arrow upgrade is a breaking release of
39//! this crate.
40
41pub use arrow_array;
42pub use arrow_schema;
43
44mod calendar;
45mod live;
46mod model;
47mod reader;
48mod series;
49mod table;
50
51pub use live::{LiveGrid, LiveGridView};
52pub use model::LiveModel;
53pub use series::{LiveSeries, SeriesError, SeriesPoints};
54pub use table::{ArrowGrid, ArrowTable, CellState, TableError};