Skip to content

Commit 087ecf2

Browse files
committed
Provide primitive support for RLegend
Just printout title and labels for beginning
1 parent 202415b commit 087ecf2

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

scripts/JSRootPainter.v7.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4316,6 +4316,7 @@
43164316
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RLine", icon: "img_graph", prereq: "v7more", func: "JSROOT.v7.drawLine", opt: "", direct: true, csstype: "line" });
43174317
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RBox", icon: "img_graph", prereq: "v7more", func: "JSROOT.v7.drawBox", opt: "", direct: true, csstype: "box" });
43184318
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RMarker", icon: "img_graph", prereq: "v7more", func: "JSROOT.v7.drawMarker", opt: "", direct: true, csstype: "marker" });
4319+
JSROOT.addDrawFunc({ name: "ROOT::Experimental::RLegend", icon: "img_graph", prereq: "v7more", func: "JSROOT.v7.drawLegend", opt: "", direct: true, csstype: "legend" });
43194320

43204321
JSROOT.v7.TAxisPainter = TAxisPainter;
43214322
JSROOT.v7.TFramePainter = TFramePainter;

scripts/JSRootPainter.v7more.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
this.FinishTextDrawing();
5252
}
5353

54+
// =================================================================================
5455

5556
function drawLine() {
5657

@@ -76,6 +77,7 @@
7677
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[line_style]);
7778
}
7879

80+
// =================================================================================
7981

8082
function drawBox() {
8183

@@ -93,7 +95,7 @@
9395

9496
this.CreateG();
9597

96-
if (fill_style == 0 ) fill_color = "none";
98+
if (fill_style == 0) fill_color = "none";
9799

98100
this.draw_g
99101
.append("svg:rect")
@@ -109,6 +111,7 @@
109111
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[line_style]);
110112
}
111113

114+
// =================================================================================
112115

113116
function drawMarker() {
114117
var marker = this.GetObject(),
@@ -128,12 +131,70 @@
128131
.call(att.func);
129132
}
130133

134+
// =================================================================================
135+
136+
function drawLegend() {
137+
138+
var legend = this.GetObject(),
139+
pp = this.pad_painter(),
140+
p1 = pp.GetCoordinate(legend.fP1),
141+
p2 = pp.GetCoordinate(legend.fP2),
142+
line_width = this.v7EvalAttr( "box_border_width", 1),
143+
line_style = this.v7EvalAttr( "box_border_style", 1),
144+
line_color = this.v7EvalColor( "box_border_color", "black"),
145+
fill_color = this.v7EvalColor( "box_fill_color", "white"),
146+
fill_style = this.v7EvalAttr( "box_fill_style", 1),
147+
text_size = this.v7EvalAttr( "title_size", 12),
148+
text_angle = -1 * this.v7EvalAttr( "title_angle", 0),
149+
text_align = this.v7EvalAttr( "title_align", 22),
150+
text_color = this.v7EvalColor( "title_color", "black"),
151+
text_font = this.v7EvalAttr( "title_font", 41);
152+
153+
this.CreateG();
154+
155+
if (fill_style == 0) fill_color = "none";
156+
157+
this.draw_g
158+
.append("svg:rect")
159+
.attr("x", p1.x)
160+
.attr("width", p2.x-p1.x)
161+
.attr("y", p2.y)
162+
.attr("height", p1.y-p2.y)
163+
.style("stroke", line_color)
164+
.attr("stroke-width", line_width)
165+
.attr("fill", fill_color)
166+
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[line_style]);
167+
168+
var nlines = legend.fEntries.length;
169+
170+
if (legend.fTitle) nlines++;
171+
172+
var arg = { align: text_align, x: (p1.x+p2.x)/2, rotate: text_angle, color: text_color, latex: 1 };
173+
174+
this.StartTextDrawing(text_font, text_size);
175+
176+
var cnt = 0;
177+
if (legend.fTitle) {
178+
this.DrawText(JSROOT.extend({ y: p2.y - 0.5*(p2.y-p1.y)/(nlines+1), text: legend.fTitle }, arg));
179+
cnt++;
180+
}
181+
182+
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));
185+
cnt++;
186+
}
187+
188+
this.FinishTextDrawing();
189+
}
190+
131191
// ================================================================================
132192

133193
JSROOT.v7.drawText = drawText;
134194
JSROOT.v7.drawLine = drawLine;
135195
JSROOT.v7.drawBox = drawBox;
136196
JSROOT.v7.drawMarker = drawMarker;
197+
JSROOT.v7.drawLegend = drawLegend;
137198

138199
return JSROOT;
139200

0 commit comments

Comments
 (0)