Skip to content

Commit 107212e

Browse files
committed
Introduce appendPath
Very often used call to add svg:path and assign 'd' attribute
1 parent 340899a commit 107212e

File tree

7 files changed

+75
-108
lines changed

7 files changed

+75
-108
lines changed

modules/base/ObjectPainter.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ class ObjectPainter extends BasePainter {
337337
* @protected */
338338
setG(g) { this.draw_g = g; return g; }
339339

340+
/** @summary Append svg::path to G
341+
* @protected */
342+
appendPath(d) { return this.draw_g.append('svg:path').attr('d', d); }
343+
340344
/** @summary (re)creates svg:g element for object drawings
341345
* @desc either one attach svg:g to pad primitives (default)
342346
* or svg:g element created in specified frame layer ('main_layer' will be used when true specified)

modules/draw/TLinePainter.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ class TLinePainter extends ObjectPainter {
109109
redraw() {
110110
this.prepareDraw();
111111

112-
const elem = this.getG().append('svg:path')
113-
.attr('d', this.createPath())
112+
const elem = this.appendPath(this.createPath())
114113
.call(this.lineatt.func);
115114

116115
if (this.getObject()?.$do_not_draw)

modules/gui/utils.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ function addMoveHandler(painter, enabled = true, hover_handler = false) {
362362
return;
363363
evnt.sourceEvent.preventDefault();
364364
evnt.sourceEvent.stopPropagation();
365-
const pos = d3_pointer(evnt, this.draw_g.node());
365+
const pos = d3_pointer(evnt, this.getG().node());
366366
not_changed = true;
367367
if (this.moveStart)
368368
this.moveStart(pos[0], pos[1], evnt.sourceEvent);
@@ -383,7 +383,7 @@ function addMoveHandler(painter, enabled = true, hover_handler = false) {
383383
let arg = null;
384384
if (not_changed) {
385385
// if not changed - provide click position
386-
const pos = d3_pointer(evnt, this.draw_g.node());
386+
const pos = d3_pointer(evnt, this.getG().node());
387387
arg = { x: pos[0], y: pos[1], dbl: false };
388388
}
389389
this.getPadPainter()?.selectObjectPainter(this, arg);

modules/hist/RPavePainter.mjs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class RPavePainter extends RObjectPainter {
130130
this.v7AttrChange(changes, 'height', this.pave_height / rect.height);
131131
this.v7SendAttrChanges(changes, false); // do not invoke canvas update on the server
132132

133-
this.draw_g.selectChild('rect')
133+
this.getG().selectChild('rect')
134134
.attr('width', this.pave_width)
135135
.attr('height', this.pave_height);
136136

@@ -199,30 +199,23 @@ class RLegendPainter extends RPavePainter {
199199
}
200200

201201
if (entry.fFill && objp?.fillatt) {
202-
this.draw_g
203-
.append('svg:path')
204-
.attr('d', `M${Math.round(margin_x)},${Math.round(posy + stepy*0.1)}h${w4}v${Math.round(stepy*0.8)}h${-w4}z`)
205-
.call(objp.fillatt.func);
202+
this.appendPath(`M${Math.round(margin_x)},${Math.round(posy + stepy*0.1)}h${w4}v${Math.round(stepy*0.8)}h${-w4}z`)
203+
.call(objp.fillatt.func);
206204
}
207205

208206
if (entry.fLine && objp?.lineatt) {
209-
this.draw_g
210-
.append('svg:path')
211-
.attr('d', `M${Math.round(margin_x)},${Math.round(posy + stepy/2)}h${w4}`)
212-
.call(objp.lineatt.func);
207+
this.appendPath(`M${Math.round(margin_x)},${Math.round(posy + stepy/2)}h${w4}`)
208+
.call(objp.lineatt.func);
213209
}
214210

215211
if (entry.fError && objp?.lineatt) {
216-
this.draw_g
217-
.append('svg:path')
218-
.attr('d', `M${Math.round(margin_x + width/8)},${Math.round(posy + stepy*0.2)}v${Math.round(stepy*0.6)}`)
219-
.call(objp.lineatt.func);
212+
this.appendPath(`M${Math.round(margin_x + width/8)},${Math.round(posy + stepy*0.2)}v${Math.round(stepy*0.6)}`)
213+
.call(objp.lineatt.func);
220214
}
221215

222216
if (entry.fMarker && objp?.markeratt) {
223-
this.draw_g.append('svg:path')
224-
.attr('d', objp.markeratt.create(margin_x + width/8, posy + stepy/2))
225-
.call(objp.markeratt.func);
217+
this.appendPath(objp.markeratt.create(margin_x + width/8, posy + stepy/2))
218+
.call(objp.markeratt.func);
226219
}
227220

228221
posy += stepy;

modules/hist/TF1Painter.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ class TF1Painter extends TH1Painter {
305305
if (this.#use_saved_points)
306306
return super.processTooltipEvent(pnt);
307307

308-
let ttrect = this.draw_g?.selectChild('.tooltip_bin');
308+
let ttrect = this.getG()?.selectChild('.tooltip_bin');
309309

310-
if (!this.draw_g || !pnt) {
310+
if (!this.getG() || !pnt) {
311311
ttrect?.remove();
312312
return null;
313313
}
@@ -322,11 +322,11 @@ class TF1Painter extends TH1Painter {
322322
ttrect.remove();
323323
else {
324324
if (ttrect.empty()) {
325-
ttrect = this.draw_g.append('svg:circle')
326-
.attr('class', 'tooltip_bin')
327-
.style('pointer-events', 'none')
328-
.style('fill', 'none')
329-
.attr('r', (this.lineatt?.width ?? 1) + 4);
325+
ttrect = this.getG().append('svg:circle')
326+
.attr('class', 'tooltip_bin')
327+
.style('pointer-events', 'none')
328+
.style('fill', 'none')
329+
.attr('r', (this.lineatt?.width ?? 1) + 4);
330330
}
331331

332332
ttrect.attr('cx', pnt.x)

modules/hist/hist3d.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ function create3DScene(render3d, x3dscale, y3dscale, orthographic) {
529529

530530
this.mode3d = false;
531531

532-
if (this.draw_g)
532+
if (this.getG())
533533
this.createFrameG();
534534

535535
return;

0 commit comments

Comments
 (0)