forked from bloomberg/ipydatagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellrenderer.py
105 lines (84 loc) · 4.2 KB
/
cellrenderer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# coding: utf-8
# Copyright (c) QuantStack.
# Distributed under the terms of the Modified BSD License.
"""
TODO: Add module docstring
"""
from traitlets import (
Any, Bool, Enum, Float, Instance, Unicode, Union, validate
)
from ipywidgets import Widget, widget_serialization, Color
# Dependency to bqplot is temporary, we should remove this dependency once scales are extracted from bqplot
from bqplot import Scale, ColorScale
from ._frontend import module_name, module_version
from py2vega import py2vega, Variable
class VegaExpr(Widget):
_model_name = Unicode('VegaExprModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
_model_module_version = Unicode(module_version).tag(sync=True)
_view_name = Unicode('VegaExprView').tag(sync=True)
_view_module = Unicode(module_name).tag(sync=True)
_view_module_version = Unicode(module_version).tag(sync=True)
value = Unicode('default_value').tag(sync=True)
def __init__(self, value='', **kwargs):
super(VegaExpr, self).__init__(value=value, **kwargs)
class Expr(VegaExpr):
value = Any().tag(sync=True)
@validate('value')
def _validate_value(self, proposal):
return py2vega(proposal['value'], [Variable('cell', ['value', 'row', 'column']), 'default_value'])
class CellRenderer(Widget):
_model_name = Unicode('CellRendererModel').tag(sync=True)
_model_module = Unicode(module_name).tag(sync=True)
_model_module_version = Unicode(module_version).tag(sync=True)
_view_name = Unicode('CellRendererView').tag(sync=True)
_view_module = Unicode(module_name).tag(sync=True)
_view_module_version = Unicode(module_version).tag(sync=True)
class TextRenderer(CellRenderer):
_model_name = Unicode('TextRendererModel').tag(sync=True)
_view_name = Unicode('TextRendererView').tag(sync=True)
text_value = Union((
Unicode(), Instance(VegaExpr), Instance(Scale)
), allow_none=True, default_value=None).tag(sync=True, **widget_serialization)
font = Union((
Unicode(), Instance(VegaExpr), Instance(Scale)
), default_value='12px sans-serif').tag(sync=True, **widget_serialization)
text_color = Union((
Color(), Instance(VegaExpr), Instance(ColorScale)
), default_value=Expr('default_value')).tag(sync=True, **widget_serialization)
background_color = Union((
Color(), Instance(VegaExpr), Instance(ColorScale)
), default_value=Expr('default_value')).tag(sync=True, **widget_serialization)
vertical_alignment = Union((
Enum(values=['top', 'center', 'bottom']), Instance(VegaExpr), Instance(Scale)
), default_value='center').tag(sync=True, **widget_serialization)
horizontal_alignment = Union((
Enum(values=['left', 'center', 'right']), Instance(VegaExpr), Instance(Scale)
), default_value='left').tag(sync=True, **widget_serialization)
format = Union((
Unicode(), Instance(VegaExpr)
), allow_none=True, default_value=None).tag(sync=True, **widget_serialization)
format_type = Enum(values=['number', 'time'], default_value='number').tag(sync=True)
missing = Unicode('').tag(sync=True)
class BarRenderer(TextRenderer):
_model_name = Unicode('BarRendererModel').tag(sync=True)
_view_name = Unicode('BarRendererView').tag(sync=True)
bar_value = Union((
Float(), Instance(VegaExpr), Instance(Scale)
), default_value=0.).tag(sync=True, **widget_serialization)
bar_color = Union((
Color(), Instance(VegaExpr), Instance(ColorScale)
), default_value='#4682b4').tag(sync=True, **widget_serialization)
orientation = Union((
Unicode(), Instance(VegaExpr), Instance(Scale)
), default_value='horizontal').tag(sync=True, **widget_serialization)
bar_vertical_alignment = Union((
Enum(values=['top', 'center', 'bottom']), Instance(VegaExpr), Instance(Scale)
), default_value='bottom').tag(sync=True, **widget_serialization)
bar_horizontal_alignment = Union((
Enum(values=['left', 'center', 'right']), Instance(VegaExpr), Instance(Scale)
), default_value='left').tag(sync=True, **widget_serialization)
show_text = Union((
Bool(), Instance(VegaExpr)
), default_value=True).tag(sync=True, **widget_serialization)