Skip to content

Commit cb017d7

Browse files
committed
Absolute primitive extraction of lineatt to make drawing of RLegend
1 parent 087ecf2 commit cb017d7

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

scripts/JSRootPainter.v7more.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133

134134
// =================================================================================
135135

136-
function drawLegend() {
136+
function drawLegend(arg) {
137137

138138
var legend = this.GetObject(),
139139
pp = this.pad_painter(),
@@ -144,16 +144,30 @@
144144
line_color = this.v7EvalColor( "box_border_color", "black"),
145145
fill_color = this.v7EvalColor( "box_fill_color", "white"),
146146
fill_style = this.v7EvalAttr( "box_fill_style", 1),
147-
text_size = this.v7EvalAttr( "title_size", 12),
147+
text_size = this.v7EvalAttr( "title_size", 20),
148148
text_angle = -1 * this.v7EvalAttr( "title_angle", 0),
149149
text_align = this.v7EvalAttr( "title_align", 22),
150150
text_color = this.v7EvalColor( "title_color", "black"),
151151
text_font = this.v7EvalAttr( "title_font", 41);
152152

153+
//if (arg=="drag_resize") {
154+
// p1.x = parseInt(this.draw_g.attr("x"));
155+
// p2.y = parseInt(this.draw_g.attr("y"));
156+
// p2.x = p1.x + parseInt(this.draw_g.attr("width"));
157+
// p1.y = p2.y + parseInt(this.draw_g.attr("height"));
158+
//}
159+
153160
this.CreateG();
154161

155162
if (fill_style == 0) fill_color = "none";
156163

164+
// position and size required only for drag functions
165+
// this.draw_g.attr("transfrom", "translate(" + p1.x + "," + p2.y + ")")
166+
// .attr("x", p1.x)
167+
// .attr("y", p2.y)
168+
// .attr("width", p2.x-p1.x)
169+
// .attr("height", p1.y-p2.y);
170+
157171
this.draw_g
158172
.append("svg:rect")
159173
.attr("x", p1.x)
@@ -169,23 +183,40 @@
169183

170184
if (legend.fTitle) nlines++;
171185

172-
var arg = { align: text_align, x: (p1.x+p2.x)/2, rotate: text_angle, color: text_color, latex: 1 };
186+
var arg = { align: text_align, rotate: text_angle, color: text_color, latex: 1 };
173187

174188
this.StartTextDrawing(text_font, text_size);
175189

176190
var cnt = 0;
177191
if (legend.fTitle) {
178-
this.DrawText(JSROOT.extend({ y: p2.y - 0.5*(p2.y-p1.y)/(nlines+1), text: legend.fTitle }, arg));
192+
this.DrawText(JSROOT.extend({ x: p1.x + (p2.x-p1.x)/2, y: p2.y - 0.5*(p2.y-p1.y)/(nlines+1), text: legend.fTitle }, arg));
179193
cnt++;
180194
}
181195

182196
for (var i=0; i<legend.fEntries.length; ++i) {
183-
var entry = legend.fEntries[i];
184-
this.DrawText(JSROOT.extend({ y: p2.y - (cnt+0.5)*(p2.y-p1.y)/(nlines+1), text: entry.fLabel }, arg));
197+
var entry = legend.fEntries[i],
198+
ypos = p2.y - (cnt+0.5)*(p2.y-p1.y)/(nlines+1);
199+
this.DrawText(JSROOT.extend({ x: p1.x + (p2.x-p1.x)/4, y: ypos, text: entry.fLabel }, arg));
200+
201+
var objp = this.FindPainterFor(entry.fDrawable.fIO);
202+
203+
if (objp && objp.lineatt)
204+
this.draw_g
205+
.append("svg:line")
206+
.attr("x1", p1.x + (p2.x-p1.x)*0.5)
207+
.attr("y1", ypos)
208+
.attr("x2", p1.x + (p2.x-p1.x)*0.8)
209+
.attr("y2", ypos)
210+
.call(objp.lineatt.func);
211+
185212
cnt++;
186213
}
187214

188215
this.FinishTextDrawing();
216+
217+
// this.AddDrag({ minwidth: 10, minheight: 20, canselect: false,
218+
// redraw: this.Redraw.bind(this, "drag_resize"),
219+
// ctxmenu: false /*JSROOT.touches && JSROOT.gStyle.ContextMenu && this.UseContextMenu */ });
189220
}
190221

191222
// ================================================================================

0 commit comments

Comments
 (0)