Skip to content

Commit e67e4db

Browse files
committed
7. Introduce createAttLine for TAttLine class
git-svn-id: https://subversion.gsi.de/dabc/trunk/plugins/root/js@2813 bcbf6573-9a26-0410-9ebc-ce4ab7aade96
1 parent 59b6e1e commit e67e4db

File tree

1 file changed

+94
-70
lines changed

1 file changed

+94
-70
lines changed

scripts/JSRootPainter.js

Lines changed: 94 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,39 @@
959959
svg_p['mainpainter'] = this;
960960
}
961961

962-
JSROOT.TObjectPainter.prototype.createFillPattern = function(attfill, pattern, color) {
962+
JSROOT.TObjectPainter.prototype.createAttLine = function(attline) {
963+
964+
var color = 0, _width = 0, style = 0;
965+
966+
if (attline=='black') { color = 1; _width = 1; } else
967+
if (attline=='none') { _width = 0; } else
968+
if (typeof attline == 'object') {
969+
if ('fLineColor' in attline) color = attline['fLineColor'];
970+
if ('fLineWidth' in attline) _width = attline['fLineWidth'];
971+
if ('fLineStyle' in attline) style = attline['fLineStyle'];
972+
}
973+
974+
var line = {
975+
color: JSROOT.Painter.root_colors[color],
976+
width: _width,
977+
dash: JSROOT.Painter.root_line_styles[style]
978+
};
979+
980+
if ((_width==0) || (color==0)) line.color = 'none';
981+
982+
line.SetLine = function(selection) {
983+
selection.style('stroke', this.color);
984+
if (this.color!='none') {
985+
selection.style('stroke-width', this.width);
986+
selection.style('stroke-dasharray', this.dash);
987+
}
988+
}
989+
line.func = line.SetLine.bind(line);
990+
991+
return line;
992+
}
993+
994+
JSROOT.TObjectPainter.prototype.createAttFill = function(attfill, pattern, color) {
963995

964996
if ((pattern==null) && attfill) pattern = attfill['fFillStyle'];
965997
if ((color==null) && attfill) color = attfill['fFillColor'];
@@ -1314,14 +1346,14 @@
13141346
var tm = height * ndc.y1;
13151347
var bm = height * (1 - ndc.y2);
13161348

1317-
var framecolor = null, bordermode = 0, bordersize = 0, linecolor = 'black', linestyle = 0, linewidth = 1;
1349+
var framecolor = this.createAttFill('white'),
1350+
lineatt = this.createAttLine('black'),
1351+
bordermode = 0, bordersize = 0;
13181352

13191353
if (this.tframe) {
13201354
bordermode = this.tframe['fBorderMode'];
13211355
bordersize = this.tframe['fBorderSize'];
1322-
linecolor = JSROOT.Painter.root_colors[this.tframe['fLineColor']];
1323-
linestyle = this.tframe['fLineStyle'];
1324-
linewidth = this.tframe['fLineWidth'];
1356+
lineatt = this.createAttLine(this.tframe);
13251357
if (root_pad) {
13261358
var xspan = width / Math.abs(root_pad['fX2'] - root_pad['fX1']);
13271359
var yspan = height / Math.abs(root_pad['fY2'] - root_pad['fY1']);
@@ -1348,16 +1380,15 @@
13481380
w -= (lm + rm);
13491381
h -= (tm + bm);
13501382
}
1351-
framecolor = this.createFillPattern(this.tframe);
1383+
framecolor = this.createAttFill(this.tframe);
13521384
} else {
13531385
if (root_pad) {
1354-
framecolor = this.createFillPattern(null, root_pad['fFrameFillStyle'], root_pad['fFrameFillColor']);
1386+
framecolor = this.createAttFill(null, root_pad['fFrameFillStyle'], root_pad['fFrameFillColor']);
13551387
}
13561388
w -= (lm + rm);
13571389
h -= (tm + bm);
13581390
}
1359-
if (framecolor == null)
1360-
framecolor = this.createFillPattern('white');
1391+
13611392

13621393
// this is svg:g object - container for every other items belonging to frame
13631394
var frame_g = this.svg_pad(true).select(".root_frame");
@@ -1402,8 +1433,7 @@
14021433
.attr("width", w)
14031434
.attr("height", h)
14041435
.call(framecolor.func)
1405-
.style("stroke", linecolor)
1406-
.style("stroke-width", linewidth);
1436+
.call(lineatt.func);
14071437
}
14081438

14091439
JSROOT.TFramePainter.prototype.Redraw = function() {
@@ -1555,30 +1585,26 @@
15551585
var x = this.main_painter().x;
15561586
var y = this.main_painter().y;
15571587

1558-
var linecolor = JSROOT.Painter.root_colors[this.tf1['fLineColor']];
1559-
if ((this.tf1['fLineColor'] == 0) || (this.tf1['fLineWidth'] == 0)) linecolor = "none";
1560-
1561-
var fill = this.createFillPattern(this.tf1);
1588+
var attline = this.createAttLine(this.tf1);
1589+
var fill = this.createAttFill(this.tf1);
15621590
if (fill.color == 'white') fill.color = 'none';
15631591

15641592
var line = d3.svg.line()
1565-
.x(function(d) { return Math.round(x(d.x)); })
1566-
.y(function(d) { return Math.round(y(d.y)); })
1593+
.x(function(d) { return x(d.x).toFixed(1); })
1594+
.y(function(d) { return y(d.y).toFixed(1); })
15671595
.interpolate(this.interpolate_method);
15681596

15691597
var area = d3.svg.area()
1570-
.x(function(d) { return Math.round(x(d.x)); })
1598+
.x(function(d) { return x(d.x).toFixed(1); })
15711599
.y1(h)
1572-
.y0(function(d) { return Math.round(y(d.y)); });
1600+
.y0(function(d) { return y(d.y).toFixed(1); });
15731601

1574-
if (linecolor != "none")
1602+
if (attline.color != "none")
15751603
this.draw_g.append("svg:path")
15761604
.attr("class", "line")
15771605
.attr("d",line(pthis.bins))
1578-
.style("stroke", linecolor)
1579-
.style("stroke-width", pthis.tf1['fLineWidth'])
1580-
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[pthis.tf1['fLineStyle']])
1581-
.style("fill", "none");
1606+
.style("fill", "none")
1607+
.call(attline.func);
15821608

15831609
if (fill.color != "none")
15841610
this.draw_g.append("svg:path")
@@ -1592,8 +1618,8 @@
15921618
this.draw_g.selectAll()
15931619
.data(this.bins).enter()
15941620
.append("svg:circle")
1595-
.attr("cx", function(d) { return x(d.x); })
1596-
.attr("cy", function(d) { return y(d.y); })
1621+
.attr("cx", function(d) { return x(d.x).toFixed(1); })
1622+
.attr("cy", function(d) { return y(d.y).toFixed(1); })
15971623
.attr("r", 4)
15981624
.style("opacity", 0)
15991625
.append("svg:title")
@@ -1759,6 +1785,8 @@
17591785

17601786
var npoints = this.graph['fNpoints'];
17611787
if ((this.graph._typename=="TCutG") && (npoints>3)) npoints--;
1788+
1789+
this.lineatt = this.createAttLine(this.graph);
17621790

17631791
this.bins = d3.range(npoints).map(
17641792
function(p) {
@@ -1796,31 +1824,33 @@
17961824
}
17971825
});
17981826

