chart: ofPie по Word — «Other»-сектор, две связи c:serLines, центрирование пары (MS-OI29500 §2.1.1507(a)/§2.1.1545(a))
PR checks / web (pull_request) Successful in 32s
PR checks / java (pull_request) Successful in 1m27s
Main: tests, deploy, autotests / web (push) Successful in 31s
Main: tests, deploy, autotests / images-web (push) Successful in 30s
Main: tests, deploy, autotests / java (push) Successful in 1m40s
Main: tests, deploy, autotests / images-app (push) Successful in 43s
Main: tests, deploy, autotests / deploy (push) Successful in 1m32s
Main: tests, deploy, autotests / autotests (push) Successful in 57s
Main: tests, deploy, autotests / rollback (push) Has been skipped
PR checks / web (pull_request) Successful in 32s
PR checks / java (pull_request) Successful in 1m27s
Main: tests, deploy, autotests / web (push) Successful in 31s
Main: tests, deploy, autotests / images-web (push) Successful in 30s
Main: tests, deploy, autotests / java (push) Successful in 1m40s
Main: tests, deploy, autotests / images-app (push) Successful in 43s
Main: tests, deploy, autotests / deploy (push) Successful in 1m32s
Main: tests, deploy, autotests / autotests (push) Successful in 57s
Main: tests, deploy, autotests / rollback (push) Has been skipped
This commit was merged in pull request #46.
This commit is contained in:
@@ -18,8 +18,9 @@ import java.util.Set;
|
||||
* MS-OI29500 §2.1.1554a/b): auto/pos — последние ceil(n/3) (или splitPos)
|
||||
* точек, val/percent — точки ниже splitPos, cust — c:secondPiePt.
|
||||
* Вторичных точек нет → обычная круговая через {@link PiePainter}.
|
||||
* c:serLines — связи от обода главного пирога (эффективный угол точки в
|
||||
* «хвостовом» секторе) до середины вторичного сектора/сегмента.
|
||||
* «Other»-сектор (MS-OI29500 §2.1.1507(a)) замыкает главный пирог и обращён к
|
||||
* вторичной диаграмме; c:serLines — ровно две связи от границ «Other»-сектора
|
||||
* к вторичному пирогу/столбцу (MS-OI29500 §2.1.1545(a)).
|
||||
*
|
||||
* Регрессия — OfPiePainterTest, фикстура samples/chart-types.docx
|
||||
* (WordPdfConverterTest#chartTypes_allTypesRenderAsImages).
|
||||
@@ -32,6 +33,10 @@ final class OfPiePainter {
|
||||
/** Доля области построения под диаметр главного пирога (Word-эмпирика). */
|
||||
private static final double MAIN_FIT = 0.72;
|
||||
|
||||
/** Зазор между пирогами как доля диаметра главного (Word-эмпирика,
|
||||
* калибровка — OfPiePainterTest). */
|
||||
private static final double GAP_FIT = 0.25;
|
||||
|
||||
/** c:ofPieType="bar" — вторичная часть столбчатая (§21.2.2.134). */
|
||||
private static final String SECONDARY_BAR = "bar";
|
||||
|
||||
@@ -58,50 +63,64 @@ final class OfPiePainter {
|
||||
return;
|
||||
}
|
||||
|
||||
double totalSecondary = 0;
|
||||
for (int i : secondary) {
|
||||
totalSecondary += s.values.get(i);
|
||||
}
|
||||
double wedgeSweep = 360.0 * totalSecondary / total;
|
||||
double primarySweep = 360.0 - wedgeSweep;
|
||||
// «Other»-сектор обращён к вторичной диаграмме (центр — 3 часа);
|
||||
// MS-OI29500 §2.1.1507(a). Для OF_PIE firstSliceAng всегда 0 —
|
||||
// CT_OfPieChart (§A.5.1) не содержит c:firstSliceAng; слагаемое
|
||||
// оставлено для аддитивной семантики.
|
||||
double mainStart = spec.firstSliceAng + 90.0 - primarySweep - wedgeSweep / 2.0;
|
||||
|
||||
double d1 = MAIN_FIT * Math.min(box.getWidth(), box.getHeight());
|
||||
double d2 = d1 * spec.secondPieSize / 100.0;
|
||||
double gap = 0.10 * d1;
|
||||
double gap = GAP_FIT * d1;
|
||||
if (d1 + gap + d2 > box.getWidth()) {
|
||||
double k = box.getWidth() / (d1 + gap + d2);
|
||||
d1 *= k;
|
||||
d2 *= k;
|
||||
gap *= k;
|
||||
}
|
||||
// Пара пирогов центрирована горизонтально (как в Word).
|
||||
double cy = box.getY() + box.getHeight() / 2.0;
|
||||
double cx1 = box.getX() + d1 / 2.0;
|
||||
double cx2 = box.getX() + d1 + gap + d2 / 2.0;
|
||||
double startX = box.getX() + (box.getWidth() - (d1 + gap + d2)) / 2.0;
|
||||
double cx1 = startX + d1 / 2.0;
|
||||
double cx2 = startX + d1 + gap + d2 / 2.0;
|
||||
double secondaryLeft = startX + d1 + gap;
|
||||
|
||||
double totalSecondary = 0;
|
||||
for (int i : secondary) {
|
||||
totalSecondary += s.values.get(i);
|
||||
}
|
||||
|
||||
// Главный пирог: только первичные точки, углы от c:firstSliceAng.
|
||||
double angle = spec.firstSliceAng;
|
||||
double primarySweep = 0;
|
||||
// Главный пирог: первичные точки от mainStart, затем «Other»-сектор
|
||||
// (MS-OI29500 §2.1.1507(a)); цвет — следующий в ротации палитры за
|
||||
// последней точкой (Word — tint-последовательность поверх accent1..6,
|
||||
// палитра конвертера плоская — ближайшее приближение).
|
||||
// Регрессия — OfPiePainterTest#otherSlice_mainPieClosed.
|
||||
double angle = mainStart;
|
||||
for (int i = 0; i < s.values.size(); i++) {
|
||||
Double v = s.values.get(i);
|
||||
if (v == null || v <= 0 || secondary.contains(i)) {
|
||||
continue;
|
||||
}
|
||||
double sweep = 360.0 * v / total;
|
||||
drawSector(g, s, i, palette, cx1, cy, d1 / 2.0, angle, sweep);
|
||||
drawSector(g, s.fillAt(i, palette), s, cx1, cy, d1 / 2.0, angle, sweep);
|
||||
angle += sweep;
|
||||
primarySweep += sweep;
|
||||
}
|
||||
Color otherFill = s.fill != null ? s.fill
|
||||
: palette.get(s.values.size() % palette.size());
|
||||
drawSector(g, otherFill, s, cx1, cy, d1 / 2.0, angle, wedgeSweep);
|
||||
|
||||
double secondaryLeft = box.getX() + d1 + gap;
|
||||
if (SECONDARY_BAR.equalsIgnoreCase(spec.ofPieType)) {
|
||||
drawSecondaryBar(g, s, palette, secondary, totalSecondary,
|
||||
secondaryLeft, cy, d1, d2);
|
||||
} else {
|
||||
drawSecondaryPie(g, spec, s, palette, secondary, totalSecondary,
|
||||
cx2, cy, d2);
|
||||
drawSecondaryPie(g, s, palette, secondary, totalSecondary,
|
||||
cx2, cy, d2, mainStart);
|
||||
}
|
||||
|
||||
if (spec.serLines) {
|
||||
drawSerLines(g, spec, s, secondary, total, totalSecondary,
|
||||
primarySweep, cx1, cy, d1, cx2, cy, d2, secondaryLeft);
|
||||
drawSerLines(g, spec, cx1, cy, d1, cx2, d2, secondaryLeft,
|
||||
mainStart, primarySweep, wedgeSweep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,14 +172,20 @@ final class OfPiePainter {
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void drawSecondaryPie(Graphics2D g, ChartSpec spec, ChartSpec.Series s,
|
||||
/**
|
||||
* Вторичный пирог: сектора в порядке индексов от эффективного угла
|
||||
* главного пирога (= конец «Other»-сектора, 90° + wedgeSweep/2) — замер
|
||||
* по эталону Excel. Регрессия —
|
||||
* OfPiePainterTest#secondaryPie_slicesInDataOrderFromWedgeEnd.
|
||||
*/
|
||||
private static void drawSecondaryPie(Graphics2D g, ChartSpec.Series s,
|
||||
List<Color> palette, Set<Integer> secondary,
|
||||
double totalSecondary, double cx, double cy,
|
||||
double d2) {
|
||||
double angle = spec.firstSliceAng;
|
||||
double d2, double startDeg) {
|
||||
double angle = startDeg;
|
||||
for (int i : orderedIndices(secondary)) {
|
||||
double sweep = 360.0 * s.values.get(i) / totalSecondary;
|
||||
drawSector(g, s, i, palette, cx, cy, d2 / 2.0, angle, sweep);
|
||||
drawSector(g, s.fillAt(i, palette), s, cx, cy, d2 / 2.0, angle, sweep);
|
||||
angle += sweep;
|
||||
}
|
||||
}
|
||||
@@ -181,56 +206,46 @@ final class OfPiePainter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Связи c:serLines: от обода главного пирога на эффективном угле точки
|
||||
* (первичные сектора + накопленная доля вторичных в «хвостовом» секторе)
|
||||
* до внешней середины её вторичного сектора/сегмента.
|
||||
* Связи c:serLines: ровно две линии от границ «Other»-сектора главного
|
||||
* пирога к вторичной диаграмме (MS-OI29500 §2.1.1545(a) — «the series
|
||||
* lines connect the secondary pie or column to the other slice»). Для
|
||||
* pie — к ободу вторичного на 270°±wedgeSweep (полуразнос относительно
|
||||
* 9 часов — Word-эмпирика); для bar — к левым верхнему/нижнему углам
|
||||
* столбца. Регрессия — OfPiePainterTest#serLines_twoConnectors.
|
||||
*/
|
||||
private static void drawSerLines(Graphics2D g, ChartSpec spec, ChartSpec.Series s,
|
||||
Set<Integer> secondary, double total,
|
||||
double totalSecondary, double primarySweep,
|
||||
double cx1, double cy1, double d1,
|
||||
double cx2, double cy2, double d2,
|
||||
double secondaryLeft) {
|
||||
private static void drawSerLines(Graphics2D g, ChartSpec spec,
|
||||
double cx1, double cy, double d1,
|
||||
double cx2, double d2, double secondaryLeft,
|
||||
double mainStart, double primarySweep,
|
||||
double wedgeSweep) {
|
||||
g.setColor(SER_LINE_COLOR);
|
||||
g.setStroke(new BasicStroke(0.75f));
|
||||
boolean bar = "bar".equalsIgnoreCase(spec.ofPieType);
|
||||
double wedgeWidth = 360.0 * totalSecondary / total;
|
||||
double acc = 0;
|
||||
double secAngle = spec.firstSliceAng;
|
||||
double stackTop = cy2 - d1 / 2.0;
|
||||
double w = d2 / 2.0;
|
||||
for (int i : orderedIndices(secondary)) {
|
||||
double share = s.values.get(i) / totalSecondary;
|
||||
double mainAngle = spec.firstSliceAng + primarySweep
|
||||
+ (acc + share / 2.0) * wedgeWidth;
|
||||
double mrad = Math.toRadians(mainAngle);
|
||||
double mx = cx1 + d1 / 2.0 * Math.sin(mrad);
|
||||
double my = cy1 - d1 / 2.0 * Math.cos(mrad);
|
||||
double tx;
|
||||
double ty;
|
||||
if (bar) {
|
||||
double h = d1 * share;
|
||||
tx = secondaryLeft + w;
|
||||
ty = stackTop + h / 2.0;
|
||||
stackTop += h;
|
||||
} else {
|
||||
double mid = Math.toRadians(secAngle + 360.0 * share / 2.0);
|
||||
tx = cx2 + d2 / 2.0 * Math.sin(mid);
|
||||
ty = cy2 - d2 / 2.0 * Math.cos(mid);
|
||||
}
|
||||
secAngle += 360.0 * share;
|
||||
acc += share;
|
||||
g.draw(new Line2D.Double(mx, my, tx, ty));
|
||||
double r1 = Math.toRadians(mainStart + primarySweep);
|
||||
double r2 = Math.toRadians(mainStart + primarySweep + wedgeSweep);
|
||||
double x1 = cx1 + d1 / 2.0 * Math.sin(r1);
|
||||
double y1 = cy - d1 / 2.0 * Math.cos(r1);
|
||||
double x2 = cx1 + d1 / 2.0 * Math.sin(r2);
|
||||
double y2 = cy - d1 / 2.0 * Math.cos(r2);
|
||||
if (SECONDARY_BAR.equalsIgnoreCase(spec.ofPieType)) {
|
||||
g.draw(new Line2D.Double(x1, y1, secondaryLeft, cy - d1 / 2.0));
|
||||
g.draw(new Line2D.Double(x2, y2, secondaryLeft, cy + d1 / 2.0));
|
||||
} else {
|
||||
double t1 = Math.toRadians(270.0 + wedgeSweep);
|
||||
double t2 = Math.toRadians(270.0 - wedgeSweep);
|
||||
g.draw(new Line2D.Double(x1, y1,
|
||||
cx2 + d2 / 2.0 * Math.sin(t1), cy - d2 / 2.0 * Math.cos(t1)));
|
||||
g.draw(new Line2D.Double(x2, y2,
|
||||
cx2 + d2 / 2.0 * Math.sin(t2), cy - d2 / 2.0 * Math.cos(t2)));
|
||||
}
|
||||
}
|
||||
|
||||
/** Один сектор: углы Word — от 12 часов по часовой, обводка как у PiePainter. */
|
||||
private static void drawSector(Graphics2D g, ChartSpec.Series s, int i,
|
||||
List<Color> palette, double cx, double cy,
|
||||
double radius, double startDeg, double sweepDeg) {
|
||||
private static void drawSector(Graphics2D g, Color fill, ChartSpec.Series s,
|
||||
double cx, double cy, double radius,
|
||||
double startDeg, double sweepDeg) {
|
||||
Arc2D.Double arc = new Arc2D.Double(cx - radius, cy - radius, 2 * radius, 2 * radius,
|
||||
90.0 - startDeg, -sweepDeg, Arc2D.PIE);
|
||||
g.setColor(s.fillAt(i, palette));
|
||||
g.setColor(fill);
|
||||
g.fill(arc);
|
||||
Color outline = s.outlineNoFill ? null
|
||||
: s.outlineColor != null ? s.outlineColor : Color.WHITE;
|
||||
|
||||
Reference in New Issue
Block a user