stockchart 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.
Files changed (58) hide show
  1. stockchart-0.1.0/.gitignore +11 -0
  2. stockchart-0.1.0/LICENSE +144 -0
  3. stockchart-0.1.0/PKG-INFO +279 -0
  4. stockchart-0.1.0/README.md +252 -0
  5. stockchart-0.1.0/README.zh-CN.md +246 -0
  6. stockchart-0.1.0/docs/design.md +461 -0
  7. stockchart-0.1.0/docs/design.zh-CN.md +306 -0
  8. stockchart-0.1.0/pyproject.toml +98 -0
  9. stockchart-0.1.0/src/stockchart/__init__.py +78 -0
  10. stockchart-0.1.0/src/stockchart/assets/leg_01.svg +1 -0
  11. stockchart-0.1.0/src/stockchart/assets/leg_02.svg +1 -0
  12. stockchart-0.1.0/src/stockchart/assets/leg_03.svg +1 -0
  13. stockchart-0.1.0/src/stockchart/assets/leg_04.svg +1 -0
  14. stockchart-0.1.0/src/stockchart/assets/leg_05.svg +1 -0
  15. stockchart-0.1.0/src/stockchart/assets/leg_06.svg +1 -0
  16. stockchart-0.1.0/src/stockchart/assets/leg_07.svg +1 -0
  17. stockchart-0.1.0/src/stockchart/assets/leg_08.svg +1 -0
  18. stockchart-0.1.0/src/stockchart/assets/leg_09.svg +1 -0
  19. stockchart-0.1.0/src/stockchart/assets/leg_10.svg +1 -0
  20. stockchart-0.1.0/src/stockchart/assets/leg_11.svg +1 -0
  21. stockchart-0.1.0/src/stockchart/assets/leg_12.svg +1 -0
  22. stockchart-0.1.0/src/stockchart/assets/leg_13.svg +1 -0
  23. stockchart-0.1.0/src/stockchart/assets/leg_14.svg +1 -0
  24. stockchart-0.1.0/src/stockchart/assets/leg_15.svg +1 -0
  25. stockchart-0.1.0/src/stockchart/assets/leg_16.svg +1 -0
  26. stockchart-0.1.0/src/stockchart/assets/leg_17.svg +1 -0
  27. stockchart-0.1.0/src/stockchart/assets/leg_18.svg +1 -0
  28. stockchart-0.1.0/src/stockchart/assets/leg_19.svg +1 -0
  29. stockchart-0.1.0/src/stockchart/assets/leg_20.svg +1 -0
  30. stockchart-0.1.0/src/stockchart/assets/leg_21.svg +1 -0
  31. stockchart-0.1.0/src/stockchart/assets/leg_22.svg +1 -0
  32. stockchart-0.1.0/src/stockchart/assets/leg_23.svg +1 -0
  33. stockchart-0.1.0/src/stockchart/assets/leg_24.svg +1 -0
  34. stockchart-0.1.0/src/stockchart/assets/leg_25.svg +1 -0
  35. stockchart-0.1.0/src/stockchart/assets/leg_26.svg +1 -0
  36. stockchart-0.1.0/src/stockchart/assets/legs.json +314 -0
  37. stockchart-0.1.0/src/stockchart/canvas.py +70 -0
  38. stockchart-0.1.0/src/stockchart/color.py +23 -0
  39. stockchart-0.1.0/src/stockchart/data.py +250 -0
  40. stockchart-0.1.0/src/stockchart/defaults.py +180 -0
  41. stockchart-0.1.0/src/stockchart/legs.py +97 -0
  42. stockchart-0.1.0/src/stockchart/library.py +202 -0
  43. stockchart-0.1.0/src/stockchart/plot.py +1439 -0
  44. stockchart-0.1.0/src/stockchart/py.typed +0 -0
  45. stockchart-0.1.0/src/stockchart/sketch.py +197 -0
  46. stockchart-0.1.0/src/stockchart/stocking/__init__.py +39 -0
  47. stockchart-0.1.0/src/stockchart/stocking/render.py +1144 -0
  48. stockchart-0.1.0/src/stockchart/stocking/styles.py +515 -0
  49. stockchart-0.1.0/src/stockchart/text.py +279 -0
  50. stockchart-0.1.0/src/stockchart/topline.py +504 -0
  51. stockchart-0.1.0/src/stockchart/vector.py +50 -0
  52. stockchart-0.1.0/tests/test_data.py +231 -0
  53. stockchart-0.1.0/tests/test_plot_annotations.py +366 -0
  54. stockchart-0.1.0/tests/test_plot_core.py +116 -0
  55. stockchart-0.1.0/tests/test_plot_layout.py +188 -0
  56. stockchart-0.1.0/tests/test_primitives.py +195 -0
  57. stockchart-0.1.0/tests/test_render.py +423 -0
  58. stockchart-0.1.0/tests/test_topline.py +313 -0
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ /out/
10
+ .zcode/
11
+ temp/
@@ -0,0 +1,144 @@
1
+ Mozilla Public License Version 2.0
2
+
3
+ 1. Definitions
4
+
5
+ 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
6
+
7
+ 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution.
8
+
9
+ 1.3. "Contribution" means Covered Software of a particular Contributor.
10
+
11
+ 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
12
+
13
+ 1.5. "Incompatible With Secondary Licenses" means
14
+
15
+ (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
16
+
17
+ (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
18
+
19
+ 1.6. "Executable Form" means any form of the work other than Source Code Form.
20
+
21
+ 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
22
+
23
+ 1.8. "License" means this document.
24
+
25
+ 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
26
+
27
+ 1.10. "Modifications" means any of the following:
28
+
29
+ (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
30
+
31
+ (b) any new file in Source Code Form that contains any Covered Software.
32
+
33
+ 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
34
+
35
+ 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
36
+
37
+ 1.13. "Source Code Form" means the form of the work preferred for making modifications.
38
+
39
+ 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
40
+
41
+ 2. License Grants and Conditions
42
+
43
+ 2.1. Grants
44
+ Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
45
+
46
+ (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
47
+
48
+ (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
49
+
50
+ 2.2. Effective Date
51
+ The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
52
+
53
+ 2.3. Limitations on Grant Scope
54
+ The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
55
+
56
+ (a) for any code that a Contributor has removed from Covered Software; or
57
+
58
+ (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
59
+
60
+ (c) under Patent Claims infringed by Covered Software in the absence of its Contributions.
61
+
62
+ This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
63
+
64
+ 2.4. Subsequent Licenses
65
+ No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
66
+
67
+ 2.5. Representation
68
+ Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
69
+
70
+ 2.6. Fair Use
71
+ This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
72
+
73
+ 2.7. Conditions
74
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
75
+
76
+ 3. Responsibilities
77
+
78
+ 3.1. Distribution of Source Form
79
+ All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form.
80
+
81
+ 3.2. Distribution of Executable Form
82
+ If You distribute Covered Software in Executable Form then:
83
+
84
+ (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
85
+
86
+ (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License.
87
+
88
+ 3.3. Distribution of a Larger Work
89
+ You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
90
+
91
+ 3.4. Notices
92
+ You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
93
+
94
+ 3.5. Application of Additional Terms
95
+ You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
96
+
97
+ 4. Inability to Comply Due to Statute or Regulation
98
+ If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
99
+
100
+ 5. Termination
101
+
102
+ 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
103
+
104
+ 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
105
+
106
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
107
+
108
+ 6. Disclaimer of Warranty
109
+ Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
110
+
111
+ 7. Limitation of Liability
112
+ Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
113
+
114
+ 8. Litigation
115
+ Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims.
116
+
117
+ 9. Miscellaneous
118
+ This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
119
+
120
+ 10. Versions of the License
121
+
122
+ 10.1. New Versions
123
+ Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
124
+
125
+ 10.2. Effect of New Versions
126
+ You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
127
+
128
+ 10.3. Modified Versions
129
+ If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
130
+
131
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
132
+ If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.
133
+
134
+ Exhibit A - Source Code Form License Notice
135
+
136
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
137
+
138
+ If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
139
+
140
+ You may add additional accurate notices of copyright ownership.
141
+
142
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
143
+
144
+ This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.5
2
+ Name: stockchart
3
+ Version: 0.1.0
4
+ Summary: A creative plotting library that draws data as stockings pulled up over a pair of legs.
5
+ Project-URL: Homepage, https://github.com/xie-huaaaan/stockchart
6
+ Project-URL: Repository, https://github.com/xie-huaaaan/stockchart
7
+ Project-URL: Issues, https://github.com/xie-huaaaan/stockchart/issues
8
+ Project-URL: Documentation, https://github.com/xie-huaaaan/stockchart/blob/main/docs/api/index.md
9
+ Author: xie-huaaaan
10
+ License-Expression: MPL-2.0
11
+ License-File: LICENSE
12
+ Keywords: charts,creative-coding,data-visualization,infographics,plotting,skia
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Multimedia :: Graphics
20
+ Classifier: Topic :: Scientific/Engineering :: Visualization
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: numpy>=2.5
24
+ Requires-Dist: pillow>=13.0
25
+ Requires-Dist: skia-python>=144.1
26
+ Description-Content-Type: text/markdown
27
+
28
+ # Stock Chart
29
+
30
+ [English](README.md) | [简体中文](README.zh-CN.md)
31
+
32
+ [![PyPI](https://img.shields.io/pypi/v/stockchart)](https://pypi.org/project/stockchart/)
33
+ [![Python](https://img.shields.io/badge/python-3.12%2B-blue)](https://www.python.org/)
34
+ [![License: MPL 2.0](https://img.shields.io/badge/license-MPL--2.0-blue)](LICENSE)
35
+
36
+ **A creative plotting library that draws data as stockings pulled up over a pair of legs.**
37
+
38
+ ![A grouped stockchart: two series over three months](docs/images/hero.png)
39
+
40
+ `stockchart` is a playful alternative to the bar chart. Each value becomes the height of a
41
+ stocking pulled up over a leg: a larger value means more stocking, and zero is a bare leg.
42
+ It is made for infographics, slides, posters, and anywhere a chart should be memorable
43
+ rather than conventional.
44
+
45
+ - **Values → stocking height.** Grouped, paired, and positive/negative mirror charts are
46
+ supported.
47
+ - **19 built-in styles.** Sheer, opaque tights, stripes, knit, fishnet, polka dots, hearts,
48
+ lace trims, and more.
49
+ - **Data-science friendly.** Lists, NumPy arrays, dictionaries, and pandas
50
+ `DataFrame`/`Series`. pandas is optional and never imported by the library itself.
51
+ - **Native high-resolution output.** Stocking textures and lighting are generated at the
52
+ target pixel density, not upscaled from a bitmap.
53
+ - **Composable by design.** Start with one-line `bar()`; drop down to pixel-level placement
54
+ when you need a custom layout.
55
+ - **No matplotlib.** Text and lines are rendered with Skia, including a per-character font
56
+ fallback for Chinese, Japanese, and Korean.
57
+
58
+ <table>
59
+ <tr>
60
+ <td width="50%" align="center">
61
+ <img src="docs/images/showcase-grouped.png" alt="A grouped chart comparing planned and actual weekend hours"><br>
62
+ <sub>Grouped chart — <code>black_sheer</code> (welt) and <code>white_sheer</code> (lace)</sub>
63
+ </td>
64
+ <td width="50%" align="center">
65
+ <img src="docs/images/showcase-single.png" alt="A single-series chart with negative values, all legs upright"><br>
66
+ <sub>Single series with negative values — every leg stays upright (<code>heart_white</code>)</sub>
67
+ </td>
68
+ </tr>
69
+ <tr>
70
+ <td width="62%" align="center">
71
+ <img src="docs/images/showcase-styles.png" width="95%" alt="Seven legs wearing seven different stocking styles"><br>
72
+ <sub>A sweep of presets — 5 fabric types, 4 top edges</sub>
73
+ </td>
74
+ <td width="38%" align="center">
75
+ <img src="docs/images/showcase-mirror.png" width="62%" alt="A mirror chart with positive and negative values"><br>
76
+ <sub>Mirror chart — positive and negative values</sub>
77
+ </td>
78
+ </tr>
79
+ </table>
80
+
81
+ ## Installation
82
+
83
+ ```bash
84
+ pip install stockchart
85
+ ```
86
+
87
+ or with [uv](https://docs.astral.sh/uv/):
88
+
89
+ ```bash
90
+ uv add stockchart
91
+ ```
92
+
93
+ Requires Python 3.12 or newer. Runtime dependencies are `skia-python`, `numpy`, and
94
+ `pillow`.
95
+
96
+ ## Quick start
97
+
98
+ ```python
99
+ from stockchart import bar
100
+
101
+ bar(
102
+ [[320, 210], [450, 280], [510, 190]],
103
+ labels=["Jan", "Feb", "Mar"],
104
+ series_labels=["This site", "Neighbor"],
105
+ title="Monthly report",
106
+ xlabel="Month",
107
+ ylabel="Active users",
108
+ style=["black_sheer", "white_sheer"],
109
+ value_labels=True,
110
+ seed=2,
111
+ ).save("chart.png")
112
+ ```
113
+
114
+ The result is the image at the top of this README. `bar()` maps the data, chooses leg
115
+ assets, lays out groups, and draws the axes. It returns a `BarPlot` that can be saved
116
+ directly or adjusted further.
117
+
118
+ A mirror chart for positive and negative values:
119
+
120
+ ```python
121
+ from stockchart import mirror_bar
122
+
123
+ mirror_bar(
124
+ [4.2, -2.8, 6.1, -5.5, 3.4, -1.9],
125
+ labels=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
126
+ title="Daily change",
127
+ style="gray_sheer",
128
+ value_labels=True,
129
+ seed=2,
130
+ ).save("mirror.png")
131
+ ```
132
+
133
+ ## Data input
134
+
135
+ Pass the data structure you already have:
136
+
137
+ | Input | How it is interpreted |
138
+ | --- | --- |
139
+ | 1-D list / tuple / sequence | One series |
140
+ | 2-D sequence `(groups, series)` | Grouped data |
141
+ | `numpy.ndarray` | 1-D or 2-D arrays |
142
+ | `dict` of scalars | Keys become x-axis labels, one series |
143
+ | `dict` of equal-length sequences | Keys become series names and a legend is generated |
144
+ | pandas `DataFrame` | Index → x labels, columns → series names |
145
+ | pandas `Series` | Index → x labels, one series |
146
+ | `PlotData` | Already-normalized data |
147
+
148
+ For example, a DataFrame gets its labels and legend automatically:
149
+
150
+ ```python
151
+ import pandas as pd
152
+ from stockchart import bar
153
+
154
+ df = pd.DataFrame(
155
+ {"This site": [320, 450, 510], "Neighbor": [210, 280, 190]},
156
+ index=["Jan", "Feb", "Mar"],
157
+ )
158
+ bar(df, title="Monthly report", style=["black_sheer", "white_sheer"]).save("chart.png")
159
+ ```
160
+
161
+ Explicit `labels=` and `series_labels=` override anything inferred from the data. Custom
162
+ containers can be registered with `register_data_type`; see the
163
+ [data input reference](docs/api/data-input.md).
164
+
165
+ ## Stocking styles
166
+
167
+ Pass a preset name, or a list of names to cycle through styles:
168
+
169
+ ```python
170
+ bar(
171
+ [5, 6, 7, 8, 6, 9, 4],
172
+ labels=["Sheer", "Lace", "Stripe", "Knit", "Fishnet", "Dots", "Tights"],
173
+ title="One of each",
174
+ style=[
175
+ "nude_sheer",
176
+ "white_sheer",
177
+ "stripe_rainbow",
178
+ "knit_cream",
179
+ "fishnet_black",
180
+ "polka_black",
181
+ "black_pantyhose",
182
+ ],
183
+ value_labels=True,
184
+ seed=3,
185
+ )
186
+ ```
187
+
188
+ The 19 presets cover sheer stockings, opaque tights, stripes, ribbed knit, fishnet,
189
+ polka dots, hearts, lace trims, and more. For direct control, pass a `StockingStyle`
190
+ built from `Plain`, `Striped`, `Ribbed`, `Fishnet`, or `Dotted` fabrics with a
191
+ `Bare`, `Welt`, `Lace`, or `Fade` top edge. The full style table is in the
192
+ [rendering reference](docs/api/rendering.md).
193
+
194
+ ## Titles, axis names, and options
195
+
196
+ ```python
197
+ bar(
198
+ data,
199
+ title="Monthly report", # centered over the plot by default
200
+ xlabel="Month",
201
+ ylabel="Active users",
202
+ title_align="left", # restore a left-aligned title
203
+ grid=True,
204
+ axis_style="handdrawn",
205
+ legend_loc="bottom",
206
+ )
207
+ ```
208
+
209
+ Chart-level parameters stay in the signature; lower-level options such as `grid`,
210
+ `axis_style`, `legend_loc`, `legend_ncol`, `x_label_rotation`, `bar_gap`, and `group_gap`
211
+ are passed through a typed option bag. See the
212
+ [`ChartOptions` table](docs/api/charts.md).
213
+
214
+ ## API layers
215
+
216
+ The library is deliberately layered, so you can choose how much control you want:
217
+
218
+ | Layer | What it gives you | Entry points |
219
+ | --- | --- | --- |
220
+ | L0 assets | Leg metadata and built-in artwork | `Leg`, `LegLibrary`, `load_leg` |
221
+ | L1 primitives | One stocking, text, hand-drawn lines | `render_stocking`, `StockingStyle`, `STYLES`, `draw_text`, `sketch_*` |
222
+ | L2 free-form plot | Canvas, baseline, arbitrary leg placement | `BarPlot`, `Scale`, `Canvas` |
223
+ | L3 layout helpers | Uniform spacing and automatic leg selection | `add_bars`, `add_grouped_bars`, `add_paired_bars` |
224
+ | L4 one-liners | Data normalization and fully automatic layout | `bar`, `mirror_bar` |
225
+
226
+ For a more hands-on layout:
227
+
228
+ ```python
229
+ from stockchart import BarPlot, Scale
230
+
231
+ plot = BarPlot(1200)
232
+ plot.add_bars([300, 500, 400], style="black_sheer")
233
+ plot.add_x_labels(["A", "B", "C"])
234
+ plot.add_y_axis(Scale((0, 500), (0, 760)))
235
+ plot.add_title("Free-form layout")
236
+ plot.save("chart.png")
237
+ ```
238
+
239
+ ## Output
240
+
241
+ `BarPlot` renders to PNG and can also return a PIL image or a NumPy array:
242
+
243
+ ```python
244
+ plot.save("chart.png", scale=2) # PNG at 2× pixel density
245
+ image = plot.to_pil()
246
+ array = plot.to_numpy()
247
+ ```
248
+
249
+ `scale` controls output pixel density; stocking textures and lighting are regenerated at
250
+ that density. SVG and PDF output are intentionally not supported.
251
+
252
+ ## Documentation
253
+
254
+ - [API reference](docs/api/index.md) — one page per layer
255
+ - [Design notes](docs/design.md)
256
+
257
+ ## Development
258
+
259
+ ```bash
260
+ git clone https://github.com/xie-huaaaan/stockchart.git
261
+ cd stockchart
262
+ uv sync
263
+ uv run python -m pytest
264
+ uv run ruff check . && uv run ruff format .
265
+ uv run python -m pyright
266
+ ```
267
+
268
+ Issues and pull requests are welcome.
269
+
270
+ ## Status
271
+
272
+ `0.1.x` is an early public release. The rendering pipeline is stable, but the public API
273
+ may still change in minor releases.
274
+
275
+ ## License
276
+
277
+ Released under the [Mozilla Public License 2.0](LICENSE) (MPL-2.0). You can use
278
+ `stockchart` in closed-source projects; if you modify MPL-covered source files, those
279
+ files must remain available under MPL-2.0.