1799-
this.bins_lw = this.graph['fLineWidth']; // line width
1800-
18011827
this.exclusionGraph = false;
1802-
if (this.bins_lw <= 99) return;
1828+
if (this.lineatt.width <= 99) return;
18031829

18041830
// special handling of exclusion graphs
18051831

18061832
this.exclusionGraph = true;
18071833

18081834
var normx, normy;
18091835
var n = this.graph['fNpoints'];
1810-
var glw = this.graph['fLineWidth'],
1811-
xo = new Array(n + 2),
1812-
yo = new Array(n + 2),
1813-
xt = new Array(n + 2),
1814-
yt = new Array(n + 2),
1815-
xf = new Array(2 * n + 2),
1836+
var xo = new Array(n + 2),
1837+
yo = new Array(n + 2),
1838+
xt = new Array(n + 2),
1839+
yt = new Array(n + 2),
1840+
xf = new Array(2 * n + 2),
18161841
yf = new Array(2 * n + 2);
18171842
// negative value means another side of the line...
1818-
if (glw > 32767) glw = 65536 - glw;
1819-
this.bins_lw = glw % 100; // line width
1820-
if (this.bins_lw > 0) this.optionLine = 1;
18211843

1822-
var a, i, j, nf, wk = (glw / 100) * 0.005;
1823-
if (this.graph['fLineWidth'] > 32767) wk *= -1;
1844+
1845+
1846+
var a, i, j, nf, wk = 1;
1847+
if (this.lineatt.width > 32767) {
1848+
this.lineatt.width = 65536 - this.lineatt.width;
1849+
wk = -1;
1850+
}
1851+
wk *= (this.lineatt.width / 100) * 0.005;
1852+
this.lineatt.width = this.lineatt.width % 100; // line width
1853+
if (this.lineatt.width > 0) this.optionLine = 1;
18241854

18251855
var w = Number(this.svg_frame(true).attr("width")),
18261856
h = Number(this.svg_frame(true).attr("height"));
@@ -2042,7 +2072,7 @@
20422072

20432073
var pthis = this;
20442074

2045-
var fill = this.createFillPattern(this.graph);
2075+
var fill = this.createAttFill(this.graph);
20462076

20472077
function TooltipText(d) {
20482078

@@ -2103,12 +2133,8 @@
21032133
var close_symbol = "";
21042134
if (this.graph._typename=="TCutG") close_symbol = " Z";
21052135

2106-
var line_color = "none", line_style = "none";
2107-
2108-
if (this.optionLine == 1) {
2109-
line_color = JSROOT.Painter.root_colors[this.graph['fLineColor']];
2110-
line_style = JSROOT.Painter.root_line_styles[this.graph['fLineStyle']];
2111-
}
2136+
var lineatt = this.lineatt;
2137+
if (this.optionLine == 0) lineatt = this.createAttLine('none');
21122138

21132139
if (this.optionFill == 1) {
21142140

@@ -2119,9 +2145,7 @@
21192145
this.draw_g.append("svg:path")
21202146
.attr("d", line(pthis.bins) + close_symbol)
21212147
.attr("class", "draw_line")
2122-
.style("stroke", line_color)
2123-
.style("stroke-width", pthis.bins_lw)
2124-
.style("stroke-dasharray", line_style)
2148+
.call(lineatt.func)
21252149
.call(fill.func);
21262150

21272151
// do not add tooltip for line, when we wants to add markers
@@ -2181,26 +2205,26 @@
21812205
.attr("y1", 0)
21822206
.attr("x2", function(d) { return d.grx2; })
21832207
.attr("y2", 0)
2184-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2185-
.style("stroke-width", this.graph['fLineWidth']);
2208+
.style("stroke", this.lineatt.color)
2209+
.style("stroke-width", this.lineatt.width);
21862210

21872211
nodes.filter(function(d) { return (d.exlow > 0); })
21882212
.append("svg:line")
21892213
.attr("y1", -3)
21902214
.attr("x1", function(d) { return d.grx0; })
21912215
.attr("y2", 3)
21922216
.attr("x2", function(d) { return d.grx0; })
2193-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2194-
.style("stroke-width", this.graph['fLineWidth']);
2217+
.style("stroke", this.lineatt.color)
2218+
.style("stroke-width", this.lineatt.width);
21952219

21962220
nodes.filter(function(d) { return (d.exhigh > 0); })
21972221
.append("svg:line")
21982222
.attr("y1", -3)
21992223
.attr("x1", function(d) { return d.grx2; })
22002224
.attr("y2", 3)
22012225
.attr("x2", function(d) { return d.grx2; })
2202-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2203-
.style( "stroke-width", this.graph['fLineWidth']);
2226+
.style("stroke", this.lineatt.color)
2227+
.style( "stroke-width", this.lineatt.width);
22042228

22052229
// Add y-error indicators
22062230

@@ -2210,26 +2234,26 @@
22102234
.attr("y1", function(d) { return d.gry0; })
22112235
.attr("x2", 0)
22122236
.attr("y2", function(d) { return d.gry2; })
2213-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2214-
.style("stroke-width", this.graph['fLineWidth']);
2237+
.style("stroke", this.lineatt.color)
2238+
.style("stroke-width", this.lineatt.width);
22152239

22162240
nodes.filter(function(d) { return (d.eylow > 0); })
22172241
.append("svg:line")
22182242
.attr("x1", -3)
22192243
.attr("y1", function(d) { return d.gry0; })
22202244
.attr("x2", 3)
22212245
.attr("y2", function(d) { return d.gry0; })
2222-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2223-
.style("stroke-width", this.graph['fLineWidth']);
2246+
.style("stroke", this.lineatt.color)
2247+
.style("stroke-width", this.lineatt.width);
22242248

22252249
nodes.filter(function(d) { return (d.eyhigh > 0); })
22262250
.append("svg:line")
22272251
.attr("x1", -3)
22282252
.attr("y1", function(d) { return d.gry2; })
22292253
.attr("x2", 3)
22302254
.attr("y2", function(d) { return d.gry2; })
2231-
.style("stroke", JSROOT.Painter.root_colors[this.graph['fLineColor']])
2232-
.style("stroke-width", this.graph['fLineWidth']);
2255+
.style("stroke", this.lineatt.color)
2256+
.style("stroke-width", this.lineatt.width);
22332257
}
22342258

22352259
if (this.showMarker) {
@@ -2315,7 +2339,7 @@
23152339
var lcolor = JSROOT.Painter.root_colors[pavetext['fLineColor']];
23162340
var tcolor = JSROOT.Painter.root_colors[pavetext['fTextColor']];
23172341
var scolor = JSROOT.Painter.root_colors[pavetext['fShadowColor']];
2318-
var fcolor = this.createFillPattern(pavetext);
2342+
var fcolor = this.createAttFill(pavetext);
23192343

23202344
// align = 10*HorizontalAlign + VerticalAlign
23212345
// 1=left adjusted, 2=centered, 3=right adjusted
@@ -2651,9 +2675,9 @@
26512675
var fill = null;
26522676

26532677
if (this.pad && 'fFillColor' in this.pad)
2654-
fill = this.createFillPattern(this.pad);
2678+
fill = this.createAttFill(this.pad);
26552679
else
2656-
fill = this.createFillPattern('white');
2680+
fill = this.createAttFill('white');
26572681

26582682
render_to.css("background-color", fill.color);
26592683

@@ -2690,7 +2714,7 @@
26902714
var h = Math.round(this.pad['fAbsHNDC'] * height);
26912715
y -= h;
26922716

2693-
var fill = this.createFillPattern(this.pad);
2717+
var fill = this.createAttFill(this.pad);
26942718

26952719
var border_width = this.pad['fLineWidth'];
26962720
var border_color = JSROOT.Painter.root_colors[this.pad['fLineColor']];
@@ -4682,7 +4706,7 @@
46824706

46834707
// from here we analyze object content
46844708
// therefore code will be moved
4685-
this.fill = this.createFillPattern(this.histo);
4709+
this.fill = this.createAttFill(this.histo);
46864710
if (this.fill.color == 'white') this.fill.color = 'none';
46874711

46884712
this.linecolor = JSROOT.Painter.root_colors[this.histo['fLineColor']];
@@ -6093,7 +6117,7 @@
60936117
y -= h;
60946118
var lcolor = JSROOT.Painter.root_colors[pave['fLineColor']];
60956119
var lwidth = pave['fBorderSize'] ? pave['fBorderSize'] : 0;
6096-
var fill = this.createFillPattern(pave);
6120+
var fill = this.createAttFill(pave);
60976121

60986122
var p = this.draw_g
60996123
.attr("x", x)
@@ -6209,7 +6233,7 @@
62096233
pos_y = pos_y - (hh / 2);
62106234
var pos_x = (tpos_x / 2) - (ww / 2);
62116235

6212-
var fill = this.createFillPattern(attfill);
6236+
var fill = this.createAttFill(attfill);
62136237

62146238
p.append("svg:rect")
62156239
.attr("x", pos_x)
@@ -6478,7 +6502,7 @@
64786502
var height = Math.abs(pavelabel['fY2NDC'] - pavelabel['fY1NDC']) * h;
64796503
pos_y -= height;
64806504
var font_size = Math.round(height / 1.9);
6481-
var fcolor = this.createFillPattern(pavelabel);
6505+
var fcolor = this.createAttFill(pavelabel);
64826506
var lcolor = JSROOT.Painter.root_colors[pavelabel['fLineColor']];
64836507
var tcolor = JSROOT.Painter.root_colors[pavelabel['fTextColor']];
64846508
var scolor = JSROOT.Painter.root_colors[pavelabel['fShadowColor']];

0 commit comments

Comments
 (0)