chart: контурная диаграмма — оба режима вид сверху, полые маркеры легенды wireframe
PR checks / web (pull_request) Successful in 42s
PR checks / java (pull_request) Successful in 1m6s
Main: tests, deploy, autotests / web (push) Successful in 32s
Main: tests, deploy, autotests / java (push) Successful in 1m29s
Main: tests, deploy, autotests / images-web (push) Successful in 30s
Main: tests, deploy, autotests / images-app (push) Successful in 41s
Main: tests, deploy, autotests / deploy (push) Successful in 1m32s
Main: tests, deploy, autotests / autotests (push) Successful in 46s
Main: tests, deploy, autotests / rollback (push) Has been skipped

surfaceChart (ECMA-376 §21.2.2.204) — «viewed from above, similar to 2-D
topographic maps»: заливочный режим вместо «торца» рисует топографическую
карту с залитыми полосами высот (fillBands — marching squares по ячейкам,
по одному пути на полосу — нет AA-шва на общих рёбрах), без изолиний и оси
значений; wireframe (§21.2.2.230) — без изменений геометрии. Маркеры
легенды полос следуют заливке: залитые при wireframe=false, полые при
wireframe=true (полосы не залиты нигде). Удалены drawContour/interp/yOf/
drawValueLabels/drawCategoryLabels и тест снятого вида торцом.

