Skip to content

Commit 59b6e1e

Browse files
committed
Introduce grid_layer for axis grids
git-svn-id: https://subversion.gsi.de/dabc/trunk/plugins/root/js@2812 bcbf6573-9a26-0410-9ebc-ce4ab7aade96
1 parent c7fb365 commit 59b6e1e

File tree

1 file changed

+60
-69
lines changed

1 file changed

+60
-69
lines changed

scripts/JSRootPainter.js

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -134,53 +134,46 @@
134134

135135
/** Function that generates all root colors */
136136
JSROOT.Painter.root_colors = function() {
137-
var colorMap = new Array('rgb(255, 255, 255)', 'rgb(0, 0, 0)',
138-
'rgb(255, 0, 0)', 'rgb(0, 255, 0)', 'rgb(0, 0, 255)',
139-
'rgb(255, 255, 0)', 'rgb(255, 0, 255)', 'rgb(0, 255, 255)',
137+
var colorMap = new Array('white', 'black', 'red', 'green', 'blue',
138+
'rgb(255,255,0)', 'rgb(255,0,255)', 'rgb(0,255,255)',
140139
'rgb(89, 211, 84)', 'rgb(89, 84, 216)', 'rgb(254, 254, 254)',
141-
'rgb(191, 181, 173)', 'rgb(76, 76, 76)', 'rgb(102, 102, 102)',
142-
'rgb(127, 127, 127)', 'rgb(153, 153, 153)', 'rgb(178, 178, 178)',
143-
'rgb(204, 204, 204)', 'rgb(229, 229, 229)', 'rgb(242, 242, 242)',
144-
'rgb(204, 198, 170)', 'rgb(204, 198, 170)', 'rgb(193, 191, 168)',
145-
'rgb(186, 181, 163)', 'rgb(178, 165, 150)', 'rgb(183, 163, 155)',
146-
'rgb(173, 153, 140)', 'rgb(155, 142, 130)', 'rgb(135, 102, 86)',
147-
'rgb(175, 206, 198)', 'rgb(132, 193, 163)', 'rgb(137, 168, 160)',
148-
'rgb(130, 158, 140)', 'rgb(173, 188, 198)', 'rgb(122, 142, 153)',
149-
'rgb(117, 137, 145)', 'rgb(104, 130, 150)', 'rgb(109, 122, 132)',
150-
'rgb(124, 153, 209)', 'rgb(127, 127, 155)', 'rgb(170, 165, 191)',
151-
'rgb(211, 206, 135)', 'rgb(221, 186, 135)', 'rgb(188, 158, 130)',
152-
'rgb(198, 153, 124)', 'rgb(191, 130, 119)', 'rgb(206, 94, 96)',
153-
'rgb(170, 142, 147)', 'rgb(165, 119, 122)', 'rgb(147, 104, 112)',
154-
'rgb(211, 89, 84)');
140+
'rgb(191,181, 173)', 'rgb(76, 76, 76)', 'rgb(102, 102, 102)',
141+
'rgb(127,127, 127)', 'rgb(153, 153, 153)', 'rgb(178, 178, 178)',
142+
'rgb(204,204, 204)', 'rgb(229, 229, 229)', 'rgb(242, 242, 242)',
143+
'rgb(204,198, 170)', 'rgb(204, 198, 170)', 'rgb(193, 191, 168)',
144+
'rgb(186,181, 163)', 'rgb(178, 165, 150)', 'rgb(183, 163, 155)',
145+
'rgb(173,153, 140)', 'rgb(155, 142, 130)', 'rgb(135, 102, 86)',
146+
'rgb(175,206, 198)', 'rgb(132, 193, 163)', 'rgb(137, 168, 160)',
147+
'rgb(130,158, 140)', 'rgb(173, 188, 198)', 'rgb(122, 142, 153)',
148+
'rgb(117,137, 145)', 'rgb(104, 130, 150)', 'rgb(109, 122, 132)',
149+
'rgb(124,153, 209)', 'rgb(127, 127, 155)', 'rgb(170, 165, 191)',
150+
'rgb(211,206, 135)', 'rgb(221, 186, 135)', 'rgb(188, 158, 130)',
151+
'rgb(198,153, 124)', 'rgb(191, 130, 119)', 'rgb(206, 94, 96)',
152+
'rgb(170,142, 147)', 'rgb(165, 119, 122)', 'rgb(147, 104, 112)',
153+
'rgb(211,89, 84)');
155154

156155
var circleColors = [ 632, 416, 600, 400, 616, 432 ];
157156

158157
var rectangleColors = [ 800, 820, 840, 860, 880, 900 ];
159158

160159
var set1 = [ 255, 204, 204, 255, 153, 153, 204, 153, 153, 255, 102, 102,
161160
204, 102, 102, 153, 102, 102, 255, 51, 51, 204, 51, 51, 153, 51,
162-
51, 102, 51, 51, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0,
163-
0 ];
161+
51, 102, 51, 51, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0, 0 ];
164162
var set2 = [ 204, 255, 204, 153, 255, 153, 153, 204, 153, 102, 255, 102,
165163
102, 204, 102, 102, 153, 102, 51, 255, 51, 51, 204, 51, 51, 153,
166-
51, 51, 102, 51, 0, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51,
167-
0 ];
164+
51, 51, 102, 51, 0, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51, 0 ];
168165
var set3 = [ 204, 204, 255, 153, 153, 255, 153, 153, 204, 102, 102, 255,
169166
102, 102, 204, 102, 102, 153, 51, 51, 255, 51, 51, 204, 51, 51,
170-
153, 51, 51, 102, 0, 0, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0,
171-
51 ];
167+
153, 51, 51, 102, 0, 0, 255, 0, 0, 204, 0, 0, 153, 0, 0, 102, 0, 0, 51 ];
172168
var set4 = [ 255, 255, 204, 255, 255, 153, 204, 204, 153, 255, 255, 102,
173169
204, 204, 102, 153, 153, 102, 255, 255, 51, 204, 204, 51, 153, 153,
174-
51, 102, 102, 51, 255, 255, 0, 204, 204, 0, 153, 153, 0, 102, 102,
175-
0, 51, 51, 0 ];
170+
51, 102, 102, 51, 255, 255, 0, 204, 204, 0, 153, 153, 0, 102, 102, 0, 51, 51, 0 ];
176171
var set5 = [ 255, 204, 255, 255, 153, 255, 204, 153, 204, 255, 102, 255,
177172
204, 102, 204, 153, 102, 153, 255, 51, 255, 204, 51, 204, 153, 51,
178-
153, 102, 51, 102, 255, 0, 255, 204, 0, 204, 153, 0, 153, 102, 0,
179-
102, 51, 0, 51 ];
173+
153, 102, 51, 102, 255, 0, 255, 204, 0, 204, 153, 0, 153, 102, 0, 102, 51, 0, 51 ];
180174
var set6 = [ 204, 255, 255, 153, 255, 255, 153, 204, 204, 102, 255, 255,
181-
102, 204, 204, 102, 153, 153, 51, 255, 255, 51, 204, 204, 51, 153,
182-
153, 51, 102, 102, 0, 255, 255, 0, 204, 204, 0, 153, 153, 0, 102,
183-
102, 0, 51, 51 ];
175+
102, 204, 204, 102, 153, 153, 51, 255, 255, 51, 204, 204, 51, 153,
176+
153, 51, 102, 102, 0, 255, 255, 0, 204, 204, 0, 153, 153, 0, 102, 102, 0, 51, 51 ];
184177

