<commit_before>from __future__ import absolute_import, division, print_function

import numpy as np

from glue.external.echo import CallbackProperty, delay_callback, ListCallbackProperty
from glue.core.state_objects import State, StateAttributeLimitsHelper

__all__ = ['Vispy3DViewerState']


class Vispy3DViewerState(State):
    """
    A common state object for all vispy 3D viewers
    """

    x_att = CallbackProperty()
    x_min = CallbackProperty(0)
    x_max = CallbackProperty(1)
    x_stretch = CallbackProperty(1.)

    y_att = CallbackProperty()
    y_min = CallbackProperty(0)
    y_max = CallbackProperty(1)
    y_stretch = CallbackProperty(1.)

    z_att = CallbackProperty()
    z_min = CallbackProperty(0)
    z_max = CallbackProperty(1)
    z_stretch = CallbackProperty(1.)

    visible_axes = CallbackProperty(True)
    perspective_view = CallbackProperty(False)
    clip_data = CallbackProperty(False)
    native_aspect = CallbackProperty(False)

    layers = ListCallbackProperty()

    limits_cache = CallbackProperty({})

    def update_priority(self, name):
        if name == 'layers':
            return 1
        else:
            return 0

    def __init__(self, **kwargs):

        super(Vispy3DViewerState, self).__init__(**kwargs)

        self.x_att_helper = StateAttributeLimitsHelper(self, attribute='x_att',
                                                       lower='x_min', upper='x_max',
                                                       cache=self.limits_cache)

        self.y_att_helper = StateAttributeLimitsHelper(self, attribute='y_att',
                                                       lower='y_min', upper='y_max',
                                                       cache=self.limits_cache)

        self.z_att_helper = StateAttributeLimitsHelper(self, attribute='z_att',
                                                       lower='z_min', upper='z_max',
                                                       cache=self.limits_cache)

    @property
    def aspect(self):
        aspect = np.array([1, 1, 1], dtype=float)
        if self.native_aspect:
            aspect[0] = 1.
            aspect[1] = (self.y_max - self.y_min) / (self.x_max - self.x_min)
            aspect[2] = (self.z_max - self.z_min) / (self.x_max - self.x_min)
            aspect /= aspect.max()
        return aspect
<commit_msg>Set default limits_cache only if unset<commit_after>from __future__ import absolute_import, division, print_function

import numpy as np

from glue.external.echo import CallbackProperty, delay_callback, ListCallbackProperty
from glue.core.state_objects import State, StateAttributeLimitsHelper

__all__ = ['Vispy3DViewerState']


class Vispy3DViewerState(State):
    """
    A common state object for all vispy 3D viewers
    """

    x_att = CallbackProperty()
    x_min = CallbackProperty(0)
    x_max = CallbackProperty(1)
    x_stretch = CallbackProperty(1.)

    y_att = CallbackProperty()
    y_min = CallbackProperty(0)
    y_max = CallbackProperty(1)
    y_stretch = CallbackProperty(1.)

    z_att = CallbackProperty()
    z_min = CallbackProperty(0)
    z_max = CallbackProperty(1)
    z_stretch = CallbackProperty(1.)

    visible_axes = CallbackProperty(True)
    perspective_view = CallbackProperty(False)
    clip_data = CallbackProperty(False)
    native_aspect = CallbackProperty(False)

    layers = ListCallbackProperty()

    limits_cache = CallbackProperty()

    def update_priority(self, name):
        if name == 'layers':
            return 1
        else:
            return 0

    def __init__(self, **kwargs):

        super(Vispy3DViewerState, self).__init__(**kwargs)

        if self.limits_cache is None:
            self.limits_cache = {}

        self.x_att_helper = StateAttributeLimitsHelper(self, attribute='x_att',
                                                       lower='x_min', upper='x_max',
                                                       cache=self.limits_cache)

        self.y_att_helper = StateAttributeLimitsHelper(self, attribute='y_att',
                                                       lower='y_min', upper='y_max',
                                                       cache=self.limits_cache)

        self.z_att_helper = StateAttributeLimitsHelper(self, attribute='z_att',
                                                       lower='z_min', upper='z_max',
                                                       cache=self.limits_cache)

    @property
    def aspect(self):
        aspect = np.array([1, 1, 1], dtype=float)
        if self.native_aspect:
            aspect[0] = 1.
            aspect[1] = (self.y_max - self.y_min) / (self.x_max - self.x_min)
            aspect[2] = (self.z_max - self.z_min) / (self.x_max - self.x_min)
            aspect /= aspect.max()
        return aspect

{'fraction_non_alphanumeric': 0.09137895389704362, 'fraction_numerical': 0.009096547446764523, 'mean_word_length': 1.9901112484548826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4606528', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1341, 'n_words': 270}