Skip to content

Commit f87ff1c

Browse files
committed
Paint pie title
1 parent 9fa5c3f commit f87ff1c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

modules/draw/TPiePainter.mjs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { clTPaveText, create, kTitle, gStyle } from '../core.mjs';
12
import { makeTranslate, DrawOptions, floatToString } from '../base/BasePainter.mjs';
23
import { ObjectPainter } from '../base/ObjectPainter.mjs';
4+
import { TPavePainter, kPosTitle } from '../hist/TPavePainter.mjs';
35
import { ensureTCanvas } from '../gpad/TCanvasPainter.mjs';
46
import { addMoveHandler } from '../gui/utils.mjs';
57
import { assignContextMenu } from '../gui/menu.mjs';
@@ -14,6 +16,7 @@ class TPiePainter extends ObjectPainter {
1416
#is3d; // if 3d mode enabled
1517
#lblor; // how to draw labels
1618
#sort; // sorting order of pies
19+
#same; // draw on existing pad
1720
#samecolor; // use same color for labels
1821

1922
/** @summary Decode options */
@@ -23,6 +26,7 @@ class TPiePainter extends ObjectPainter {
2326
this.#lblor = 0;
2427
this.#sort = 0;
2528
this.#samecolor = false;
29+
this.#same = d.check('SAME');
2630
if (d.check('SC'))
2731
this.#samecolor = true; // around
2832
if (d.check('T'))
@@ -53,6 +57,41 @@ class TPiePainter extends ObjectPainter {
5357
return;
5458
}
5559

60+
/** @summary Draw title
61+
* @return {Promise} with painter */
62+
async drawTitle() {
63+
// case when histogram drawn over other histogram (same option)
64+
if (this.#same)
65+
return this;
66+
67+
const pie = this.getObject(), st = gStyle,
68+
draw_title = (st.fOptTitle > 0) && pie.fTitle,
69+
pp = this.getPadPainter();
70+
71+
let pt = pp.findInPrimitives(kTitle, clTPaveText);
72+
73+
if (pt) {
74+
pt.Clear();
75+
if (draw_title)
76+
pt.AddText(pie.fTitle);
77+
return this;
78+
}
79+
80+
pt = create(clTPaveText);
81+
Object.assign(pt, {
82+
fName: kTitle, fOption: 'blNDC', fFillColor: st.fTitleColor, fFillStyle: st.fTitleStyle, fBorderSize: st.fTitleBorderSize,
83+
fTextFont: st.fTitleFont, fTextSize: st.fTitleFontSize, fTextColor: st.fTitleTextColor, fTextAlign: 22
84+
});
85+
86+
if (draw_title)
87+
pt.AddText(pie.fTitle);
88+
89+
return TPavePainter.draw(pp, pt, kPosTitle).then(p => {
90+
p?.setSecondaryId(this, kTitle);
91+
return this;
92+
});
93+
}
94+
5695
/** @summary Update TPie object */
5796
updateObject(obj, opt) {
5897
if (!this.matchObjectType(obj))
@@ -271,7 +310,7 @@ class TPiePainter extends ObjectPainter {
271310
promises.push(pr);
272311
}
273312

274-
return Promise.all(promises).then(() => {
313+
return Promise.all(promises).then(() => this.drawTitle()).then(() => {
275314
assignContextMenu(this);
276315

277316
addMoveHandler(this);

0 commit comments

Comments
 (0)