API Reference
Encoding
Parameters
----------
field: str
The name of the data field to encode.
aggregate: str | None (optional)
The aggregate operation.
axis: bool | None (optional)
If the axis is displayed or not, default is set to True (show axis).
encoding_type: str | None (optional)
The encoding type.
groupby: list | None (optional)
The fields of the aggrupation.
X
Y
Z
to_dict
Returns the dictionary specifications expression.
split_field_and_encoding
Splits and returns the field and the encoding data type of the parameter.
Raises
------
TypeError
If the encoding type is incorrect.
Notes
-----
Supposing that param is a string, as it has been called from encode() method.
FilterTransform
FilterTransform base class.
FieldEqualPredicate
Equal predicate filter class.
FieldGTPredicate
Greater than predicate filter class.
FieldLTPredicate
Lower than predicate filter class.
to_dict
Returns a dictionary about the equation of the filter with the syntaxis of the JSON specifications.
from_equation
from_dict
Creates a child filter object from the given filter's specifications.
Parameters
----------
filter_specs : dict
Filter specifications.
Raises
------
TypeError
If equation is not a dictionary.
ValueError
If the specifications of the filter is not correct.
get_filtered_data
Filters and returns the data.
to_dict
to_dict
to_dict
Data
Data class. See the example below to see the format.
Examples
--------
# To instantiate Data using Data(data_format_as_list)
>>> import aframexr
>>> data_format_as_list = [{"a": 1, "b": 2}, {"a": 2, "b": 4}]
>>> data = aframexr.Data(data_format_as_list)
# To instantiate Data using Data.from_json(data_format_as_string)
>>> import aframexr
>>> data_format_as_string = '[{"a": 1, "b": 2}, {"a": 2, "b": 4}]'
>>> data = aframexr.Data.from_json(data_format_as_string)
UrlData
UrlData class. Examples -------- >>> import aframexr >>> url = '...' # The URL of the file storing the data >>> data = aframexr.UrlData(url)
from_json
Create a Data object from JSON string.
to_json
Return a JSON string representation of the data.
AggregatedFieldDef
Aggregated field definition.
from_dict
Creates an AggregatedFieldDef object from the aggregate specifications.
to_dict
Returns the dictionary representation for chart specifications of the aggregated field.
get_aggregated_data
Returns the aggregated data.
split_operator_field
Returns the aggregate operator, the field and the groupby in the aggregate formula.
TopLevelMixin
Top level chart class.
Chart
Simple chart class.
Parameters
----------
data : Data | UrlData | DataFrame
Data, UrlData object or pandas DataFrame of the data.
depth : float (optional)
Depth of the chart. If not defined, using DEFAULT_CHART_DEPTH.
height : float (optional)
Height of the chart. If not defined, using DEFAULT_CHART_HEIGHT.
position : str (optional)
Position of the chart. The format is: 'x y z'. Refers to the position for the origin of coordinate system.
If not defined, using DEFAULT_CHART_POS.
rotation : str (optional)
Rotation of the chart in degrees. The format is: 'x y z'. The rotation axis is the coordinate system.
If not defined, using DEFAULT_CHART_ROTATION.
width : float (optional)
Width of the chart. If not defined, using DEFAULT_CHART_WIDTH.
Raises
------
TypeError
If any parameter has invalid type.
ValueError
If depth, height, position, rotation or width is invalid.
Element
Box
Cone
Cylinder
Dodecahedron
GLTF
Icosahedron
Image
Line
Octahedron
Plane
Sphere
Tetrahedron
Text
Torus
copy
Return a deep copy of the chart while keeping large data as reference.
from_dict
Import the chart from the JSON dict specifications.
Parameters
----------
specs : dict
JSON specifications of the chart.
Raises
------
TypeError
If specs is not a dictionary.
from_json
Create the chart from the JSON string specifications.
Parameters
----------
specs : str
JSON specifications of the chart.
Raises
------
TypeError
If specs is not a string.
JSONDecodeError
If specs is not a valid JSON.
movable
Make the entity movable. Concatenated charts cannot be movable, each chart must be defined as movable before concatenating.
save
Saves the chart into a file, supported formats are JSON and HTML.
Parameters
----------
fp : str
File path.
file_format : str (optional)
Format of the file could be ['html', 'json'].
If no format is specified, the chart will be saved depending on the file extension.
environment : str (optional)
Environment of the scene.
Raises
------
ValueError
If file_format is invalid.
show
Show the scene in the notebook.
to_dict
Returns the scene specifications as a dictionary.
to_html
Returns the HTML representation of the scene.
to_json
Returns the JSON string of the scene.
add_params
mark_arc
Pie chart and doughnut chart.
Parameters
----------
radius : float (optional)
Outer radius of the pie chart. If not specified, using DEFAULT_PIE_RADIUS. Must be greater than 0.
mark_bar
Bars chart.
Parameters
----------
color: str (optional)
Color of the bars. If not defined, using DEFAULT_ELEMENTS_COLOR_IN_CHART.
size : float (optional)
Width of the bars. If not specified, bars will be adjusted automatically. Must be greater than 0.
Raises
------
ValueError
If defined size is not greater than 0.
mark_line
Line chart.
Parameters
----------
color: str (optional)
Color of the line. If not defined, using DEFAULT_ELEMENTS_COLOR_IN_CHART.
point : bool (optional)
Either if add points in vertices or not. If not defined, using
mark_point
Scatter plot and bubble chart.
Parameters
----------
color: str (optional)
Color of the spheres. If not defined, using DEFAULT_ELEMENTS_COLOR_IN_CHART.
size : float (optional)
Maximum radius of the point. If not specified, using DEFAULT_POINT_RADIUS. Must be greater than 0.
Raises
------
ValueError
If size is not greater than 0.
encode
Add properties to the chart.
Parameters
----------
color : str (optional)
Field of the data that will determine the color of the sphere in the scatter plot.
size : str (optional)
Field of the data that will determine the size of the sphere in the bubble chart (must be quantitative).
theta : str (optional)
Field of the data that will determine the arcs of the pie and doughnut chart (must be quantitative).
x : str | X (optional)
Field of the data that will determine the x-axis of the chart.
y : str | Y (optional)
Field of the data what will determine the y-axis of the chart (must be quantitative).
z : str | Z (optional)
Field of the data what will determine the z-axis of the chart.
Raises
------
TypeError
If the encoding type is incorrect.
ValueError
If the encoding values are incorrect.
properties
Modify general properties of the chart.
transform_aggregate
Aggregates the data with the specified aggregate function, grouped by the specified groupby.
Parameters
----------
groupby : list | None
Data fields that will be grouped, optional. If not set, the defined fields in encode() method will be taken.
kwargs : dict
Format is: =().
transform_filter
Filters the chart with the given transformation.
Parameters
----------
equation_filter : str | FilterTransform | Parameter
The equation string of the filter transformation, a Filter object (see Examples) or Parameter object.
Raises
------
TypeError
If equation is not a string, a Filter object or a Parameter object.
Notes
-----
Can be concatenated with the rest of functions of the Chart, without needing an asignation. It can also be
concatenated several times (the result will be an addition of the filters, in order of assignation).
Examples
--------
*Using transform_filter() giving the equation string:*
>>> import aframexr
>>> data = aframexr.UrlData('./data.json')
>>> chart = aframexr.Chart(data).mark_bar().encode(x='model', y='sales')
>>> filtered_chart = chart.transform_filter('datum.motor == diesel')
>>> #filtered_chart.show()
*Using transform_filter() giving a Filter object*
>>> import aframexr
>>> data = aframexr.UrlData('./data.json')
>>> chart = aframexr.Chart(data).mark_bar().encode(x='model', y='sales')
>>> filter_object = aframexr.FieldEqualPredicate(field='motor', equal='diesel')
>>> filtered_chart = chart.transform_filter(filter_object)
>>> #filtered_chart.show()
materialize_data
selection_point
Add selection to the chart.