mirror of
https://github.com/house-of-vanity/libopenanal.git
synced 2025-07-07 13:44:07 +00:00
plot improvements.
This commit is contained in:
@ -8,9 +8,8 @@
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
|
||||
crossorigin="anonymous">
|
||||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
|
||||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="../static/css/style.css">
|
||||
<title>libOpenAnal appliance</title>
|
||||
{% endblock %}
|
||||
|
@ -115,39 +115,69 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="card text-center">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Charts</h5>
|
||||
|
||||
<span class="badge {% if 'bar' == plot_type %} badge-primary {% endif %}" id="bar" onclick="plot_type_changer(this.id)">Bars</span>
|
||||
<span class="badge {% if 'scatter' == plot_type %} badge-primary {% endif %}" id="scatter" onclick="plot_type_changer(this.id)">Lines</span>
|
||||
<div id="words_chart">
|
||||
</div>
|
||||
<div id="messages_chart">
|
||||
</div>
|
||||
<script>
|
||||
function plot_type_changer(type="bar") {
|
||||
location.href = URL_add_parameter(location.href, 'plot_type', type);
|
||||
}
|
||||
function URL_add_parameter(url, param, value) {
|
||||
var hash = {};
|
||||
var parser = document.createElement('a');
|
||||
|
||||
parser.href = url;
|
||||
|
||||
var parameters = parser.search.split(/\?|&/);
|
||||
|
||||
for (var i = 0; i < parameters.length; i++) {
|
||||
if (!parameters[i])
|
||||
continue;
|
||||
|
||||
var ary = parameters[i].split('=');
|
||||
hash[ary[0]] = ary[1];
|
||||
}
|
||||
|
||||
hash[param] = value;
|
||||
|
||||
var list = [];
|
||||
Object.keys(hash).forEach(function (key) {
|
||||
list.push(key + '=' + hash[key]);
|
||||
});
|
||||
|
||||
parser.search = '?' + list.join('&');
|
||||
return parser.href;
|
||||
}
|
||||
var user_id = {{ user_info.id }};
|
||||
var plot_data = [];
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/data',
|
||||
data: { action: 'user_word_count', user: user_id },
|
||||
data: { action: 'user_word_count', user: user_id, plot_type: "{{ plot_type }}" },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
plot_data[0] = data[0];
|
||||
write_plot()
|
||||
_write_plot();
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/data',
|
||||
data: { action: 'user_message_count', user: user_id },
|
||||
data: { action: 'user_message_count', user: user_id, plot_type: "{{ plot_type }}" },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
plot_data[1] = data[0];
|
||||
write_plot()
|
||||
_write_plot();
|
||||
}
|
||||
});
|
||||
function write_plot() {
|
||||
function _write_plot() {
|
||||
var layout = {
|
||||
title: 'Words per day',
|
||||
title: 'Daily plot',
|
||||
showlegend: false,
|
||||
//autosize: false,
|
||||
//width: 500,
|
||||
|
Reference in New Issue
Block a user