/* $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; // console.log(iPageCount, // iPageCountHalf, // iPages, // iCurrentPage, // 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 < iLen; i++) { if (an[i].childNodes.length === 0) { continue; } /* Update the 'premanent botton's classes */ anButtons = an[i].getElementsByTagName('span'); anStatic = [ anButtons[0], anButtons[1], anButtons[anButtons.length - 2], anButtons[anButtons.length - 1]]; $(anStatic).removeClass(oClasses.sPageButton + " " + oClasses.sPageButtonActive + " " + oClasses.sPageButtonStaticDisabled); if (iCurrentPage == 1) { anStatic[0].className += " " + oClasses.sPageButtonStaticDisabled; anStatic[1].className += " " + oClasses.sPageButtonStaticDisabled; } else { anStatic[0].className += " " + oClasses.sPageButton; anStatic[1].className += " " + oClasses.sPageButton; } if (iPages === 0 || iCurrentPage == iPages || oSettings._iDisplayLength == -1) { anStatic[2].className += " " + oClasses.sPageButtonStaticDisabled; anStatic[3].className += " " + oClasses.sPageButtonStaticDisabled; } else { anStatic[2].className += " " + oClasses.sPageButton; anStatic[3].className += " " + oClasses.sPageButton; } } if (iPages <= 1) { $("." + temporalGraphProcessor.dataTableParams.paginationContainerDIVClass).hide(); } else { $("." + temporalGraphProcessor.dataTableParams.paginationContainerDIVClass).show(); } } }; $.fn.ellipsis = function () { return this.each(function () { var el = $(this); if (el.css("overflow") == "hidden") { var text = el.html(); var multiline = el.hasClass('multiline'); var t = $(this.cloneNode(true)).hide().css('position', 'absolute').css('overflow', 'visible').width(multiline ? el.width() : 'auto').height(multiline ? 'auto' : el.height()); el.after(t); function height() { return t.height() > 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 " + optionSelected); $('#yaxislabel').html("Number of " + optionSelected).mbFlipText(false); $('#comparisonHeader').html(optionSelected).css('font-weight', 'bold'); $('#legend-known-bar-text').text(COMPARISON_PARAMETERS_INFO[currentParameter].name + " with known year"); $('#legend-current-year-bar-text').text(COMPARISON_PARAMETERS_INFO[currentParameter].name + " from current incomplete year"); $('#legend-unknown-bar-text').text(COMPARISON_PARAMETERS_INFO[currentParameter].name + " with unknown year"); var defaultFlotOptions = { xaxis : { min : globalDateObject.getFullYear() - 10, max : globalDateObject.getFullYear() - 1, 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) { combinedCount = calcSumOfComparisonParameter(currentEntity); validCountsInData.push(combinedCount.knownYearCount + combinedCount.unknownYearCount); }); 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 known = 0; var unknown = 0; var currentYear = 0; $.each(entity.data, function(index, data){ if (this[0] === -1) { unknown += this[1]; } else { known += this[1]; if (this[0] === globalDateObject.getFullYear()) { currentYear += this[1]; } } }); sum = { knownYearCount: known, unknownYearCount: unknown, currentYearCount: currentYear }; 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; } var LineWidth = { getLineWidth: function(tickSize) { if (tickSize >= 0 && tickSize < 10) { return 3; } else if (tickSize >= 10 && tickSize < 50) { return 2; } else { return 1; } } }; var TickSize = { maxValue: 0.0, maxTicks: { yAxis: 12.0, xAxis: 12.0 }, tickSizeUnits: { yAxis: [1.0, 2.5, 5.0], xAxis: [1.0, 2, 5.0] }, getApproximateTickSize: function(allowedMaxTicks) { return Math.max(Math.ceil(parseFloat(this.maxValue) / allowedMaxTicks), 1.0); }, getFinalTickSize: function(unitTickSizeGenerator) { tickSizeMultiplier = 1.0; finalTickSize = 1.0; approximateTickSize = this.getApproximateTickSize(this.maxTicks.yAxis); while (true) { if (approximateTickSize <= (unitTickSizeGenerator[0] * tickSizeMultiplier)) { finalTickSize = unitTickSizeGenerator[0] * tickSizeMultiplier; break; } if (approximateTickSize <= (unitTickSizeGenerator[1] * tickSizeMultiplier)) { finalTickSize = unitTickSizeGenerator[1] * tickSizeMultiplier; break; } if (approximateTickSize <= (unitTickSizeGenerator[2] * tickSizeMultiplier)) { finalTickSize = unitTickSizeGenerator[2] * tickSizeMultiplier; break; } tickSizeMultiplier *= 10.0; } return finalTickSize; }, getTickSize: function(value, onAxis) { this.maxValue = value; if (onAxis.trim().toLowerCase() === 'y') { return this.getFinalTickSize(this.tickSizeUnits.yAxis); } else if (onAxis.trim().toLowerCase() === 'x') { return this.getFinalTickSize(this.tickSizeUnits.xAxis); } } }; /** * 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.entityURI)); 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.entityURI); var hiddenLabel = $('