2017-11-16 15:08:14 +01:00
|
|
|
/* VARS */
|
2017-11-17 09:13:18 +01:00
|
|
|
var dateStart;
|
|
|
|
var dateEnd;
|
2017-11-16 15:08:14 +01:00
|
|
|
var eventPie = ["#eventPie"];
|
|
|
|
var eventLine = ["#eventLine"];
|
|
|
|
var categPie = ["#categPie"];
|
|
|
|
var categLine = ["#categLine"];
|
|
|
|
var tagPie = ["#tagPie"];
|
|
|
|
var tagLine = ["#tagLine"];
|
2017-11-17 14:45:20 +01:00
|
|
|
var sightingLineWidget;
|
2017-11-17 16:50:04 +01:00
|
|
|
var discLine = ["#discussionLine"];
|
2017-12-11 12:19:11 +01:00
|
|
|
var timeline;
|
2017-11-20 17:42:25 +01:00
|
|
|
var allData;
|
2017-11-21 09:17:02 +01:00
|
|
|
var globalColorMapping = {};
|
2017-11-16 15:08:14 +01:00
|
|
|
|
|
|
|
/* OPTIONS */
|
|
|
|
var datePickerOptions = {
|
|
|
|
showOn: "button",
|
|
|
|
maxDate: 0,
|
|
|
|
buttonImage: urlIconCalendar,
|
|
|
|
buttonImageOnly: true,
|
|
|
|
buttonText: "Select date",
|
|
|
|
showAnim: "slideDown",
|
|
|
|
onSelect: dateChanged
|
|
|
|
};
|
|
|
|
var lineChartOption = {
|
|
|
|
lines: {
|
|
|
|
show: true,
|
|
|
|
},
|
2017-11-17 09:43:59 +01:00
|
|
|
points: { show: true },
|
2017-11-16 15:08:14 +01:00
|
|
|
xaxis: {
|
|
|
|
mode: "time",
|
|
|
|
minTickSize: [1, "day"],
|
2017-11-16 16:57:48 +01:00
|
|
|
},
|
2017-11-17 10:41:22 +01:00
|
|
|
legend: { show: false },
|
|
|
|
grid: {
|
|
|
|
hoverable: true
|
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
};
|
|
|
|
var pieChartOption = {
|
|
|
|
series: {
|
|
|
|
pie: {
|
2017-11-17 09:13:18 +01:00
|
|
|
innerRadius: 0.2,
|
2017-11-16 16:57:48 +01:00
|
|
|
show: true,
|
2017-11-17 15:57:50 +01:00
|
|
|
radius: 100,
|
2018-02-22 10:35:59 +01:00
|
|
|
stroke: { color: 'black' },
|
2017-11-16 16:57:48 +01:00
|
|
|
label: {
|
2017-11-17 09:13:18 +01:00
|
|
|
show: true,
|
2017-11-17 15:57:50 +01:00
|
|
|
radius: 6/10,
|
2017-11-17 09:13:18 +01:00
|
|
|
formatter: innerPieLabelFormatter,
|
2017-11-16 16:57:48 +01:00
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
2017-11-16 16:57:48 +01:00
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: true,
|
|
|
|
labelFormatter: legendFormatter
|
2017-11-17 10:41:22 +01:00
|
|
|
},
|
|
|
|
grid: {
|
2017-11-20 15:42:57 +01:00
|
|
|
hoverable: true,
|
|
|
|
clickable: true
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
|
|
|
};
|
2017-11-20 17:42:25 +01:00
|
|
|
var typeaheadOption_event = {
|
|
|
|
source: function (query, process) {
|
|
|
|
if (allData === undefined) { // caching
|
|
|
|
return $.getJSON(url_getTypeaheadData, function (data) {
|
|
|
|
allData = data;
|
|
|
|
return process(data.TRENDINGS_EVENTS);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return process(allData.TRENDINGS_EVENTS);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updater: function(theevent) {
|
2017-11-21 08:42:54 +01:00
|
|
|
updateLineForLabel(eventLine, theevent, undefined, url_getTrendingEvent);
|
2017-11-20 17:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var typeaheadOption_categ = {
|
|
|
|
source: function (query, process) {
|
|
|
|
if (allData === undefined) { // caching
|
|
|
|
return $.getJSON(url_getTypeaheadData, function (data) {
|
|
|
|
allData = data;
|
|
|
|
return process(data.TRENDINGS_CATEGS);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return process(allData.TRENDINGS_CATEGS);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updater: function(categ) {
|
2017-11-21 09:17:02 +01:00
|
|
|
updateLineForLabel(categLine, categ, undefined, url_getTrendingCateg);
|
2017-11-20 17:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var typeaheadOption_tag = {
|
|
|
|
source: function (query, process) {
|
|
|
|
if (allData === undefined) { // caching
|
|
|
|
return $.getJSON(url_getTypeaheadData, function (data) {
|
|
|
|
allData = data;
|
|
|
|
return process(data.TRENDINGS_TAGS);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return process(allData.TRENDINGS_TAGS);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updater: function(tag) {
|
2017-11-21 09:17:02 +01:00
|
|
|
updateLineForLabel(tagLine, tag, undefined, url_getTrendingTag);
|
2017-11-20 17:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-11 14:54:22 +01:00
|
|
|
var timeline_option = {
|
|
|
|
groupOrder: 'content',
|
|
|
|
maxHeight: '94vh',
|
|
|
|
verticalScroll: true,
|
|
|
|
horizontalScroll: true,
|
|
|
|
zoomKey: 'ctrlKey',
|
|
|
|
};
|
2017-12-11 12:19:11 +01:00
|
|
|
|
2017-11-16 15:08:14 +01:00
|
|
|
|
|
|
|
/* FUNCTIONS */
|
2017-11-21 09:17:02 +01:00
|
|
|
function getColor(label) {
|
|
|
|
try {
|
|
|
|
return globalColorMapping[label];
|
|
|
|
} catch(err) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-17 09:13:18 +01:00
|
|
|
function innerPieLabelFormatter(label, series) {
|
|
|
|
var count = series.data[0][1];
|
|
|
|
return '<div '
|
|
|
|
+ 'style="font-size:8pt;text-align:inherit;padding:2px;">'
|
|
|
|
+ '<a class="tagElem" style="background-color: '+ 'white' + ';'
|
|
|
|
+ 'color: ' + 'black' + ';"> ' + count + '</a>'
|
|
|
|
+ '</div>';
|
|
|
|
}
|
|
|
|
|
2017-11-16 16:57:48 +01:00
|
|
|
function getTextColour(rgb) {
|
|
|
|
var r = parseInt('0x'+rgb.substring(0,2));
|
|
|
|
var g = parseInt('0x'+rgb.substring(2,4));
|
|
|
|
var b = parseInt('0x'+rgb.substring(4,6));
|
|
|
|
var avg = ((2 * r) + b + (3 * g))/6;
|
|
|
|
if (avg < 128) {
|
|
|
|
return 'white';
|
|
|
|
} else {
|
|
|
|
return 'black';
|
|
|
|
}
|
|
|
|
}
|
2017-12-11 14:54:22 +01:00
|
|
|
|
2019-05-29 01:30:57 +02:00
|
|
|
// If json (from tag), only retrieve the name> otherwise return the supplied arg.
|
2017-12-11 14:54:22 +01:00
|
|
|
function getOnlyName(potentialJson) {
|
|
|
|
try {
|
|
|
|
jsonLabel = JSON.parse(potentialJson);
|
|
|
|
return jsonLabel.name;
|
|
|
|
} catch(err) {
|
|
|
|
return potentialJson;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function legendFormatter(label) {
|
2017-11-16 16:57:48 +01:00
|
|
|
try {
|
2017-11-17 14:45:20 +01:00
|
|
|
jsonLabel = JSON.parse(label);
|
2017-11-16 16:57:48 +01:00
|
|
|
var backgroundColor = jsonLabel.colour;
|
|
|
|
var color = getTextColour(backgroundColor.substring(1,6));;
|
|
|
|
var labelText = jsonLabel.name;
|
|
|
|
return '<div '
|
|
|
|
+ 'style="font-size:8pt;text-align:inherit;padding:2px;">'
|
|
|
|
+ '<a class="tagElem" style="background-color: '+ backgroundColor + ';'
|
|
|
|
+ 'color: ' + color + ';"> ' + labelText + '</a>'
|
|
|
|
+ '</div>';
|
|
|
|
} catch(err) {
|
2017-11-17 14:45:20 +01:00
|
|
|
// removing unwanted "
|
|
|
|
var label = label.replace(/\\"/g, "").replace(/\"/g, "");
|
|
|
|
// limiting size
|
2017-11-21 12:09:17 +01:00
|
|
|
if (label.length >= 40){
|
|
|
|
labelLimited = label.substring(0, 40) + '[...]';
|
2017-11-17 14:45:20 +01:00
|
|
|
} else {
|
|
|
|
labelLimited = label;
|
|
|
|
}
|
2017-11-16 16:57:48 +01:00
|
|
|
return '<div '
|
2017-11-17 10:46:25 +01:00
|
|
|
+ 'style="font-size:8pt;text-align:inherit;padding:2px;">'
|
2017-12-13 09:02:27 +01:00
|
|
|
+ '<a class="tagElem" title="'+label+'" style="background-color: white; color: black;"> ' + labelLimited
|
2017-11-17 10:46:25 +01:00
|
|
|
+ '</a>';
|
|
|
|
+ '</div>';
|
2017-11-16 16:57:48 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
|
2017-11-20 17:01:31 +01:00
|
|
|
function generateEmptyAndFillData(data, specificLabel, colorMapping) {
|
2017-11-17 14:45:20 +01:00
|
|
|
// formating - Generate empty data
|
|
|
|
var toPlot_obj = {};
|
|
|
|
var allDates = [];
|
|
|
|
for (var arr of data) {
|
|
|
|
var date = new Date(arr[0]*1000);
|
|
|
|
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000); // center the data around the day
|
|
|
|
allDates.push(date);
|
|
|
|
var items = arr[1];
|
|
|
|
if (items.length > 0) {
|
|
|
|
for(var item_arr of items) {
|
|
|
|
var count = item_arr[1];
|
|
|
|
var itemStr = JSON.stringify(item_arr[0]);
|
2017-11-21 09:17:02 +01:00
|
|
|
if (specificLabel === undefined || specificLabel == item_arr[0]) { // no tag
|
|
|
|
if(toPlot_obj[itemStr] === undefined)
|
|
|
|
toPlot_obj[itemStr] = {};
|
|
|
|
toPlot_obj[itemStr][date] = count;
|
|
|
|
} else if (specificLabel == item_arr[0].name) { // tag
|
|
|
|
if(toPlot_obj[itemStr] === undefined)
|
|
|
|
toPlot_obj[itemStr] = {};
|
|
|
|
toPlot_obj[itemStr][date] = count;
|
|
|
|
} else if (specificLabel == itemStr.substring(1, itemStr.length-1)) { // tag from click (countain { and }, need to supress it)
|
2017-11-20 15:42:57 +01:00
|
|
|
if(toPlot_obj[itemStr] === undefined)
|
|
|
|
toPlot_obj[itemStr] = {};
|
|
|
|
toPlot_obj[itemStr][date] = count;
|
|
|
|
}
|
2017-11-17 14:45:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
toPlot = []
|
|
|
|
for (var itemStr in toPlot_obj) {
|
|
|
|
if (toPlot_obj.hasOwnProperty(itemStr)) {
|
|
|
|
data_toPlot = []
|
|
|
|
for (var curDate of allDates) {
|
|
|
|
if (toPlot_obj[itemStr].hasOwnProperty(curDate)) {
|
|
|
|
data_toPlot.push([curDate, toPlot_obj[itemStr][curDate]])
|
|
|
|
} else {
|
|
|
|
data_toPlot.push([curDate, 0])
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 09:17:02 +01:00
|
|
|
if (colorMapping === undefined) {
|
|
|
|
//try to get color, else no color
|
|
|
|
var colorCode = getColor(itemStr);
|
|
|
|
if (!( colorCode === undefined)) {
|
|
|
|
toPlot.push({label: itemStr, data: data_toPlot, color: colorCode})
|
|
|
|
} else {
|
|
|
|
toPlot.push({label: itemStr, data: data_toPlot})
|
|
|
|
}
|
2017-11-20 17:01:31 +01:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var color = colorMapping[itemStr].colour;
|
|
|
|
toPlot.push({label: itemStr, data: data_toPlot, color: color})
|
|
|
|
} catch(err) {
|
|
|
|
// ignore, only shows data displayed in the pie chart
|
|
|
|
}
|
|
|
|
}
|
2017-11-17 14:45:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return toPlot;
|
|
|
|
}
|
|
|
|
|
2017-11-20 15:14:13 +01:00
|
|
|
function compareObj(a,b) {
|
|
|
|
if (a.data < b.data)
|
|
|
|
return -1;
|
|
|
|
if (a.data > b.data)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-17 14:45:20 +01:00
|
|
|
/* UPDATES */
|
|
|
|
|
2017-11-20 17:01:31 +01:00
|
|
|
// return the color maping: label->color
|
|
|
|
function updatePie(pie, line, data, url) {
|
2017-11-17 14:45:20 +01:00
|
|
|
var pieID = pie[0];
|
|
|
|
var pieWidget = pie[1];
|
|
|
|
var itemMapping = {};
|
2017-11-20 17:01:31 +01:00
|
|
|
var colorMapping = {};
|
2017-11-16 15:08:14 +01:00
|
|
|
if (data === undefined || data.length == 0 || (data[0] == 0 && data[1] == 0)) {
|
|
|
|
toPlot = [{ label: 'No data', data: 100 }];
|
|
|
|
} else {
|
2017-11-17 09:13:18 +01:00
|
|
|
toPlot_obj = {}
|
|
|
|
for (var arr of data) {
|
|
|
|
var date = arr[0];
|
|
|
|
var items = arr[1]
|
|
|
|
for(var item_arr of items) {
|
2017-11-17 14:45:20 +01:00
|
|
|
var itemStr = JSON.stringify(item_arr[0]);
|
|
|
|
itemMapping[itemStr] = item_arr[0];
|
2017-11-17 09:13:18 +01:00
|
|
|
var count = item_arr[1];
|
2017-11-17 14:45:20 +01:00
|
|
|
if(toPlot_obj[itemStr] === undefined)
|
|
|
|
toPlot_obj[itemStr] = 0;
|
|
|
|
toPlot_obj[itemStr] += count;
|
2017-11-17 09:13:18 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-20 15:14:13 +01:00
|
|
|
if (Object.keys(toPlot_obj).length == 0) { // no data
|
|
|
|
toPlot = [{ label: 'No data', data: 100 }];
|
|
|
|
} else {
|
|
|
|
toPlot = [];
|
|
|
|
for (var itemStr in toPlot_obj) {
|
|
|
|
if (toPlot_obj.hasOwnProperty(itemStr)) {
|
2017-11-20 17:01:31 +01:00
|
|
|
var itemColor = itemMapping[itemStr].colour
|
|
|
|
colorMapping[itemStr] = itemColor;
|
|
|
|
toPlot.push({label: itemStr, data: toPlot_obj[itemStr], color: itemColor})
|
2017-11-20 15:14:13 +01:00
|
|
|
}
|
2017-11-17 09:13:18 +01:00
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
2017-11-20 15:14:13 +01:00
|
|
|
toPlot.sort(compareObj).reverse();
|
2017-11-21 15:20:07 +01:00
|
|
|
var maxNum = $('#num_selector').val();
|
|
|
|
toPlot = toPlot.slice(0,maxNum); // take at max 12 elements
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
|
|
|
if (!(pieWidget === undefined)) {
|
|
|
|
pieWidget.setData(toPlot);
|
|
|
|
pieWidget.setupGrid();
|
|
|
|
pieWidget.draw();
|
2017-11-20 17:01:31 +01:00
|
|
|
// fill colorMapping
|
|
|
|
for (item of pieWidget.getData()) {
|
|
|
|
colorMapping[item.label] = {colour: item.color};
|
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
} else {
|
|
|
|
pieWidget = $.plot(pieID, toPlot, pieChartOption);
|
|
|
|
pie.push(pieWidget);
|
2017-11-20 15:42:57 +01:00
|
|
|
// Hover
|
2017-11-17 10:41:22 +01:00
|
|
|
$(pieID).bind("plothover", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
$("#tooltip").html(legendFormatter(item.series.label))
|
|
|
|
.css({top: pos.pageY+5, left: pos.pageX+5})
|
|
|
|
.fadeIn(200);
|
2017-11-17 16:14:39 +01:00
|
|
|
} else {
|
|
|
|
$("#tooltip").hide();
|
|
|
|
}
|
|
|
|
});
|
2017-11-20 15:42:57 +01:00
|
|
|
// Click
|
|
|
|
$(pieID).bind("plotclick", function(event, pos, obj) {
|
|
|
|
if (!obj) { return; }
|
2017-11-20 17:01:31 +01:00
|
|
|
var specificLabel = obj.series.label;
|
|
|
|
colorMapping[specificLabel] = {};
|
|
|
|
colorMapping[specificLabel] = { colour: obj.series.color };
|
2017-11-21 08:42:54 +01:00
|
|
|
updateLineForLabel(line, specificLabel.substring(1, specificLabel.length-1), colorMapping, url);
|
2017-11-20 15:42:57 +01:00
|
|
|
});
|
2017-11-20 17:01:31 +01:00
|
|
|
for (item of pieWidget.getData()) {
|
|
|
|
colorMapping[item.label] = {colour: item.color};
|
|
|
|
}
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
2017-11-20 17:01:31 +01:00
|
|
|
return colorMapping;
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 17:01:31 +01:00
|
|
|
function updateLine(line, data, chartOptions, specificLabel, colorMapping) {
|
2017-11-16 15:08:14 +01:00
|
|
|
lineID = line[0];
|
|
|
|
lineWidget = line[1];
|
2017-11-20 17:01:31 +01:00
|
|
|
toPlot = generateEmptyAndFillData(data, specificLabel, colorMapping);
|
2017-11-16 16:57:48 +01:00
|
|
|
// plot
|
2017-11-16 15:08:14 +01:00
|
|
|
if (!(lineWidget === undefined)) {
|
|
|
|
lineWidget.setData(toPlot);
|
2017-11-16 16:57:48 +01:00
|
|
|
lineWidget.setupGrid();
|
2017-11-16 15:08:14 +01:00
|
|
|
lineWidget.draw();
|
|
|
|
} else {
|
2017-11-17 16:50:04 +01:00
|
|
|
if (chartOptions === undefined) {
|
|
|
|
chartOptions = lineChartOption;
|
|
|
|
}
|
|
|
|
lineWidget = $.plot(lineID, toPlot, chartOptions);
|
2017-11-16 15:08:14 +01:00
|
|
|
line.push(lineWidget);
|
2017-11-17 10:41:22 +01:00
|
|
|
$(lineID).bind("plothover", function (event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
$("#tooltip").html(legendFormatter(item.series.label))
|
|
|
|
.css({top: item.pageY+5, left: item.pageX+5})
|
|
|
|
.fadeIn(200);
|
|
|
|
} else {
|
|
|
|
$("#tooltip").hide();
|
|
|
|
}
|
|
|
|
});
|
2017-11-16 15:08:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:20 +01:00
|
|
|
function updateSignthingsChart() {
|
|
|
|
$.getJSON( url_getTrendingSightings+"?dateS="+parseInt(dateStart.getTime()/1000)+"&dateE="+parseInt(dateEnd.getTime()/1000), function( data ) {
|
|
|
|
var toPlot_obj = {};
|
|
|
|
toPlot_obj['Sightings'] = [];
|
|
|
|
toPlot_obj['False positive'] = [];
|
|
|
|
var allDates = [];
|
|
|
|
for (var arr of data) {
|
|
|
|
var date = new Date(arr[0]*1000);
|
|
|
|
date = new Date(date.valueOf() - date.getTimezoneOffset() * 60000); // center the data around the day
|
|
|
|
allDates.push(date);
|
|
|
|
var items = arr[1];
|
|
|
|
var sight = items.sightings;
|
|
|
|
var fp = items.false_positive;
|
|
|
|
toPlot_obj['Sightings'].push([date, sight]);
|
|
|
|
toPlot_obj['False positive'].push([date, -fp]);
|
|
|
|
}
|
|
|
|
toPlot = []
|
|
|
|
toPlot.push({label: 'Sightings', data: toPlot_obj['Sightings'], color: '#4da74d'})
|
|
|
|
toPlot.push({label: 'False positive', data: toPlot_obj['False positive'], color: '#cb4b4b'})
|
|
|
|
|
|
|
|
if (!(sightingLineWidget === undefined)) {
|
|
|
|
sightingLineWidget.setData(toPlot);
|
|
|
|
sightingLineWidget.setupGrid();
|
|
|
|
sightingLineWidget.draw();
|
|
|
|
} else {
|
|
|
|
var lineChartOptionSight = jQuery.extend(true, {}, lineChartOption);
|
|
|
|
lineChartOptionSight['legend']['show'] = true;
|
|
|
|
lineChartOptionSight['legend']['position'] = 'nw';
|
|
|
|
lineChartOptionSight['grid'] = {};
|
2017-11-21 15:24:49 +01:00
|
|
|
lineChartOptionSight['lines']['fill'] = true;
|
2017-11-17 14:45:20 +01:00
|
|
|
sightingLineWidget = $.plot("#sightingLine", toPlot, lineChartOptionSight);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-20 17:01:31 +01:00
|
|
|
function updateLineForLabel(line, specificLabel, colorMapping, url) {
|
2017-11-21 08:42:54 +01:00
|
|
|
$.getJSON( url+"?dateS="+parseInt(dateStart.getTime()/1000)+"&dateE="+parseInt(dateEnd.getTime()/1000)+"&specificLabel="+specificLabel, function( data ) {
|
2017-11-20 17:01:31 +01:00
|
|
|
updateLine(line, data, undefined, specificLabel, colorMapping);
|
2017-11-20 15:42:57 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:08:14 +01:00
|
|
|
function updatePieLine(pie, line, url) {
|
2017-11-17 09:13:18 +01:00
|
|
|
$.getJSON( url+"?dateS="+parseInt(dateStart.getTime()/1000)+"&dateE="+parseInt(dateEnd.getTime()/1000), function( data ) {
|
2017-11-20 17:01:31 +01:00
|
|
|
var colorMapping = updatePie(pie, line, data, url);
|
2017-11-21 09:17:02 +01:00
|
|
|
for (var item in colorMapping) {
|
|
|
|
if (colorMapping.hasOwnProperty(item) && colorMapping[item] != undefined) {
|
|
|
|
globalColorMapping[item] = colorMapping[item].colour;
|
|
|
|
}
|
|
|
|
}
|
2017-11-20 17:01:31 +01:00
|
|
|
updateLine(line, data, undefined, undefined, colorMapping);
|
2017-11-16 15:08:14 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-17 16:50:04 +01:00
|
|
|
function updateDisc() {
|
|
|
|
var lineChartOptionDisc = jQuery.extend(true, {}, lineChartOption);
|
|
|
|
lineChartOptionDisc['legend']['show'] = true;
|
|
|
|
lineChartOptionDisc['legend']['position'] = 'nw';
|
2017-11-21 15:24:49 +01:00
|
|
|
lineChartOptionDisc['lines']['fill'] = true;
|
2017-11-17 16:50:04 +01:00
|
|
|
$.getJSON( url_getTrendingDisc+"?dateS="+parseInt(dateStart.getTime()/1000)+"&dateE="+parseInt(dateEnd.getTime()/1000), function( data ) {
|
|
|
|
updateLine(discLine, data, lineChartOptionDisc);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-16 09:28:16 +01:00
|
|
|
var items_timeline = [];
|
2017-12-11 12:19:11 +01:00
|
|
|
function updateTimeline() {
|
2017-12-11 14:54:22 +01:00
|
|
|
var selected = $( "#timeline_selector" ).val();
|
|
|
|
$.getJSON( url_getGenericTrendingOvertime+"?dateS="+parseInt(dateStart.getTime()/1000)+"&dateE="+parseInt(dateEnd.getTime()/1000)+"&choice="+selected, function( data ) {
|
2018-01-16 09:28:16 +01:00
|
|
|
items_timeline = [];
|
2017-12-11 14:21:33 +01:00
|
|
|
var groups = new vis.DataSet();
|
|
|
|
var dico_groups = {};
|
2017-12-11 12:19:11 +01:00
|
|
|
var i = 1;
|
2017-12-11 14:21:33 +01:00
|
|
|
var g = 1;
|
2017-12-11 12:19:11 +01:00
|
|
|
for (var obj of data) {
|
2017-12-11 14:21:33 +01:00
|
|
|
var index = dico_groups[obj.name];
|
|
|
|
if (index == undefined) { // new group
|
2017-12-11 14:54:22 +01:00
|
|
|
index = groups.add({id: g, content: legendFormatter(obj.name)});
|
2017-12-11 14:21:33 +01:00
|
|
|
dico_groups[obj.name] = g;
|
|
|
|
g++;
|
|
|
|
}
|
2018-01-16 09:28:16 +01:00
|
|
|
items_timeline.push({
|
2017-12-11 12:19:11 +01:00
|
|
|
id: i,
|
2017-12-11 14:54:22 +01:00
|
|
|
content: getOnlyName(obj.name),
|
2018-01-16 09:28:16 +01:00
|
|
|
title: obj.name,
|
2017-12-11 12:19:11 +01:00
|
|
|
start: obj.start*1000,
|
2017-12-11 14:21:33 +01:00
|
|
|
end: obj.end*1000,
|
|
|
|
group: dico_groups[obj.name]
|
2017-12-11 12:19:11 +01:00
|
|
|
});
|
|
|
|
i++;
|
|
|
|
}
|
2018-01-16 09:28:16 +01:00
|
|
|
items_timeline = new vis.DataSet(items_timeline);
|
2017-12-11 12:19:11 +01:00
|
|
|
if (timeline === undefined) { // create timeline
|
2017-12-11 14:21:33 +01:00
|
|
|
timeline = new vis.Timeline(document.getElementById('timeline'));
|
2018-01-16 09:28:16 +01:00
|
|
|
// set listener for tooltip
|
|
|
|
timeline.on('doubleClick', function (properties) {
|
|
|
|
var type = $( "#timeline_selector" ).val();
|
|
|
|
var itemValue = items_timeline.get(properties.item).content;
|
|
|
|
if (type.localeCompare('events') == 0 || type.localeCompare('tags') == 0) { // Do not open a tab for categ
|
|
|
|
window.open(url_misp+'/'+type+'/index/searchall:'+itemValue, '_blank'); // as we do not have index for the moment, search it
|
|
|
|
}
|
|
|
|
});
|
2017-12-11 12:19:11 +01:00
|
|
|
}
|
2017-12-13 09:03:52 +01:00
|
|
|
var dateEndExtended = new Date(dateEnd).setDate(dateEnd.getDate()+1); // dateEnd+1
|
|
|
|
timeline_option.start = dateStart;
|
|
|
|
timeline_option.end = dateEndExtended;
|
|
|
|
timeline.setOptions(timeline_option);
|
2017-12-11 14:21:33 +01:00
|
|
|
timeline.setGroups(groups);
|
2018-01-16 09:28:16 +01:00
|
|
|
timeline.setItems(items_timeline);
|
2017-12-11 12:19:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:23:02 +01:00
|
|
|
function dateChanged() {
|
2017-11-17 09:13:18 +01:00
|
|
|
dateStart = datePickerWidgetStart.datepicker( "getDate" );
|
|
|
|
dateEnd = datePickerWidgetEnd.datepicker( "getDate" );
|
2017-11-17 14:45:20 +01:00
|
|
|
updatePieLine(eventPie, eventLine, url_getTrendingEvent);
|
|
|
|
updatePieLine(categPie, categLine, url_getTrendingCateg);
|
|
|
|
updatePieLine(tagPie, tagLine, url_getTrendingTag);
|
|
|
|
updateSignthingsChart();
|
2017-11-17 16:50:04 +01:00
|
|
|
updateDisc();
|
2017-12-11 12:19:11 +01:00
|
|
|
updateTimeline();
|
2017-11-16 12:23:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
2017-11-17 09:13:18 +01:00
|
|
|
datePickerWidgetStart = $( "#datepickerStart" ).datepicker(datePickerOptions);
|
|
|
|
var lastWeekDate = new Date();
|
|
|
|
lastWeekDate.setDate(lastWeekDate.getDate()-7);
|
|
|
|
datePickerWidgetStart.datepicker("setDate", lastWeekDate);
|
|
|
|
dateStart = datePickerWidgetStart.datepicker( "getDate" );
|
|
|
|
datePickerWidgetEnd = $( "#datepickerEnd" ).datepicker(datePickerOptions);
|
|
|
|
datePickerWidgetEnd.datepicker("setDate", new Date());
|
|
|
|
dateEnd = datePickerWidgetEnd.datepicker( "getDate" );
|
2017-11-16 15:08:14 +01:00
|
|
|
|
2017-11-20 17:42:25 +01:00
|
|
|
$('#typeaheadEvent').typeahead(typeaheadOption_event);
|
|
|
|
$('#typeaheadCateg').typeahead(typeaheadOption_categ);
|
|
|
|
$('#typeaheadTag').typeahead(typeaheadOption_tag);
|
|
|
|
|
2017-11-16 15:08:14 +01:00
|
|
|
updatePieLine(eventPie, eventLine, url_getTrendingEvent)
|
|
|
|
updatePieLine(categPie, categLine, url_getTrendingCateg)
|
|
|
|
updatePieLine(tagPie, tagLine, url_getTrendingTag)
|
2017-11-17 14:45:20 +01:00
|
|
|
updateSignthingsChart();
|
2017-11-17 16:50:04 +01:00
|
|
|
updateDisc();
|
2017-12-11 12:19:11 +01:00
|
|
|
updateTimeline();
|
2017-11-17 10:41:22 +01:00
|
|
|
|
2017-11-21 15:20:07 +01:00
|
|
|
$( "#num_selector" ).change(function() {
|
|
|
|
var sel = parseInt($( this ).val());
|
|
|
|
var maxNum = sel;
|
|
|
|
window.location.href = url_currentPage+'?maxNum='+maxNum;
|
|
|
|
});
|
|
|
|
|
2017-12-11 14:54:22 +01:00
|
|
|
$( "#timeline_selector" ).change(function() {
|
|
|
|
updateTimeline();
|
|
|
|
});
|
|
|
|
|
2017-11-17 10:41:22 +01:00
|
|
|
$("<div id='tooltip'></div>").css({
|
|
|
|
position: "absolute",
|
|
|
|
display: "none",
|
|
|
|
}).appendTo("body");
|
2017-11-16 12:23:02 +01:00
|
|
|
});
|