# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
"""The documentation for Menu"""

from omni import ui
from omni.ui import color as cl
from .doc_page import DocPage

import math


class PlotDoc(DocPage):
    """ document for Plot"""

    def __init__(self, extension_path):
        super().__init__(extension_path)
        self._data = []
        for i in range(360):
            self._data.append(math.cos(math.radians(i)))

    def create_doc(self, navigate_to=None):
        self._section_title("Plot")
        self._text("The Plot class displayes a line or histogram image.")
        self._text("The data of image is specified as a data array or a provider function.")

        ui.Plot(ui.Type.LINE, -1.0, 1.0, *self._data, width=360, height=100, style={"color": cl.red})

        self._code(
            """
        self._data = []
        for i in range(360):
            self._data.append(math.cos(math.radians(i)))

        ui.Plot(ui.Type.LINE, -1.0, 1.0, *self._data, width=360, height=100, style={"color": cl.red})
            """
        )

        plot = ui.Plot(
            ui.Type.HISTOGRAM,
            -1.0,
            1.0,
            self._on_data_provider,
            360,
            width=360,
            height=100,
            style={"color": cl.blue},
        )
        plot.value_stride = 6

        self._code(
            """
        def _on_data_provider(self, index):
            return math.sin(math.radians(index))

        plot = ui.Plot(ui.Type.HISTOGRAM, -1.0, 1.0, self._on_data_provider, 360, width=360, height=100, style={"color": cl.blue})
        plot.value_stride = 6
            """
        )

        ui.Spacer(height=100)

    def _on_data_provider(self, index):
        return math.sin(math.radians(index))
