Repository navigation
Add Chart.setSize so a chart can be resized before export - #1036
Merged
Merged
Conversation
A chart's width and height could only be set through the builder, so a chart constructed by code the caller does not control could not be exported at a chosen size. setSize is a public fluent setter that updates both dimensions, which every exporter already reads from the chart. Fixes #807 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public, fluent
setSize(int width, int height)toChart. Until now a chart's dimensions could only be set via the builder, so a chart constructed by code outside the caller's control (the case in #807) could not be exported at a chosen size. The existingsetWidth/setHeightare protected and stay that way.Every exporter (
BitmapEncoder,VectorGraphicsEncoder,PdfboxGraphicsEncoder) already readsgetWidth()/getHeight()from the chart, so no encoder changes are needed and all formats pick up the new size. Non-positive dimensions throwIllegalArgumentException.This is an alternative to #1034, which adds width/height overloads to
ChartEncoder. A single setter on the chart covers the same use case with less API surface, makes the size change explicit rather than a side effect of exporting, and also helps anyone who wants to resize a chart before handing it to a Swing panel.Changes
Chart.setSize(int, int)returningthisChartSizeTest: chaining, validation, PNG dimensions, SVG viewBox, PDF page size, pie and category chartsTestForIssue807demoTest plan
mvn -pl xchart test: 180 tests, 0 failuresxchart-democompilesFixes #807
🤖 Generated with Claude Code