mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-01 14:07:48 +00:00
first commit
This commit is contained in:
24
.venv/Lib/site-packages/altair/vegalite/v3/__init__.py
Normal file
24
.venv/Lib/site-packages/altair/vegalite/v3/__init__.py
Normal file
@ -0,0 +1,24 @@
|
||||
# flake8: noqa
|
||||
from .schema import *
|
||||
from .api import *
|
||||
from ._deprecated import *
|
||||
|
||||
from ...datasets import list_datasets, load_dataset
|
||||
|
||||
from ... import expr
|
||||
from ...expr import datum
|
||||
|
||||
from .display import VegaLite, renderers
|
||||
|
||||
from .data import (
|
||||
MaxRowsError,
|
||||
pipe,
|
||||
curry,
|
||||
limit_rows,
|
||||
sample,
|
||||
to_json,
|
||||
to_csv,
|
||||
to_values,
|
||||
default_data_transformer,
|
||||
data_transformers,
|
||||
)
|
19
.venv/Lib/site-packages/altair/vegalite/v3/_deprecated.py
Normal file
19
.venv/Lib/site-packages/altair/vegalite/v3/_deprecated.py
Normal file
@ -0,0 +1,19 @@
|
||||
from ...utils.deprecation import _deprecate
|
||||
from . import channels
|
||||
|
||||
# Deprecated classes (see https://github.com/altair-viz/altair/issues/1474).
|
||||
# TODO: Remove these in Altair 3.2.
|
||||
Fillopacity = _deprecate(channels.FillOpacity, "Fillopacity")
|
||||
FillopacityValue = _deprecate(channels.FillOpacityValue, "FillopacityValue")
|
||||
Strokeopacity = _deprecate(channels.StrokeOpacity, "Strokeopacity")
|
||||
StrokeopacityValue = _deprecate(channels.StrokeOpacityValue, "StrokeopacityValue")
|
||||
Strokewidth = _deprecate(channels.StrokeWidth, "Strokewidth")
|
||||
StrokewidthValue = _deprecate(channels.StrokeWidthValue, "StrokewidthValue")
|
||||
Xerror = _deprecate(channels.XError, "Xerror")
|
||||
XerrorValue = _deprecate(channels.XErrorValue, "XerrorValue")
|
||||
Xerror2 = _deprecate(channels.XError2, "Xerror2")
|
||||
Xerror2Value = _deprecate(channels.XError2Value, "Xerror2Value")
|
||||
Yerror = _deprecate(channels.YError, "Yerror")
|
||||
YerrorValue = _deprecate(channels.YErrorValue, "YerrorValue")
|
||||
Yerror2 = _deprecate(channels.YError2, "Yerror2")
|
||||
Yerror2Value = _deprecate(channels.YError2Value, "Yerror2Value")
|
2177
.venv/Lib/site-packages/altair/vegalite/v3/api.py
Normal file
2177
.venv/Lib/site-packages/altair/vegalite/v3/api.py
Normal file
File diff suppressed because it is too large
Load Diff
43
.venv/Lib/site-packages/altair/vegalite/v3/data.py
Normal file
43
.venv/Lib/site-packages/altair/vegalite/v3/data.py
Normal file
@ -0,0 +1,43 @@
|
||||
from ..data import (
|
||||
MaxRowsError,
|
||||
curry,
|
||||
default_data_transformer,
|
||||
limit_rows,
|
||||
pipe,
|
||||
sample,
|
||||
to_csv,
|
||||
to_json,
|
||||
to_values,
|
||||
DataTransformerRegistry,
|
||||
)
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# VegaLite 3 data transformers
|
||||
# ==============================================================================
|
||||
|
||||
|
||||
ENTRY_POINT_GROUP = "altair.vegalite.v3.data_transformer" # type: str
|
||||
|
||||
|
||||
data_transformers = DataTransformerRegistry(
|
||||
entry_point_group=ENTRY_POINT_GROUP
|
||||
) # type: DataTransformerRegistry
|
||||
data_transformers.register("default", default_data_transformer)
|
||||
data_transformers.register("json", to_json)
|
||||
data_transformers.register("csv", to_csv)
|
||||
data_transformers.enable("default")
|
||||
|
||||
|
||||
__all__ = (
|
||||
"MaxRowsError",
|
||||
"curry",
|
||||
"default_data_transformer",
|
||||
"limit_rows",
|
||||
"pipe",
|
||||
"sample",
|
||||
"to_csv",
|
||||
"to_json",
|
||||
"to_values",
|
||||
"data_transformers",
|
||||
)
|
146
.venv/Lib/site-packages/altair/vegalite/v3/display.py
Normal file
146
.venv/Lib/site-packages/altair/vegalite/v3/display.py
Normal file
@ -0,0 +1,146 @@
|
||||
import os
|
||||
|
||||
from ...utils.mimebundle import spec_to_mimebundle
|
||||
from ..display import Displayable
|
||||
from ..display import default_renderer_base
|
||||
from ..display import json_renderer_base
|
||||
from ..display import RendererRegistry
|
||||
from ..display import HTMLRenderer
|
||||
|
||||
from .schema import SCHEMA_VERSION
|
||||
|
||||
VEGALITE_VERSION = SCHEMA_VERSION.lstrip("v")
|
||||
VEGA_VERSION = "5"
|
||||
VEGAEMBED_VERSION = "5"
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
# VegaLite v3 renderer logic
|
||||
# ==============================================================================
|
||||
|
||||
|
||||
# The MIME type for Vega-Lite 3.x releases.
|
||||
VEGALITE_MIME_TYPE = "application/vnd.vegalite.v3+json" # type: str
|
||||
|
||||
# The entry point group that can be used by other packages to declare other
|
||||
# renderers that will be auto-detected. Explicit registration is also
|
||||
# allowed by the PluginRegistery API.
|
||||
ENTRY_POINT_GROUP = "altair.vegalite.v3.renderer" # type: str
|
||||
|
||||
# The display message when rendering fails
|
||||
DEFAULT_DISPLAY = """\
|
||||
<VegaLite 3 object>
|
||||
|
||||
If you see this message, it means the renderer has not been properly enabled
|
||||
for the frontend that you are using. For more information, see
|
||||
https://altair-viz.github.io/user_guide/troubleshooting.html
|
||||
"""
|
||||
|
||||
renderers = RendererRegistry(entry_point_group=ENTRY_POINT_GROUP)
|
||||
|
||||
here = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
|
||||
def default_renderer(spec, **metadata):
|
||||
return default_renderer_base(spec, VEGALITE_MIME_TYPE, DEFAULT_DISPLAY, **metadata)
|
||||
|
||||
|
||||
def json_renderer(spec, **metadata):
|
||||
return json_renderer_base(spec, DEFAULT_DISPLAY, **metadata)
|
||||
|
||||
|
||||
def png_renderer(spec, **metadata):
|
||||
return spec_to_mimebundle(
|
||||
spec,
|
||||
format="png",
|
||||
mode="vega-lite",
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
**metadata,
|
||||
)
|
||||
|
||||
|
||||
def svg_renderer(spec, **metadata):
|
||||
return spec_to_mimebundle(
|
||||
spec,
|
||||
format="svg",
|
||||
mode="vega-lite",
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
**metadata,
|
||||
)
|
||||
|
||||
|
||||
colab_renderer = HTMLRenderer(
|
||||
mode="vega-lite",
|
||||
fullhtml=True,
|
||||
requirejs=False,
|
||||
output_div="altair-viz",
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
)
|
||||
|
||||
zeppelin_renderer = HTMLRenderer(
|
||||
mode="vega-lite",
|
||||
fullhtml=True,
|
||||
requirejs=False,
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
)
|
||||
|
||||
kaggle_renderer = HTMLRenderer(
|
||||
mode="vega-lite",
|
||||
fullhtml=False,
|
||||
requirejs=True,
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
)
|
||||
|
||||
html_renderer = HTMLRenderer(
|
||||
mode="vega-lite",
|
||||
template="universal",
|
||||
vega_version=VEGA_VERSION,
|
||||
vegaembed_version=VEGAEMBED_VERSION,
|
||||
vegalite_version=VEGALITE_VERSION,
|
||||
)
|
||||
|
||||
renderers.register("default", default_renderer)
|
||||
renderers.register("html", html_renderer)
|
||||
renderers.register("jupyterlab", default_renderer)
|
||||
renderers.register("nteract", default_renderer)
|
||||
renderers.register("colab", colab_renderer)
|
||||
renderers.register("kaggle", kaggle_renderer)
|
||||
renderers.register("json", json_renderer)
|
||||
renderers.register("png", png_renderer)
|
||||
renderers.register("svg", svg_renderer)
|
||||
renderers.register("zeppelin", zeppelin_renderer)
|
||||
renderers.enable("default")
|
||||
|
||||
|
||||
class VegaLite(Displayable):
|
||||
"""An IPython/Jupyter display class for rendering VegaLite 3."""
|
||||
|
||||
renderers = renderers
|
||||
schema_path = (__name__, "schema/vega-lite-schema.json")
|
||||
|
||||
|
||||
def vegalite(spec, validate=True):
|
||||
"""Render and optionally validate a VegaLite 3 spec.
|
||||
|
||||
This will use the currently enabled renderer to render the spec.
|
||||
|
||||
Parameters
|
||||
==========
|
||||
spec: dict
|
||||
A fully compliant VegaLite 3 spec, with the data portion fully processed.
|
||||
validate: bool
|
||||
Should the spec be validated against the VegaLite 3 schema?
|
||||
"""
|
||||
from IPython.display import display
|
||||
|
||||
display(VegaLite(spec, validate=validate))
|
@ -0,0 +1,5 @@
|
||||
# flake8: noqa
|
||||
from .core import *
|
||||
from .channels import *
|
||||
SCHEMA_VERSION = 'v3.4.0'
|
||||
SCHEMA_URL = 'https://vega.github.io/schema/vega-lite/v3.4.0.json'
|
5324
.venv/Lib/site-packages/altair/vegalite/v3/schema/channels.py
Normal file
5324
.venv/Lib/site-packages/altair/vegalite/v3/schema/channels.py
Normal file
File diff suppressed because it is too large
Load Diff
16039
.venv/Lib/site-packages/altair/vegalite/v3/schema/core.py
Normal file
16039
.venv/Lib/site-packages/altair/vegalite/v3/schema/core.py
Normal file
File diff suppressed because it is too large
Load Diff
807
.venv/Lib/site-packages/altair/vegalite/v3/schema/mixins.py
Normal file
807
.venv/Lib/site-packages/altair/vegalite/v3/schema/mixins.py
Normal file
@ -0,0 +1,807 @@
|
||||
# The contents of this file are automatically written by
|
||||
# tools/generate_schema_wrapper.py. Do not modify directly.
|
||||
from . import core
|
||||
from altair.utils import use_signature
|
||||
from altair.utils.schemapi import Undefined
|
||||
|
||||
|
||||
class MarkMethodMixin(object):
|
||||
"""A mixin class that defines mark methods"""
|
||||
|
||||
def mark_area(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'area'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="area", **kwds)
|
||||
else:
|
||||
copy.mark = "area"
|
||||
return copy
|
||||
|
||||
def mark_bar(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'bar'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="bar", **kwds)
|
||||
else:
|
||||
copy.mark = "bar"
|
||||
return copy
|
||||
|
||||
def mark_line(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'line'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="line", **kwds)
|
||||
else:
|
||||
copy.mark = "line"
|
||||
return copy
|
||||
|
||||
def mark_trail(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined,
|
||||
shape=Undefined, size=Undefined, stroke=Undefined, strokeCap=Undefined,
|
||||
strokeDash=Undefined, strokeDashOffset=Undefined, strokeJoin=Undefined,
|
||||
strokeMiterLimit=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined,
|
||||
style=Undefined, tension=Undefined, text=Undefined, theta=Undefined,
|
||||
thickness=Undefined, tooltip=Undefined, width=Undefined, x=Undefined, x2=Undefined,
|
||||
x2Offset=Undefined, xOffset=Undefined, y=Undefined, y2=Undefined, y2Offset=Undefined,
|
||||
yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'trail'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="trail", **kwds)
|
||||
else:
|
||||
copy.mark = "trail"
|
||||
return copy
|
||||
|
||||
def mark_point(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined,
|
||||
shape=Undefined, size=Undefined, stroke=Undefined, strokeCap=Undefined,
|
||||
strokeDash=Undefined, strokeDashOffset=Undefined, strokeJoin=Undefined,
|
||||
strokeMiterLimit=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined,
|
||||
style=Undefined, tension=Undefined, text=Undefined, theta=Undefined,
|
||||
thickness=Undefined, tooltip=Undefined, width=Undefined, x=Undefined, x2=Undefined,
|
||||
x2Offset=Undefined, xOffset=Undefined, y=Undefined, y2=Undefined, y2Offset=Undefined,
|
||||
yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'point'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="point", **kwds)
|
||||
else:
|
||||
copy.mark = "point"
|
||||
return copy
|
||||
|
||||
def mark_text(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'text'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="text", **kwds)
|
||||
else:
|
||||
copy.mark = "text"
|
||||
return copy
|
||||
|
||||
def mark_tick(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'tick'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="tick", **kwds)
|
||||
else:
|
||||
copy.mark = "tick"
|
||||
return copy
|
||||
|
||||
def mark_rect(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'rect'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="rect", **kwds)
|
||||
else:
|
||||
copy.mark = "rect"
|
||||
return copy
|
||||
|
||||
def mark_rule(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined, shape=Undefined,
|
||||
size=Undefined, stroke=Undefined, strokeCap=Undefined, strokeDash=Undefined,
|
||||
strokeDashOffset=Undefined, strokeJoin=Undefined, strokeMiterLimit=Undefined,
|
||||
strokeOpacity=Undefined, strokeWidth=Undefined, style=Undefined, tension=Undefined,
|
||||
text=Undefined, theta=Undefined, thickness=Undefined, tooltip=Undefined,
|
||||
width=Undefined, x=Undefined, x2=Undefined, x2Offset=Undefined, xOffset=Undefined,
|
||||
y=Undefined, y2=Undefined, y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'rule'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="rule", **kwds)
|
||||
else:
|
||||
copy.mark = "rule"
|
||||
return copy
|
||||
|
||||
def mark_circle(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined,
|
||||
shape=Undefined, size=Undefined, stroke=Undefined, strokeCap=Undefined,
|
||||
strokeDash=Undefined, strokeDashOffset=Undefined, strokeJoin=Undefined,
|
||||
strokeMiterLimit=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined,
|
||||
style=Undefined, tension=Undefined, text=Undefined, theta=Undefined,
|
||||
thickness=Undefined, tooltip=Undefined, width=Undefined, x=Undefined, x2=Undefined,
|
||||
x2Offset=Undefined, xOffset=Undefined, y=Undefined, y2=Undefined,
|
||||
y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'circle'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="circle", **kwds)
|
||||
else:
|
||||
copy.mark = "circle"
|
||||
return copy
|
||||
|
||||
def mark_square(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined,
|
||||
shape=Undefined, size=Undefined, stroke=Undefined, strokeCap=Undefined,
|
||||
strokeDash=Undefined, strokeDashOffset=Undefined, strokeJoin=Undefined,
|
||||
strokeMiterLimit=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined,
|
||||
style=Undefined, tension=Undefined, text=Undefined, theta=Undefined,
|
||||
thickness=Undefined, tooltip=Undefined, width=Undefined, x=Undefined, x2=Undefined,
|
||||
x2Offset=Undefined, xOffset=Undefined, y=Undefined, y2=Undefined,
|
||||
y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'square'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="square", **kwds)
|
||||
else:
|
||||
copy.mark = "square"
|
||||
return copy
|
||||
|
||||
def mark_geoshape(self, align=Undefined, angle=Undefined, baseline=Undefined, binSpacing=Undefined,
|
||||
clip=Undefined, color=Undefined, cornerRadius=Undefined, cursor=Undefined,
|
||||
dir=Undefined, dx=Undefined, dy=Undefined, ellipsis=Undefined, fill=Undefined,
|
||||
fillOpacity=Undefined, filled=Undefined, font=Undefined, fontSize=Undefined,
|
||||
fontStyle=Undefined, fontWeight=Undefined, height=Undefined, href=Undefined,
|
||||
interpolate=Undefined, limit=Undefined, line=Undefined, opacity=Undefined,
|
||||
order=Undefined, orient=Undefined, point=Undefined, radius=Undefined,
|
||||
shape=Undefined, size=Undefined, stroke=Undefined, strokeCap=Undefined,
|
||||
strokeDash=Undefined, strokeDashOffset=Undefined, strokeJoin=Undefined,
|
||||
strokeMiterLimit=Undefined, strokeOpacity=Undefined, strokeWidth=Undefined,
|
||||
style=Undefined, tension=Undefined, text=Undefined, theta=Undefined,
|
||||
thickness=Undefined, tooltip=Undefined, width=Undefined, x=Undefined,
|
||||
x2=Undefined, x2Offset=Undefined, xOffset=Undefined, y=Undefined, y2=Undefined,
|
||||
y2Offset=Undefined, yOffset=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'geoshape'
|
||||
|
||||
For information on additional arguments, see :class:`MarkDef`
|
||||
"""
|
||||
kwds = dict(align=align, angle=angle, baseline=baseline, binSpacing=binSpacing, clip=clip,
|
||||
color=color, cornerRadius=cornerRadius, cursor=cursor, dir=dir, dx=dx, dy=dy,
|
||||
ellipsis=ellipsis, fill=fill, fillOpacity=fillOpacity, filled=filled, font=font,
|
||||
fontSize=fontSize, fontStyle=fontStyle, fontWeight=fontWeight, height=height,
|
||||
href=href, interpolate=interpolate, limit=limit, line=line, opacity=opacity,
|
||||
order=order, orient=orient, point=point, radius=radius, shape=shape, size=size,
|
||||
stroke=stroke, strokeCap=strokeCap, strokeDash=strokeDash,
|
||||
strokeDashOffset=strokeDashOffset, strokeJoin=strokeJoin,
|
||||
strokeMiterLimit=strokeMiterLimit, strokeOpacity=strokeOpacity,
|
||||
strokeWidth=strokeWidth, style=style, tension=tension, text=text, theta=theta,
|
||||
thickness=thickness, tooltip=tooltip, width=width, x=x, x2=x2, x2Offset=x2Offset,
|
||||
xOffset=xOffset, y=y, y2=y2, y2Offset=y2Offset, yOffset=yOffset, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.MarkDef(type="geoshape", **kwds)
|
||||
else:
|
||||
copy.mark = "geoshape"
|
||||
return copy
|
||||
|
||||
def mark_boxplot(self, box=Undefined, clip=Undefined, color=Undefined, extent=Undefined,
|
||||
median=Undefined, opacity=Undefined, orient=Undefined, outliers=Undefined,
|
||||
rule=Undefined, size=Undefined, ticks=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'boxplot'
|
||||
|
||||
For information on additional arguments, see :class:`BoxPlotDef`
|
||||
"""
|
||||
kwds = dict(box=box, clip=clip, color=color, extent=extent, median=median, opacity=opacity,
|
||||
orient=orient, outliers=outliers, rule=rule, size=size, ticks=ticks, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.BoxPlotDef(type="boxplot", **kwds)
|
||||
else:
|
||||
copy.mark = "boxplot"
|
||||
return copy
|
||||
|
||||
def mark_errorbar(self, clip=Undefined, color=Undefined, extent=Undefined, opacity=Undefined,
|
||||
orient=Undefined, rule=Undefined, ticks=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'errorbar'
|
||||
|
||||
For information on additional arguments, see :class:`ErrorBarDef`
|
||||
"""
|
||||
kwds = dict(clip=clip, color=color, extent=extent, opacity=opacity, orient=orient, rule=rule,
|
||||
ticks=ticks, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.ErrorBarDef(type="errorbar", **kwds)
|
||||
else:
|
||||
copy.mark = "errorbar"
|
||||
return copy
|
||||
|
||||
def mark_errorband(self, band=Undefined, borders=Undefined, clip=Undefined, color=Undefined,
|
||||
extent=Undefined, interpolate=Undefined, opacity=Undefined, orient=Undefined,
|
||||
tension=Undefined, **kwds):
|
||||
"""Set the chart's mark to 'errorband'
|
||||
|
||||
For information on additional arguments, see :class:`ErrorBandDef`
|
||||
"""
|
||||
kwds = dict(band=band, borders=borders, clip=clip, color=color, extent=extent,
|
||||
interpolate=interpolate, opacity=opacity, orient=orient, tension=tension, **kwds)
|
||||
copy = self.copy(deep=False)
|
||||
if any(val is not Undefined for val in kwds.values()):
|
||||
copy.mark = core.ErrorBandDef(type="errorband", **kwds)
|
||||
else:
|
||||
copy.mark = "errorband"
|
||||
return copy
|
||||
|
||||
|
||||
class ConfigMethodMixin(object):
|
||||
"""A mixin class that defines config methods"""
|
||||
|
||||
@use_signature(core.Config)
|
||||
def configure(self, *args, **kwargs):
|
||||
copy = self.copy(deep=False)
|
||||
copy.config = core.Config(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AreaConfig)
|
||||
def configure_area(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["area"] = core.AreaConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axis(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axis"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisBand(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisBand"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisBottom(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisBottom"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisLeft(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisLeft"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisRight(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisRight"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisTop(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisTop"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisX(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisX"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.AxisConfig)
|
||||
def configure_axisY(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["axisY"] = core.AxisConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.RectConfig)
|
||||
def configure_bar(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["bar"] = core.RectConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.BoxPlotConfig)
|
||||
def configure_boxplot(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["boxplot"] = core.BoxPlotConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_circle(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["circle"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.CompositionConfig)
|
||||
def configure_concat(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["concat"] = core.CompositionConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.ErrorBandConfig)
|
||||
def configure_errorband(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["errorband"] = core.ErrorBandConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.ErrorBarConfig)
|
||||
def configure_errorbar(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["errorbar"] = core.ErrorBarConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.CompositionConfig)
|
||||
def configure_facet(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["facet"] = core.CompositionConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_geoshape(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["geoshape"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.HeaderConfig)
|
||||
def configure_header(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["header"] = core.HeaderConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.HeaderConfig)
|
||||
def configure_headerColumn(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["headerColumn"] = core.HeaderConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.HeaderConfig)
|
||||
def configure_headerFacet(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["headerFacet"] = core.HeaderConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.HeaderConfig)
|
||||
def configure_headerRow(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["headerRow"] = core.HeaderConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.LegendConfig)
|
||||
def configure_legend(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["legend"] = core.LegendConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.LineConfig)
|
||||
def configure_line(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["line"] = core.LineConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_mark(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["mark"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_point(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["point"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.ProjectionConfig)
|
||||
def configure_projection(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["projection"] = core.ProjectionConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.RangeConfig)
|
||||
def configure_range(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["range"] = core.RangeConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.RectConfig)
|
||||
def configure_rect(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["rect"] = core.RectConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.CompositionConfig)
|
||||
def configure_repeat(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["repeat"] = core.CompositionConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_rule(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["rule"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.ScaleConfig)
|
||||
def configure_scale(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["scale"] = core.ScaleConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.SelectionConfig)
|
||||
def configure_selection(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["selection"] = core.SelectionConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.MarkConfig)
|
||||
def configure_square(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["square"] = core.MarkConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.TextConfig)
|
||||
def configure_text(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["text"] = core.TextConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.TickConfig)
|
||||
def configure_tick(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["tick"] = core.TickConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.TitleConfig)
|
||||
def configure_title(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["title"] = core.TitleConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.LineConfig)
|
||||
def configure_trail(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["trail"] = core.LineConfig(*args, **kwargs)
|
||||
return copy
|
||||
|
||||
@use_signature(core.ViewConfig)
|
||||
def configure_view(self, *args, **kwargs):
|
||||
copy = self.copy(deep=['config'])
|
||||
if copy.config is Undefined:
|
||||
copy.config = core.Config()
|
||||
copy.config["view"] = core.ViewConfig(*args, **kwargs)
|
||||
return copy
|
13315
.venv/Lib/site-packages/altair/vegalite/v3/schema/vega-lite-schema.json
Normal file
13315
.venv/Lib/site-packages/altair/vegalite/v3/schema/vega-lite-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
937
.venv/Lib/site-packages/altair/vegalite/v3/tests/test_api.py
Normal file
937
.venv/Lib/site-packages/altair/vegalite/v3/tests/test_api.py
Normal file
@ -0,0 +1,937 @@
|
||||
"""Unit tests for altair API"""
|
||||
|
||||
import io
|
||||
import json
|
||||
import operator
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import jsonschema
|
||||
import pytest
|
||||
import pandas as pd
|
||||
|
||||
import altair.vegalite.v3 as alt
|
||||
from altair.utils import AltairDeprecationWarning
|
||||
|
||||
try:
|
||||
import altair_saver # noqa: F401
|
||||
except ImportError:
|
||||
altair_saver = None
|
||||
|
||||
|
||||
def getargs(*args, **kwargs):
|
||||
return args, kwargs
|
||||
|
||||
|
||||
OP_DICT = {
|
||||
"layer": operator.add,
|
||||
"hconcat": operator.or_,
|
||||
"vconcat": operator.and_,
|
||||
}
|
||||
|
||||
|
||||
def _make_chart_type(chart_type):
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"x": [28, 55, 43, 91, 81, 53, 19, 87],
|
||||
"y": [43, 91, 81, 53, 19, 87, 52, 28],
|
||||
"color": list("AAAABBBB"),
|
||||
}
|
||||
)
|
||||
base = (
|
||||
alt.Chart(data)
|
||||
.mark_point()
|
||||
.encode(
|
||||
x="x",
|
||||
y="y",
|
||||
color="color",
|
||||
)
|
||||
)
|
||||
|
||||
if chart_type in ["layer", "hconcat", "vconcat", "concat"]:
|
||||
func = getattr(alt, chart_type)
|
||||
return func(base.mark_square(), base.mark_circle())
|
||||
elif chart_type == "facet":
|
||||
return base.facet("color")
|
||||
elif chart_type == "facet_encoding":
|
||||
return base.encode(facet="color")
|
||||
elif chart_type == "repeat":
|
||||
return base.encode(alt.X(alt.repeat(), type="quantitative")).repeat(["x", "y"])
|
||||
elif chart_type == "chart":
|
||||
return base
|
||||
else:
|
||||
raise ValueError("chart_type='{}' is not recognized".format(chart_type))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def basic_chart():
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
|
||||
"b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
|
||||
}
|
||||
)
|
||||
|
||||
return alt.Chart(data).mark_bar().encode(x="a", y="b")
|
||||
|
||||
|
||||
def test_chart_data_types():
|
||||
def Chart(data):
|
||||
return alt.Chart(data).mark_point().encode(x="x:Q", y="y:Q")
|
||||
|
||||
# Url Data
|
||||
data = "/path/to/my/data.csv"
|
||||
dct = Chart(data).to_dict()
|
||||
assert dct["data"] == {"url": data}
|
||||
|
||||
# Dict Data
|
||||
data = {"values": [{"x": 1, "y": 2}, {"x": 2, "y": 3}]}
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct = Chart(data).to_dict()
|
||||
assert dct["data"] == data
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct = Chart(data).to_dict()
|
||||
name = dct["data"]["name"]
|
||||
assert dct["datasets"][name] == data["values"]
|
||||
|
||||
# DataFrame data
|
||||
data = pd.DataFrame({"x": range(5), "y": range(5)})
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct = Chart(data).to_dict()
|
||||
assert dct["data"]["values"] == data.to_dict(orient="records")
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct = Chart(data).to_dict()
|
||||
name = dct["data"]["name"]
|
||||
assert dct["datasets"][name] == data.to_dict(orient="records")
|
||||
|
||||
# Named data object
|
||||
data = alt.NamedData(name="Foo")
|
||||
dct = Chart(data).to_dict()
|
||||
assert dct["data"] == {"name": "Foo"}
|
||||
|
||||
|
||||
def test_chart_infer_types():
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"x": pd.date_range("2012", periods=10, freq="Y"),
|
||||
"y": range(10),
|
||||
"c": list("abcabcabca"),
|
||||
}
|
||||
)
|
||||
|
||||
def _check_encodings(chart):
|
||||
dct = chart.to_dict()
|
||||
assert dct["encoding"]["x"]["type"] == "temporal"
|
||||
assert dct["encoding"]["x"]["field"] == "x"
|
||||
assert dct["encoding"]["y"]["type"] == "quantitative"
|
||||
assert dct["encoding"]["y"]["field"] == "y"
|
||||
assert dct["encoding"]["color"]["type"] == "nominal"
|
||||
assert dct["encoding"]["color"]["field"] == "c"
|
||||
|
||||
# Pass field names by keyword
|
||||
chart = alt.Chart(data).mark_point().encode(x="x", y="y", color="c")
|
||||
_check_encodings(chart)
|
||||
|
||||
# pass Channel objects by keyword
|
||||
chart = (
|
||||
alt.Chart(data)
|
||||
.mark_point()
|
||||
.encode(x=alt.X("x"), y=alt.Y("y"), color=alt.Color("c"))
|
||||
)
|
||||
_check_encodings(chart)
|
||||
|
||||
# pass Channel objects by value
|
||||
chart = alt.Chart(data).mark_point().encode(alt.X("x"), alt.Y("y"), alt.Color("c"))
|
||||
_check_encodings(chart)
|
||||
|
||||
# override default types
|
||||
chart = (
|
||||
alt.Chart(data)
|
||||
.mark_point()
|
||||
.encode(alt.X("x", type="nominal"), alt.Y("y", type="ordinal"))
|
||||
)
|
||||
dct = chart.to_dict()
|
||||
assert dct["encoding"]["x"]["type"] == "nominal"
|
||||
assert dct["encoding"]["y"]["type"] == "ordinal"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"args, kwargs",
|
||||
[
|
||||
getargs(detail=["value:Q", "name:N"], tooltip=["value:Q", "name:N"]),
|
||||
getargs(detail=["value", "name"], tooltip=["value", "name"]),
|
||||
getargs(alt.Detail(["value:Q", "name:N"]), alt.Tooltip(["value:Q", "name:N"])),
|
||||
getargs(alt.Detail(["value", "name"]), alt.Tooltip(["value", "name"])),
|
||||
getargs(
|
||||
[alt.Detail("value:Q"), alt.Detail("name:N")],
|
||||
[alt.Tooltip("value:Q"), alt.Tooltip("name:N")],
|
||||
),
|
||||
getargs(
|
||||
[alt.Detail("value"), alt.Detail("name")],
|
||||
[alt.Tooltip("value"), alt.Tooltip("name")],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_multiple_encodings(args, kwargs):
|
||||
df = pd.DataFrame({"value": [1, 2, 3], "name": ["A", "B", "C"]})
|
||||
encoding_dct = [
|
||||
{"field": "value", "type": "quantitative"},
|
||||
{"field": "name", "type": "nominal"},
|
||||
]
|
||||
chart = alt.Chart(df).mark_point().encode(*args, **kwargs)
|
||||
dct = chart.to_dict()
|
||||
assert dct["encoding"]["detail"] == encoding_dct
|
||||
assert dct["encoding"]["tooltip"] == encoding_dct
|
||||
|
||||
|
||||
def test_chart_operations():
|
||||
data = pd.DataFrame(
|
||||
{
|
||||
"x": pd.date_range("2012", periods=10, freq="Y"),
|
||||
"y": range(10),
|
||||
"c": list("abcabcabca"),
|
||||
}
|
||||
)
|
||||
chart1 = alt.Chart(data).mark_line().encode(x="x", y="y", color="c")
|
||||
chart2 = chart1.mark_point()
|
||||
chart3 = chart1.mark_circle()
|
||||
chart4 = chart1.mark_square()
|
||||
|
||||
chart = chart1 + chart2 + chart3
|
||||
assert isinstance(chart, alt.LayerChart)
|
||||
assert len(chart.layer) == 3
|
||||
chart += chart4
|
||||
assert len(chart.layer) == 4
|
||||
|
||||
chart = chart1 | chart2 | chart3
|
||||
assert isinstance(chart, alt.HConcatChart)
|
||||
assert len(chart.hconcat) == 3
|
||||
chart |= chart4
|
||||
assert len(chart.hconcat) == 4
|
||||
|
||||
chart = chart1 & chart2 & chart3
|
||||
assert isinstance(chart, alt.VConcatChart)
|
||||
assert len(chart.vconcat) == 3
|
||||
chart &= chart4
|
||||
assert len(chart.vconcat) == 4
|
||||
|
||||
|
||||
def test_selection_to_dict():
|
||||
brush = alt.selection(type="interval")
|
||||
|
||||
# test some value selections
|
||||
# Note: X and Y cannot have conditions
|
||||
alt.Chart("path/to/data.json").mark_point().encode(
|
||||
color=alt.condition(brush, alt.ColorValue("red"), alt.ColorValue("blue")),
|
||||
opacity=alt.condition(brush, alt.value(0.5), alt.value(1.0)),
|
||||
text=alt.condition(brush, alt.TextValue("foo"), alt.value("bar")),
|
||||
).to_dict()
|
||||
|
||||
# test some field selections
|
||||
# Note: X and Y cannot have conditions
|
||||
# Conditions cannot both be fields
|
||||
alt.Chart("path/to/data.json").mark_point().encode(
|
||||
color=alt.condition(brush, alt.Color("col1:N"), alt.value("blue")),
|
||||
opacity=alt.condition(brush, "col1:N", alt.value(0.5)),
|
||||
text=alt.condition(brush, alt.value("abc"), alt.Text("col2:N")),
|
||||
size=alt.condition(brush, alt.value(20), "col2:N"),
|
||||
).to_dict()
|
||||
|
||||
|
||||
def test_selection_expression():
|
||||
selection = alt.selection_single(fields=["value"])
|
||||
|
||||
assert isinstance(selection.value, alt.expr.Expression)
|
||||
assert selection.value.to_dict() == "{0}.value".format(selection.name)
|
||||
|
||||
assert isinstance(selection["value"], alt.expr.Expression)
|
||||
assert selection["value"].to_dict() == "{0}['value']".format(selection.name)
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
selection.__magic__
|
||||
|
||||
|
||||
@pytest.mark.parametrize("format", ["html", "json", "png", "svg", "pdf"])
|
||||
def test_save(format, basic_chart):
|
||||
if format in ["pdf", "png"]:
|
||||
out = io.BytesIO()
|
||||
mode = "rb"
|
||||
else:
|
||||
out = io.StringIO()
|
||||
mode = "r"
|
||||
|
||||
if format in ["svg", "png", "pdf"]:
|
||||
if not altair_saver:
|
||||
with pytest.raises(ValueError) as err:
|
||||
basic_chart.save(out, format=format)
|
||||
assert "github.com/altair-viz/altair_saver" in str(err.value)
|
||||
return
|
||||
elif format not in altair_saver.available_formats():
|
||||
with pytest.raises(ValueError) as err:
|
||||
basic_chart.save(out, format=format)
|
||||
assert f"No enabled saver found that supports format='{format}'" in str(
|
||||
err.value
|
||||
)
|
||||
return
|
||||
|
||||
basic_chart.save(out, format=format)
|
||||
out.seek(0)
|
||||
content = out.read()
|
||||
|
||||
if format == "json":
|
||||
assert "$schema" in json.loads(content)
|
||||
if format == "html":
|
||||
assert content.startswith("<!DOCTYPE html>")
|
||||
|
||||
fid, filename = tempfile.mkstemp(suffix="." + format)
|
||||
os.close(fid)
|
||||
|
||||
try:
|
||||
basic_chart.save(filename)
|
||||
with open(filename, mode) as f:
|
||||
assert f.read()[:1000] == content[:1000]
|
||||
finally:
|
||||
os.remove(filename)
|
||||
|
||||
|
||||
def test_facet_basic():
|
||||
# wrapped facet
|
||||
chart1 = (
|
||||
alt.Chart("data.csv")
|
||||
.mark_point()
|
||||
.encode(
|
||||
x="x:Q",
|
||||
y="y:Q",
|
||||
)
|
||||
.facet("category:N", columns=2)
|
||||
)
|
||||
|
||||
dct1 = chart1.to_dict()
|
||||
|
||||
assert dct1["facet"] == alt.Facet("category:N").to_dict()
|
||||
assert dct1["columns"] == 2
|
||||
assert dct1["data"] == alt.UrlData("data.csv").to_dict()
|
||||
|
||||
# explicit row/col facet
|
||||
chart2 = (
|
||||
alt.Chart("data.csv")
|
||||
.mark_point()
|
||||
.encode(
|
||||
x="x:Q",
|
||||
y="y:Q",
|
||||
)
|
||||
.facet(row="category1:Q", column="category2:Q")
|
||||
)
|
||||
|
||||
dct2 = chart2.to_dict()
|
||||
|
||||
assert dct2["facet"]["row"] == alt.Facet("category1:Q").to_dict()
|
||||
assert dct2["facet"]["column"] == alt.Facet("category2:Q").to_dict()
|
||||
assert "columns" not in dct2
|
||||
assert dct2["data"] == alt.UrlData("data.csv").to_dict()
|
||||
|
||||
|
||||
def test_facet_parse():
|
||||
chart = (
|
||||
alt.Chart("data.csv")
|
||||
.mark_point()
|
||||
.encode(x="x:Q", y="y:Q")
|
||||
.facet(row="row:N", column="column:O")
|
||||
)
|
||||
dct = chart.to_dict()
|
||||
assert dct["data"] == {"url": "data.csv"}
|
||||
assert "data" not in dct["spec"]
|
||||
assert dct["facet"] == {
|
||||
"column": {"field": "column", "type": "ordinal"},
|
||||
"row": {"field": "row", "type": "nominal"},
|
||||
}
|
||||
|
||||
|
||||
def test_facet_parse_data():
|
||||
data = pd.DataFrame({"x": range(5), "y": range(5), "row": list("abcab")})
|
||||
chart = (
|
||||
alt.Chart(data)
|
||||
.mark_point()
|
||||
.encode(x="x", y="y:O")
|
||||
.facet(row="row", column="column:O")
|
||||
)
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct = chart.to_dict()
|
||||
assert "values" in dct["data"]
|
||||
assert "data" not in dct["spec"]
|
||||
assert dct["facet"] == {
|
||||
"column": {"field": "column", "type": "ordinal"},
|
||||
"row": {"field": "row", "type": "nominal"},
|
||||
}
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct = chart.to_dict()
|
||||
assert "datasets" in dct
|
||||
assert "name" in dct["data"]
|
||||
assert "data" not in dct["spec"]
|
||||
assert dct["facet"] == {
|
||||
"column": {"field": "column", "type": "ordinal"},
|
||||
"row": {"field": "row", "type": "nominal"},
|
||||
}
|
||||
|
||||
|
||||
def test_selection():
|
||||
# test instantiation of selections
|
||||
interval = alt.selection_interval(name="selec_1")
|
||||
assert interval.selection.type == "interval"
|
||||
assert interval.name == "selec_1"
|
||||
|
||||
single = alt.selection_single(name="selec_2")
|
||||
assert single.selection.type == "single"
|
||||
assert single.name == "selec_2"
|
||||
|
||||
multi = alt.selection_multi(name="selec_3")
|
||||
assert multi.selection.type == "multi"
|
||||
assert multi.name == "selec_3"
|
||||
|
||||
# test adding to chart
|
||||
chart = alt.Chart().add_selection(single)
|
||||
chart = chart.add_selection(multi, interval)
|
||||
assert set(chart.selection.keys()) == {"selec_1", "selec_2", "selec_3"}
|
||||
|
||||
# test logical operations
|
||||
assert isinstance(single & multi, alt.Selection)
|
||||
assert isinstance(single | multi, alt.Selection)
|
||||
assert isinstance(~single, alt.Selection)
|
||||
assert isinstance((single & multi)[0].group, alt.SelectionAnd)
|
||||
assert isinstance((single | multi)[0].group, alt.SelectionOr)
|
||||
assert isinstance((~single)[0].group, alt.SelectionNot)
|
||||
|
||||
# test that default names increment (regression for #1454)
|
||||
sel1 = alt.selection_single()
|
||||
sel2 = alt.selection_multi()
|
||||
sel3 = alt.selection_interval()
|
||||
names = {s.name for s in (sel1, sel2, sel3)}
|
||||
assert len(names) == 3
|
||||
|
||||
|
||||
def test_transforms():
|
||||
# aggregate transform
|
||||
agg1 = alt.AggregatedFieldDef(**{"as": "x1", "op": "mean", "field": "y"})
|
||||
agg2 = alt.AggregatedFieldDef(**{"as": "x2", "op": "median", "field": "z"})
|
||||
chart = alt.Chart().transform_aggregate([agg1], ["foo"], x2="median(z)")
|
||||
kwds = dict(aggregate=[agg1, agg2], groupby=["foo"])
|
||||
assert chart.transform == [alt.AggregateTransform(**kwds)]
|
||||
|
||||
# bin transform
|
||||
chart = alt.Chart().transform_bin("binned", field="field", bin=True)
|
||||
kwds = {"as": "binned", "field": "field", "bin": True}
|
||||
assert chart.transform == [alt.BinTransform(**kwds)]
|
||||
|
||||
# calcualte transform
|
||||
chart = alt.Chart().transform_calculate("calc", "datum.a * 4")
|
||||
kwds = {"as": "calc", "calculate": "datum.a * 4"}
|
||||
assert chart.transform == [alt.CalculateTransform(**kwds)]
|
||||
|
||||
# impute transform
|
||||
chart = alt.Chart().transform_impute("field", "key", groupby=["x"])
|
||||
kwds = {"impute": "field", "key": "key", "groupby": ["x"]}
|
||||
assert chart.transform == [alt.ImputeTransform(**kwds)]
|
||||
|
||||
# joinaggregate transform
|
||||
chart = alt.Chart().transform_joinaggregate(min="min(x)", groupby=["key"])
|
||||
kwds = {
|
||||
"joinaggregate": [
|
||||
alt.JoinAggregateFieldDef(field="x", op="min", **{"as": "min"})
|
||||
],
|
||||
"groupby": ["key"],
|
||||
}
|
||||
assert chart.transform == [alt.JoinAggregateTransform(**kwds)]
|
||||
|
||||
# filter transform
|
||||
chart = alt.Chart().transform_filter("datum.a < 4")
|
||||
assert chart.transform == [alt.FilterTransform(filter="datum.a < 4")]
|
||||
|
||||
# flatten transform
|
||||
chart = alt.Chart().transform_flatten(["A", "B"], ["X", "Y"])
|
||||
kwds = {"as": ["X", "Y"], "flatten": ["A", "B"]}
|
||||
assert chart.transform == [alt.FlattenTransform(**kwds)]
|
||||
|
||||
# fold transform
|
||||
chart = alt.Chart().transform_fold(["A", "B", "C"], as_=["key", "val"])
|
||||
kwds = {"as": ["key", "val"], "fold": ["A", "B", "C"]}
|
||||
assert chart.transform == [alt.FoldTransform(**kwds)]
|
||||
|
||||
# lookup transform
|
||||
lookup_data = alt.LookupData(alt.UrlData("foo.csv"), "id", ["rate"])
|
||||
chart = alt.Chart().transform_lookup(
|
||||
from_=lookup_data, as_="a", lookup="a", default="b"
|
||||
)
|
||||
kwds = {"from": lookup_data, "as": "a", "lookup": "a", "default": "b"}
|
||||
assert chart.transform == [alt.LookupTransform(**kwds)]
|
||||
|
||||
# sample transform
|
||||
chart = alt.Chart().transform_sample()
|
||||
assert chart.transform == [alt.SampleTransform(1000)]
|
||||
|
||||
# stack transform
|
||||
chart = alt.Chart().transform_stack("stacked", "x", groupby=["y"])
|
||||
assert chart.transform == [
|
||||
alt.StackTransform(stack="x", groupby=["y"], **{"as": "stacked"})
|
||||
]
|
||||
|
||||
# timeUnit transform
|
||||
chart = alt.Chart().transform_timeunit("foo", field="x", timeUnit="date")
|
||||
kwds = {"as": "foo", "field": "x", "timeUnit": "date"}
|
||||
assert chart.transform == [alt.TimeUnitTransform(**kwds)]
|
||||
|
||||
# window transform
|
||||
chart = alt.Chart().transform_window(xsum="sum(x)", ymin="min(y)", frame=[None, 0])
|
||||
window = [
|
||||
alt.WindowFieldDef(**{"as": "xsum", "field": "x", "op": "sum"}),
|
||||
alt.WindowFieldDef(**{"as": "ymin", "field": "y", "op": "min"}),
|
||||
]
|
||||
|
||||
# kwargs don't maintain order in Python < 3.6, so window list can
|
||||
# be reversed
|
||||
assert chart.transform == [
|
||||
alt.WindowTransform(frame=[None, 0], window=window)
|
||||
] or chart.transform == [alt.WindowTransform(frame=[None, 0], window=window[::-1])]
|
||||
|
||||
|
||||
def test_filter_transform_selection_predicates():
|
||||
selector1 = alt.selection_interval(name="s1")
|
||||
selector2 = alt.selection_interval(name="s2")
|
||||
base = alt.Chart("data.txt").mark_point()
|
||||
|
||||
chart = base.transform_filter(selector1)
|
||||
assert chart.to_dict()["transform"] == [{"filter": {"selection": "s1"}}]
|
||||
|
||||
chart = base.transform_filter(~selector1)
|
||||
assert chart.to_dict()["transform"] == [{"filter": {"selection": {"not": "s1"}}}]
|
||||
|
||||
chart = base.transform_filter(selector1 & selector2)
|
||||
assert chart.to_dict()["transform"] == [
|
||||
{"filter": {"selection": {"and": ["s1", "s2"]}}}
|
||||
]
|
||||
|
||||
chart = base.transform_filter(selector1 | selector2)
|
||||
assert chart.to_dict()["transform"] == [
|
||||
{"filter": {"selection": {"or": ["s1", "s2"]}}}
|
||||
]
|
||||
|
||||
chart = base.transform_filter(selector1 | ~selector2)
|
||||
assert chart.to_dict()["transform"] == [
|
||||
{"filter": {"selection": {"or": ["s1", {"not": "s2"}]}}}
|
||||
]
|
||||
|
||||
chart = base.transform_filter(~selector1 | ~selector2)
|
||||
assert chart.to_dict()["transform"] == [
|
||||
{"filter": {"selection": {"or": [{"not": "s1"}, {"not": "s2"}]}}}
|
||||
]
|
||||
|
||||
chart = base.transform_filter(~(selector1 & selector2))
|
||||
assert chart.to_dict()["transform"] == [
|
||||
{"filter": {"selection": {"not": {"and": ["s1", "s2"]}}}}
|
||||
]
|
||||
|
||||
|
||||
def test_resolve_methods():
|
||||
chart = alt.LayerChart().resolve_axis(x="shared", y="independent")
|
||||
assert chart.resolve == alt.Resolve(
|
||||
axis=alt.AxisResolveMap(x="shared", y="independent")
|
||||
)
|
||||
|
||||
chart = alt.LayerChart().resolve_legend(color="shared", fill="independent")
|
||||
assert chart.resolve == alt.Resolve(
|
||||
legend=alt.LegendResolveMap(color="shared", fill="independent")
|
||||
)
|
||||
|
||||
chart = alt.LayerChart().resolve_scale(x="shared", y="independent")
|
||||
assert chart.resolve == alt.Resolve(
|
||||
scale=alt.ScaleResolveMap(x="shared", y="independent")
|
||||
)
|
||||
|
||||
|
||||
def test_layer_encodings():
|
||||
chart = alt.LayerChart().encode(x="column:Q")
|
||||
assert chart.encoding.x == alt.X(shorthand="column:Q")
|
||||
|
||||
|
||||
def test_add_selection():
|
||||
selections = [
|
||||
alt.selection_interval(),
|
||||
alt.selection_single(),
|
||||
alt.selection_multi(),
|
||||
]
|
||||
chart = (
|
||||
alt.Chart()
|
||||
.mark_point()
|
||||
.add_selection(selections[0])
|
||||
.add_selection(selections[1], selections[2])
|
||||
)
|
||||
expected = {s.name: s.selection for s in selections}
|
||||
assert chart.selection == expected
|
||||
|
||||
|
||||
def test_repeat_add_selections():
|
||||
base = alt.Chart("data.csv").mark_point()
|
||||
selection = alt.selection_single()
|
||||
chart1 = base.add_selection(selection).repeat(list("ABC"))
|
||||
chart2 = base.repeat(list("ABC")).add_selection(selection)
|
||||
assert chart1.to_dict() == chart2.to_dict()
|
||||
|
||||
|
||||
def test_facet_add_selections():
|
||||
base = alt.Chart("data.csv").mark_point()
|
||||
selection = alt.selection_single()
|
||||
chart1 = base.add_selection(selection).facet("val:Q")
|
||||
chart2 = base.facet("val:Q").add_selection(selection)
|
||||
assert chart1.to_dict() == chart2.to_dict()
|
||||
|
||||
|
||||
def test_layer_add_selection():
|
||||
base = alt.Chart("data.csv").mark_point()
|
||||
selection = alt.selection_single()
|
||||
chart1 = alt.layer(base.add_selection(selection), base)
|
||||
chart2 = alt.layer(base, base).add_selection(selection)
|
||||
assert chart1.to_dict() == chart2.to_dict()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("charttype", [alt.concat, alt.hconcat, alt.vconcat])
|
||||
def test_compound_add_selections(charttype):
|
||||
base = alt.Chart("data.csv").mark_point()
|
||||
selection = alt.selection_single()
|
||||
chart1 = charttype(base.add_selection(selection), base.add_selection(selection))
|
||||
chart2 = charttype(base, base).add_selection(selection)
|
||||
assert chart1.to_dict() == chart2.to_dict()
|
||||
|
||||
|
||||
def test_selection_property():
|
||||
sel = alt.selection_interval()
|
||||
chart = alt.Chart("data.csv").mark_point().properties(selection=sel)
|
||||
|
||||
assert list(chart["selection"].keys()) == [sel.name]
|
||||
|
||||
|
||||
def test_LookupData():
|
||||
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
|
||||
lookup = alt.LookupData(data=df, key="x")
|
||||
|
||||
dct = lookup.to_dict()
|
||||
assert dct["key"] == "x"
|
||||
assert dct["data"] == {
|
||||
"values": [{"x": 1, "y": 4}, {"x": 2, "y": 5}, {"x": 3, "y": 6}]
|
||||
}
|
||||
|
||||
|
||||
def test_themes():
|
||||
chart = alt.Chart("foo.txt").mark_point()
|
||||
active = alt.themes.active
|
||||
|
||||
try:
|
||||
alt.themes.enable("default")
|
||||
assert chart.to_dict()["config"] == {
|
||||
"mark": {"tooltip": None},
|
||||
"view": {"width": 400, "height": 300},
|
||||
}
|
||||
|
||||
alt.themes.enable("opaque")
|
||||
assert chart.to_dict()["config"] == {
|
||||
"background": "white",
|
||||
"mark": {"tooltip": None},
|
||||
"view": {"width": 400, "height": 300},
|
||||
}
|
||||
|
||||
alt.themes.enable("none")
|
||||
assert "config" not in chart.to_dict()
|
||||
|
||||
finally:
|
||||
# re-enable the original active theme
|
||||
alt.themes.enable(active)
|
||||
|
||||
|
||||
def test_chart_from_dict():
|
||||
base = alt.Chart("data.csv").mark_point().encode(x="x:Q", y="y:Q")
|
||||
|
||||
charts = [
|
||||
base,
|
||||
base + base,
|
||||
base | base,
|
||||
base & base,
|
||||
base.facet("c:N"),
|
||||
(base + base).facet(row="c:N", data="data.csv"),
|
||||
base.repeat(["c", "d"]),
|
||||
(base + base).repeat(row=["c", "d"]),
|
||||
]
|
||||
|
||||
for chart in charts:
|
||||
print(chart)
|
||||
chart_out = alt.Chart.from_dict(chart.to_dict())
|
||||
assert type(chart_out) is type(chart)
|
||||
|
||||
# test that an invalid spec leads to a schema validation error
|
||||
with pytest.raises(jsonschema.ValidationError):
|
||||
alt.Chart.from_dict({"invalid": "spec"})
|
||||
|
||||
|
||||
def test_consolidate_datasets(basic_chart):
|
||||
subchart1 = basic_chart
|
||||
subchart2 = basic_chart.copy()
|
||||
subchart2.data = basic_chart.data.copy()
|
||||
chart = subchart1 | subchart2
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct_consolidated = chart.to_dict()
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct_standard = chart.to_dict()
|
||||
|
||||
assert "datasets" in dct_consolidated
|
||||
assert "datasets" not in dct_standard
|
||||
|
||||
datasets = dct_consolidated["datasets"]
|
||||
|
||||
# two dataset copies should be recognized as duplicates
|
||||
assert len(datasets) == 1
|
||||
|
||||
# make sure data matches original & names are correct
|
||||
name, data = datasets.popitem()
|
||||
|
||||
for spec in dct_standard["hconcat"]:
|
||||
assert spec["data"]["values"] == data
|
||||
|
||||
for spec in dct_consolidated["hconcat"]:
|
||||
assert spec["data"] == {"name": name}
|
||||
|
||||
|
||||
def test_consolidate_InlineData():
|
||||
data = alt.InlineData(
|
||||
values=[{"a": 1, "b": 1}, {"a": 2, "b": 2}], format={"type": "csv"}
|
||||
)
|
||||
chart = alt.Chart(data).mark_point()
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct = chart.to_dict()
|
||||
assert dct["data"]["format"] == data.format
|
||||
assert dct["data"]["values"] == data.values
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct = chart.to_dict()
|
||||
assert dct["data"]["format"] == data.format
|
||||
assert list(dct["datasets"].values())[0] == data.values
|
||||
|
||||
data = alt.InlineData(values=[], name="runtime_data")
|
||||
chart = alt.Chart(data).mark_point()
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
dct = chart.to_dict()
|
||||
assert dct["data"] == data.to_dict()
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=True):
|
||||
dct = chart.to_dict()
|
||||
assert dct["data"] == data.to_dict()
|
||||
|
||||
|
||||
def test_deprecated_encodings():
|
||||
base = alt.Chart("data.txt").mark_point()
|
||||
|
||||
with pytest.warns(AltairDeprecationWarning) as record:
|
||||
chart1 = base.encode(strokeOpacity=alt.Strokeopacity("x:Q")).to_dict()
|
||||
assert "alt.StrokeOpacity" in record[0].message.args[0]
|
||||
chart2 = base.encode(strokeOpacity=alt.StrokeOpacity("x:Q")).to_dict()
|
||||
|
||||
assert chart1 == chart2
|
||||
|
||||
|
||||
def test_repeat():
|
||||
# wrapped repeat
|
||||
chart1 = (
|
||||
alt.Chart("data.csv")
|
||||
.mark_point()
|
||||
.encode(
|
||||
x=alt.X(alt.repeat(), type="quantitative"),
|
||||
y="y:Q",
|
||||
)
|
||||
.repeat(["A", "B", "C", "D"], columns=2)
|
||||
)
|
||||
|
||||
dct1 = chart1.to_dict()
|
||||
|
||||
assert dct1["repeat"] == ["A", "B", "C", "D"]
|
||||
assert dct1["columns"] == 2
|
||||
assert dct1["spec"]["encoding"]["x"]["field"] == {"repeat": "repeat"}
|
||||
|
||||
# explicit row/col repeat
|
||||
chart2 = (
|
||||
alt.Chart("data.csv")
|
||||
.mark_point()
|
||||
.encode(
|
||||
x=alt.X(alt.repeat("row"), type="quantitative"),
|
||||
y=alt.Y(alt.repeat("column"), type="quantitative"),
|
||||
)
|
||||
.repeat(row=["A", "B", "C"], column=["C", "B", "A"])
|
||||
)
|
||||
|
||||
dct2 = chart2.to_dict()
|
||||
|
||||
assert dct2["repeat"] == {"row": ["A", "B", "C"], "column": ["C", "B", "A"]}
|
||||
assert "columns" not in dct2
|
||||
assert dct2["spec"]["encoding"]["x"]["field"] == {"repeat": "row"}
|
||||
assert dct2["spec"]["encoding"]["y"]["field"] == {"repeat": "column"}
|
||||
|
||||
|
||||
def test_data_property():
|
||||
data = pd.DataFrame({"x": [1, 2, 3], "y": list("ABC")})
|
||||
chart1 = alt.Chart(data).mark_point()
|
||||
chart2 = alt.Chart().mark_point().properties(data=data)
|
||||
|
||||
assert chart1.to_dict() == chart2.to_dict()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("method", ["layer", "hconcat", "vconcat", "concat"])
|
||||
@pytest.mark.parametrize(
|
||||
"data", ["data.json", pd.DataFrame({"x": range(3), "y": list("abc")})]
|
||||
)
|
||||
def test_subcharts_with_same_data(method, data):
|
||||
func = getattr(alt, method)
|
||||
|
||||
point = alt.Chart(data).mark_point().encode(x="x:Q", y="y:Q")
|
||||
line = point.mark_line()
|
||||
text = point.mark_text()
|
||||
|
||||
chart1 = func(point, line, text)
|
||||
assert chart1.data is not alt.Undefined
|
||||
assert all(c.data is alt.Undefined for c in getattr(chart1, method))
|
||||
|
||||
if method != "concat":
|
||||
op = OP_DICT[method]
|
||||
chart2 = op(op(point, line), text)
|
||||
assert chart2.data is not alt.Undefined
|
||||
assert all(c.data is alt.Undefined for c in getattr(chart2, method))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("method", ["layer", "hconcat", "vconcat", "concat"])
|
||||
@pytest.mark.parametrize(
|
||||
"data", ["data.json", pd.DataFrame({"x": range(3), "y": list("abc")})]
|
||||
)
|
||||
def test_subcharts_different_data(method, data):
|
||||
func = getattr(alt, method)
|
||||
|
||||
point = alt.Chart(data).mark_point().encode(x="x:Q", y="y:Q")
|
||||
otherdata = alt.Chart("data.csv").mark_point().encode(x="x:Q", y="y:Q")
|
||||
nodata = alt.Chart().mark_point().encode(x="x:Q", y="y:Q")
|
||||
|
||||
chart1 = func(point, otherdata)
|
||||
assert chart1.data is alt.Undefined
|
||||
assert getattr(chart1, method)[0].data is data
|
||||
|
||||
chart2 = func(point, nodata)
|
||||
assert chart2.data is alt.Undefined
|
||||
assert getattr(chart2, method)[0].data is data
|
||||
|
||||
|
||||
def test_layer_facet(basic_chart):
|
||||
chart = (basic_chart + basic_chart).facet(row="row:Q")
|
||||
assert chart.data is not alt.Undefined
|
||||
assert chart.spec.data is alt.Undefined
|
||||
for layer in chart.spec.layer:
|
||||
assert layer.data is alt.Undefined
|
||||
|
||||
dct = chart.to_dict()
|
||||
assert "data" in dct
|
||||
|
||||
|
||||
def test_layer_errors():
|
||||
toplevel_chart = alt.Chart("data.txt").mark_point().configure_legend(columns=2)
|
||||
|
||||
facet_chart1 = alt.Chart("data.txt").mark_point().encode(facet="row:Q")
|
||||
|
||||
facet_chart2 = alt.Chart("data.txt").mark_point().facet("row:Q")
|
||||
|
||||
repeat_chart = alt.Chart("data.txt").mark_point().repeat(["A", "B", "C"])
|
||||
|
||||
simple_chart = alt.Chart("data.txt").mark_point()
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
toplevel_chart + simple_chart
|
||||
assert str(err.value).startswith(
|
||||
'Objects with "config" attribute cannot be used within LayerChart.'
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
repeat_chart + simple_chart
|
||||
assert str(err.value) == "Repeat charts cannot be layered."
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
facet_chart1 + simple_chart
|
||||
assert str(err.value) == "Faceted charts cannot be layered."
|
||||
|
||||
with pytest.raises(ValueError) as err:
|
||||
alt.layer(simple_chart) + facet_chart2
|
||||
assert str(err.value) == "Faceted charts cannot be layered."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"chart_type",
|
||||
["layer", "hconcat", "vconcat", "concat", "facet", "facet_encoding", "repeat"],
|
||||
)
|
||||
def test_resolve(chart_type):
|
||||
chart = _make_chart_type(chart_type)
|
||||
chart = (
|
||||
chart.resolve_scale(
|
||||
x="independent",
|
||||
)
|
||||
.resolve_legend(color="independent")
|
||||
.resolve_axis(y="independent")
|
||||
)
|
||||
dct = chart.to_dict()
|
||||
assert dct["resolve"] == {
|
||||
"scale": {"x": "independent"},
|
||||
"legend": {"color": "independent"},
|
||||
"axis": {"y": "independent"},
|
||||
}
|
||||
|
||||
|
||||
# TODO: test vconcat, hconcat, concat when schema allows them.
|
||||
# This is blocked by https://github.com/vega/vega-lite/issues/5261
|
||||
@pytest.mark.parametrize("chart_type", ["chart", "layer", "facet_encoding"])
|
||||
@pytest.mark.parametrize("facet_arg", [None, "facet", "row", "column"])
|
||||
def test_facet(chart_type, facet_arg):
|
||||
chart = _make_chart_type(chart_type)
|
||||
if facet_arg is None:
|
||||
chart = chart.facet("color:N", columns=2)
|
||||
else:
|
||||
chart = chart.facet(**{facet_arg: "color:N", "columns": 2})
|
||||
dct = chart.to_dict()
|
||||
|
||||
assert "spec" in dct
|
||||
assert dct["columns"] == 2
|
||||
expected = {"field": "color", "type": "nominal"}
|
||||
if facet_arg is None or facet_arg == "facet":
|
||||
assert dct["facet"] == expected
|
||||
else:
|
||||
assert dct["facet"][facet_arg] == expected
|
||||
|
||||
|
||||
def test_sequence():
|
||||
data = alt.sequence(100)
|
||||
assert data.to_dict() == {"sequence": {"start": 0, "stop": 100}}
|
||||
|
||||
data = alt.sequence(5, 10)
|
||||
assert data.to_dict() == {"sequence": {"start": 5, "stop": 10}}
|
||||
|
||||
data = alt.sequence(0, 1, 0.1, as_="x")
|
||||
assert data.to_dict() == {
|
||||
"sequence": {"start": 0, "stop": 1, "step": 0.1, "as": "x"}
|
||||
}
|
||||
|
||||
|
||||
def test_graticule():
|
||||
data = alt.graticule()
|
||||
assert data.to_dict() == {"graticule": True}
|
||||
|
||||
data = alt.graticule(step=[15, 15])
|
||||
assert data.to_dict() == {"graticule": {"step": [15, 15]}}
|
||||
|
||||
|
||||
def test_sphere():
|
||||
data = alt.sphere()
|
||||
assert data.to_dict() == {"sphere": True}
|
@ -0,0 +1,33 @@
|
||||
import os
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
from .. import data as alt
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_data():
|
||||
return pd.DataFrame({"x": range(10), "y": range(10)})
|
||||
|
||||
|
||||
def test_disable_max_rows(sample_data):
|
||||
with alt.data_transformers.enable("default", max_rows=5):
|
||||
# Ensure max rows error is raised.
|
||||
with pytest.raises(alt.MaxRowsError):
|
||||
alt.data_transformers.get()(sample_data)
|
||||
|
||||
# Ensure that max rows error is properly disabled.
|
||||
with alt.data_transformers.disable_max_rows():
|
||||
alt.data_transformers.get()(sample_data)
|
||||
|
||||
try:
|
||||
with alt.data_transformers.enable("json"):
|
||||
# Ensure that there is no TypeError for non-max_rows transformers.
|
||||
with alt.data_transformers.disable_max_rows():
|
||||
jsonfile = alt.data_transformers.get()(sample_data)
|
||||
except TypeError:
|
||||
jsonfile = {}
|
||||
finally:
|
||||
if jsonfile:
|
||||
os.remove(jsonfile["url"])
|
@ -0,0 +1,69 @@
|
||||
from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
|
||||
import altair.vegalite.v3 as alt
|
||||
|
||||
|
||||
@contextmanager
|
||||
def check_render_options(**options):
|
||||
"""
|
||||
Context manager that will assert that alt.renderers.options are equivalent
|
||||
to the given options in the IPython.display.display call
|
||||
"""
|
||||
import IPython.display
|
||||
|
||||
def check_options(obj):
|
||||
assert alt.renderers.options == options
|
||||
|
||||
_display = IPython.display.display
|
||||
IPython.display.display = check_options
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
IPython.display.display = _display
|
||||
|
||||
|
||||
def test_check_renderer_options():
|
||||
# this test should pass
|
||||
with check_render_options():
|
||||
from IPython.display import display
|
||||
|
||||
display(None)
|
||||
|
||||
# check that an error is appropriately raised if the test fails
|
||||
with pytest.raises(AssertionError):
|
||||
with check_render_options(foo="bar"):
|
||||
from IPython.display import display
|
||||
|
||||
display(None)
|
||||
|
||||
|
||||
def test_display_options():
|
||||
chart = alt.Chart("data.csv").mark_point().encode(x="foo:Q")
|
||||
|
||||
# check that there are no options by default
|
||||
with check_render_options():
|
||||
chart.display()
|
||||
|
||||
# check that display options are passed
|
||||
with check_render_options(embed_options={"tooltip": False, "renderer": "canvas"}):
|
||||
chart.display("canvas", tooltip=False)
|
||||
|
||||
# check that above options do not persist
|
||||
with check_render_options():
|
||||
chart.display()
|
||||
|
||||
# check that display options augment rather than overwrite pre-set options
|
||||
with alt.renderers.enable(embed_options={"tooltip": True, "renderer": "svg"}):
|
||||
with check_render_options(embed_options={"tooltip": True, "renderer": "svg"}):
|
||||
chart.display()
|
||||
|
||||
with check_render_options(
|
||||
embed_options={"tooltip": True, "renderer": "canvas"}
|
||||
):
|
||||
chart.display("canvas")
|
||||
|
||||
# check that above options do not persist
|
||||
with check_render_options():
|
||||
chart.display()
|
@ -0,0 +1,204 @@
|
||||
import pytest
|
||||
import altair.vegalite.v3 as alt
|
||||
|
||||
|
||||
def geom_obj(geom):
|
||||
class Geom(object):
|
||||
pass
|
||||
|
||||
geom_obj = Geom()
|
||||
setattr(geom_obj, "__geo_interface__", geom)
|
||||
return geom_obj
|
||||
|
||||
|
||||
# correct translation of Polygon geometry to Feature type
|
||||
def test_geo_interface_polygon_feature():
|
||||
geom = {
|
||||
"coordinates": [[(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]],
|
||||
"type": "Polygon",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"]["type"] == "Feature"
|
||||
|
||||
|
||||
# merge geometry with empty properties dictionary
|
||||
def test_geo_interface_removal_empty_properties():
|
||||
geom = {
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[6.90, 53.48], [5.98, 51.85], [6.07, 53.51], [6.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": None,
|
||||
"properties": {},
|
||||
"type": "Feature",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"]["type"] == "Feature"
|
||||
|
||||
|
||||
# only register metadata in the properties member
|
||||
def test_geo_interface_register_foreign_member():
|
||||
geom = {
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[6.90, 53.48], [5.98, 51.85], [6.07, 53.51], [6.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": 2,
|
||||
"properties": {"foo": "bah"},
|
||||
"type": "Feature",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
with pytest.raises(KeyError):
|
||||
spec["data"]["values"]["id"]
|
||||
assert spec["data"]["values"]["foo"] == "bah"
|
||||
|
||||
|
||||
# correct serializing of arrays and nested tuples
|
||||
def test_geo_interface_serializing_arrays_tuples():
|
||||
import array as arr
|
||||
|
||||
geom = {
|
||||
"bbox": arr.array("d", [1, 2, 3, 4]),
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
tuple(
|
||||
(
|
||||
tuple((6.90, 53.48)),
|
||||
tuple((5.98, 51.85)),
|
||||
tuple((6.07, 53.51)),
|
||||
tuple((6.90, 53.48)),
|
||||
)
|
||||
)
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": 27,
|
||||
"properties": {},
|
||||
"type": "Feature",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"]["geometry"]["coordinates"][0][0] == [6.9, 53.48]
|
||||
|
||||
|
||||
# overwrite existing 'type' value in properties with `Feature`
|
||||
def test_geo_interface_reserved_members():
|
||||
geom = {
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[6.90, 53.48], [5.98, 51.85], [6.07, 53.51], [6.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": 27,
|
||||
"properties": {"type": "foo"},
|
||||
"type": "Feature",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"]["type"] == "Feature"
|
||||
|
||||
|
||||
# an empty FeatureCollection is valid
|
||||
def test_geo_interface_empty_feature_collection():
|
||||
geom = {"type": "FeatureCollection", "features": []}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"] == []
|
||||
|
||||
|
||||
# Features in a FeatureCollection only keep properties and geometry
|
||||
def test_geo_interface_feature_collection():
|
||||
geom = {
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[6.90, 53.48], [5.98, 51.85], [6.07, 53.51], [6.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": 27,
|
||||
"properties": {"type": "foo", "id": 1, "geometry": 1},
|
||||
"type": "Feature",
|
||||
},
|
||||
{
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[8.90, 53.48], [7.98, 51.85], [8.07, 53.51], [8.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": 28,
|
||||
"properties": {"type": "foo", "id": 2, "geometry": 1},
|
||||
"type": "Feature",
|
||||
},
|
||||
],
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"][0]["id"] == 1
|
||||
assert spec["data"]["values"][1]["id"] == 2
|
||||
assert "coordinates" in spec["data"]["values"][0]["geometry"]
|
||||
assert "coordinates" in spec["data"]["values"][1]["geometry"]
|
||||
assert spec["data"]["values"][0]["type"] == "Feature"
|
||||
assert spec["data"]["values"][1]["type"] == "Feature"
|
||||
|
||||
|
||||
# typical output of a __geo_interface__ from geopandas GeoDataFrame
|
||||
# notic that the index value is registerd as a commonly used identifier
|
||||
# with the name "id" (in this case 49). Similar to serialization of a
|
||||
# pandas DataFrame is the index not included in the output
|
||||
def test_geo_interface_feature_collection_gdf():
|
||||
geom = {
|
||||
"bbox": (19.89, -26.82, 29.43, -17.66),
|
||||
"features": [
|
||||
{
|
||||
"bbox": (19.89, -26.82, 29.43, -17.66),
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[[6.90, 53.48], [5.98, 51.85], [6.07, 53.51], [6.90, 53.48]]
|
||||
],
|
||||
"type": "Polygon",
|
||||
},
|
||||
"id": "49",
|
||||
"properties": {
|
||||
"continent": "Africa",
|
||||
"gdp_md_est": 35900.0,
|
||||
"id": "BWA",
|
||||
"iso_a3": "BWA",
|
||||
"name": "Botswana",
|
||||
"pop_est": 2214858,
|
||||
},
|
||||
"type": "Feature",
|
||||
}
|
||||
],
|
||||
"type": "FeatureCollection",
|
||||
}
|
||||
feat = geom_obj(geom)
|
||||
|
||||
with alt.data_transformers.enable(consolidate_datasets=False):
|
||||
spec = alt.Chart(feat).mark_geoshape().to_dict()
|
||||
assert spec["data"]["values"][0]["id"] == "BWA"
|
@ -0,0 +1,86 @@
|
||||
"""Tests of various renderers"""
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
import altair.vegalite.v3 as alt
|
||||
|
||||
|
||||
def _extract_embedOpt(html):
|
||||
"""Extract an embedOpt definition from an html string.
|
||||
|
||||
Note: this is very brittle, but works for the specific test in this file.
|
||||
"""
|
||||
result = re.search(r"embedOpt\s+=\s+(?P<embedOpt>\{.*?\})", html)
|
||||
if not result:
|
||||
return None
|
||||
else:
|
||||
return json.loads(result.groupdict()["embedOpt"])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart():
|
||||
return alt.Chart("data.csv").mark_point()
|
||||
|
||||
|
||||
def test_colab_renderer_embed_options(chart):
|
||||
"""Test that embed_options in renderer metadata are correctly manifest in html"""
|
||||
|
||||
def assert_actions_true(chart):
|
||||
bundle = chart._repr_mimebundle_(None, None)
|
||||
embedOpt = _extract_embedOpt(bundle["text/html"])
|
||||
assert embedOpt == {"actions": True, "mode": "vega-lite"}
|
||||
|
||||
def assert_actions_false(chart):
|
||||
bundle = chart._repr_mimebundle_(None, None)
|
||||
embedOpt = _extract_embedOpt(bundle["text/html"])
|
||||
assert embedOpt == {"actions": False, "mode": "vega-lite"}
|
||||
|
||||
with alt.renderers.enable("colab", embed_options=dict(actions=False)):
|
||||
assert_actions_false(chart)
|
||||
|
||||
with alt.renderers.enable("colab"):
|
||||
with alt.renderers.enable(embed_options=dict(actions=True)):
|
||||
assert_actions_true(chart)
|
||||
|
||||
with alt.renderers.set_embed_options(actions=False):
|
||||
assert_actions_false(chart)
|
||||
|
||||
with alt.renderers.set_embed_options(actions=True):
|
||||
assert_actions_true(chart)
|
||||
|
||||
|
||||
def test_default_renderer_embed_options(chart, renderer="default"):
|
||||
# check that metadata is passed appropriately
|
||||
mimetype = alt.display.VEGALITE_MIME_TYPE
|
||||
spec = chart.to_dict()
|
||||
with alt.renderers.enable(renderer, embed_options=dict(actions=False)):
|
||||
bundle, metadata = chart._repr_mimebundle_(None, None)
|
||||
assert set(bundle.keys()) == {mimetype, "text/plain"}
|
||||
assert bundle[mimetype] == spec
|
||||
assert metadata == {mimetype: {"embed_options": {"actions": False}}}
|
||||
|
||||
# Sanity check: no metadata specified
|
||||
with alt.renderers.enable(renderer):
|
||||
bundle, metadata = chart._repr_mimebundle_(None, None)
|
||||
assert bundle[mimetype] == spec
|
||||
assert metadata == {}
|
||||
|
||||
|
||||
def test_json_renderer_embed_options(chart, renderer="json"):
|
||||
"""Test that embed_options in renderer metadata are correctly manifest in html"""
|
||||
mimetype = "application/json"
|
||||
spec = chart.to_dict()
|
||||
with alt.renderers.enable("json", option="foo"):
|
||||
bundle, metadata = chart._repr_mimebundle_(None, None)
|
||||
assert set(bundle.keys()) == {mimetype, "text/plain"}
|
||||
assert bundle[mimetype] == spec
|
||||
assert metadata == {mimetype: {"option": "foo"}}
|
||||
|
||||
# Sanity check: no options specified
|
||||
with alt.renderers.enable(renderer):
|
||||
bundle, metadata = chart._repr_mimebundle_(None, None)
|
||||
assert bundle[mimetype] == spec
|
||||
assert metadata == {}
|
@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
|
||||
import altair.vegalite.v3 as alt
|
||||
from altair.vegalite.v3.theme import VEGA_THEMES
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def chart():
|
||||
return alt.Chart("data.csv").mark_bar().encode(x="x:Q")
|
||||
|
||||
|
||||
def test_vega_themes(chart):
|
||||
for theme in VEGA_THEMES:
|
||||
with alt.themes.enable(theme):
|
||||
dct = chart.to_dict()
|
||||
assert dct["usermeta"] == {"embedOptions": {"theme": theme}}
|
||||
assert dct["config"] == {
|
||||
"view": {"width": 400, "height": 300},
|
||||
"mark": {"tooltip": None},
|
||||
}
|
54
.venv/Lib/site-packages/altair/vegalite/v3/theme.py
Normal file
54
.venv/Lib/site-packages/altair/vegalite/v3/theme.py
Normal file
@ -0,0 +1,54 @@
|
||||
"""Tools for enabling and registering chart themes"""
|
||||
|
||||
from ...utils.theme import ThemeRegistry
|
||||
|
||||
VEGA_THEMES = ["ggplot2", "quartz", "vox", "fivethirtyeight", "dark", "latimes"]
|
||||
|
||||
|
||||
class VegaTheme(object):
|
||||
"""Implementation of a builtin vega theme."""
|
||||
|
||||
def __init__(self, theme):
|
||||
self.theme = theme
|
||||
|
||||
def __call__(self):
|
||||
return {
|
||||
"usermeta": {"embedOptions": {"theme": self.theme}},
|
||||
"config": {
|
||||
"view": {"width": 400, "height": 300},
|
||||
"mark": {"tooltip": None},
|
||||
},
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return "VegaTheme({!r})".format(self.theme)
|
||||
|
||||
|
||||
# The entry point group that can be used by other packages to declare other
|
||||
# renderers that will be auto-detected. Explicit registration is also
|
||||
# allowed by the PluginRegistery API.
|
||||
ENTRY_POINT_GROUP = "altair.vegalite.v3.theme" # type: str
|
||||
themes = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP)
|
||||
|
||||
themes.register(
|
||||
"default",
|
||||
lambda: {
|
||||
"config": {"view": {"width": 400, "height": 300}, "mark": {"tooltip": None}}
|
||||
},
|
||||
)
|
||||
themes.register(
|
||||
"opaque",
|
||||
lambda: {
|
||||
"config": {
|
||||
"background": "white",
|
||||
"view": {"width": 400, "height": 300},
|
||||
"mark": {"tooltip": None},
|
||||
}
|
||||
},
|
||||
)
|
||||
themes.register("none", lambda: {})
|
||||
|
||||
for theme in VEGA_THEMES:
|
||||
themes.register(theme, VegaTheme(theme))
|
||||
|
||||
themes.enable("default")
|
Reference in New Issue
Block a user