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)#

Render a visualization from a dictionary-based specification and data.

Parameters:
  • spec (dict) – Specification of the visualization.

  • data (DataFrame) – Data to render.

Return type:

TypeVar(T)

Returns:

Produced visualization object of type T.

AltairRenderer#

class draco.renderer.AltairRenderer(concat_mode=None)#

Produces a Vega-Lite visualization represented as an Altair chart object.

__init__(concat_mode=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.

render(spec, data)#

Render a visualization from a dictionary-based specification and data.

Parameters:
  • spec (dict) – Specification of the visualization.

  • data (DataFrame) – Data to render.

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_id when 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.

Read More.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'aggregate': FieldInfo(annotation=Union[Literal['count', 'mean', 'median', 'min', 'max', 'stdev', 'sum'], NoneType], required=False, default=None), 'binning': FieldInfo(annotation=Union[Annotated[int, Gt], NoneType], required=False, default=None), 'channel': FieldInfo(annotation=Literal['x', 'y', 'color', 'size', 'shape', 'text'], required=True), 'field': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'stack': FieldInfo(annotation=Union[Literal['zero', 'center', 'normalize'], NoneType], required=False, default=None)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

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.

Read More.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'binning': FieldInfo(annotation=Union[Annotated[int, Gt], NoneType], required=False, default=None), 'channel': FieldInfo(annotation=Literal['col', 'row'], required=True), 'field': FieldInfo(annotation=str, required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

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.

Read More.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'entropy': FieldInfo(annotation=Union[Annotated[float, Gt], NoneType], required=False, default=None), 'freq': FieldInfo(annotation=Union[Annotated[int, Gt], NoneType], required=False, default=None), 'id': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias='__id__', alias_priority=2), 'interesting': FieldInfo(annotation=Union[bool, NoneType], required=False, default=None), 'max': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'min': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'name': FieldInfo(annotation=str, required=True), 'std': FieldInfo(annotation=Union[float, NoneType], required=False, default=None), 'type': FieldInfo(annotation=Literal['number', 'string', 'boolean', 'datetime'], required=True), 'unique': FieldInfo(annotation=Union[Annotated[int, Gt], NoneType], required=False, default=None)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

draco.renderer.altair.types.FieldEntropy#

The minimum value. Only used for numbers. Described as (field,min)

alias of Annotated[float, Gt(gt=0)]

draco.renderer.altair.types.FieldFreq#

When the task regards specific fields, fields can be marked as relevant to the task. Described as (field,interesting)

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.FieldMin#

The maximum value. Only used for numbers. Described as (field,max)

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.FieldStd#

The frequency of the most common value. Only used for strings. Described as (field,freq)

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.

Read More.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'encoding': FieldInfo(annotation=list[Encoding], required=True), 'type': FieldInfo(annotation=Literal['point', 'bar', 'line', 'area', 'text', 'tick', 'rect'], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

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.

Read More.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'channel': FieldInfo(annotation=Literal['x', 'y', 'color', 'size', 'shape', 'text'], required=True), 'type': FieldInfo(annotation=Literal['linear', 'log', 'ordinal', 'categorical'], required=False, default='linear'), 'zero': FieldInfo(annotation=Union[bool, NoneType], required=False, default=None)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

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_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

class draco.renderer.altair.types.SpecificationDict(**data)#

Specification schema. Describes a visualization completely.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'field': FieldInfo(annotation=list[Field], required=True), 'number_rows': FieldInfo(annotation=int, required=True, metadata=[Gt(gt=0)]), 'scale': FieldInfo(annotation=Union[list[Scale], NoneType], required=False, default=None), 'task': FieldInfo(annotation=Union[Literal['value', 'summary'], NoneType], required=False, default=None), 'view': FieldInfo(annotation=list[View], required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

view: list[View]#

Top-level scales define shared scales across views. None means no shared scales are used.

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.

Read More.

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_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'coordinates': FieldInfo(annotation=Literal['cartesian', 'polar'], required=False, default='cartesian'), 'facet': FieldInfo(annotation=Union[list[Facet], NoneType], required=False, default=None), 'mark': FieldInfo(annotation=list[Mark], required=True), 'scale': FieldInfo(annotation=Union[list[Scale], NoneType], required=False, default=None)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

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’]