185178
var circleSets = new Array(set1, set2, set3, set4, set5, set6);
186179

@@ -217,17 +210,12 @@
217210

218211
var rectSets = new Array(set7, set8, set9, set10, set11, set12);
219212

220-
/*
221-
* Define circle colors
222-
*/
223213
for (var i = 0; i < 6; i++) {
224214
for (var j = 0; j < 15; j++) {
225215
var colorn = circleColors[i] + j - 10;
226-
colorMap[colorn] = 'rgb(' + circleSets[i][3 * j] + ', '
227-
+ circleSets[i][3 * j + 1] + ', ' + circleSets[i][3 * j + 2] + ')';
216+
colorMap[colorn] = 'rgb(' + circleSets[i][3 * j] + ',' + circleSets[i][3 * j + 1] + ',' + circleSets[i][3 * j + 2] + ')';
228217
colorn = rectangleColors[i] + j - 9;
229-
colorMap[colorn] = 'rgb(' + rectSets[i][3 * j] + ', '
230-
+ rectSets[i][3 * j + 1] + ', ' + rectSets[i][3 * j + 2] + ')';
218+
colorMap[colorn] = 'rgb(' + rectSets[i][3 * j] + ',' + rectSets[i][3 * j + 1] + ',' + rectSets[i][3 * j + 2] + ')';
231219
}
232220
}
233221
return colorMap;
@@ -243,13 +231,14 @@
243231
var num = col.fNumber;
244232
if ((num<0) || (num>4096)) continue;
245233

