[jOOQ/jOOQ#12332] Result.formatChart() produces bad default formatting for Display.HUNDRED_PERCENT_STACKED

This commit is contained in:
Lukas Eder 2021-08-19 12:18:13 +02:00
parent 3a73dfe389
commit 7154cc51de
2 changed files with 66 additions and 18 deletions

View File

@ -66,6 +66,7 @@ public final class ChartFormat {
final boolean showVerticalLegend;
final String newline;
final DecimalFormat numericFormat;
final DecimalFormat percentFormat;
public ChartFormat() {
this(
@ -81,7 +82,8 @@ public final class ChartFormat {
true,
true,
"\n",
new DecimalFormat("###,###.00")
new DecimalFormat("###,###.00"),
new DecimalFormat("##0.00'%'")
);
}
@ -98,7 +100,8 @@ public final class ChartFormat {
boolean showHorizontalLegend,
boolean showVerticalLegend,
String newline,
DecimalFormat numericFormat
DecimalFormat numericFormat,
DecimalFormat percentFormat
) {
this.output = output;
this.type = type;
@ -113,6 +116,7 @@ public final class ChartFormat {
this.showVerticalLegend = showVerticalLegend;
this.newline = newline;
this.numericFormat = numericFormat;
this.percentFormat = percentFormat;
}
/**
@ -133,7 +137,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -163,7 +168,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -190,7 +196,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -220,7 +227,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -272,7 +280,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -301,7 +310,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -330,7 +340,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -360,7 +371,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -390,7 +402,8 @@ public final class ChartFormat {
newShowHorizontalLegend,
newShowVerticalLegend,
newline,
numericFormat
numericFormat,
percentFormat
);
}
@ -442,7 +455,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newNewline,
numericFormat
numericFormat,
percentFormat
);
}
@ -472,7 +486,8 @@ public final class ChartFormat {
showHorizontalLegend,
showVerticalLegend,
newline,
newNumericFormat
newNumericFormat,
percentFormat
);
}
@ -484,6 +499,37 @@ public final class ChartFormat {
return numericFormat;
}
/**
* The new numeric format for percentages, defaulting to <code>###.00'%'</code>.
*/
@NotNull
public ChartFormat percentFormat(DecimalFormat newPercentFormat) {
return new ChartFormat(
output,
type,
display,
width,
height,
category,
categoryAsText,
values,
shades,
showHorizontalLegend,
showVerticalLegend,
newline,
numericFormat,
newPercentFormat
);
}
/**
* The numeric format for percentages.
*/
@NotNull
public DecimalFormat percentFormat() {
return percentFormat;
}
/**
* The chart output format.
*/

View File

@ -917,10 +917,12 @@ abstract class AbstractResult<R extends Record> extends AbstractFormattable impl
}
int verticalLegendWidth = format.showVerticalLegend()
? Math.max(
format.numericFormat().format(axisMin).length(),
format.numericFormat().format(axisMax).length()
)
? (format.display() == Display.HUNDRED_PERCENT_STACKED)
? fp.width(format.percentFormat().format(100.0))
: Math.max(
format.numericFormat().format(axisMin).length(),
format.numericFormat().format(axisMax).length()
)
: 0;
int horizontalLegendHeight = format.showHorizontalLegend() ? 1 : 0;
@ -940,7 +942,7 @@ abstract class AbstractResult<R extends Record> extends AbstractFormattable impl
if (format.showVerticalLegend()) {
String axisLegendString = (format.display() == Display.HUNDRED_PERCENT_STACKED)
? format.numericFormat().format(axisLegendPercent * 100.0) + "%"
? format.percentFormat().format(axisLegendPercent * 100.0)
: format.numericFormat().format(axisLegend);
for (int x = fp.width(axisLegendString); x < verticalLegendWidth; x++)