Skip to content

Commit

Permalink
minor tweak for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Aug 10, 2024
1 parent 6872621 commit 3c53977
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
1 change: 0 additions & 1 deletion ostap/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import ostap.core.default_config as default_config
from ostap.utils.basic import get_env as ostap_getenv
# =============================================================================

## print for configparger
def _cp_str_ ( cp ) :
"""print for configparger"""
Expand Down
33 changes: 25 additions & 8 deletions ostap/plotting/makestyles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
!/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# @file ostap/plotting/makestyles.py
Expand Down Expand Up @@ -291,7 +291,7 @@ def table_style ( style , prefix = '' , title = '' ) :
# set_style ( style , config )
# style.set ( config ) ## ditto
# @endcode
def set_style ( style , config ) :
def set_style ( style , config , **kwargs ) :
"""Set the style from the configurtaion dictionary
>>> config = ...
>>> style = ...
Expand All @@ -301,10 +301,11 @@ def set_style ( style , config ) :

conf = cidict ( transform = cidict_fun )
conf.update ( config )
conf.update ( kwargs )

changed = {}

for attr in style_setters [0] :
for attr in style_setters [ 0 ] :

if not attr in conf : continue

Expand Down Expand Up @@ -571,9 +572,21 @@ def make_styles ( config = None ) :
name = n.strip ( )
description = section.get ( 'description' , fallback = 'The style %s' % name )
ok = section.getboolean ( 'ostaplike' , fallback = True )
base = section.get ( 'basestyle' , fallback = '' )

base_config = {}
if base :
groot = ROOT.ROOT.GetROOT ()
slst = groot.GetListOfStyles ()
for s in slst :
if base == s.GetName() :
base_config = dump_style ( s )
break
else :
logger.warning ( "makestyles: no base style `%s' is found! " % base )

## create ostap-like style
if ok : style = make_ostap_style ( name , description , section )
if ok : style = make_ostap_style ( name , description , section , base = base_conf )
else :
## generic style

Expand All @@ -586,7 +599,8 @@ def make_styles ( config = None ) :
else :
logger.info ( 'Create new generic style %s/%s' % ( name , description ) )
style = ROOT.TStyle ( name , description )


if base_config : set_style ( style , base_config )
set_style ( style , section )

if name in StyleStore.styles :
Expand Down Expand Up @@ -647,7 +661,8 @@ def get_str ( config , name , default ) :
## make Ostap-like style
def make_ostap_style ( name ,
description = 'The Style' ,
config = {} , **kwargs ) :
config = {} ,
base = {} , **kwargs ) :


kw = cidict ( transform = cidict_fun )
Expand All @@ -662,9 +677,11 @@ def make_ostap_style ( name ,
description = config.get ( 'description' , description )

conf = {}
conf.update ( config )

conf.update ( base ) ## base style configuration
conf.update ( config ) ## own configuration



conf [ 'AxisColor_X' ] = get_int ( config , 'AxisColor_X' , 1 )
conf [ 'AxisColor_Y' ] = get_int ( config , 'AxisColor_Y' , 1 )
conf [ 'AxisColor_Z' ] = get_int ( config , 'AxisColor_Z' , 1 )
Expand Down
19 changes: 16 additions & 3 deletions ostap/plotting/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
## Create Ostap-style for the plots
def OstapStyle ( name ,
description ,
line_width = ostap_line_width ,
font = ostap_font ,
base = '' ,
line_width = ostap_line_width ,
font = ostap_font ,
force = True ,
scale = 1.0 ,
colz = False ) :
Expand All @@ -63,6 +64,17 @@ def OstapStyle ( name ,
config = {}
n2 = name.strip()

base_conf = {}
if base :
groot = ROOT.ROOT.GetROOT ()
slst = groot.GetListOfStyles ()
for s in slst :
if base == s.GetName() :
base_config = dump_style ( s )
break
else :
logger.warning ( "OstapStyle: no base style `%s' is found! " % base )

## Look for "[Style:Nick]" in configuration
for key in CONFIG.config :
lkey = key.lower()
Expand All @@ -77,7 +89,8 @@ def OstapStyle ( name ,

import ostap.plotting.makestyles as MS
style = MS.make_ostap_style ( name = name ,
description = description ,
description = description ,
base = base_conf ,
config = config ,
colz = colz ,
scale = scale ,
Expand Down

0 comments on commit 3c53977

Please sign in to comment.