Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: update to Vega-Lite 5.2 #2528

Merged
merged 27 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14bbb8d
Initial creation of vegalite/v5 folder
ChristopherDavisUCI Nov 27, 2021
65399d3
Initial VariableParameter definitions
ChristopherDavisUCI Nov 27, 2021
50c4732
Updates to parameter definitions
ChristopherDavisUCI Nov 27, 2021
c2a58b2
Move height/width/view from layer to parent
ChristopherDavisUCI Nov 27, 2021
c143c04
Increase compatibility with old selection syntax
ChristopherDavisUCI Nov 28, 2021
5bba402
Fix formatting
ChristopherDavisUCI Nov 28, 2021
4d0ae32
Updated use of PredicateComposition
ChristopherDavisUCI Dec 2, 2021
d4915ce
Update scatter_with_minimap.py
ChristopherDavisUCI Dec 2, 2021
870e30c
Update api.py
ChristopherDavisUCI Dec 3, 2021
566a779
First draft of parameters documentation
ChristopherDavisUCI Dec 13, 2021
015b036
Merge remote-tracking branch 'upstream/master' into samplev52
ChristopherDavisUCI Dec 13, 2021
ea9ae53
Merge remote-tracking branch 'upstream/master' into samplev52
ChristopherDavisUCI Dec 30, 2021
846a842
Define SelectionPredicateComposition
ChristopherDavisUCI Jan 8, 2022
b391eec
Update test_add_selection
ChristopherDavisUCI Jan 8, 2022
3b41f22
Update test_selection_expression
ChristopherDavisUCI Jan 8, 2022
b8fd70e
Update tests related to selections
ChristopherDavisUCI Jan 11, 2022
55e88fb
point temporary to master of altair_viewer
mattijn Jan 17, 2022
c1236a6
alt.VEGALITE_VERSION uses this schema
mattijn Jan 18, 2022
96634c8
Update expected vega_spec
ChristopherDavisUCI Jan 18, 2022
454bbfe
Merge branch 'samplev52' of https://github.com/ChristopherDavisUCI/al…
ChristopherDavisUCI Jan 18, 2022
62ec051
Update release notes
ChristopherDavisUCI Feb 4, 2022
d0022f3
Update test_plugin_registry.py
ChristopherDavisUCI Feb 4, 2022
6e62f53
Corrected add_parameter definition on multi-view charts
ChristopherDavisUCI Feb 9, 2022
a941cc1
Remove remove obsolete schema classes from the user guide
ChristopherDavisUCI Mar 2, 2022
5d83434
Update parameters documentation
ChristopherDavisUCI Mar 3, 2022
2168430
Include new classes in API.rst
ChristopherDavisUCI Mar 4, 2022
af0c3b4
Examples involving offsets
ChristopherDavisUCI Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 77 additions & 40 deletions altair/expr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,114 +31,151 @@ def _js_repr(val):
return "false"
elif val is None:
return "null"
elif isinstance(val, OperatorMixin):
return val._to_expr()
else:
return repr(val)


class Expression(SchemaBase):
"""Expression

Base object for enabling build-up of Javascript expressions using
a Python syntax. Calling ``repr(obj)`` will return a Javascript
representation of the object and the operations it encodes.
"""

_schema = {"type": "string"}

def to_dict(self, *args, **kwargs):
# Designed to work with Expression and VariableParameter
class OperatorMixin(object):
def _to_expr(self):
return repr(self)

def __setattr__(self, attr, val):
# We don't need the setattr magic defined in SchemaBase
return object.__setattr__(self, attr, val)
def _from_expr(self, expr):
return expr

def __add__(self, other):
return BinaryExpression("+", self, other)
comp_value = BinaryExpression("+", self, other)
return self._from_expr(comp_value)

def __radd__(self, other):
return BinaryExpression("+", other, self)
comp_value = BinaryExpression("+", other, self)
return self._from_expr(comp_value)

def __sub__(self, other):
return BinaryExpression("-", self, other)
comp_value = BinaryExpression("-", self, other)
return self._from_expr(comp_value)

def __rsub__(self, other):
return BinaryExpression("-", other, self)
comp_value = BinaryExpression("-", other, self)
return self._from_expr(comp_value)

def __mul__(self, other):
return BinaryExpression("*", self, other)
comp_value = BinaryExpression("*", self, other)
return self._from_expr(comp_value)

def __rmul__(self, other):
return BinaryExpression("*", other, self)
comp_value = BinaryExpression("*", other, self)
return self._from_expr(comp_value)

def __truediv__(self, other):
return BinaryExpression("/", self, other)
comp_value = BinaryExpression("/", self, other)
return self._from_expr(comp_value)

def __rtruediv__(self, other):
return BinaryExpression("/", other, self)
comp_value = BinaryExpression("/", other, self)
return self._from_expr(comp_value)

__div__ = __truediv__

__rdiv__ = __rtruediv__

def __mod__(self, other):
return BinaryExpression("%", self, other)
comp_value = BinaryExpression("%", self, other)
return self._from_expr(comp_value)

def __rmod__(self, other):
return BinaryExpression("%", other, self)
comp_value = BinaryExpression("%", other, self)
return self._from_expr(comp_value)

def __pow__(self, other):
# "**" Javascript operator is not supported in all browsers
return FunctionExpression("pow", (self, other))
comp_value = FunctionExpression("pow", (self, other))
return self._from_expr(comp_value)

def __rpow__(self, other):
# "**" Javascript operator is not supported in all browsers
return FunctionExpression("pow", (other, self))
comp_value = FunctionExpression("pow", (other, self))
return self._from_expr(comp_value)

def __neg__(self):
return UnaryExpression("-", self)
comp_value = UnaryExpression("-", self)
return self._from_expr(comp_value)

def __pos__(self):
return UnaryExpression("+", self)
comp_value = UnaryExpression("+", self)
return self._from_expr(comp_value)

# comparison operators

def __eq__(self, other):
return BinaryExpression("===", self, other)
comp_value = BinaryExpression("===", self, other)
return self._from_expr(comp_value)

def __ne__(self, other):
return BinaryExpression("!==", self, other)
comp_value = BinaryExpression("!==", self, other)
return self._from_expr(comp_value)

def __gt__(self, other):
return BinaryExpression(">", self, other)
comp_value = BinaryExpression(">", self, other)
return self._from_expr(comp_value)

def __lt__(self, other):
return BinaryExpression("<", self, other)
comp_value = BinaryExpression("<", self, other)
return self._from_expr(comp_value)

def __ge__(self, other):
return BinaryExpression(">=", self, other)
comp_value = BinaryExpression(">=", self, other)
return self._from_expr(comp_value)

def __le__(self, other):
return BinaryExpression("<=", self, other)
comp_value = BinaryExpression("<=", self, other)
return self._from_expr(comp_value)

def __abs__(self):
return FunctionExpression("abs", (self,))
comp_value = FunctionExpression("abs", (self,))
return self._from_expr(comp_value)

# logical operators

def __and__(self, other):
return BinaryExpression("&&", self, other)
comp_value = BinaryExpression("&&", self, other)
return self._from_expr(comp_value)

def __rand__(self, other):
return BinaryExpression("&&", other, self)
comp_value = BinaryExpression("&&", other, self)
return self._from_expr(comp_value)

def __or__(self, other):
return BinaryExpression("||", self, other)
comp_value = BinaryExpression("||", self, other)
return self._from_expr(comp_value)

def __ror__(self, other):
return BinaryExpression("||", other, self)
comp_value = BinaryExpression("||", other, self)
return self._from_expr(comp_value)

def __invert__(self):
return UnaryExpression("!", self)
comp_value = UnaryExpression("!", self)
return self._from_expr(comp_value)


class Expression(OperatorMixin, SchemaBase):
"""Expression

Base object for enabling build-up of Javascript expressions using
a Python syntax. Calling ``repr(obj)`` will return a Javascript
representation of the object and the operations it encodes.
"""

_schema = {"type": "string"}

def to_dict(self, *args, **kwargs):
return repr(self)

def __setattr__(self, attr, val):
# We don't need the setattr magic defined in SchemaBase
return object.__setattr__(self, attr, val)

# item access
def __getitem__(self, val):
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# flake8: noqa
from .v4 import *
from .v5 import *
23 changes: 23 additions & 0 deletions altair/vegalite/v5/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# flake8: noqa
from .schema import *
from .api 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,
)
Loading