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

Export image #11

Merged
merged 20 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions dimes/dimensional_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ def __init__(
x_axis: DimensionalData | TimeSeriesAxis | list[SupportsFloat] | list[datetime],
title: str | None = None,
additional_info: str | None = None,
width: int | None = None,
height: int | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

It looks like these are never set in any calls to this function. Can we remove them?

Copy link
Member Author

Choose a reason for hiding this comment

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

width and height are set in lines 245 and 246. Is that what you mean, or is there something else wrong?

Copy link
Member

Choose a reason for hiding this comment

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

There are two calls to finalize_plot (line 461 and line 471), but neither of them actually pass in width or height so they are always None.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want width and height to be passed into finalize_plot? I was debating whether to pass them into finalize_plot or DimensionalPlot.

If passed into DimensionalPlot, then jpeg and html plots are both adjusted. If only passed into write_plot_image (as well as finalize_plot), then jpeg files are the only files with modified height and width, which makes more sense to me.

We could also pass in width and height into write_html_plot, but I don't think that is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please review latest changes

):
self.figure = Figure()
self.x_axis: DimensionalData | TimeSeriesAxis
Expand All @@ -240,6 +242,8 @@ def __init__(
self.subplots: list[DimensionalSubplot | None] = [None]
self.is_finalized = False
self.figure.layout["title"] = title
self.figure.layout["width"] = width
self.figure.layout["height"] = height
if additional_info is not None:
self.figure.add_trace(
Scatter(
Expand Down Expand Up @@ -456,6 +460,17 @@ def write_html_plot(self, path: Path) -> None:
self.finalize_plot()
self.figure.write_html(path)

def write_image_plot(self, path: Path, scale: int | float | None = None) -> None:
"""
Write plots to html file at specified path.
scale (int, float, None): Adjusts the resolution of the output image.
A value cannot be equal to or less than 0 or greater than 16.
"""
if (scale > 16) | (scale <= 0):
raise ValueError(f"Scale value {scale} cannot be greater than 16 or less than or equal to 0.")
self.finalize_plot()
self.figure.write_image(path, scale=scale)


def get_subplot_domains(number_of_subplots: int, gap: float = 0.05) -> list[tuple[float, float]]:
"""Calculate and return the 'Y' domain ranges for a given number of subplots with the specified gap size."""
Expand Down
19 changes: 17 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions pyproject.toml
Copy link
Member

Choose a reason for hiding this comment

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

Looks like a formatter was automatically applied to this file, causing unrelated diffs. Not sure I like it.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you want to do about it?

Copy link
Member

Choose a reason for hiding this comment

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

Change your editor settings so it doesn't automatically format TOML files (or at least disable the reordering of keywords).

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find the setting. I will need your help.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
[tool.poetry]
name = "dimes"
authors = ["Big Ladder Software"]
description = "A dimensionally aware scientific plotting package."
keywords = ["template"]
license = "BSD-3"
name = "dimes"
readme = "README.md"
repository = "https://github.com/bigladder/dimes"
version = "0.0.0" # Generated from git on CI
description = "A dimensionally aware scientific plotting package."
authors = ["Big Ladder Software"]
license = "BSD-3"
readme = "README.md"
keywords = ["template"]
repository = "https://github.com/bigladder/dimes"

[tool.poetry.dependencies]
python = "^3.10"
plotly = "*"
koozie = "^1.3.0"
kaleido = "==0.2.1" # Required by plotly to save figures as images
koozie = "^1.3.0"
plotly = "*"
python = "^3.10"

[tool.poetry.dev-dependencies]
pytest = "^7.1.3"
pylint = "*"
black = "*"
mypy = "*"
pylint = "*"
pytest = "^7.1.3"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["poetry-core>=1.0.0"]

[tool.black]
line-length = 120

[tool.mypy]
check_untyped_defs = true
disallow_incomplete_defs = true
no_implicit_optional = true
check_untyped_defs = true

[[tool.mypy.overrides]]
module = "dimes.*"
disable_error_code = ["import"]
module = "dimes.*"
Loading