from django.shortcuts import render

# Create your views here.
from django.shortcuts import render
from plotly.offline import plot
import plots.polygon as poly
import matplotlib
matplotlib.use('Agg')
from django.http import JsonResponse
from plotly.graph_objs import Scatter
import plotly.graph_objects as go
from django.http import HttpResponse
import pdb;pdb.set_trace
import matplotlib.pyplot as plt
import mpld3
from plotly.subplots import make_subplots
import math
from plots import plot_helpers

# def index(request):
#     return HttpResponse("Hello, world. You're at the polls index.")


def index(request):







    #[(0.5, 0), (0, 1), (1, 0), (0.5, 0)]
    convex_polygons = poly.create_multiple_convex_polygons(10,3)

    polygons_plot = plot_helpers.polygon_plot(convex_polygons)
    hc = poly.height_classes(convex_polygons)
    plot_high_class_list =plot_helpers.high_class_plot(hc)
    #containers = poly.building_containers(hc)
    #plot_hc_container_list = plot_helpers.hc_container_plot(containers)
    # plot_polygon_list = []
    # for polygon in convex_polygons:
    #     fig = go.Figure()
    #     x_data = polygon.x_values
    #     y_data = polygon.y_values
    #     scatter = go.Scatter(x=x_data, y=y_data,
    #                      mode='lines', name='test',
    #                      opacity=0.8, marker_color='green')
    #     fig.add_trace(scatter)
    #     plt_div = plot(fig, output_type='div')
    #     plot_polygon_list.append(plt_div)
    #
    #
    #
    # high_classes = poly.height_classes(convex_polygons)

    return render(request, 'plots/index.html', context={'polygons_plot': polygons_plot,
                                                        'high_classes': plot_high_class_list,})
            #                                            'hc_container': hc_container})





def get_json_view(request):
    convex_polygons = poly.create_multiple_convex_polygons(10, 3)
    hc = poly.height_classes(convex_polygons)
    containers = poly.building_containers(hc)

    container_plots=[]
    for container  in containers:
        container_plots.append(container.plots)
    #g = convex_polygons[0].plot_polygon()
    return render(request, 'plots/get.html', context={'containers': container_plots,})