<commit_before>"""
Functions for adding decorations (axes, colorbar, outlines..) to the
pipeline in a procedural way.
"""

# Author: <NAME> 
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.

import operator

import numpy as np

# Enthought library imports.
import enthought.mayavi.modules.api as modules
from enthought.traits.api import String, CFloat, Instance, HasTraits, \
            Trait, CArray, true, Any, Range, Either
import tools
from figure import draw, gcf

# Mayavi imports
from pipe_base import make_function
from modules import ModuleFactory
from engine_manager import get_engine, engine_manager

#############################################################################
# Colorbar related functions

def _orient_colorbar(lut_mgr, orientation):
    """Orients the given LUTManager (make it horizontal or vertical).
    """
    rep = lut_mgr.scalar_bar_representation
    colorbar = lut_mgr.scalar_bar
    if orientation == "vertical":
        if rep is None:
            colorbar.orientation = "vertical"
        else:
            rep.orientation = 1
        colorbar.width = 0.1
        colorbar.height = 0.8
        colorbar.position = (0.01, 0.15)
    elif orientation == "horizontal":
        if rep is None:
            colorbar.orientation = "horizontal"
        else:
            rep.orientation = 0
        colorbar.width = 0.8
        colorbar.height = 0.17
        colorbar.position = (0.1, 0.01)
    else:
        print "Unknown orientation"
    draw()

def _lut_manager_properties(lut_manager, **props):
    """ Internal function used to apply properties to a colorbar.
    """
    need_redraw = False
    orientation = props.get('orientation', None)
    if orientation is not None:
        _orient_colorbar(lut_manager, orientation)

    colorbar = lut_manager.scalar_bar
    title = props.get('title', None)
    if title is not None:
        colorbar.title = title
        need_redraw = True

    label_fmt = props.get('label_fmt', None)
    if label_fmt is not None:
        colorbar.label_format = label_fmt
        need_redraw = True

    nb_labels = props.get('nb_labels', None)
    if nb_labels is not None:
        colorbar.number_of_labels = nb_labels
        need_redraw = True

    nb_colors = props.get('nb_colors', None)
    if nb_colors is not None:
        colorbar.maximum_number_of_colors = nb_colors
        need_redraw = True<commit_msg>BUG: Fix scalarbar positionning for VTK >= 5.2<commit_after>"""
Functions for adding decorations (axes, colorbar, outlines..) to the
pipeline in a procedural way.
"""

# Author: <NAME> 
# Copyright (c) 2007, 2008, 2009, Enthought, Inc.
# License: BSD Style.

import operator

import numpy as np

# Enthought library imports.
from enthought.traits.api import String, CFloat, Instance, HasTraits, \
            Trait, CArray, true, Any, Range, Either
import tools
from figure import draw, gcf

# Mayavi imports
import enthought.mayavi.modules.api as modules
from .pipe_base import make_function
from .modules import ModuleFactory
from .engine_manager import get_engine, engine_manager

#############################################################################
# Colorbar related functions

def _orient_colorbar(lut_mgr, orientation):
    """Orients the given LUTManager (make it horizontal or vertical).
    """
    rep = lut_mgr.scalar_bar_representation
    colorbar = lut_mgr.scalar_bar
    if orientation == "vertical":
        if rep is None:
            # VTK < 5.2
            colorbar.orientation = "vertical"
        else:
            rep.orientation = 1
            rep.position = (0.01, 0.15)
            rep.position2 = (0.1, 0.8)
        colorbar.width = 0.1
        colorbar.height = 0.8
        colorbar.position = (0.01, 0.15)
    elif orientation == "horizontal":
        if rep is None:
            colorbar.orientation = "horizontal"
        else:
            rep.orientation = 0
            rep.position  = (0.1, 0.01)
            rep.position2 = (0.8, 0.17)
        colorbar.width = 0.8
        colorbar.height = 0.17
        colorbar.position = (0.1, 0.01)
    else:
        raise ValueError("Unknown orientation: %s" % orientation)
    draw()

def _lut_manager_properties(lut_manager, **props):
    """ Internal function used to apply properties to a colorbar.
    """
    need_redraw = False
    orientation = props.get('orientation', None)
    if orientation is not None:
        _orient_colorbar(lut_manager, orientation)

    colorbar = lut_manager.scalar_bar
    title = props.get('title', None)
    if title is not None:
        colorbar.title = title
        need_redraw = True

    label_fmt = props.get('label_fmt', None)
    if label_fmt is not None:
        colorbar.label_format = label_fmt
        need_redraw = True

    nb_labels = props.get('nb_labels', None)
    if nb_labels is not None:
        colorbar.number_of_labels = nb_labels
        need_redraw = True

    nb_colors = props.get('nb_colors', None)
    if nb_colors is not None:
        colorbar.maximum_number_of_colors = nb_colors
        need_redraw = True
{'fraction_non_alphanumeric': 0.11642617118007512, 'fraction_numerical': 0.01699940699743032, 'mean_word_length': 2.778939507094847, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868985', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1476, 'n_words': 441}