Skip to content

Add explicit export dimensions to ChartEncoder - #1034

Closed
PHJ2000 wants to merge 1 commit into
knowm:developfrom
PHJ2000:feature-export-dimensions
Closed

PHJ2000 wants to merge 1 commit into
knowm:developfrom
PHJ2000:feature-export-dimensions

Conversation

@PHJ2000

@PHJ2000 PHJ2000 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Adds explicit width and height to ChartEncoder file, stream and byte-array exports, so callers can choose the output size without rebuilding a chart.

ChartEncoder.saveChart(chart, "chart", "png", 1920, 1080);

The overloads reuse the existing raster/vector/PDF encoders through an IChart view with the requested dimensions. Charts are laid out at that size rather than scaling a rendered image. Invalid dimensions are rejected before opening the output file.

Rendering follows the existing IChart.paint behavior: XChart charts retain the last rendered dimensions. This is documented in the API and README. Existing overloads are unchanged.

Includes TestForIssue807 and tests for XY/pie/category charts, PNG/JPEG dimensions, SVG viewBox and PDF page size, stream ownership, file extensions, and invalid dimensions preserving existing files.

Validation: Java 11 mvn clean verify — 175 tests passed. The demo also rendered at 1280×720 and 600×800 headlessly. The repository skips mvn fmt:check; changed Java files pass a direct check with its google-java-format 1.23.0 version.

Fixes #807.

@timmolter

Copy link
Copy Markdown
Member

Thanks for taking this on, and for the thorough tests. We went a different direction for #807 in #1036, which has now been merged: Chart.setSize(width, height) is a public fluent setter, so a chart received from elsewhere can be resized before calling any of the existing ChartEncoder methods.

chart.setSize(1920, 1080);
ChartEncoder.saveChart(chart, "./MyChart", "png");

That covers the same use case with a single method instead of three overloads, and it makes the size change explicit rather than a side effect of exporting. Closing this one in favor of that approach. Your other two PRs (#1033 and #1035) are still being looked at.

@timmolter timmolter closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setting the size (dimensions) of the image when saving

2 participants