Source code for highcharts_core.options.navigation

from typing import Optional

from validator_collection import validators

from highcharts_core.decorators import class_sensitive
from highcharts_core.metaclasses import HighchartsMeta
from highcharts_core.options.annotations import Annotation
from highcharts_core.options.navigation.bindings import Bindings
from highcharts_core.utility_classes.breadcrumbs import BreadcrumbOptions
from highcharts_core.utility_classes.buttons import NavigationButtonConfiguration
from highcharts_core.utility_classes.events import NavigationEvents


class NavigationBase(HighchartsMeta):
    """A collection of options for buttons and menus appearing in the exporting
    module or in Stock Tools.
    """

    def __init__(self, **kwargs):
        self._annotation_options = None
        self._bindings = None
        self._bindings_class_name = None
        self._button_options = None
        self._events = None
        self._icons_url = None
        self._menu_item_hover_style = None
        self._menu_item_style = None
        self._menu_style = None

        self.annotation_options = kwargs.get('annotation_options', None)
        self.bindings = kwargs.get('bindings', None)
        self.bindings_class_name = kwargs.get('bindings_class_name', None)
        self.button_options = kwargs.get('button_options', None)
        self.events = kwargs.get('events', None)
        self.icons_url = kwargs.get('icons_url', None)
        self.menu_item_hover_style = kwargs.get('menu_item_hover_style', None)
        self.menu_item_style = kwargs.get('menu_item_style', None)
        self.menu_style = kwargs.get('menu_style', None)

        super().__init__(**kwargs)

    @property
    def annotation_options(self) -> Optional[Annotation]:
        """Additional options to be applied to all annotations.

        :rtype: :class:`NavigationAnnotationOptions` or :obj:`None <python:None>`
        """
        return self._annotation_options

    @annotation_options.setter
    @class_sensitive(Annotation)
    def annotation_options(self, value):
        self._annotation_options = value

    @property
    def bindings(self) -> Optional[Bindings]:
        """JavaScript event bindings for custom HTML buttons.

        :rtype: :class:`Bindings` or :obj:`None <python:None>`
        """
        return self._bindings

    @bindings.setter
    @class_sensitive(Bindings)
    def bindings(self, value):
        self._bindings = value

    @property
    def bindings_class_name(self) -> Optional[str]:
        """A CSS class name where all bindings will be attached to. Defaults to
        ``'highcharts-bindings-container'``.

        .. hint::

          Multiple charts on the same page should have separate class names to prevent
          duplicating events.

        :rtype: :class:`str <python:str>` or :obj:`None <python:None>`
        """
        return self._bindings_class_name

    @bindings_class_name.setter
    def bindings_class_name(self, value):
        self._bindings_class_name = validators.string(value, allow_empty = True)

    @property
    def button_options(self) -> Optional[NavigationButtonConfiguration]:
        """Configuration options for navigation buttons.

        :rtype: :class:`NavigationButtonConfiguration <highcharts_core.utility_classes.buttons.NavigationButtonConfiguration>`
        """
        return self._button_options

    @button_options.setter
    @class_sensitive(NavigationButtonConfiguration)
    def button_options(self, value):
        self._button_options = value

    @property
    def events(self) -> Optional[NavigationEvents]:
        """Events to communicate between Stock Tools and custom GUI.

        :rtype: :class:`NavigationEvents` or :obj:`None <python:None>`
        """
        return self._events

    @events.setter
    @class_sensitive(NavigationEvents)
    def events(self, value):
        self._events = value

    @property
    def icons_url(self) -> Optional[str]:
        """Path where Highcharts will look for icons. Defaults to
        ``'https://code.highcharts.com/@product.version@/gfx/stock-icons/'``.

        Change this to use icons from a different server.

        :rtype: :class:`str <python:str>` or :obj:`None <python:None>`
        """
        return self._icons_url

    @icons_url.setter
    def icons_url(self, value):
        self._icons_url = validators.string(value, allow_empty = True)

    @property
    def menu_item_hover_style(self) -> Optional[str | dict]:
        """CSS styles for the individual items within the popup menu when the user's mouse hovers over them.

        .. note::

          Font size defaults to 11px on desktop and 14px on touch devices.

        Defaults to:
        ``{"background": "#f2f2f2" }``.

        :rtype: :class:`str <python:str>` or :class:`dict <python:dict>` or :obj:`None <python:None>`
        """
        return self._menu_item_hover_style

    @menu_item_hover_style.setter
    def menu_item_hover_style(self, value):
        try:
            self._menu_item_hover_style = validators.dict(value, allow_empty = True)
        except (ValueError, TypeError):
            self._menu_item_hover_style = validators.string(value,
                                                            allow_empty = True,
                                                            coerce_value = True)

    @property
    def menu_item_style(self) -> Optional[str | dict]:
        """CSS styles for the individual items within the popup menu.

        .. note::

          Font size defaults to 11px on desktop and 14px on touch devices.

        Defaults to:
        ``{"padding": "0.5em", "color": "#333333", "background": "none", "borderRadius": "3px", "fontSize": "0.8em", "transition": "background 250ms, color 250ms"}``.

        :rtype: :class:`str <python:str>` or :class:`dict <python:dict>` or :obj:`None <python:None>`
        """
        return self._menu_item_style

    @menu_item_style.setter
    def menu_item_style(self, value):
        try:
            self._menu_item_style = validators.dict(value, allow_empty = True)
        except (ValueError, TypeError):
            self._menu_item_style = validators.string(value,
                                                      allow_empty = True,
                                                      coerce_value = True)

    @property
    def menu_style(self) -> Optional[str | dict]:
        """CSS styles for the popup menu appearing when the popup button is clicked.

        Defaults to:
        ``{"background": "#ffffff", "borderRadius": "3px", "padding": "0.5em"}``.

        :rtype: :class:`str <python:str>` or :class:`dict <python:dict>` or :obj:`None <python:None>`
        """
        return self._menu_style

    @menu_style.setter
    def menu_style(self, value):
        try:
            self._menu_style = validators.dict(value, allow_empty = True)
        except (ValueError, TypeError):
            self._menu_style = validators.string(value,
                                                 allow_empty = True,
                                                 coerce_value = True)

    @classmethod
    def _get_kwargs_from_dict(cls, as_dict):
        kwargs = {
            'annotation_options': as_dict.get('annotationOptions', None),
            'bindings': as_dict.get('bindings', None),
            'bindings_class_name': as_dict.get('bindingsClassName', None),
            'button_options': as_dict.get('buttonOptions', None),
            'events': as_dict.get('events', None),
            'icons_url': as_dict.get('iconsURL', None),
            'menu_item_hover_style': as_dict.get('menuItemHoverStyle', None),
            'menu_item_style': as_dict.get('menuItemStyle', None),
            'menu_style': as_dict.get('menuStyle', None),
        }

        return kwargs

    def _to_untrimmed_dict(self, in_cls = None) -> dict:
        untrimmed = {
            'annotationOptions': self.annotation_options,
            'bindings': self.bindings,
            'bindingsClassName': self.bindings_class_name,
            'buttonOptions': self.button_options,
            'events': self.events,
            'iconsURL': self.icons_url,
            'menuItemHoverStyle': self.menu_item_hover_style,
            'menuItemStyle': self.menu_item_style,
            'menuStyle': self.menu_style,
        }

        return untrimmed