246-
var rgb = "rgb(" + (col.fRed*255).toFixed(0) + ", " + (col.fGreen*255).toFixed(0) + ", " + (col.fBlue*255).toFixed(0) + ")";
234+
var rgb = "rgb(" + (col.fRed*255).toFixed(0) + "," + (col.fGreen*255).toFixed(0) + "," + (col.fBlue*255).toFixed(0) + ")";
235+
236+
if (rgb == 'rgb(255,255,255)') rgb = 'white';
247237

248238
while (num>JSROOT.Painter.root_colors.length)
249239
JSROOT.Painter.root_colors.push(rgb);
250240

251241
if (JSROOT.Painter.root_colors[num] != rgb) {
252-
// console.log("Replace color "+ num + " " + rgb);
253242
JSROOT.Painter.root_colors[num] = rgb;
254243
}
255244
}
@@ -988,15 +977,13 @@
988977
return fill;
989978
}
990979

991-
992-
if ((pattern == 0) || (color==0) || ((pattern >= 4000) && (pattern <= 4100))) return fill;
980+
if ((pattern < 1001) || ((pattern >= 4000) && (pattern <= 4100))) return fill;
981+
982+
fill.color = JSROOT.Painter.root_colors[color];
993983

994984
var svg = this.svg_canvas(true);
995985

996-
if ((pattern < 3000) || (pattern>3025) || svg.empty()) {
997-
fill.color = JSROOT.Painter.root_colors[color];
998-
return fill;
999-
}
986+
if ((pattern < 3000) || (pattern>3025) || svg.empty()) return fill;
1000987

1001988
var id = "pat_" + pattern + "_" + color;
1002989

@@ -1382,7 +1369,8 @@
13821369

13831370
top_rect = frame_g.append("svg:rect");
13841371

1385-
// append for the moment two layers - for drawing and axis
1372+
// append for the moment three layers - for drawing and axis
1373+
frame_g.append('svg:g').attr('class','grid_layer');
13861374
frame_g.append('svg:g').attr('class','main_layer');
13871375
frame_g.append('svg:g').attr('class','axis_layer');
13881376
} else {
@@ -1571,6 +1559,7 @@
15711559
if ((this.tf1['fLineColor'] == 0) || (this.tf1['fLineWidth'] == 0)) linecolor = "none";
15721560

15731561
var fill = this.createFillPattern(this.tf1);
1562+
if (fill.color == 'white') fill.color = 'none';
15741563

15751564
var line = d3.svg.line()
15761565
.x(function(d) { return Math.round(x(d.x)); })
@@ -1606,7 +1595,7 @@
16061595
.attr("cx", function(d) { return x(d.x); })
16071596
.attr("cy", function(d) { return y(d.y); })
16081597
.attr("r", 4)
1609-
.attr("opacity", 0)
1598+
.style("opacity", 0)
16101599
.append("svg:title")
16111600
.text( function(d) { return "x = " + d.x.toPrecision(4) + " \ny = " + d.y.toPrecision(4); });
16121601
}
@@ -1816,8 +1805,6 @@
18161805

18171806
this.exclusionGraph = true;
18181807

1819-
var ec, ff = 1;
1820-
18211808
var normx, normy;
18221809
var n = this.graph['fNpoints'];
18231810
var glw = this.graph['fLineWidth'],
@@ -1831,9 +1818,6 @@
18311818
if (glw > 32767) glw = 65536 - glw;
18321819
this.bins_lw = glw % 100; // line width
18331820
if (this.bins_lw > 0) this.optionLine = 1;
1834-
ec = JSROOT.Painter.root_colors[this.graph['fFillColor']];
1835-
ec = ec.replace('rgb', 'rgba');
1836-
ec = ec.replace(')', ', 0.20)');
18371821

18381822
var a, i, j, nf, wk = (glw / 100) * 0.005;
18391823
if (this.graph['fLineWidth'] > 32767) wk *= -1;
@@ -2032,8 +2016,7 @@
20322016

20332017
this.excl = d3.range(nf).map(function(p) { return { x : xf[p], y : yf[p] }; });
20342018

2035-
this.excl_ec = ec;
2036-
this.excl_ff = ff;
2019+
this.excl_ff = 1;
20372020

20382021
/* some clean-up */
20392022
xo.splice(0, xo.length);
@@ -2085,7 +2068,7 @@
20852068

20862069
if (this.seriesType == 'bar') {
20872070
var fillcolor = JSROOT.Painter.root_colors[this.graph['fFillColor']];
2088-
if (typeof (fillcolor) == 'undefined') fillcolor = "rgb(204, 204, 204)";
2071+
if (typeof (fillcolor) == 'undefined') fillcolor = "rgb(204,204,204)";
20892072
/* filled bar graph */
20902073
var xdom = this.main_painter().x.domain();
20912074
var xfactor = xdom[1] - xdom[0];
@@ -2111,7 +2094,8 @@
21112094
.attr("d", line(pthis.excl))
21122095
.style("stroke", "none")
21132096
.style("stroke-width", pthis.excl_ff)
2114-
.call(fill.func);
2097+
.call(fill.func)
2098+
.style('opacity', 0.75);
21152099
}
21162100

