2016-07-27 11:26:56 +02:00
|
|
|
/* Already defined variable (Before the input)
|
2018-09-25 14:37:14 +02:00
|
|
|
*
|
2016-07-27 11:26:56 +02:00
|
|
|
* var chart_1_num_day = 5;
|
|
|
|
* var chart_2_num_day = 15;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-09-25 14:37:14 +02:00
|
|
|
function getSyncScriptParams() {
|
|
|
|
var scripts = document.getElementsByTagName('script');
|
|
|
|
var lastScript = scripts[scripts.length-1];
|
|
|
|
var scriptName = lastScript;
|
|
|
|
return {
|
|
|
|
url_providersChart : scriptName.getAttribute('data-url_providersChart'),
|
|
|
|
url_moduleCharts : scriptName.getAttribute('data-url_moduleCharts'),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var url_providersChart = getSyncScriptParams().url_providersChart;
|
|
|
|
var url_moduleCharts = getSyncScriptParams().url_moduleCharts;
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
/* VARIABLES */
|
|
|
|
var pie_threshold = 0.05
|
|
|
|
var options = {
|
|
|
|
series: { pie: { show: true,
|
|
|
|
radius: 3/5,
|
|
|
|
combine: {
|
|
|
|
color: '#999',
|
|
|
|
threshold: pie_threshold
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
show: true,
|
|
|
|
radius: 1,
|
|
|
|
formatter: labelFormatter,
|
|
|
|
background: {
|
|
|
|
opacity: 0.5,
|
|
|
|
color: '#000'
|
|
|
|
}
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
},
|
|
|
|
grid: { hoverable: true, clickable: true },
|
|
|
|
legend: { show: false },
|
|
|
|
};
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
/* Linked graph - remember the data */
|
|
|
|
var plot_data_old = []
|
|
|
|
var plot_old = []
|
2016-07-27 11:26:56 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
/* FUNCTIONS */
|
2016-07-28 16:35:30 +02:00
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
function labelFormatter(label, series) {
|
|
|
|
return "<div style='font-size:8pt; text-align:center; padding:2px; color:white;'>"
|
|
|
|
+ label + "<br/>" + Math.round(series.percent) + "%</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
/* Plot, and bind chart listener */
|
2016-07-28 09:52:07 +02:00
|
|
|
function plot_top_graph(module_name, init){
|
2016-07-27 11:26:56 +02:00
|
|
|
|
|
|
|
/**** Pie Chart ****/
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
// moduleCharts is used the decide the url to request data
|
2018-09-25 14:37:14 +02:00
|
|
|
var moduleCharts = "size" == module_name ? url_providersChart : ("num" == module_name ? url_providersChart : url_moduleCharts);
|
|
|
|
console.log(moduleCharts)
|
2016-07-28 09:52:07 +02:00
|
|
|
var tot_sum = 0; // used to detect elements placed in 'Other' pie's part
|
|
|
|
var data_other = []; // used to detect elements placed in 'Other' pie's part
|
2016-07-27 11:26:56 +02:00
|
|
|
|
2018-09-25 14:37:14 +02:00
|
|
|
var createPie = $.getJSON(moduleCharts+"?moduleName="+module_name+"&num_day="+chart_1_num_day,
|
2016-07-27 11:26:56 +02:00
|
|
|
function(data) {
|
|
|
|
var temp_data_pie = [];
|
|
|
|
for(i=0; i<data.length; i++){
|
|
|
|
if (i==0 && data[0][0] == "passed_days"){ // If there is no data today, take it from the past
|
|
|
|
if (data[0][1] > 0 && data[0][1] < 7){ // If data is [1:6] day(s) old, put the panel in yellow
|
2018-09-25 14:37:14 +02:00
|
|
|
$("#day-"+module_name).text(data[0][1] + " Day(s) ago ");
|
2016-08-10 10:42:06 +02:00
|
|
|
$("#panel-"+module_name).removeClass("panel-green");
|
|
|
|
$("#panel-"+module_name).addClass("panel-yellow");
|
2016-07-27 11:26:56 +02:00
|
|
|
} else if (data[0][1] > 6) { // data old of more than 7 days, put the panel in red
|
2018-09-25 14:37:14 +02:00
|
|
|
$("#day-"+module_name).text(data[0][1] + " Day(s) ago ");
|
2016-08-10 10:42:06 +02:00
|
|
|
$("#panel-"+module_name).removeClass("panel-green");
|
|
|
|
$("#panel-"+module_name).addClass("panel-red");
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
temp_data_pie.push({label: data[i][0], data: data[i][1]});
|
2016-08-10 10:42:06 +02:00
|
|
|
tot_sum += data[i][1];
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0; i<temp_data_pie.length; i++){ // Detect element below a certain threshold
|
|
|
|
if (parseInt(temp_data_pie[i].data) / tot_sum < pie_threshold)
|
2016-07-29 14:30:41 +02:00
|
|
|
data_other.push(temp_data_pie[i].label);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$.plot($("#flot-pie-chart-"+module_name), temp_data_pie, options);
|
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
if (init){ //prevent multiple binding due to the refresh function
|
2016-07-28 09:52:07 +02:00
|
|
|
$("#flot-pie-chart-"+module_name).bind("plotclick", function (event, pos, item) {
|
|
|
|
if (item == null)
|
2018-09-25 14:37:14 +02:00
|
|
|
return;
|
2016-07-28 09:52:07 +02:00
|
|
|
var clicked_label = item.series.label;
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
if (module_name == "size"){ // if Provider pie chart clicked, draw the two bar charts
|
2018-09-25 14:37:14 +02:00
|
|
|
update_bar_chart(moduleCharts, module_name, "#flot-bar-chart-"+module_name, clicked_label,
|
2016-07-29 14:30:41 +02:00
|
|
|
item.series.color, "%m/%d", false);
|
|
|
|
update_bar_chart(moduleCharts, "num", "#flot-bar-chart-"+"num", clicked_label,
|
|
|
|
item.series.color, "%m/%d", true);
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
|
|
|
else if (module_name == "num"){
|
2018-09-25 14:37:14 +02:00
|
|
|
update_bar_chart(moduleCharts, module_name, "#flot-bar-chart-"+module_name, clicked_label,
|
2016-07-29 14:30:41 +02:00
|
|
|
item.series.color, "%m/%d", false);
|
2018-09-25 14:37:14 +02:00
|
|
|
update_bar_chart(moduleCharts, "size", "#flot-bar-chart-"+"size", clicked_label,
|
2016-07-29 14:30:41 +02:00
|
|
|
item.series.color, "%m/%d", true);
|
2016-07-28 16:35:30 +02:00
|
|
|
} else {
|
2018-09-25 14:37:14 +02:00
|
|
|
update_bar_chart(moduleCharts, module_name, "#flot-bar-chart-"+module_name, clicked_label,
|
2016-07-29 14:30:41 +02:00
|
|
|
item.series.color, "%m/%d", true);
|
2018-09-25 14:37:14 +02:00
|
|
|
}
|
2016-07-28 09:52:07 +02:00
|
|
|
});
|
|
|
|
}
|
2016-07-27 11:26:56 +02:00
|
|
|
});
|
2018-09-25 14:37:14 +02:00
|
|
|
|
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
/**** Bar Chart ****/
|
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
function update_bar_chart(chartUrl, module_name, chartID, involved_item, serie_color, timeformat, can_bind){
|
|
|
|
var num_day = chart_1_num_day;
|
2016-07-27 11:26:56 +02:00
|
|
|
var barOptions = {
|
|
|
|
series: {
|
2016-07-28 09:52:07 +02:00
|
|
|
bars: { show: true, barWidth: 82800000 },
|
|
|
|
lines: { show: false, fill: true }
|
2016-07-27 11:26:56 +02:00
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
mode: "time",
|
|
|
|
timeformat: timeformat,
|
|
|
|
tickSize: [1, 'day'],
|
|
|
|
minTickSize: [1, "day"]
|
|
|
|
},
|
|
|
|
grid: { hoverable: true },
|
|
|
|
legend: { show: true,
|
|
|
|
noColumns: 0,
|
|
|
|
position: "nw"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
var plot; // will contain the current plotting object
|
|
|
|
/* If part 'Other' has been clicked */
|
|
|
|
if (involved_item == "Other"){
|
|
|
|
|
|
|
|
var all_other_temp_data = []; // the data_bar of all series
|
|
|
|
var temp_data_bar; //the data_bar associated with one serie
|
|
|
|
var promises = []; // Use to plot when everything has been received
|
2016-07-28 09:52:07 +02:00
|
|
|
var involved_item
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
for(i=0; i<data_other.length; i++){ // Get data for elements summed up in the part 'Other'
|
2016-07-28 09:52:07 +02:00
|
|
|
involved_item = data_other[i];
|
2018-09-25 14:37:14 +02:00
|
|
|
var request = $.getJSON(chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day,
|
2016-07-27 11:26:56 +02:00
|
|
|
function(data) {
|
|
|
|
temp_data_bar = []
|
2016-07-28 09:52:07 +02:00
|
|
|
for(i=1; i<data.length; i++){
|
2016-07-27 11:26:56 +02:00
|
|
|
var curr_date = data[i][0].split('/');
|
2016-07-28 09:52:07 +02:00
|
|
|
var offset = (data_other.length/2 - data_other.indexOf(data[0]))*10000000
|
2016-07-29 16:52:50 +02:00
|
|
|
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime() + offset, data[i][1].toFixed(2)]);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
// Insert temp_data_bar in order so that color and alignement correspond for the provider graphs
|
2018-09-25 14:37:14 +02:00
|
|
|
all_other_temp_data.splice(data_other.indexOf(data[0]), 0, [ data[0], temp_data_bar, data_other.indexOf(data[0])]);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
2016-07-28 09:52:07 +02:00
|
|
|
)
|
2016-07-29 14:30:41 +02:00
|
|
|
promises.push(request);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
/* When everything has been received, start the plotting process */
|
2016-07-28 09:52:07 +02:00
|
|
|
$.when.apply($, promises).done( function (arg) {
|
2016-07-27 11:26:56 +02:00
|
|
|
var dataBar = []
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2016-07-28 09:52:07 +02:00
|
|
|
for(i=0; i<all_other_temp_data.length; i++) //format data for the plot
|
2016-07-29 14:30:41 +02:00
|
|
|
dataBar.push({bars: { barWidth: 8280000, order: all_other_temp_data[i][2] }, label: all_other_temp_data[i][0], data: all_other_temp_data[i][1]});
|
|
|
|
|
|
|
|
plot = $.plot($(chartID), dataBar, {
|
2016-07-29 10:36:44 +02:00
|
|
|
series: {
|
|
|
|
stack: false,
|
|
|
|
lines: { show: false, fill: true, steps: false },
|
|
|
|
bars: { show: true},
|
|
|
|
},
|
2016-07-27 11:26:56 +02:00
|
|
|
xaxis: {
|
|
|
|
mode: "time",
|
|
|
|
timeformat: timeformat,
|
|
|
|
tickSize: [1, 'day'],
|
|
|
|
minTickSize: [1, "day"]
|
|
|
|
},
|
2016-07-28 12:06:54 +02:00
|
|
|
yaxis: {
|
2016-07-29 16:52:50 +02:00
|
|
|
//transform: function (v) { return v < 1 ? v : Math.log(v); }
|
2016-07-28 12:06:54 +02:00
|
|
|
},
|
2016-07-27 11:26:56 +02:00
|
|
|
grid: { hoverable: true },
|
|
|
|
legend: { show: true,
|
|
|
|
noColumns: 1,
|
|
|
|
position: "nw"
|
|
|
|
},
|
|
|
|
tooltip: true,
|
2016-07-29 10:36:44 +02:00
|
|
|
tooltipOpts: { content: "x: %x, y: %y" },
|
|
|
|
colors: ["#72a555", "#ab62c0", "#c57c3c", "#638ccc", "#ca5670"]
|
2016-07-28 12:06:54 +02:00
|
|
|
})
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-08-02 16:17:25 +02:00
|
|
|
/* rememeber the data for the two provider graph */
|
2018-09-25 14:37:14 +02:00
|
|
|
if (chartUrl == url_providersChart){
|
2016-08-02 16:17:25 +02:00
|
|
|
if (plot_data_old.length>1){ // avoid adding plot_data for previous clicked pie part
|
|
|
|
plot_data_old = [];
|
|
|
|
plot_old = [];
|
|
|
|
}
|
|
|
|
plot_data_old.push(plot.getData());
|
|
|
|
plot_old.push(plot);
|
2016-07-29 10:36:44 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
if (can_bind){ // avoid binding two listener for provider graphs
|
2016-07-29 10:36:44 +02:00
|
|
|
binder(module_name);
|
2016-07-29 14:30:41 +02:00
|
|
|
if (module_name == "size") // bind the linked provider graph
|
2016-07-29 10:36:44 +02:00
|
|
|
binder("num");
|
|
|
|
else if (module_name == "num")
|
|
|
|
binder("size");
|
2018-09-25 14:37:14 +02:00
|
|
|
}
|
2016-07-28 12:06:54 +02:00
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
} else { // Normal pie's part clicked
|
|
|
|
|
2018-09-25 14:37:14 +02:00
|
|
|
$.getJSON(chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day,
|
2016-07-27 11:26:56 +02:00
|
|
|
function(data) {
|
|
|
|
var temp_data_bar = []
|
2016-07-28 09:52:07 +02:00
|
|
|
for(i=1; i<data.length; i++){
|
2016-07-27 11:26:56 +02:00
|
|
|
var curr_date = data[i][0].split('/');
|
2016-07-29 16:52:50 +02:00
|
|
|
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime(), data[i][1].toFixed(2)]);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
var barData = {
|
|
|
|
label: involved_item,
|
|
|
|
data: temp_data_bar,
|
|
|
|
color: serie_color
|
|
|
|
};
|
2016-07-29 14:30:41 +02:00
|
|
|
plot = $.plot($(chartID), [barData], barOptions);
|
|
|
|
|
|
|
|
/* rememeber the data for the two graph */
|
2016-08-01 11:08:53 +02:00
|
|
|
if ((module_name == "size") || (module_name == "num")) { // Add only for the provider graph
|
|
|
|
if (plot_data_old.length>1){ // avoid adding plot_data for previous clicked pie part
|
|
|
|
plot_data_old = [];
|
|
|
|
plot_old = [];
|
|
|
|
}
|
|
|
|
plot_data_old.push(plot.getData());
|
|
|
|
plot_old.push(plot);
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
if (can_bind){ // avoid binding two listener for provider graphs
|
|
|
|
$("#flot-bar-chart-"+module_name).unbind( "plothover.customHandler" );
|
2016-07-28 16:35:30 +02:00
|
|
|
binder(module_name);
|
2016-07-29 14:30:41 +02:00
|
|
|
if (module_name == "size"){ // bind the linked provider graph
|
|
|
|
$("#flot-bar-chart-"+"num").unbind( "plothover.customHandler" );
|
2016-07-28 16:35:30 +02:00
|
|
|
binder("num");
|
2016-07-29 14:30:41 +02:00
|
|
|
}
|
|
|
|
else if (module_name == "num"){
|
|
|
|
$("#flot-bar-chart-"+"size").unbind( "plothover.customHandler" );
|
2016-07-28 16:35:30 +02:00
|
|
|
binder("size");
|
2016-07-29 14:30:41 +02:00
|
|
|
}
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
});
|
|
|
|
}
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
}; // end update_bar_chart
|
|
|
|
|
|
|
|
} // end plot_top_graph
|
2016-07-28 16:35:30 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
/* Bind a listener to the graph to display the value under the cursor in the approriate div */
|
2016-07-28 16:35:30 +02:00
|
|
|
function binder(module_name){
|
2016-07-29 14:30:41 +02:00
|
|
|
$("#flot-bar-chart-"+module_name).bind("plothover.customHandler", function (event, pos, item) {
|
|
|
|
if (item) { // a correct item is hovered
|
2016-07-28 16:35:30 +02:00
|
|
|
var x = item.datapoint[0]
|
|
|
|
var y = item.datapoint[1]
|
|
|
|
var date = new Date(parseInt(x));
|
|
|
|
var formated_date = date.getMonth()+'/'+date.getDate();
|
2016-07-29 14:30:41 +02:00
|
|
|
var color = item.series.color;
|
|
|
|
var color_opac = "rgba" + color.slice(3, color.length-1)+",0.15)";
|
2018-09-25 14:37:14 +02:00
|
|
|
|
2016-07-29 14:30:41 +02:00
|
|
|
// display the hovered value in the chart div
|
2016-07-28 16:35:30 +02:00
|
|
|
$("#tooltip_graph-"+module_name).html(item.series.label + " of " + formated_date + " = <b>" + y+"</b>")
|
2016-07-29 14:30:41 +02:00
|
|
|
.css({padding: "2px", width: 'auto', 'background': color_opac , 'border': "3px solid "+color})
|
2016-07-28 16:35:30 +02:00
|
|
|
.fadeIn(200);
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* If provider bar chart hovered, highlight and display associated value */
|
2018-09-25 14:37:14 +02:00
|
|
|
if (module_name == "size" || module_name == "num"){
|
2016-07-29 14:30:41 +02:00
|
|
|
new_module_name = module_name == "size" ? "num" : "size";
|
|
|
|
|
|
|
|
/* Used to get the corresponding associated value for providers charts */
|
|
|
|
var plot_obj = plot_data_old[0]; //contain series
|
|
|
|
|
|
|
|
for(serie=0; serie<plot_obj.length; serie++){ //for all series
|
|
|
|
var data_other = plot_obj[serie].data;
|
|
|
|
|
|
|
|
for(i=0; i<data_other.length; i++){ //for all datapoints
|
|
|
|
if (data_other[i][0] == date.getTime()){
|
|
|
|
if(y == data_other[i][1]){ // get the correct data and plot object
|
|
|
|
var other_graph_plot = plot_old[1];
|
|
|
|
var curr_data_other = plot_data_old[1][serie].data[i][1];
|
|
|
|
} else {
|
|
|
|
var other_graph_plot = plot_old[0];
|
|
|
|
var curr_data_other = data_other[i][1];
|
|
|
|
}
|
2016-07-28 16:35:30 +02:00
|
|
|
var datapoint = i;
|
2016-07-29 10:36:44 +02:00
|
|
|
var the_serie = serie;
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
2016-07-29 10:36:44 +02:00
|
|
|
}
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
$("#tooltip_graph-"+new_module_name).html(item.series.label + " of " + formated_date + " = <b>" + curr_data_other+"</b>")
|
|
|
|
.css({padding: "2px", width: 'auto', 'background': color_opac, 'border': "3px solid "+color})
|
2016-07-29 10:36:44 +02:00
|
|
|
.fadeIn(200);
|
2016-07-29 14:30:41 +02:00
|
|
|
|
|
|
|
// clean up other highlighted bar
|
|
|
|
|
2016-07-29 10:36:44 +02:00
|
|
|
for(i=0; i<data_other.length; i++)
|
|
|
|
for(s=0; s<plot_obj.length; s++)
|
|
|
|
other_graph_plot.unhighlight(s, i);
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2016-07-29 10:36:44 +02:00
|
|
|
other_graph_plot.highlight(the_serie, datapoint);
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2016-07-28 16:35:30 +02:00
|
|
|
}
|
2016-07-29 14:30:41 +02:00
|
|
|
|
2016-07-28 16:35:30 +02:00
|
|
|
} else {
|
2016-07-29 14:30:41 +02:00
|
|
|
// No correct item hovered, clean up the highlighted one
|
2016-07-28 16:35:30 +02:00
|
|
|
for(i=0; i<plot_old.length; i++)
|
|
|
|
for(j=0; j<plot_data_old[0][0].data.length; j++)
|
|
|
|
plot_old[i].unhighlight(0, j);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|