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

Chalk-Numpy Version 3 #140

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
384dbd1
numpy
srush May 28, 2024
852fb6b
numpy
srush May 28, 2024
4175891
numpy
srush May 28, 2024
b015027
fix to work with pure numpy
srush May 29, 2024
ae6f310
multi envelope
srush May 30, 2024
9053132
multi envelope
srush May 30, 2024
d46ba1b
paths
srush May 31, 2024
7e2d1ff
trace
srush May 31, 2024
642e0c0
numpy
srush May 31, 2024
c69e4cb
numpy
srush Jun 1, 2024
9d2512a
diff
srush Jun 3, 2024
6cd8421
working diff
srush Jun 4, 2024
06e3e77
color rendering
srush Jun 6, 2024
25bb3a9
fix svg
srush Jun 9, 2024
06859af
fix svg
srush Jun 9, 2024
e583b8c
deriv example
srush Jun 10, 2024
4803f44
deriv example
srush Jun 11, 2024
76fc8d9
mess around
srush Jun 12, 2024
6c10a42
done
srush Jun 13, 2024
b818ff5
envelope
srush Jun 19, 2024
695de84
prototype batched diagram
srush Jun 19, 2024
a2110f5
fix trace
srush Jun 20, 2024
c6c9f42
namespace
srush Jun 20, 2024
02513e1
namespace
srush Jun 20, 2024
0991c9f
jax only version
srush Jun 28, 2024
9b0077b
test
srush Jun 30, 2024
d538a58
regroup files
srush Jul 30, 2024
3645a29
.
srush Jul 31, 2024
a6a4155
text
srush Aug 1, 2024
e2212c0
update
srush Aug 2, 2024
6234137
update
srush Aug 4, 2024
cd64457
update
srush Aug 5, 2024
b30bcad
update
srush Aug 5, 2024
80a78ef
updates to typing
srush Aug 7, 2024
603adc1
tests pass
srush Aug 8, 2024
dccbaf1
tests pass
srush Aug 8, 2024
08599a6
typing
srush Aug 9, 2024
c00c4f2
faster version
srush Aug 10, 2024
e6294d9
more examples
srush Aug 18, 2024
00e9873
more examples
srush Aug 18, 2024
225ff85
more examples
srush Aug 18, 2024
75a0620
update
srush Aug 18, 2024
ca60357
update
srush Aug 18, 2024
fddaeb1
update
srush Aug 18, 2024
baa7be3
more examples
srush Aug 18, 2024
2af4ca7
more examples
srush Aug 18, 2024
be080aa
more examples
srush Aug 18, 2024
3db6740
update
srush Aug 18, 2024
0d25d72
more examples
srush Aug 18, 2024
09aa6a6
more examples
srush Aug 18, 2024
e66138f
update
srush Aug 19, 2024
b2a2ece
update
srush Aug 19, 2024
efdc88a
svg animation
srush Aug 20, 2024
d6b5945
update
srush Aug 21, 2024
bf4b6ce
.
srush Aug 28, 2024
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
36 changes: 6 additions & 30 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.10"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -17,41 +17,17 @@ jobs:
- name: Install dependencies
run: |
sudo apt update && sudo apt upgrade -y
sudo apt-get install libcairo2-dev pdf2svg texlive texlive-science texlive-latex-recommended texlive-latex-extra
sudo apt-get install libcairo2-dev
python -m pip install --upgrade pip
pip install -U pip wheel
make install.dev install.base install.e install.docs
- name: Format with [[ isort ]]
run: |
# stop the build if there are errors raised by isort
make isort
- name: Format with [[ black ]]
run: |
# stop the build if there are errors raised by black
make black
- name: Lint with [[ flake8 ]]
run: |
# stop the build if there are Python syntax errors or undefined names
make flake
- name: Docstring linting -- type check against function/method signature with [[ darglint ]]
run: |
# stop the build if docstring type-mismatch detected
make darglint
- name: Doctest coverage check with [[ interrogate ]]
run: |
# stop the build if doctest threshold does not meet
make interrogate
- name: Type check with [[ mypy ]]
run: |
# stop the build if there are type errors
make type
- name: Unit test with [[ pytest ]]
pip install -r requirements.txt -r requirements/dev.txt
- name: Check types with pyright
run: |
# stop the build if there are type errors
make test
pyright
- name: Make sure examples run
run: |
make images
- name: Make sure docs run
run: |
make docsapi
make
69 changes: 27 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,64 +273,49 @@ gendocsall.local: pregendocs.local gendocs postgendocs.local

####------------------------------------------------------------####

### Generate Output for Examples

intro:
python examples/intro.py

squares:
python examples/squares.py
# Define the examples directory
EXAMPLES_DIR := examples

hanoi:
python examples/hanoi.py
# List of images to be generated
IMAGES := squares bigben hanoi intro hilbert koch tensor hex_variation tree tournament parade arrows lenet escher_square logo

escher_square:
python examples/escher_square_limit.py

lattice:
python examples/lattice.py

lenet:
python examples/lenet.py

logo:
python examples/logo.py

hilbert:
python examples/hilbert.py

koch:
python examples/koch.py
# Generate the images
images: $(IMAGES)
@echo "🎁 Generate all examples ... ⏳"

