You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

90 lines
2.5 KiB

[<link rel="stylesheet" type="text/css" href="(#CHEMIN{css/spip_d3_graph.css})" />]
[<link rel="stylesheet" type="text/css" href="(#CHEMIN{css/spip_d3_statistiques.css})" />]
[<script type="text/javascript" src="(#CHEMIN{lib/d3/d3.min.js})"></script>]
[<script type="text/javascript" src="(#CHEMIN{javascript/spip_d3_graph.js})"></script>]
[<script type="text/javascript" src="(#CHEMIN{javascript/spip_d3_statistiques.js})"></script>]
<script type="text/javascript">
function spip_d3_statistiques_create(id, options = {}) {
if (jQuery(id).data('graph')) {
return;
}
const $nav = jQuery(id).parent().find('.statistiques-nav');
if ($nav.find('.groupe-boutons--stats-graph .bouton.principal').length) {
jQuery(id)[0].dataset.json = $nav.find('.groupe-boutons--stats-graph .bouton.principal').data('json');
}
const table_visible = !!$nav.find('.btn--stats-to-table.principal').length;
const graph = new Spip_d3_graph(id, {
language: '#ENV{lang}',
d3_directory: '[(#CHEMIN{lib/d3/d3.min.js}|dirname)]',
});
jQuery(id).data('graph', graph);
graph.set_dataLoader(data => {
// ici on peuple les dates manquantes du json
return new Promise((resolve, reject) => {
function fillInDates(meta, data){
// put current data hash for efficient retrieval
// determine min/max of data
const currentDates = {};
const minDate = meta.start_date;
let currentDate = minDate;
const maxDate = meta.end_date;
data.forEach(d => {
currentDates[d.date] = d;
});
// loop data and fill in missing dates
const filledInDates = [];
while (currentDate < maxDate) {
if (currentDates[currentDate]) {
filledInDates.push(currentDates[currentDate]);
} else {
filledInDates.push({"date": currentDate, "visites": 0});
}
currentDate = graph.nextDate(currentDate, meta.unite, 1);
}
return filledInDates;
}
data.data = fillInDates(data.meta, data.data);
resolve(data);
})
.then(data => {
graph.update_table(data);
spip_d3_statistiques_update_graph(id, data);
});
});
graph.loading_start();
Promise.resolve()
.then((d) => {
// charger la locale de date avant de créer les axes… sinon ils ne sont pas traduits
return graph.localize_d3_time(d);
})
.then(() => {
graph.prepare_table(table_visible);
spip_d3_statistiques_prepare_graph(id, !table_visible);
graph.updateJson();
});
}
function spip_dessiner_statistiques(){
spip_d3_statistiques_create("#statistiques_visites");
}
jQuery(function($) {
spip_dessiner_statistiques();
onAjaxLoad(spip_dessiner_statistiques);
});
</script>