Skip to content

Fix ptable scatter examples in homepage #180

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

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Compress SVG assets and commit to current PR
run: |
svgo --multipass assets
svgo --multipass --final-newline assets --exclude ptable-scatters-*.svg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janosh Wondering why do we exclude ptable scatter here? svgo seem to work just fine on my machine.

Copy link
Owner

@janosh janosh Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svgo is the SVG compressor that kept repeatedly mangling those example plots you fixed in this PR. like you wrote above, i fixed them before

Copy link
Collaborator Author

@DanielYang59 DanielYang59 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked into the history, you indeed fixed them in eb8fd62, and for some reason they got broken again in 3e89e59. Meanwhile I didn't notice svgo to break these two plots on my machine (installed from homebrew)? Perhaps you should try to update svgo on your side?

I'm just wondering why svgo only break scatter plots, not others 🤣

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the commit that broke the assets was d218a46 which was created by the svgo.yml CI workflow, not on my local machine. it always uses the latest svgo (running on Linux which shouldn't matter much since SVGO uses nodejs and so should be largely platform independent).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering why svgo only break scatter plots, not others 🤣

that i don't know. i suspect it's a bug in svgo

Copy link
Collaborator Author

@DanielYang59 DanielYang59 Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful. Thanks for the input. I might collect this in to my TODO list and perhaps report this to the svgo team.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be great! could also be a bug in matplotlib btw. perhaps matplotlib is not following the SVG spec in some way which makes it harder for svgo to losslessly compress. seems less likely though given the SVG renders fine before compression

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! But I would need to figure out how to recreate this in the first place :)

if git diff --quiet assets; then
echo "No changes to commit"
exit 0
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default_install_hook_types: [pre-commit, commit-msg]

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
rev: v0.5.2
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -87,6 +87,6 @@ repos:
- typescript-eslint

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.371
rev: v1.1.372
hooks:
- id: pyright
2 changes: 1 addition & 1 deletion assets/ptable-scatters-parabola.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/ptable-scatters-parity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions pymatviz/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,40 @@ class Key(LabelEnum):
piezoelectric_tensor = "piezoelectric_tensor", "Piezoelectric Tensor"


class Task(LabelEnum):
"""What kind of task is being performed."""

static = "static", "Static" # aka single-point
relax = "relax", "Relaxation" # aka geometry optimization
double_relax = "double_relax", "Double Relaxation"
phonon = "phonon", "Phonon" # aka vibrational analysis
eos = "eos", "Equation of State" # aka volume optimization
band_structure = "band_structure", "Band Structure" # aka electronic structure
dos = "dos", "Density of States"
line_non_scf = "line_non_scf", "Non-SCF Line"
defect = "defect", "Defect"
point_defect = "point_defect", "Point Defect"
line_defect = "line_defect", "Line Defect"
adsorption = "adsorption", "Adsorption" # aka surface adsorption
surface = "surface", "Surface" # aka surface energy
reaction = "reaction", "Reaction" # aka chemical reaction
formation_energy = "formation_energy", "Formation Energy"
bandgap = "bandgap", "Band Gap"
elastic = "elastic", "Elastic"
thermal = "thermal", "Thermal"
magnetic = "magnetic", "Magnetic"
magnetic_ordering = "magnetic_ordering", "Magnetic Ordering"
optical = "optical", "Optical"
dielectric = "dielectric", "Dielectric" # aka optical properties
electronic = "electronic", "Electronic"
synthesis = "synthesis", "Synthesis"
molecular_dynamics = "molecular_dynamics", "Molecular Dynamics"
ion_diffusion = "ion_diffusion", "Ion Diffusion"
electron_transport = "electron_transport", "Electron Transport"
charge_transport = "charge_transport", "Charge Transport"
thermal_transport = "thermal_transport", "Thermal Transport"


@unique
class Model(LabelEnum):
"""Model names."""
Expand Down
6 changes: 4 additions & 2 deletions pymatviz/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def save_and_compress_svg(

# Compress SVG if svgo is available
if (svgo := which("svgo")) is not None:
subprocess.run([svgo, "--multipass", filepath], check=True) # noqa: S603
subprocess.run([svgo, "--multipass", "--final-newline", filepath], check=True) # noqa: S603


DEFAULT_DF_STYLES: Final = {
Expand Down Expand Up @@ -642,7 +642,9 @@ def print_table(
# Compress SVG if requested and svgo is available
if compress:
if (svgo := which("svgo")) is not None:
subprocess.run([svgo, "--multipass", str(file_path)], check=True) # noqa: S603
subprocess.run( # noqa: S603
[svgo, "--multipass", "--final-newline", str(file_path)], check=True
)
else:
print("svgo not found in PATH. SVG compression skipped.") # noqa: T201

Expand Down
2 changes: 1 addition & 1 deletion tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def test_pickle_enum() -> None:
assert type(unpickled_key) is str
assert unpickled_key == "energy_per_atom"
assert unpickled_key == Key.energy_per_atom
assert type(key) == Key
assert type(key) is Key

assert Key.energy.__reduce_ex__(1) == (str, ("energy",))