"""
Demonstrating the examples from pyqtgraph
"""

from atom.api import (Atom, Str, Range, List, Bool)

from enaml.widgets.api import (
    Window, Container, DockArea,DockItem,PushButton, CheckBox, RadioButton
)
from enaml.core.looper import Looper
from enaml.widgets.spin_box import SpinBox

import numpy as np
from enamlx.widgets.api import PlotArea,PlotItemArray,PlotItemArray3D
from enaml.layout.dock_layout import VSplitLayout, HSplitLayout
from enamlx.widgets.double_spin_box import DoubleSpinBox
from enaml.widgets.dual_slider import DualSlider


enamldef Main(Window):
    minimum_size = (960,640)
    Container:
        padding = 0
        DockArea:
            layout = HSplitLayout(
                VSplitLayout(
                    'basic',
                    'multi',
                    'range',
                ), VSplitLayout(
                    'multi2',
                    'multi3',
                    'multi4'
                )
                #'scatter',
            )
            DockItem:
                name = 'basic'
                PlotArea:
                    PlotItemArray:
                        title = 'Basic array plotting'
                        y << np.random.normal(size=100)
                        label_left = 'Value'
                    
            DockItem:
                name = 'multi'
                title = 'Multiple curves'
                PlotArea:
                    PlotItemArray:
                        multi_axis = False
                        label_left = 'A'
                        line_pen = 'g'
                        y << np.random.normal(size=100)
                        PlotItemArray:
                            line_pen = 'b'
                            label_right = 'B'
                            y << np.random.normal(size=100)+10
                        PlotItemArray:
                            line_pen = 'r'
                            label_right = 'C'
                            y << np.random.normal(size=100)+20 
            DockItem:
                name = 'multi2'
                title = 'Multiple curves with axis'
                PlotArea:
                    PlotItemArray:
                        multi_axis = False
                        label_left = 'A'
                        line_pen = 'g'
                        y << np.random.normal(size=100)
                        PlotItemArray:
                            line_pen = 'b'
                            label_right = 'B'
                            y << np.random.normal(size=100)+10
                        PlotItemArray:
                            line_pen = 'r'
                            label_right = 'C'
                            y << np.random.normal(size=100)+20 
            DockItem:
                name = 'multi3'
                title = 'Multiple plot'
                PlotArea:
                    PlotItemArray:
                        row = 1
                        label_left = 'A'
                        line_pen = 'g'
                        y << np.random.normal(size=100)
                    PlotItemArray:
                        row = 2 # leave row out to stack however it likes
                        line_pen = 'b'
                        label_left = 'B'
                        y << np.random.normal(size=100)+10
            DockItem:
                name = 'multi4'
                title = 'Multiple plot'
                PlotArea:
                    PlotItemArray:
                        label_left = 'A'
                        line_pen = 'g'
                        y << np.random.normal(size=100)
                    PlotItemArray:
                        line_pen = 'b'
                        label_left = 'B'
                        y << np.random.normal(size=100)+10
            DockItem:
                name = 'range'
                title = 'View range'
                Container:
                    padding = 0
                    PlotArea:
                        PlotItemArray: range_plot:
                            auto_range = (False,True)
                            background = 'white'
                            #range_x << (range_slider.low_value,range_slider.high_value)
                            #range_x :: range_slider.low_value,range_slider.high_value = map(int,change['value'])
                            y << np.random.normal(size=100)
                    DualSlider: range_slider:
                        minimum = 0
                        maximum = 100
                        low_value << int(range_plot.range_x[0])
                        low_value :: range_plot.range_x[0] = change['value']
                        
                        high_value << int(range_plot.range_x[1])
                        high_value :: range_plot.range_x[1] = change['value']
#             DockItem:
#                 name = 'scatter'
#                 Container:
#                     PlotItemArray3D: # TODO, does not work
#                         minimum_size = (360,360)
#                         x = np.linspace(-10,10,100)
#                         y = np.linspace(-10,10,51)
#                         z = np.random.normal(size=100)