From 7e8d05a53178b7a581844a399a9100e1a0108b67 Mon Sep 17 00:00:00 2001 From: Tolga Yurtseven <tolgayurt02@outlook.de> Date: Wed, 11 Nov 2020 14:09:32 +0100 Subject: [PATCH] combines csv and polyedittool --- mysite/plots/polygon.txt | 3 +- mysite/plots/templates/plots/test.html | 30 ++- mysite/plots/templates/plots/test2.html | 91 +++++++++ mysite/plots/urls.py | 5 +- mysite/plots/views.py | 162 +++++++++++----- mysite/plots/views2_with_csv.py | 246 ++++++++++++++++++++++++ 6 files changed, 480 insertions(+), 57 deletions(-) create mode 100644 mysite/plots/templates/plots/test2.html create mode 100644 mysite/plots/views2_with_csv.py diff --git a/mysite/plots/polygon.txt b/mysite/plots/polygon.txt index 7f293743..fdb043f0 100644 --- a/mysite/plots/polygon.txt +++ b/mysite/plots/polygon.txt @@ -1,3 +1,4 @@ Polygon +[(3.0, 0.0),(0.0, 1.0),(0,0),(0.0, 4.0),(3.0, 5.0),(5.0, 3.0),(5.0, 1.0),(2.0, 0.0)] [(2.0, 0.0),(0.0, 1.0),(0.0, 4.0),(3.0, 5.0),(5.0, 3.0),(5.0, 1.0),(2.0, 0.0)] -[(2.0, 0.0),(0.0, 1.0),(0.0, 4.0),(3.0, 5.0),(5.0, 3.0),(5.0, 1.0),(2.0, 0.0)] \ No newline at end of file +[(-12.0, 0.0),(0.0, 1.0),(0.0, 4.0),(3.0, 5.0),(5.0, 3.0),(5.0, 1.0),(2.0, 0.0)] \ No newline at end of file diff --git a/mysite/plots/templates/plots/test.html b/mysite/plots/templates/plots/test.html index 53e3d53a..29075895 100644 --- a/mysite/plots/templates/plots/test.html +++ b/mysite/plots/templates/plots/test.html @@ -13,15 +13,37 @@ <body> - <div> + <div style='display:inline'> + <h1>Drawn Polygons</h1> {{ response|safe }} - <form action="/test/" method="post"> + <form style='display:inline' action="/test/" method="post"> {% csrf_token %} - <label for="your_name">Load the input Polygons</label> + <label for="your_name">Load/Clear the drawn Polygons</label> <input id="your_name" type="hidden" name="your_name" value="test"> <input type="submit" onclick="myFunction()" value="load"> </form> + <form style='display:inline' action="/clear_polygons/" method="get"> + {% csrf_token %} + <label for="clear_polygons"></label> + <input id="clear_polygons" type="hidden" name="clear_polygons" value="test"> + <input type="submit" value="clear"> + </form> + </div> + <div> + <form action="/csv_polygons/" method="post"> + {% csrf_token %} + <label for="load_csv_polygons">Load CSV Polygons into PolyEditTool</label> + <input id="load_csv_polygons" type="hidden" name="load_csv_polygons" value="test"> + <input type="submit" value="load"> + </form> </div> + <!--<form style='display:inline' action="/csv_polygons/" method="get">--> + <!--{% csrf_token %}--> + <!--<label for="clear_csv_polygons"></label>--> + <!--<input id="clear_csv_polygons" type="hidden" name="clear_csv_polygons" value="test">--> + <!--<input type="submit" value="clear">--> + <!--</form>--> + <div> <form action="/packing_rect_container/" target="_blank" method="get"> {% csrf_token %} @@ -49,7 +71,7 @@ <div> {% autoescape off %} <h1>Convex Polygons</h1> - {{polygons_plot|safe}} + {{drawn_polygons|safe}} <h1>Convex Polygons in one Plot</h1> {{polygons_single_plot|safe}} diff --git a/mysite/plots/templates/plots/test2.html b/mysite/plots/templates/plots/test2.html new file mode 100644 index 00000000..aab43958 --- /dev/null +++ b/mysite/plots/templates/plots/test2.html @@ -0,0 +1,91 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title></title> + <script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.2.3.min.js" + crossorigin="anonymous"></script> + <script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.2.3.min.js" + crossorigin="anonymous"></script> + <script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.2.3.min.js" + crossorigin="anonymous"></script> + </head> + <body> + + + <div> + {{ response|safe }} + <form action="/test/" method="post"> + {% csrf_token %} + <label for="your_name">Load the drawn Polygons</label> + <input id="your_name" type="hidden" name="your_name" value="test"> + <input type="submit" onclick="myFunction()" value="load"> + </form> + </div> + <div style='display:inline'> + <form style='display:inline' action="/csv_polygons/" method="post"> + {% csrf_token %} + <label for="load_csv_polygons">Load CSV Polygons</label> + <input id="load_csv_polygons" type="hidden" name="load_csv_polygons" value="test"> + <input type="submit" value="load"> + </form> + </div> + <form style='display:inline' action="/csv_polygons/" method="get"> + {% csrf_token %} + <label for="clear_csv_polygons"></label> + <input id="clear_csv_polygons" type="hidden" name="clear_csv_polygons" value="test"> + <input type="submit" value="clear"> + </form> + + <div> + <form action="/packing_rect_container/" target="_blank" method="get"> + {% csrf_token %} + <label for="pack_rect_container">Packing Rectengular Container</label> + <input id="pack_rect_container" type="hidden" name="pack_polygon" value="test"> + <input type="submit" onclick="packPolygons()" value="pack"> + </form> + </div> + <div> + <form action="/packing_rotated_rect_container/" target="_blank" method="get"> + {% csrf_token %} + <label for="pack_rotated_rect_container">Packing Rotated Rectengular Container</label> + <input id="pack_rotated_rect_container" type="hidden" name="pack_polygon" value="test"> + <input type="submit" onclick="packPolygons()" value="pack"> + </form> + </div> + <div> + <form action="/packing_convex_container/" target="_blank" method="post"> + {% csrf_token %} + <label for="pack_convex_container">Packing Convex Container (degree between 1-360)</label> + <input id="pack_convex_container" type="number" min="1" max="360" name="angle" value=10> + <input type="submit" value="pack"> + </form> + </div> + <div> + {% autoescape off %} + <h1>Drawn Convex Polygons</h1> + {{drawn_polygons|safe}} + <h1>Csv input Convex Polygons</h1> + {{csv_polygons|safe}} + <h1>Convex Polygons to Pack</h1> + {{polygons_single_plot|safe}} + + + {% endautoescape %} + </div> + + + </body> + + + + +<script> +function myFunction() { + var ds = Bokeh.documents[0].get_model_by_name('my-data-source'); + var dict1 = {x:ds.data["x"], y:ds.data["y"]}; + document.getElementById("your_name").value =JSON.stringify(dict1); +} +</script> + +</html> \ No newline at end of file diff --git a/mysite/plots/urls.py b/mysite/plots/urls.py index 9e65f3b9..14bfeaee 100644 --- a/mysite/plots/urls.py +++ b/mysite/plots/urls.py @@ -1,5 +1,6 @@ from django.urls import path -from plots.views import PolygonEditView, PackingRectContainer, PackingRotatedRectContainer, PackingConvexContainer +from plots.views import PolygonEditView, PackingRectContainer, PackingRotatedRectContainer, PackingConvexContainer, \ + CSVPolygons, ClearPolygons from . import views urlpatterns = [ @@ -11,4 +12,6 @@ urlpatterns = [ path('packing_rect_container/', PackingRectContainer.as_view(), name='rect_container'), path('packing_rotated_rect_container/', PackingRotatedRectContainer.as_view(), name='rotated_rect_container'), path('packing_convex_container/', PackingConvexContainer.as_view(), name='convex_container'), + path('csv_polygons/', CSVPolygons.as_view(), name='csv_polygons'), + path('clear_polygons/', ClearPolygons.as_view(), name='csv_polygons'), ] \ No newline at end of file diff --git a/mysite/plots/views.py b/mysite/plots/views.py index 19a1a010..4b3b2f89 100644 --- a/mysite/plots/views.py +++ b/mysite/plots/views.py @@ -58,48 +58,118 @@ def index(request): class PackingRectContainer(View): def get(self, request, *args, **kwargs): - cc = poly.pack_polygons( PolygonEditView.polygons) - plot_steps = cc.plot_steps(render=False) - plot_steps_html = file_html(plot_steps, CDN, "my plot23") - #PackingPolygons.context["packed_polygons"]=plot_steps_html + if PolygonEditView.polygons==[]: + plot_steps_html = "No Polygon" + else: + cc = poly.pack_polygons(PolygonEditView.polygons) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + #PackingPolygons.context["packed_polygons"]=plot_steps_html return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) class PackingRotatedRectContainer(View): def get(self, request, *args, **kwargs): - cc = poly.ConvexContainer(PolygonEditView.polygons,steps=90) - plot_steps = cc.plot_steps(render=False) - plot_steps_html = file_html(plot_steps, CDN, "my plot23") - # PackingPolygons.context["packed_polygons"]=plot_steps_html + if PolygonEditView.polygons==[]: + plot_steps_html = "No Polygon" + else: + cc = poly.ConvexContainer(PolygonEditView.polygons,steps=90) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + # PackingPolygons.context["packed_polygons"]=plot_steps_html return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) - class PackingConvexContainer(View): # context = {} - def get(self, request, *args, **kwargs): - cc = poly.ConvexContainer(PolygonEditView.polygons, steps=1) - plot_steps = cc.plot_steps(render=False) - plot_steps_html = file_html(plot_steps, CDN, "my plot23") - # PackingPolygons.context["packed_polygons"]=plot_steps_html - return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) + # def get(self, request, *args, **kwargs): + # + # cc = poly.ConvexContainer(PolygonEditView.polygons, steps=1) + # plot_steps = cc.plot_steps(render=False) + # plot_steps_html = file_html(plot_steps, CDN, "my plot23") + # # PackingPolygons.context["packed_polygons"]=plot_steps_html + # return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) def post(self, request, *args, **kwargs): - angle = int(request.POST["angle"]) - cc = poly.ConvexContainer(PolygonEditView.polygons, steps=angle) - plot_steps = cc.plot_steps(render=False) - plot_steps_html = file_html(plot_steps, CDN, "my plot23") + if PolygonEditView.polygons==[]: + plot_steps_html = "No Polygon" + else: + angle = int(request.POST["angle"]) + cc = poly.ConvexContainer(PolygonEditView.polygons, steps=angle) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) +class ClearPolygons(View): + def get(self, request): + PolygonEditView.colum_data_x.clear() + PolygonEditView.colum_data_y.clear() + PolygonEditView.context["drawn_polygons"] = "No Polygons" + PolygonEditView.context["polygons_single_plot"] = "No Polygons" + PolygonEditView.polygons = [] + return HttpResponseRedirect('/test/') + +class CSVPolygons(View): + def get(self,request,): + PolygonEditView.csv_polygons = [] + PolygonEditView.polygons = PolygonEditView.drawn_polygons + PolygonEditView.context["csv_polygons"] = "Cleared" + + if len(PolygonEditView.polygons) != 0: + polygons_single_plot = poly.plot_polygons_in_single_plot(PolygonEditView.drawn_polygons, plot_height=850, plot_width=2000, + render=False) + polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") + else: + polygons_single_plot_html = "No Polygons" + PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html + return HttpResponseRedirect('/test/') + + def post(self, request, *args, **kwargs): + df = pandas.read_csv('plots/polygon.txt',sep="#") + # csv_polygons =[] + # for csv_polygon in df["Polygon"]: + # polygon_shell = eval(csv_polygon) + # polygon = poly.ConvexPolygon(polygon_shell) + # csv_polygons.append(polygon) + # plot_csv = poly.plot_polygons(csv_polygons, render=False) + # PolygonEditView.csv_polygons = csv_polygons + # PolygonEditView.polygons = PolygonEditView.drawn_polygons+csv_polygons + # polygons_single_plot = poly.plot_polygons_in_single_plot(PolygonEditView.polygons, plot_height=850, plot_width=2000, + # render=False) + # polygons_csv_plot_html = file_html(plot_csv, CDN, "my plot") + # polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") + # PolygonEditView.context["csv_polygons"] = polygons_csv_plot_html + # PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html + x_values=[] + y_values=[] + csv_polygons = df["Polygon"] + for polygon_str in csv_polygons: + polygon = eval(polygon_str) + x_tuples, y_tuples = (zip(*polygon)) + x_values= list(x_tuples) + y_values = list(y_tuples) + PolygonEditView.colum_data_x.append(x_values) + PolygonEditView.colum_data_y.append(y_values) + # PolygonEditView.colum_data_x, + # y = PolygonEditView.colum_data_y + return HttpResponseRedirect('/test/') + + + + + class PolygonEditView(View): - context={} - polygons=[] - plot_min_x= 0 - plot_max_x= 100 + context = {} + polygons = [] + drawn_polygons = [] + + #all_polygons=[] + plot_min_x = 0 + plot_max_x = 100 plot_min_y = 0 - plot_max_y= 100 - colum_data_x=[] # wil be a list of lists - colum_data_y=[] + plot_max_y = 100 + colum_data_x =[] # wil be a list of lists + colum_data_y =[] def get(self, request, *args, **kwargs): TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{1.1}, $y{1.1})"), ] source = ColumnDataSource(data=dict(x=PolygonEditView.colum_data_x, @@ -126,13 +196,6 @@ class PolygonEditView(View): def post(self, request, *args, **kwargs): - df = pandas.read_csv('plots/polygon.txt', sep="+") - csv_polygons =[] - for csv_polygon in df["Polygon"]: - polygon_shell = eval(csv_polygon) - polygon = poly.ConvexPolygon(polygon_shell) - csv_polygons.append(polygon) - print(csv_polygons) test = request.POST["your_name"] dict_poly = json.loads(test) print(dict_poly["x"]) @@ -148,28 +211,23 @@ class PolygonEditView(View): polygon_list=[] polygons_x_y_tuple = list(zip(dict_poly["x"], dict_poly["y"])) - # polygon_x_list = [] - # polygon_y_list = [] for x,y in polygons_x_y_tuple: polygon_list.append(list(zip(x,y))) - # for x,y in polygons_x_y_tuple: - # polygon_x_list.append(x) - # polygon_y_list.append(y) print(polygon_list) - real_polygons=[] + drawn_polygons=[] polygon_max_x_list=[] polygon_min_x_list = [] polygon_min_y_list = [] polygon_max_y_list=[] for polygon in polygon_list: - if len(polygon)<3: continue if polygon[0]!= polygon[-1]: polygon.append(polygon[0]) - - - polygon2 = poly.ConvexPolygon(polygon) + try: + polygon2 = poly.ConvexPolygon(polygon) + except: + print(polygon, " hast to convex Points") print("konkav",list(polygon2.shell)) #polygon_parent_class = polygon2.convex_hull #polygon2 = poly.Polygon2(list(polygon_parent_class.exterior.coords)) @@ -177,26 +235,28 @@ class PolygonEditView(View): polygon_min_x_list.append(polygon2.min_x) polygon_max_y_list.append(polygon2.max_y) polygon_min_y_list.append(polygon2.min_y) - real_polygons.append(polygon2) - all_polygons = real_polygons + csv_polygons - PolygonEditView.polygons = all_polygons + drawn_polygons.append(polygon2) + PolygonEditView.drawn_polygons = drawn_polygons + PolygonEditView.polygons = drawn_polygons PolygonEditView.plot_max_y = max(polygon_max_y_list) PolygonEditView.plot_min_y = min(polygon_min_y_list) PolygonEditView.plot_max_x = max(polygon_max_x_list) PolygonEditView.plot_min_x = min(polygon_min_x_list) - polygons_single_plot = poly.plot_polygons_in_single_plot(all_polygons,plot_height=850, plot_width=2000,render=False) - plot = poly.plot_polygons(all_polygons,render=False) + polygons_single_plot = poly.plot_polygons_in_single_plot(drawn_polygons,plot_height=850, plot_width=2000,render=False) + plot_drawn = poly.plot_polygons(drawn_polygons,render=False) + #plot_csv = poly.plot_polygons(csv_polygons, render=False) # print(type(test)) # p = figure() # p.multi_line("x", "y", source=source) - polygons_plot_html= file_html(plot, CDN, "my plot") + polygons_dawn_plot_html = file_html(plot_drawn, CDN, "my plot") + #polygons_csv_plot_html = file_html(plot_csv, CDN, "my plot") polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") #self.polygons.append(response2) - PolygonEditView.context["polygons_plot"]= polygons_plot_html + PolygonEditView.context["drawn_polygons"] = polygons_dawn_plot_html + #PolygonEditView.context["csv_polygons"] = polygons_csv_plot_html PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html - return HttpResponseRedirect('/test/') diff --git a/mysite/plots/views2_with_csv.py b/mysite/plots/views2_with_csv.py new file mode 100644 index 00000000..3592f144 --- /dev/null +++ b/mysite/plots/views2_with_csv.py @@ -0,0 +1,246 @@ +from django.shortcuts import render + +# Create your views here. + +import json +from django.shortcuts import render +from django.views import View + + +from django.http import HttpResponseRedirect +import plots.packing_algo as poly +from bokeh.embed import file_html +from bokeh.models import BoxZoomTool +from django.views.generic import TemplateView +import matplotlib +from django.http import JsonResponse + +from django.http import HttpResponse +import pdb;pdb.set_trace +import matplotlib.pyplot as plt +import mpld3 + +import math +from plots import plot_helpers +from bokeh.plotting import figure, output_file, show +from bokeh.resources import CDN +from bokeh.models.widgets import Panel, Tabs +from bokeh.layouts import layout +from bokeh.models.widgets import Tabs, Panel +from bokeh.io import curdoc +from bokeh.plotting import figure +from bokeh.layouts import column +from bokeh.models import CustomJS, ColumnDataSource +from bokeh.plotting import Figure +from bokeh.models import ColumnDataSource, CustomJS, Slider +from bokeh.embed import components +from bokeh.embed import json_item +from bokeh.events import ButtonClick +import numpy as np +from bokeh.models import PolyDrawTool, PolyEditTool +from bokeh.models.callbacks import CustomJS +from bokeh.embed import json_item +import json +import pandas + + +def index(request): + + convex_polygons = poly.create_multiple_convex_polygons(10,9) + cc = poly.ConvexContainer(convex_polygons) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot2") + + return render(request, 'plots/index_new.html', context={"plot_steps":plot_steps_html}) + + # 'high_classes': plot_high_class_list,}) + # 'hc_container': hc_container}) + +class PackingRectContainer(View): + def get(self, request, *args, **kwargs): + cc = poly.pack_polygons( PolygonEditView.polygons) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + #PackingPolygons.context["packed_polygons"]=plot_steps_html + return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) + + +class PackingRotatedRectContainer(View): + def get(self, request, *args, **kwargs): + cc = poly.ConvexContainer(PolygonEditView.polygons,steps=90) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + # PackingPolygons.context["packed_polygons"]=plot_steps_html + return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) + + +class CSVPolygons(View): + def get(self,request,): + PolygonEditView.csv_polygons = [] + PolygonEditView.polygons = PolygonEditView.drawn_polygons + PolygonEditView.context["csv_polygons"] = "Cleared" + + if len(PolygonEditView.polygons) != 0: + polygons_single_plot = poly.plot_polygons_in_single_plot(PolygonEditView.drawn_polygons, plot_height=850, plot_width=2000, + render=False) + polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") + else: + polygons_single_plot_html = "No Polygons" + PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html + return HttpResponseRedirect('/test/') + + def post(self, request, *args, **kwargs): + df = pandas.read_csv('plots/polygon.txt',sep="#") + csv_polygons =[] + for csv_polygon in df["Polygon"]: + polygon_shell = eval(csv_polygon) + polygon = poly.ConvexPolygon(polygon_shell) + csv_polygons.append(polygon) + plot_csv = poly.plot_polygons(csv_polygons, render=False) + PolygonEditView.csv_polygons = csv_polygons + PolygonEditView.polygons = PolygonEditView.drawn_polygons+csv_polygons + polygons_single_plot = poly.plot_polygons_in_single_plot(PolygonEditView.polygons, plot_height=850, plot_width=2000, + render=False) + polygons_csv_plot_html = file_html(plot_csv, CDN, "my plot") + polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") + PolygonEditView.context["csv_polygons"] = polygons_csv_plot_html + PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html + x_values=[] + y_values=[] + # for polygon in csv_polygons: + # PolygonEditView.colum_data_x.append(polygon.x_values) + # PolygonEditView.colum_data_y.append(polygon.y_values) + #PolygonEditView.colum_data_x, + #y = PolygonEditView.colum_data_y + return HttpResponseRedirect('/test/') + + +class PackingConvexContainer(View): + # context = {} + def get(self, request, *args, **kwargs): + cc = poly.ConvexContainer(PolygonEditView.polygons, steps=1) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + # PackingPolygons.context["packed_polygons"]=plot_steps_html + return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) + def post(self, request, *args, **kwargs): + angle = int(request.POST["angle"]) + cc = poly.ConvexContainer(PolygonEditView.polygons, steps=angle) + plot_steps = cc.plot_steps(render=False) + plot_steps_html = file_html(plot_steps, CDN, "my plot23") + return render(request, 'plots/index_new.html', context={"plot_steps": plot_steps_html}) + + + +class PolygonEditView(View): + context = {} + polygons = [] + drawn_polygons=[] + csv_polygons = [] + #all_polygons=[] + plot_min_x = 0 + plot_max_x = 100 + plot_min_y = 0 + plot_max_y = 100 + colum_data_x =[] # wil be a list of lists + colum_data_y =[] + def get(self, request, *args, **kwargs): + TOOLTIPS = [("index", "$index"), ("(x,y)", "($x{1.1}, $y{1.1})"), ] + source = ColumnDataSource(data=dict(x=PolygonEditView.colum_data_x, + y=PolygonEditView.colum_data_y), + name='my-data-source') + + p = figure(x_range=(PolygonEditView.plot_min_x, PolygonEditView.plot_max_x), y_range=(PolygonEditView.plot_min_y, PolygonEditView.plot_max_y), width=1000, height=1000, + title='Poly Edit Tool', tooltips=TOOLTIPS) + p.aspect_ratio = 1 + p1 = p.patches("x", "y", fill_alpha=0.4, source=source, fill_color="red") + + c1 = p.circle([], [], size=10, color='red', ) + + draw_tool = PolyDrawTool(renderers=[p1]) + edit_tool = PolyEditTool(renderers=[p1], vertex_renderer=c1) + + p.add_tools(draw_tool, edit_tool) + p.toolbar.active_drag = draw_tool + response = file_html(p, CDN, "my plot") + PolygonEditView.context["response"] = response + + + return render(request, 'plots/test.html', PolygonEditView.context) + + def post(self, request, *args, **kwargs): + + # df = pandas.read_csv('plots/polygon.txt', sep="+") + # csv_polygons =[] + # for csv_polygon in df["Polygon"]: + # polygon_shell = eval(csv_polygon) + # polygon = poly.ConvexPolygon(polygon_shell) + # csv_polygons.append(polygon) + # print(csv_polygons) + test = request.POST["your_name"] + dict_poly = json.loads(test) + print(dict_poly["x"]) + print(dict_poly["y"]) + PolygonEditView.colum_data_x.clear() + PolygonEditView.colum_data_y.clear() + + for poly_x in dict_poly["x"]: + PolygonEditView.colum_data_x.append(poly_x) + for poly_y in dict_poly["y"]: + PolygonEditView.colum_data_y.append(poly_y) + + + polygon_list=[] + polygons_x_y_tuple = list(zip(dict_poly["x"], dict_poly["y"])) + # polygon_x_list = [] + # polygon_y_list = [] + for x,y in polygons_x_y_tuple: + polygon_list.append(list(zip(x,y))) + # for x,y in polygons_x_y_tuple: + # polygon_x_list.append(x) + # polygon_y_list.append(y) + print(polygon_list) + drawn_polygons=[] + polygon_max_x_list=[] + polygon_min_x_list = [] + polygon_min_y_list = [] + polygon_max_y_list=[] + for polygon in polygon_list: + if len(polygon)<3: + continue + if polygon[0]!= polygon[-1]: + polygon.append(polygon[0]) + polygon2 = poly.ConvexPolygon(polygon) + print("konkav",list(polygon2.shell)) + #polygon_parent_class = polygon2.convex_hull + #polygon2 = poly.Polygon2(list(polygon_parent_class.exterior.coords)) + polygon_max_x_list.append(polygon2.max_x) + polygon_min_x_list.append(polygon2.min_x) + polygon_max_y_list.append(polygon2.max_y) + polygon_min_y_list.append(polygon2.min_y) + drawn_polygons.append(polygon2) + PolygonEditView.drawn_polygons = drawn_polygons + all_polygons = drawn_polygons + self.csv_polygons + PolygonEditView.polygons = all_polygons + PolygonEditView.plot_max_y = max(polygon_max_y_list) + PolygonEditView.plot_min_y = min(polygon_min_y_list) + PolygonEditView.plot_max_x = max(polygon_max_x_list) + PolygonEditView.plot_min_x = min(polygon_min_x_list) + + + polygons_single_plot = poly.plot_polygons_in_single_plot(all_polygons,plot_height=850, plot_width=2000,render=False) + plot_drawn = poly.plot_polygons(drawn_polygons,render=False) + #plot_csv = poly.plot_polygons(csv_polygons, render=False) + # print(type(test)) + # p = figure() + # p.multi_line("x", "y", source=source) + polygons_dawn_plot_html = file_html(plot_drawn, CDN, "my plot") + #polygons_csv_plot_html = file_html(plot_csv, CDN, "my plot") + polygons_single_plot_html = file_html(polygons_single_plot, CDN, "single plot") + #self.polygons.append(response2) + PolygonEditView.context["drawn_polygons"] = polygons_dawn_plot_html + #PolygonEditView.context["csv_polygons"] = polygons_csv_plot_html + PolygonEditView.context["polygons_single_plot"] = polygons_single_plot_html + + return HttpResponseRedirect('/test/') + -- GitLab