<commit_before># Copyright (c) 2011, Enthought, Ltd.
# Author: <NAME> <<EMAIL>>
# License: Apache license
from chaco.label_axis import LabelAxis
from chaco.scales.scales import FixedScale
from chaco.scales_tick_generator import ScalesTickGenerator
import numpy as np

from traits.api import HasTraits, Str
from traitsui.api import HGroup, Spring, Item, View, VGroup, Include
from pyanno.plots.plot_tools import SaveToolPlus, CopyDataToClipboardTool


class PyannoPlotContainer(HasTraits):

    #### plot-related traits
    title = Str

    instructions = Str
    def _instructions_default(self):
        import sys
        if sys.platform == 'darwin':
            return 'Cmd-S: Save, Cmd-C: Copy data'
        else:
            return 'Ctrl-S: Save,  Ctrl-C: Copy data'


    def decorate_plot(self, plot, data):
        """Add Copy and Save tools."""

        save_tool = SaveToolPlus(component=plot)
        copy_tool = CopyDataToClipboardTool(component=plot, data=data)

        plot.tools.append(save_tool)
        plot.tools.append(copy_tool)


    def _set_title(self, plot):
        if self.title is not None:
            plot.title = self.title


    def _create_increment_one_axis(self, plot, start, number, orientation,
                                   ticks=None):
        """Create axis with ticks at a distance of one units.

        Parameters
        ----------
        plot : Plot
            plot where the axis will be attached
        start : float
            position of first tick
        number : int
            number of ticks
        orientation: ['top', 'bottom', 'left', 'right']
            position of axis on the plot
        ticks : list of strings
            string to be displayed for each tick
        """

        ids = start + np.arange(0, number)
        if ticks is None:
            ticks = [str(idx) for idx in np.arange(0, number)]

        axis = LabelAxis(
            plot,
            orientation = orientation,
            positions = ids,
            labels = ticks,
            label_rotation = 0
        )

        # use a FixedScale tick generator with a resolution of 1
        axis.tick_generator = ScalesTickGenerator(scale=FixedScale(1.))

        return axis


    def _remove_grid_and_axes(self, plot):
        """Remove grids and axes."""
        plot.underlays = []


    def _add_index_axis(self, plot, axis):
        plot.index_axis = axis
        plot.underlays.append(axis)


    def _add_value_axis(self, plot, axis):
        plot.value_axis = axis
        plot.underlays.append(axis)


    #### View definitions #####################################################

    instructions_group = HGroup(
        Spring(),
        Item('instructions', style='readonly', show_label=False),
        Spring()
    )

    resizable_view = View(
        VGroup(
            Include('resizable_plot_item'),
            Include('instructions_group'),
            ),
        resizable = True
    )


    traits_view = View(
        VGroup(
            Include('traits_plot_item'),
            Include('instructions_group'),
            ),
        resizable = True
    )<commit_msg>RF: make traits_view in plots superclass overridable<commit_after># Copyright (c) 2011, Enthought, Ltd.
# Author: <NAME> <<EMAIL>>
# License: Apache license
from chaco.label_axis import LabelAxis
from chaco.scales.scales import FixedScale
from chaco.scales_tick_generator import ScalesTickGenerator
import numpy as np

from traits.api import HasTraits, Str
from traitsui.api import HGroup, Spring, Item, View, VGroup, Include
from pyanno.plots.plot_tools import SaveToolPlus, CopyDataToClipboardTool


class PyannoPlotContainer(HasTraits):

    #### plot-related traits
    title = Str

    instructions = Str
    def _instructions_default(self):
        import sys
        if sys.platform == 'darwin':
            return 'Cmd-S: Save, Cmd-C: Copy data'
        else:
            return 'Ctrl-S: Save,  Ctrl-C: Copy data'


    def decorate_plot(self, plot, data):
        """Add Copy and Save tools."""

        save_tool = SaveToolPlus(component=plot)
        copy_tool = CopyDataToClipboardTool(component=plot, data=data)

        plot.tools.append(save_tool)
        plot.tools.append(copy_tool)


    def _set_title(self, plot):
        if self.title is not None:
            plot.title = self.title


    def _create_increment_one_axis(self, plot, start, number, orientation,
                                   ticks=None):
        """Create axis with ticks at a distance of one units.

        Parameters
        ----------
        plot : Plot
            plot where the axis will be attached
        start : float
            position of first tick
        number : int
            number of ticks
        orientation: ['top', 'bottom', 'left', 'right']
            position of axis on the plot
        ticks : list of strings
            string to be displayed for each tick
        """

        ids = start + np.arange(0, number)
        if ticks is None:
            ticks = [str(idx) for idx in np.arange(0, number)]

        axis = LabelAxis(
            plot,
            orientation = orientation,
            positions = ids,
            labels = ticks,
            label_rotation = 0
        )

        # use a FixedScale tick generator with a resolution of 1
        axis.tick_generator = ScalesTickGenerator(scale=FixedScale(1.))

        return axis


    def _remove_grid_and_axes(self, plot):
        """Remove grids and axes."""
        plot.underlays = []


    def _add_index_axis(self, plot, axis):
        plot.index_axis = axis
        plot.underlays.append(axis)


    def _add_value_axis(self, plot, axis):
        plot.value_axis = axis
        plot.underlays.append(axis)


    #### View definitions #####################################################

    instructions_group = HGroup(
        Spring(),
        Item('instructions', style='readonly', show_label=False),
        Spring()
    )

    resizable_view = View(
        VGroup(
            Include('resizable_plot_item'),
            Include('instructions_group'),
            ),
        resizable = True
    )

    def traits_view(self):
        traits_view = View(
            VGroup(
                Include('traits_plot_item'),
                Include('instructions_group'),
                ),
            resizable = True
        )
        return traits_view
{'fraction_non_alphanumeric': 0.10513141426783479, 'fraction_numerical': 0.002816020025031289, 'mean_word_length': 2.0854247104247103, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3496080', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1700, 'n_words': 502}