Skip to content

Commit 9147104

Browse files
committed
docs update
1 parent 022a545 commit 9147104

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

chartlets.py/chartlets/contribution.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77

88
class Contribution(ABC):
9+
"""Base class for specific application contributions.
10+
11+
Derived classes typically add attributes that allow
12+
customizing the appearance of the contribution in the
13+
user interface. The user-provided values for such
14+
attributes determine the initial state of the
15+
contribution when it is rendered for the first time.
16+
17+
Args:
18+
name: A name that should be unique within an extension.
19+
initial_state: contribution specific attribute values.
20+
"""
921
# noinspection PyShadowingBuiltins
1022
def __init__(self, name: str, **initial_state):
1123
self.name = name
@@ -15,6 +27,9 @@ def __init__(self, name: str, **initial_state):
1527
self.callbacks: list[Callback] = []
1628

1729
def to_dict(self) -> dict[str, Any]:
30+
"""Convert this contribution into a
31+
JSON serializable dictionary.
32+
"""
1833
d = dict(name=self.name)
1934
if self.initial_state is not None:
2035
d.update(initialState=self.initial_state)
@@ -27,7 +42,31 @@ def to_dict(self) -> dict[str, Any]:
2742
return d
2843

2944
def layout(self, *args) -> Callable:
30-
"""Decorator."""
45+
"""A decorator for a user-provided function that
46+
returns the initial user interface layout.
47+
48+
The decorated function must return an instance of
49+
a `chartlets.Component`, usually a `chartlets.components.Box`
50+
that arranges other components in some layout.
51+
52+
The first parameter of the decorated function must be a
53+
positional argument. It provides an application-specific
54+
context that is used to allow for access server-side
55+
configuration and resources. The parameter should be
56+
called `ctx`.
57+
58+
Other parameters of the decorated function are user-defined
59+
and must have a corresponding `chartlets.Input` argument
60+
in the `layout` decorator in the same order.
61+
62+
Args:
63+
args: Instances of the `chartlets.Input` class that
64+
define the source of the value for the corresponding
65+
parameter of the decorated function. Optional.
66+
67+
Returns:
68+
The decorated, user-provided function.
69+
"""
3170

3271
def decorator(function: Callable) -> Callable:
3372
self.layout_callback = Callback.from_decorator(

docs/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The Chartlets framework has two types of users:
1+
The Chartlets framework has two types of target users:
22

33
- **Application contributors** develop new contributions
44
for a specific web application that is powered by Chartlets.

0 commit comments

Comments
 (0)