pub trait View<S: Schema> {
type PrimaryDimension;
type BreakdownDimension;
type DisplayDimensions: Dimensions;
// Required methods
fn dataset(&self) -> &Dataset<S>;
fn value(&self, dims: &S::Dimensions) -> f64;
fn value_label(&self) -> String;
fn primary_dim(&self, dims: &S::Dimensions) -> Self::PrimaryDimension;
fn breakdown_dim(&self, dims: &S::Dimensions) -> Self::BreakdownDimension;
fn breakdown_label(&self) -> Option<String>;
fn display_dims(&self, dims: &S::Dimensions) -> Self::DisplayDimensions;
fn display_headers(&self) -> Vec<String>;
}
Expand description
Trait which defines how to render a Dataset
across different [Schema
]s.
Consumers may choose to implement this trait to provide custom views over datasets.
Required Associated Types§
sourcetype PrimaryDimension
type PrimaryDimension
The primary dimension - see View::primary_dim
for more details.
sourcetype BreakdownDimension
type BreakdownDimension
The breakdown dimension - see View::breakdown_dim
for more details.
sourcetype DisplayDimensions: Dimensions
type DisplayDimensions: Dimensions
The display dimension(s) - see View::display_dims
for more details.
The first must always be the PrimaryDimension
for the View
.
Required Methods§
sourcefn value(&self, dims: &S::Dimensions) -> f64
fn value(&self, dims: &S::Dimensions) -> f64
Extract the render value for this view from the input vector.
This will become aggregated according to the Render
configuration.
Dimensions.. | Rendering
primary_A | aggregate(VALUE)
sourcefn value_label(&self) -> String
fn value_label(&self) -> String
Get the label for the values in this view. For example:
Dimensions.. | VALUE_LABEL
primary_A | **
primary_B | ******
sourcefn primary_dim(&self, dims: &S::Dimensions) -> Self::PrimaryDimension
fn primary_dim(&self, dims: &S::Dimensions) -> Self::PrimaryDimension
Extract the primary dimension for this view from the input vector.
In flat
, the primary dimension forms the organizational basis for the rendering
For example:
Dimensions.. | Rendering
primary_A | **
secondary_A <-
tertiary_A <- these do not take part in the rendering directly
primary_B | ******
secondary_B <-
sourcefn breakdown_dim(&self, dims: &S::Dimensions) -> Self::BreakdownDimension
fn breakdown_dim(&self, dims: &S::Dimensions) -> Self::BreakdownDimension
Extract the breakdown dimension for this view from the input vector.
In the case of non-breakdown views (when View::breakdown_label
.is_none()), this method should return Nothing
.
Breakdown views allow flat
renderings to span the horizontal space.
For example:
| Breakdown Rendering.. |
Dimensions.. | breakdown_A breakdown_B breakdown_C |
primary_A | * ****** |
primary_B | *** * |
sourcefn breakdown_label(&self) -> Option<String>
fn breakdown_label(&self) -> Option<String>
Get the label for the breakdown in this view, if applicable.
When Some(...)
, View::breakdown_dim
must extract the breakdown value.
When None
, View::breakdown_dim
must extract Nothing
.
sourcefn display_dims(&self, dims: &S::Dimensions) -> Self::DisplayDimensions
fn display_dims(&self, dims: &S::Dimensions) -> Self::DisplayDimensions
Extract the display dimensions for this view from the input vector.
The display dimensions are optionally shown in the frame of flat
.
How they are shown is totally at the discretion of the widget’s implementation.
However, the widget implementation must always include the primary dimension.
For example:
Dimensions.. | Rendering
DISPLAY_A (primary) .. DISPLAY_N | **
The first display dimension must always be the primary dimension.
The length of the display dimensions must match the length of View::display_headers
.
sourcefn display_headers(&self) -> Vec<String>
fn display_headers(&self) -> Vec<String>
Get the dimensional headers for this view. These serve to label the display dimensions.
The length of the headers must match the length of View::display_dims
.
For example:
HEADER_1 .. HEADER_N | Rendering
primary_A .. | **
primary_B .. | ******