Skip to content
Snippets Groups Projects
Commit e5e3fa2c authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Resize pubdate visualization with page.

parent 12f8fb35
No related merge requests found
(function(n,p,u){var w=n([]),s=n.resize=n.extend(n.resize,{}),o,l="setTimeout",m="resize",t=m+"-special-event",v="delay",r="throttleWindow";s[v]=250;s[r]=true;n.event.special[m]={setup:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.add(a);n.data(this,t,{w:a.width(),h:a.height()});if(w.length===1){q()}},teardown:function(){if(!s[r]&&this[l]){return false}var a=n(this);w=w.not(a);a.removeData(t);if(!w.length){clearTimeout(o)}},add:function(b){if(!s[r]&&this[l]){return false}var c;function a(d,h,g){var f=n(this),e=n.data(this,t);e.w=h!==u?h:f.width();e.h=g!==u?g:f.height();c.apply(this,arguments)}if(n.isFunction(b)){c=b;return a}else{c=b.handler;b.handler=a}}};function q(){o=p[l](function(){w.each(function(){var d=n(this),a=d.width(),b=d.height(),c=n.data(this,t);if(a!==c.w||b!==c.h){d.trigger(m,[c.w=a,c.h=b])}});q()},s[v])}})(jQuery,this);(function(b){var a={};function c(f){function e(){var h=f.getPlaceholder();if(h.width()==0||h.height()==0){return}f.resize();f.setupGrid();f.draw()}function g(i,h){i.getPlaceholder().resize(e)}function d(i,h){i.getPlaceholder().unbind("resize",e)}f.hooks.bindEvents.push(g);f.hooks.shutdown.push(d)}b.plot.plugins.push({init:c,options:a,name:"resize",version:"1.0"})})(jQuery);
\ No newline at end of file
......@@ -2,118 +2,118 @@
function PadDigits(n, totalDigits)
{
if (n <= 0){
n= 1;
}
n = n.toString();
var pd = '';
if (totalDigits > n.length)
if (n <= 0){
n= 1;
}
n = n.toString();
var pd = '';
if (totalDigits > n.length)
{
for (var i=0; i < (totalDigits-n.length); i++)
{
for (var i=0; i < (totalDigits-n.length); i++)
{
pd += '0';
}
pd += '0';
}
return pd + n;
}
return pd + n;
}
function loadVis(facetFields, searchParams, baseURL, zooming) {
// options for the graph, TODO: make configurable
var options = {
series: {
bars: {
show: true,
align: "center",
fill: true,
fillColor: "rgb(234,234,234)"
}
},
colors: ["#0088CC"],
legend: { noColumns: 2 },
xaxis: { tickDecimals: 0 },
yaxis: { min: 0, ticks: [] },
selection: {mode: "x"},
grid: { backgroundColor: null /*"#ffffff"*/ }
};
// options for the graph, TODO: make configurable
var options = {
series: {
bars: {
show: true,
align: "center",
fill: true,
fillColor: "rgb(234,234,234)"
}
},
colors: ["#0088CC"],
legend: { noColumns: 2 },
xaxis: { tickDecimals: 0 },
yaxis: { min: 0, ticks: [] },
selection: {mode: "x"},
grid: { backgroundColor: null /*"#ffffff"*/ }
};
// AJAX call
var url = baseURL + '/AJAX/json?method=getVisData&facetFields=' + encodeURIComponent(facetFields) + '&' + searchParams;
$.getJSON(url, function (data) {
if (data.status == 'OK') {
$.each(data['data'], function(key, val) {
//check if there is data to display, if there isn't hide the box
if (val['data'] == undefined || val['data'].length == 0) {
return;
}
$("#datevis" + key + "xWrapper").show();
// AJAX call
var url = baseURL + '/AJAX/json?method=getVisData&facetFields=' + encodeURIComponent(facetFields) + '&' + searchParams;
$.getJSON(url, function (data) {
if (data.status == 'OK') {
$.each(data['data'], function(key, val) {
//check if there is data to display, if there isn't hide the box
if (val['data'] == undefined || val['data'].length == 0) {
return;
}
$("#datevis" + key + "xWrapper").show();
// plot graph
var placeholder = $("#datevis" + key + "x");
// plot graph
var placeholder = $("#datevis" + key + "x");
//set up the hasFilter variable
var hasFilter = true;
//set up the hasFilter variable
var hasFilter = true;
//set the has filter
if (val['min'] == 0 && val['max']== 0) {
hasFilter = false;
}
//set the has filter
if (val['min'] == 0 && val['max']== 0) {
hasFilter = false;
}
//check if the min and max value have been set otherwise set them to the ends of the graph
if (val['min'] == 0) {
val['min'] = val['data'][0][0] - 5;
}
if (val['max']== 0) {
val['max'] = parseInt(val['data'][val['data'].length - 1][0], 10) + 5;
}
//check if the min and max value have been set otherwise set them to the ends of the graph
if (val['min'] == 0) {
val['min'] = val['data'][0][0] - 5;
}
if (val['max']== 0) {
val['max'] = parseInt(val['data'][val['data'].length - 1][0], 10) + 5;
}
if (zooming) {
//check the first and last elements of the data array against min and max value (+padding)
//if the element exists leave it, otherwise create a new marker with a minus one value
if (val['data'][val['data'].length - 1][0] != parseInt(val['max'], 10) + 5) {
val['data'].push([parseInt(val['max'], 10) + 5, -1]);
}
if (val['data'][0][0] != val['min'] - 5) {
val['data'].push([val['min'] - 5, -1]);
}
//check for values outside the selected range and remove them by setting them to null
for (var i=0; i<val['data'].length; i++) {
if (val['data'][i][0] < val['min'] -5 || val['data'][i][0] > parseInt(val['max'], 10) + 5) {
//remove this
val['data'].splice(i,1);
i--;
}
}
if (zooming) {
//check the first and last elements of the data array against min and max value (+padding)
//if the element exists leave it, otherwise create a new marker with a minus one value
if (val['data'][val['data'].length - 1][0] != parseInt(val['max'], 10) + 5) {
val['data'].push([parseInt(val['max'], 10) + 5, -1]);
}
if (val['data'][0][0] != val['min'] - 5) {
val['data'].push([val['min'] - 5, -1]);
}
//check for values outside the selected range and remove them by setting them to null
for (var i=0; i<val['data'].length; i++) {
if (val['data'][i][0] < val['min'] -5 || val['data'][i][0] > parseInt(val['max'], 10) + 5) {
//remove this
val['data'].splice(i,1);
i--;
}
}
} else {
//no zooming means that we need to specifically set the margins
//do the last one first to avoid getting the new last element
val['data'].push([parseInt(val['data'][val['data'].length - 1][0], 10) + 5, -1]);
//now get the first element
val['data'].push([val['data'][0][0] - 5, -1]);
}
} else {
//no zooming means that we need to specifically set the margins
//do the last one first to avoid getting the new last element
val['data'].push([parseInt(val['data'][val['data'].length - 1][0], 10) + 5, -1]);
//now get the first element
val['data'].push([val['data'][0][0] - 5, -1]);
}
var plot = $.plot(placeholder, [val], options);
if (hasFilter) {
// mark pre-selected area
plot.setSelection({ x1: val['min'] , x2: val['max']});
}
// selection handler
placeholder.bind("plotselected", function (event, ranges) {
var from = Math.floor(ranges.xaxis.from);
var to = Math.ceil(ranges.xaxis.to);
location.href = val['removalURL'] + '&daterange[]=' + key + '&' + key + 'to=' + PadDigits(to,4) + '&' + key + 'from=' + PadDigits(from,4);
});
var plot = $.plot(placeholder, [val], options);
if (hasFilter) {
// mark pre-selected area
plot.setSelection({ x1: val['min'] , x2: val['max']});
}
// selection handler
placeholder.bind("plotselected", function (event, ranges) {
var from = Math.floor(ranges.xaxis.from);
var to = Math.ceil(ranges.xaxis.to);
location.href = val['removalURL'] + '&daterange[]=' + key + '&' + key + 'to=' + PadDigits(to,4) + '&' + key + 'from=' + PadDigits(from,4);
});
if (hasFilter) {
var newdiv = document.createElement('div');
var text = document.getElementById("clearButtonText").innerHTML;
newdiv.setAttribute('id', 'clearButton' + key);
newdiv.innerHTML = '<a href="' + htmlEncode(val['removalURL']) + '">' + text + '</a>';
newdiv.className += "dateVisClear";
placeholder.append(newdiv);
}
});
if (hasFilter) {
var newdiv = document.createElement('div');
var text = document.getElementById("clearButtonText").innerHTML;
newdiv.setAttribute('id', 'clearButton' + key);
newdiv.innerHTML = '<a href="' + htmlEncode(val['removalURL']) + '">' + text + '</a>';
newdiv.className += "dateVisClear";
placeholder.append(newdiv);
}
});
});
}
});
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
<? /* load jQuery flot */ ?>
<?$this->headScript()->appendFile('flot/excanvas.min.js', null, array('conditional' => 'IE'));
$this->headScript()->appendFile('flot/jquery.flot.min.js');
$this->headScript()->appendFile('flot/jquery.flot.resize.min.js');
$this->headScript()->appendFile('flot/jquery.flot.selection.min.js');
$this->headScript()->appendFile('pubdate_vis.js'); ?>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment