Skip to content

Commit

Permalink
Merge pull request #421 from freezingsaddles/c3-various
Browse files Browse the repository at this point in the history
Remove all usage of google charts
  • Loading branch information
merlinorg authored Jan 19, 2025
2 parents 630c993 + a37a325 commit 27a4787
Show file tree
Hide file tree
Showing 16 changed files with 736 additions and 1,762 deletions.
2 changes: 1 addition & 1 deletion freezing/web/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ div.row > div > div.row, .big-bottom {
margin-bottom: 15px;
}

iframe, .g-chart svg {
iframe {
border-radius: var(--bs-border-radius);
}

Expand Down
4 changes: 3 additions & 1 deletion freezing/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Raleway:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet">
<script src="https://www.gstatic.com/charts/loader.js"></script>
{% block head %}
{% endblock %}
</head>
Expand Down Expand Up @@ -172,6 +171,9 @@
<li>
<a class="dropdown-item" href="/explore/distance_by_lowtemp">Distance vs. Avg Low Temp</a>
</li>
<li>
<a class="dropdown-item" href="/explore/riders_by_lowtemp">Riders vs. Avg Low Temp</a>
</li>
<li>
<a class="dropdown-item" href="/explore/indiv_elev_dist">Individual Dist/Elev/Speed</a>
</li>
Expand Down
129 changes: 65 additions & 64 deletions freezing/web/templates/explore/distance_by_lowtemp.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,85 @@
integrity="sha384-xOzJ6ocROuPNeY/PUgXyXgiPyvvePCiWVkKXro4Lb1gWoGJOtrJw+zrpf3NBx1B5"
crossorigin="anonymous"></script>
<script type="text/javascript">
$(function () {
function requestData() {
$.ajax({
url: '/chartdata/distance_by_lowtemp',
success: function(data) {
var chart = c3.generate({
data: {
x: 'x',
columns: [
['x'].concat(data.data.map(val => new Date(val.date.year, val.date.month - 1, val.date.day))),
['distance'].concat(data.data.map(val => val.distance)),
['low_temp'].concat(data.data.map(val => val.low_temp))
],
type: 'bar',
types: {
low_temp: 'spline'
},
axes: {
low_temp: 'y2'
},
names: {
distance: 'Total Distance',
low_temp: 'Temperature'
},
$(() => {
$.ajax({
url: '/chartdata/distance_by_lowtemp',
success: function(data) {
c3.generate({
data: {
x: 'x',
columns: [
['x'].concat(data.data.map(val => new Date(val.date.year, val.date.month - 1, val.date.day))),
['distance'].concat(data.data.map(val => val.distance)),
['low_temp'].concat(data.data.map(val => val.low_temp))
],
type: 'bar',
types: {
low_temp: 'spline'
},
axes: {
low_temp: 'y2'
},
names: {
distance: 'Total Distance',
low_temp: 'Temperature'
},
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%-m/%-d'
}
},
y: {
label: {
text: 'Total Distance',
position: 'outer-middle'
},
axis: {
x: {
type: 'timeseries',
tick: {
format: '%-m/%-d'
}
},
y: {
label: {
text: 'Total Distance',
position: 'outer-middle'
},
tick: {
format: (d) => Math.round(d) + ' mi'
}
},
y2: {
show: true,
label: {
text: 'Temperature',
position: 'outer-middle'
},
tick: {
format: (d) => d + '°F'
}
}
tick: {
format: (d) => Math.round(d) + ' mi'
}
},
y2: {
show: true,
label: {
text: 'Temperature',
position: 'outer-middle'
},
tooltip: {
format: {
value: (value, ratio, id) =>
Math.round(value) + (id === 'distance' ? ' mi' : '°F')
}
tick: {
format: (d) => d + '°F'
}
});
}
},
cache: false
});
}

requestData();
tooltip: {
format: {
value: (value, ratio, id) =>
Math.round(value) + (id === 'distance' ? ' mi' : '°F')
}
}
});
}
});
});
</script>
{% endblock %}
{% block content %}
<!--Div that will hold our leaderboard chart-->
<div class="text-center">
<strong>Miles Logged vs. Avg. Low Temp</strong>
</div>
<div class="text-center text-muted small">
Relationship between total number of miles logged riders and the average low daily temperatures.
</div>
{# djlint:off H021 #}
<!--Div that will hold our leaderboard chart-->
<div id="chart" style="width:100%; height:560px;">
{# djlint:on #}
<svg width="48"
height="48"
viewBox="0 0 24 24"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg">
<style>.spinner_zWVm{animation:spinner_5QiW 1.2s linear infinite,spinner_PnZo 1.2s linear infinite}.spinner_gfyD{animation:spinner_5QiW 1.2s linear infinite,spinner_4j7o 1.2s linear infinite;animation-delay:.1s}.spinner_T5JJ{animation:spinner_5QiW 1.2s linear infinite,spinner_fLK4 1.2s linear infinite;animation-delay:.1s}.spinner_E3Wz{animation:spinner_5QiW 1.2s linear infinite,spinner_tDji 1.2s linear infinite;animation-delay:.2s}.spinner_g2vs{animation:spinner_5QiW 1.2s linear infinite,spinner_CMiT 1.2s linear infinite;animation-delay:.2s}.spinner_ctYB{animation:spinner_5QiW 1.2s linear infinite,spinner_cHKR 1.2s linear infinite;animation-delay:.2s}.spinner_BDNj{animation:spinner_5QiW 1.2s linear infinite,spinner_Re6e 1.2s linear infinite;animation-delay:.3s}.spinner_rCw3{animation:spinner_5QiW 1.2s linear infinite,spinner_EJmJ 1.2s linear infinite;animation-delay:.3s}.spinner_Rszm{animation:spinner_5QiW 1.2s linear infinite,spinner_YJOP 1.2s linear infinite;animation-delay:.4s}@keyframes spinner_5QiW{0%,50%{width:7.33px;height:7.33px}25%{width:1.33px;height:1.33px}}@keyframes spinner_PnZo{0%,50%{x:1px;y:1px}25%{x:4px;y:4px}}@keyframes spinner_4j7o{0%,50%{x:8.33px;y:1px}25%{x:11.33px;y:4px}}@keyframes spinner_fLK4{0%,50%{x:1px;y:8.33px}25%{x:4px;y:11.33px}}@keyframes spinner_tDji{0%,50%{x:15.66px;y:1px}25%{x:18.66px;y:4px}}@keyframes spinner_CMiT{0%,50%{x:8.33px;y:8.33px}25%{x:11.33px;y:11.33px}}@keyframes spinner_cHKR{0%,50%{x:1px;y:15.66px}25%{x:4px;y:18.66px}}@keyframes spinner_Re6e{0%,50%{x:15.66px;y:8.33px}25%{x:18.66px;y:11.33px}}@keyframes spinner_EJmJ{0%,50%{x:8.33px;y:15.66px}25%{x:11.33px;y:18.66px}}@keyframes spinner_YJOP{0%,50%{x:15.66px;y:15.66px}25%{x:18.66px;y:18.66px}}</style><rect class="spinner_zWVm" x="1" y="1" width="7.33" height="7.33" /><rect class="spinner_gfyD" x="8.33" y="1" width="7.33" height="7.33" /><rect class="spinner_T5JJ" x="1" y="8.33" width="7.33" height="7.33" /><rect class="spinner_E3Wz" x="15.66" y="1" width="7.33" height="7.33" /><rect class="spinner_g2vs" x="8.33" y="8.33" width="7.33" height="7.33" /><rect class="spinner_ctYB" x="1" y="15.66" width="7.33" height="7.33" /><rect class="spinner_BDNj" x="15.66" y="8.33" width="7.33" height="7.33" /><rect class="spinner_rCw3" x="8.33" y="15.66" width="7.33" height="7.33" /><rect class="spinner_Rszm" x="15.66" y="15.66" width="7.33" height="7.33" />
</svg>
&nbsp;Loading chart data...
</div>
{% endblock %}
112 changes: 71 additions & 41 deletions freezing/web/templates/explore/indiv_elev_dist.html
Original file line number Diff line number Diff line change
@@ -1,51 +1,81 @@
{% extends "base.html" %}
{% block head %}
<script type="text/javascript">
google.charts.load("visualization", "1", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.

function drawChart() {

$.ajax({
url: "/chartdata/indiv_elev_dist",
dataType: "json"
}).done(function(jsonData) {

// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BubbleChart(document.getElementById('chart_div'));
var width = $('#chart_div').width();
var options = {
title: 'Correlation between distance, elevation, and average speed.',
hAxis: {title: 'Distance'},
vAxis: {title: 'Elevation'},
height: 800,
width: width,
legend: {position: 'none'},
bubble: {textStyle: {fontSize: 11}},
chartArea: {left: 125, top: 50, width: width - 175, height: 700},
};


chart.draw(data, options);
});
}

</script>
{% block foot %}
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.css"
integrity="sha384-ztqQYuF0ztQOO26+6hbRTtSQ6HGLosUJRQI9kx0L9OpJiESTtsiriiQNqwBIBl9a"
crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.8.0/d3.min.js"
integrity="sha384-Nth41CoN2s0hj2li43h7cs5a1J0zroMLa7ugSGFSdWJMF1OuKrJwZaritPHBnk3E"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.min.js"
integrity="sha384-xOzJ6ocROuPNeY/PUgXyXgiPyvvePCiWVkKXro4Lb1gWoGJOtrJw+zrpf3NBx1B5"
crossorigin="anonymous"></script>
<script type="text/javascript">
var pattern = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728', '#ff9896', '#9467bd', '#c5b0d5', '#8c564b', '#c49c94', '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7', '#bcbd22', '#dbdb8d', '#17becf', '#9edae5'];
$(() => {
$.ajax({
url: "/chartdata/indiv_elev_dist",
dataType: "json"
}).done(function (jsonData) {
c3.generate({
bindto: '#chart_div',
data: {
type: 'scatter',
x: 'distance',
y: 'elevation',
columns: [
['distance', ...jsonData.distances],
['elevation', ...jsonData.elevations],
],
color: (a, {index}) => pattern[index % pattern.length],
},
axis: {
x: {
label: 'Miles',
tick: {
fit: false,
format: d => d.toLocaleString(),
},
},
y: {
label: 'Feet',
padding: 20,
tick: {
format: d => d.toLocaleString(),
}
}
},
point: {
r: ({index}) => jsonData.speeds[index],
},
tooltip: {
contents: function ([{index}]) {
return "<table class='" + this.CLASS.tooltip + "'>" +
"<tr><th colspan='2'>" + jsonData.labels[index] + "</th></tr>" +
"<tr><td class='name'>distance</td><td class='value'>" + Math.round(jsonData.distances[index]).toLocaleString() + " mi</td></tr>" +
"<tr><td class='name'>elevation</td><td class='value'>" + Math.round(jsonData.elevations[index]).toLocaleString() + " feet</td></tr>" +
"<tr><td class='name'>speed</td><td class='value'>" + +jsonData.speeds[index]?.toFixed(1) + "mph</td></tr>" +
"</table>";
}
},
legend: {
show: false
}
});
});
});
</script>
{% endblock %}
{% block content %}
<h1>
Individual Distance, Elevation, Speed
</h1>
<div class="text-center mt-3">
<strong>Correlation between distance, elevation and average speed</strong>
</div>
<!--Div that will hold our leaderboard chart-->
<div id="chart_div" class="g-chart">
<div id="chart_div" style="width:100%; aspect-ratio: 1.333">
<svg width="48" height="48" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><style>.spinner_zWVm{animation:spinner_5QiW 1.2s linear infinite,spinner_PnZo 1.2s linear infinite}.spinner_gfyD{animation:spinner_5QiW 1.2s linear infinite,spinner_4j7o 1.2s linear infinite;animation-delay:.1s}.spinner_T5JJ{animation:spinner_5QiW 1.2s linear infinite,spinner_fLK4 1.2s linear infinite;animation-delay:.1s}.spinner_E3Wz{animation:spinner_5QiW 1.2s linear infinite,spinner_tDji 1.2s linear infinite;animation-delay:.2s}.spinner_g2vs{animation:spinner_5QiW 1.2s linear infinite,spinner_CMiT 1.2s linear infinite;animation-delay:.2s}.spinner_ctYB{animation:spinner_5QiW 1.2s linear infinite,spinner_cHKR 1.2s linear infinite;animation-delay:.2s}.spinner_BDNj{animation:spinner_5QiW 1.2s linear infinite,spinner_Re6e 1.2s linear infinite;animation-delay:.3s}.spinner_rCw3{animation:spinner_5QiW 1.2s linear infinite,spinner_EJmJ 1.2s linear infinite;animation-delay:.3s}.spinner_Rszm{animation:spinner_5QiW 1.2s linear infinite,spinner_YJOP 1.2s linear infinite;animation-delay:.4s}@keyframes spinner_5QiW{0%,50%{width:7.33px;height:7.33px}25%{width:1.33px;height:1.33px}}@keyframes spinner_PnZo{0%,50%{x:1px;y:1px}25%{x:4px;y:4px}}@keyframes spinner_4j7o{0%,50%{x:8.33px;y:1px}25%{x:11.33px;y:4px}}@keyframes spinner_fLK4{0%,50%{x:1px;y:8.33px}25%{x:4px;y:11.33px}}@keyframes spinner_tDji{0%,50%{x:15.66px;y:1px}25%{x:18.66px;y:4px}}@keyframes spinner_CMiT{0%,50%{x:8.33px;y:8.33px}25%{x:11.33px;y:11.33px}}@keyframes spinner_cHKR{0%,50%{x:1px;y:15.66px}25%{x:4px;y:18.66px}}@keyframes spinner_Re6e{0%,50%{x:15.66px;y:8.33px}25%{x:18.66px;y:11.33px}}@keyframes spinner_EJmJ{0%,50%{x:8.33px;y:15.66px}25%{x:11.33px;y:18.66px}}@keyframes spinner_YJOP{0%,50%{x:15.66px;y:15.66px}25%{x:18.66px;y:18.66px}}</style><rect class="spinner_zWVm" x="1" y="1" width="7.33" height="7.33"/><rect class="spinner_gfyD" x="8.33" y="1" width="7.33" height="7.33"/><rect class="spinner_T5JJ" x="1" y="8.33" width="7.33" height="7.33"/><rect class="spinner_E3Wz" x="15.66" y="1" width="7.33" height="7.33"/><rect class="spinner_g2vs" x="8.33" y="8.33" width="7.33" height="7.33"/><rect class="spinner_ctYB" x="1" y="15.66" width="7.33" height="7.33"/><rect class="spinner_BDNj" x="15.66" y="8.33" width="7.33" height="7.33"/><rect class="spinner_rCw3" x="8.33" y="15.66" width="7.33" height="7.33"/><rect class="spinner_Rszm" x="15.66" y="15.66" width="7.33" height="7.33"/></svg>
&nbsp;Loading correlation chart...
&nbsp;Loading chart data...
</div>
{% endblock %}
Loading

0 comments on commit 27a4787

Please sign in to comment.