chart: barDir=bar по Word — подписи категорий слева, категория 0 внизу, заголовок резервирует все строки
PR checks / web (pull_request) Successful in 31s
PR checks / java (pull_request) Successful in 1m33s
Main: tests, deploy, autotests / web (push) Successful in 32s
Main: tests, deploy, autotests / images-web (push) Successful in 31s
Main: tests, deploy, autotests / java (push) Successful in 1m28s
Main: tests, deploy, autotests / images-app (push) Successful in 56s
Main: tests, deploy, autotests / deploy (push) Successful in 3m21s
Main: tests, deploy, autotests / autotests (push) Failing after 2m7s
Main: tests, deploy, autotests / rollback (push) Successful in 3m9s
PR checks / web (pull_request) Successful in 31s
PR checks / java (pull_request) Successful in 1m33s
Main: tests, deploy, autotests / web (push) Successful in 32s
Main: tests, deploy, autotests / images-web (push) Successful in 31s
Main: tests, deploy, autotests / java (push) Successful in 1m28s
Main: tests, deploy, autotests / images-app (push) Successful in 56s
Main: tests, deploy, autotests / deploy (push) Successful in 3m21s
Main: tests, deploy, autotests / autotests (push) Failing after 2m7s
Main: tests, deploy, autotests / rollback (push) Successful in 3m9s
- CartesianPainter: горизонтальный layout — резерв catLabelGutter слева под подписи категорий и topGutter сверху под подписи значений; подписи категорий вправо к оси (Paragraph align=null вместо «ctr», перекрывавшего defAlign); крайняя подпись значений клиппуется внутрь plot - catPos: minMax → категория 0 внизу, парсинг c:orientation=maxMin (§21.2.2.130, ST_Orientation §21.2.3.30, MS-OI29500 §2.1.1511) → AxisSpec.reversed - ChartRenderer.drawTitle: резерв = фактическое число строк жадного переноса (DrawMlText.lineCount), а не ровно 2 — заголовок 3+ строк больше не лезет на область построения - регрессии: horizontalBar_categoriesBottomUp, horizontalBar_reversedOrientation_categoriesTopDown, horizontalBar_categoryLabelsVisible, horizontalBar_lastValueLabelNotClipped, longTitle_reservesAllWrappedLines, lineCount_wraps, catAxOrientationMaxMin_reversedParsed
This commit was merged in pull request #48.
This commit is contained in:
+126
@@ -677,4 +677,130 @@ class CartesianPainterTest {
|
||||
}
|
||||
return new int[]{xs.get(0), xs.get(xs.size() / 2), xs.get(xs.size() - 1)};
|
||||
}
|
||||
|
||||
/**
|
||||
* barDir=bar: Word рисует категорию 0 внизу (ось категорий при дефолтном
|
||||
* c:orientation=minMax идёт снизу-вверх, ECMA-376 §21.2.2.130, MS-OI29500
|
||||
* §2.1.1511). Один ряд с per-point fill: RED — категория 0, BLUE — категория 1;
|
||||
* вся красная полоса ниже всей синей.
|
||||
* Регрессия — CartesianPainterTest#horizontalBar_categoriesBottomUp.
|
||||
*/
|
||||
@Test
|
||||
void horizontalBar_categoriesBottomUp() {
|
||||
BufferedImage img = ChartRenderer.render(horizontalCatSpec(), 219.23, 149.08,
|
||||
new DrawMlColor(null));
|
||||
int[] red = yStats(img, Color.RED);
|
||||
int[] blue = yStats(img, Color.BLUE);
|
||||
assertTrue(red[1] < NO_LINE, "красная полоса (категория 0) не найдена");
|
||||
assertTrue(blue[1] < NO_LINE, "синяя полоса (категория 1) не найдена");
|
||||
assertTrue(red[0] > blue[2],
|
||||
"minMax: категория 0 (RED) должна быть ниже категории 1 (BLUE): redMinY="
|
||||
+ red[0] + ", blueMaxY=" + blue[2]);
|
||||
}
|
||||
|
||||
/** c:orientation=maxMin (§21.2.2.130) переворачивает порядок: категория 0 сверху. */
|
||||
@Test
|
||||
void horizontalBar_reversedOrientation_categoriesTopDown() {
|
||||
ChartSpec spec = horizontalCatSpec();
|
||||
spec.catAxis.reversed = true;
|
||||
BufferedImage img = ChartRenderer.render(spec, 219.23, 149.08,
|
||||
new DrawMlColor(null));
|
||||
int[] red = yStats(img, Color.RED);
|
||||
int[] blue = yStats(img, Color.BLUE);
|
||||
assertTrue(red[1] < NO_LINE, "красная полоса не найдена");
|
||||
assertTrue(blue[1] < NO_LINE, "синяя полоса не найдена");
|
||||
assertTrue(blue[0] > red[2],
|
||||
"maxMin: категория 1 (BLUE) должна быть ниже категории 0 (RED): blueMinY="
|
||||
+ blue[0] + ", redMaxY=" + red[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* barDir=bar: подписи категорий (Q1/Q2/Q3) видны слева от оси. Раньше в
|
||||
* Paragraph был захардкожен align="ctr", перекрывающий defAlign="r": текст
|
||||
* центрировался в боксе левее области и уходил за левый край холста.
|
||||
* Считаем серый подписи (0x595959) в регионе слева от области построения.
|
||||
* Регрессия — CartesianPainterTest#horizontalBar_categoryLabelsVisible,
|
||||
* фикстура samples/chart-types.docx (chart12).
|
||||
*/
|
||||
@Test
|
||||
void horizontalBar_categoryLabelsVisible() {
|
||||
BufferedImage img = ChartRenderer.render(horizontalLabelSpec(), 219.23, 149.08,
|
||||
new DrawMlColor(null));
|
||||
Color label = new Color(0x59, 0x59, 0x59);
|
||||
int gray = 0;
|
||||
for (int y = img.getHeight() / 2; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth() / 4; x++) {
|
||||
if (closeTo(img.getRGB(x, y), label, 40)) {
|
||||
gray++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(gray >= 10, "подписей категорий слева от оси нет: " + gray + " px");
|
||||
}
|
||||
|
||||
/** Крайняя подпись оси значений («15») не обрезается правым краем холста. */
|
||||
@Test
|
||||
void horizontalBar_lastValueLabelNotClipped() {
|
||||
BufferedImage img = ChartRenderer.render(horizontalLabelSpec(), 219.23, 149.08,
|
||||
new DrawMlColor(null));
|
||||
Color label = new Color(0x59, 0x59, 0x59);
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = img.getWidth() - 2; x < img.getWidth(); x++) {
|
||||
assertFalse(closeTo(img.getRGB(x, y), label, 40),
|
||||
"подпись обрезана правым краем холста, пиксель (" + x + "," + y + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Горизонтальный ряд: RED=категория 0, BLUE=категория 1, категории A/B. */
|
||||
private static ChartSpec horizontalCatSpec() {
|
||||
ChartSpec spec = new ChartSpec();
|
||||
spec.type = ChartSpec.Type.BAR_HORIZONTAL;
|
||||
spec.legendPos = null;
|
||||
DrawMlText.Style style = new DrawMlText.Style(9, false, false,
|
||||
new Color(0x59, 0x59, 0x59), "carlito");
|
||||
spec.catAxis = new ChartSpec.AxisSpec();
|
||||
spec.catAxis.labelStyle = style;
|
||||
spec.valAxis = new ChartSpec.AxisSpec();
|
||||
spec.valAxis.labelStyle = style;
|
||||
spec.categories.add("A");
|
||||
spec.categories.add("B");
|
||||
ChartSpec.Series s = new ChartSpec.Series();
|
||||
s.values.add(5.0);
|
||||
s.values.add(5.0);
|
||||
s.pointFills.put(0, Color.RED);
|
||||
s.pointFills.put(1, Color.BLUE);
|
||||
spec.series.add(s);
|
||||
return spec;
|
||||
}
|
||||
|
||||
/** Горизонтальный ряд Q1..Q3 со значениями до 15 (как chart12). */
|
||||
private static ChartSpec horizontalLabelSpec() {
|
||||
ChartSpec spec = new ChartSpec();
|
||||
spec.type = ChartSpec.Type.BAR_HORIZONTAL;
|
||||
spec.legendPos = null;
|
||||
DrawMlText.Style style = new DrawMlText.Style(9, false, false,
|
||||
new Color(0x59, 0x59, 0x59), "carlito");
|
||||
spec.catAxis = new ChartSpec.AxisSpec();
|
||||
spec.catAxis.labelStyle = style;
|
||||
spec.valAxis = new ChartSpec.AxisSpec();
|
||||
spec.valAxis.labelStyle = style;
|
||||
spec.categories.add("Q1");
|
||||
spec.categories.add("Q2");
|
||||
spec.categories.add("Q3");
|
||||
ChartSpec.Series s = new ChartSpec.Series();
|
||||
s.values.add(5.0);
|
||||
s.values.add(8.0);
|
||||
s.values.add(15.0);
|
||||
spec.series.add(s);
|
||||
return spec;
|
||||
}
|
||||
|
||||
/** Пиксель близок к target (дельта каналов < maxDelta). */
|
||||
private static boolean closeTo(int rgb, Color target, int maxDelta) {
|
||||
int dr = Math.abs(((rgb >> 16) & 0xFF) - target.getRed());
|
||||
int dg = Math.abs(((rgb >> 8) & 0xFF) - target.getGreen());
|
||||
int db = Math.abs((rgb & 0xFF) - target.getBlue());
|
||||
return Math.max(Math.max(dr, dg), db) < maxDelta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,4 +478,59 @@ class ChartRendererTest {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Заголовок в 3 строки переноса резервирует фактическую высоту: бар
|
||||
* начинается ниже трёхстрочной полосы. Раньше резерв был ровно 2 строки,
|
||||
* и третья строка рисовалась поверх области построения.
|
||||
* Регрессия — ChartRendererTest#longTitle_reservesAllWrappedLines.
|
||||
*/
|
||||
@Test
|
||||
void longTitle_reservesAllWrappedLines() {
|
||||
ChartSpec spec = new ChartSpec();
|
||||
spec.type = ChartSpec.Type.BAR;
|
||||
spec.legendPos = null;
|
||||
DrawMlText.Style axisStyle = new DrawMlText.Style(9, false, false,
|
||||
new Color(0x59, 0x59, 0x59), "carlito");
|
||||
spec.catAxis = new ChartSpec.AxisSpec();
|
||||
spec.catAxis.labelStyle = axisStyle;
|
||||
spec.valAxis = new ChartSpec.AxisSpec();
|
||||
spec.valAxis.labelStyle = axisStyle;
|
||||
DrawMlText.Style style = new DrawMlText.Style(14, false, false,
|
||||
new Color(0x59, 0x59, 0x59), "carlito");
|
||||
spec.titleStyle = style;
|
||||
spec.title = "Очень длинное название диаграммы которое не должно помещаться "
|
||||
+ "в две строки и поэтому обязано занять три или четыре строки";
|
||||
assertEquals(3, DrawMlText.lineCount(spec.title, style, 360 - 2 * 4),
|
||||
"заголовок должен переноситься ровно в 3 строки при ширине бокса");
|
||||
ChartSpec.Series s = new ChartSpec.Series();
|
||||
s.fill = new Color(68, 114, 196);
|
||||
s.values.add(5.0);
|
||||
s.values.add(5.0);
|
||||
spec.series.add(s);
|
||||
BufferedImage img = ChartRenderer.render(spec, 360, 216, new DrawMlColor(null));
|
||||
int minY = -1;
|
||||
outer:
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
if (isBarFill(img.getRGB(x, y))) {
|
||||
minY = y;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(minY >= 0, "заливки бара не найдено");
|
||||
double threeLineBand = (4 + 3 * DrawMlText.textHeight(style))
|
||||
* ChartRenderer.DPI / 72.0 - 1;
|
||||
assertTrue(minY >= threeLineBand,
|
||||
"бар начинается в полосе заголовка: minY=" + minY
|
||||
+ ", нижний край трёхстрочной полосы=" + threeLineBand);
|
||||
}
|
||||
|
||||
/** Пиксель — заливка ряда (0x4472C4) с запасом на AA-края. */
|
||||
private static boolean isBarFill(int rgb) {
|
||||
return Math.abs(((rgb >> 16) & 0xFF) - 68) < 30
|
||||
&& Math.abs(((rgb >> 8) & 0xFF) - 114) < 30
|
||||
&& Math.abs((rgb & 0xFF) - 196) < 30;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ import org.docx4j.dml.chart.CTLine3DChart;
|
||||
import org.docx4j.dml.chart.CTPieChart;
|
||||
import org.docx4j.dml.chart.CTPlotArea;
|
||||
import org.docx4j.dml.chart.CTScaling;
|
||||
import org.docx4j.dml.chart.CTOrientation;
|
||||
import org.docx4j.dml.chart.STOrientation;
|
||||
import org.docx4j.dml.chart.CTOfPieChart;
|
||||
import org.docx4j.dml.chart.CTOfPieType;
|
||||
import org.docx4j.dml.chart.CTPerspective;
|
||||
@@ -1509,6 +1511,37 @@ class ChartSpecTest {
|
||||
() -> ChartSpec.parse(spaceWith(ct), new DrawMlColor(null)));
|
||||
}
|
||||
|
||||
/**
|
||||
* c:scaling/c:orientation (ECMA-376 §21.2.2.130, ST_Orientation §21.2.3.30):
|
||||
* maxMin → reversed; minMax и отсутствие элемента — прямое направление.
|
||||
* Регрессия — ChartSpecTest#catAxOrientationMaxMin_reversedParsed.
|
||||
*/
|
||||
@Test
|
||||
void catAxOrientationMaxMin_reversedParsed() {
|
||||
assertTrue(ChartSpec.parse(spaceWith(chartWithCatOrientation(STOrientation.MAX_MIN)),
|
||||
new DrawMlColor(null)).catAxis.reversed, "maxMin должен взводить reversed");
|
||||
assertFalse(ChartSpec.parse(spaceWith(chartWithCatOrientation(STOrientation.MIN_MAX)),
|
||||
new DrawMlColor(null)).catAxis.reversed, "minMax — дефолтное направление");
|
||||
assertFalse(ChartSpec.parse(spaceWith(chartWithCatOrientation(null)),
|
||||
new DrawMlColor(null)).catAxis.reversed, "нет c:orientation — дефолтное направление");
|
||||
}
|
||||
|
||||
private static CTChart chartWithCatOrientation(STOrientation orientation) {
|
||||
CTChart chart = new CTChart();
|
||||
CTPlotArea pa = new CTPlotArea();
|
||||
CTCatAx cat = new CTCatAx();
|
||||
CTScaling scaling = new CTScaling();
|
||||
if (orientation != null) {
|
||||
CTOrientation o = new CTOrientation();
|
||||
o.setVal(orientation);
|
||||
scaling.setOrientation(o);
|
||||
}
|
||||
cat.setScaling(scaling);
|
||||
pa.getValAxOrCatAxOrDateAx().add(cat);
|
||||
chart.setPlotArea(pa);
|
||||
return chart;
|
||||
}
|
||||
|
||||
private static CTNumData numCache(double... vals) {
|
||||
CTNumData cache = new CTNumData();
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
|
||||
@@ -276,4 +276,14 @@ class DrawMlTextTest {
|
||||
new Rectangle2D.Double(0, 0, 50, 40), null, "t");
|
||||
assertEquals(0, inkBands(blank), "пробельный абзац — чернил нет");
|
||||
}
|
||||
|
||||
/** lineCount — та же жадная разбивка, что в paint: 1/2/3 строки при 100 pt. */
|
||||
@Test
|
||||
void lineCount_wraps() {
|
||||
DrawMlText.Style s = new DrawMlText.Style(9, false, false, Color.BLACK, "carlito");
|
||||
assertEquals(1, DrawMlText.lineCount("short", s, 100));
|
||||
assertEquals(2, DrawMlText.lineCount("альфа бета гамма дельта эпсилон", s, 100));
|
||||
assertEquals(3, DrawMlText.lineCount(
|
||||
"альфа бета гамма дельта эпсилон зета эта йота капа лямбда", s, 100));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user