@@ -18,56 +18,57 @@ import { getRootColors } from './colors.mjs';
18
18
19
19
class ObjectPainter extends BasePainter {
20
20
21
+ #pad_name; // pad name where object is drawn
21
22
#draw_object; // drawn object
22
23
#main_painter; // WeakRef to main painter in the pad
23
24
#primary_ref; // reference of primary painter - if any
24
25
#secondary_id; // id of this painter in relation to primary painter
25
26
#options_store; // stored draw options used to check changes
26
27
#user_tooltip_handler; // configured user tooltip handler
27
28
#user_tooltip_timeout; // timeout configured with tooltip handler
29
+ #user_toottip_handle; // timeout handle processing user tooltip
30
+ #user_context_menu; // function for user context menu
28
31
#special_draw_area; // current special draw area like projection
32
+ #root_colors; // custom colors list
29
33
30
34
/** @summary constructor
31
35
* @param {object|string } dom - dom element or identifier or pad painter
32
36
* @param {object } obj - object to draw
33
37
* @param {string } [opt] - object draw options */
34
38
constructor ( dom , obj , opt ) {
35
- let pp = null ;
36
- if ( isFunc ( dom ?. forEachPainterInPad ) && ( dom ?. this_pad_name !== undefined ) ) {
37
- pp = dom ;
38
- dom = pp . getDom ( ) ;
39
+ let pad_name = '' ;
40
+ if ( isFunc ( dom ?. forEachPainterInPad ) ) {
41
+ pad_name = dom . this_pad_name ;
42
+ dom = dom . getDom ( ) ;
39
43
}
40
44
41
45
super ( dom ) ;
42
46
43
47
// this.draw_g = undefined; // container for all drawn objects
44
- this . pad_name = pp ?. this_pad_name ?? '' ; // name of pad where object is drawn
48
+ this . setPadName ( pad_name ) ; // name of pad where object is drawn
45
49
this . assignObject ( obj ) ;
46
50
if ( isStr ( opt ) )
47
51
this . options = { original : opt } ;
48
52
}
49
53
50
54
/** @summary Assign object to the painter
51
55
* @protected */
52
- assignObject ( obj ) {
53
- this . #draw_object = isObject ( obj ) ? obj : null ;
54
- }
56
+ assignObject ( obj ) { this . #draw_object = isObject ( obj ) ? obj : null ; }
55
57
56
58
/** @summary Returns drawn object */
57
59
getObject ( ) { return this . #draw_object; }
58
60
59
61
/** @summary Assigns pad name where element will be drawn
60
62
* @desc Should happened before first draw of element is performed, only for special use case
61
63
* @param {string } [pad_name] - on which sub-pad element should be draw, if not specified - use current
62
- * @protected
63
- * @deprecated to be removed in v8 */
64
+ * @protected */
64
65
setPadName ( pad_name ) {
65
66
// console.warn('setPadName is deprecated, to be removed in v8');
66
- this . pad_name = isStr ( pad_name ) ? pad_name : '' ;
67
+ this . # pad_name = isStr ( pad_name ) ? pad_name : '' ;
67
68
}
68
69
69
70
/** @summary Returns pad name where object is drawn */
70
- getPadName ( ) { return this . pad_name || '' ; }
71
+ getPadName ( ) { return this . # pad_name || '' ; }
71
72
72
73
/** @summary Indicates that drawing runs in batch mode
73
74
* @private */
@@ -88,12 +89,12 @@ class ObjectPainter extends BasePainter {
88
89
89
90
if ( this . isMainPainter ( ) ) {
90
91
const pp = this . getPadPainter ( ) ;
91
- if ( ! pp || pp . _auto_canvas )
92
+ if ( ! pp || pp . isCanvas ( 'auto' ) )
92
93
keep_origin = false ;
93
94
}
94
95
95
96
// cleanup all existing references
96
- delete this . pad_name ;
97
+ this . # pad_name = undefined ;
97
98
this . #main_painter = null ;
98
99
this . #draw_object = null ;
99
100
delete this . snapid ;
@@ -105,7 +106,7 @@ class ObjectPainter extends BasePainter {
105
106
delete this . fillatt ;
106
107
delete this . lineatt ;
107
108
delete this . markeratt ;
108
- delete this . _root_colors ;
109
+ this . #root_colors = undefined ;
109
110
delete this . options ;
110
111
this . #options_store = undefined ;
111
112
@@ -249,30 +250,36 @@ class ObjectPainter extends BasePainter {
249
250
return this . getObjectName ( ) || this . getClassName ( ) || '' ;
250
251
}
251
252
253
+ /** @summary Set colors list
254
+ * @protected */
255
+ setColors ( lst ) { this . #root_colors = lst ; }
256
+
257
+ /** @summary Return colors list
258
+ * @protected */
259
+ getColors ( force ) {
260
+ if ( ! this . #root_colors && force )
261
+ this . setColors ( this . getCanvPainter ( ) ?. getColors ( ) || getRootColors ( ) ) ;
262
+ return this . #root_colors;
263
+ }
264
+
252
265
/** @summary returns color from current list of colors
253
266
* @desc First checks canvas painter and then just access global list of colors
254
267
* @param {number } indx - color index
255
268
* @return {string } with SVG color name or rgb()
256
269
* @protected */
257
- getColor ( indx ) {
258
- if ( ! this . _root_colors )
259
- this . _root_colors = this . getCanvPainter ( ) ?. _root_colors || getRootColors ( ) ;
260
-
261
- return this . _root_colors [ indx ] ;
262
- }
270
+ getColor ( indx ) { return this . getColors ( true ) [ indx ] ; }
263
271
264
272
/** @summary Add color to list of colors
265
273
* @desc Returned color index can be used as color number in all other draw functions
266
274
* @return {number } new color index
267
275
* @protected */
268
276
addColor ( color ) {
269
- if ( ! this . _root_colors )
270
- this . _root_colors = this . getCanvPainter ( ) ?. _root_colors || getRootColors ( ) ;
271
- const indx = this . _root_colors . indexOf ( color ) ;
277
+ const lst = this . getColors ( true ) ,
278
+ indx = lst . indexOf ( color ) ;
272
279
if ( indx >= 0 )
273
280
return indx ;
274
- this . _root_colors . push ( color ) ;
275
- return this . _root_colors . length - 1 ;
281
+ lst . push ( color ) ;
282
+ return lst . length - 1 ;
276
283
}
277
284
278
285
/** @summary returns tooltip allowed flag
@@ -386,23 +393,13 @@ class ObjectPainter extends BasePainter {
386
393
* @protected */
387
394
getPadSvg ( pad_name ) {
388
395
if ( pad_name === undefined )
389
- pad_name = this . pad_name ;
396
+ pad_name = this . getPadName ( ) ;
390
397
391
- let c = this . getCanvSvg ( ) ;
398
+ const c = this . getCanvSvg ( ) ;
392
399
if ( ! pad_name || c . empty ( ) )
393
400
return c ;
394
401
395
- const cp = c . property ( 'pad_painter' ) ;
396
- if ( cp ?. pads_cache && cp . pads_cache [ pad_name ] )
397
- return d3_select ( cp . pads_cache [ pad_name ] ) ;
398
-
399
- c = c . select ( '.primitives_layer .__root_pad_' + pad_name ) ;
400
- if ( cp ) {
401
- if ( ! cp . pads_cache )
402
- cp . pads_cache = { } ;
403
- cp . pads_cache [ pad_name ] = c . node ( ) ;
404
- }
405
- return c ;
402
+ return c . select ( '.primitives_layer .__root_pad_' + pad_name ) ;
406
403
}
407
404
408
405
/** @summary Assign secondary id
@@ -490,20 +487,20 @@ class ObjectPainter extends BasePainter {
490
487
const func = { isndc, nornd } ,
491
488
use_frame = this . draw_g ?. property ( 'in_frame' ) ;
492
489
if ( use_frame || ( use_frame_coordinates && ! isndc ) )
493
- func . main = this . getFramePainter ( ) ;
494
- if ( func . main ?. grx && func . main ?. gry ) {
495
- func . x0 = ( use_frame_coordinates && ! isndc ) ? func . main . getFrameX ( ) : 0 ;
496
- func . y0 = ( use_frame_coordinates && ! isndc ) ? func . main . getFrameY ( ) : 0 ;
490
+ func . fp = this . getFramePainter ( ) ;
491
+ if ( func . fp ?. grx && func . fp ?. gry ) {
492
+ func . x0 = ( use_frame_coordinates && ! isndc ) ? func . fp . getFrameX ( ) : 0 ;
493
+ func . y0 = ( use_frame_coordinates && ! isndc ) ? func . fp . getFrameY ( ) : 0 ;
497
494
if ( nornd ) {
498
- func . x = function ( x ) { return this . x0 + this . main . grx ( x ) ; } ;
499
- func . y = function ( y ) { return this . y0 + this . main . gry ( y ) ; } ;
495
+ func . x = function ( x ) { return this . x0 + this . fp . grx ( x ) ; } ;
496
+ func . y = function ( y ) { return this . y0 + this . fp . gry ( y ) ; } ;
500
497
} else {
501
- func . x = function ( x ) { return this . x0 + Math . round ( this . main . grx ( x ) ) ; } ;
502
- func . y = function ( y ) { return this . y0 + Math . round ( this . main . gry ( y ) ) ; } ;
498
+ func . x = function ( x ) { return this . x0 + Math . round ( this . fp . grx ( x ) ) ; } ;
499
+ func . y = function ( y ) { return this . y0 + Math . round ( this . fp . gry ( y ) ) ; } ;
503
500
}
504
501
} else if ( ! use_frame ) {
505
502
const pp = this . getPadPainter ( ) ;
506
- if ( ! isndc ) func . pad = pp ?. getRootPad ( true ) ; // need for NDC conversion
503
+ func . pad = isndc ? null : pp ?. getRootPad ( true ) ; // need for NDC conversion
507
504
func . padw = pp ?. getPadWidth ( ) ?? 10 ;
508
505
func . x = function ( value ) {
509
506
if ( this . pad ) {
@@ -969,7 +966,7 @@ class ObjectPainter extends BasePainter {
969
966
. property ( 'text_factor' , 0 )
970
967
. property ( 'max_text_width' , 0 ) // keep maximal text width, use it later
971
968
. property ( 'max_font_size' , max_font_size )
972
- . property ( '_fast_drawing' , this . getPadPainter ( ) ?. _fast_drawing ?? false ) ;
969
+ . property ( '_fast_drawing' , this . getPadPainter ( ) ?. isFastDrawing ( ) ?? false ) ;
973
970
974
971
if ( draw_g . property ( '_fast_drawing' ) )
975
972
draw_g . property ( '_font_too_small' , ( max_font_size && ( max_font_size < 5 ) ) || ( font . size < 4 ) ) ;
@@ -1371,17 +1368,14 @@ class ObjectPainter extends BasePainter {
1371
1368
* Function should return promise with menu when items are filled
1372
1369
* @param {function } fillmenu_func - function to fill custom context menu for object */
1373
1370
configureUserContextMenu ( fillmenu_func ) {
1374
- if ( ! fillmenu_func || ! isFunc ( fillmenu_func ) )
1375
- delete this . _userContextMenuFunc ;
1376
- else
1377
- this . _userContextMenuFunc = fillmenu_func ;
1371
+ this . #user_context_menu = isFunc ( fillmenu_func ) ? fillmenu_func : undefined ;
1378
1372
}
1379
1373
1380
1374
/** @summary Fill object menu in web canvas
1381
1375
* @private */
1382
1376
async fillObjectExecMenu ( menu , kind ) {
1383
- if ( isFunc ( this . _userContextMenuFunc ) )
1384
- return this . _userContextMenuFunc ( menu , kind ) ;
1377
+ if ( isFunc ( this . #user_context_menu ) )
1378
+ return this . #user_context_menu ( menu , kind ) ;
1385
1379
1386
1380
const canvp = this . getCanvPainter ( ) ;
1387
1381
@@ -1421,8 +1415,8 @@ class ObjectPainter extends BasePainter {
1421
1415
}
1422
1416
1423
1417
menu . showMethodArgsDialog ( item ) . then ( args => {
1424
- if ( ! args ) return ;
1425
- if ( execp . executeMenuCommand ( item , args ) ) return ;
1418
+ if ( ! args || execp . executeMenuCommand ( item , args ) )
1419
+ return ;
1426
1420
1427
1421
const exec = item . fExec . slice ( 0 , item . fExec . length - 1 ) + args + ')' ;
1428
1422
if ( cp ?. v7canvas )
@@ -1557,17 +1551,17 @@ class ObjectPainter extends BasePainter {
1557
1551
if ( this . #user_tooltip_timeout <= 0 )
1558
1552
return this . #user_tooltip_handler( data ) ;
1559
1553
1560
- if ( this . _user_tooltip_handle ) {
1561
- clearTimeout ( this . _user_tooltip_handle ) ;
1562
- delete this . _user_tooltip_handle ;
1554
+ if ( this . #user_toottip_handle ) {
1555
+ clearTimeout ( this . #user_toottip_handle ) ;
1556
+ this . #user_toottip_handle = undefined ;
1563
1557
}
1564
1558
1565
1559
if ( ! data )
1566
1560
return this . #user_tooltip_handler( data ) ;
1567
1561
1568
1562
// only after timeout user function will be called
1569
- this . _user_tooltip_handle = setTimeout ( ( ) => {
1570
- delete this . _user_tooltip_handle ;
1563
+ this . #user_toottip_handle = setTimeout ( ( ) => {
1564
+ this . #user_toottip_handle = undefined ;
1571
1565
if ( this . #user_tooltip_handler)
1572
1566
this . #user_tooltip_handler( data ) ;
1573
1567
} , this . #user_tooltip_timeout) ;
@@ -1673,7 +1667,14 @@ function drawRawText(dom, txt /* , opt */) {
1673
1667
return painter . drawText ( ) ;
1674
1668
}
1675
1669
1676
- /** @summary Returns canvas painter (if any) for specified HTML element
1670
+ /** @summary Returns pad painter (if any) for specified DOM element
1671
+ * @param {string|object } dom - id or DOM element
1672
+ * @private */
1673
+ function getElementPadPainter ( dom ) {
1674
+ return new ObjectPainter ( dom ) . getPadPainter ( ) ;
1675
+ }
1676
+
1677
+ /** @summary Returns canvas painter (if any) for specified DOM element
1677
1678
* @param {string|object } dom - id or DOM element
1678
1679
* @private */
1679
1680
function getElementCanvPainter ( dom ) {
@@ -1780,6 +1781,6 @@ const EAxisBits = {
1780
1781
1781
1782
Object . assign ( internals . jsroot , { ObjectPainter, cleanup, resize } ) ;
1782
1783
1783
- export { getElementCanvPainter , getElementMainPainter , drawingJSON ,
1784
+ export { getElementPadPainter , getElementCanvPainter , getElementMainPainter , drawingJSON ,
1784
1785
selectActivePad , getActivePad , cleanup , resize , drawRawText ,
1785
1786
ObjectPainter , EAxisBits , kAxisLabels , kAxisNormal , kAxisFunc , kAxisTime } ;
0 commit comments