diff --git a/amadeus/static/js/charts/home.js b/amadeus/static/js/charts/home.js new file mode 100644 index 0000000..52ea3c1 --- /dev/null +++ b/amadeus/static/js/charts/home.js @@ -0,0 +1,62 @@ +/* + HOME CHARTS +*/ + +//Adding this code by @jshanley to create a filter to look for the last child + +d3.selection.prototype.first = function() { + return d3.select(this[0]); +}; +d3.selection.prototype.last = function() { + var last = this.size() - 1; + return d3.select(this[last]); +}; + +var resource_donut_chart = { + build: function(url){ + $.get(url, function(dataset){ + + + var width = 360; + var height = 400; + var radius = Math.min(width, height) / 2; + + var color = d3.scaleOrdinal(d3.schemeCategory20c); + var new_div = d3.select(".carousel-inner").append("div").attr("class","item"); + var svg = new_div.append("svg").attr("width", width).attr("height", height) + .style("margin","auto") + .style("display","block") + .append('g') + .attr('transform', 'translate(' + (width / 2) + + ',' + (height / 2) + ')'); + + + var donutInner = 50; + var arc = d3.arc() + .innerRadius(radius - donutInner) + .outerRadius(radius); + + svg.append("text") + .attr("x", (width / 2)) + .attr("y", 0 - (height / 2)) + .attr("text-anchor", "middle") + .style("font-size", "16px") + .text("Recurso mais utilizado"); + + var pie = d3.pie() + .value(function(d) { return d[1]; }) + .sort(null); + + var path = svg.selectAll('path') + .data(pie(dataset)) + .enter() + .append('path') + .attr('d', arc) + .attr('fill', function(d, i) { + return color(i); + }); + }) // end of the get method + } +} + +resource_donut_chart.build('/topics/count_resources/'); \ No newline at end of file diff --git a/amadeus/static/js/main.js b/amadeus/static/js/main.js index 59aa8cc..4d6e05b 100755 --- a/amadeus/static/js/main.js +++ b/amadeus/static/js/main.js @@ -35,3 +35,5 @@ var change_language = { } } + + diff --git a/subjects/templates/subjects/initial.html b/subjects/templates/subjects/initial.html index 8a7d7c6..2e733ca 100644 --- a/subjects/templates/subjects/initial.html +++ b/subjects/templates/subjects/initial.html @@ -28,37 +28,26 @@ @@ -93,6 +82,7 @@ + - + {% endblock content %} \ No newline at end of file diff --git a/topics/urls.py b/topics/urls.py index 7063692..4f91162 100644 --- a/topics/urls.py +++ b/topics/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ url(r'^view_log/(?P[\w_-]+)/$', views.topic_view_log, name = 'view_log'), url(r'^update_order/$', views.update_order, name = 'update_order'), url(r'^update_resource_order/$', views.update_resource_order, name = 'update_resource_order'), + url(r'^count_resources/$', views.getResourceCount, name='resource_count'), ] diff --git a/topics/views.py b/topics/views.py index 8e1acbf..0041874 100644 --- a/topics/views.py +++ b/topics/views.py @@ -260,4 +260,23 @@ def update_resource_order(request): return JsonResponse({'message': 'ok'}) - return JsonResponse({'message': 'No data received'}) \ No newline at end of file + return JsonResponse({'message': 'No data received'}) + + +def getResourceCount(request): + resources = Resource.objects.distinct() + + data = {} + for resource in resources: + key = resource.__dict__['_my_subclass'] + if key in data.keys(): + data[key] = data[key] + 1 + else: + data[key] = 1 + + data["test"] = 30 + data["azul"] = 20 + real_data = [] + for item in data.items(): + real_data.append(item) + return JsonResponse(real_data, safe=False) -- libgit2 0.21.2