Renderer#
The renderer was designed with extensibility in mind and allows you to create custom renderers for different specification formats. The renderer module exposes a BaseRenderer abstract class to provide the clients with a common interface. The AltairRenderer class is a concrete implementation of the BaseRenderer. In order to constraint the input handled by AltairRenderer, strict typing is introduced in the draco.renderer.altair.types module.
BaseRenderer#
- class draco.renderer.BaseRenderer#
Base class for all renderers. Should handle the creation of a visualization represented as an object of type T.
- __init__()#
- abstract render(spec, data, label_mapping=None)#
Render a visualization from a dictionary-based specification and data.
- Parameters:
spec (
dict) – Specification of the visualization.data (
Union[dict[Any,Any],NativeDataFrame]) – Data to render.label_mapping (
Union[dict[str,str],Callable[[str],str],None]) – Mapping of field names to human-readable labels. If a callable is provided, it will be called with the field name and should return a human-readable label.
- Return type:
TypeVar(T)- Returns:
Produced visualization object of type T.
AltairRenderer#
- class draco.renderer.AltairRenderer(concat_mode=None, mark_config=None)#
Produces a Vega-Lite visualization represented as an Altair chart object.
- __init__(concat_mode=None, mark_config=None)#
Instantiates a new Altair <https://altair-viz.github.io/>-based renderer.
- Parameters:
concat_mode (
Optional[Literal['hconcat','vconcat']]) – The concatenation mode to use when concatenating multiple views. Only the first view is returned if None.mark_config (
dict[str,dict[str,Any]] |None) – Optional custom mark configuration. The keys are the mark types, the values are the configuration dictionaries for the mark type.
- render(spec, data, label_mapping=None)#
Render a visualization from a dictionary-based specification and data.
- Parameters:
spec (
dict) – Specification of the visualization.data (
Union[dict[Any,Any],NativeDataFrame]) – Data to render.label_mapping (
Union[dict[str,str],Callable[[str],str],None]) – Mapping of field names to human-readable labels. If a callable is provided, it will be called with the field name and should return a human-readable label.
- Return type:
TypeVar(VegaLiteChart,VConcatChart,HConcatChart,FacetChart,Chart,LayerChart)- Returns:
Produced visualization object of type T.
Types#
Note
Introducing the types through the below-described members made it possible to traverse specifications in a type-safe manner in the AltairRenderer class. The types reflect the default specification form, as described in the Facts chapters.
- draco.renderer.altair.types.DatasetNumberRows#
ID set for a field to be used as the
entity_idwhen being processed as an ASP entity.alias of
Annotated[int,Gt(gt=0)]
- class draco.renderer.altair.types.Encoding(**data)#
Encoding schema. Encodings define how data fields map to visual properties (channel) of the mark.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.EncodingAggregate#
How the data is binned into N bins. Positive integer. Described as (encoding,binning)
alias of
Literal[‘count’, ‘mean’, ‘median’, ‘min’, ‘max’, ‘stdev’, ‘sum’]
- draco.renderer.altair.types.EncodingBinning#
Stacking strategy. One of zero, center, or normalize. Described as (encoding,stack).
alias of
Annotated[int,Gt(gt=0)]
- draco.renderer.altair.types.EncodingChannel#
The field that maps to the visual property of the mark. Arbitrary string. Described as (encoding,field).
alias of
Literal[‘x’, ‘y’, ‘color’, ‘size’, ‘shape’, ‘text’]
- draco.renderer.altair.types.EncodingField#
How the data is aggregated. One of count, mean, median, min, max, stdev, or sum. Described as (encoding,aggregate).
- draco.renderer.altair.types.EncodingStack#
The scale channel. One of x, y, color, size, shape, or text. Same as EncodingChannel. Described as (scale,channel).
alias of
Literal[‘zero’, ‘center’, ‘normalize’]
- class draco.renderer.altair.types.Facet(**data)#
Facet schema. With the facet operator, we can partition a dataset by a field and create a view for each field. The resulting chart is often called a small multiples chart.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.FacetChannel#
The facet field. Arbitrary string. Described as (facet,field).
alias of
Literal[‘col’, ‘row’]
- draco.renderer.altair.types.FacetField#
Binning a numeric field for faceting. Positive integer. Described as (facet,binning).
- class draco.renderer.altair.types.Field(**data)#
Field schema. Represents a column in the dataset. Draco can use information about the field type and field statistics.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.FieldEntropy#
The minimum value. Only used for numbers. Described as (field,min)
alias of
Annotated[float,Ge(ge=0)]
- draco.renderer.altair.types.FieldFreq#
The minimum length of the field. Only used for strings. Described as (field,min_length)
alias of
Annotated[int,Gt(gt=0)]
- draco.renderer.altair.types.FieldId#
The name of a data field. Described as (field,name)
- draco.renderer.altair.types.FieldInteresting#
The coordinates system of the view. Can be one of cartesian, or polar. Described as (view,coordinates).
- draco.renderer.altair.types.FieldMax#
The standard deviation. Only used for numbers. Described as (field,std)
- draco.renderer.altair.types.FieldMaxLength#
The time span of the field in seconds. Only used for datetime fields. Described as (field,span_seconds)
alias of
Annotated[int,Ge(ge=0)]
- draco.renderer.altair.types.FieldMin#
The maximum value. Only used for numbers. Described as (field,max)
- draco.renderer.altair.types.FieldMinLength#
The maximum length of a field. Only used for strings. Described as (field,max_length)
alias of
Annotated[int,Ge(ge=0)]
- draco.renderer.altair.types.FieldName#
The type of the data in the column for this field. One of number, string, boolean, or datetime. Described as (field,type)
- draco.renderer.altair.types.FieldSkew#
The frequency of the most common value. Only used for strings. Described as (field,freq)
- draco.renderer.altair.types.FieldSpanSeconds#
When the task regards specific fields, fields can be marked as relevant to the task. Described as (field,interesting)
alias of
Annotated[int,Ge(ge=0)]
- draco.renderer.altair.types.FieldStd#
The skew of the field. Only used for numbers. Described as (field,skew)
- draco.renderer.altair.types.FieldType#
The number of unique values. Described as (field,unique)
alias of
Literal[‘number’, ‘string’, ‘boolean’, ‘datetime’]
- draco.renderer.altair.types.FieldUnique#
The entropy of the field. Described as (field,entropy)
alias of
Annotated[int,Gt(gt=0)]
- class draco.renderer.altair.types.Mark(**data)#
Mark schema. A mark represents the graphical mark of the visualization.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.MarkType#
The visual channel. One of x, y, color, size, shape, or text. Same as ScaleChannel. Described as (encoding,channel).
alias of
Literal[‘point’, ‘bar’, ‘line’, ‘area’, ‘text’, ‘tick’, ‘rect’]
- class draco.renderer.altair.types.Scale(**data)#
Scale schema. Scales map abstract values such as time or temperature to a visual value such as x- or y-position or color.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.ScaleChannel#
The scale type. One of linear, log, ordinal, or categorical. Described as (scale,type).
alias of
Literal[‘x’, ‘y’, ‘color’, ‘size’, ‘shape’, ‘text’]
- draco.renderer.altair.types.ScaleType#
Whether to include zero in the scale domain. Described as (scale,zero).
alias of
Literal[‘linear’, ‘log’, ‘ordinal’, ‘categorical’]
- draco.renderer.altair.types.ScaleZero#
The task type. The task that the user tries to complete when looking at a visualization helps Draco find the most appropriate visualization.
- class draco.renderer.altair.types.SchemaBase(**data)#
Base class for all schema classes.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class draco.renderer.altair.types.SpecificationDict(**data)#
Specification schema. Describes a visualization completely.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- draco.renderer.altair.types.Task#
The facet channel. Can be one of col and row. Described as (facet,channel).
alias of
Literal[‘value’, ‘summary’]
- class draco.renderer.altair.types.View(**data)#
View schema. A view can group marks and scales together.
-
facet:
list[Facet] |None# View-specific scales define scales on a per-channel basis in the view. None means that a top-level scale (shared scale) is present.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
-
facet:
- draco.renderer.altair.types.ViewCoordinate#
The mark type. One of point, bar, line, area, text, tick, or rect. Described as (mark,type).
alias of
Literal[‘cartesian’, ‘polar’]