|
51 | 51 | this.FinishTextDrawing(); |
52 | 52 | } |
53 | 53 |
|
| 54 | + // ================================================================================= |
54 | 55 |
|
55 | 56 | function drawLine() { |
56 | 57 |
|
|
76 | 77 | .style("stroke-dasharray", JSROOT.Painter.root_line_styles[line_style]); |
77 | 78 | } |
78 | 79 |
|
| 80 | + // ================================================================================= |
79 | 81 |
|
80 | 82 | function drawBox() { |
81 | 83 |
|
|
93 | 95 |
|
94 | 96 | this.CreateG(); |
95 | 97 |
|
96 | | - if (fill_style == 0 ) fill_color = "none"; |
| 98 | + if (fill_style == 0) fill_color = "none"; |
97 | 99 |
|
98 | 100 | this.draw_g |
99 | 101 | .append("svg:rect") |
|
109 | 111 | .style("stroke-dasharray", JSROOT.Painter.root_line_styles[line_style]); |
110 | 112 | } |
111 | 113 |
|
| 114 | + // ================================================================================= |
112 | 115 |
|
113 | 116 | function drawMarker() { |
114 | 117 | var marker = this.GetObject(), |
|
128 | 131 | .call(att.func); |
129 | 132 | } |
130 | 133 |
|
| 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 | + |
131 | 191 | // ================================================================================ |
132 | 192 |
|
133 | 193 | JSROOT.v7.drawText = drawText; |
134 | 194 | JSROOT.v7.drawLine = drawLine; |
135 | 195 | JSROOT.v7.drawBox = drawBox; |
136 | 196 | JSROOT.v7.drawMarker = drawMarker; |
| 197 | + JSROOT.v7.drawLegend = drawLegend; |
137 | 198 |
|
138 | 199 | return JSROOT; |
139 | 200 |
|
|
0 commit comments