2016-07-11 13:05:04 +00:00
|
|
|
function Graph(id_pannel, path, header_size){
|
2016-07-04 09:43:38 +00:00
|
|
|
this.path = path;
|
|
|
|
this.id_pannel = id_pannel;
|
|
|
|
|
2016-07-11 13:05:04 +00:00
|
|
|
// Hide every header during initialisation
|
|
|
|
var false_tab = [];
|
|
|
|
for(i=0; i<header_size; i++){
|
|
|
|
false_tab[i] = false;
|
|
|
|
}
|
|
|
|
this.false_tab = false_tab;
|
|
|
|
|
|
|
|
g2 = new Dygraph(
|
2016-07-04 09:43:38 +00:00
|
|
|
document.getElementById(this.id_pannel),
|
|
|
|
// path to CSV file
|
|
|
|
//"{{ url_for('static', filename='csv/tldstrendingdata.csv') }}",
|
|
|
|
//"../static//csv/tldstrendingdata.csv",
|
|
|
|
this.path,
|
|
|
|
//window.csv,
|
|
|
|
{
|
|
|
|
rollPeriod: 1,
|
|
|
|
showRoller: true,
|
|
|
|
//drawPoints: true,
|
|
|
|
//fillGraph: true,
|
|
|
|
logscale: true,
|
2016-07-11 13:05:04 +00:00
|
|
|
|
2016-07-04 09:43:38 +00:00
|
|
|
animatedZooms: true,
|
|
|
|
labelsKMB: true,
|
|
|
|
highlightCircleSize: 3,
|
|
|
|
highlightSeriesOpts: {
|
|
|
|
strokeWidth: 3,
|
|
|
|
strokeBorderWidth: 1,
|
|
|
|
highlightCircleSize: 5,
|
|
|
|
},
|
|
|
|
underlayCallback: function(canvas, area, g) {
|
|
|
|
canvas.fillStyle = "rgba(255, 193, 37, 0.5)";
|
|
|
|
|
|
|
|
function highlight_period(x_start, x_end) {
|
|
|
|
var canvas_left_x = g.toDomXCoord(x_start);
|
|
|
|
var canvas_right_x = g.toDomXCoord(x_end);
|
|
|
|
var canvas_width = canvas_right_x - canvas_left_x;
|
|
|
|
canvas.fillRect(canvas_left_x, area.y, canvas_width, area.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
var min_data_x = g.getValue(0,0);
|
|
|
|
var max_data_x = g.getValue(g.numRows()-1,0);
|
|
|
|
|
|
|
|
// get day of week
|
|
|
|
var d = new Date(min_data_x);
|
|
|
|
var dow = d.getUTCDay();
|
|
|
|
var ds = d.toUTCString();
|
|
|
|
|
|
|
|
var w = min_data_x;
|
|
|
|
// starting on Sunday is a special case
|
|
|
|
if (dow == 0) {
|
|
|
|
highlight_period(w,w+12*3600*1000);
|
|
|
|
}
|
|
|
|
// find first saturday
|
|
|
|
while (dow != 5) {
|
|
|
|
w += 24*3600*1000;
|
|
|
|
d = new Date(w);
|
|
|
|
dow = d.getUTCDay();
|
|
|
|
}
|
|
|
|
|
|
|
|
// shift back 1/2 day to center highlight around the point for the day
|
|
|
|
w -= 12*3600*1000;
|
|
|
|
while (w < max_data_x) {
|
|
|
|
var start_x_highlight = w;
|
|
|
|
var end_x_highlight = w + 2*24*3600*1000;
|
|
|
|
// make sure we don't try to plot outside the graph
|
|
|
|
if (start_x_highlight < min_data_x) {
|
|
|
|
start_x_highlight = min_data_x;
|
|
|
|
}
|
|
|
|
if (end_x_highlight > max_data_x) {
|
|
|
|
end_x_highlight = max_data_x;
|
|
|
|
}
|
|
|
|
highlight_period(start_x_highlight,end_x_highlight);
|
|
|
|
// calculate start of highlight for next Saturday
|
|
|
|
w += 7*24*3600*1000;
|
|
|
|
}
|
2016-07-11 13:05:04 +00:00
|
|
|
},
|
|
|
|
visibility: false_tab
|
2016-07-04 09:43:38 +00:00
|
|
|
});
|
2016-07-11 13:05:04 +00:00
|
|
|
this.graph = g2;
|
2016-07-11 14:57:45 +00:00
|
|
|
this.set_Visibility = setVis;
|
|
|
|
this.set_Visibility_andHide = setVis_andHide;
|
2016-07-04 09:43:38 +00:00
|
|
|
|
|
|
|
onclick = function(ev) {
|
|
|
|
if (g2.isSeriesLocked()) {
|
|
|
|
g2.clearSelection();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g2.setSelection(g2.getSelection(), g2.getHighlightSeries(), true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
g2.updateOptions({clickCallback: onclick}, true);
|
|
|
|
|
|
|
|
var linear = document.getElementById("linear");
|
|
|
|
var log = document.getElementById("log");
|
|
|
|
linear.onclick = function() { setLog(false); }
|
|
|
|
log.onclick = function() { setLog(true); }
|
|
|
|
var setLog = function(val) {
|
|
|
|
g2.updateOptions({ logscale: val });
|
|
|
|
linear.disabled = !val;
|
|
|
|
log.disabled = val;
|
|
|
|
}
|
|
|
|
function unzoomGraph() {
|
|
|
|
g2.updateOptions({
|
|
|
|
dateWindow:null,
|
|
|
|
valueRange:null
|
|
|
|
});
|
|
|
|
}
|
2016-07-11 13:05:04 +00:00
|
|
|
|
|
|
|
// display the top headers
|
|
|
|
function setVis(max_display){
|
2016-08-09 09:59:36 +00:00
|
|
|
var headings = this.graph.getLabels();
|
2016-07-11 13:05:04 +00:00
|
|
|
headings.splice(0,1);
|
|
|
|
var sorted_list = new Array();
|
2016-08-09 09:59:36 +00:00
|
|
|
var today = new Date().getDate();
|
|
|
|
//today = new Date().getDate()-1; // Could take the top from yesterday so that we can see the current evolution
|
2016-07-11 13:05:04 +00:00
|
|
|
for( i=0; i<headings.length; i++){
|
2016-08-09 09:59:36 +00:00
|
|
|
var the_heading = headings[i];
|
|
|
|
//console.log('heading='+the_heading+' tab['+(today)+']['+(parseInt(i)+1)+']='+this.graph.getValue(today-1, parseInt(i)+1));
|
2016-07-11 13:05:04 +00:00
|
|
|
sorted_list.push({dom: the_heading, val: this.graph.getValue(today-1, parseInt(i)+1), index: parseInt(i)});
|
2016-07-12 09:47:51 +00:00
|
|
|
}
|
|
|
|
sorted_list.sort(function(a,b) {
|
2016-07-11 13:05:04 +00:00
|
|
|
return b.val - a.val;
|
2016-07-12 09:47:51 +00:00
|
|
|
});
|
2016-07-11 13:05:04 +00:00
|
|
|
|
2016-08-09 09:59:36 +00:00
|
|
|
|
2016-07-11 13:05:04 +00:00
|
|
|
var display_list = sorted_list.slice(0, max_display);
|
|
|
|
for( i=0; i<display_list.length; i++){
|
|
|
|
this.graph.setVisibility(display_list[i].index, true);
|
|
|
|
}
|
2016-07-11 14:57:45 +00:00
|
|
|
return sorted_list.slice(0, sorted_list.length);
|
|
|
|
}
|
|
|
|
function setVis_andHide(max_display, old_display){
|
|
|
|
display_list = this.set_Visibility(max_display);
|
|
|
|
for(i=max_display; i<old_display; i++) {
|
|
|
|
this.graph.setVisibility(display_list[i].index, false);
|
|
|
|
}
|
2016-07-11 13:05:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-04 09:43:38 +00:00
|
|
|
}
|