forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTFramePainter.mjs
More file actions
2839 lines (2258 loc) · 101 KB
/
TFramePainter.mjs
File metadata and controls
2839 lines (2258 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { gStyle, settings, isBatchMode, isFunc, isStr, browser, clTAxis, kNoZoom } from '../core.mjs';
import { select as d3_select, pointer as d3_pointer, pointers as d3_pointers, drag as d3_drag } from '../d3.mjs';
import { getActivePad, ObjectPainter, EAxisBits } from '../base/ObjectPainter.mjs';
import { getSvgLineStyle } from '../base/TAttLineHandler.mjs';
import { TAxisPainter } from './TAxisPainter.mjs';
import { getElementRect, getAbsPosInCanvas } from '../base/BasePainter.mjs';
import { FontHandler } from '../base/FontHandler.mjs';
import { createMenu, closeMenu } from '../gui/menu.mjs';
import { detectRightButton, injectStyle } from '../gui/utils.mjs';
function setPainterTooltipEnabled(painter, on) {
if (!painter) return;
let fp = painter.getFramePainter();
if (isFunc(fp?.setTooltipEnabled)) {
fp.setTooltipEnabled(on);
fp.processFrameTooltipEvent(null);
}
// this is 3D control object
if (isFunc(painter.control?.setTooltipEnabled))
painter.control.setTooltipEnabled(on);
}
// global, allow single drag at once
let drag_rect = null, drag_kind = '', drag_painter = null;
/** @summary Check if dragging performed currently
* @private */
function is_dragging(painter, kind) {
return drag_rect && (drag_painter === painter) && (drag_kind === kind);
}
/** @summary Add drag for interactive rectangular elements for painter
* @private */
function addDragHandler(_painter, arg) {
if (!settings.MoveResize || isBatchMode()) return;
let painter = _painter, pp = painter.getPadPainter();
if (pp?._fast_drawing) return;
function makeResizeElements(group, handler) {
function addElement(cursor, d) {
let clname = 'js_' + cursor.replace(/[-]/g, '_'),
elem = group.selectChild('.' + clname);
if (elem.empty()) elem = group.append('path').classed(clname, true);
elem.style('opacity', 0).style('cursor', cursor).attr('d', d);
if (handler) elem.call(handler);
}
addElement('nw-resize', 'M2,2h15v-5h-20v20h5Z');
addElement('ne-resize', `M${arg.width - 2},2h-15v-5h20v20h-5 Z`);
addElement('sw-resize', `M2,${arg.height - 2}h15v5h-20v-20h5Z`);
addElement('se-resize', `M${arg.width - 2},${arg.height - 2}h-15v5h20v-20h-5Z`);
if (!arg.no_change_x) {
addElement('w-resize', `M-3,18h5v${Math.max(0, arg.height - 2 * 18)}h-5Z`);
addElement('e-resize', `M${arg.width + 3},18h-5v${Math.max(0, arg.height - 2 * 18)}h5Z`);
}
if (!arg.no_change_y) {
addElement('n-resize', `M18,-3v5h${Math.max(0, arg.width - 2 * 18)}v-5Z`);
addElement('s-resize', `M18,${arg.height + 3}v-5h${Math.max(0, arg.width - 2 * 18)}v5Z`);
}
}
const complete_drag = (newx, newy, newwidth, newheight) => {
drag_painter = null;
drag_kind = '';
if (drag_rect) {
drag_rect.remove();
drag_rect = null;
}
if (!painter.draw_g)
return false;
let oldx = arg.x, oldy = arg.y;
if (arg.minwidth && newwidth < arg.minwidth) newwidth = arg.minwidth;
if (arg.minheight && newheight < arg.minheight) newheight = arg.minheight;
let change_size = (newwidth !== arg.width) || (newheight !== arg.height),
change_pos = (newx !== oldx) || (newy !== oldy);
arg.x = newx; arg.y = newy; arg.width = newwidth; arg.height = newheight;
painter.draw_g.attr('transform', `translate(${newx},${newy})`);
setPainterTooltipEnabled(painter, true);
makeResizeElements(painter.draw_g);
if (change_size || change_pos) {
if (change_size && ('resize' in arg)) arg.resize(newwidth, newheight);
if (change_pos && ('move' in arg)) arg.move(newx, newy, newx - oldx, newy - oldy);
if (change_size || change_pos) {
if ('obj' in arg) {
let rect = pp.getPadRect();
arg.obj.fX1NDC = newx / rect.width;
arg.obj.fX2NDC = (newx + newwidth) / rect.width;
arg.obj.fY1NDC = 1 - (newy + newheight) / rect.height;
arg.obj.fY2NDC = 1 - newy / rect.height;
arg.obj.modified_NDC = true; // indicate that NDC was interactively changed, block in updated
}
if ('redraw' in arg) arg.redraw(arg);
}
}
return change_size || change_pos;
};
// add interactive styles when frame painter not there
if (_painter) {
let fp = _painter.getFramePainter();
if (!fp || fp.mode3d)
injectFrameStyle(_painter.draw_g);
}
let drag_move = d3_drag().subject(Object);
drag_move
.on('start', function(evnt) {
if (detectRightButton(evnt.sourceEvent) || drag_kind) return;
closeMenu(); // close menu
setPainterTooltipEnabled(painter, false); // disable tooltip
evnt.sourceEvent.preventDefault();
evnt.sourceEvent.stopPropagation();
let pad_rect = pp.getPadRect();
let handle = {
x: arg.x, y: arg.y, width: arg.width, height: arg.height,
acc_x1: arg.x, acc_y1: arg.y,
pad_w: pad_rect.width - arg.width,
pad_h: pad_rect.height - arg.height,
drag_tm: new Date(),
path: `v${arg.height}h${arg.width}v${-arg.height}z`
};
drag_painter = painter;
drag_kind = 'move';
drag_rect = d3_select(painter.draw_g.node().parentNode).append('path')
.classed('zoom', true)
.attr('d', `M${handle.acc_x1},${handle.acc_y1}${handle.path}`)
.style('cursor', 'move')
.style('pointer-events', 'none') // let forward double click to underlying elements
.property('drag_handle', handle);
}).on('drag', function(evnt) {
if (!is_dragging(painter, 'move')) return;
evnt.sourceEvent.preventDefault();
evnt.sourceEvent.stopPropagation();
let handle = drag_rect.property('drag_handle');
if (!arg.no_change_x)
handle.acc_x1 += evnt.dx;
if (!arg.no_change_y)
handle.acc_y1 += evnt.dy;
handle.x = Math.min(Math.max(handle.acc_x1, 0), handle.pad_w);
handle.y = Math.min(Math.max(handle.acc_y1, 0), handle.pad_h);
drag_rect.attr('d', `M${handle.x},${handle.y}${handle.path}`);
}).on('end', function(evnt) {
if (!is_dragging(painter, 'move')) return;
evnt.sourceEvent.preventDefault();
let handle = drag_rect.property('drag_handle');
if (complete_drag(handle.x, handle.y, arg.width, arg.height) === false) {
let spent = (new Date()).getTime() - handle.drag_tm.getTime();
if (arg.ctxmenu && (spent > 600) && painter.showContextMenu) {
let rrr = resize_se.node().getBoundingClientRect();
painter.showContextMenu('main', { clientX: rrr.left, clientY: rrr.top });
} else if (arg.canselect && (spent <= 600)) {
painter.getPadPainter()?.selectObjectPainter(painter);
}
}
});
let drag_resize = d3_drag().subject(Object);
drag_resize
.on('start', function(evnt) {
if (detectRightButton(evnt.sourceEvent) || drag_kind) return;
evnt.sourceEvent.stopPropagation();
evnt.sourceEvent.preventDefault();
setPainterTooltipEnabled(painter, false); // disable tooltip
let pad_rect = pp.getPadRect();
let handle = {
x: arg.x, y: arg.y, width: arg.width, height: arg.height,
acc_x1: arg.x, acc_y1: arg.y,
acc_x2: arg.x + arg.width, acc_y2: arg.y + arg.height,
pad_w: pad_rect.width, pad_h: pad_rect.height
};
drag_painter = painter;
drag_kind = 'resize';
drag_rect = d3_select(painter.draw_g.node().parentNode)
.append('rect')
.classed('zoom', true)
.style('cursor', d3_select(this).style('cursor'))
.attr('x', handle.acc_x1)
.attr('y', handle.acc_y1)
.attr('width', handle.acc_x2 - handle.acc_x1)
.attr('height', handle.acc_y2 - handle.acc_y1)
.property('drag_handle', handle);
}).on('drag', function(evnt) {
if (!is_dragging(painter, 'resize')) return;
evnt.sourceEvent.preventDefault();
evnt.sourceEvent.stopPropagation();
let handle = drag_rect.property('drag_handle'),
dx = evnt.dx, dy = evnt.dy, elem = d3_select(this);
if (arg.no_change_x) dx = 0;
if (arg.no_change_y) dy = 0;
if (elem.classed('js_nw_resize')) { handle.acc_x1 += dx; handle.acc_y1 += dy; }
else if (elem.classed('js_ne_resize')) { handle.acc_x2 += dx; handle.acc_y1 += dy; }
else if (elem.classed('js_sw_resize')) { handle.acc_x1 += dx; handle.acc_y2 += dy; }
else if (elem.classed('js_se_resize')) { handle.acc_x2 += dx; handle.acc_y2 += dy; }
else if (elem.classed('js_w_resize')) { handle.acc_x1 += dx; }
else if (elem.classed('js_n_resize')) { handle.acc_y1 += dy; }
else if (elem.classed('js_e_resize')) { handle.acc_x2 += dx; }
else if (elem.classed('js_s_resize')) { handle.acc_y2 += dy; }
let x1 = Math.max(0, handle.acc_x1), x2 = Math.min(handle.acc_x2, handle.pad_w),
y1 = Math.max(0, handle.acc_y1), y2 = Math.min(handle.acc_y2, handle.pad_h);
handle.x = Math.min(x1, x2);
handle.y = Math.min(y1, y2);
handle.width = Math.abs(x2 - x1);
handle.height = Math.abs(y2 - y1);
drag_rect.attr('x', handle.x).attr('y', handle.y).attr('width', handle.width).attr('height', handle.height);
}).on('end', function(evnt) {
if (!is_dragging(painter, 'resize')) return;
evnt.sourceEvent.preventDefault();
let handle = drag_rect.property('drag_handle');
complete_drag(handle.x, handle.y, handle.width, handle.height);
});
if (!arg.only_resize)
painter.draw_g.style('cursor', 'move').call(drag_move);
if (!arg.only_move)
makeResizeElements(painter.draw_g, drag_resize);
}
const TooltipHandler = {
/** @desc only canvas info_layer can be used while other pads can overlay
* @return layer where frame tooltips are shown */
hints_layer() {
let pp = this.getCanvPainter();
return pp ? pp.getLayerSvg('info_layer') : d3_select(null);
},
/** @return true if tooltip is shown, use to prevent some other action */
isTooltipShown() {
if (!this.tooltip_enabled || !this.isTooltipAllowed()) return false;
let hintsg = this.hints_layer().select('.objects_hints');
return hintsg.empty() ? false : hintsg.property('hints_pad') == this.getPadName();
},
setTooltipEnabled(enabled) {
if (enabled !== undefined) this.tooltip_enabled = enabled;
},
/** @summary central function which let show selected hints for the object */
processFrameTooltipEvent(pnt, evnt) {
if (pnt?.handler) {
// special use of interactive handler in the frame painter
let rect = this.draw_g ? this.draw_g.select('.main_layer') : null;
if (!rect || rect.empty()) {
pnt = null; // disable
} else if (pnt.touch && evnt) {
let pos = d3_pointers(evnt, rect.node());
pnt = (pos && pos.length == 1) ? { touch: true, x: pos[0][0], y: pos[0][1] } : null;
} else if (evnt) {
let pos = d3_pointer(evnt, rect.node());
pnt = { touch: false, x: pos[0], y: pos[1] };
}
}
let hints = [], nhints = 0, nexact = 0, maxlen = 0, lastcolor1 = 0, usecolor1 = false,
textheight = 11, hmargin = 3, wmargin = 3, hstep = 1.2,
frame_rect = this.getFrameRect(),
pp = this.getPadPainter(),
pad_width = pp.getPadWidth(),
font = new FontHandler(160, textheight),
disable_tootlips = !this.isTooltipAllowed() || !this.tooltip_enabled;
if (pnt && disable_tootlips) pnt.disabled = true; // indicate that highlighting is not required
if (pnt) pnt.painters = true; // get also painter
// collect tooltips from pad painter - it has list of all drawn objects
if (pp) hints = pp.processPadTooltipEvent(pnt);
if (pp?._deliver_webcanvas_events && pp?.is_active_pad && pnt && isFunc(pp?.deliverWebCanvasEvent))
pp.deliverWebCanvasEvent('move', frame_rect.x + pnt.x, frame_rect.y + pnt.y, hints);
if (pnt?.touch) textheight = 15;
for (let n = 0; n < hints.length; ++n) {
let hint = hints[n];
if (!hint) continue;
if (hint.painter && (hint.user_info !== undefined))
hint.painter.provideUserTooltip(hint.user_info);
if (!hint.lines || (hint.lines.length === 0)) {
hints[n] = null;
continue;
}
// check if fully duplicated hint already exists
for (let k = 0; k < n; ++k) {
let hprev = hints[k], diff = false;
if (!hprev || (hprev.lines.length !== hint.lines.length)) continue;
for (let l = 0; l < hint.lines.length && !diff; ++l)
if (hprev.lines[l] !== hint.lines[l]) diff = true;
if (!diff) { hints[n] = null; break; }
}
if (!hints[n]) continue;
nhints++;
if (hint.exact) nexact++;
hint.lines.forEach(line => { maxlen = Math.max(maxlen, line.length); });
hint.height = Math.round(hint.lines.length * textheight * hstep + 2 * hmargin - textheight * (hstep - 1));
if ((hint.color1 !== undefined) && (hint.color1 !== 'none')) {
if ((lastcolor1 !== 0) && (lastcolor1 !== hint.color1)) usecolor1 = true;
lastcolor1 = hint.color1;
}
}
let layer = this.hints_layer(),
hintsg = layer.select('.objects_hints'), // group with all tooltips
title = '', name = '', info = '',
hint = null, best_dist2 = 1e10, best_hint = null, show_only_best = nhints > 15,
coordinates = pnt ? Math.round(pnt.x) + ',' + Math.round(pnt.y) : '';
// try to select hint with exact match of the position when several hints available
for (let k = 0; k < (hints?.length || 0); ++k) {
if (!hints[k]) continue;
if (!hint) hint = hints[k];
// select exact hint if this is the only one
if (hints[k].exact && (nexact < 2) && (!hint || !hint.exact)) { hint = hints[k]; break; }
if (!pnt || (hints[k].x === undefined) || (hints[k].y === undefined)) continue;
let dist2 = (pnt.x - hints[k].x) ** 2 + (pnt.y - hints[k].y) ** 2;
if (dist2 < best_dist2) { best_dist2 = dist2; best_hint = hints[k]; }
}
if ((!hint || !hint.exact) && (best_dist2 < 400)) hint = best_hint;
if (hint) {
name = (hint.lines && hint.lines.length > 1) ? hint.lines[0] : hint.name;
title = hint.title || '';
info = hint.line;
if (!info && hint.lines) info = hint.lines.slice(1).join(' ');
}
this.showObjectStatus(name, title, info, coordinates);
// end of closing tooltips
if (!pnt || disable_tootlips || (hints.length === 0) || (maxlen === 0) || (show_only_best && !best_hint)) {
hintsg.remove();
return;
}
// we need to set pointer-events=none for all elements while hints
// placed in front of so-called interactive rect in frame, used to catch mouse events
if (hintsg.empty())
hintsg = layer.append('svg:g')
.attr('class', 'objects_hints')
.style('pointer-events', 'none');
let frame_shift = { x: 0, y: 0 }, trans = frame_rect.transform || '';
if (!pp.iscan) {
frame_shift = getAbsPosInCanvas(this.getPadSvg(), frame_shift);
trans = `translate(${frame_shift.x},${frame_shift.y}) ${trans}`;
}
// copy transform attributes from frame itself
hintsg.attr('transform', trans)
.property('last_point', pnt)
.property('hints_pad', this.getPadName());
let viewmode = hintsg.property('viewmode') || '',
actualw = 0, posx = pnt.x + frame_rect.hint_delta_x;
if (show_only_best || (nhints == 1)) {
viewmode = 'single';
posx += 15;
} else {
// if there are many hints, place them left or right
let bleft = 0.5, bright = 0.5;
if (viewmode == 'left')
bright = 0.7;
else if (viewmode == 'right')
bleft = 0.3;
if (posx <= bleft * frame_rect.width) {
viewmode = 'left';
posx = 20;
} else if (posx >= bright * frame_rect.width) {
viewmode = 'right';
posx = frame_rect.width - 60;
} else {
posx = hintsg.property('startx');
}
}
if (viewmode !== hintsg.property('viewmode')) {
hintsg.property('viewmode', viewmode);
hintsg.selectAll('*').remove();
}
let curry = 10, // normal y coordinate
gapy = 10, // y coordinate, taking into account all gaps
gapminx = -1111, gapmaxx = -1111,
minhinty = -frame_shift.y,
cp = this.getCanvPainter(),
maxhinty = cp.getPadHeight() - frame_rect.y - frame_shift.y;
const FindPosInGap = y => {
for (let n = 0; (n < hints.length) && (y < maxhinty); ++n) {
let hint = hints[n];
if (!hint) continue;
if ((hint.y >= y - 5) && (hint.y <= y + hint.height + 5)) {
y = hint.y + 10;
n = -1;
}
}
return y;
};
for (let n = 0; n < hints.length; ++n) {
let hint = hints[n],
group = hintsg.select('.painter_hint_' + n);
if (show_only_best && (hint !== best_hint)) hint = null;
if (hint === null) {
group.remove();
continue;
}
let was_empty = group.empty();
if (was_empty)
group = hintsg.append('svg:svg')
.attr('class', 'painter_hint_' + n)
.attr('opacity', 0) // use attribute, not style to make animation with d3.transition()
.style('overflow', 'hidden')
.style('pointer-events', 'none');
if (viewmode == 'single') {
curry = pnt.touch ? (pnt.y - hint.height - 5) : Math.min(pnt.y + 15, maxhinty - hint.height - 3) + frame_rect.hint_delta_y;
} else {
gapy = FindPosInGap(gapy);
if ((gapminx === -1111) && (gapmaxx === -1111)) gapminx = gapmaxx = hint.x;
gapminx = Math.min(gapminx, hint.x);
gapmaxx = Math.min(gapmaxx, hint.x);
}
group.attr('x', posx)
.attr('y', curry)
.property('curry', curry)
.property('gapy', gapy);
curry += hint.height + 5;
gapy += hint.height + 5;
if (!was_empty)
group.selectAll('*').remove();
group.attr('width', 60)
.attr('height', hint.height);
let r = group.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', 60)
.attr('height', hint.height)
.style('fill', 'lightgrey')
.style('pointer-events', 'none');
if (nhints > 1) {
let col = usecolor1 ? hint.color1 : hint.color2;
if (col && (col !== 'none'))
r.style('stroke', col);
}
r.attr('stroke-width', hint.exact ? 3 : 1);
for (let l = 0; l < (hint.lines ? hint.lines.length : 0); l++)
if (hint.lines[l] !== null) {
let txt = group.append('svg:text')
.attr('text-anchor', 'start')
.attr('x', wmargin)
.attr('y', hmargin + l * textheight * hstep)
.attr('dy', '.8em')
.style('fill', 'black')
.style('pointer-events', 'none')
.call(font.func)
.text(hint.lines[l]);
let box = getElementRect(txt, 'bbox');
actualw = Math.max(actualw, box.width);
}
function translateFn() {
// We only use 'd', but list d,i,a as params just to show can have them as params.
// Code only really uses d and t.
return function(/*d, i, a*/) {
return function(t) {
return t < 0.8 ? '0' : (t - 0.8) * 5;
};
};
}
if (was_empty)
if (settings.TooltipAnimation > 0)
group.transition().duration(settings.TooltipAnimation).attrTween('opacity', translateFn());
else
group.attr('opacity', 1);
}
actualw += 2 * wmargin;
let svgs = hintsg.selectAll('svg');
if ((viewmode == 'right') && (posx + actualw > frame_rect.width - 20)) {
posx = frame_rect.width - actualw - 20;
svgs.attr('x', posx);
}
if ((viewmode == 'single') && (posx + actualw > pad_width - frame_rect.x) && (posx > actualw + 20)) {
posx -= (actualw + 20);
svgs.attr('x', posx);
}
// if gap not very big, apply gapy coordinate to open view on the histogram
if ((viewmode !== 'single') && (gapy < maxhinty) && (gapy !== curry)) {
if ((gapminx <= posx + actualw + 5) && (gapmaxx >= posx - 5))
svgs.attr('y', function() { return d3_select(this).property('gapy'); });
} else if ((viewmode !== 'single') && (curry > maxhinty)) {
let shift = Math.max((maxhinty - curry - 10), minhinty);
if (shift < 0)
svgs.attr('y', function() { return d3_select(this).property('curry') + shift; });
}
if (actualw > 10)
svgs.attr('width', actualw)
.select('rect').attr('width', actualw);
hintsg.property('startx', posx);
if (cp._highlight_connect && isFunc(cp.processHighlightConnect))
cp.processHighlightConnect(hints);
},
/** @summary Assigns tooltip methods */
assign(painter) {
Object.assign(painter, this, { tooltip_enabled: true });
}
} // TooltipHandler
function injectFrameStyle(draw_g) {
injectStyle(`
.jsroot rect.h1bin { stroke: #4572A7; fill: #4572A7; opacity: 0; }
.jsroot rect.zoom { stroke: steelblue; fill-opacity: 0.1; }
.jsroot path.zoom { stroke: steelblue; fill-opacity: 0.1; }
.jsroot svg:not(:root) { overflow: hidden; }`, draw_g.node());
}
/** @summary Set of frame interactivity methods
* @private */
const FrameInteractive = {
/** @summary Adding basic interactivity */
addBasicInteractivity() {
TooltipHandler.assign(this);
if (!this._frame_rotate && !this._frame_fixpos)
addDragHandler(this, { obj: this, x: this._frame_x, y: this._frame_y, width: this.getFrameWidth(), height: this.getFrameHeight(),
only_resize: true, minwidth: 20, minheight: 20, redraw: () => this.sizeChanged() });
injectFrameStyle(this.draw_g);
let main_svg = this.draw_g.select('.main_layer');
main_svg.style('pointer-events','visibleFill')
.property('handlers_set', 0);
let pp = this.getPadPainter(),
handlers_set = pp?._fast_drawing ? 0 : 1;
if (main_svg.property('handlers_set') != handlers_set) {
let close_handler = handlers_set ? this.processFrameTooltipEvent.bind(this, null) : null,
mouse_handler = handlers_set ? this.processFrameTooltipEvent.bind(this, { handler: true, touch: false }) : null;
main_svg.property('handlers_set', handlers_set)
.on('mouseenter', mouse_handler)
.on('mousemove', mouse_handler)
.on('mouseleave', close_handler);
if (browser.touches) {
let touch_handler = handlers_set ? this.processFrameTooltipEvent.bind(this, { handler: true, touch: true }) : null;
main_svg.on('touchstart', touch_handler)
.on('touchmove', touch_handler)
.on('touchend', close_handler)
.on('touchcancel', close_handler);
}
}
main_svg.attr('x', 0)
.attr('y', 0)
.attr('width', this.getFrameWidth())
.attr('height', this.getFrameHeight());
let hintsg = this.hints_layer().select('.objects_hints');
// if tooltips were visible before, try to reconstruct them after short timeout
if (!hintsg.empty() && this.isTooltipAllowed() && (hintsg.property('hints_pad') == this.getPadName()))
setTimeout(this.processFrameTooltipEvent.bind(this, hintsg.property('last_point'), null), 10);
},
/** @summary Add interactive handlers */
async addFrameInteractivity(for_second_axes) {
let pp = this.getPadPainter(),
svg = this.getFrameSvg();
if (pp?._fast_drawing || svg.empty())
return this;
if (for_second_axes) {
// add extra handlers for second axes
let svg_x2 = svg.selectAll('.x2axis_container'),
svg_y2 = svg.selectAll('.y2axis_container');
if (settings.ContextMenu) {
svg_x2.on('contextmenu', evnt => this.showContextMenu('x2', evnt));
svg_y2.on('contextmenu', evnt => this.showContextMenu('y2', evnt));
}
svg_x2.on('mousemove', evnt => this.showAxisStatus('x2', evnt));
svg_y2.on('mousemove', evnt => this.showAxisStatus('y2', evnt));
return this;
}
let svg_x = svg.selectAll('.xaxis_container'),
svg_y = svg.selectAll('.yaxis_container');
this.can_zoom_x = this.can_zoom_y = settings.Zooming;
if (pp?.options) {
if (pp.options.NoZoomX) this.can_zoom_x = false;
if (pp.options.NoZoomY) this.can_zoom_y = false;
}
if (!svg.property('interactive_set')) {
this.addFrameKeysHandler();
this.last_touch = new Date(0);
this.zoom_kind = 0; // 0 - none, 1 - XY, 2 - only X, 3 - only Y, (+100 for touches)
this.zoom_rect = null;
this.zoom_origin = null; // original point where zooming started
this.zoom_curr = null; // current point for zooming
this.touch_cnt = 0;
}
if (settings.Zooming && !this.projection) {
if (settings.ZoomMouse) {
svg.on('mousedown', this.startRectSel.bind(this));
svg.on('dblclick', this.mouseDoubleClick.bind(this));
}
if (settings.ZoomWheel)
svg.on('wheel', this.mouseWheel.bind(this));
}
if (browser.touches && ((settings.Zooming && settings.ZoomTouch && !this.projection) || settings.ContextMenu))
svg.on('touchstart', this.startTouchZoom.bind(this));
if (settings.ContextMenu) {
if (browser.touches) {
svg_x.on('touchstart', this.startTouchMenu.bind(this,'x'));
svg_y.on('touchstart', this.startTouchMenu.bind(this,'y'));
}
svg.on('contextmenu', evnt => this.showContextMenu('', evnt));
svg_x.on('contextmenu', evnt => this.showContextMenu('x', evnt));
svg_y.on('contextmenu', evnt => this.showContextMenu('y', evnt));
}
svg_x.on('mousemove', evnt => this.showAxisStatus('x', evnt));
svg_y.on('mousemove', evnt => this.showAxisStatus('y', evnt));
svg.property('interactive_set', true);
return this;
},
/** @summary Add keys handler */
addFrameKeysHandler() {
if (this.keys_handler || (typeof window == 'undefined')) return;
this.keys_handler = evnt => this.processKeyPress(evnt);
window.addEventListener('keydown', this.keys_handler, false);
},
/** @summary Handle key press */
processKeyPress(evnt) {
const allowed = ['PageUp', 'PageDown', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown', 'PrintScreen', '*'];
let main = this.selectDom(),
key = evnt.key,
pp = this.getPadPainter();
if (!settings.HandleKeys || main.empty() || (this.enabledKeys === false) ||
(getActivePad() !== pp) || (allowed.indexOf(key) < 0)) return false;
if (evnt.shiftKey) key = 'Shift ' + key;
if (evnt.altKey) key = 'Alt ' + key;
if (evnt.ctrlKey) key = 'Ctrl ' + key;
let zoom = { name: 'x', dleft: 0, dright: 0 };
switch (key) {
case 'ArrowLeft': zoom.dleft = -1; zoom.dright = 1; break;
case 'ArrowRight': zoom.dleft = 1; zoom.dright = -1; break;
case 'Ctrl ArrowLeft': zoom.dleft = zoom.dright = -1; break;
case 'Ctrl ArrowRight': zoom.dleft = zoom.dright = 1; break;
case 'ArrowUp': zoom.name = 'y'; zoom.dleft = 1; zoom.dright = -1; break;
case 'ArrowDown': zoom.name = 'y'; zoom.dleft = -1; zoom.dright = 1; break;
case 'Ctrl ArrowUp': zoom.name = 'y'; zoom.dleft = zoom.dright = 1; break;
case 'Ctrl ArrowDown': zoom.name = 'y'; zoom.dleft = zoom.dright = -1; break;
}
if (zoom.dleft || zoom.dright) {
if (!settings.Zooming) return false;
// in 3dmode with orbit control ignore simple arrows
if (this.mode3d && (key.indexOf('Ctrl') !== 0)) return false;
this.analyzeMouseWheelEvent(null, zoom, 0.5);
this.zoom(zoom.name, zoom.min, zoom.max);
if (zoom.changed) this.zoomChangedInteractive(zoom.name, true);
evnt.stopPropagation();
evnt.preventDefault();
} else {
let func = pp?.findPadButton(key);
if (func) {
pp.clickPadButton(func);
evnt.stopPropagation();
evnt.preventDefault();
}
}
return true; // just process any key press
},
/** @summary Function called when frame is clicked and object selection can be performed
* @desc such event can be used to select */
processFrameClick(pnt, dblckick) {
let pp = this.getPadPainter();
if (!pp) return;
pnt.painters = true; // provide painters reference in the hints
pnt.disabled = true; // do not invoke graphics
// collect tooltips from pad painter - it has list of all drawn objects
let hints = pp.processPadTooltipEvent(pnt), exact = null, res;
for (let k = 0; (k < hints.length) && !exact; ++k)
if (hints[k] && hints[k].exact)
exact = hints[k];
if (exact) {
let handler = dblckick ? this._dblclick_handler : this._click_handler;
if (handler) res = handler(exact.user_info, pnt);
}
if (!dblckick)
pp.selectObjectPainter(exact ? exact.painter : this,
{ x: pnt.x + (this._frame_x || 0), y: pnt.y + (this._frame_y || 0) });
return res;
},
/** @summary Start mouse rect zooming */
startRectSel(evnt) {
// ignore when touch selection is activated
if (this.zoom_kind > 100) return;
// ignore all events from non-left button
if ((evnt.which || evnt.button) !== 1) return;
evnt.preventDefault();
let frame = this.getFrameSvg(),
pos = d3_pointer(evnt, frame.node());
this.clearInteractiveElements();
let w = this.getFrameWidth(), h = this.getFrameHeight();
this.zoom_lastpos = pos;
this.zoom_curr = [ Math.max(0, Math.min(w, pos[0])),
Math.max(0, Math.min(h, pos[1])) ];
this.zoom_origin = [0,0];
this.zoom_second = false;
if ((pos[0] < 0) || (pos[0] > w)) {
this.zoom_second = (pos[0] > w) && this.y2_handle;
this.zoom_kind = 3; // only y
this.zoom_origin[1] = this.zoom_curr[1];
this.zoom_curr[0] = w;
this.zoom_curr[1] += 1;
} else if ((pos[1] < 0) || (pos[1] > h)) {
this.zoom_second = (pos[1] < 0) && this.x2_handle;
this.zoom_kind = 2; // only x
this.zoom_origin[0] = this.zoom_curr[0];
this.zoom_curr[0] += 1;
this.zoom_curr[1] = h;
} else {
this.zoom_kind = 1; // x and y
this.zoom_origin[0] = this.zoom_curr[0];
this.zoom_origin[1] = this.zoom_curr[1];
}
d3_select(window).on('mousemove.zoomRect', this.moveRectSel.bind(this))
.on('mouseup.zoomRect', this.endRectSel.bind(this), true);
this.zoom_rect = null;
// disable tooltips in frame painter
setPainterTooltipEnabled(this, false);
evnt.stopPropagation();
if (this.zoom_kind != 1)
setTimeout(() => this.startLabelsMove(), 500);
},
/** @summary Starts labels move */
startLabelsMove() {
if (this.zoom_rect) return;
let handle = (this.zoom_kind == 2) ? this.x_handle : this.y_handle;
if (!handle || !isFunc(handle.processLabelsMove) || !this.zoom_lastpos) return;
if (handle.processLabelsMove('start', this.zoom_lastpos))
this.zoom_labels = handle;
},
/** @summary Process mouse rect zooming */
moveRectSel(evnt) {
if ((this.zoom_kind == 0) || (this.zoom_kind > 100)) return;
evnt.preventDefault();
let m = d3_pointer(evnt, this.getFrameSvg().node());
if (this.zoom_labels)
return this.zoom_labels.processLabelsMove('move', m);
this.zoom_lastpos[0] = m[0];
this.zoom_lastpos[1] = m[1];
m[0] = Math.max(0, Math.min(this.getFrameWidth(), m[0]));
m[1] = Math.max(0, Math.min(this.getFrameHeight(), m[1]));
switch (this.zoom_kind) {
case 1: this.zoom_curr[0] = m[0]; this.zoom_curr[1] = m[1]; break;
case 2: this.zoom_curr[0] = m[0]; break;
case 3: this.zoom_curr[1] = m[1]; break;
}
let x = Math.min(this.zoom_origin[0], this.zoom_curr[0]),
y = Math.min(this.zoom_origin[1], this.zoom_curr[1]),
w = Math.abs(this.zoom_curr[0] - this.zoom_origin[0]),
h = Math.abs(this.zoom_curr[1] - this.zoom_origin[1]);
if (!this.zoom_rect) {
// ignore small changes, can be switching to labels move
if ((this.zoom_kind != 1) && ((w < 2) || (h < 2))) return;
this.zoom_rect = this.getFrameSvg()
.append('rect')
.attr('class', 'zoom')
.style('pointer-events','none');
}
this.zoom_rect.attr('x', x).attr('y', y).attr('width', w).attr('height', h);
},
/** @summary Finish mouse rect zooming */
endRectSel(evnt) {
if ((this.zoom_kind == 0) || (this.zoom_kind > 100)) return;
evnt.preventDefault();
d3_select(window).on('mousemove.zoomRect', null)
.on('mouseup.zoomRect', null);
let m = d3_pointer(evnt, this.getFrameSvg().node()), kind = this.zoom_kind;
if (this.zoom_labels) {
this.zoom_labels.processLabelsMove('stop', m);
} else {
let changed = [this.can_zoom_x, this.can_zoom_y];
m[0] = Math.max(0, Math.min(this.getFrameWidth(), m[0]));
m[1] = Math.max(0, Math.min(this.getFrameHeight(), m[1]));
switch (this.zoom_kind) {
case 1: this.zoom_curr[0] = m[0]; this.zoom_curr[1] = m[1]; break;
case 2: this.zoom_curr[0] = m[0]; changed[1] = false; break; // only X
case 3: this.zoom_curr[1] = m[1]; changed[0] = false; break; // only Y
}
let xmin, xmax, ymin, ymax, isany = false,
idx = this.swap_xy ? 1 : 0, idy = 1 - idx,
namex = 'x', namey = 'y';
if (changed[idx] && (Math.abs(this.zoom_curr[idx] - this.zoom_origin[idx]) > 10)) {
if (this.zoom_second && (this.zoom_kind == 2)) namex = 'x2';
xmin = Math.min(this.revertAxis(namex, this.zoom_origin[idx]), this.revertAxis(namex, this.zoom_curr[idx]));
xmax = Math.max(this.revertAxis(namex, this.zoom_origin[idx]), this.revertAxis(namex, this.zoom_curr[idx]));
isany = true;
}
if (changed[idy] && (Math.abs(this.zoom_curr[idy] - this.zoom_origin[idy]) > 10)) {
if (this.zoom_second && (this.zoom_kind == 3)) namey = 'y2';
ymin = Math.min(this.revertAxis(namey, this.zoom_origin[idy]), this.revertAxis(namey, this.zoom_curr[idy]));
ymax = Math.max(this.revertAxis(namey, this.zoom_origin[idy]), this.revertAxis(namey, this.zoom_curr[idy]));
isany = true;
}
if (namex == 'x2') {
this.zoomChangedInteractive(namex, true);
this.zoomSingle(namex, xmin, xmax);
kind = 0;
} else if (namey == 'y2') {
this.zoomChangedInteractive(namey, true);
this.zoomSingle(namey, ymin, ymax);
kind = 0;
} else if (isany) {
this.zoomChangedInteractive('x', true);
this.zoomChangedInteractive('y', true);
this.zoom(xmin, xmax, ymin, ymax);
kind = 0;
}
}
let pnt = (kind===1) ? { x: this.zoom_origin[0], y: this.zoom_origin[1] } : null;
this.clearInteractiveElements();
// if no zooming was done, select active object instead
switch (kind) {
case 1:
this.processFrameClick(pnt);
break;
case 2: