Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions src/main/java/org/jfree/chart/block/FlowArrangement.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2,
double x = 0.0;
double y = 0.0;
double maxHeight = 0.0;
List<Block> itemsInRow = new ArrayList<>();
boolean haveItemsInRow = false;
for (Block block : blocks) {
Size2D size = block.arrange(g2, RectangleConstraint.NONE);
if (x + size.width <= width) {
itemsInRow.add(block);
haveItemsInRow = true;
block.setBounds(
new Rectangle2D.Double(x, y, size.width, size.height)
);
x = x + size.width + this.horizontalGap;
maxHeight = Math.max(maxHeight, size.height);
}
else {
if (itemsInRow.isEmpty()) {
if (!haveItemsInRow) {
// place in this row (truncated) anyway
block.setBounds(
new Rectangle2D.Double(
Expand All @@ -199,7 +199,6 @@ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2,
}
else {
// start new row
Copy link

Choose a reason for hiding this comment

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

Should we not reinitialize haveItemsInRow to false here?

Copy link
Author

@cinsttool cinsttool Sep 1, 2024

Choose a reason for hiding this comment

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

The original code clears the itemsInRow and adds an element to the itemsInRow afterwards in the same code block.

So I think the reinitialization is not required.

itemsInRow.clear();
x = 0.0;
y = y + maxHeight + this.verticalGap;
maxHeight = size.height;
Expand All @@ -209,7 +208,7 @@ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2,
)
);
x = size.width + this.horizontalGap;
itemsInRow.add(block);
haveItemsInRow = true;
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/jfree/chart/plot/XYPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3986,9 +3986,8 @@ public void handleClick(int x, int y, PlotRenderingInfo info) {
*
* @return A list of datasets.
*/
private List<XYDataset<S>> getDatasetsMappedToDomainAxis(Integer axisIndex) {
private List<XYDataset<S>> getDatasetsMappedToDomainAxis(Integer axisIndex, List<XYDataset<S>> result) {
Copy link

Choose a reason for hiding this comment

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

Not sure about efficiency, but IMHO, this makes the contract of these methods worse. Previously these were pure functions without side effects, but now there are side effects introduced. I would be pretty careful here if any performance improvement warrants changing the contract of the methods like this.

Copy link
Author

Choose a reason for hiding this comment

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

Got it!

If such changes cause some concerns, I will undo these changes in the next commit.

Args.nullNotPermitted(axisIndex, "axisIndex");
List<XYDataset<S>> result = new ArrayList<>();
for (Entry<Integer, XYDataset<S>> entry : this.datasets.entrySet()) {
int index = entry.getKey();
List<Integer> mappedAxes = this.datasetToDomainAxesMap.get(index);
Expand All @@ -4013,9 +4012,8 @@ private List<XYDataset<S>> getDatasetsMappedToDomainAxis(Integer axisIndex) {
*
* @return A list of datasets.
*/
private List<XYDataset<S>> getDatasetsMappedToRangeAxis(Integer axisIndex) {
private List<XYDataset<S>> getDatasetsMappedToRangeAxis(Integer axisIndex, List<XYDataset<S>> result) {
Args.nullNotPermitted(axisIndex, "axisIndex");
List<XYDataset<S>> result = new ArrayList<>();
for (Entry<Integer, XYDataset<S>> entry : this.datasets.entrySet()) {
int index = entry.getKey();
List<Integer> mappedAxes = this.datasetToRangeAxesMap.get(index);
Expand Down Expand Up @@ -4115,7 +4113,7 @@ public Range getDataRange(ValueAxis axis) {
int domainIndex = getDomainAxisIndex(axis);
if (domainIndex >= 0) {
isDomainAxis = true;
mappedDatasets.addAll(getDatasetsMappedToDomainAxis(domainIndex));
getDatasetsMappedToDomainAxis(domainIndex, mappedDatasets);
if (domainIndex == 0) {
// grab the plot's annotations
for (XYAnnotation annotation : this.annotations) {
Expand All @@ -4130,7 +4128,7 @@ public Range getDataRange(ValueAxis axis) {
int rangeIndex = getRangeAxisIndex(axis);
if (rangeIndex >= 0) {
isDomainAxis = false;
mappedDatasets.addAll(getDatasetsMappedToRangeAxis(rangeIndex));
getDatasetsMappedToRangeAxis(rangeIndex, mappedDatasets);
if (rangeIndex == 0) {
for (XYAnnotation annotation : this.annotations) {
if (annotation instanceof XYAnnotationBoundsInfo) {
Expand Down