tensor:
python examples/tensor.py
# Rule to process each image
$(IMAGES):
CHALK_CHECK=1 python $(EXAMPLES_DIR)/[email protected]
# jupytext --execute --run-path . --set-kernel chalk --to ipynb -o $(EXAMPLES_DIR)/output/[email protected] $(EXAMPLES_DIR)/[email protected]
# jupyter nbconvert --to html $(EXAMPLES_DIR)/output/[email protected]

latex:
python examples/latex.py
# List of images to be generated
VISTESTS := alignment animation arc broadcast combinators envelope names path rendering shapes styles subdiagram trails transformations trace text

hex_variation:
python examples/hex_variation.py
VT_DIR := api

tree:
python examples/tree.py
vis: $(VISTESTS)
@echo "🎁 Generate all vis tests ... ⏳"

tournament:
python examples/tournament-network.py

parade:
python examples/rectangle_parade.py
$(VISTESTS):
@echo "$@"
CHALK_CHECK=1 python $(VT_DIR)/[email protected]
# jupytext --to ipynb -o $(VT_DIR)/output/[email protected] $(VT_DIR)/[email protected]
# jupyter nbconvert --execute --inplace --to ipynb $(VT_DIR)/output/[email protected]
# jupyter nbconvert --to html $(VT_DIR)/output/[email protected]

arrows:
python examples/arrows.py

path:
python examples/path.py
.PHONY: images $(IMAGES) vis $(VISTESTS)

images: squares hanoi intro hilbert koch tensor hex_variation tree tournament parade arrows path lenet escher_square logo
@echo "🎁 Generate all examples ... ⏳"

serve:
python -m http.server 8080 -d examples/output/

docsapi:
python docs/api/*.py



156 changes: 156 additions & 0 deletions api/alignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# ---
# jupyter:
# jupytext:
# cell_markers: '"""'
# cell_metadata_filter: tags,title,-all
# formats: py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# ---

# %% tags=["hide_inp"]
from chalk.core import BaseDiagram
from chalk import *


# %% [markdown]
"""
Each diagram has an origin and an envelope.
Manipulating the position of the diagram with respect to its origin and envelope allows for precise control of the layout.
Note that the Chalk API is immutable and always returns a new ``Diagram`` object.
"""

# %% [markdown]
"""
### Diagram.show_origin
"""

# %% tags=["hide_inp"]
help(BaseDiagram.show_origin)

# %% [markdown]
"""

"""

# %%
d = triangle(1).show_origin()
from IPython.display import HTML, Image
d.render("test.png")
Image("test.png")


# %%
triangle(1).show_origin()

# %% [markdown]
"""
### Diagram.show_envelope
"""

# %% tags=["hide_inp"]
help(BaseDiagram.show_envelope)

# %% Cell 2
rectangle(1, 1).show_envelope()


# %%
triangle(1).show_envelope()


# %%
rectangle(1, 1).show_beside(triangle(1), unit_x)


# %%
(rectangle(1, 1) | triangle(1)).pad(1.4)


# %%
arc(1, 0, 90)

# %% [markdown]
"""
### Diagram.align_*
"""

# %% tags=["hide_inp"]
help(BaseDiagram.align_t)

# %% [markdown]
"""

"""

# %%
triangle(1).align_t().show_origin()

# %%

# %%
triangle(1).align_t().show_beside(rectangle(1, 1).align_b(), unit_x)


# %% tags=["hide_inp"]
help(BaseDiagram.align_r)

# %% [markdown]
"""
### Diagram.center_xy
"""

# %% tags=["hide_inp"]
help(BaseDiagram.center_xy)

# %% [markdown]
"""

"""

# %%
triangle(1).center_xy().show_envelope().show_origin()


# %% [markdown]
"""
### Diagram.pad_*
"""

# %% tags=["hide_inp"]
help(BaseDiagram.pad)


# %% [markdown]
"""

"""

# %%
triangle(1).pad(1.5).show_envelope().show_origin()


# %% [markdown]
"""
### Diagram.with_envelope
"""

# %% tags=["hide_inp"]
help(BaseDiagram.with_envelope)


# %% [markdown]
"""

"""


# %%
(rectangle(1, 1) + triangle(0.5)) | rectangle(1, 1)


# %%
(rectangle(1, 1) + triangle(0.5)).with_envelope(triangle(0.5)) | rectangle(1, 1).fill_color("red")
21 changes: 21 additions & 0 deletions api/animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# + tags=["hide"]

import numpy as np
from chalk import *

# -


line((0, np.arange(5, 1, -1)), (np.arange(1, 5), 0)).animate_svg("test0.svg")

c = (square(5).fill_color("black") + circle(np.arange(1, 5)))
c.animate("test1.gif")
c.animate_svg("test1.svg")


s = square(10) + (circle(np.arange(5, 1, -1)).translate_by(tx.scale_vec(unit_x, np.arange(1, 6)[:, None]))).concat()
print(s.shape)
s.animate("test2.gif")


s = square(10) + (circle(np.arange(5, 1, -1)).translate_by(tx.scale_vec(unit_x, np.arange(1, 6)[:, None]))).hcat().vcat()
7 changes: 7 additions & 0 deletions api/arc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from chalk import *

arc(1, 0, 270)



square(2).fill_color("orange") + arc(1, 0, 90)
Loading
Loading