/* $This file is distributed under the terms of the license in /doc/license.txt$ */ (function ($) { $.fn.dataTableExt.oPagination.gmail_style = { "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) { //var nInfo = document.createElement( 'div' ); var nFirst = document.createElement( 'span' ); var nPrevious = document.createElement( 'span' ); var nNext = document.createElement( 'span' ); var nLast = document.createElement( 'span' ); /* nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst; nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious; nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext; nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast; */ nFirst.innerHTML = "« First"; nPrevious.innerHTML = " Prev"; nNext.innerHTML = "Next"; nLast.innerHTML = "Last»"; var oClasses = oSettings.oClasses; nFirst.className = oClasses.sPageButton+" "+oClasses.sPageFirst; nPrevious.className = oClasses.sPageButton+" "+oClasses.sPagePrevious; nNext.className= oClasses.sPageButton+" "+oClasses.sPageNext; nLast.className = oClasses.sPageButton+" "+oClasses.sPageLast; //nPaging.appendChild( nInfo ); nPaging.appendChild( nFirst ); nPaging.appendChild( nPrevious ); nPaging.appendChild( nNext ); nPaging.appendChild( nLast ); $(nFirst).click( function () { if ( oSettings.oApi._fnPageChange( oSettings, "first" ) ) { fnCallbackDraw( oSettings ); } } ); $(nPrevious).click( function() { if ( oSettings.oApi._fnPageChange( oSettings, "previous" ) ) { fnCallbackDraw( oSettings ); } } ); $(nNext).click( function() { if ( oSettings.oApi._fnPageChange( oSettings, "next" ) ) { fnCallbackDraw( oSettings ); } } ); $(nLast).click( function() { if ( oSettings.oApi._fnPageChange( oSettings, "last" ) ) { fnCallbackDraw( oSettings ); } } ); /* Take the brutal approach to cancelling text selection */ $('span', nPaging) .bind( 'mousedown', function () { return false; } ) .bind( 'selectstart', function () { return false; } ); /* ID the first elements only */ if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" ) { nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' ); nFirst.setAttribute( 'id', oSettings.sTableId+'_first' ); nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' ); //nInfo.setAttribute( 'id', 'infoContainer' ); nNext.setAttribute( 'id', oSettings.sTableId+'_next' ); nLast.setAttribute( 'id', oSettings.sTableId+'_last' ); } }, /* * Function: oPagination.full_numbers.fnUpdate * Purpose: Update the list of page buttons shows * Returns: - * Inputs: object:oSettings - dataTables settings object * function:fnCallbackDraw - draw function to call on page change */ "fnUpdate": function ( oSettings, fnCallbackDraw ) { if ( !oSettings.aanFeatures.p ) { return; } var iPageCount = 5; var iPageCountHalf = Math.floor(iPageCount / 2); var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength); var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; var iStartButton, iEndButton, i, iLen; var oClasses = oSettings.oClasses; /* Pages calculation */ if (iPages < iPageCount) { iStartButton = 1; iEndButton = iPages; } else { if (iCurrentPage <= iPageCountHalf) { iStartButton = 1; iEndButton = iPageCount; } else { if (iCurrentPage >= (iPages - iPageCountHalf)) { iStartButton = iPages - iPageCount + 1; iEndButton = iPages; } else { iStartButton = iCurrentPage - Math.ceil(iPageCount / 2) + 1; iEndButton = iStartButton + iPageCount - 1; } } } /* Loop over each instance of the pager */ var an = oSettings.aanFeatures.p; var anButtons, anStatic, nPaginateList; var fnClick = function() { /* Use the information in the element to jump to the required page */ var iTarget = (this.innerHTML * 1) - 1; oSettings._iDisplayStart = iTarget * oSettings._iDisplayLength; fnCallbackDraw( oSettings ); return false; }; var fnFalse = function () { return false; }; for ( i=0, iLen=an.length ; i el.height(); }; function width() { return t.width() > el.width(); }; var func = multiline ? height : width; while (text.length > 0 && func()) { text = text.substr(0, text.length - 1); t.html(text + "..."); } el.html(t.html()); t.remove(); } }); }; })(jQuery); /** * init sets some initial options for the default graph. i.e for when the page * is initially loaded or when its refreshed or when all the checkboxes on the * page are unchecked. * * @param graphContainer * is the div that contains the main graph. */ function init(graphContainer) { var optionSelected = $("select.comparisonValues option:selected").val(); // TODO: make use of the id on the select field instead of a generic one. $("#comparisonParameter").text("Total Number of " + $("select.comparisonValues option:selected").val()); $('#yaxislabel').html("Number of " + optionSelected).mbFlipText(false); $('#comparisonHeader').html(optionSelected).css('font-weight', 'bold'); var defaultFlotOptions = { xaxis : { min : globalDateObject.getFullYear() - 9, max : globalDateObject.getFullYear(), tickDecimals : 0, tickSize : 2 }, yaxis: { tickDecimals : 0, min : 0, max: 5 }, grid: { borderColor : "#D9D9D9" } }; /* * [[]] is an empty 2D array object. $.plot is passed this for the default * behavior. Ex.When the page initially loads, or when no graphs are present * on the webpage. */ var initialDataObject = [ [] ]; $.plot(graphContainer, initialDataObject, defaultFlotOptions); } /** * unStuffZerosFromLineGraphs removes the previously stuffed zero values. r is * the current data object. s is the current min and max {year} values. All the * datapoints < curr_min{year} && > > curr_max{year} are removed, so that they * don't show up on the graph * * @param {Object} * jsonObject * @param {Object} * arrayOfMinAndMaxYears * @returns jsonObject with modified data points. */ //TODO: side-effect year. function unStuffZerosFromLineGraphs(jsonObject, year) { calcZeroLessMinAndMax(jsonObject, year); var currentMinYear = year.globalMin, currentMaxYear = year.globalMax; var normalizedYearRange = getNormalizedYearRange(); $.each(jsonObject, function(key, val) { var i = 0; for (i = 0; i < val.data.length; i++) { if (((val.data[i][0] < normalizedYearRange.normalizedMinYear) || (val.data[i][0] > normalizedYearRange.normalizedMaxYear)) && val.data[i][1] == 0) { val.data.splice(i, 1); i--; } else { continue; } } }); } /** * while unStuffZerosFromLineGraphs is for a group of data objects, * unStuffZerosFromLineGraph is for a single data object. It removes zeroes from * the single object passed as parameter. * * @param {Object} * jsonObject */ function unStuffZerosFromLineGraph(jsonObject) { var i = 0; for (i = 0; i < jsonObject.data.length; i++) { if (jsonObject.data[i][1] == 0) { jsonObject.data.splice(i, 1); i--; } } } /** * This is used to normalize the year range for the currently selected entities to always * display the last 10 years worth of data points. * */ function getNormalizedYearRange() { /* * This is done to make sure that at least last 10 years worth of data points * can be displayed. * */ if (globalDateObject.getFullYear() < year.globalMax) { inferredMaxYear = year.globalMax; } else { inferredMaxYear = globalDateObject.getFullYear(); } if (globalDateObject.getFullYear() - 9 > year.globalMin) { inferredMinYear = year.globalMin; } else { inferredMinYear = globalDateObject.getFullYear() - 9; } return { normalizedMinYear: inferredMinYear, normalizedMaxYear: inferredMaxYear, normalizedRange: inferredMaxYear - inferredMinYear }; } /** * stuffZerosIntoLineGraphs is used to fill discontinuities in data points. For * example, if a linegraph has the following data points [1990, * 2],[1992,3],[1994, 5],[1996,5],[2000,4],[2001,1]. stuffZerosIntoLineGraphs * inserts [1991,0],[1993,0],1995,0]..and so on. It also inserts zeroes at the * beginning and the end if the max and min{year} of the current linegraph fall * in between the global max and min{year} * * @param {Object} * jsonObject * @param {Object} * arrayOfMinAndMaxYears * @returns jsonObject with stuffed data points. */ function stuffZerosIntoLineGraphs(jsonObject, year) { calcZeroLessMinAndMax(jsonObject, year); var normalizedYearRange = getNormalizedYearRange(); $.each(jsonObject, function(key, val) { var position = normalizedYearRange.normalizedMinYear, i = 0; //console.log(key, val, position, (arrayOfMinAndMaxYears[1] - arrayOfMinAndMaxYears[0]) + 1); for (i = 0; i < normalizedYearRange.normalizedRange + 1; i++) { //console.log("val.data[i]", val.data[i]); if (val.data[i]) { if (val.data[i][0] != position && position <= normalizedYearRange.normalizedMaxYear) { val.data.splice(i, 0, [ position, 0 ]); } } else { val.data.push( [ position, 0 ]); } position++; } }); //console.log("after stuffing", jsonObject); } /** * During runtime, when the user checks/unchecks a checkbox, the zeroes have to * be inserted and removed dynamically. This function calculates the max{year} * and min{year} among all the linegraphs present on the graph at a particular * instance in time . * * @param {Object} * jsonObject * @returns an array of current min and max years. */ function calcZeroLessMinAndMax(jsonObject, year) { var validYearsInData = new Array(); $.each(jsonObject, function(key, val) { for (i = 0; i < val.data.length; i++) { /* * TO make sure that, * 1. Not to consider years that dont have any counts attached to it. * 2. Not to consider unknown years indicated by "-1". * */ if (val.data[i][1] != 0 && val.data[i][0] != -1) { validYearsInData.push(val.data[i][0]); } } }); year.globalMin = Math.min.apply(Math, validYearsInData); year.globalMax = Math.max.apply(Math, validYearsInData); } /** * z is an an object with two properties label and data. data is of the form * [year,value] This function returns the min and max values of all such years. * * @param {Object} * jsonObject * @returns [minYear, maxYear] */ function calcMinandMaxYears(jsonObject, year) { var validYearsInData = new Array(); $.each(jsonObject, function(key, val) { for (i = 0; i < val.data.length; i++) { /* * TO make sure that, * 1. Not to consider years that dont have any counts attached to it. * 2. Not to consider unknown years indicated by "-1". * */ if (val.data[i][1] != 0 && val.data[i][0] != -1) { validYearsInData.push(val.data[i][0]); } } }); year.min = Math.min.apply(Math, validYearsInData); year.max = Math.max.apply(Math, validYearsInData); } /** * This function returns the max from the counts of all the entities. Mainly used to * normalize the width of bar below the line graph, also known as legend row. * @returns maxCount */ function calcMaxOfComparisonParameter(allEntities) { var validCountsInData = new Array(); $.each(allEntities, function(key, currentEntity) { validCountsInData.push(calcSumOfComparisonParameter(currentEntity)); }); return Math.max.apply(Math, validCountsInData); } function calcMaxWithinComparisonParameter(jsonObject){ var validCountsInData = new Array(); $.each(jsonObject, function(key, val) { for (i = 0; i < val.data.length; i++) { /* * TO make sure that, * 1. Not to consider years that dont have any counts attached to it. * 2. Not to consider unknown years indicated by "-1". * */ if (val.data[i][1] != 0 && val.data[i][0] != -1) { validCountsInData.push(val.data[i][1]); } } }); return Math.max.apply(Math, validCountsInData); } /** * This is used to find out the sum of all the counts of a particular entity. This is * especially useful to render the bars below the line graph where it doesnt matter if * a count has any associated year to it or not. * @returns sum{values}. */ function calcSumOfComparisonParameter(entity) { var sum = 0; $.each(entity.data, function(index, data){ sum += this[1]; }); return sum; } /** * A simple function to see if the passed * * @param {array} * objectArray * @param {Object} * object * @returns a flag - 0/1 - indicating whether a contains b. */ function contains(objectArray, object) { var i = 0, flag = 0; for (i = 0; i < objectArray.length; i++) { if (objectArray[i] == object) { flag = i; } } return flag; } /** * Dynamically change the linewidth and ticksize based on input year range. * * @param {Object} * yearRange */ function setLineWidthAndTickSize(yearRange, flotOptions) { if (yearRange > 0 && yearRange < 15) { flotOptions.series.lines.lineWidth = 3; flotOptions.xaxis.tickSize = 1; } else if (yearRange > 15 && yearRange < 70) { flotOptions.series.lines.lineWidth = 2; flotOptions.xaxis.tickSize = 5; } else if (yearRange == 0 ) { flotOptions.series.lines.lineWidth = 3; flotOptions.xaxis.tickSize = 1; } else { flotOptions.series.lines.lineWidth = 1; flotOptions.xaxis.tickSize = 10; } } /** * Dynamically change the ticksize of y-axis. */ function setTickSizeOfYAxis(maxValue, flotOptions){ var tickSize = 0; if (maxValue > 0 && maxValue <= 5) { flotOptions.yaxis.tickSize = 1; } else if (maxValue > 5 && maxValue <= 10) { flotOptions.yaxis.tickSize = 2; } else if (maxValue > 10 && maxValue <= 15) { flotOptions.yaxis.tickSize = 5; } else if (maxValue > 15 && maxValue <= 70) { flotOptions.yaxis.tickSize = 5; } else { flotOptions.yaxis.tickSize = 10; } } /** * Create a div that represents the rectangular bar A hidden input class that is * used to pass the value and a label beside the checkbox. * * @param {Object} * entityLabel */ function createLegendRow(entity, bottomDiv) { var parentP = $('

'); parentP.attr('id', slugify(entity.label)); var labelDiv = $('

'); labelDiv.attr('class', 'easy-deselect-label'); labelDiv.html('
'); /* * We should display a further drill-down option only when available. In case of people * there is no drill-down possible, so don't diaply the temporal graph icon. * */ if (entity.visMode !== "PERSON") { labelDiv.append(''); } var checkbox = $(''); checkbox.attr('type', 'checkbox'); checkbox.attr('checked', true); checkbox.attr('id', 'checkbox'); checkbox.attr('class', 'easyDeselectCheckbox'); checkbox.attr('value', entity.label); var hiddenLabel = $('