Регрессии — Surface2dPainterTest#filledContour_*,
ChartRendererTest#wireframeSurfaceLegend_hollowMarkers, фикстура
samples/chart-types.docx.
This commit was merged in pull request #61.
This commit is contained in:
Pjandro
2026-10-26 20:47:31 +00:00
parent b708772227
commit 7ffafefd27
5 changed files with 440 additions and 249 deletions
@@ -15,6 +15,15 @@ import static org.junit.jupiter.api.Assertions.*;
*/
class ChartRendererTest {
/**
* Полый маркер: в средней колонке — верхняя и нижняя рамки контура
* 1pt ≈ 4px @300dpi + AA-ряды (замер ~5), прогон не больше порога.
*/
private static final int HOLLOW_MAX_RUN = 8;
/** Залитый маркер: квадрат 0,55·9pt ≈ 21px @300dpi, прогон не меньше. */
private static final int FILLED_MIN_RUN = 15;
/**
* Одна и та же LINE-спека с legendOverlay=false/true: легенда видима
* в обеих (нижняя полоса), но у overlay кривая опускается ниже —
@@ -361,6 +370,37 @@ class ChartRendererTest {
"surface с данными и полосами должен рисоваться");
}
/**
* c:wireframe (§21.2.2.230) — «no color on the surface» распространяется
* и на легенду: маркеры полос полые (цветной контур, белый интерьер) —
* в средней колонке маркера только верхняя и нижняя рамки. Контраст —
* та же спека с wireframe=false: маркер залит на всю высоту квадратика.
* Регрессия — ChartRendererTest#wireframeSurfaceLegend_hollowMarkers.
*/
@Test
void wireframeSurfaceLegend_hollowMarkers() {
ChartSpec spec = surfaceLegendSpec(true);
BufferedImage hollow = ChartRenderer.render(spec, 219.23, 149.08,
new DrawMlColor(null));
int[] box = firstAccent1Box(hollow);
int cx = (box[0] + box[2]) / 2;
int cy = (box[1] + box[3]) / 2;
assertTrue(isWhite(hollow.getRGB(cx, cy)),
"интерьер wireframe-маркера не белый: " + Integer.toHexString(hollow.getRGB(cx, cy)));
int run = maxVerticalAccent1Run(hollow, cx);
assertTrue(run <= HOLLOW_MAX_RUN,
"wireframe-маркер легенды залит: вертикальный прогон=" + run);
spec.wireframe = false;
BufferedImage filled = ChartRenderer.render(spec, 219.23, 149.08,
new DrawMlColor(null));
int[] fbox = firstAccent1Box(filled);
int fcx = (fbox[0] + fbox[2]) / 2;
int filledRun = maxVerticalAccent1Run(filled, fcx);
assertTrue(filledRun >= FILLED_MIN_RUN,
"заливочный маркер легенды не залит: вертикальный прогон=" + filledRun);
}
/** BAR: легенда без имени ряда — квадратик; без рядов — легенды нет. */
@Test
void barLegendDefaultSquareAndNameless() {
@@ -563,4 +603,75 @@ class ChartRendererTest {
&& Math.abs(((rgb >> 8) & 0xFF) - 114) < 30
&& Math.abs((rgb & 0xFF) - 196) < 30;
}
/**
* SURFACE 2 ряда × 2 категории, c:majorUnit=1 → полосы 0-1/1-2, легенда
* «0-1» (accent1) «1-2» (accent2); данные 1.2/1.8 — выше первой границы
* полос, поэтому область построения не рисует ни изолиний, ни accent1.
*/
private static ChartSpec surfaceLegendSpec(boolean wireframe) {
ChartSpec spec = new ChartSpec();
spec.type = ChartSpec.Type.SURFACE;
spec.wireframe = wireframe;
spec.legendPos = "b";
spec.valAxis = new ChartSpec.AxisSpec();
spec.valAxis.majorUnit = 1.0;
ChartSpec.Series bottom = new ChartSpec.Series();
bottom.values.add(1.2);
bottom.values.add(1.2);
ChartSpec.Series top = new ChartSpec.Series();
top.values.add(1.8);
top.values.add(1.8);
spec.series.add(bottom);
spec.series.add(top);
return spec;
}
/** Bounding box пикселей accent1 (первый маркер легенды): {minX, minY, maxX, maxY}. */
private static int[] firstAccent1Box(BufferedImage img) {
int minX = Integer.MAX_VALUE;
int minY = Integer.MAX_VALUE;
int maxX = -1;
int maxY = -1;
for (int y = 0; y < img.getHeight(); y++) {
for (int x = 0; x < img.getWidth(); x++) {
if (isAccent1(img.getRGB(x, y))) {
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
maxY = Math.max(maxY, y);
}
}
}
assertTrue(maxX >= 0, "маркер легенды accent1 не найден");
return new int[] {minX, minY, maxX, maxY};
}
/** Максимальный вертикальный прогон accent1 в колонке x. */
private static int maxVerticalAccent1Run(BufferedImage img, int x) {
int best = 0;
int run = 0;
for (int y = 0; y < img.getHeight(); y++) {
if (isAccent1(img.getRGB(x, y))) {
run++;
best = Math.max(best, run);
} else {
run = 0;
}
}
return best;
}
/** Пиксель — цвет accent1 (0x4472C4) с запасом на AA-края. */
private static boolean isAccent1(int rgb) {
return Math.abs(((rgb >> 16) & 0xFF) - 0x44) <= 24
&& Math.abs(((rgb >> 8) & 0xFF) - 0x72) <= 24
&& Math.abs((rgb & 0xFF) - 0xC4) <= 24;
}
/** Пиксель — белый фон. */
private static boolean isWhite(int rgb) {
return ((rgb >> 16) & 0xFF) >= 0xF0 && ((rgb >> 8) & 0xFF) >= 0xF0
&& (rgb & 0xFF) >= 0xF0;
}
}
@@ -10,14 +10,14 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* Контурная диаграмма (ECMA-376 §21.2.2.204). Заливочный режим: лист между
* ломаными соседних рядов режется контурными полосами высот (c:bandFmts,
* §21.2.2.13 — от низкого к высокого; без них — палитра). c:wireframe
* (§21.2.2.230) — вид сверху, как Word: X — категории, Y — ряды (серия 0
* внизу), без заливок и оси значений; рисуются изолинии на внутренних
* границах полос высот lo + k·unit цветом полосы НИЖЕ уровня (marching
* squares, седло — по среднему ячейки), сетка узлов catAx/serAx и рамка
* области построения. Регрессия — Surface2dPainterTest, фикстура
* Контурная диаграмма (ECMA-376 §21.2.2.204) — оба режима вид сверху
* («viewed from above», Microsoft Support): X — категории по узлам сетки,
* Y — ряды (серия 0 внизу), оси значений нет. Заливочный
* (c:wireframe val="0") — области полос высот lo + k·unit залиты их
* цветами (c:bandFmts §21.2.2.13/.14, без них — палитра), без изолиний.
* c:wireframe (§21.2.2.230) — изолинии на внутренних границах полос
* цветом полосы НИЖЕ уровня (marching squares, седло — по среднему
* ячейки), без заливок. Регрессия — Surface2dPainterTest, фикстура
* samples/chart-types.docx (WordPdfConverterTest#chartTypes_allTypesRenderAsImages).
*/
class Surface2dPainterTest {
@@ -27,36 +27,22 @@ class Surface2dPainterTest {
private static final Color ACCENT3 = new Color(0xA5A5A5);
private static final Color ACCENT4 = new Color(0xFFC000);
/** Порог «тёмный» пикселя по каждому каналу (текст подписей 0x595959). */
private static final int DARK_MAX = 0x80;
/** Масштаб растра: 300 dpi → pt·25/6 px. */
private static final double PX = 300.0 / 72.0;
/**
* Геометрия render(): box = (4, 4, 211.23, 141.08) pt; в wireframe без
* подписей осей plot = (12, 4, 203.23, 135.08) pt (serGutter 8, catGutter 6).
* Геометрия render(): box = (4, 4, 211.23, 141.08) pt; без подписей
* осей plot = (12, 4, 203.23, 135.08) pt (serGutter 8, catGutter 6) —
* одинаково в обоих режимах вида сверху.
*/
private static final double PLOT_X = 12;
private static final double PLOT_W = 203.23;
private static final double PLOT_Y = 4;
private static final double PLOT_H = 135.08;
/**
* Плоские ряды 0/2/4: lo=0, hi=4, unit=1 → лист от 0 до 4 делится на
* четыре горизонтальные полосы высот: снизу вверх accent1 (0-1),
* accent2 (1-2), accent3 (2-3), accent4 (3-4).
*/
@Test
void contourStripes_areValueBandsBottomUp() {
BufferedImage img = render(surfaceSpec(false));
assertTrue(matches(px(img, 400, 507), ACCENT1),
"полоса 0-1 не accent1: " + hex(px(img, 400, 507)));
assertTrue(matches(px(img, 400, 368), ACCENT2),
"полоса 1-2 не accent2: " + hex(px(img, 400, 368)));
assertTrue(matches(px(img, 400, 227), ACCENT3),
"полоса 2-3 не accent3: " + hex(px(img, 400, 227)));
assertTrue(matches(px(img, 400, 87), ACCENT4),
"полоса 3-4 не accent4: " + hex(px(img, 400, 87)));
}
/**
* Вид сверху, z[r][c] = c: lo=0, hi=4, unit=1 → изолинии уровней 1, 2, 3 —
* вертикали точно в узлах xOf(1..3) цветами полос НИЖЕ уровня
@@ -221,11 +207,94 @@ class Surface2dPainterTest {
"ниже уровня изолинии быть не должно");
}
/**
* Заливка, вид сверху: z[r][c] = r, 4 ряда × 3 категории — lo=0, hi=3,
* unit=1 → полосы 0-1/1-2/2-3 заливают межрядные ячейки
* (accent1/2/3); серия 0 внизу (центр ячейки ряда 0 ниже центра
* ячейки ряда 2 на экране).
*/
@Test
void filledContour_flatRows_bandsFillRowsTopView() {
double[][] z = {
{0, 0, 0},
{1, 1, 1},
{2, 2, 2},
{3, 3, 3},
};
BufferedImage img = render(surfaceSpec(z, false));
int x = (int) Math.round((xPt(0, 3) + xPt(1, 3)) / 2 * PX);
int yCell0 = (yPx(0, 4) + yPx(1, 4)) / 2;
int yCell1 = (yPx(1, 4) + yPx(2, 4)) / 2;
int yCell2 = (yPx(2, 4) + yPx(3, 4)) / 2;
assertTrue(yCell0 > yCell2,
"серия 0 должна быть внизу: yCell0=" + yCell0 + ", yCell2=" + yCell2);
assertTrue(matches(px(img, x, yCell0), ACCENT1),
"полоса 0-1 не accent1: " + hex(px(img, x, yCell0)));
assertTrue(matches(px(img, x, yCell1), ACCENT2),
"полоса 1-2 не accent2: " + hex(px(img, x, yCell1)));
assertTrue(matches(px(img, x, yCell2), ACCENT3),
"полоса 2-3 не accent3: " + hex(px(img, x, yCell2)));
}
/**
* «Холм» 3×3 (углы z=0, середины рёбер z=2, центр z=4): lo=0, hi=4,
* unit=1 → в ячейке (0..1, 0..1) биллинейно z = 2x̂+2ŷ, точки диагонали
* от угла (0,0) к центру при t=0.15/0.35/0.65/0.85 (z=0.6/1.4/2.6/3.4)
* залиты цветами полос 0-1…3-4.
*/
@Test
void filledContour_hillCell_bandsNestedDiagonal() {
double[][] z = {
{0, 2, 0},
{2, 4, 2},
{0, 2, 0},
};
BufferedImage img = render(surfaceSpec(z, false));
double[] ts = {0.15, 0.35, 0.65, 0.85};
Color[] want = {ACCENT1, ACCENT2, ACCENT3, ACCENT4};
for (int i = 0; i < ts.length; i++) {
double t = ts[i];
double x = xPt(0, 3) + (xPt(1, 3) - xPt(0, 3)) * t;
double y = yPt(0, 3) + (yPt(1, 3) - yPt(0, 3)) * t;
int xp = (int) Math.round(x * PX);
int yp = (int) Math.round(y * PX);
assertTrue(matches(px(img, xp, yp), want[i]),
"точка диагонали t=" + t + " не " + want[i] + ": " + hex(px(img, xp, yp)));
}
}
/**
* Оси значений в виде сверху нет: слева от plot (x < plotX−1) в
* вертикальной полосе области построения нет тёмных пикселей — ни в
* заливочном, ни в wireframe-режиме.
*/
@Test
void filledContour_noValueAxisLabels() {
double[][] z = {
{0, 0, 0},
{1, 1, 1},
{2, 2, 2},
{3, 3, 3},
};
int xLimit = (int) Math.round((PLOT_X - 1) * PX);
int yTop = (int) Math.round(PLOT_Y * PX);
int yBottom = (int) Math.round((PLOT_Y + PLOT_H) * PX);
assertFalse(hasDarkLeftOf(render(surfaceSpec(z, false)), xLimit, yTop, yBottom),
"слева от plot подписи оси значений (заливка)");
assertFalse(hasDarkLeftOf(render(surfaceSpec(z, true)), xLimit, yTop, yBottom),
"слева от plot подписи оси значений (wireframe)");
}
/** Спека wireframe-поверхности без подписей осей (серии из z, категории пустые). */
private static ChartSpec wireframeSpec(double[][] z) {
return surfaceSpec(z, true);
}
/** Спека поверхности без подписей осей (серии из z, категории пустые), режим по флагу. */
private static ChartSpec surfaceSpec(double[][] z, boolean wireframe) {
ChartSpec spec = new ChartSpec();
spec.type = ChartSpec.Type.SURFACE;
spec.wireframe = true;
spec.wireframe = wireframe;
spec.legendPos = null;
spec.valAxis = new ChartSpec.AxisSpec();
for (double[] row : z) {
@@ -248,8 +317,12 @@ class Surface2dPainterTest {
}
/** Пиксельная координата узла ряда: serY(r) = 4 + 135.08·(1 − r/(nSer−1)), серия 0 внизу. */
private static double yPt(double r, int nSer) {
return PLOT_Y + PLOT_H * (1 - r / (nSer - 1.0));
}
private static int yPx(double r, int nSer) {
return (int) Math.round((PLOT_Y + PLOT_H * (1 - r / (nSer - 1))) * PX);
return (int) Math.round(yPt(r, nSer) * PX);
}
private static boolean hasSegment(List<Line2D.Double> segs,
@@ -270,23 +343,6 @@ class Surface2dPainterTest {
return Math.abs(a - b) < 1e-9;
}
private static ChartSpec surfaceSpec(boolean wireframe) {
ChartSpec spec = new ChartSpec();
spec.type = ChartSpec.Type.SURFACE;
spec.wireframe = wireframe;
spec.legendPos = null;
spec.valAxis = new ChartSpec.AxisSpec();
double[] rows = {0, 2, 4};
for (double row : rows) {
ChartSpec.Series s = new ChartSpec.Series();
for (int c = 0; c < 3; c++) {
s.values.add(row);
}
spec.series.add(s);
}
return spec;
}
private static BufferedImage render(ChartSpec spec) {
return ChartRenderer.render(spec, 219.23, 149.08, new DrawMlColor(null));
}
@@ -306,6 +362,21 @@ class Surface2dPainterTest {
|| matches(rgb, ACCENT3) || matches(rgb, ACCENT4);
}
/** Есть ли тёмный пиксель в полосе x < xLimit, yTop..yBottom. */
private static boolean hasDarkLeftOf(BufferedImage img, int xLimit,
int yTop, int yBottom) {
for (int y = yTop; y <= yBottom && y < img.getHeight(); y++) {
for (int x = 0; x < xLimit; x++) {
int rgb = img.getRGB(x, y);
if (((rgb >> 16) & 0xFF) < DARK_MAX && ((rgb >> 8) & 0xFF) < DARK_MAX
&& (rgb & 0xFF) < DARK_MAX) {
return true;
}
}
}
return false;
}
private static String hex(int rgb) {
return String.format("#%06X", rgb & 0xFFFFFF);
}