reflex-charts 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reflex_charts-0.1.0/LICENSE +201 -0
- reflex_charts-0.1.0/NOTICE +13 -0
- reflex_charts-0.1.0/PKG-INFO +186 -0
- reflex_charts-0.1.0/README.md +160 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/__init__.py +70 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/base.py +56 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/base.pyi +81 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/chart.py +111 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/chart.pyi +103 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/constants.py +54 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/examples/__init__.py +1 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/examples/data.py +154 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/helpers.py +144 -0
- reflex_charts-0.1.0/custom_components/reflex_charts/py.typed +0 -0
- reflex_charts-0.1.0/custom_components/reflex_charts.egg-info/PKG-INFO +186 -0
- reflex_charts-0.1.0/custom_components/reflex_charts.egg-info/SOURCES.txt +25 -0
- reflex_charts-0.1.0/custom_components/reflex_charts.egg-info/dependency_links.txt +1 -0
- reflex_charts-0.1.0/custom_components/reflex_charts.egg-info/requires.txt +8 -0
- reflex_charts-0.1.0/custom_components/reflex_charts.egg-info/top_level.txt +1 -0
- reflex_charts-0.1.0/pyproject.toml +56 -0
- reflex_charts-0.1.0/setup.cfg +4 -0
- reflex_charts-0.1.0/tests/test_components.py +109 -0
- reflex_charts-0.1.0/tests/test_constants.py +54 -0
- reflex_charts-0.1.0/tests/test_examples.py +104 -0
- reflex_charts-0.1.0/tests/test_helpers.py +152 -0
- reflex_charts-0.1.0/tests/test_imports.py +70 -0
- reflex_charts-0.1.0/tests/test_public_api.py +65 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ernesto Crespo
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
reflex-charts
|
|
2
|
+
Copyright 2026 Ernesto Crespo
|
|
3
|
+
|
|
4
|
+
This product is a Reflex (https://reflex.dev) custom component that wraps the
|
|
5
|
+
following third-party software, which is downloaded at build time and is NOT
|
|
6
|
+
redistributed as part of this source repository:
|
|
7
|
+
|
|
8
|
+
- Chart.js (MIT License) https://www.chartjs.org
|
|
9
|
+
- react-chartjs-2 (MIT License) https://react-chartjs-2.js.org
|
|
10
|
+
|
|
11
|
+
Chart.js and react-chartjs-2 are the property of their respective authors and
|
|
12
|
+
are used here under the terms of the MIT License. This repository itself is
|
|
13
|
+
licensed under the Apache License, Version 2.0 (see the LICENSE file).
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reflex-charts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Reflex custom component that wraps Chart.js (via react-chartjs-2), usable from pure Python.
|
|
5
|
+
Author-email: Ernesto Crespo <ecrespo@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ecrespo/reflex-charts
|
|
8
|
+
Project-URL: Repository, https://github.com/ecrespo/reflex-charts
|
|
9
|
+
Project-URL: Issues, https://github.com/ecrespo/reflex-charts/issues
|
|
10
|
+
Keywords: reflex,reflex-custom-components,chartjs,chart.js,charts,react-chartjs-2,dataviz
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
License-File: NOTICE
|
|
19
|
+
Requires-Dist: reflex>=0.8.6
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
22
|
+
Provides-Extra: publish
|
|
23
|
+
Requires-Dist: build; extra == "publish"
|
|
24
|
+
Requires-Dist: twine; extra == "publish"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# reflex-charts
|
|
28
|
+
|
|
29
|
+
**Chart.js for [Reflex](https://reflex.dev) — every chart type, from pure Python.**
|
|
30
|
+
|
|
31
|
+
`reflex-charts` is a Reflex custom component that wraps
|
|
32
|
+
[Chart.js](https://www.chartjs.org) (via its React bindings,
|
|
33
|
+
[react-chartjs-2](https://react-chartjs-2.js.org)). It exposes the full Chart.js
|
|
34
|
+
feature set through a small, Pythonic API so you can build interactive,
|
|
35
|
+
reactive charts in a Reflex app without writing any JavaScript.
|
|
36
|
+
|
|
37
|
+
> Status: **v0.1.0 — foundation.** Base wrapper, generic component, typed
|
|
38
|
+
> factories, data builders, and a demo gallery covering every chart type.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- **All eight Chart.js types** from one versatile component: line, bar, radar,
|
|
43
|
+
doughnut, pie, polar area, bubble, scatter — plus area, horizontal bar and
|
|
44
|
+
mixed variants.
|
|
45
|
+
- **Pure Python.** Configure charts with `data`/`options` dicts that mirror the
|
|
46
|
+
Chart.js docs one-to-one. Any chartjs.org example pastes straight in.
|
|
47
|
+
- **Reactive.** Bind chart data to `rx.State` computed vars; charts update when
|
|
48
|
+
state changes.
|
|
49
|
+
- **Interactive.** Surface the canvas `on_click` event (with the clicked
|
|
50
|
+
elements) as a Reflex event handler.
|
|
51
|
+
- **Zero setup.** All Chart.js controllers, scales and plugins are registered
|
|
52
|
+
automatically — no manual `Chart.register(...)`.
|
|
53
|
+
- **Optional builders** for datasets, palettes and options; raw dicts always work.
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install reflex-charts # once published to PyPI
|
|
59
|
+
# or from a clone:
|
|
60
|
+
pip install -e .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Requires Reflex ≥ 0.8.6 and Python ≥ 3.11.
|
|
64
|
+
|
|
65
|
+
## Quick start
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import reflex as rx
|
|
69
|
+
import reflex_charts as rxc
|
|
70
|
+
|
|
71
|
+
data = rxc.chart_data(
|
|
72
|
+
labels=["Jan", "Feb", "Mar", "Apr"],
|
|
73
|
+
datasets=[rxc.dataset("Sales", [10, 25, 18, 30], tension=0.3)],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def index() -> rx.Component:
|
|
77
|
+
return rx.box(
|
|
78
|
+
rxc.line(data=data, options=rxc.options(title="Monthly sales")),
|
|
79
|
+
height="320px",
|
|
80
|
+
width="100%",
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
app = rx.App()
|
|
84
|
+
app.add_page(index)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Put charts in a **fixed-height box** — the `options()` builder sets
|
|
88
|
+
`maintainAspectRatio=False` so the chart fills its container.
|
|
89
|
+
|
|
90
|
+
## Chart types
|
|
91
|
+
|
|
92
|
+
| Factory | Type | Notes |
|
|
93
|
+
|---------|------|-------|
|
|
94
|
+
| `rxc.line(...)` | `line` | area via dataset `fill` |
|
|
95
|
+
| `rxc.bar(...)` | `bar` | horizontal via `options(indexAxis="y")` |
|
|
96
|
+
| `rxc.radar(...)` | `radar` | |
|
|
97
|
+
| `rxc.doughnut(...)` | `doughnut` | |
|
|
98
|
+
| `rxc.pie(...)` | `pie` | |
|
|
99
|
+
| `rxc.polar_area(...)` | `polarArea` | |
|
|
100
|
+
| `rxc.bubble(...)` | `bubble` | points `{x, y, r}` |
|
|
101
|
+
| `rxc.scatter(...)` | `scatter` | points `{x, y}` |
|
|
102
|
+
| `rxc.chart(type=..., ...)` | any | generic / mixed / runtime-chosen |
|
|
103
|
+
|
|
104
|
+
See [`docs/usage.md`](docs/usage.md) for an example of each.
|
|
105
|
+
|
|
106
|
+
## Run the demo
|
|
107
|
+
|
|
108
|
+
A standalone demo app (`reflex_charts_demo/`) shows a gallery of every chart
|
|
109
|
+
type plus a state-driven, click-aware interactive example.
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install -e . # install the component (editable)
|
|
113
|
+
cd reflex_charts_demo
|
|
114
|
+
reflex run # open http://localhost:3000
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Build & publish (custom component)
|
|
118
|
+
|
|
119
|
+
This repo follows the [Reflex custom-component](https://reflex.dev/docs/custom-components/overview/)
|
|
120
|
+
layout, so the standard tooling works:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
reflex component build # build the wheel/sdist into dist/
|
|
124
|
+
reflex component publish # upload to PyPI (needs a PyPI token)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The build ships typed `.pyi` stubs (and a `py.typed` marker) for editor
|
|
128
|
+
autocomplete. To **regenerate** the stubs after changing component props, make
|
|
129
|
+
the source importable by its on-disk path so Reflex's stub generator can load it:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
PYTHONPATH="$PWD" reflex component build
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Project layout
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
reflex-charts/
|
|
139
|
+
├── custom_components/
|
|
140
|
+
│ └── reflex_charts/ # the importable component package (PyPI: reflex-charts)
|
|
141
|
+
│ ├── base.py # ChartJSBase: deps + Chart.js registration
|
|
142
|
+
│ ├── chart.py # ChartCanvas + typed factories
|
|
143
|
+
│ ├── helpers.py # dataset / chart_data / options builders
|
|
144
|
+
│ ├── constants.py # npm pins, chart types, palette
|
|
145
|
+
│ └── examples/data.py # canonical sample figures
|
|
146
|
+
├── reflex_charts_demo/ # standalone demo app (gallery + interactive)
|
|
147
|
+
│ ├── rxconfig.py
|
|
148
|
+
│ └── reflex_charts_demo/reflex_charts_demo.py
|
|
149
|
+
├── specs/ # Spec-Driven Design artifacts (see below)
|
|
150
|
+
├── docs/usage.md # usage guide
|
|
151
|
+
├── tests/ # unit tests
|
|
152
|
+
└── scripts/ # GitHub bootstrap helper
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Design docs (Spec-Driven Design)
|
|
156
|
+
|
|
157
|
+
This repository is built spec-first. The full SDD set lives in
|
|
158
|
+
[`specs/`](specs/README.md):
|
|
159
|
+
|
|
160
|
+
- [Specification / PRD](specs/prd/reflex-charts-prd.md)
|
|
161
|
+
- [Architecture](specs/technical/architecture.md) (incl. ADRs)
|
|
162
|
+
- [Component API v1](specs/api/component-api-v1.md)
|
|
163
|
+
- [Data model](specs/data-model/chart-data-schemas.md)
|
|
164
|
+
- [Phases](specs/phases/phases.md)
|
|
165
|
+
- [Implementation plan](specs/plans/implementation-plan.md)
|
|
166
|
+
- [Task breakdown](specs/tasks/task-breakdown.md)
|
|
167
|
+
|
|
168
|
+
## How it works
|
|
169
|
+
|
|
170
|
+
Reflex compiles Python components to React. `reflex-charts` declares a component
|
|
171
|
+
whose generated JSX is the generic `<Chart>` from `react-chartjs-2`, with
|
|
172
|
+
Chart.js registered globally (`Chart.register(...registerables)`) so any `type`
|
|
173
|
+
renders. Your `data`/`options` dicts are serialized to props; on interaction,
|
|
174
|
+
Chart.js events are forwarded back to your Reflex state. See the
|
|
175
|
+
[architecture doc](specs/technical/architecture.md) for the details and the
|
|
176
|
+
decision records.
|
|
177
|
+
|
|
178
|
+
## Acknowledgements
|
|
179
|
+
|
|
180
|
+
Built on the excellent [Chart.js](https://www.chartjs.org) and
|
|
181
|
+
[react-chartjs-2](https://react-chartjs-2.js.org) projects (both MIT licensed —
|
|
182
|
+
see [`NOTICE`](NOTICE)) and the [Reflex](https://reflex.dev) framework.
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
[Apache-2.0](LICENSE) © 2026 Ernesto Crespo.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# reflex-charts
|
|
2
|
+
|
|
3
|
+
**Chart.js for [Reflex](https://reflex.dev) — every chart type, from pure Python.**
|
|
4
|
+
|
|
5
|
+
`reflex-charts` is a Reflex custom component that wraps
|
|
6
|
+
[Chart.js](https://www.chartjs.org) (via its React bindings,
|
|
7
|
+
[react-chartjs-2](https://react-chartjs-2.js.org)). It exposes the full Chart.js
|
|
8
|
+
feature set through a small, Pythonic API so you can build interactive,
|
|
9
|
+
reactive charts in a Reflex app without writing any JavaScript.
|
|
10
|
+
|
|
11
|
+
> Status: **v0.1.0 — foundation.** Base wrapper, generic component, typed
|
|
12
|
+
> factories, data builders, and a demo gallery covering every chart type.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **All eight Chart.js types** from one versatile component: line, bar, radar,
|
|
17
|
+
doughnut, pie, polar area, bubble, scatter — plus area, horizontal bar and
|
|
18
|
+
mixed variants.
|
|
19
|
+
- **Pure Python.** Configure charts with `data`/`options` dicts that mirror the
|
|
20
|
+
Chart.js docs one-to-one. Any chartjs.org example pastes straight in.
|
|
21
|
+
- **Reactive.** Bind chart data to `rx.State` computed vars; charts update when
|
|
22
|
+
state changes.
|
|
23
|
+
- **Interactive.** Surface the canvas `on_click` event (with the clicked
|
|
24
|
+
elements) as a Reflex event handler.
|
|
25
|
+
- **Zero setup.** All Chart.js controllers, scales and plugins are registered
|
|
26
|
+
automatically — no manual `Chart.register(...)`.
|
|
27
|
+
- **Optional builders** for datasets, palettes and options; raw dicts always work.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install reflex-charts # once published to PyPI
|
|
33
|
+
# or from a clone:
|
|
34
|
+
pip install -e .
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Requires Reflex ≥ 0.8.6 and Python ≥ 3.11.
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import reflex as rx
|
|
43
|
+
import reflex_charts as rxc
|
|
44
|
+
|
|
45
|
+
data = rxc.chart_data(
|
|
46
|
+
labels=["Jan", "Feb", "Mar", "Apr"],
|
|
47
|
+
datasets=[rxc.dataset("Sales", [10, 25, 18, 30], tension=0.3)],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def index() -> rx.Component:
|
|
51
|
+
return rx.box(
|
|
52
|
+
rxc.line(data=data, options=rxc.options(title="Monthly sales")),
|
|
53
|
+
height="320px",
|
|
54
|
+
width="100%",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
app = rx.App()
|
|
58
|
+
app.add_page(index)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Put charts in a **fixed-height box** — the `options()` builder sets
|
|
62
|
+
`maintainAspectRatio=False` so the chart fills its container.
|
|
63
|
+
|
|
64
|
+
## Chart types
|
|
65
|
+
|
|
66
|
+
| Factory | Type | Notes |
|
|
67
|
+
|---------|------|-------|
|
|
68
|
+
| `rxc.line(...)` | `line` | area via dataset `fill` |
|
|
69
|
+
| `rxc.bar(...)` | `bar` | horizontal via `options(indexAxis="y")` |
|
|
70
|
+
| `rxc.radar(...)` | `radar` | |
|
|
71
|
+
| `rxc.doughnut(...)` | `doughnut` | |
|
|
72
|
+
| `rxc.pie(...)` | `pie` | |
|
|
73
|
+
| `rxc.polar_area(...)` | `polarArea` | |
|
|
74
|
+
| `rxc.bubble(...)` | `bubble` | points `{x, y, r}` |
|
|
75
|
+
| `rxc.scatter(...)` | `scatter` | points `{x, y}` |
|
|
76
|
+
| `rxc.chart(type=..., ...)` | any | generic / mixed / runtime-chosen |
|
|
77
|
+
|
|
78
|
+
See [`docs/usage.md`](docs/usage.md) for an example of each.
|
|
79
|
+
|
|
80
|
+
## Run the demo
|
|
81
|
+
|
|
82
|
+
A standalone demo app (`reflex_charts_demo/`) shows a gallery of every chart
|
|
83
|
+
type plus a state-driven, click-aware interactive example.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install -e . # install the component (editable)
|
|
87
|
+
cd reflex_charts_demo
|
|
88
|
+
reflex run # open http://localhost:3000
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Build & publish (custom component)
|
|
92
|
+
|
|
93
|
+
This repo follows the [Reflex custom-component](https://reflex.dev/docs/custom-components/overview/)
|
|
94
|
+
layout, so the standard tooling works:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
reflex component build # build the wheel/sdist into dist/
|
|
98
|
+
reflex component publish # upload to PyPI (needs a PyPI token)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The build ships typed `.pyi` stubs (and a `py.typed` marker) for editor
|
|
102
|
+
autocomplete. To **regenerate** the stubs after changing component props, make
|
|
103
|
+
the source importable by its on-disk path so Reflex's stub generator can load it:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
PYTHONPATH="$PWD" reflex component build
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Project layout
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
reflex-charts/
|
|
113
|
+
├── custom_components/
|
|
114
|
+
│ └── reflex_charts/ # the importable component package (PyPI: reflex-charts)
|
|
115
|
+
│ ├── base.py # ChartJSBase: deps + Chart.js registration
|
|
116
|
+
│ ├── chart.py # ChartCanvas + typed factories
|
|
117
|
+
│ ├── helpers.py # dataset / chart_data / options builders
|
|
118
|
+
│ ├── constants.py # npm pins, chart types, palette
|
|
119
|
+
│ └── examples/data.py # canonical sample figures
|
|
120
|
+
├── reflex_charts_demo/ # standalone demo app (gallery + interactive)
|
|
121
|
+
│ ├── rxconfig.py
|
|
122
|
+
│ └── reflex_charts_demo/reflex_charts_demo.py
|
|
123
|
+
├── specs/ # Spec-Driven Design artifacts (see below)
|
|
124
|
+
├── docs/usage.md # usage guide
|
|
125
|
+
├── tests/ # unit tests
|
|
126
|
+
└── scripts/ # GitHub bootstrap helper
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Design docs (Spec-Driven Design)
|
|
130
|
+
|
|
131
|
+
This repository is built spec-first. The full SDD set lives in
|
|
132
|
+
[`specs/`](specs/README.md):
|
|
133
|
+
|
|
134
|
+
- [Specification / PRD](specs/prd/reflex-charts-prd.md)
|
|
135
|
+
- [Architecture](specs/technical/architecture.md) (incl. ADRs)
|
|
136
|
+
- [Component API v1](specs/api/component-api-v1.md)
|
|
137
|
+
- [Data model](specs/data-model/chart-data-schemas.md)
|
|
138
|
+
- [Phases](specs/phases/phases.md)
|
|
139
|
+
- [Implementation plan](specs/plans/implementation-plan.md)
|
|
140
|
+
- [Task breakdown](specs/tasks/task-breakdown.md)
|
|
141
|
+
|
|
142
|
+
## How it works
|
|
143
|
+
|
|
144
|
+
Reflex compiles Python components to React. `reflex-charts` declares a component
|
|
145
|
+
whose generated JSX is the generic `<Chart>` from `react-chartjs-2`, with
|
|
146
|
+
Chart.js registered globally (`Chart.register(...registerables)`) so any `type`
|
|
147
|
+
renders. Your `data`/`options` dicts are serialized to props; on interaction,
|
|
148
|
+
Chart.js events are forwarded back to your Reflex state. See the
|
|
149
|
+
[architecture doc](specs/technical/architecture.md) for the details and the
|
|
150
|
+
decision records.
|
|
151
|
+
|
|
152
|
+
## Acknowledgements
|
|
153
|
+
|
|
154
|
+
Built on the excellent [Chart.js](https://www.chartjs.org) and
|
|
155
|
+
[react-chartjs-2](https://react-chartjs-2.js.org) projects (both MIT licensed —
|
|
156
|
+
see [`NOTICE`](NOTICE)) and the [Reflex](https://reflex.dev) framework.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
[Apache-2.0](LICENSE) © 2026 Ernesto Crespo.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""reflex-charts: a pure-Python Reflex wrapper around Chart.js.
|
|
2
|
+
|
|
3
|
+
Wraps `react-chartjs-2 <https://react-chartjs-2.js.org>`_ (the React bindings
|
|
4
|
+
for `Chart.js <https://www.chartjs.org>`_) as a Reflex custom component, so the
|
|
5
|
+
full Chart.js feature set is usable from Python without writing any JavaScript.
|
|
6
|
+
|
|
7
|
+
Quick start::
|
|
8
|
+
|
|
9
|
+
import reflex as rx
|
|
10
|
+
import reflex_charts as rxc
|
|
11
|
+
|
|
12
|
+
data = rxc.chart_data(
|
|
13
|
+
labels=["Jan", "Feb", "Mar"],
|
|
14
|
+
datasets=[rxc.dataset("Sales", [10, 25, 18])],
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def index() -> rx.Component:
|
|
18
|
+
return rx.box(
|
|
19
|
+
rxc.line(data=data, options=rxc.options(title="Monthly sales")),
|
|
20
|
+
height="320px",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
Every chart type (line, bar, radar, doughnut, pie, polarArea, bubble, scatter)
|
|
24
|
+
is available either through the generic :func:`chart` factory or its named
|
|
25
|
+
helper. The :func:`dataset`, :func:`categorical_dataset`, :func:`chart_data`
|
|
26
|
+
and :func:`options` builders are optional sugar over raw Chart.js dicts.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from .chart import (
|
|
32
|
+
ChartCanvas,
|
|
33
|
+
bar,
|
|
34
|
+
bubble,
|
|
35
|
+
chart,
|
|
36
|
+
doughnut,
|
|
37
|
+
line,
|
|
38
|
+
pie,
|
|
39
|
+
polar_area,
|
|
40
|
+
radar,
|
|
41
|
+
scatter,
|
|
42
|
+
)
|
|
43
|
+
from .constants import CHART_TYPES, PALETTE
|
|
44
|
+
from .helpers import categorical_dataset, chart_data, dataset, options
|
|
45
|
+
|
|
46
|
+
__version__ = "0.1.0"
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"__version__",
|
|
50
|
+
# component
|
|
51
|
+
"ChartCanvas",
|
|
52
|
+
# factories
|
|
53
|
+
"chart",
|
|
54
|
+
"line",
|
|
55
|
+
"bar",
|
|
56
|
+
"radar",
|
|
57
|
+
"doughnut",
|
|
58
|
+
"pie",
|
|
59
|
+
"polar_area",
|
|
60
|
+
"bubble",
|
|
61
|
+
"scatter",
|
|
62
|
+
# builders
|
|
63
|
+
"dataset",
|
|
64
|
+
"categorical_dataset",
|
|
65
|
+
"chart_data",
|
|
66
|
+
"options",
|
|
67
|
+
# constants
|
|
68
|
+
"CHART_TYPES",
|
|
69
|
+
"PALETTE",
|
|
70
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Base wrapper around Chart.js / react-chartjs-2 for Reflex.
|
|
2
|
+
|
|
3
|
+
This module defines the low-level bridge between Reflex (pure Python) and the
|
|
4
|
+
``react-chartjs-2`` React bindings for Chart.js. Every public chart component in
|
|
5
|
+
:mod:`reflex_charts` ultimately inherits from :class:`ChartJSBase`.
|
|
6
|
+
|
|
7
|
+
The base class is responsible for three things:
|
|
8
|
+
|
|
9
|
+
1. Declaring the npm dependencies (``react-chartjs-2`` and ``chart.js``).
|
|
10
|
+
2. Importing the Chart.js registry symbols on the generated frontend.
|
|
11
|
+
3. Registering **all** Chart.js controllers, elements, scales and plugins via
|
|
12
|
+
``ChartJS.register(...registerables)`` so that any chart ``type`` works out
|
|
13
|
+
of the box without the user having to register pieces manually.
|
|
14
|
+
|
|
15
|
+
Pinning the npm versions keeps generated apps reproducible. Bump the constants
|
|
16
|
+
in :mod:`reflex_charts.constants` to upgrade.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import reflex as rx
|
|
22
|
+
|
|
23
|
+
from .constants import CHARTJS_NPM, REACT_CHARTJS_2_NPM
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChartJSBase(rx.Component):
|
|
27
|
+
"""Common base for every Chart.js powered Reflex component.
|
|
28
|
+
|
|
29
|
+
Subclasses only need to set ``tag`` (the export name from
|
|
30
|
+
``react-chartjs-2``) and declare the props they accept. The dependency
|
|
31
|
+
wiring and global registration handled here are inherited automatically.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# The npm package that provides the React bindings.
|
|
35
|
+
library = REACT_CHARTJS_2_NPM
|
|
36
|
+
|
|
37
|
+
# Chart.js itself is a peer dependency of react-chartjs-2.
|
|
38
|
+
lib_dependencies: list[str] = [CHARTJS_NPM]
|
|
39
|
+
|
|
40
|
+
def add_imports(self) -> dict[str, list[str]]:
|
|
41
|
+
"""Import the Chart.js registry helpers on the frontend.
|
|
42
|
+
|
|
43
|
+
``registerables`` is the bundle of all built-in controllers, elements,
|
|
44
|
+
scales and plugins shipped with Chart.js.
|
|
45
|
+
"""
|
|
46
|
+
return {"chart.js": ["Chart as ChartJS", "registerables"]}
|
|
47
|
+
|
|
48
|
+
def add_custom_code(self) -> list[str]:
|
|
49
|
+
"""Register every Chart.js building block exactly once per module.
|
|
50
|
+
|
|
51
|
+
Chart.js de-duplicates repeated registrations, so emitting this for each
|
|
52
|
+
component class is safe. It is what lets a single generic ``Chart``
|
|
53
|
+
component render line, bar, radar, doughnut, pie, polar-area, bubble and
|
|
54
|
+
scatter charts interchangeably.
|
|
55
|
+
"""
|
|
56
|
+
return ["ChartJS.register(...registerables);"]
|