21172101
if (this.seriesType == 'line') {
@@ -2148,7 +2132,7 @@
21482132
.attr("cx", function(d) { return Math.round(x(d.x)); })
21492133
.attr("cy", function(d) { return Math.round(y(d.y)); })
21502134
.attr("r", 3)
2151-
.attr("opacity", 0)
2135+
.style("opacity", 0)
21522136
.append("svg:title")
21532137
.text(TooltipText);
21542138
}
@@ -3672,43 +3656,49 @@
36723656
JSROOT.THistPainter.prototype.DrawGrids = function() {
36733657
// grid can only be drawn by first painter
36743658
if (!this.is_main_painter()) return;
3659+
3660+
var layer = this.svg_frame(true).select(".grid_layer");
36753661

3676-
this.svg_frame(true).selectAll(".gridLine").remove();
3662+
layer.selectAll(".xgrid").remove();
3663+
layer.selectAll(".ygrid").remove();
36773664
/* add a grid on x axis, if the option is set */
36783665

36793666
// add a grid on x axis, if the option is set
36803667
if (this.options.Gridx) {
36813668

36823669
var h = Number(this.svg_frame(true).attr("height"));
3670+
3671+
var xticks = this.x.ticks(this.x_nticks);
36833672

3684-
this.svg_frame(true).selectAll("gridLine")
3685-
.data(this.x.ticks(this.x_nticks)).enter()
3673+
layer.selectAll(".xgrid")
3674+
.data(xticks).enter()
36863675
.append("svg:line")
3687-
.attr("class", "gridLine")
3676+
.attr("class", "xgrid")
36883677
.attr("x1", this.x)
36893678
.attr("y1", h)
36903679
.attr("x2", this.x)
36913680
.attr("y2",0)
36923681
.style("stroke", "black")
3693-
.style("stroke-width", this.histo['fLineWidth'])
3682+
.style("stroke-width", 1)
36943683
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[11]);
36953684
}
36963685

36973686
// add a grid on y axis, if the option is set
36983687
if (this.options.Gridy) {
3699-
37003688
var w = Number(this.svg_frame(true).attr("width"));
37013689

3702-
this.svg_frame(true).selectAll("gridLine")
3703-
.data(this.y.ticks(this.y_nticks)).enter()
3690+
var yticks = this.y.ticks(this.y_nticks);
3691+
3692+
layer.selectAll('.ygrid')
3693+
.data(yticks).enter()
37043694
.append("svg:line")
3705-
.attr("class", "gridLine")
3695+
.attr("class", "ygrid")
37063696
.attr("x1", 0)
37073697
.attr("y1", this.y)
37083698
.attr("x2", w)
37093699
.attr("y2", this.y)
37103700
.style("stroke", "black")
3711-
.style("stroke-width", this.histo['fLineWidth'])
3701+
.style("stroke-width", 1)
37123702
.style("stroke-dasharray", JSROOT.Painter.root_line_styles[11]);
37133703
}
37143704
}
@@ -4693,6 +4683,7 @@
46934683
// from here we analyze object content
46944684
// therefore code will be moved
46954685
this.fill = this.createFillPattern(this.histo);
4686+
if (this.fill.color == 'white') this.fill.color = 'none';
46964687

46974688
this.linecolor = JSROOT.Painter.root_colors[this.histo['fLineColor']];
46984689
if (this.histo['fLineColor'] == 0) this.linecolor = '#4572A7';
@@ -5124,7 +5115,7 @@
51245115
.attr("y1", function(d) { return Math.max(0, d.y); })
51255116
.attr("x2", function(d) { return d.x + d.width / 2; })
51265117
.attr("y2", function(d) { return height; })
5127-
.attr("opacity", 0)
5118+
.style("opacity", 0)
51285119
.style("stroke", "#4572A7")
51295120
.style("stroke-width", function(d) { return d.width; })
51305121
.on('mouseover', function() {
@@ -5172,7 +5163,7 @@
51725163
// create painter and add it to canvas
51735164
var painter = new JSROOT.TH1Painter(histo);
51745165
painter.SetDivId(divid, 1);
5175-
5166+
51765167
// here we deciding how histogram will look like and how will be shown
51775168
painter.options = painter.DecodeOptions(opt);
51785169

0 commit comments

Comments
 (0)