Skip to content

struct

Table

pub struct Table {
    pub columns: Vec<Column>,
    pub rows: Vec<Value>,
    pub meta: Meta,
    pub geometry: Option<Rc<Vec<Option<Shape>>>>,
}

Data read from a source: its columns and rows (records), with what the source says about it.

Fields

columns

pub columns: Vec<Column>

The columns, in order.

rows

pub rows: Vec<Value>

Records. A cell with no value is Null, never zero, and any reason published for it is under STATUS.

meta

pub meta: Meta

What the source says about the data.

geometry

pub geometry: Option<Rc<Vec<Option<Shape>>>>

Each row's shape, when the data is map regions.

Methods

apply

pub fn apply(&mut self, incoming: Table, how: Update, key: Option<&str>, keep: Option<usize>)

Apply a message's rows. Later rows take the types the table already has: a "12.3" in a number column is a number.

from_text

pub fn from_text(headers: &[String], rows: Vec<Vec<String>>, missing: &[String]) -> Table

From header names and rows of text (CSV).

from_records

pub fn from_records(records: Vec<Value>, missing: &[String]) -> Table

From records (JSON). Nested records become country.value columns.

reorder

pub fn reorder(&mut self, keys: &[String])

Put columns in this order (any not named go last).

apply_labels

pub fn apply_labels(&mut self, _: &Table)

Without the stats feature a codebook can't be asked for.

to_csv

pub fn to_csv(&self) -> String

The visible columns as CSV. A cell starting like a spreadsheet formula is quoted so that opening the file can't run it.

set_labels

pub fn set_labels(&mut self, keys: &[String], labels: &[Option<String>])

Give columns their names to show (surveys' question text).

column

pub fn column(&self, key: &str) -> Option<&Column>

The column with key, if there's one.

status

pub fn status<'a>(row: &'a Value, key: &str) -> Option<&'a str>

Why a row's cell has no value (np, ..), if the source said.

varying_dimensions

pub fn varying_dimensions(&self) -> Vec<&Column>

Dimensions with more than one value: if a chart doesn't split or filter on these, it would draw different things as one series.

filter

pub fn filter(&mut self, wanted: &BTreeMap<String, Value>)

Keep rows matching every key: value (a list means any of them).

sort

pub fn sort(&mut self, by: &str)

Sort by key (-key for descending). No value sorts last, always.

group

pub fn group(&mut self, by: &str, how: &str)

One row per distinct by value, each number column combined with how (sum, mean, count, min, max). Cells with no value aren't counted, and the table's notes say how many were left out.

group_within

pub fn group_within(&mut self, by: &str, within: &[String], how: &str)

[Table::group], keeping these columns apart too: a value per by within each of them.

visible_columns

pub fn visible_columns(&self) -> Value

{key, label} records for Table/DataTable.

Trait implementations