2016-07-27 11:26:56 +02:00
|
|
|
/* Already defined variable (Before the input)
|
|
|
|
*
|
|
|
|
* var chart_1_num_day = 5;
|
|
|
|
* var chart_2_num_day = 15;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: { hoverable: true, clickable: true },
|
|
|
|
legend: { show: false },
|
|
|
|
};
|
|
|
|
|
|
|
|
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-28 09:52:07 +02:00
|
|
|
function plot_top_graph(module_name, init){
|
2016-07-27 11:26:56 +02:00
|
|
|
|
|
|
|
/**** Pie Chart ****/
|
|
|
|
|
|
|
|
// moduleCharts is used the decide the url to request data
|
2016-07-27 11:55:57 +02:00
|
|
|
var moduleCharts = "size" == module_name ? "providersChart" : ("num" == module_name ? "providersChart" : "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
|
|
|
|
|
|
|
|
2016-07-28 09:52:07 +02:00
|
|
|
var createPie = $.getJSON($SCRIPT_ROOT+"/_"+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
|
|
|
|
$("#day-"+module_name).text(data[0][1] + " Day(s) ago ");
|
|
|
|
$("#panel-"+module_name).removeClass("panel-green")
|
|
|
|
$("#panel-"+module_name).addClass("panel-yellow")
|
|
|
|
} else if (data[0][1] > 6) { // data old of more than 7 days, put the panel in red
|
|
|
|
$("#day-"+module_name).text(data[0][1] + " Day(s) ago ");
|
|
|
|
$("#panel-"+module_name).removeClass("panel-green")
|
|
|
|
$("#panel-"+module_name).addClass("panel-red")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
temp_data_pie.push({label: data[i][0], data: data[i][1]});
|
|
|
|
tot_sum += data[i][1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
data_other.push(temp_data_pie[i].label);
|
|
|
|
}
|
|
|
|
|
|
|
|
$.plot($("#flot-pie-chart-"+module_name), temp_data_pie, options);
|
|
|
|
|
2016-07-28 09:52:07 +02:00
|
|
|
if (init){
|
|
|
|
$("#flot-pie-chart-"+module_name).bind("plotclick", function (event, pos, item) {
|
|
|
|
if (item == null)
|
|
|
|
return;
|
|
|
|
var clicked_label = item.series.label;
|
|
|
|
update_bar_chart(moduleCharts, "#flot-bar-chart-"+module_name, clicked_label, item.series.color, chart_1_num_day, "%m/%d");
|
2016-07-28 12:06:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
$("#flot-bar-chart-"+module_name).bind("plothover", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
var x = item.datapoint[0].toFixed(2);
|
|
|
|
var y = item.datapoint[1].toFixed(2);
|
|
|
|
var date = new Date(parseInt(x));
|
|
|
|
date = date.getMonth()+'/'+date.getDate();
|
|
|
|
|
|
|
|
$("#tooltip_graph-"+module_name).html(item.series.label + " of " + date + " = <b>" + y+"</b>")
|
|
|
|
.css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color})
|
|
|
|
.fadeIn(200);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
});
|
2016-07-28 09:52:07 +02:00
|
|
|
});
|
|
|
|
}
|
2016-07-27 11:26:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**** Bar Chart ****/
|
|
|
|
|
|
|
|
function update_bar_chart(chartUrl, chartID, involved_item, serie_color, num_day, timeformat){
|
|
|
|
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"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (involved_item == "Other"){ // If part 'Other' has been clicked
|
|
|
|
var all_other_temp_data = [];
|
|
|
|
var temp_data_bar = [];
|
|
|
|
var promises = []; // Use to plot when everything have been received
|
2016-07-28 09:52:07 +02:00
|
|
|
var involved_item
|
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];
|
|
|
|
var request = $.getJSON($SCRIPT_ROOT+"/_"+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
|
|
|
|
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime() + offset, data[i][1]]);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
2016-07-28 09:52:07 +02:00
|
|
|
all_other_temp_data.push([ data[0], temp_data_bar ]);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
2016-07-28 09:52:07 +02:00
|
|
|
)
|
|
|
|
promises.push(request);
|
2016-07-27 11:26:56 +02:00
|
|
|
}
|
|
|
|
|
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-28 09:52:07 +02:00
|
|
|
for(i=0; i<all_other_temp_data.length; i++) //format data for the plot
|
|
|
|
dataBar.push({bars: { barWidth: 8280000 }, label: all_other_temp_data[i][0], data: all_other_temp_data[i][1]})
|
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
$.plot($(chartID), dataBar, {
|
|
|
|
series: {
|
2016-07-28 09:52:07 +02:00
|
|
|
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: {
|
|
|
|
transform: function (v) { return v < 1 ? v : Math.log(v); }
|
|
|
|
},
|
2016-07-27 11:26:56 +02:00
|
|
|
grid: { hoverable: true },
|
|
|
|
legend: { show: true,
|
|
|
|
noColumns: 1,
|
|
|
|
position: "nw"
|
|
|
|
},
|
|
|
|
tooltip: true,
|
|
|
|
tooltipOpts: { content: "x: %x, y: %y" }
|
2016-07-28 12:06:54 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-27 11:26:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
} else { // Normal pie's part clicked
|
|
|
|
|
|
|
|
$.getJSON($SCRIPT_ROOT+"/_"+chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day,
|
|
|
|
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('/');
|
|
|
|
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]), data[i][1]]);
|
|
|
|
}
|
|
|
|
var barData = {
|
|
|
|
label: involved_item,
|
|
|
|
data: temp_data_bar,
|
|
|
|
color: serie_color
|
|
|
|
};
|
|
|
|
$.plot($(chartID), [barData], barOptions);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|