def fixLabel(label, maxlen, delim=None, repl='<STR_LIT>', truncend=True):
if len(label) <= maxlen:<EOL><INDENT>return label<EOL><DEDENT>else:<EOL><INDENT>maxlen -= len(repl)<EOL>if delim is not None:  <EOL><INDENT>if truncend:<EOL><INDENT>end = label.rfind(delim, <NUM_LIT:0>, maxlen)<EOL>if end > <NUM_LIT:0>:<EOL><INDENT>return label[:end+<NUM_LIT:1>] + repl<EOL><DEDENT><DEDENT>else:<EOL><INDENT>start = label.find(delim, len(label) - maxlen)<EOL>if start > <NUM_LIT:0>:<EOL><INDENT>return repl + label[start:]<EOL><DEDENT><DEDENT><DEDENT>if truncend:<EOL><INDENT>return label[:maxlen] + repl<EOL><DEDENT>else:<EOL><INDENT>return repl + label[-maxlen:]<EOL><DEDENT><DEDENT>
Truncate long graph and field labels.

        @param label:    Label text.
        @param maxlen:   Maximum field label length in characters.
                         No maximum field label length is enforced by default.
        @param delim:    Delimiter for field labels field labels longer than 
                         maxlen will preferably be truncated at delimiter.
        @param repl:     Replacement string for truncated part.
        @param truncend: Truncate the end of label name if True. (Default)
                         The beginning part of label will be truncated if False.