Browse Source

finishing touches to stats page

pull/10/head
crunch 6 months ago
parent
commit
4e9d1398ae
8 changed files with 32 additions and 78 deletions
  1. +1
    -1
      Consulta_project/landing/static/js/bundle.js
  2. +14
    -1
      Consulta_project/landing/static/js/stats.js
  3. +14
    -1
      Consulta_project/landing/static/js/stats_compiled.js
  4. +0
    -37
      Consulta_project/landing/static/js/stats_test.js
  5. +0
    -33
      Consulta_project/landing/static/js/stats_test_compiled.js
  6. +1
    -1
      Consulta_project/polls/templates/polls/stats.html
  7. +0
    -2
      Consulta_project/polls/views.py
  8. +2
    -2
      utils/compile_&_bundle.sh

+ 1
- 1
Consulta_project/landing/static/js/bundle.js
File diff suppressed because it is too large
View File


+ 14
- 1
Consulta_project/landing/static/js/stats.js View File

@@ -83,6 +83,19 @@ function createBarChart(series, labels, target_id) {

function createPieChart(series, labels, target_id) {
/* console.log(series + " " + labels + " " + target_id); */
var colorArray = [];

function dynamicColor() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
return "rgb(" + r + "," + g + "," + b + ")";
}

for (const d in series) {
colorArray.push(dynamicColor())
}

var ctx = document.getElementById(target_id).getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
@@ -92,7 +105,7 @@ function createPieChart(series, labels, target_id) {
data: {
labels: labels,
datasets: [{
backgroundColor: 'rgb(0,188,140)',
backgroundColor: colorArray,
borderColor: '#282d32',
data: series
}]


+ 14
- 1
Consulta_project/landing/static/js/stats_compiled.js View File

@@ -157,6 +157,19 @@ function createBarChart(series, labels, target_id) {

function createPieChart(series, labels, target_id) {
/* console.log(series + " " + labels + " " + target_id); */
var colorArray = [];

function dynamicColor() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
return "rgb(" + r + "," + g + "," + b + ")";
}

for (var d in series) {
colorArray.push(dynamicColor());
}

var ctx = document.getElementById(target_id).getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
@@ -165,7 +178,7 @@ function createPieChart(series, labels, target_id) {
data: {
labels: labels,
datasets: [{
backgroundColor: 'rgb(0,188,140)',
backgroundColor: colorArray,
borderColor: '#282d32',
data: series
}]


+ 0
- 37
Consulta_project/landing/static/js/stats_test.js View File

@@ -1,37 +0,0 @@
window.onload = function() {
function createBarChart(series, labels, target_id) {
/* console.log(series + " " + labels + " " + target_id); */
var ctx = document.getElementById("stats").getContext("2d");
var chart = new Chart(ctx, {
// The type of chart we want to create
type: "bar",

// The data for our dataset
data: {
labels: ["test", "kek", "lel"],
datasets: [
{
label: "Number of votes",
backgroundColor: "rgb(0,188,140)",
borderColor: "#282d32",
data: [1, 2, 3]
}
]
},

// Configuration options go here
options: {
events: null,
scales: {
yAxes: [
{
ticks: {
beginAtZero: true
}
}
]
}
}
});
}
};

+ 0
- 33
Consulta_project/landing/static/js/stats_test_compiled.js View File

@@ -1,33 +0,0 @@
"use strict";

window.onload = function () {
function createBarChart(series, labels, target_id) {
/* console.log(series + " " + labels + " " + target_id); */
var ctx = document.getElementById("stats").getContext("2d");
var chart = new Chart(ctx, {
// The type of chart we want to create
type: "bar",
// The data for our dataset
data: {
labels: ["test", "kek", "lel"],
datasets: [{
label: "Number of votes",
backgroundColor: "rgb(0,188,140)",
borderColor: "#282d32",
data: [1, 2, 3]
}]
},
// Configuration options go here
options: {
events: null,
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
};

+ 1
- 1
Consulta_project/polls/templates/polls/stats.html View File

@@ -71,6 +71,6 @@
{% endblock content %}

{% block bottom_scripts %}
<!-- <script type="text/javascript" src="{% static 'js/stats_compiled.js' %}"></script> -->
<!-- <script type="text/javascript" src="{% static 'js/stats.js' %}"></script> -->
<script type="text/javascript" src="{% static 'js/bundle.js' %}"></script>
{% endblock %}

+ 0
- 2
Consulta_project/polls/views.py View File

@@ -88,11 +88,9 @@ def vote(request, question, **kwargs):
try:
choice = question.answer_set.get(pk=request.POST['choice'])
except (KeyError, Answer.DoesNotExist):
print("Vote failed")
raise Http404
else:
choice.count += 1
print("Vote successful")
choice.save()
return HttpResponseRedirect(reverse('poll-detail', kwargs={'slug':question.poll.slug}))



+ 2
- 2
utils/compile_&_bundle.sh View File

@@ -1,2 +1,2 @@
npx babel ../Consulta_project/landing/static/js/stats.js --out-file ../Consulta_project/landing/static/js/stats_compiled.js --presets=@babel/env
webpack ../Consulta_project/landing/static/js/stats_compiled.js ../Consulta_project/landing/static/js/bundle.js
npx babel ../Consulta_project/landing/static/js/stats.js --out-file ../Consulta_project/landing/static/js/stats_compiled.js --presets=@babel/env && \
webpack ../Consulta_project/landing/static/js/stats_compiled.js --output-filename ../../Consulta_project/landing/static/js/bundle.js

Loading…
Cancel
Save