diff options
author | isjusterin <erinproductions@gmail.com> | 2015-07-22 19:06:03 -0500 |
---|---|---|
committer | isjusterin <erinproductions@gmail.com> | 2015-07-22 19:06:03 -0500 |
commit | eda26599175299cd1481bc93ecfc57c4840f8705 (patch) | |
tree | 5bb7fed81f5788ed955bcc1f341667466d3c6d0c /comiccontrol/includes | |
parent | 2e1397a1c1ee6bde877c351010e0fdaed43efd25 (diff) | |
download | ComicControl-3.0-master.zip ComicControl-3.0-master.tar.gz ComicControl-3.0-master.tar.bz2 |
ComicControl files to be dumped in root folderHEADorigin/masterorigin/HEADmaster
Diffstat (limited to 'comiccontrol/includes')
-rw-r--r-- | comiccontrol/includes/chart.js | 7068 | ||||
-rw-r--r-- | comiccontrol/includes/dragndrop.js | 56 | ||||
-rw-r--r-- | comiccontrol/includes/footer.php | 3 | ||||
-rw-r--r-- | comiccontrol/includes/header.php | 67 | ||||
-rw-r--r-- | comiccontrol/includes/jquery.js | 4 | ||||
-rw-r--r-- | comiccontrol/includes/lightGallery.css | 629 | ||||
-rw-r--r-- | comiccontrol/includes/lightGallery.js | 781 |
7 files changed, 8608 insertions, 0 deletions
diff --git a/comiccontrol/includes/chart.js b/comiccontrol/includes/chart.js new file mode 100644 index 0000000..ecb869f --- /dev/null +++ b/comiccontrol/includes/chart.js @@ -0,0 +1,7068 @@ +/* + * ChartNew.js + * + * Vancoppenolle Francois - January 2014 + * francois.vancoppenolle@favomo.be + * + * Source location : http:\\www.favomo.be\graphjs + * GitHub community : https://github.com/FVANCOP/ChartNew.js + * + * This file is originally an adaptation of the chart.js source developped by Nick Downie (2013) + * https://github.com/nnnick/Chart.js. But since june 2014, Nick puts a new version with a + * refunded code. Current code of ChartNew.js is no more comparable to the code of Chart.js + * + * new charts compared to Chart.js + * + * horizontalBar + * horizontalStackedBar + * + * Added items compared to Chart.js: + * + * Title, Subtitle, footnotes, axis labels, unit label + * Y Axis on the right and/or the left + * canvas Border + * Legend + * crossText, crossImage + * graphMin, graphMax + * logarithmic y-axis (for line and bar) + * rotateLabels + * and lot of others... + * + */ +// non standard functions; + +var chartJSLineStyle=[]; + +chartJSLineStyle["solid"]=[]; +chartJSLineStyle["dotted"]=[1,4]; +chartJSLineStyle["shortDash"]=[2,1]; +chartJSLineStyle["dashed"]=[4,2]; +chartJSLineStyle["dashSpace"]=[4,6]; +chartJSLineStyle["longDashDot"]=[7,2,1,2]; +chartJSLineStyle["longDashShortDash"]=[10,4,4,4]; +chartJSLineStyle["gradient"]=[1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,9,9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1]; + +function lineStyleFn(data) +{ +if ((typeof chartJSLineStyle[data]) === "object")return chartJSLineStyle[data]; +else return chartJSLineStyle["solid"]; +}; + +if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } +}; +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(searchElement /*, fromIndex */ ) { + "use strict"; + if (this == null) { + throw new TypeError(); + } + var t = Object(this); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } + var n = 0; + if (arguments.length > 0) { + n = Number(arguments[1]); + if (n != n) { // shortcut for verifying if it's NaN + n = 0; + } else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + if (n >= len) { + return -1; + } + var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0); + for (; k < len; k++) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + } +}; +var charJSPersonalDefaultOptions = {}; +var charJSPersonalDefaultOptionsLine = {} ; +var charJSPersonalDefaultOptionsRadar = {} ; +var charJSPersonalDefaultOptionsPolarArea = {} ; +var charJSPersonalDefaultOptionsPie = {}; +var charJSPersonalDefaultOptionsDoughnut = {}; +var charJSPersonalDefaultOptionsBar = {}; +var charJSPersonalDefaultOptionsStackedBar = {}; +var charJSPersonalDefaultOptionsHorizontalBar = {}; +var charJSPersonalDefaultOptionsHorizontalStackedBar = {}; + ///////// FUNCTIONS THAN CAN BE USED IN THE TEMPLATES /////////////////////////////////////////// + +function roundToWithThousands(config, num, place) { + var newval = 1 * unFormat(config, num); + if (typeof(newval) == "number" && place != "none") { + var roundVal; + if (place <= 0) { + roundVal = -place; + newval = +(Math.round(newval + "e+" + roundVal) + "e-" + roundVal); + } else { + roundVal = place; + var divval = "1e+" + roundVal; + newval = +(Math.round(newval / divval)) * divval; + } + } + newval = fmtChartJS(config, newval, "none"); + return (newval); +}; + +function unFormat(config, num) { + if ((config.decimalSeparator != "." || config.thousandSeparator != "") && typeof(num) == "string") { + var v1 = "" + num; + if (config.thousandSeparator != "") { + while (v1.indexOf(config.thousandSeparator) >= 0) v1 = "" + v1.replace(config.thousandSeparator, ""); + } + if (config.decimalSeparator != ".") v1 = "" + v1.replace(config.decimalSeparator, ".") + return 1 * v1; + } else { + return num; + } +}; +///////// ANNOTATE PART OF THE SCRIPT /////////////////////////////////////////// +/******************************************************************************** +Copyright (C) 1999 Thomas Brattli +This script is made by and copyrighted to Thomas Brattli +Visit for more great scripts. This may be used freely as long as this msg is intact! +I will also appriciate any links you could give me. +Distributed by Hypergurl +********************************************************************************/ +var cachebis = {}; + +function fmtChartJSPerso(config, value, fmt) { + switch (fmt) { + case "SampleJS_Format": + if (typeof(value) == "number") return_value = "My Format : " + value.toString() + " $"; + else return_value = value + "XX"; + break; + case "Change_Month": + if (typeof(value) == "string") return_value = value.toString() + " 2014"; + else return_value = value.toString() + "YY"; + break; + default: + return_value = value; + break; + } + return (return_value); +}; + +function fmtChartJS(config, value, fmt) { + var return_value; + if (fmt == "notformatted") { + return_value = value; + } else if (fmt == "none" && typeof(value) == "number") { + if (config.roundNumber != "none") { + var roundVal; + if (config.roundNumber <= 0) { + roundVal = -config.roundNumber; + value = +(Math.round(value + "e+" + roundVal) + "e-" + roundVal); + } else { + roundVal = config.roundNumber; + var divval = "1e+" + roundVal; + value = +(Math.round(value / divval)) * divval; + } + } + if (config.decimalSeparator != "." || config.thousandSeparator != "") { + return_value = value.toString().replace(/\./g, config.decimalSeparator); + if (config.thousandSeparator != "") { + var part1 = return_value; + var part2 = ""; + var posdec = part1.indexOf(config.decimalSeparator); + if (posdec >= 0) { + part2 = part1.substring(posdec + 1, part1.length); + part2 = part2.split('').reverse().join(''); // reverse string + part1 = part1.substring(0, posdec); + } + part1 = part1.toString().replace(/\B(?=(\d{3})+(?!\d))/g, config.thousandSeparator); + part2 = part2.split('').reverse().join(''); // reverse string + return_value = part1 + if (part2 != "") return_value = return_value + config.decimalSeparator + part2; + } + } else return_value = value; + } else if (fmt != "none" && fmt != "notformatted") { + return_value = fmtChartJSPerso(config, value, fmt); + } else { + return_value = value; + } + return (return_value); +}; + +function addParameters2Function(data, fctName, fctList) { + var mathFunctions = { + mean: { + data: data.data, + datasetNr: data.v11 + }, + varianz: { + data: data.data, + datasetNr: data.v11 + }, + stddev: { + data: data.data, + datasetNr: data.v11 + }, + cv: { + data: data.data, + datasetNr: data.v11 + }, + median: { + data: data.data, + datasetNr: data.v11 + } + }; + // difference to current value (v3) + dif = false; + if (fctName.substr(-3) == "Dif") { + fctName = fctName.substr(0, fctName.length - 3); + dif = true; + } + if (typeof eval(fctName) == "function") { + var parameter = eval(fctList + "." + fctName); + if (dif) { + // difference between v3 (current value) and math function + return data.v3 - window[fctName](parameter); + } + return window[fctName](parameter); + } + return null; +}; + +function isNumber(n) { + return !isNaN(parseFloat(n)) && isFinite(n); +}; + +function tmplbis(str, data,config) { + newstr=str; + if(newstr.substr(0,config.templatesOpenTag.length)==config.templatesOpenTag)newstr="<%="+newstr.substr(config.templatesOpenTag.length,newstr.length-config.templatesOpenTag.length); + if(newstr.substr(newstr.length-config.templatesCloseTag.length,config.templatesCloseTag.length)==config.templatesCloseTag)newstr=newstr.substr(0,newstr.length-config.templatesCloseTag.length)+"%>"; + return tmplter(newstr,data); +} + +function tmplter(str, data) { + var mathFunctionList = ["mean", "varianz", "stddev", "cv", "median"]; + var regexMath = new RegExp('<%=((?:(?:.*?)\\W)??)((?:' + mathFunctionList.join('|') + ')(?:Dif)?)\\(([0-9]*?)\\)(.*?)%>', 'g'); + while (regexMath.test(str)) { + str = str.replace(regexMath, function($0, $1, $2, $3, $4) { + var rndFac; + if ($3) rndFac = $3; + else rndFac = 2; + var value = addParameters2Function(data, $2, "mathFunctions"); + if (isNumber(value)) + return '<%=' + $1 + '' + Math.round(Math.pow(10, rndFac) * value) / Math.pow(10, rndFac) + '' + $4 + '%>'; + return '<%= %>'; + }); + } + // Figure out if we're getting a template, or if we need to + // load the template - and be sure to cache the result. + // first check if it's can be an id + var fn = /^[A-Za-z][-A-Za-z0-9_:.]*$/.test(str) ? cachebis[str] = cachebis[str] || + tmplter(document.getElementById(str).innerHTML) : + // Generate a reusable function that will serve as a template + // generator (and which will be cached). + new Function("obj", + "var p=[],print=function(){p.push.apply(p,arguments);};" + + // Introduce the data as local variables using with(){} + "with(obj){p.push('" + + // Convert the template into pure JavaScript + str + .replace(/[\r\n]/g, "\\n") + .replace(/[\t]/g, " ") + .split("<%").join("\t") + .replace(/((^|%>)[^\t]*)'/g, "$1\r") + .replace(/\t=(.*?)%>/g, "',$1,'") + .split("\t").join("');") + .split("%>").join("p.push('") + .split("\r").join("\\'") + "');}return p.join('');"); + // Provide some basic currying to the user + return data ? fn(data) : fn; +}; +if (typeof CanvasRenderingContext2D !== 'undefined') { + /** + * ctx.prototype + * fillText option for canvas Multiline Support + * @param text string \n for newline + * @param x x position + * @param y y position + * @param yLevel = "bottom" => last line has this y-Pos [default], = "middle" => the middle line has this y-Pos) + * @param lineHeight lineHeight + * @param horizontal horizontal + */ + CanvasRenderingContext2D.prototype.fillTextMultiLine = function(text, x, y, yLevel, lineHeight,horizontal) { + var lines = ("" + text).split("\n"); + // if its one line => in the middle + // two lines one above the mid one below etc. + if (yLevel == "middle") { + if(horizontal)y -= ((lines.length - 1) / 2) * lineHeight; + } else if (yLevel == "bottom") { // default + if(horizontal)y -= (lines.length - 1) * lineHeight; + } + for (var i = 0; i < lines.length; i++) { + this.fillText(lines[i], x, y); + y += lineHeight; + } + }; + CanvasRenderingContext2D.prototype.measureTextMultiLine = function(text, lineHeight) { + var textWidth = 0; + var lg; + var lines = ("" + text).split("\n"); + var textHeight = lines.length * lineHeight; + // if its one line => in the middle + // two lines one above the mid one below etc. + for (var i = 0; i < lines.length; i++) { + lg = this.measureText(lines[i]).width; + if (lg > textWidth) textWidth = lg; + } + return { + textWidth: textWidth, + textHeight: textHeight + }; + }; + if (typeof CanvasRenderingContext2D.prototype.setLineDash !== 'function') { + CanvasRenderingContext2D.prototype.setLineDash = function( listdash) { + return 0; + }; + }; +}; +cursorDivCreated = false; + +function createCursorDiv() { + if (cursorDivCreated == false) { + var div = document.createElement('divCursor'); + div.id = 'divCursor'; + div.style.position = 'absolute'; + document.body.appendChild(div); + cursorDivCreated = true; + } +}; + +initChartJsResize = false; +var jsGraphResize = new Array(); + +function addResponsiveChart(id,ctx,data,config) { + initChartResize(); + var newSize=resizeGraph(ctx,config); + if(typeof ctx.prevWidth != "undefined") { + resizeCtx(ctx,newSize.newWidth,newSize.newHeight,config); + ctx.prevWidth=newSize.newWidth; + } else if (config.responsiveScaleContent && config.responsiveWindowInitialWidth) { + ctx.initialWidth =newSize.newWidth; + } + + ctx.prevWidth=newSize.newWidth; + ctx.prevHeight=newSize.newHeight; + jsGraphResize[jsGraphResize.length]= [id,ctx.tpchart,ctx,data,config]; +}; + +function initChartResize() { + if(initChartJsResize==false) { + if (window.addEventListener) { + window.addEventListener("resize", chartJsResize); + } else { + window.attachEvent("resize", chartJsResize); + } + } +}; + +var container; +function getMaximumWidth(domNode){ + if(domNode.parentNode!=null) + if(domNode.parentNode!=undefined) + container = domNode.parentNode; + return container.clientWidth; +}; + +function getMaximumHeight(domNode){ + if(domNode.parentNode!=null) + if(domNode.parentNode!=undefined) + container = domNode.parentNode; + return container.clientHeight; +}; + +function resizeCtx(ctx,newWidth,newHeight,config) +{ + if (window.devicePixelRatio) { // Retina device + ctx.canvas.style.width = newWidth/window.devicePixelRatio + "px"; + ctx.canvas.style.height = newHeight/window.devicePixelRatio + "px"; + ctx.canvas.height = newHeight/window.devicePixelRatio * window.devicePixelRatio; + ctx.canvas.width = newWidth/window.devicePixelRatio * window.devicePixelRatio; + ctx.scale(window.devicePixelRatio, window.devicePixelRatio); + if(typeof ctx.chartTextScale != "undefined" && config.responsiveScaleContent) { + ctx.chartTextScale=config.chartTextScale*(newWidth/ctx.initialWidth); + ctx.chartLineScale=config.chartLineScale*(newWidth/ctx.initialWidth); + ctx.chartSpaceScale=config.chartSpaceScale*(newWidth/ctx.initialWidth); + } + } else { + ctx.canvas.height = newHeight ; + ctx.canvas.width = newWidth; + /* new ratio */ + if(typeof ctx.chartTextScale != "undefined" && config.responsiveScaleContent) { + ctx.chartTextScale=config.chartTextScale*(newWidth/ctx.initialWidth); + ctx.chartLineScale=config.chartLineScale*(newWidth/ctx.initialWidth); + ctx.chartSpaceScale=config.chartSpaceScale*(newWidth/ctx.initialWidth); + } + } +}; + +function resizeGraph(ctx,config) { + if(typeof config.maintainAspectRatio == "undefined")config.maintainAspectRatio=true; + if(typeof config.responsiveMinWidth == "undefined")config.responsiveMinWidth=0; + if(typeof config.responsiveMinHeight == "undefined")config.responsiveMinHeight=0; + if(typeof config.responsiveMaxWidth == "undefined")config.responsiveMaxWidth=9999999; + if(typeof config.responsiveMaxHeight == "undefined")config.responsiveMaxHeight=9999999; + var canvas = ctx.canvas; + if(typeof ctx.aspectRatio == "undefined") { + ctx.aspectRatio = canvas.width / canvas.height; + } + + var newWidth = getMaximumWidth(canvas); + var newHeight = config.maintainAspectRatio ? newWidth / ctx.aspectRatio : getMaximumHeight(canvas); + newWidth=Math.min(config.responsiveMaxWidth,Math.max(config.responsiveMinWidth,newWidth)); + newHeight=Math.min(config.responsiveMaxHeight,Math.max(config.responsiveMinHeight,newHeight)); + return { newWidth : parseInt(newWidth), newHeight : parseInt(newHeight)}; +}; + + + +function chartJsResize() { + for (var i=0;i<jsGraphResize.length;i++) { + if(typeof jsGraphResize[i][2].firstPass != "undefined") { + if(jsGraphResize[i][2].firstPass == 5)jsGraphResize[i][2].firstPass=6; + } + subUpdateChart(jsGraphResize[i][2],jsGraphResize[i][3],jsGraphResize[i][4]); + } +}; + +function testRedraw(ctx,data,config) { + if (ctx.firstPass==2 || ctx.firstPass==4 || ctx.firstPass==9) { + ctx.firstPass=6; + subUpdateChart(ctx,data,config) ; + return true; + } else { + ctx.firstPass=5; + return false; + } +}; + +function updateChart(ctx,data,config,animation,runanimationcompletefunction) { + if (ctx.firstPass==5) + { + ctx.runanimationcompletefunction=runanimationcompletefunction; + if(animation)ctx.firstPass=0; + else if (config.responsive) ctx.firstPass=7; + else ctx.firstPass=7; + subUpdateChart(ctx,data,config) ; + + } +}; + +function subUpdateChart(ctx,data,config) { + // ctx.firstPass==undefined => graph never drawn + // ctx.firstPass==0 => graph is drawn but need to be redrawn with animation + // ctx.firstPass==1 => graph is drawn with animation + // ctx.firstPass==2 => graph is in animation but at the end the graph need perhaps to be redrawn; + // ctx.firstPass==3 => graph currently drawing without animation; + // ctx.firstPass==4 => graph currently drawing without animationb but at the end, the graph need perhaps to be redrawn; + // ctx.firstPass==5 => graph is displayed ; + // ctx.firstPass==6 => graph is displayed but need to be redraw without animation (because of a resize); + // ctx.firstPass==7 => graph is displayed but need to be redraw without responsivity; + if(!dynamicFunction(data, config, ctx)) { return; } + var newSize; + if(typeof ctx.firstPass == "undefined") { + ctx.firstPass=1; + newSize=resizeGraph(ctx,config); + if(config.responsive) { + resizeCtx(ctx,newSize.newWidth,newSize.newHeight,config); + ctx.prevWidth=newSize.newWidth; + ctx.prevHeight=newSize.newHeight; + } else { + ctx.prevWidth=0; + ctx.prevHeight=0; + } + ctx.runanimationcompletefunction=true; + redrawGraph(ctx,data,config); + } else if(ctx.firstPass == 0) { + ctx.firstPass=1; + newSize=resizeGraph(ctx,config); + if(config.responsive) { + resizeCtx(ctx,newSize.newWidth,newSize.newHeight,config); + ctx.prevWidth=newSize.newWidth; + ctx.prevHeight=newSize.newHeight; + } else { + ctx.prevWidth=0; + ctx.prevHeight=0; + } + redrawGraph(ctx,data,config); + } else if(ctx.firstPass==1 || ctx.firstPass==2) { + ctx.firstPass=2; + } else if (ctx.firstPass==3 || ctx.firstPass==4) { + ctx.firstPass=4; + } else if(ctx.firstPass==5) { + ctx.firstPass=1; + redrawGraph(ctx,data,config); + } else if(ctx.firstPass==6) { + newSize=resizeGraph(ctx,config); + if (newSize.newWidth!=ctx.prevWidth || newSize.newHeight != ctx.prevHeight) { + ctx.firstPass=3; + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); + if(config.responsive) { + resizeCtx(ctx,newSize.newWidth,newSize.newHeight,config); + ctx.prevWidth=newSize.newWidth; + ctx.prevHeight=newSize.newHeight; + } else { + ctx.prevWidth=0; + ctx.prevHeight=0; + } + redrawGraph(ctx,data,config); + } else ctx.firstPass=5; + } else if(ctx.firstPass==7) { + newSize=resizeGraph(ctx,config); + ctx.firstPass=3; + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); + if(config.responsive) { + resizeCtx(ctx,newSize.newWidth,newSize.newHeight,config); + ctx.prevWidth=newSize.newWidth; + ctx.prevHeight=newSize.newHeight; + } else { + ctx.prevWidth=0; + ctx.prevHeight=0; + } + redrawGraph(ctx,data,config); + } +}; + +function redrawGraph(ctx,data,config) { + var myGraph = new Chart(ctx); + switch (ctx.tpchart) { + case "Bar": + myGraph.Bar(data,config); + break; + case "Pie": + myGraph.Pie(data,config); + break; + case "Doughnut": + myGraph.Doughnut(data,config); + break; + case "Radar": + myGraph.Radar(data,config); + break; + case "PolarArea": + myGraph.PolarArea(data,config); + break; + case "HorizontalBar": + myGraph.HorizontalBar(data,config); + break; + case "StackedBar": + myGraph.StackedBar(data,config); + break; + case "HorizontalStackedBar": + myGraph.HorizontalStackedBar(data,config); + break; + case "Line": + myGraph.Line(data,config); + break; + } +}; + + +//Default browsercheck, added to all scripts! +function checkBrowser() { + this.ver = navigator.appVersion + this.dom = document.getElementById ? 1 : 0 + this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom) ? 1 : 0; + this.ie4 = (document.all && !this.dom) ? 1 : 0; + this.ns5 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0; + this.ns4 = (document.layers && !this.dom) ? 1 : 0; + this.bw = (this.ie5 || this.ie4 || this.ns4 || this.ns5) + return this +}; +bw = new checkBrowser(); +//Set these variables: +fromLeft = 10; // How much from the left of the cursor should the div be? +fromTop = 10; // How much from the top of the cursor should the div be? +/******************************************************************** +Initilizes the objects +*********************************************************************/ +function cursorInit() { + scrolled = bw.ns4 || bw.ns5 ? "window.pageYOffset" : "document.body.scrollTop" + if (bw.ns4) document.captureEvents(Event.MOUSEMOVE) +}; +/******************************************************************** +Contructs the cursorobjects +*********************************************************************/ +function makeCursorObj(obj, nest) { + createCursorDiv(); + nest = (!nest) ? '' : 'document.' + nest + '.' + this.css = bw.dom ? document.getElementById(obj).style : bw.ie4 ? document.all[obj].style : bw.ns4 ? eval(nest + "document.layers." + obj) : 0; + this.moveIt = b_moveIt; + cursorInit(); + return this +}; + +function b_moveIt(x, y) { + this.x = x; + this.y = y; + this.css.left = this.x + "px"; + this.css.top = this.y + "px"; +}; + +function isIE() { + var myNav = navigator.userAgent.toLowerCase(); + return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false; +}; + +function mergeChartConfig(defaults, userDefined) { + var returnObj = {}; + for (var attrname in defaults) { + returnObj[attrname] = defaults[attrname]; + } + for (var attrnameBis in userDefined) { + returnObj[attrnameBis] = userDefined[attrnameBis]; + } + return returnObj; +}; + +function sleep(ms) { + var dt = new Date(); + dt.setTime(dt.getTime() + ms); + while (new Date().getTime() < dt.getTime()) {}; +}; + +function saveCanvas(ctx, data, config) { + cvSave = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height); + var saveCanvasConfig = { + savePng: false, + annotateDisplay: false, + animation: false, + dynamicDisplay: false + }; + var savePngConfig = mergeChartConfig(config, saveCanvasConfig); + savePngConfig.clearRect = false; + /* And ink them */ + + redrawGraph(ctx,data,savePngConfig); + var image; + if (config.savePngOutput == "NewWindow") { + image = ctx.canvas.toDataURL(); + ctx.putImageData(cvSave, 0, 0); + window.open(image, '_blank'); + } + if (config.savePngOutput == "CurrentWindow") { + image = ctx.canvas.toDataURL(); + ctx.putImageData(cvSave, 0, 0); + window.location.href = image; + } + if (config.savePngOutput == "Save") { + image = ctx.canvas.toDataURL(); + var downloadLink = document.createElement("a"); + downloadLink.href = image; + downloadLink.download = config.savePngName + ".png"; + document.body.appendChild(downloadLink); + downloadLink.click(); + document.body.removeChild(downloadLink); + } +}; +if (typeof String.prototype.trim !== 'function') { + String.prototype.trim = function() { + return this.replace(/^\s+|\s+$/g, ''); + } +}; +var dynamicDisplay = new Array(); +var dynamicDisplayList = new Array(); + +function dynamicFunction(data, config, ctx) { + + if (isIE() < 9 && isIE() != false) return(true); + + + if (config.dynamicDisplay) { + if (ctx.canvas.id == "") { + var cvdate = new Date(); + var cvmillsec = cvdate.getTime(); + ctx.canvas.id = "Canvas_" + cvmillsec; + } + if (typeof(dynamicDisplay[ctx.canvas.id]) == "undefined") { + dynamicDisplayList[dynamicDisplayList["length"]] = ctx.canvas.id; + dynamicDisplay[ctx.canvas.id] = [ctx, false, false, data, config, ctx.canvas]; + dynamicDisplay[ctx.canvas.id][1] = isScrolledIntoView(ctx.canvas); + window.onscroll = scrollFunction; + } else if (dynamicDisplay[ctx.canvas.id][2] == false) { + dynamicDisplay[ctx.canvas.id][1] = isScrolledIntoView(ctx.canvas); + } + if (dynamicDisplay[ctx.canvas.id][1] == false && dynamicDisplay[ctx.canvas.id][2] == false) { + return false; + } + dynamicDisplay[ctx.canvas.id][2] = true; + } + return true; +}; + +function isScrolledIntoView(element) { + var xPosition = 0; + var yPosition = 0; + elem = element; + while (elem) { + xPosition += (elem.offsetLeft - elem.scrollLeft + elem.clientLeft); + yPosition += (elem.offsetTop - elem.scrollTop + elem.clientTop); + elem = elem.offsetParent; + } + if (xPosition + element.width / 2 >= window.pageXOffset && + xPosition + element.width / 2 <= window.pageXOffset + window.innerWidth && + yPosition + element.height / 2 >= window.pageYOffset && + yPosition + element.height / 2 <= window.pageYOffset + window.innerHeight + ) return (true); + else return false; +}; + +function scrollFunction() { + for (var i = 0; i < dynamicDisplayList["length"]; i++) { + if (isScrolledIntoView(dynamicDisplay[dynamicDisplayList[i]][5]) && dynamicDisplay[dynamicDisplayList[i]][2] == false) { + dynamicDisplay[dynamicDisplayList[i]][1] = true; + redrawGraph(dynamicDisplay[dynamicDisplayList[i]][0],dynamicDisplay[dynamicDisplayList[i]][3], dynamicDisplay[dynamicDisplayList[i]][4]); + } + } +}; + +var jsGraphAnnotate = new Array(); + +function clearAnnotate(ctxid) { + jsGraphAnnotate[ctxid] = []; +}; + +function getMousePos(canvas, evt) { + var rect = canvas.getBoundingClientRect(); + return { + x: evt.clientX - rect.left, + y: evt.clientY - rect.top + }; +}; + +function doMouseAction(config, ctx, event, data, action, funct) { + + var onData = false; + var textMsr; + + if (action == "annotate") { + var annotateDIV = document.getElementById('divCursor'); + var show = false; + annotateDIV.className = (config.annotateClassName) ? config.annotateClassName : ''; + annotateDIV.style.border = (config.annotateClassName) ? '' : config.annotateBorder; + annotateDIV.style.padding = (config.annotateClassName) ? '' : config.annotatePadding; + annotateDIV.style.borderRadius = (config.annotateClassName) ? '' : config.annotateBorderRadius; + annotateDIV.style.backgroundColor = (config.annotateClassName) ? '' : config.annotateBackgroundColor; + annotateDIV.style.color = (config.annotateClassName) ? '' : config.annotateFontColor; + annotateDIV.style.fontFamily = (config.annotateClassName) ? '' : config.annotateFontFamily; + annotateDIV.style.fontSize = (config.annotateClassName) ? '' : (Math.ceil(ctx.chartTextScale*config.annotateFontSize)).toString() + "pt"; + annotateDIV.style.fontStyle = (config.annotateClassName) ? '' : config.annotateFontStyle; + annotateDIV.style.zIndex = 999; + ctx.save(); + ctx.font= annotateDIV.style.fontStyle+" "+ annotateDIV.style.fontSize+" "+annotateDIV.style.fontFamily; + var rect = ctx.canvas.getBoundingClientRect(); + } + if (action=="annotate") { + show=false; + annotateDIV.style.display = show ? '' : 'none'; + } + canvas_pos = getMousePos(ctx.canvas, event); + for (var i = 0; i < jsGraphAnnotate[ctx.ChartNewId]["length"]; i++) { + if (jsGraphAnnotate[ctx.ChartNewId][i][0] == "ARC") { + myStatData=jsGraphAnnotate[ctx.ChartNewId][i][3][jsGraphAnnotate[ctx.ChartNewId][i][1]]; + distance = Math.sqrt((canvas_pos.x - myStatData.midPosX) * (canvas_pos.x - myStatData.midPosX) + (canvas_pos.y - myStatData.midPosY) * (canvas_pos.y - myStatData.midPosY)); + if (distance > myStatData.int_radius && distance < myStatData.radiusOffset) { + angle = (Math.acos((canvas_pos.x - myStatData.midPosX) / distance) % (2* Math.PI) + 2*Math.PI) % (2*Math.PI); + if (canvas_pos.y < myStatData.midPosY) angle = -angle; + angle = (((angle + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + myStatData.startAngle=(((myStatData.startAngle + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI); + myStatData.endAngle=(((myStatData.endAngle + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI); + if(myStatData.endAngle<myStatData.startAngle)myStatData.endAngle+=2 * Math.PI; + if ((angle > myStatData.startAngle && angle < myStatData.endAngle) || (angle > myStatData.startAngle - 2 * Math.PI && angle < myStatData.endAngle - 2 * Math.PI) || (angle > myStatData.startAngle + 2 * Math.PI && angle < myStatData.endAngle + 2 * Math.PI)) { + myStatData.graphPosX = canvas_pos.x; + myStatData.graphPosY = canvas_pos.y; + onData = true; + if (action == "annotate") { + dispString = tmplbis(setOptionValue(1,"ANNOTATELABEL",ctx,data,jsGraphAnnotate[ctx.ChartNewId][i][3],undefined,config.annotateLabel,jsGraphAnnotate[ctx.ChartNewId][i][1],-1,{otherVal:true}), myStatData,config); + textMsr=ctx.measureTextMultiLine(dispString); + ctx.restore(); + annotateDIV.innerHTML = dispString; + show = true; + } else { + funct(event, ctx, config, data, myStatData ); + } + if (action == "annotate") { + x = bw.ns4 || bw.ns5 ? event.pageX : event.x; + y = bw.ns4 || bw.ns5 ? event.pageY : event.y; + if (bw.ie4 || bw.ie5) y = y + eval(scrolled); + if(config.annotateRelocate && x+fromLeft+textMsr.textWidth > window.innerWidth-rect.left-10) oCursor.moveIt(x + fromLeft-textMsr.textWidth, y + fromTop); + else oCursor.moveIt(x + fromLeft, y + fromTop); + } + } + } + } else if (jsGraphAnnotate[ctx.ChartNewId][i][0] == "RECT") { + myStatData=jsGraphAnnotate[ctx.ChartNewId][i][3][jsGraphAnnotate[ctx.ChartNewId][i][1]][jsGraphAnnotate[ctx.ChartNewId][i][2]]; + + if (canvas_pos.x > Math.min(myStatData.xPosLeft,myStatData.xPosRight) && canvas_pos.x < Math.max(myStatData.xPosLeft,myStatData.xPosRight) && canvas_pos.y < Math.max(myStatData.yPosBottom,myStatData.yPosTop) && canvas_pos.y > Math.min(myStatData.yPosBottom,myStatData.yPosTop)) { + myStatData.graphPosX = canvas_pos.x; + myStatData.graphPosY = canvas_pos.y; + onData = true; + if (action == "annotate") { + dispString = tmplbis(setOptionValue(1,"ANNOTATELABEL",ctx,data,jsGraphAnnotate[ctx.ChartNewId][i][3],undefined,config.annotateLabel,jsGraphAnnotate[ctx.ChartNewId][i][1],jsGraphAnnotate[ctx.ChartNewId][i][2],{otherVal:true}), myStatData,config); + textMsr=ctx.measureTextMultiLine(dispString); + ctx.restore(); + annotateDIV.innerHTML = dispString; + show = true; + } else { + funct(event, ctx, config, data, myStatData ); + } + if (action == "annotate") { + x = bw.ns4 || bw.ns5 ? event.pageX : event.x; + y = bw.ns4 || bw.ns5 ? event.pageY : event.y; + if (bw.ie4 || bw.ie5) y = y + eval(scrolled); + if(config.annotateRelocate && x+fromLeft+textMsr.textWidth > window.innerWidth-rect.left-10) oCursor.moveIt(x + fromLeft-textMsr.textWidth, y + fromTop); + else oCursor.moveIt(x + fromLeft, y + fromTop); + } + } + } else if (jsGraphAnnotate[ctx.ChartNewId][i][0] == "POINT") { + myStatData=jsGraphAnnotate[ctx.ChartNewId][i][3][jsGraphAnnotate[ctx.ChartNewId][i][1]][jsGraphAnnotate[ctx.ChartNewId][i][2]]; + var distance; + if(config.detectAnnotateOnFullLine) { + if(canvas_pos.x < Math.min(myStatData.annotateStartPosX,myStatData.annotateEndPosX)-Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius) || canvas_pos.x > Math.max(myStatData.annotateStartPosX,myStatData.annotateEndPosX)+Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius) || canvas_pos.y < Math.min(myStatData.annotateStartPosY,myStatData.annotateEndPosY)-Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius) || canvas_pos.y > Math.max(myStatData.annotateStartPosY,myStatData.annotateEndPosY)+Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius)) { + distance=Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius)+1; + } else { + if(typeof myStatData.D1A=="undefined") { + distance=Math.abs(canvas_pos.x-myStatData.posX); + } else if(typeof myStatData.D2A=="undefined") { + distance=Math.abs(canvas_pos.y-myStatData.posY); + } else { + var D2B=-myStatData.D2A*canvas_pos.x+canvas_pos.y; + var g=-(myStatData.D1B-D2B)/(myStatData.D1A-myStatData.D2A); + var h=myStatData.D2A*g+D2B; + distance=Math.sqrt((canvas_pos.x - g) * (canvas_pos.x - g) + (canvas_pos.y - h) * (canvas_pos.y - h)); + } + + } + + } else { + distance = Math.sqrt((canvas_pos.x - myStatData.posX) * (canvas_pos.x - myStatData.posX) + (canvas_pos.y - myStatData.posY) * (canvas_pos.y - myStatData.posY)); + } + if (distance < Math.ceil(ctx.chartSpaceScale*config.pointHitDetectionRadius)) { + myStatData.graphPosX = canvas_pos.x; + myStatData.graphPosY = canvas_pos.y; + onData = true; + if (action == "annotate") { + dispString = tmplbis(setOptionValue(1,"ANNOTATELABEL",ctx,data,jsGraphAnnotate[ctx.ChartNewId][i][3],undefined,config.annotateLabel,jsGraphAnnotate[ctx.ChartNewId][i][1],jsGraphAnnotate[ctx.ChartNewId][i][2],{otherVal:true}), myStatData,config); + textMsr=ctx.measureTextMultiLine(dispString); + ctx.restore(); + annotateDIV.innerHTML = dispString; + show = true; + } else { + funct(event, ctx, config, data, myStatData); + } + if (action == "annotate") { + x = bw.ns4 || bw.ns5 ? event.pageX : event.x; + y = bw.ns4 || bw.ns5 ? event.pageY : event.y; + if (bw.ie4 || bw.ie5) y = y + eval(scrolled); + if(config.annotateRelocate && x+fromLeft+textMsr.textWidth > window.innerWidth-rect.left-10) oCursor.moveIt(x + fromLeft-textMsr.textWidth, y + fromTop); + else oCursor.moveIt(x + fromLeft, y + fromTop); + } + } + } + if (action == "annotate") { + annotateDIV.style.display = show ? '' : 'none'; + } + } + if (onData == false && action != "annotate") { + funct(event, ctx, config, data, null); + } +}; +///////// GRAPHICAL PART OF THE SCRIPT /////////////////////////////////////////// +//Define the global Chart Variable as a class. +window.Chart = function(context) { + var chart = this; + //Easing functions adapted from Robert Penner's easing equations + //http://www.robertpenner.com/easing/ + var animationOptions = { + linear: function(t) { + return t; + }, + easeInQuad: function(t) { + return t * t; + }, + easeOutQuad: function(t) { + return -1 * t * (t - 2); + }, + easeInOutQuad: function(t) { + if ((t /= 1 / 2) < 1) return 1 / 2 * t * t; + return -1 / 2 * ((--t) * (t - 2) - 1); + }, + easeInCubic: function(t) { + return t * t * t; + }, + easeOutCubic: function(t) { + return 1 * ((t = t / 1 - 1) * t * t + 1); + }, + easeInOutCubic: function(t) { + if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t; + return 1 / 2 * ((t -= 2) * t * t + 2); + }, + easeInQuart: function(t) { + return t * t * t * t; + }, + easeOutQuart: function(t) { + return -1 * ((t = t / 1 - 1) * t * t * t - 1); + }, + easeInOutQuart: function(t) { + if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t; + return -1 / 2 * ((t -= 2) * t * t * t - 2); + }, + easeInQuint: function(t) { + return 1 * (t /= 1) * t * t * t * t; + }, + easeOutQuint: function(t) { + return 1 * ((t = t / 1 - 1) * t * t * t * t + 1); + }, + easeInOutQuint: function(t) { + if ((t /= 1 / 2) < 1) return 1 / 2 * t * t * t * t * t; + return 1 / 2 * ((t -= 2) * t * t * t * t + 2); + }, + easeInSine: function(t) { + return -1 * Math.cos(t / 1 * (Math.PI / 2)) + 1; + }, + easeOutSine: function(t) { + return 1 * Math.sin(t / 1 * (Math.PI / 2)); + }, + easeInOutSine: function(t) { + return -1 / 2 * (Math.cos(Math.PI * t / 1) - 1); + }, + easeInExpo: function(t) { + return (t == 0) ? 1 : 1 * Math.pow(2, 10 * (t / 1 - 1)); + }, + easeOutExpo: function(t) { + return (t == 1) ? 1 : 1 * (-Math.pow(2, -10 * t / 1) + 1); + }, + easeInOutExpo: function(t) { + if (t == 0) return 0; + if (t == 1) return 1; + if ((t /= 1 / 2) < 1) return 1 / 2 * Math.pow(2, 10 * (t - 1)); + return 1 / 2 * (-Math.pow(2, -10 * --t) + 2); + }, + easeInCirc: function(t) { + if (t >= 1) return t; + return -1 * (Math.sqrt(1 - (t /= 1) * t) - 1); + }, + easeOutCirc: function(t) { + return 1 * Math.sqrt(1 - (t = t / 1 - 1) * t); + }, + easeInOutCirc: function(t) { + if ((t /= 1 / 2) < 1) return -1 / 2 * (Math.sqrt(1 - t * t) - 1); + return 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1); + }, + easeInElastic: function(t) { + var s = 1.70158; + var p = 0; + var a = 1; + if (t == 0) return 0; + if ((t /= 1) == 1) return 1; + if (!p) p = 1 * .3; + if (a < Math.abs(1)) { + a = 1; + s = p / 4; + } else s = p / (2 * Math.PI) * Math.asin(1 / a); + return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p)); + }, + easeOutElastic: function(t) { + var s = 1.70158; + var p = 0; + var a = 1; + if (t == 0) return 0; + if ((t /= 1) == 1) return 1; + if (!p) p = 1 * .3; + if (a < Math.abs(1)) { + a = 1; + s = p / 4; + } else s = p / (2 * Math.PI) * Math.asin(1 / a); + return a * Math.pow(2, -10 * t) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) + 1; + }, + easeInOutElastic: function(t) { + var s = 1.70158; + var p = 0; + var a = 1; + if (t == 0) return 0; + if ((t /= 1 / 2) == 2) return 1; + if (!p) p = 1 * (.3 * 1.5); + if (a < Math.abs(1)) { + a = 1; + s = p / 4; + } else s = p / (2 * Math.PI) * Math.asin(1 / a); + if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p)); + return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * 1 - s) * (2 * Math.PI) / p) * .5 + 1; + }, + easeInBack: function(t) { + var s = 1.70158; + return 1 * (t /= 1) * t * ((s + 1) * t - s); + }, + easeOutBack: function(t) { + var s = 1.70158; + return 1 * ((t = t / 1 - 1) * t * ((s + 1) * t + s) + 1); + }, + easeInOutBack: function(t) { + var s = 1.70158; + if ((t /= 1 / 2) < 1) return 1 / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)); + return 1 / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2); + }, + easeInBounce: function(t) { + return 1 - animationOptions.easeOutBounce(1 - t); + }, + easeOutBounce: function(t) { + if ((t /= 1) < (1 / 2.75)) { + return 1 * (7.5625 * t * t); + } else if (t < (2 / 2.75)) { + return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + .75); + } else if (t < (2.5 / 2.75)) { + return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375); + } else { + return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375); + } + }, + easeInOutBounce: function(t) { + if (t < 1 / 2) return animationOptions.easeInBounce(t * 2) * .5; + return animationOptions.easeOutBounce(t * 2 - 1) * .5 + 1 * .5; + } + }; + //Variables global to the chart + var width = context.canvas.width; + var height = context.canvas.height; + //High pixel density displays - multiply the size of the canvas height/width by the device pixel ratio, then scale. + if (window.devicePixelRatio) { + context.canvas.style.width = width + "px"; + context.canvas.style.height = height + "px"; + context.canvas.height = height * window.devicePixelRatio; + context.canvas.width = width * window.devicePixelRatio; + context.scale(window.devicePixelRatio, window.devicePixelRatio); + }; + this.PolarArea = function(data, options) { + chart.PolarArea.defaults = { + inGraphDataShow: false, + inGraphDataPaddingRadius: 5, + inGraphDataPaddingAngle: 0, + inGraphDataTmpl: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + inGraphDataAlign: "off-center", // "right", "center", "left", "off-center" or "to-center" + inGraphDataVAlign: "off-center", // "bottom", "center", "top", "off-center" or "to-center" + inGraphDataRotate: 0, // rotateAngle value (0->360) , "inRadiusAxis" or "inRadiusAxisRotateLabels" + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataRadiusPosition: 3, + inGraphDataAnglePosition: 2, + scaleOverlay: true, + scaleOverride: false, + scaleOverride2: false, + scaleGridLinesStep : 1, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleShowLine: true, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineWidth: 1, + scaleLineStyle: "solid", + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowLabelBackdrop: true, + scaleBackdropColor: "rgba(255,255,255,0.75)", + scaleBackdropPaddingY: 2, + scaleBackdropPaddingX: 2, + segmentShowStroke: true, + segmentStrokeColor: "#fff", + segmentStrokeStyle: "solid", + segmentStrokeWidth: 2, + animation: true, + animationByData : "ByArc", + animationSteps: 100, + animationEasing: "easeOutBounce", + animateRotate: true, + animateScale: false, + onAnimationComplete: null, + annotateLabel: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + startAngle: 90 + }; + chart.PolarArea.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.PolarArea.defaults); + chart.PolarArea.defaults = mergeChartConfig(chart.PolarArea.defaults, charJSPersonalDefaultOptions); + chart.PolarArea.defaults = mergeChartConfig(chart.PolarArea.defaults, charJSPersonalDefaultOptionsPolarArea); + var config = (options) ? mergeChartConfig(chart.PolarArea.defaults, options) : chart.PolarArea.defaults; + return new PolarArea(data, config, context); + }; + this.Radar = function(data, options) { + chart.Radar.defaults = { + inGraphDataShow: false, + inGraphDataPaddingRadius: 5, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "off-center", // "right", "center", "left", "off-center" or "to-center" + inGraphDataVAlign: "off-center", // "right", "center", "left", "off-center" or "to-center" + inGraphDataRotate: 0, // rotateAngle value (0->360) , "inRadiusAxis" or "inRadiusAxisRotateLabels" + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataRadiusPosition: 3, + yAxisMinimumInterval: "none", + scaleGridLinesStep : 1, + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleShowLine: true, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: false, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowLabelBackdrop: true, + scaleBackdropColor: "rgba(255,255,255,0.75)", + scaleBackdropPaddingY: 2, + scaleBackdropPaddingX: 2, + angleShowLineOut: true, + angleLineColor: "rgba(0,0,0,.1)", + angleLineStyle: "solid", + angleLineWidth: 1, + pointLabelFontFamily: "'Arial'", + pointLabelFontStyle: "normal", + pointLabelFontSize: 12, + pointLabelFontColor: "#666", + pointDot: true, + pointDotRadius: 3, + pointDotStrokeWidth: 1, + pointDotStrokeStyle:"solid", + datasetFill: true, + datasetStrokeWidth: 2, + datasetStrokeStyle:"solid", + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + onAnimationComplete: null, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3%>", + pointHitDetectionRadius : 10, + startAngle: 90 + }; + // merge annotate defaults + chart.Radar.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.Radar.defaults); + chart.Radar.defaults = mergeChartConfig(chart.Radar.defaults, charJSPersonalDefaultOptions); + chart.Radar.defaults = mergeChartConfig(chart.Radar.defaults, charJSPersonalDefaultOptionsRadar); + var config = (options) ? mergeChartConfig(chart.Radar.defaults, options) : chart.Radar.defaults; + return new Radar(data, config, context); + }; + this.Pie = function(data, options) { + chart.Pie.defaults = { + inGraphDataShow: false, + inGraphDataPaddingRadius: 5, + inGraphDataPaddingAngle: 0, + inGraphDataTmpl: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + inGraphDataAlign: "off-center", // "right", "center", "left", "off-center" or "to-center" + inGraphDataVAlign: "off-center", // "bottom", "center", "top", "off-center" or "to-center" + inGraphDataRotate: 0, // rotateAngle value (0->360) , "inRadiusAxis" or "inRadiusAxisRotateLabels" + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataRadiusPosition: 3, + inGraphDataAnglePosition: 2, + inGraphDataMinimumAngle : 0, + segmentShowStroke: true, + segmentStrokeColor: "#fff", + segmentStrokeStyle: "solid", + segmentStrokeWidth: 2, + animation: true, + animationByData : false, + animationSteps: 100, + animationEasing: "easeOutBounce", + animateRotate: true, + animateScale: false, + onAnimationComplete: null, + annotateLabel: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + startAngle: 90, + radiusScale: 1 + }; + // merge annotate defaults + chart.Pie.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.Pie.defaults); + chart.Pie.defaults = mergeChartConfig(chart.Pie.defaults, charJSPersonalDefaultOptions); + chart.Pie.defaults = mergeChartConfig(chart.Pie.defaults, charJSPersonalDefaultOptionsPie); + var config = (options) ? mergeChartConfig(chart.Pie.defaults, options) : chart.Pie.defaults; + return new Pie(data, config, context); + }; + this.Doughnut = function(data, options) { + chart.Doughnut.defaults = { + inGraphDataShow: false, + inGraphDataPaddingRadius: 5, + inGraphDataPaddingAngle: 0, + inGraphDataTmpl: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + inGraphDataAlign: "off-center", // "right", "center", "left", "off-center" or "to-center" + inGraphDataVAlign: "off-center", // "bottom", "middle", "top", "off-center" or "to-center" + inGraphDataRotate: 0, // rotateAngle value (0->360) , "inRadiusAxis" or "inRadiusAxisRotateLabels" + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataRadiusPosition: 3, + inGraphDataAnglePosition: 2, + inGraphDataMinimumAngle : 0, + segmentShowStroke: true, + segmentStrokeColor: "#fff", + segmentStrokeStyle: "solid", + segmentStrokeWidth: 2, + percentageInnerCutout: 50, + animation: true, + animationByData : false, + animationSteps: 100, + animationEasing: "easeOutBounce", + animateRotate: true, + animateScale: false, + onAnimationComplete: null, + annotateLabel: "<%=(v1 == ''? '' : v1+':')+ v2 + ' (' + v6 + ' %)'%>", + startAngle: 90, + radiusScale: 1 + }; + // merge annotate defaults + chart.Doughnut.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.Doughnut.defaults); + chart.Doughnut.defaults = mergeChartConfig(chart.Doughnut.defaults, charJSPersonalDefaultOptions); + chart.Doughnut.defaults = mergeChartConfig(chart.Doughnut.defaults, charJSPersonalDefaultOptionsDoughnut); + var config = (options) ? mergeChartConfig(chart.Doughnut.defaults, options) : chart.Doughnut.defaults; + return new Doughnut(data, config, context); + }; + this.Line = function(data, options) { + chart.Line.defaults = { + inGraphDataShow: false, + inGraphDataPaddingX: 3, + inGraphDataPaddingY: 3, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "left", + inGraphDataVAlign: "bottom", + inGraphDataRotate: 0, + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + drawXScaleLine: [{ + position: "bottom" + }], + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleSteps2: null, + scaleStepWidth2: null, + scaleStartValue2: null, + scaleLabel2 : "<%=value%>", + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowGridLines: true, + scaleXGridLinesStep: 1, + scaleYGridLinesStep: 1, + scaleGridLineColor: "rgba(0,0,0,.05)", + scaleGridLineStyle: "solid", + scaleGridLineWidth: 1, + showYAxisMin: true, // Show the minimum value on Y axis (in original version, this minimum is not displayed - it can overlap the X labels) + rotateLabels: "smart", // smart <=> 0 degre if space enough; otherwise 45 degres if space enough otherwise90 degre; + // you can force an integer value between 0 and 180 degres + logarithmic: false, // can be 'fuzzy',true and false ('fuzzy' => if the gap between min and maximum is big it's using a logarithmic y-Axis scale + logarithmic2: false, // can be 'fuzzy',true and false ('fuzzy' => if the gap between min and maximum is big it's using a logarithmic y-Axis scale + scaleTickSizeLeft: 5, + scaleTickSizeRight: 5, + scaleTickSizeBottom: 5, + scaleTickSizeTop: 5, + bezierCurve: true, + bezierCurveTension : 0.4, + pointDot: true, + pointDotRadius: 4, + pointDotStrokeStyle: "solid", + pointDotStrokeWidth: 2, + datasetStrokeStyle: "solid", + datasetStrokeWidth: 2, + datasetFill: true, + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + extrapolateMissingData: true, + onAnimationComplete: null, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3%>", + pointHitDetectionRadius : 10 + }; + // merge annotate defaults + chart.Line.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.Line.defaults); + chart.Line.defaults = mergeChartConfig(chart.defaults.xyAxisCommonOptions, chart.Line.defaults); + chart.Line.defaults = mergeChartConfig(chart.Line.defaults, charJSPersonalDefaultOptions); + chart.Line.defaults = mergeChartConfig(chart.Line.defaults, charJSPersonalDefaultOptionsLine); + var config = (options) ? mergeChartConfig(chart.Line.defaults, options) : chart.Line.defaults; + return new Line(data, config, context); + }; + this.StackedBar = function(data, options) { + chart.StackedBar.defaults = { + inGraphDataShow: false, + inGraphDataPaddingX: 0, + inGraphDataPaddingY: -3, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "center", + inGraphDataVAlign: "top", + inGraphDataRotate: 0, + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataXPosition: 2, + inGraphDataYPosition: 3, + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowGridLines: true, + scaleXGridLinesStep: 1, + scaleYGridLinesStep: 1, + scaleGridLineColor: "rgba(0,0,0,.05)", + scaleGridLineStyle: "solid", + scaleGridLineWidth: 1, + showYAxisMin: true, // Show the minimum value on Y axis (in original version, this minimum is not displayed - it can overlap the X labels) + rotateLabels: "smart", // smart <=> 0 degre if space enough; otherwise 45 degres if space enough otherwise90 degre; + // you can force an integer value between 0 and 180 degres + scaleTickSizeLeft: 5, + scaleTickSizeRight: 5, + scaleTickSizeBottom: 5, + scaleTickSizeTop: 5, + pointDot: true, + pointDotRadius: 4, + pointDotStrokeStyle: "solid", + pointDotStrokeWidth: 2, + barShowStroke: true, +// barStrokeStyle: "solid", + barStrokeWidth: 2, + barValueSpacing: 5, + barDatasetSpacing: 1, + spaceBetweenBar : 0, + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + onAnimationComplete: null, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3 + ' (' + v6 + ' %)'%>", + pointHitDetectionRadius : 10 + }; + // merge annotate defaults + chart.StackedBar.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.StackedBar.defaults); + chart.StackedBar.defaults = mergeChartConfig(chart.defaults.xyAxisCommonOptions, chart.StackedBar.defaults); + chart.StackedBar.defaults = mergeChartConfig(chart.StackedBar.defaults, charJSPersonalDefaultOptions); + chart.StackedBar.defaults = mergeChartConfig(chart.StackedBar.defaults, charJSPersonalDefaultOptionsStackedBar); + var config = (options) ? mergeChartConfig(chart.StackedBar.defaults, options) : chart.StackedBar.defaults; + return new StackedBar(data, config, context); + }; + this.HorizontalStackedBar = function(data, options) { + chart.HorizontalStackedBar.defaults = { + inGraphDataShow: false, + inGraphDataPaddingX: -3, + inGraphDataPaddingY: 0, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "right", + inGraphDataVAlign: "middle", + inGraphDataRotate: 0, + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataXPosition: 3, + inGraphDataYPosition: 2, + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowGridLines: true, + scaleXGridLinesStep: 1, + scaleYGridLinesStep: 1, + scaleGridLineColor: "rgba(0,0,0,.05)", + scaleGridLineStyle: "solid", + scaleGridLineWidth: 1, + scaleTickSizeLeft: 5, + scaleTickSizeRight: 5, + scaleTickSizeBottom: 5, + scaleTickSizeTop: 5, + showYAxisMin: true, // Show the minimum value on Y axis (in original version, this minimum is not displayed - it can overlap the X labels) + rotateLabels: "smart", // smart <=> 0 degre if space enough; otherwise 45 degres if space enough otherwise90 degre; + barShowStroke: true, +// barStrokeStyle: "solid", + barStrokeWidth: 2, + barValueSpacing: 5, + barDatasetSpacing: 1, + spaceBetweenBar : 0, + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + onAnimationComplete: null, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3 + ' (' + v6 + ' %)'%>", + reverseOrder: false + }; + // merge annotate defaults + chart.HorizontalStackedBar.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.HorizontalStackedBar.defaults); + chart.HorizontalStackedBar.defaults = mergeChartConfig(chart.defaults.xyAxisCommonOptions, chart.HorizontalStackedBar.defaults); + chart.HorizontalStackedBar.defaults = mergeChartConfig(chart.HorizontalStackedBar.defaults, charJSPersonalDefaultOptions); + chart.HorizontalStackedBar.defaults = mergeChartConfig(chart.HorizontalStackedBar.defaults, charJSPersonalDefaultOptionsHorizontalStackedBar); + var config = (options) ? mergeChartConfig(chart.HorizontalStackedBar.defaults, options) : chart.HorizontalStackedBar.defaults; + return new HorizontalStackedBar(data, config, context); + }; + this.Bar = function(data, options) { + chart.Bar.defaults = { + inGraphDataShow: false, + inGraphDataPaddingX: 0, + inGraphDataPaddingY: 3, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "center", + inGraphDataVAlign: "bottom", + inGraphDataRotate: 0, + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataXPosition: 2, + inGraphDataYPosition: 3, + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleSteps2: null, + scaleStepWidth2: null, + scaleStartValue2: null, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleLabel2: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowGridLines: true, + scaleXGridLinesStep: 1, + scaleYGridLinesStep: 1, + scaleGridLineColor: "rgba(0,0,0,.05)", + scaleGridLineWidth: 1, + scaleGridLineStyle: "solid", + showYAxisMin: true, // Show the minimum value on Y axis (in original version, this minimum is not displayed - it can overlap the X labels) + rotateLabels: "smart", // smart <=> 0 degre if space enough; otherwise 45 degres if space enough otherwise90 degre; + // you can force an integer value between 0 and 180 degres + logarithmic: false, // can be 'fuzzy',true and false ('fuzzy' => if the gap between min and maximum is big it's using a logarithmic y-Axis scale + logarithmic2: false, // can be 'fuzzy',true and false ('fuzzy' => if the gap between min and maximum is big it's using a logarithmic y-Axis scale + scaleTickSizeLeft: 5, + scaleTickSizeRight: 5, + scaleTickSizeBottom: 5, + scaleTickSizeTop: 5, + barShowStroke: true, +// barStrokeStyle: "solid", + barStrokeWidth: 2, + barValueSpacing: 5, + barDatasetSpacing: 1, + barBorderRadius: 0, + pointDot: true, + pointDotRadius: 4, + pointDotStrokeStyle: "solid", + pointDotStrokeWidth: 2, + extrapolateMissingData: true, + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + onAnimationComplete: null, + bezierCurve: true, + bezierCurveTension : 0.4, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3 + ' (' + v6 + ' %)'%>", + pointHitDetectionRadius : 10 + }; + // merge annotate defaults + chart.Bar.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.Bar.defaults); + chart.Bar.defaults = mergeChartConfig(chart.defaults.xyAxisCommonOptions, chart.Bar.defaults); + chart.Bar.defaults = mergeChartConfig(chart.Bar.defaults, charJSPersonalDefaultOptions); + chart.Bar.defaults = mergeChartConfig(chart.Bar.defaults, charJSPersonalDefaultOptionsBar); + var config = (options) ? mergeChartConfig(chart.Bar.defaults, options) : chart.Bar.defaults; + return new Bar(data, config, context); + }; + this.HorizontalBar = function(data, options) { + chart.HorizontalBar.defaults = { + inGraphDataShow: false, + inGraphDataPaddingX: 3, + inGraphDataPaddingY: 0, + inGraphDataTmpl: "<%=v3%>", + inGraphDataAlign: "left", + inGraphDataVAlign: "middle", + inGraphDataRotate: 0, + inGraphDataFontFamily: "'Arial'", + inGraphDataFontSize: 12, + inGraphDataFontStyle: "normal", + inGraphDataFontColor: "#666", + inGraphDataXPosition: 3, + inGraphDataYPosition: 2, + scaleOverlay: false, + scaleOverride: false, + scaleOverride2: false, + scaleSteps: null, + scaleStepWidth: null, + scaleStartValue: null, + scaleLineColor: "rgba(0,0,0,.1)", + scaleLineStyle: "solid", + scaleLineWidth: 1, + scaleShowLabels: true, + scaleShowLabels2: true, + scaleLabel: "<%=value%>", + scaleFontFamily: "'Arial'", + scaleFontSize: 12, + scaleFontStyle: "normal", + scaleFontColor: "#666", + scaleShowGridLines: true, + scaleXGridLinesStep: 1, + scaleYGridLinesStep: 1, + scaleGridLineColor: "rgba(0,0,0,.05)", + scaleGridLineStyle: "solid", + scaleGridLineWidth: 1, + scaleTickSizeLeft: 5, + scaleTickSizeRight: 5, + scaleTickSizeBottom: 5, + scaleTickSizeTop: 5, + showYAxisMin: true, // Show the minimum value on Y axis (in original version, this minimum is not displayed - it can overlap the X labels) + rotateLabels: "smart", // smart <=> 0 degre if space enough; otherwise 45 degres if space enough otherwise90 degre; + barShowStroke: true, +// barStrokeStyle: "solid", + barStrokeWidth: 2, + barValueSpacing: 5, + barDatasetSpacing: 1, + barBorderRadius: 0, + animation: true, + animationSteps: 60, + animationEasing: "easeOutQuart", + onAnimationComplete: null, + annotateLabel: "<%=(v1 == '' ? '' : v1) + (v1!='' && v2 !='' ? ' - ' : '')+(v2 == '' ? '' : v2)+(v1!='' || v2 !='' ? ':' : '') + v3 + ' (' + v6 + ' %)'%>", + reverseOrder: false + }; + // merge annotate defaults + chart.HorizontalBar.defaults = mergeChartConfig(chart.defaults.commonOptions, chart.HorizontalBar.defaults); + chart.HorizontalBar.defaults = mergeChartConfig(chart.defaults.xyAxisCommonOptions, chart.HorizontalBar.defaults); + chart.HorizontalBar.defaults = mergeChartConfig(chart.HorizontalBar.defaults, charJSPersonalDefaultOptions); + chart.HorizontalBar.defaults = mergeChartConfig(chart.HorizontalBar.defaults, charJSPersonalDefaultOptionsHorizontalBar); + var config = (options) ? mergeChartConfig(chart.HorizontalBar.defaults, options) : chart.HorizontalBar.defaults; + return new HorizontalBar(data, config, context); + }; + chart.defaults = {}; + chart.defaults.commonOptions = { + chartTextScale : 1, + chartLineScale : 1, + chartSpaceScale : 1, + multiGraph: false, + clearRect: true, // do not change clearRect options; for internal use only + dynamicDisplay: false, + graphSpaceBefore: 5, + graphSpaceAfter: 5, + canvasBorders: false, + canvasBackgroundColor: "none", + canvasBordersWidth: 3, + canvasBordersStyle: "solid", + canvasBordersColor: "black", + zeroValue : 0.0000000001, + graphTitle: "", + graphTitleFontFamily: "'Arial'", + graphTitleFontSize: 24, + graphTitleFontStyle: "bold", + graphTitleFontColor: "#666", + graphTitleSpaceBefore: 5, + graphTitleSpaceAfter: 5, + graphTitleBorders : false, + graphTitleBordersColor : "black", + graphTitleBordersXSpace : 3, + graphTitleBordersYSpace : 3, + graphTitleBordersWidth : 1, + graphTitleBordersStyle : "solid", + graphTitleBackgroundColor : "none", + graphSubTitle: "", + graphSubTitleFontFamily: "'Arial'", + graphSubTitleFontSize: 18, + graphSubTitleFontStyle: "normal", + graphSubTitleFontColor: "#666", + graphSubTitleSpaceBefore: 5, + graphSubTitleSpaceAfter: 5, + graphSubTitleBorders : false, + graphSubTitleBordersColor : "black", + graphSubTitleBordersXSpace : 3, + graphSubTitleBordersYSpace : 3, + graphSubTitleBordersWidth : 1, + graphSubTitleBordersStyle : "solid", + graphSubTitleBackgroundColor : "none", + footNote: "", + footNoteFontFamily: "'Arial'", + footNoteFontSize: 8, + footNoteFontStyle: "bold", + footNoteFontColor: "#666", + footNoteSpaceBefore: 5, + footNoteSpaceAfter: 5, + footNoteBorders : false, + footNoteBordersColor : "black", + footNoteBordersXSpace : 3, + footNoteBordersYSpace : 3, + footNoteBordersWidth : 1, + footNoteBordersStyle : "solid", + footNoteBackgroundColor : "none", + legend : false, + showSingleLegend: false, + maxLegendCols : 999, + legendPosY :4, + legendPosX : -2, + legendFontFamily: "'Arial'", + legendFontSize: 12, + legendFontStyle: "normal", + legendFontColor: "#666", + legendBlockSize: 15, + legendBorders: true, + legendBordersStyle: "solid", + legendBordersWidth: 1, + legendBordersColors: "#666", + legendBordersSpaceBefore: 5, + legendBordersSpaceAfter: 5, + legendBordersSpaceLeft: 5, + legendBordersSpaceRight: 5, + legendSpaceBeforeText: 5, + legendSpaceAfterText: 5, + legendSpaceLeftText: 5, + legendSpaceRightText: 5, + legendSpaceBetweenTextVertical: 5, + legendSpaceBetweenTextHorizontal: 5, + legendSpaceBetweenBoxAndText: 5, + legendFillColor : "rgba(0,0,0,0)", + legendXPadding : 0, + legendYPadding : 0, + inGraphDataBorders : false, + inGraphDataBordersColor : "black", + inGraphDataBordersXSpace : 3, + inGraphDataBordersYSpace : 3, + inGraphDataBordersWidth : 1, + inGraphDataBordersStyle : "solid", + inGraphDataBackgroundColor : "none", + annotateDisplay: false, + annotateRelocate: false, + savePng: false, + savePngOutput: "NewWindow", // Allowed values : "NewWindow", "CurrentWindow", "Save" + savePngFunction: "mousedown right", + savePngBackgroundColor: 'WHITE', + annotateFunction: "mousemove", + annotateFontFamily: "'Arial'", + annotateBorder: 'none', + annotateBorderRadius: '2px', + annotateBackgroundColor: 'rgba(0,0,0,0.8)', + annotateFontSize: 12, + annotateFontColor: 'white', + annotateFontStyle: "normal", + annotatePadding: "3px", + annotateClassName: "", + crossText: [""], + crossTextIter: ["all"], + crossTextOverlay: [true], + crossTextFontFamily: ["'Arial'"], + crossTextFontSize: [12], + crossTextFontStyle: ["normal"], + crossTextFontColor: ["rgba(220,220,220,1)"], + crossTextRelativePosX: [2], + crossTextRelativePosY: [2], + crossTextBaseline: ["middle"], + crossTextAlign: ["center"], + crossTextPosX: [0], + crossTextPosY: [0], + crossTextAngle: [0], + crossTextFunction: null, + crossTextBorders : [false], + crossTextBordersColor : ["black"], + crossTextBordersXSpace : [3], + crossTextBordersYSpace : [3], + crossTextBordersWidth : [1], + crossTextBordersStyle : ["solid"], + crossTextBackgroundColor : ["none"], + crossImage: [undefined], + crossImageIter: ["all"], + crossImageOverlay: [true], + crossImageRelativePosX: [2], + crossImageRelativePosY: [2], + crossImageBaseline: ["middle"], + crossImageAlign: ["center"], + crossImagePosX: [0], + crossImagePosY: [0], + crossImageAngle: [0], + spaceTop: 0, + spaceBottom: 0, + spaceRight: 0, + spaceLeft: 0, + decimalSeparator: ".", + thousandSeparator: "", + roundNumber: "none", + roundPct: -1, + templatesOpenTag : "<%=", + templatesCloseTag : "%>", + fmtV1: "none", + fmtV2: "none", + fmtV3: "none", + fmtV4: "none", + fmtV5: "none", + fmtV6: "none", + fmtV6T: "none", + fmtV7: "none", + fmtV8: "none", + fmtV8T: "none", + fmtV9: "none", + fmtV10: "none", + fmtV11: "none", + fmtV12: "none", + fmtV13: "none", + fmtXLabel: "none", + fmtYLabel: "none", + fmtYLabel2: "none", + fmtLegend: "none", + animationStartValue: 0, + animationStopValue: 1, + animationCount: 1, + animationPauseTime: 5, + animationBackward: false, + animationStartWithDataset: 1, + animationStartWithData: 1, + animationLeftToRight: false, + animationByDataset: false, + defaultStrokeColor: "rgba(220,220,220,1)", + defaultFillColor: "rgba(220,220,220,0.5)", + defaultLineWidth : 2, + graphMaximized: false, + mouseDownRight: null, + mouseDownLeft: null, + mouseDownMiddle: null, + mouseMove: null, + mouseOut: null, + mouseWheel : null, + savePngName: "canvas", + responsive : false, + responsiveMinWidth : 0, + responsiveMinHeight : 0, + responsiveMaxWidth : 9999999, + responsiveMaxHeight : 9999999, + maintainAspectRatio: true, + responsiveScaleContent : false, + responsiveWindowInitialWidth : false, + pointMarker : "circle" // "circle","cross","plus","diamond","triangle","square" + }; + chart.defaults.xyAxisCommonOptions = { + yAxisMinimumInterval: "none", + yAxisMinimumInterval2: "none", + yScaleLabelsMinimumWidth: 0, + xScaleLabelsMinimumWidth: 0, + yAxisLeft: true, + yAxisRight: false, + xAxisBottom: true, + xAxisTop: false, + xAxisSpaceBetweenLabels: 5, + fullWidthGraph: false, + yAxisLabel: "", + yAxisLabel2: "", + yAxisFontFamily: "'Arial'", + yAxisFontSize: 16, + yAxisFontStyle: "normal", + yAxisFontColor: "#666", + yAxisLabelSpaceRight: 5, + yAxisLabelSpaceLeft: 5, + yAxisSpaceRight: 5, + yAxisSpaceLeft: 5, + yAxisLabelBorders : false, + yAxisLabelBordersColor : "black", + yAxisLabelBordersXSpace : 3, + yAxisLabelBordersYSpace : 3, + yAxisLabelBordersWidth : 1, + yAxisLabelBordersStyle : "solid", + yAxisLabelBackgroundColor : "none", + xAxisLabel: "", + xAxisFontFamily: "'Arial'", + xAxisFontSize: 16, + xAxisFontStyle: "normal", + xAxisFontColor: "#666", + xAxisLabelSpaceBefore: 5, + xAxisLabelSpaceAfter: 5, + xAxisSpaceBefore: 5, + xAxisSpaceAfter: 5, + xAxisLabelBorders : false, + xAxisLabelBordersColor : "black", + xAxisLabelBordersXSpace : 3, + xAxisLabelBordersYSpace : 3, + xAxisLabelBordersWidth : 1, + xAxisLabelBordersStyle : "solid", + xAxisLabelBackgroundColor : "none", + yAxisUnit: "", + yAxisUnit2: "", + yAxisUnitFontFamily: "'Arial'", + yAxisUnitFontSize: 8, + yAxisUnitFontStyle: "normal", + yAxisUnitFontColor: "#666", + yAxisUnitSpaceBefore: 5, + yAxisUnitSpaceAfter: 5, + yAxisUnitBorders : false, + yAxisUnitBordersColor : "black", + yAxisUnitBordersXSpace : 3, + yAxisUnitBordersYSpace : 3, + yAxisUnitBordersWidth : 1, + yAxisUnitBordersStyle : "solid", + yAxisUnitBackgroundColor : "none" + }; + var clear = function(c) { + c.clearRect(0, 0, width, height); + }; + + function init_and_start(ctx,data,config) { + + if (typeof ctx.initialWidth == "undefined") { + ctx.initialWidth =ctx.canvas.width; + } + if (typeof ctx.chartTextScale == "undefined") { + ctx.chartTextScale=config.chartTextScale; + } + if (typeof ctx.chartLineScale == "undefined") { + ctx.chartLineScale=config.chartLineScale; + } + if (typeof ctx.chartSpaceScale == "undefined") { + ctx.chartSpaceScale=config.chartSpaceScale; + } + if (typeof ctx.ChartNewId == "undefined") { + + ctx.runanimationcompletefunction=true; + var cvdate = new Date(); + var cvmillsec = cvdate.getTime(); + ctx.ChartNewId = ctx.tpchart + '_' + cvmillsec; + ctx._eventListeners = {}; + } + if (!dynamicFunction(data, config, ctx)) { + if(config.responsive && typeof ctx.firstPass == "undefined") { if(!config.multiGraph) { addResponsiveChart(ctx.ChartNewId,ctx,data,config); } } + return false; + } + if(config.responsive && typeof ctx.firstPass == "undefined") { + if(!config.multiGraph) { + addResponsiveChart(ctx.ChartNewId,ctx,data,config); + subUpdateChart(ctx,data,config); + return false; + } else { ctx.firstPass=1; } + } + + if (typeof jsGraphAnnotate[ctx.ChartNewId] == "undefined") jsGraphAnnotate[ctx.ChartNewId] = new Array(); + else if (!config.multiGraph) clearAnnotate(ctx.ChartNewId); + + defMouse(ctx, data, config); + + setRect(ctx, config); + + return true; + } ; + + var PolarArea = function(data, config, ctx) { + var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, msr, midPosX, midPosY; + ctx.tpchart="PolarArea"; + + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + + valueBounds = getValueBounds(); + + config.logarithmic = false; + config.logarithmic2 = false; + + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, false, false, true, "PolarArea"); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + graphMax: scaleStartValue + scaleSteps * scaleStepWidth, + labels: [] + } + populateLabels(1, config, labelTemplateString, calculatedScale.labels, calculatedScale.steps, scaleStartValue, calculatedScale.graphMax, scaleStepWidth); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, false, false, true, "PolarArea"); + } + + midPosX = msr.leftNotUsableSize + (msr.availableWidth / 2); + midPosY = msr.topNotUsableSize + (msr.availableHeight / 2); + scaleHop = Math.floor(((Min([msr.availableHeight, msr.availableWidth]) / 2) - 5) / calculatedScale.steps); + //Wrap in an animation loop wrapper + if(scaleHop > 0) { + initPassVariableData_part2(statData,data,config,ctx,{midPosX : midPosX,midPosY : midPosY,int_radius : 0,ext_radius : scaleHop*calculatedScale.steps, calculatedScale : calculatedScale, scaleHop : scaleHop}); + animationLoop(config, drawScale, drawAllSegments, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, midPosX, midPosY, midPosX - ((Min([msr.availableHeight, msr.availableWidth]) / 2) - 5), midPosY + ((Min([msr.availableHeight, msr.availableWidth]) / 2) - 5), data); + } else { + testRedraw(ctx,data,config); + } + + function drawAllSegments(animationDecimal) { + + for (var i = 0; i < data.length; i++) { + var scaleAnimation = 1, + rotateAnimation = 1; + + if (config.animation) { + if (config.animateScale) { + scaleAnimation = animationDecimal; + } + if (config.animateRotate) { + rotateAnimation = animationDecimal; + } + } + correctedRotateAnimation = animationCorrection(rotateAnimation, data, config, i, -1, 0).mainVal; + if (!(typeof(data[i].value) == 'undefined')) { + ctx.beginPath(); + if(config.animationByData == "ByArc") { + endAngle=statData[i].startAngle+correctedRotateAnimation*statData[i].segmentAngle; + ctx.arc(midPosX, midPosY, scaleAnimation * statData[i].radiusOffset, statData[i].startAngle, endAngle, false); + } else if(config.animationByData) { + if(statData[i].startAngle-statData[i].firstAngle < correctedRotateAnimation*2*Math.PI ) { + endAngle=statData[i].endAngle; + if((statData[i].endAngle-statData[i].firstAngle)> correctedRotateAnimation*2*Math.PI) endAngle=statData[i].firstAngle+correctedRotateAnimation*2*Math.PI; + ctx.arc(midPosX, midPosY, scaleAnimation * statData[i].radiusOffset, statData[i].startAngle, endAngle, false); + + } + else continue; + } else { + ctx.arc(midPosX, midPosY, scaleAnimation * statData[i].radiusOffset, statData[i].firstAngle+correctedRotateAnimation * (statData[i].startAngle-statData[i].firstAngle), statData[i].firstAngle+correctedRotateAnimation * (statData[i].endAngle-statData[i].firstAngle)); + } + ctx.lineTo(midPosX, midPosY); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data[i].color,config.defaultFillColor,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ); + ctx.fill(); + if (config.segmentShowStroke) { + ctx.strokeStyle = config.segmentStrokeColor; + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.segmentStrokeWidth); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"SEGMENTSTROKESTYLE",ctx,data,statData,data[i].segmentStrokeStyle,config.segmentStrokeStyle,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ))); + ctx.stroke(); + ctx.setLineDash([]); + } + } + } + + + if (animationDecimal >= config.animationStopValue) { + for (i = 0; i < data.length; i++) { + if (typeof(data[i].value) == 'undefined') continue; + if (setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,-1,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["ARC", i, -1,statData]; + } + if (setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,-1,{nullValue : true})) { + if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 1) posAngle = statData[i].realStartAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 2) posAngle = (2*statData[i].realStartAngle - statData[i].segmentAngle) / 2 + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 3) posAngle = statData[i].realStartAngle - statData[i].segmentAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 1) labelRadius = 0 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 2) labelRadius = statData[i].radiusOffset / 2 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 3) labelRadius = statData[i].radiusOffset + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 4) labelRadius = scaleHop * calculatedScale.steps + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + ctx.save() + if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "off-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "left"; + else ctx.textAlign = "right"; + } else if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "to-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "right"; + else ctx.textAlign = "left"; + } else ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }); + if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "off-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "top"; + else ctx.textBaseline = "bottom"; + } else if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "to-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "bottom"; + else ctx.textBaseline = "top"; + } else ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,-1,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i],config); + ctx.translate(midPosX + labelRadius * Math.cos(posAngle), midPosY - labelRadius * Math.sin(posAngle)); + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis") ctx.rotate(2 * Math.PI - posAngle); + else if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxisRotateLabels") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI / 2 && (posAngle + 2 * Math.PI) % (2 * Math.PI) < 3 * Math.PI / 2) ctx.rotate(3 * Math.PI - posAngle); + else ctx.rotate(2 * Math.PI - posAngle); + } else ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,-1,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,-1,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ), true); + ctx.restore(); + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"PolarArea"); + }; + + function drawScale() { + for (var i = 0; i < calculatedScale.steps; i++) { + if (config.scaleShowLine && (i+1) % config.scaleGridLinesStep==0) { + ctx.beginPath(); + ctx.arc(midPosX, midPosY, scaleHop * (i + 1), 0, (Math.PI * 2), true); + ctx.strokeStyle = config.scaleLineColor; + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + + ctx.stroke(); + ctx.setLineDash([]); + } + if (config.scaleShowLabels) { + ctx.textAlign = "center"; + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + var label = calculatedScale.labels[i + 1]; + if (config.scaleShowLabelBackdrop) { + var textWidth = ctx.measureTextMultiLine(label, Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + ctx.fillStyle = config.scaleBackdropColor; + ctx.beginPath(); + ctx.rect( + Math.round(midPosX - textWidth / 2 - Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingX)), //X + Math.round(midPosY - (scaleHop * (i + 1)) - (Math.ceil(ctx.chartTextScale*config.scaleFontSize)) * 0.5 - Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingY)), //Y + Math.round(textWidth + (Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingX) * 2)), //Width + Math.round((Math.ceil(ctx.chartTextScale*config.scaleFontSize)) + (Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingY) * 2)) //Height + ); + ctx.fill(); + } + ctx.textBaseline = "middle"; + ctx.fillStyle = config.scaleFontColor; + ctx.fillTextMultiLine(label, midPosX, midPosY - (scaleHop * (i + 1)), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + for (var i = 0; i < data.length; i++) { + if(typeof data[i].value == "undefined") continue; + if (1 * data[i].value > upperValue) { + upperValue = 1 * data[i].value; + } + if (1 * data[i].value < lowerValue) { + lowerValue = 1 * data[i].value; + } + }; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + if(typeof config.graphMin=="function") lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + var Radar = function(data, config, ctx) { + var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, msr, midPosX, midPosY; + + ctx.tpchart="Radar"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + valueBounds = getValueBounds(); + + config.logarithmic = false; + config.logarithmic2 = false; + //If no labels are defined set to an empty array, so referencing length for looping doesn't blow up. + if (!data.labels) data.labels = []; + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, false, true, config.datasetFill, "Radar"); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + graphMax: scaleStartValue + scaleSteps * scaleStepWidth, + labels: [] + } + populateLabels(1, config, labelTemplateString, calculatedScale.labels, calculatedScale.steps, scaleStartValue, calculatedScale.graphMax, scaleStepWidth); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, false, true, config.datasetFill, "Radar"); + } + + calculateDrawingSizes(); + midPosY = msr.topNotUsableSize + (msr.availableHeight / 2); + scaleHop = maxSize / (calculatedScale.steps); + //Wrap in an animation loop wrapper + initPassVariableData_part2(statData,data,config,ctx,{midPosX : midPosX, midPosY : midPosY, calculatedScale: calculatedScale, scaleHop: scaleHop, maxSize:maxSize}); + animationLoop(config, drawScale, drawAllDataPoints, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, midPosX, midPosY, midPosX - maxSize, midPosY + maxSize, data); + //Radar specific functions. + function drawAllDataPoints(animationDecimal) { + var rotationDegree = (2 * Math.PI) / data.datasets[0].data.length; + ctx.save(); + //We accept multiple data sets for radar charts, so show loop through each set + for (var i = 0; i < data.datasets.length; i++) { + var fPt = -1; + for (var j = 0; j < data.datasets[i].data.length; j++) { + var currentAnimPc = animationCorrection(animationDecimal, data, config, i, j, 1).animVal; + if (currentAnimPc > 1) currentAnimPc = currentAnimPc - 1; + if (!(typeof(data.datasets[i].data[j]) == 'undefined')) { + if (fPt == -1) { + ctx.beginPath(); + ctx.moveTo(midPosX + currentAnimPc * statData[i][j].offsetX, midPosY - currentAnimPc * statData[i][j].offsetY); + fPt = j; + } else { + ctx.lineTo(midPosX + currentAnimPc * statData[i][j].offsetX, midPosY - currentAnimPc * statData[i][j].offsetY); + } + } + } + ctx.closePath(); + if (config.datasetFill) { + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,-1,{animationValue : currentAnimPc, midPosX : statData[i][0].midPosX, midPosY : statData[i][0].midPosY, ext_radius : (config.animationLeftToRight ? 1 : currentAnimPc) * (statData[i][0].calculated_offset_max)} ); + } else ctx.fillStyle = "rgba(0,0,0,0)"; + + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,-1,{nullvalue : null} ); + + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.datasetStrokeWidth); + ctx.fill(); +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + if (config.pointDot && (!config.animationLeftToRight || (config.animationLeftToRight && animationDecimal >= 1))) { + ctx.beginPath(); + ctx.fillStyle=setOptionValue(1,"MARKERFILLCOLOR",ctx,data,statData,data.datasets[i].pointColor,config.defaultStrokeColor,i,-1,{nullvalue: true} ); + ctx.strokeStyle=setOptionValue(1,"MARKERSTROKESTYLE",ctx,data,statData,data.datasets[i].pointStrokeColor,config.defaultStrokeColor,i,-1,{nullvalue: true} ); + ctx.lineWidth=setOptionValue(ctx.chartLineScale,"MARKERLINEWIDTH",ctx,data,statData,data.datasets[i].pointDotStrokeWidth,config.pointDotStrokeWidth,i,-1,{nullvalue: true} ); + + for (var k = 0; k < data.datasets[i].data.length; k++) { + if (!(typeof(data.datasets[i].data[k]) == 'undefined')) { + ctx.beginPath(); + var markerShape=setOptionValue(1,"MARKERSHAPE",ctx,data,statData,data.datasets[i].markerShape,config.markerShape,i,j,{nullvalue: true} ); + var markerRadius=setOptionValue(ctx.chartSpaceScale,"MARKERRADIUS",ctx,data,statData,data.datasets[i].pointDotRadius,config.pointDotRadius,i,j,{nullvalue: true} ); + var markerStrokeStyle=setOptionValue(1,"MARKERSTROKESTYLE",ctx,data,statData,data.datasets[i].pointDotStrokeStyle,config.pointDotStrokeStyle,i,j,{nullvalue: true} ); + drawMarker(ctx,midPosX + currentAnimPc * statData[i][k].offsetX, midPosY - currentAnimPc * statData[i][k].offsetY, markerShape,markerRadius,markerStrokeStyle); + } + } + } + } + ctx.restore(); + if (animationDecimal >= config.animationStopValue) { + for (i = 0; i < data.datasets.length; i++) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; + if (setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["POINT", i,j,statData]; + } + if(setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + + + ctx.save(); + ctx.beginPath(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ); + if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "off-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) <= Math.PI / 2) ctx.textAlign = "left"; + else ctx.textAlign = "right"; + } else if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "to-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "right"; + else ctx.textAlign = "left"; + } else ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }); + if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "off-center") { + if ((config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "bottom"; + else ctx.textBaseline = "top"; + } else if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "to-center") { + if ((config.startAngle * Math.PI / 180 - j * rotationDegree + 4 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "top"; + else ctx.textBaseline = "bottom"; + } else ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,-1,{nullValue : true} ); + var radiusPrt; + if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 1) radiusPrt = 0 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 2) radiusPrt = (statData[i][j].calculated_offset) / 2 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 3) radiusPrt = (statData[i][j].calculated_offset) + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + if(statData[i][j].calculated_offset>0) { + ctx.translate(midPosX + statData[i][j].offsetX * (radiusPrt/statData[i][j].calculated_offset), midPosY - statData[i][j].offsetY * (radiusPrt/statData[i][j].calculated_offset)); + } else { + ctx.translate(midPosX, midPosY); + } + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis") ctx.rotate(j * rotationDegree); + else if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxisRotateLabels") { + if ((j * rotationDegree + 2 * Math.PI) % (2 * Math.PI) > Math.PI / 2 && (j * rotationDegree + 2 * Math.PI) % (2 * Math.PI) < 3 * Math.PI / 2) ctx.rotate(3 * Math.PI + j * rotationDegree); + else ctx.rotate(2 * Math.PI + j * rotationDegree); + } else ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) * (Math.PI / 180)); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i][j],config); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,-1,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,-1,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),true); + ctx.restore(); + } + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"Radar"); + }; + + function drawScale() { + var rotationDegree = (2 * Math.PI) / data.datasets[0].data.length; + ctx.save(); + ctx.translate(midPosX, midPosY); + ctx.rotate((90 - config.startAngle) * Math.PI / 180); + if (config.angleShowLineOut) { + ctx.strokeStyle = config.angleLineColor; + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.angleLineWidth); + for (var h = 0; h < data.datasets[0].data.length; h++) { + ctx.rotate(rotationDegree); + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(0, -maxSize); +// ctx.setLineDash(lineStyleFn(config.angleLineStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"ANGLELINESTYLE",ctx,data,statData,undefined,config.angleLineStyle,h,-1,{nullValue : true} ))); + ctx.stroke(); + ctx.setLineDash([]); + } + } + for (var i = 0; i < calculatedScale.steps; i++) { + ctx.beginPath(); + if (config.scaleShowLine && (i+1) % config.scaleGridLinesStep == 0 ) { + ctx.strokeStyle = config.scaleLineColor; + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.moveTo(0, -scaleHop * (i + 1)); + for (var j = 0; j < data.datasets[0].data.length; j++) { + ctx.rotate(rotationDegree); + ctx.lineTo(0, -scaleHop * (i + 1)); + } + ctx.closePath(); + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.stroke(); + ctx.setLineDash([]); + } + } + ctx.rotate(-(90 - config.startAngle) * Math.PI / 180); + if (config.scaleShowLabels) { + for (i = 0; i < calculatedScale.steps; i++) { + ctx.textAlign = 'center'; + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + ctx.textBaseline = "middle"; + if (config.scaleShowLabelBackdrop) { + var textWidth = ctx.measureTextMultiLine(calculatedScale.labels[i + 1], (Math.ceil(ctx.chartTextScale*config.scaleFontSize))).textWidth; + ctx.fillStyle = config.scaleBackdropColor; + ctx.beginPath(); + ctx.rect( + Math.round(Math.cos(config.startAngle * Math.PI / 180) * (scaleHop * (i + 1)) - textWidth / 2 - Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingX)), //X + Math.round((-Math.sin(config.startAngle * Math.PI / 180) * scaleHop * (i + 1)) - (Math.ceil(ctx.chartTextScale*config.scaleFontSize)) * 0.5 - Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingY)), //Y + Math.round(textWidth + (Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingX) * 2)), //Width + Math.round((Math.ceil(ctx.chartTextScale*config.scaleFontSize)) + (Math.ceil(ctx.chartSpaceScale*config.scaleBackdropPaddingY) * 2)) //Height + ); + ctx.fill(); + } + ctx.fillStyle = config.scaleFontColor; + ctx.fillTextMultiLine(calculatedScale.labels[i + 1], Math.cos(config.startAngle * Math.PI / 180) * (scaleHop * (i + 1)), -Math.sin(config.startAngle * Math.PI / 180) * scaleHop * (i + 1), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + for (var k = 0; k < data.labels.length; k++) { + ctx.font = config.pointLabelFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.pointLabelFontSize)).toString() + "px " + config.pointLabelFontFamily; + ctx.fillStyle = config.pointLabelFontColor; + var opposite = Math.sin((90 - config.startAngle) * Math.PI / 180 + rotationDegree * k) * (maxSize + (Math.ceil(ctx.chartTextScale*config.pointLabelFontSize))); + var adjacent = Math.cos((90 - config.startAngle) * Math.PI / 180 + rotationDegree * k) * (maxSize + (Math.ceil(ctx.chartTextScale*config.pointLabelFontSize))); + var vangle = (90 - config.startAngle) * Math.PI / 180 + rotationDegree * k; + while (vangle < 0) vangle = vangle + 2 * Math.PI; + while (vangle > 2 * Math.PI) vangle = vangle - 2 * Math.PI; + if (vangle == Math.PI || vangle == 0) { + ctx.textAlign = "center"; + } else if (vangle > Math.PI) { + ctx.textAlign = "right"; + } else { + ctx.textAlign = "left"; + } + ctx.textBaseline = "middle"; + ctx.fillTextMultiLine(data.labels[k], opposite, -adjacent, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.pointLabelFontSize)),true); + } + ctx.restore(); + }; + + function calculateDrawingSizes() { + var midX, mxlb, maxL, maxR, iter, nbiter, prevMaxSize, prevMidX,i,textMeasurement; + var rotationDegree = (2 * Math.PI) / data.datasets[0].data.length; + var rotateAngle = config.startAngle * Math.PI / 180; + // Compute range for Mid Point of graph + ctx.font = config.pointLabelFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.pointLabelFontSize)).toString() + "px " + config.pointLabelFontFamily; + if (!config.graphMaximized) { + maxR = msr.availableWidth / 2; + maxL = msr.availableWidth / 2; + nbiter = 1; + } else { + maxR = msr.availableWidth / 2; + maxL = msr.availableWidth / 2; + nbiter = 40; + for (i = 0; i < data.labels.length; i++) { + textMeasurement = ctx.measureTextMultiLine(data.labels[i], (Math.ceil(ctx.chartTextScale*config.scaleFontSize))).textWidth + ctx.measureTextMultiLine(data.labels[i], (Math.ceil(ctx.chartTextScale*config.scaleFontSize))).textHeight; + mxlb = (msr.availableWidth - textMeasurement) / (1 + Math.abs(Math.cos(rotateAngle))); + if ((rotateAngle < Math.PI / 2 && rotateAngle > -Math.PI / 2) || rotateAngle > 3 * Math.PI / 2) { + if (mxlb < maxR) maxR = mxlb; + } else if (Math.cos(rotateAngle) != 0) { + if (mxlb < maxL) maxL = mxlb; + } + rotateAngle -= rotationDegree; + } + } + // compute max Radius and midPoint in that range + prevMaxSize = 0; + prevMidX = 0; + midPosX = maxR + msr.rightNotUsableSize; + for (midX = maxR, iter = 0; iter < nbiter; ++iter, midX += (msr.availableWidth - maxL - maxR) / nbiter) { + maxSize = Max([midX, msr.availableWidth - midX]); + rotateAngle = config.startAngle * Math.PI / 180; + mxlb = msr.available; + for (i = 0; i < data.labels.length; i++) { + textMeasurement = ctx.measureTextMultiLine(data.labels[i], (Math.ceil(ctx.chartTextScale*config.scaleFontSize))).textWidth + ctx.measureTextMultiLine(data.labels[i], (Math.ceil(ctx.chartTextScale*config.scaleFontSize))).textHeight; + if ((rotateAngle < Math.PI / 2 && rotateAngle > -Math.PI / 2) || rotateAngle > 3 * Math.PI / 2) { + mxlb = ((msr.availableWidth - midX) - textMeasurement) / Math.abs(Math.cos(rotateAngle)); + } else if (Math.cos(rotateAngle != 0)) { + mxlb = (midX - textMeasurement) / Math.abs(Math.cos(rotateAngle)); + } + if (mxlb < maxSize) maxSize = mxlb; + if (Math.sin(rotateAngle) * msr.availableHeight / 2 > msr.availableHeight / 2 - (Math.ceil(ctx.chartTextScale*config.scaleFontSize)) * 2) { + mxlb = Math.sin(rotateAngle) * msr.availableHeight / 2 - 1.5 * (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + if (mxlb < maxSize) maxSize = mxlb; + } + rotateAngle -= rotationDegree; + } + if (maxSize > prevMaxSize) { + prevMaxSize = maxSize; + midPosX = midX + msr.rightNotUsableSize; + } + } + maxSize = prevMaxSize - (Math.ceil(ctx.chartTextScale*config.scaleFontSize)) / 2; + //If the label height is less than 5, set it to 5 so we don't have lines on top of each other. + labelHeight = Default(labelHeight, 5); + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + if(typeof data.datasets[i].data[j]=="undefined")continue; + if (1 * data.datasets[i].data[j] > upperValue) { + upperValue = 1 * data.datasets[i].data[j] + } + if (1 * data.datasets[i].data[j] < lowerValue) { + lowerValue = 1 * data.datasets[i].data[j] + } + } + } + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue){ upperValue = .9;lowerValue=-.9;} + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + if(typeof config.graphMin=="function") lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + + + var Pie = function(data, config, ctx) { + var msr, midPieX, midPieY, pieRadius; + + ctx.tpchart="Pie"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + config.logarithmic = false; + config.logarithmic2 = false; + msr = setMeasures(data, config, ctx, height, width, "none", null, true, false, false, false, true, "Pie"); + calculateDrawingSize(); + if(pieRadius > 0) { + initPassVariableData_part2(statData,data,config,ctx,{midPosX : midPieX,midPosY : midPieY,int_radius : 0,ext_radius : pieRadius}); + animationLoop(config, null, drawPieSegments, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, midPieX, midPieY, midPieX - pieRadius, midPieY + pieRadius, data); + } else { + testRedraw(ctx,data,config); + } + function drawPieSegments(animationDecimal) { + for (var i = 0; i < data.length; i++) { + var scaleAnimation = 1, + rotateAnimation = 1; + + if (config.animation) { + if (config.animateScale) { + scaleAnimation = animationDecimal; + } + if (config.animateRotate) { + rotateAnimation = animationDecimal; + } + } + correctedRotateAnimation = animationCorrection(rotateAnimation, data, config, i, -1, 0).mainVal; + if (!(typeof(data[i].value) == 'undefined')&& 1*data[i].value >=0) { + ctx.beginPath(); + if(config.animationByData == "ByArc") { + endAngle=statData[i].startAngle+correctedRotateAnimation*statData[i].segmentAngle; + ctx.arc(midPieX, midPieY, scaleAnimation * pieRadius, statData[i].startAngle, endAngle); + } else if(config.animationByData) { + if(statData[i].startAngle-statData[i].firstAngle < correctedRotateAnimation*2*Math.PI ) { + endAngle=statData[i].endAngle; + if((statData[i].endAngle-statData[i].firstAngle)> correctedRotateAnimation*2*Math.PI) endAngle=statData[i].firstAngle+correctedRotateAnimation*2*Math.PI; + ctx.arc(midPieX, midPieY, scaleAnimation * pieRadius, statData[i].startAngle, endAngle); + + } + else continue; + } else { + ctx.arc(midPieX, midPieY, scaleAnimation * pieRadius, statData[i].firstAngle+correctedRotateAnimation * (statData[i].startAngle-statData[i].firstAngle), statData[i].firstAngle+correctedRotateAnimation * (statData[i].endAngle-statData[i].firstAngle)); + } + ctx.lineTo(midPieX, midPieY); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data[i].color,config.defaultFillColor,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ); + ctx.fill(); + if (config.segmentShowStroke) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.segmentStrokeWidth); + ctx.strokeStyle = config.segmentStrokeColor; + ctx.setLineDash(lineStyleFn(setOptionValue(1,"SEGMENTSTROKESTYLE",ctx,data,statData,data[i].segmentStrokeStyle,config.segmentStrokeStyle,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ))); + ctx.stroke(); + ctx.setLineDash([]); + } + } + } + if (animationDecimal >= config.animationStopValue) { + for (i = 0; i < data.length; i++) { + if (typeof(data[i].value) == 'undefined' || 1*data[i].value<0) continue; + if (setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,-1,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["ARC", i,-1,statData]; + } + if (setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,-1,{nullValue : true}) && statData[i]["segmentAngle"] >= (Math.PI/180) * setOptionValue(1,"INGRAPHDATAMINIMUMANGLE",ctx,data,statData,undefined,config.inGraphDataMinimumAngle,i,-1,{nullValue : true} )) { + if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 1) posAngle = statData[i].realStartAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 2) posAngle = statData[i].realStartAngle - statData[i]["segmentAngle"] / 2 + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 3) posAngle = statData[i].realStartAngle - statData[i].segmentAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 1) labelRadius = 0 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 2) labelRadius = pieRadius / 2 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 3) labelRadius = pieRadius + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + ctx.save(); + if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "off-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "left"; + else ctx.textAlign = "right"; + } else if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "to-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "right"; + else ctx.textAlign = "left"; + } else ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }); + if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "off-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "top"; + else ctx.textBaseline = "bottom"; + } else if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "to-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "bottom"; + else ctx.textBaseline = "top"; + } else ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,-1,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i],config); + ctx.translate(midPieX + labelRadius * Math.cos(posAngle), midPieY - labelRadius * Math.sin(posAngle)); + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis") ctx.rotate(2 * Math.PI - posAngle); + else if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxisRotateLabels") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI / 2 && (posAngle + 2 * Math.PI) % (2 * Math.PI) < 3 * Math.PI / 2) ctx.rotate(3 * Math.PI - posAngle); + else ctx.rotate(2 * Math.PI - posAngle); + } else ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,-1,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,-1,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),true); + ctx.restore(); + } + } + + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"Pie"); + }; + + function calculateDrawingSize() { + midPieX = msr.leftNotUsableSize + (msr.availableWidth / 2); + midPieY = msr.topNotUsableSize + (msr.availableHeight / 2); + pieRadius = Min([msr.availableHeight / 2, msr.availableWidth / 2]) - 5; + // Computerange Pie Radius + if (isBooleanOptionTrue(undefined,config.inGraphDataShow) && setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,0,-1,{nullValue : true} ) == 3 && setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,0,-1,{nullValue: true }) == "off-center" && setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,0,-1,{nullValue : true} ) == 0) { + pieRadius = Min([msr.availableHeight / 2, msr.availableWidth / 2]) - setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,0,-1,{nullValue : true} ) - setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,0,-1,{nullValue: true} ) - 5; + var realCumulativeAngle = ((config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2*Math.PI) + 2*Math.PI) % (2*Math.PI); + for (var i = 0; i < data.length; i++) { + if (!(typeof(data[i].value) == 'undefined') && 1*data[i].value>=0) { + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,0,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 1) posAngle = realCumulativeAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 2) posAngle = realCumulativeAngle - statData[i].segmentAngle / 2 + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 3) posAngle = realCumulativeAngle - statData[i].segmentAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + realCumulativeAngle -= statData[i].segmentAngle; + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i],config); + var textMeasurement = ctx.measureText(dispString).width; + var MaxRadiusX = Math.abs((msr.availableWidth / 2 - textMeasurement) / Math.cos(posAngle)) - setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ) - 5; + if (MaxRadiusX < pieRadius) pieRadius = MaxRadiusX; + } + } + } + pieRadius = pieRadius * config.radiusScale; + }; + }; + var Doughnut = function(data, config, ctx) { + var msr, midPieX, midPieY, doughnutRadius; + + ctx.tpchart="Doughnut"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + + var realCumulativeAngle = (((config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + config.logarithmic = false; + config.logarithmic2 = false; + msr = setMeasures(data, config, ctx, height, width, "none", null, true, false, false, false, true, "Doughnut"); + calculateDrawingSize(); + + var cutoutRadius = doughnutRadius * (config.percentageInnerCutout / 100); + if(doughnutRadius > 0) { + initPassVariableData_part2(statData,data,config,ctx,{midPosX : midPieX,midPosY : midPieY ,int_radius : cutoutRadius ,ext_radius : doughnutRadius}); + animationLoop(config, null, drawPieSegments, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, midPieX, midPieY, midPieX - doughnutRadius, midPieY + doughnutRadius, data); + } else { + testRedraw(ctx,data,config); + } + + + function drawPieSegments(animationDecimal) { + var cumulativeAngle = (((-config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + + for (var i = 0; i < data.length; i++) { + var scaleAnimation = 1, + rotateAnimation = 1; + + if (config.animation) { + if (config.animateScale) { + scaleAnimation = animationDecimal; + } + if (config.animateRotate) { + rotateAnimation = animationDecimal; + } + } + correctedRotateAnimation = animationCorrection(rotateAnimation, data, config, i, -1, 0).mainVal; + if (!(typeof(data[i].value) == 'undefined') && 1*data[i].value >=0) { + ctx.beginPath(); + if (config.animationByData == "ByArc") { + endAngle=statData[i].startAngle+correctedRotateAnimation*statData[i].segmentAngle; + ctx.arc(midPieX, midPieY, scaleAnimation * doughnutRadius, statData[i].startAngle, endAngle,false); + ctx.arc(midPieX, midPieY, scaleAnimation * cutoutRadius, endAngle,statData[i].startAngle, true); + } else if(config.animationByData) { + if(statData[i].startAngle-statData[i].firstAngle < correctedRotateAnimation*2*Math.PI ) { + endAngle=statData[i].endAngle; + if((statData[i].endAngle-statData[i].firstAngle)> correctedRotateAnimation*2*Math.PI) endAngle=statData[i].firstAngle+correctedRotateAnimation*2*Math.PI; + ctx.arc(midPieX, midPieY, scaleAnimation * doughnutRadius, statData[i].startAngle, endAngle,false); + ctx.arc(midPieX, midPieY, scaleAnimation * cutoutRadius, endAngle,statData[i].startAngle, true); + + } + else continue; + } else { + ctx.arc(midPieX, midPieY, scaleAnimation * doughnutRadius, statData[i].firstAngle+correctedRotateAnimation * (statData[i].startAngle-statData[i].firstAngle), statData[i].firstAngle+correctedRotateAnimation * (statData[i].endAngle-statData[i].firstAngle),false); + ctx.arc(midPieX, midPieY, scaleAnimation * cutoutRadius, statData[i].firstAngle+correctedRotateAnimation * (statData[i].endAngle-statData[i].firstAngle), statData[i].firstAngle+correctedRotateAnimation * (statData[i].startAngle-statData[i].firstAngle), true); + } + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data[i].color,config.defaultFillColor,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ); + ctx.fill(); + if (config.segmentShowStroke) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.segmentStrokeWidth); + ctx.strokeStyle = config.segmentStrokeColor; + ctx.setLineDash(lineStyleFn(setOptionValue(1,"SEGMENTSTROKESTYLE",ctx,data,statData,data[i].segmentStrokeStyle,config.segmentStrokeStyle,i,-1,{animationDecimal: animationDecimal, scaleAnimation : scaleAnimation} ))); + ctx.stroke(); + ctx.setLineDash([]); + } + } + } + if (animationDecimal >= config.animationStopValue) { + for (i = 0; i < data.length; i++) { + if (typeof(data[i].value) == 'undefined' || 1*data[i].value<0) continue; + if(setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,-1,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["ARC", i,-1,statData]; + } + if (setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,-1,{nullValue : true}) && statData[i].segmentAngle >= (Math.PI/180) * setOptionValue(1,"INGRAPHDATAMINIMUMANGLE",ctx,data,statData,undefined,config.inGraphDataMinimumAngle,i,-1,{nullValue : true} )) { + if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 1) posAngle = statData[i].realStartAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 2) posAngle = statData[i].realStartAngle- statData[i].segmentAngle / 2 + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 3) posAngle = statData[i].realStartAngle - statData[i].segmentAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 1) labelRadius = cutoutRadius + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 2) labelRadius = cutoutRadius + (doughnutRadius - cutoutRadius) / 2 + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + else if (setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,i,-1,{nullValue : true} ) == 3) labelRadius = doughnutRadius + setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ); + ctx.save(); + if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "off-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "left"; + else ctx.textAlign = "right"; + } else if (setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }) == "to-center") { + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis" || (posAngle + 2 * Math.PI) % (2 * Math.PI) > 3 * Math.PI / 2 || (posAngle + 2 * Math.PI) % (2 * Math.PI) < Math.PI / 2) ctx.textAlign = "right"; + else ctx.textAlign = "left"; + } else ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,-1,{nullValue: true }); + if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "off-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "top"; + else ctx.textBaseline = "bottom"; + } else if (setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ) == "to-center") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI) ctx.textBaseline = "bottom"; + else ctx.textBaseline = "top"; + } else ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,-1,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,-1,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i],config); + ctx.translate(midPieX + labelRadius * Math.cos(posAngle), midPieY - labelRadius * Math.sin(posAngle)); + if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxis") ctx.rotate(2 * Math.PI - posAngle); + else if (setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) == "inRadiusAxisRotateLabels") { + if ((posAngle + 2 * Math.PI) % (2 * Math.PI) > Math.PI / 2 && (posAngle + 2 * Math.PI) % (2 * Math.PI) < 3 * Math.PI / 2) ctx.rotate(3 * Math.PI - posAngle); + else ctx.rotate(2 * Math.PI - posAngle); + } else ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,-1,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,-1,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,-1,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,-1,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,-1,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ),true); + ctx.restore(); + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"Doughnut"); + }; + + function calculateDrawingSize() { + midPieX = msr.leftNotUsableSize + (msr.availableWidth / 2); + midPieY = msr.topNotUsableSize + (msr.availableHeight / 2); + doughnutRadius = Min([msr.availableHeight / 2, msr.availableWidth / 2]) - 5; + // Computerange Pie Radius + if (isBooleanOptionTrue(undefined,config.inGraphDataShow) && setOptionValue(1,"INGRAPHDATARADIUSPOSITION",ctx,data,statData,undefined,config.inGraphDataRadiusPosition,0,-1,{nullValue : true} ) == 3 && setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,0,-1,{nullValue: true }) == "off-center" && setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,0,-1,{nullValue : true} ) == 0) { + doughnutRadius = Min([msr.availableHeight / 2, msr.availableWidth / 2]) - setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,0,-1,{nullValue : true} ) - setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,0,-1,{nullValue: true} ) - 5; + var realCumulativeAngle = (((config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + var posAngle; + for (var i = 0; i < data.length; i++) { + if (!(typeof(data[i].value) == 'undefined') && 1*data[i].value>=0) { + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,-1,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,-1,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,-1,{nullValue : true} ); + if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 1) posAngle = realCumulativeAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 2) posAngle = realCumulativeAngle - statData[i].segmentAngle / 2 + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + else if (setOptionValue(1,"INGRAPHDATAANGLEPOSITION",ctx,data,statData,undefined,config.inGraphDataAnglePosition,i,-1,{nullValue : true} ) == 3) posAngle = realCumulativeAngle - statData[i].segmentAngle + setOptionValue(1,"INGRAPHDATAPADDINANGLE",ctx,data,statData,undefined,config.inGraphDataPaddingAngle,i,-1,{nullValue: true }) * (Math.PI / 180); + realCumulativeAngle -= statData[i].segmentAngle; + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,-1,{nullValue : true} ), statData[i],config); + var textMeasurement = ctx.measureText(dispString).width; + var MaxRadiusX = Math.abs((msr.availableWidth / 2 - textMeasurement) / Math.cos(posAngle)) - setOptionValue(1,"INGRAPHDATAPADDINGRADIUS",ctx,data,statData,undefined,config.inGraphDataPaddingRadius,i,-1,{nullValue: true} ) - 5; + if (MaxRadiusX < doughnutRadius) doughnutRadius = MaxRadiusX; + } + } + } + doughnutRadius = doughnutRadius * config.radiusScale; + }; + }; + var Line = function(data, config, ctx) { + var maxSize, scaleHop, scaleHop2, calculatedScale, calculatedScale2, labelHeight, scaleHeight, valueBounds, labelTemplateString, labelTemplateString2; + var valueHop, widestXLabel, xAxisLength, yAxisPosX, xAxisPosY, rotateLabels = 0, + msr; + var zeroY = 0; + var zeroY2 = 0; + ctx.tpchart="Line"; + if (!init_and_start(ctx,data,config)) return; + // adapt data when length is 1; + var mxlgt = 0; + for (var i = 0; i < data.datasets.length; i++) {mxlgt = Max([mxlgt, data.datasets[i].data.length]);} + if (mxlgt == 1) { + if (typeof(data.labels[0]) == "string") data.labels = ["", data.labels[0], ""]; + for (i = 0; i < data.datasets.length; i++) { + if (typeof(data.datasets[i].data[0] != "undefined")) data.datasets[i].data = [undefined, data.datasets[i].data[0], undefined]; + } + mxlgt=3; + } + var statData=initPassVariableData_part1(data,config,ctx); + for (i = 0; i < data.datasets.length; i++) statData[i][0].tpchart="Line"; + msr = setMeasures(data, config, ctx, height, width, "nihil", [""], false, false, true, true, config.datasetFill, "Line"); + valueBounds = getValueBounds(); + // true or fuzzy (error for negativ values (included 0)) + if (config.logarithmic !== false) { + if (valueBounds.minValue <= 0) { + config.logarithmic = false; + } + } + if (config.logarithmic2 !== false) { + if (valueBounds.minValue2 <= 0) { + config.logarithmic2 = false; + } + } + // Check if logarithmic is meanigful + var OrderOfMagnitude = calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.maxValue) + 1)) - calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.minValue))); + if ((config.logarithmic == 'fuzzy' && OrderOfMagnitude < 4) || config.scaleOverride) { + config.logarithmic = false; + } + // Check if logarithmic is meanigful + var OrderOfMagnitude2 = calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.maxValue2) + 1)) - calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.minValue2))); + if ((config.logarithmic2 == 'fuzzy' && OrderOfMagnitude2 < 4) || config.scaleOverride2) { + config.logarithmic2 = false; + } + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + labelTemplateString2 = (config.scaleShowLabels2) ? config.scaleLabel2 : ""; + if (!config.scaleOverride) { + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + } + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + graphMax: scaleStartValue + scaleSteps * scaleStepWidth, + labels: [] + } + populateLabels(1, config, labelTemplateString, calculatedScale.labels, calculatedScale.steps, scaleStartValue, calculatedScale.graphMax, scaleStepWidth); + } + + if (valueBounds.dbAxis) { + if (!config.scaleOverride2) { + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + calculatedScale2 = calculateScale(2, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue2, valueBounds.minValue2, labelTemplateString); + } + } else { + var scaleStartValue2= setOptionValue(1,"SCALESTARTVALUE2",ctx,data,statData,undefined,config.scaleStartValue2,-1,-1,{nullValue : true} ); + var scaleSteps2 =setOptionValue(1,"SCALESTEPS2",ctx,data,statData,undefined,config.scaleSteps2,-1,-1,{nullValue : true} ); + var scaleStepWidth2 = setOptionValue(1,"SCALESTEPWIDTH2",ctx,data,statData,undefined,config.scaleStepWidth2,-1,-1,{nullValue : true} ); + + calculatedScale2 = { + steps: scaleSteps2, + stepValue: scaleStepWidth2, + graphMin: scaleStartValue2, + graphMax: scaleStartValue2 + scaleSteps2 * scaleStepWidth2, + labels: [] + } + populateLabels(2, config, labelTemplateString2, calculatedScale2.labels, calculatedScale2.steps, scaleStartValue2, calculatedScale2.graphMax, scaleStepWidth2); + } + } else { + calculatedScale2 = { + steps: 0, + stepValue: 0, + graphMin: 0, + graphMax: 0, + labels: null + } + } + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, calculatedScale2.labels, false, false, true, true, config.datasetFill, "Line"); + var prevHeight=msr.availableHeight; + msr.availableHeight = msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + msr.availableWidth = msr.availableWidth - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight); + scaleHop = Math.floor(msr.availableHeight / calculatedScale.steps); + scaleHop2 = Math.floor(msr.availableHeight / calculatedScale2.steps); + valueHop = Math.floor(msr.availableWidth / (data.labels.length - 1)); + if (valueHop == 0 || config.fullWidthGraph) valueHop = (msr.availableWidth / (data.labels.length - 1)); + msr.clrwidth = msr.clrwidth - (msr.availableWidth - (data.labels.length - 1) * valueHop); + msr.availableWidth = (data.labels.length - 1) * valueHop; + msr.availableHeight = (calculatedScale.steps) * scaleHop; + msr.xLabelPos+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + msr.clrheight+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + yAxisPosX = msr.leftNotUsableSize + Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft); + xAxisPosY = msr.topNotUsableSize + msr.availableHeight + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + drawLabels(); + if (valueBounds.minValue < 0) { + zeroY = calculateOffset(config.logarithmic, 0, calculatedScale, scaleHop); + } + if (valueBounds.minValue2 < 0) { + zeroY2 = calculateOffset(config.logarithmic2, 0, calculatedScale2, scaleHop2); + } + initPassVariableData_part2(statData,data,config,ctx,{ + xAxisPosY : xAxisPosY, + yAxisPosX : yAxisPosX, + valueHop : valueHop, + nbValueHop : data.labels.length - 1, + scaleHop : scaleHop, + zeroY : zeroY, + calculatedScale : calculatedScale, + logarithmic : config.logarithmic, + scaleHop2: scaleHop2, + zeroY2: zeroY2, + msr : msr, + calculatedScale2: calculatedScale2, + logarithmic2: config.logarithmic2} ); + animationLoop(config, drawScale, drawLines, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, yAxisPosX + msr.availableWidth / 2, xAxisPosY - msr.availableHeight / 2, yAxisPosX, xAxisPosY, data); + } else { + testRedraw(ctx,data,config); + } + + + function drawLines(animPc) { + + drawLinesDataset(animPc, data, config, ctx, statData,{xAxisPosY : xAxisPosY,yAxisPosX : yAxisPosX, valueHop : valueHop, nbValueHop : data.labels.length - 1 }); + if (animPc >= 1) { + if (typeof drawMath == "function") { + drawMath(ctx, config, data, msr, { + xAxisPosY: xAxisPosY, + yAxisPosX: yAxisPosX, + valueHop: valueHop, + scaleHop: scaleHop, + zeroY: zeroY, + calculatedScale: calculatedScale, + calculateOffset: calculateOffset, + statData : statData + + }); + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"Line"); + }; + + function drawScale() { + //X axis line + // if the xScale should be drawn + if (config.drawXScaleLine !== false) { + for (var s = 0; s < config.drawXScaleLine.length; s++) { + // get special lineWidth and lineColor for this xScaleLine + ctx.lineWidth = config.drawXScaleLine[s].lineWidth ? config.drawXScaleLine[s].lineWidth : Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.drawXScaleLine[s].lineColor ? config.drawXScaleLine[s].lineColor : config.scaleLineColor; + ctx.beginPath(); + var yPosXScale; + switch (config.drawXScaleLine[s].position) { + case "bottom": + yPosXScale = xAxisPosY; + break; + case "top": + yPosXScale = xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + break; + case "0": + case 0: + // check if zero exists + if (zeroY != 0) { + yPosXScale = xAxisPosY - zeroY; + } + break; + } + // draw the scale line + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), yPosXScale); + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), yPosXScale); + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.stroke(); + ctx.setLineDash([]); + + } + } + for (var i = 0; i < data.labels.length; i++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + //Check i isnt 0, so we dont go over the Y axis twice. + if (config.scaleShowGridLines && i > 0 && i % config.scaleXGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + } else { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY); + } + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + ctx.stroke(); + ctx.setLineDash([]); + } + //Y axis + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.beginPath(); + ctx.moveTo(yAxisPosX, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineTo(yAxisPosX, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.stroke(); + ctx.setLineDash([]); + for (var j = 0; j < calculatedScale.steps; j++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY - ((j + 1) * scaleHop)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + if (config.scaleShowGridLines && (j+1) % config.scaleYGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY - ((j + 1) * scaleHop)); + } else { + ctx.lineTo(yAxisPosX, xAxisPosY - ((j + 1) * scaleHop)); + } + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + ctx.stroke(); + ctx.setLineDash([]); + } + }; + + function drawLabels() { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + //X Labels + if (config.xAxisTop || config.xAxisBottom) { + ctx.textBaseline = "top"; + if (msr.rotateLabels > 90) { + ctx.save(); + ctx.textAlign = "left"; + } else if (msr.rotateLabels > 0) { + ctx.save(); + ctx.textAlign = "right"; + } else { + ctx.textAlign = "center"; + } + ctx.fillStyle = config.scaleFontColor; + if (config.xAxisBottom) { + for (var i = 0; i < data.labels.length; i++) { + ctx.save(); + if (msr.rotateLabels > 0) { + ctx.translate(yAxisPosX + i * valueHop - msr.highestXLabel / 2, msr.xLabelPos); + ctx.rotate(-(msr.rotateLabels * (Math.PI / 180))); + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } else { + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), yAxisPosX + i * valueHop, msr.xLabelPos, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + ctx.restore(); + } + } + } + //Y Labels + ctx.textAlign = "right"; + ctx.textBaseline = "middle"; + for (var j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale.steps; j++) { + if (config.scaleShowLabels) { + if (config.yAxisLeft) { + ctx.textAlign = "right"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX - (Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + if (config.yAxisRight && !valueBounds.dbAxis) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + } + if (config.yAxisRight && valueBounds.dbAxis) { + for (j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale2.steps; j++) { + if (config.scaleShowLabels) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(calculatedScale2.labels[j + 1], yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop2), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + var upperValue2 = -Number.MAX_VALUE; + var lowerValue2 = Number.MAX_VALUE; + var secondAxis = false; + var firstAxis = false; + for (var i = 0; i < data.datasets.length; i++) { + var mathFctName = data.datasets[i].drawMathDeviation; + var mathValueHeight = 0; + if (typeof eval(mathFctName) == "function") { + var parameter = { + data: data, + datasetNr: i + }; + mathValueHeight = window[mathFctName](parameter); + } + for (var j = 0; j < data.datasets[i].data.length; j++) { + if(typeof data.datasets[i].data[j] == "undefined") continue; + if (data.datasets[i].axis == 2) { + secondAxis = true; + if (1 * data.datasets[i].data[j] + mathValueHeight > upperValue2) { + upperValue2 = 1 * data.datasets[i].data[j] + mathValueHeight + }; + if (1 * data.datasets[i].data[j] - mathValueHeight < lowerValue2) { + lowerValue2 = 1 * data.datasets[i].data[j] - mathValueHeight + }; + } else { + firstAxis = true; + if (1 * data.datasets[i].data[j] + mathValueHeight > upperValue) { + upperValue = 1 * data.datasets[i].data[j] + mathValueHeight + }; + if (1 * data.datasets[i].data[j] - mathValueHeight < lowerValue) { + lowerValue = 1 * data.datasets[i].data[j] - mathValueHeight + }; + } + } + }; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + + } + if(typeof config.graphMin=="function")lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + + if (secondAxis) { + if(upperValue2<lowerValue2){upperValue2=0;lowerValue2=0;} + if (Math.abs(upperValue2 - lowerValue2) < config.zeroValue) { + if(Math.abs(upperValue2)< config.zeroValue) upperValue2 = .9; + if(upperValue2>0) { + upperValue2=upperValue2*1.1; + lowerValue2=lowerValue2*0.9; + } else { + upperValue2=upperValue2*0.9; + lowerValue2=lowerValue2*1.1; + } + } + if(typeof config.graphMin2=="function")lowerValue2= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin2,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin2)) lowerValue2 = config.graphMin2; + if(typeof config.graphMax2=="function") upperValue2= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax2,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax2)) upperValue2 = config.graphMax2; + } + + if (!firstAxis && secondAxis) { + upperValue = upperValue2; + lowerValue = lowerValue2; + } + + labelHeight = (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + scaleHeight = msr.availableHeight; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxValue2: upperValue2, + minValue2: lowerValue2, + dbAxis: secondAxis, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + var StackedBar = function(data, config, ctx) { + var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, valueHop, widestXLabel, xAxisLength, yAxisPosX, xAxisPosY, barWidth, rotateLabels = 0, + msr; + ctx.tpchart="StackedBar"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + + config.logarithmic = false; + msr = setMeasures(data, config, ctx, height, width, "nihil", [""], true, false, true, true, true, "StackedBar"); + valueBounds = getValueBounds(); + + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, true, true, true, "StackedBar"); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + labels: [] + } + for (var i = 0; i <= calculatedScale.steps; i++) { + if (labelTemplateString) { + calculatedScale.labels.push(tmpl(labelTemplateString, { + value: fmtChartJS(config, 1 * ((scaleStartValue + (scaleStepWidth * i)).toFixed(getDecimalPlaces(scaleStepWidth))), config.fmtYLabel) + },config)); + } + } + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, false, true, true, true, "StackedBar"); + } + + var prevHeight=msr.availableHeight; + + msr.availableHeight = msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + msr.availableWidth = msr.availableWidth - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight); + scaleHop = Math.floor(msr.availableHeight / calculatedScale.steps); + valueHop = Math.floor(msr.availableWidth / (data.labels.length)); + if (valueHop == 0 || config.fullWidthGraph) valueHop = (msr.availableWidth / data.labels.length); + msr.clrwidth = msr.clrwidth - (msr.availableWidth - ((data.labels.length) * valueHop)); + msr.availableWidth = (data.labels.length) * valueHop; + msr.availableHeight = (calculatedScale.steps) * scaleHop; + msr.xLabelPos+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + msr.clrheight+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + + yAxisPosX = msr.leftNotUsableSize + Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft); + xAxisPosY = msr.topNotUsableSize + msr.availableHeight + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + barWidth = (valueHop - Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) * 2) - (Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2) - 1); + if(barWidth>=0 && barWidth<=1)barWidth=1; + if(barWidth<0 && barWidth>=-1)barWidth=-1; + + drawLabels(); + initPassVariableData_part2(statData,data,config,ctx,{ + calculatedScale : calculatedScale, + scaleHop : scaleHop, + valueHop : valueHop, + yAxisPosX : yAxisPosX, + xAxisPosY : xAxisPosY, + barWidth : barWidth + }); + animationLoop(config, drawScale, drawBars, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, yAxisPosX + msr.availableWidth / 2, xAxisPosY - msr.availableHeight / 2, yAxisPosX, xAxisPosY, data); + } else { + testRedraw(ctx,data,config); + } + function drawBars(animPc) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.barStrokeWidth); + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + var currentAnimPc = animationCorrection(animPc, data, config, i, j, 1).animVal; + if (currentAnimPc > 1) currentAnimPc = currentAnimPc - 1; + if ((typeof data.datasets[i].data[j] == 'undefined') || 1*data.datasets[i].data[j] == 0 ) continue; + var botBar, topBar; + if(config.animationByDataset) { + botBar=statData[i][j].yPosBottom; + topBar=statData[i][j].yPosTop; + topBar=botBar+currentAnimPc*(topBar-botBar); + } else { + botBar=statData[statData[i][j].firstNotMissing][j].yPosBottom - currentAnimPc*(statData[statData[i][j].firstNotMissing][j].yPosBottom-statData[i][j].yPosBottom); + topBar=statData[statData[i][j].firstNotMissing][j].yPosBottom - currentAnimPc*(statData[statData[i][j].firstNotMissing][j].yPosBottom-statData[i][j].yPosTop); + } + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc, xPosLeft : statData[i][j].xPosLeft, yPosBottom : botBar, xPosRight : statData[i][j].xPosRight, yPosTop : topBar} ); + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + + if(currentAnimPc !=0 && botBar!=topBar) { + ctx.beginPath(); + ctx.moveTo(statData[i][j].xPosLeft, botBar); + ctx.lineTo(statData[i][j].xPosLeft, topBar); + ctx.lineTo(statData[i][j].xPosRight, topBar); + ctx.lineTo(statData[i][j].xPosRight, botBar); + if (config.barShowStroke) { + ctx.setLineDash(lineStyleFn(setOptionValue(1,"STROKESTYLE",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + }; + ctx.closePath(); + ctx.fill(); + } + } + } + if (animPc >= config.animationStopValue) { + var yPos = 0, + xPos = 0; + for (i = 0; i < data.datasets.length; i++) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; + if(setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["RECT", i, j, statData]; + } + if(setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + ctx.save(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,j,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,j,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,j,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,j,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,j,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,j,{nullValue : true} ), statData[i][j],config); + ctx.beginPath(); + ctx.beginPath(); + yPos = 0; + xPos = 0; + if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 1) { + xPos = statData[i][j].xPosLeft + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 2) { + xPos = statData[i][j].xPosLeft + barWidth / 2 + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 3) { + xPos = statData[i][j].xPosLeft+ barWidth + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } + if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 1) { + yPos = statData[i][j].yPosBottom - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 2) { + yPos = (statData[i][j].yPosTop + statData[i][j].yPosBottom)/2 - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 3) { + yPos = statData[i][j].yPosTop - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } + if(yPos>msr.topNotUsableSize) { + ctx.translate(xPos, yPos); + ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,j,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,j,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,j,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),true); + } + ctx.restore(); + } + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"StackedBar"); + }; + + function drawScale() { + //X axis line + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY); + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY); + ctx.stroke(); + ctx.setLineDash([]); + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var i = 0; i < data.labels.length; i++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + //Check i isnt 0, so we dont go over the Y axis twice. + if (config.scaleShowGridLines && i > 0 && i % config.scaleXGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + } else { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY); + } + ctx.stroke(); + } + ctx.setLineDash([]); + + //Y axis + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineTo(yAxisPosX, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale.steps; j++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY - ((j + 1) * scaleHop)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + if (config.scaleShowGridLines && (j+1) % config.scaleYGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY - ((j + 1) * scaleHop)); + } else { + ctx.lineTo(yAxisPosX, xAxisPosY - ((j + 1) * scaleHop)); + } + ctx.stroke(); + } + ctx.setLineDash([]); + }; + + function drawLabels() { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + //X axis labels + if (config.xAxisTop || config.xAxisBottom) { + ctx.textBaseline = "top"; + if (msr.rotateLabels > 90) { + ctx.save(); + ctx.textAlign = "left"; + } else if (msr.rotateLabels > 0) { + ctx.save(); + ctx.textAlign = "right"; + } else { + ctx.textAlign = "center"; + } + ctx.fillStyle = config.scaleFontColor; + if (config.xAxisBottom) { + for (var i = 0; i < data.labels.length; i++) { + ctx.save(); + if (msr.rotateLabels > 0) { + ctx.translate(yAxisPosX + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) + i * valueHop + (barWidth / 2) - msr.highestXLabel / 2, msr.xLabelPos); + ctx.rotate(-(msr.rotateLabels * (Math.PI / 180))); + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } else { + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), yAxisPosX + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) + i * valueHop + (barWidth / 2), msr.xLabelPos, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + ctx.restore(); + } + } + } + //Y axis + ctx.textAlign = "right"; + ctx.textBaseline = "middle"; + for (var j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale.steps; j++) { + if (config.scaleShowLabels) { + if (config.yAxisLeft) { + ctx.textAlign = "right"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX - (Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + if (config.yAxisRight) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + var minvl = new Array(data.datasets.length); + var maxvl = new Array(data.datasets.length); + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + var k = i; + var tempp = 0; + var tempn = 0; + if (!(typeof(data.datasets[0].data[j]) == 'undefined')) { + if(1 * data.datasets[0].data[j] > 0) { + tempp += 1 * data.datasets[0].data[j]; + if (tempp > upperValue) { + upperValue = tempp; + }; + if (tempp < lowerValue) { + lowerValue = tempp; + }; + } else { + tempn += 1 * data.datasets[0].data[j]; + if (tempn > upperValue) { + upperValue = tempn; + }; + if (tempn < lowerValue) { + lowerValue = tempn; + }; + } + } + while (k > 0) { //get max of stacked data + if (!(typeof(data.datasets[k].data[j]) == 'undefined')) { + if(1 * data.datasets[k].data[j] > 0) { + tempp += 1 * data.datasets[k].data[j]; + if (tempp > upperValue) { + upperValue = tempp; + }; + if (tempp < lowerValue) { + lowerValue = tempp; + }; + } else { + tempn += 1 * data.datasets[k].data[j]; + if (tempn > upperValue) { + upperValue = tempn; + }; + if (tempn < lowerValue) { + lowerValue = tempn; + }; + } + } + k--; + } + } + }; + if(typeof config.graphMin=="function")lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + labelHeight = (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + scaleHeight = msr.availableHeight; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + /** + * Reverse the data structure for horizontal charts + * - reverse labels and every array inside datasets + * @param {object} data datasets and labels for the chart + * @return return the reversed data + */ + function reverseData(data) { + data.labels = data.labels.reverse(); + for (var i = 0; i < data.datasets.length; i++) { + for (var key in data.datasets[i]) { + if (Array.isArray(data.datasets[i][key])) { + data.datasets[i][key] = data.datasets[i][key].reverse(); + } + } + } + return data; + }; + var HorizontalStackedBar = function(data, config, ctx) { + var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, valueHop, widestXLabel, xAxisLength, yAxisPosX, xAxisPosY, barWidth, rotateLabels = 0, + msr; + + if (config.reverseOrder && typeof ctx.reversed == "undefined") { + ctx.reversed=true; + data = reverseData(data); + } + + ctx.tpchart="HorizontalStackedBar"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + + config.logarithmic = false; + msr = setMeasures(data, config, ctx, height, width, "nihil", [""], true, true, true, true, true, "HorizontalStackedBar"); + valueBounds = getValueBounds(); + + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, true, true, true, true, "HorizontalStackedBar"); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + labels: [] + } + for (var i = 0; i <= calculatedScale.steps; i++) { + if (labelTemplateString) { + calculatedScale.labels.push(tmpl(labelTemplateString, { + value: fmtChartJS(config, 1 * ((scaleStartValue + (scaleStepWidth * i)).toFixed(getDecimalPlaces(scaleStepWidth))), config.fmtYLabel) + },config)); + } + } + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, true, true, true, true, "HorizontalStackedBar"); + } + msr.availableHeight = msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + msr.availableWidth = msr.availableWidth - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight); + scaleHop = Math.floor(msr.availableHeight / data.labels.length); + valueHop = Math.floor(msr.availableWidth / (calculatedScale.steps)); + if (valueHop == 0 || config.fullWidthGraph) valueHop = (msr.availableWidth / (calculatedScale.steps)); + msr.clrwidth = msr.clrwidth - (msr.availableWidth - (calculatedScale.steps * valueHop)); + msr.availableWidth = (calculatedScale.steps) * valueHop; + msr.availableHeight = (data.labels.length) * scaleHop; + yAxisPosX = msr.leftNotUsableSize + Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft); + xAxisPosY = msr.topNotUsableSize + msr.availableHeight + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + barWidth = (scaleHop - Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) * 2) - (Math.ceil(ctx.chartSpaceScale*config.barDatasetSpacing) * data.datasets.length - 1) - (Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2) - 1); + if(barWidth>=0 && barWidth<=1)barWidth=1; + if(barWidth<0 && barWidth>=-1)barWidth=-1; + drawLabels(); + zeroY= HorizontalCalculateOffset(0 , calculatedScale, scaleHop); + initPassVariableData_part2(statData,data,config,ctx,{ + yAxisPosX : yAxisPosX, + xAxisPosY : xAxisPosY, + barWidth : barWidth, + zeroY : zeroY, + scaleHop : scaleHop, + valueHop : valueHop, + calculatedScale : calculatedScale + }); + + animationLoop(config, drawScale, drawBars, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, yAxisPosX + msr.availableWidth / 2, xAxisPosY - msr.availableHeight / 2, yAxisPosX, xAxisPosY, data); + } else { + testRedraw(ctx,data,config); + } + function HorizontalCalculateOffset(val, calculatedScale, scaleHop) { + var outerValue = calculatedScale.steps * calculatedScale.stepValue; + var adjustedValue = val - calculatedScale.graphMin; + var scalingFactor = CapValue(adjustedValue / outerValue, 1, 0); + return (scaleHop * calculatedScale.steps) * scalingFactor; + }; + + function drawBars(animPc) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.barStrokeWidth); + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + var currentAnimPc = animationCorrection(animPc, data, config, i, j, 1).animVal; + if (currentAnimPc > 1) currentAnimPc = currentAnimPc - 1; + if ((typeof(data.datasets[i].data[j]) == 'undefined') || 1*data.datasets[i].data[j] == 0 ) continue; + var leftBar, rightBar; + if(config.animationByDataset) { + leftBar= statData[i][j].xPosLeft; + rightBar= statData[i][j].xPosRight; + rightBar=leftBar+currentAnimPc*(rightBar-leftBar); + } else { + leftBar=statData[statData[i][j].firstNotMissing][j].xPosLeft + currentAnimPc*(statData[i][j].xPosLeft-statData[statData[i][j].firstNotMissing][j].xPosLeft); + rightBar=statData[statData[i][j].firstNotMissing][j].xPosLeft + currentAnimPc*(statData[i][j].xPosRight-statData[statData[i][j].firstNotMissing][j].xPosLeft); + } + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc, xPosLeft : leftBar, yPosBottom : statData[i][j].yPosBottom, xPosRight : rightBar, yPosTop : statData[i][j].yPosBottom} ); + + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + + if(currentAnimPc !=0 && statData[i][j].xPosLeft!=statData[i][j].xPosRight ) { + ctx.beginPath(); + ctx.moveTo(leftBar, statData[i][j].yPosTop); + ctx.lineTo(rightBar, statData[i][j].yPosTop); + ctx.lineTo(rightBar, statData[i][j].yPosBottom); + ctx.lineTo(leftBar, statData[i][j].yPosBottom); + ctx.lineTo(leftBar, statData[i][j].yPosTop); + if (config.barShowStroke){ + ctx.setLineDash(lineStyleFn(setOptionValue(1,"STROKESTYLE",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + } + ctx.closePath(); + ctx.fill(); + } + } + } + if (animPc >= config.animationStopValue) { + var yPos = 0, + xPos = 0; + for (i = 0; i < data.datasets.length; i++) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if ((typeof(data.datasets[i].data[j]) == 'undefined')) continue; + if (setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["RECT", i ,j, statData]; + } + if(setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + ctx.save(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,j,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,j,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,j,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,j,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,j,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,j,{nullValue : true} ),statData[i][j],config); + ctx.beginPath(); + yPos = 0; + xPos = 0; + if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 1) { + xPos = statData[i][j].xPosLeft + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 2) { + xPos = statData[i][j].xPosLeft + (statData[i][j].xPosRight-statData[i][j].xPosLeft)/2 + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 3) { + xPos = statData[i][j].xPosRight + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } + if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 1) { + yPos = statData[i][j].yPosBottom - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 2) { + yPos = statData[i][j].yPosBottom - barWidth / 2 - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 3) { + yPos = statData[i][j].yPosTop - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } +// if(xPos<=msr.availableWidth+msr.leftNotUsableSize) { + ctx.translate(xPos, yPos); + ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,j,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,j,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,j,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),true); + ctx.restore(); +// } + } + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"HorizontalStackedBar"); + }; + + function drawScale() { + //X axis line + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY); + ctx.lineTo(yAxisPosX + msr.availableWidth, xAxisPosY); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var i = ((config.showYAxisMin) ? -1 : 0); i < calculatedScale.steps; i++) { + if (i >= 0) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + //Check i isnt 0, so we dont go over the Y axis twice. + if (config.scaleShowGridLines && i > 0 && i % config.scaleXGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + } else { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY); + } + ctx.stroke(); + } + ctx.setLineDash([]); + } + //Y axis + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineTo(yAxisPosX, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + ctx.stroke(); + ctx.setLineDash([]); + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var j = 0; j < data.labels.length; j++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY - ((j + 1) * scaleHop)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + if (config.scaleShowGridLines && (j+1) % config.scaleYGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + msr.availableWidth, xAxisPosY - ((j + 1) * scaleHop)); + } else { + ctx.lineTo(yAxisPosX, xAxisPosY - ((j + 1) * scaleHop)); + } + ctx.stroke(); + } + ctx.setLineDash([]); + }; + + function drawLabels() { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + //X axis line + if (config.scaleShowLabels && (config.xAxisTop || config.xAxisBottom)) { + ctx.textBaseline = "top"; + if (msr.rotateLabels > 90) { + ctx.save(); + ctx.textAlign = "left"; + } else if (msr.rotateLabels > 0) { + ctx.save(); + ctx.textAlign = "right"; + } else { + ctx.textAlign = "center"; + } + ctx.fillStyle = config.scaleFontColor; + if (config.xAxisBottom) { + for (var i = ((config.showYAxisMin) ? -1 : 0); i < calculatedScale.steps; i++) { + ctx.save(); + if (msr.rotateLabels > 0) { + ctx.translate(yAxisPosX + (i + 1) * valueHop - msr.highestXLabel / 2, msr.xLabelPos); + ctx.rotate(-(msr.rotateLabels * (Math.PI / 180))); + ctx.fillTextMultiLine(calculatedScale.labels[i + 1], 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } else { + ctx.fillTextMultiLine(calculatedScale.labels[i + 1], yAxisPosX + ((i + 1) * valueHop), msr.xLabelPos, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + ctx.restore(); + } + } + } + //Y axis + ctx.textAlign = "right"; + ctx.textBaseline = "middle"; + for (var j = 0; j < data.labels.length; j++) { + if (config.yAxisLeft) { + ctx.textAlign = "right"; + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[j], config.fmtXLabel), yAxisPosX - (Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop) + barWidth / 2, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + if (config.yAxisRight) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[j], config.fmtXLabel), yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop) + barWidth / 2, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + var minvl = new Array(data.datasets.length); + var maxvl = new Array(data.datasets.length); + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + var k = i; + var tempp = 0; + var tempn = 0; + if (!(typeof(data.datasets[0].data[j]) == 'undefined')) { + if(1 * data.datasets[0].data[j] > 0) { + tempp += 1 * data.datasets[0].data[j]; + if (tempp > upperValue) { + upperValue = tempp; + }; + if (tempp < lowerValue) { + lowerValue = tempp; + }; + } else { + tempn += 1 * data.datasets[0].data[j]; + if (tempn > upperValue) { + upperValue = tempn; + }; + if (tempn < lowerValue) { + lowerValue = tempn; + }; + } + } + while (k > 0) { //get max of stacked data + if (!(typeof(data.datasets[k].data[j]) == 'undefined')) { + if(1 * data.datasets[k].data[j] > 0) { + tempp += 1 * data.datasets[k].data[j]; + if (tempp > upperValue) { + upperValue = tempp; + }; + if (tempp < lowerValue) { + lowerValue = tempp; + }; + } else { + tempn += 1 * data.datasets[k].data[j]; + if (tempn > upperValue) { + upperValue = tempn; + }; + if (tempn < lowerValue) { + lowerValue = tempn; + }; + } + } + k--; + } + } + }; + if(typeof config.graphMin=="function")lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + labelHeight = (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + scaleHeight = msr.availableHeight; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxSteps: maxSteps, + minSteps: minSteps + }; + + + }; + }; + var Bar = function(data, config, ctx) { + var maxSize, scaleHop, scaleHop2, calculatedScale, calculatedScale2, labelHeight, scaleHeight, valueBounds, labelTemplateString, labelTemplateString2, valueHop, widestXLabel, xAxisLength, yAxisPosX, xAxisPosY, barWidth, rotateLabels = 0, + msr; + + ctx.tpchart="Bar"; + if (!init_and_start(ctx,data,config)) return; + var statData=initPassVariableData_part1(data,config,ctx); + + var nrOfBars = data.datasets.length; + for (var i = 0; i < data.datasets.length; i++) { + if (data.datasets[i].type == "Line") { statData[i][0].tpchart="Line";nrOfBars--;} + else statData[i][0].tpchart="Bar"; + } + + + // change the order (at first all bars then the lines) (form of BubbleSort) + var bufferDataset, l = 0; + + + msr = setMeasures(data, config, ctx, height, width, "nihil", [""], true, false, true, true, true, "Bar"); + valueBounds = getValueBounds(); + if(valueBounds.minValue<=0)config.logarithmic=false; + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + + // true or fuzzy (error for negativ values (included 0)) + if (config.logarithmic !== false) { + if (valueBounds.minValue <= 0) { + config.logarithmic = false; + } + } + if (config.logarithmic2 !== false) { + if (valueBounds.minValue2 <= 0) { + config.logarithmic2 = false; + } + } + // Check if logarithmic is meanigful + var OrderOfMagnitude = calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.maxValue) + 1)) - calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.minValue))); + if ((config.logarithmic == 'fuzzy' && OrderOfMagnitude < 4) || config.scaleOverride) { + config.logarithmic = false; + } + // Check if logarithmic is meanigful + var OrderOfMagnitude2 = calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.maxValue2) + 1)) - calculateOrderOfMagnitude(Math.pow(10, calculateOrderOfMagnitude(valueBounds.minValue2))); + if ((config.logarithmic2 == 'fuzzy' && OrderOfMagnitude2 < 4) || config.scaleOverride2) { + config.logarithmic2 = false; + } + + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + labelTemplateString2 = (config.scaleShowLabels2) ? config.scaleLabel2 : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + graphMax: scaleStartValue + scaleSteps * scaleStepWidth, + labels: [] + } + populateLabels(1, config, labelTemplateString, calculatedScale.labels, calculatedScale.steps, scaleStartValue, calculatedScale.graphMax, scaleStepWidth); + } + if (valueBounds.dbAxis) { + if (!config.scaleOverride2) { + calculatedScale2 = calculateScale(2, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue2, valueBounds.minValue2, labelTemplateString); + } else { + var scaleStartValue2= setOptionValue(1,"SCALESTARTVALUE2",ctx,data,statData,undefined,config.scaleStartValue2,-1,-1,{nullValue : true} ); + var scaleSteps2 =setOptionValue(1,"SCALESTEPS2",ctx,data,statData,undefined,config.scaleSteps2,-1,-1,{nullValue : true} ); + var scaleStepWidth2 = setOptionValue(1,"SCALESTEPWIDTH2",ctx,data,statData,undefined,config.scaleStepWidth2,-1,-1,{nullValue : true} ); + + calculatedScale2 = { + steps: scaleSteps2, + stepValue: scaleStepWidth2, + graphMin: scaleStartValue2, + graphMax: scaleStartValue2 + scaleSteps2 * scaleStepWidth2, + labels: [] + } + populateLabels(2, config, labelTemplateString2, calculatedScale2.labels, calculatedScale2.steps, scaleStartValue2, calculatedScale2.graphMax, scaleStepWidth2); + } + } else { + calculatedScale2 = { + steps: 0, + stepValue: 0, + graphMin: 0, + graphMax: 0, + labels: null + } + } + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, calculatedScale2.labels, true, false, true, true, true, "Bar"); + + var prevHeight=msr.availableHeight; + + msr.availableHeight = msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + msr.availableWidth = msr.availableWidth - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight); + scaleHop = Math.floor(msr.availableHeight / calculatedScale.steps); + scaleHop2 = Math.floor(msr.availableHeight / calculatedScale2.steps); + valueHop = Math.floor(msr.availableWidth / (data.labels.length)); + if (valueHop == 0 || config.fullWidthGraph) valueHop = (msr.availableWidth / data.labels.length); + msr.clrwidth = msr.clrwidth - (msr.availableWidth - ((data.labels.length) * valueHop)); + msr.availableWidth = (data.labels.length) * valueHop; + msr.availableHeight = (calculatedScale.steps) * scaleHop; + msr.xLabelPos+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + msr.clrheight+=(Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop) - (prevHeight-msr.availableHeight)); + + yAxisPosX = msr.leftNotUsableSize + Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft); + xAxisPosY = msr.topNotUsableSize + msr.availableHeight + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + barWidth = (valueHop - Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) * 2) - (Math.ceil(ctx.chartSpaceScale*config.barDatasetSpacing) * nrOfBars - 1) - ((Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2) * nrOfBars - 1)) / nrOfBars; + if(barWidth>=0 && barWidth<=1)barWidth=1; + if(barWidth<0 && barWidth>=-1)barWidth=-1; + var zeroY = 0; + var zeroY2 = 0; + if (valueBounds.minValue < 0) { + zeroY = calculateOffset(config.logarithmic, 0, calculatedScale, scaleHop); + } + if (valueBounds.minValue2 < 0) { + zeroY2 = calculateOffset(config.logarithmic2, 0, calculatedScale2, scaleHop2); + } + initPassVariableData_part2(statData,data,config,ctx,{ + msr: msr, + yAxisPosX : yAxisPosX, + xAxisPosY : xAxisPosY, + valueHop : valueHop, + barWidth : barWidth, + zeroY : zeroY, + zeroY2 : zeroY2, + calculatedScale : calculatedScale, + calculatedScale2 : calculatedScale2, + scaleHop : scaleHop, + scaleHop2 : scaleHop2 + }); + drawLabels(); + animationLoop(config, drawScale, drawBars, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, yAxisPosX + msr.availableWidth / 2, xAxisPosY - msr.availableHeight / 2, yAxisPosX, xAxisPosY, data); + } else { + testRedraw(ctx,data,config); + } + + function drawBars(animPc) { + var t1, t2, t3; + + + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.barStrokeWidth); + for (var i = 0; i < data.datasets.length; i++) { + if(data.datasets[i].type=="Line") continue; + for (var j = 0; j < data.datasets[i].data.length; j++) { + if (!(typeof(data.datasets[i].data[j]) == 'undefined')) { + var currentAnimPc = animationCorrection(animPc, data, config, i, j, 1).animVal; + if (currentAnimPc > 1) currentAnimPc = currentAnimPc - 1; + var barHeight = currentAnimPc * (statData[i][j].barHeight) + (Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc, xPosLeft : statData[i][j].xPosLeft, yPosBottom : statData[i][j].yPosBottom, xPosRight : statData[i][j].xPosLeft+barWidth, yPosTop : statData[i][j].yPosBottom-barHeight} ); + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + roundRect(ctx, statData[i][j].xPosLeft, statData[i][j].yPosBottom, barWidth, barHeight, config.barShowStroke, config.barBorderRadius,i,j,(data.datasets[i].data[j] < 0 ? -1 : 1)); + } + } + } + drawLinesDataset(animPc, data, config, ctx, statData,{xAxisPosY : xAxisPosY,yAxisPosX : yAxisPosX, valueHop : valueHop, nbValueHop : data.labels.length }); + + if (animPc >= config.animationStopValue) { + + for (i = 0; i < data.datasets.length; i++) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; + if (data.datasets[i].type == "Line") continue; + if(setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["RECT", i , j, statData]; + if(setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + ctx.save(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,j,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,j,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,j,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,j,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,j,{nullValue : true} ); + t1 = statData[i][j].yPosBottom; + t2 = statData[i][j].yPosTop; + ctx.beginPath(); + var yPos = 0, + xPos = 0; + if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 1) { + xPos = statData[i][j].xPosLeft + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 2) { + xPos = statData[i][j].xPosLeft + barWidth / 2 + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 3) { + xPos = statData[i][j].xPosLeft + barWidth + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } + if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 1) { + yPos = statData[i][j].yPosBottom - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 2) { + yPos = (statData[i][j].yPosBottom+statData[i][j].yPosTop)/2 - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 3) { + yPos = statData[i][j].yPosTop - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } + ctx.translate(xPos, yPos); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,j,{nullValue : true} ), statData[i][j],config); + ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,j,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,j,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,j,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),true); + ctx.restore(); + } + } + } + } + if (animPc >= 1 && typeof drawMath == "function") { + drawMath(ctx, config, data, msr, { + xAxisPosY: xAxisPosY, + yAxisPosX: yAxisPosX, + valueHop: valueHop, + scaleHop: scaleHop, + zeroY: zeroY, + calculatedScale: calculatedScale, + calculateOffset: calculateOffset, + barWidth: barWidth + }); + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"Bar"); + }; + + function roundRect(ctx, x, y, w, h, stroke, radius,i,j,fact) { + ctx.beginPath(); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"STROKESTYLE",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.moveTo(x + radius, y); + ctx.lineTo(x + w - radius, y); + ctx.quadraticCurveTo(x + w, y, x + w, y); + ctx.lineTo(x + w, y - h + fact*radius); + ctx.quadraticCurveTo(x + w, y - h, x + w - radius, y - h); + ctx.lineTo(x + radius, y - h); + ctx.quadraticCurveTo(x, y - h, x, y - h + fact*radius); + ctx.lineTo(x, y); + ctx.quadraticCurveTo(x, y, x + radius, y); + if (stroke) ctx.stroke(); + ctx.closePath(); + ctx.fill(); + ctx.setLineDash([]); + }; + + function drawScale() { + //X axis line + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY); + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var i = 0; i < data.labels.length; i++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + //Check i isnt 0, so we dont go over the Y axis twice. + if (config.scaleShowGridLines && i > 0 && i % config.scaleXGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + } else { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY); + } + ctx.stroke(); + } + ctx.setLineDash([]); + + //Y axis + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineTo(yAxisPosX, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var j = 0; j < calculatedScale.steps; j++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY - ((j + 1) * scaleHop)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + if (config.scaleShowGridLines && (j+1) % config.scaleYGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY - ((j + 1) * scaleHop)); + } else { + ctx.lineTo(yAxisPosX, xAxisPosY - ((j + 1) * scaleHop)); + } + ctx.stroke(); + } + ctx.setLineDash([]); + }; + + function drawLabels() { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + //X axis line + if (config.xAxisTop || config.xAxisBottom) { + ctx.textBaseline = "top"; + if (msr.rotateLabels > 90) { + ctx.save(); + ctx.textAlign = "left"; + } else if (msr.rotateLabels > 0) { + ctx.save(); + ctx.textAlign = "right"; + } else { + ctx.textAlign = "center"; + } + ctx.fillStyle = config.scaleFontColor; + if (config.xAxisBottom) { + for (var i = 0; i < data.labels.length; i++) { + ctx.save(); + if (msr.rotateLabels > 0) { + + ctx.translate(yAxisPosX + i * valueHop + (valueHop / 2) - msr.highestXLabel / 2, msr.xLabelPos); + ctx.rotate(-(msr.rotateLabels * (Math.PI / 180))); + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } else { + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), yAxisPosX + i * valueHop + (valueHop / 2), msr.xLabelPos, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + ctx.restore(); + } + } + } + //Y axis + ctx.textAlign = "right"; + ctx.textBaseline = "middle"; + for (var j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale.steps; j++) { + if (config.scaleShowLabels) { + if (config.yAxisLeft) { + ctx.textAlign = "right"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX - (Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + if (config.yAxisRight && !valueBounds.dbAxis) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(calculatedScale.labels[j + 1], yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + } + if (config.yAxisRight && valueBounds.dbAxis) { + for (j = ((config.showYAxisMin) ? -1 : 0); j < calculatedScale2.steps; j++) { + if (config.scaleShowLabels) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(calculatedScale2.labels[j + 1], yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - ((j + 1) * scaleHop2), ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + var upperValue2 = -Number.MAX_VALUE; + var lowerValue2 = Number.MAX_VALUE; + var secondAxis = false; + var firstAxis = false; + + for (var i = 0; i < data.datasets.length; i++) { + var mathFctName = data.datasets[i].drawMathDeviation; + var mathValueHeight = 0; + if (typeof eval(mathFctName) == "function") { + var parameter = { + data: data, + datasetNr: i + }; + mathValueHeight = window[mathFctName](parameter); + } + for (var j = 0; j < data.datasets[i].data.length; j++) { + if(typeof data.datasets[i].data[j]=="undefined")continue; + if (data.datasets[i].axis == 2) { + secondAxis = true; + if (1 * data.datasets[i].data[j] + mathValueHeight > upperValue2) { + upperValue2 = 1 * data.datasets[i].data[j] + mathValueHeight; + }; + if (1 * data.datasets[i].data[j] - mathValueHeight < lowerValue2) { + lowerValue2 = 1 * data.datasets[i].data[j] - mathValueHeight; + }; + } else { + firstAxis=true; + if (1 * data.datasets[i].data[j] + mathValueHeight > upperValue) { + upperValue = 1 * data.datasets[i].data[j] + mathValueHeight; + }; + if (1 * data.datasets[i].data[j] - mathValueHeight < lowerValue) { + lowerValue = 1 * data.datasets[i].data[j] - mathValueHeight; + }; + } + } + }; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + if(typeof config.graphMin=="function")lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + + if (secondAxis) { + if(upperValue2<lowerValue2){upperValue2=0;lowerValue2=0;} + if (Math.abs(upperValue2 - lowerValue2) < config.zeroValue) { + if(Math.abs(upperValue2)< config.zeroValue) upperValue2 = .9; + if(upperValue2>0) { + upperValue2=upperValue2*1.1; + lowerValue2=lowerValue2*0.9; + } else { + upperValue2=upperValue2*0.9; + lowerValue2=lowerValue2*1.1; + } + } + if(typeof config.graphMin2=="function")lowerValue2= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin2,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin2)) lowerValue2 = config.graphMin2; + if(typeof config.graphMax2=="function") upperValue2= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax2,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax2)) upperValue2 = config.graphMax2; + } + if (!firstAxis && secondAxis) { + upperValue = upperValue2; + lowerValue = lowerValue2; + } + + labelHeight = (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + scaleHeight = msr.availableHeight; + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxValue2: upperValue2, + minValue2: lowerValue2, + dbAxis: secondAxis, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + + var HorizontalBar = function(data, config, ctx) { + var maxSize, scaleHop, calculatedScale, labelHeight, scaleHeight, valueBounds, labelTemplateString, valueHop, widestXLabel, xAxisLength, yAxisPosX, xAxisPosY, barWidth, rotateLabels = 0, + msr; + ctx.tpchart="HorizontalBar"; + if (!init_and_start(ctx,data,config)) return; + + if (config.reverseOrder && typeof ctx.reversed == "undefined") { + ctx.reversed=true; + data = reverseData(data); + } + + var statData=initPassVariableData_part1(data,config,ctx); + + msr = setMeasures(data, config, ctx, height, width, "nihil", [""], true, true, true, true, true, "StackedBar"); + valueBounds = getValueBounds(); + if(valueBounds.minValue<=0)config.logarithmic=false; + if(valueBounds.maxSteps>0 && valueBounds.minSteps>0) { + if (config.logarithmic !== false) { + if (valueBounds.minValue <= 0) { + config.logarithmic = false; + } + } + //Check and set the scale + labelTemplateString = (config.scaleShowLabels) ? config.scaleLabel : ""; + if (!config.scaleOverride) { + calculatedScale = calculateScale(1, config, valueBounds.maxSteps, valueBounds.minSteps, valueBounds.maxValue, valueBounds.minValue, labelTemplateString); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, true, true, true, true, "HorizontalBar"); + } else { + var scaleStartValue= setOptionValue(1,"SCALESTARTVALUE",ctx,data,statData,undefined,config.scaleStartValue,-1,-1,{nullValue : true} ); + var scaleSteps =setOptionValue(1,"SCALESTEPS",ctx,data,statData,undefined,config.scaleSteps,-1,-1,{nullValue : true} ); + var scaleStepWidth = setOptionValue(1,"SCALESTEPWIDTH",ctx,data,statData,undefined,config.scaleStepWidth,-1,-1,{nullValue : true} ); + + calculatedScale = { + steps: scaleSteps, + stepValue: scaleStepWidth, + graphMin: scaleStartValue, + graphMax: scaleStartValue + scaleSteps * scaleStepWidth, + labels: [] + } + populateLabels(1, config, labelTemplateString, calculatedScale.labels, calculatedScale.steps, scaleStartValue, calculatedScale.graphMax, scaleStepWidth); + msr = setMeasures(data, config, ctx, height, width, calculatedScale.labels, null, true, true, true, true, true, "HorizontalBar"); + } + msr.availableHeight = msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + msr.availableWidth = msr.availableWidth - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) - Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight); + scaleHop = Math.floor(msr.availableHeight / data.labels.length); + valueHop = Math.floor(msr.availableWidth / (calculatedScale.steps)); + if (valueHop == 0 || config.fullWidthGraph) valueHop = (msr.availableWidth / calculatedScale.steps); + msr.clrwidth = msr.clrwidth - (msr.availableWidth - (calculatedScale.steps * valueHop)); + msr.availableWidth = (calculatedScale.steps) * valueHop; + msr.availableHeight = (data.labels.length) * scaleHop; + yAxisPosX = msr.leftNotUsableSize + Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft); + xAxisPosY = msr.topNotUsableSize + msr.availableHeight + Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop); + barWidth = (scaleHop - Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) * 2) - (Math.ceil(ctx.chartSpaceScale*config.barDatasetSpacing) * data.datasets.length - 1) - ((Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2) * data.datasets.length - 1)) / data.datasets.length; + if(barWidth>=0 && barWidth<=1)barWidth=1; + if(barWidth<0 && barWidth>=-1)barWidth=-1; + var zeroY = 0; + if (valueBounds.minValue < 0) { + zeroY = calculateOffset(config.logarithmic, 0, calculatedScale, valueHop); + } + drawLabels(); + initPassVariableData_part2(statData,data,config,ctx,{ + yAxisPosX : yAxisPosX, + xAxisPosY : xAxisPosY, + barWidth : barWidth, + zeroY : zeroY, + scaleHop : scaleHop, + valueHop : valueHop, + calculatedScale : calculatedScale + }); + animationLoop(config, drawScale, drawBars, ctx, msr.clrx, msr.clry, msr.clrwidth, msr.clrheight, yAxisPosX + msr.availableWidth / 2, xAxisPosY - msr.availableHeight / 2, yAxisPosX, xAxisPosY, data); + } else { + testRedraw(ctx,data,config); + } + + function drawBars(animPc) { + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.barStrokeWidth); + var currentAnimPc = animationCorrection(animPc, data, config, i, j, 1).animVal; + if (currentAnimPc > 1) currentAnimPc = currentAnimPc - 1; + var barHeight = currentAnimPc * statData[i][j].barWidth + (Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc, xPosLeft : statData[i][j].xPosLeft, yPosBottom : statData[i][j].yPosBottom, xPosRight : statData[i][j].xPosLeft+barHeight, yPosTop : statData[i][j].yPosBottom} ); + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + + if (!(typeof(data.datasets[i].data[j]) == 'undefined')) { + roundRect(ctx, statData[i][j].yPosTop, statData[i][j].xPosLeft , barWidth, barHeight, config.barShowStroke, config.barBorderRadius, 0,i,j,(data.datasets[i].data[j] < 0 ? -1 : 1)); + } + } + } + if (animPc >= config.animationStopValue) { + for (i = 0; i < data.datasets.length; i++) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; + if(setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["RECT", i ,j ,statData]; + } + if(setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + ctx.save(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,j,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,j,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,j,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,j,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,j,{nullValue : true} ); + ctx.beginPath(); + var yPos = 0, + xPos = 0; + if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 1) { + yPos = statData[i][j].yPosTop - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ) + barWidth; + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 2) { + yPos = statData[i][j].yPosTop + barWidth / 2 - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAYPOSITION",ctx,data,statData,undefined,config.inGraphDataYPosition,i,j,{nullValue : true} ) == 3) { + yPos = statData[i][j].yPosTop - setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + } + if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 1) { + xPos = statData[i][j].xPosLeft + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 2) { + xPos = (statData[i][j].xPosLeft+statData[i][j].xPosRight)/2 + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } else if (setOptionValue(1,"INGRAPHDATAXPOSITION",ctx,data,statData,undefined,config.inGraphDataXPosition,i,j,{nullValue : true} ) == 3) { + xPos = statData[i][j].xPosRight + setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ); + } + ctx.translate(xPos, yPos); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,j,{nullValue : true} ), statData[i][j],config); + ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,j,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,j,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,j,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),true); + ctx.restore(); + } + } + } + } + if(msr.legendMsr.dispLegend)drawLegend(msr.legendMsr,data,config,ctx,"HorizontalBar"); + }; + + function roundRect(ctx, x, y, w, h, stroke, radius, zeroY,i,j,fact) { + ctx.beginPath(); + ctx.moveTo(y + zeroY, x + radius); + ctx.lineTo(y + zeroY, x + w - radius); + ctx.quadraticCurveTo(y + zeroY, x + w, y + zeroY, x + w); + ctx.lineTo(y + h - fact*radius, x + w); + ctx.quadraticCurveTo(y + h, x + w, y + h, x + w - radius); + ctx.lineTo(y + h, x + radius); + ctx.quadraticCurveTo(y + h, x, y + h - fact*radius, x); + ctx.lineTo(y + zeroY, x); + ctx.quadraticCurveTo(y + zeroY, x, y + zeroY, x + radius); + if (stroke) { + ctx.setLineDash(lineStyleFn(setOptionValue(1,"STROKESTYLE",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + }; + ctx.closePath(); + ctx.fill(); + }; + + function drawScale() { + //X axis line + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY); + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY); + ctx.stroke(); + ctx.setLineDash([]); + + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var i = ((config.showYAxisMin) ? -1 : 0); i < calculatedScale.steps; i++) { + if (i >= 0) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX + i * valueHop, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + //Check i isnt 0, so we dont go over the Y axis twice. + if (config.scaleShowGridLines && i > 0 && i % config.scaleXGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + } else { + ctx.lineTo(yAxisPosX + i * valueHop, xAxisPosY); + } + ctx.stroke(); + } + + } + ctx.setLineDash([]); + //Y axis + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleLineWidth); + ctx.strokeStyle = config.scaleLineColor; + ctx.setLineDash(lineStyleFn(config.scaleLineStyle)); + ctx.beginPath(); + ctx.moveTo(yAxisPosX, xAxisPosY + Math.ceil(ctx.chartLineScale*config.scaleTickSizeBottom)); + ctx.lineTo(yAxisPosX, xAxisPosY - msr.availableHeight - Math.ceil(ctx.chartLineScale*config.scaleTickSizeTop)); + ctx.stroke(); + ctx.setLineDash([]); + ctx.setLineDash(lineStyleFn(config.scaleGridLineStyle)); + for (var j = 0; j < data.labels.length; j++) { + ctx.beginPath(); + ctx.moveTo(yAxisPosX - Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft), xAxisPosY - ((j + 1) * scaleHop)); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.scaleGridLineWidth); + ctx.strokeStyle = config.scaleGridLineColor; + if (config.scaleShowGridLines && (j+1) % config.scaleYGridLinesStep == 0) { + ctx.lineTo(yAxisPosX + msr.availableWidth + Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight), xAxisPosY - ((j + 1) * scaleHop)); + } else { + ctx.lineTo(yAxisPosX, xAxisPosY - ((j + 1) * scaleHop)); + } + ctx.stroke(); + } + ctx.setLineDash([]); + }; + + function drawLabels() { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + //X axis line + if (config.scaleShowLabels && (config.xAxisTop || config.xAxisBottom)) { + ctx.textBaseline = "top"; + if (msr.rotateLabels > 90) { + ctx.save(); + ctx.textAlign = "left"; + } else if (msr.rotateLabels > 0) { + ctx.save(); + ctx.textAlign = "right"; + } else { + ctx.textAlign = "center"; + } + ctx.fillStyle = config.scaleFontColor; + if (config.xAxisBottom) { + for (var i = ((config.showYAxisMin) ? -1 : 0); i < calculatedScale.steps; i++) { + ctx.save(); + if (msr.rotateLabels > 0) { + ctx.translate(yAxisPosX + (i + 1) * valueHop - msr.highestXLabel / 2, msr.xLabelPos); + ctx.rotate(-(msr.rotateLabels * (Math.PI / 180))); + ctx.fillTextMultiLine(calculatedScale.labels[i + 1], 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } else { + ctx.fillTextMultiLine(calculatedScale.labels[i + 1], yAxisPosX + (i + 1) * valueHop, msr.xLabelPos, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + ctx.restore(); + } + } + } + //Y axis + ctx.textAlign = "right"; + ctx.textBaseline = "middle"; + for (var j = 0; j < data.labels.length; j++) { + if (config.yAxisLeft) { + ctx.textAlign = "right"; + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[j], config.fmtXLabel), yAxisPosX - (Math.ceil(ctx.chartLineScale*config.scaleTickSizeLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - (j * scaleHop) - scaleHop / 2, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + if (config.yAxisRight) { + ctx.textAlign = "left"; + ctx.fillTextMultiLine(fmtChartJS(config, data.labels[j], config.fmtXLabel), yAxisPosX + msr.availableWidth + (Math.ceil(ctx.chartLineScale*config.scaleTickSizeRight) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight)), xAxisPosY - (j * scaleHop) - scaleHop / 2, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.scaleFontSize)),true); + } + } + }; + + function getValueBounds() { + var upperValue = -Number.MAX_VALUE; + var lowerValue = Number.MAX_VALUE; + for (var i = 0; i < data.datasets.length; i++) { + for (var j = 0; j < data.datasets[i].data.length; j++) { + if(typeof data.datasets[i].data[j]=="undefined")continue; + if (1 * data.datasets[i].data[j] > upperValue) { + upperValue = 1 * data.datasets[i].data[j] + }; + if (1 * data.datasets[i].data[j] < lowerValue) { + lowerValue = 1 * data.datasets[i].data[j] + }; + } + }; + if(upperValue<lowerValue){upperValue=0;lowerValue=0;} + if (Math.abs(upperValue - lowerValue) < config.zeroValue) { + if(Math.abs(upperValue)< config.zeroValue) upperValue = .9; + if(upperValue>0) { + upperValue=upperValue*1.1; + lowerValue=lowerValue*0.9; + } else { + upperValue=upperValue*0.9; + lowerValue=lowerValue*1.1; + } + } + // AJOUT CHANGEMENT + if(typeof config.graphMin=="function")lowerValue= setOptionValue(1,"GRAPHMIN",ctx,data,statData,undefined,config.graphMin,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMin)) lowerValue = config.graphMin; + if(typeof config.graphMax=="function") upperValue= setOptionValue(1,"GRAPHMAX",ctx,data,statData,undefined,config.graphMax,-1,-1,{nullValue : true}) + else if (!isNaN(config.graphMax)) upperValue = config.graphMax; + + labelHeight = (Math.ceil(ctx.chartTextScale*config.scaleFontSize)); + scaleHeight = msr.availableHeight; + + var maxSteps = Math.floor((scaleHeight / (labelHeight * 0.66))); + var minSteps = Math.floor((scaleHeight / labelHeight * 0.5)); + return { + maxValue: upperValue, + minValue: lowerValue, + maxSteps: maxSteps, + minSteps: minSteps + }; + }; + }; + + function calculateOffset(logarithmic, val, calculatedScale, scaleHop) { + if (!logarithmic) { // no logarithmic scale + var outerValue = calculatedScale.steps * calculatedScale.stepValue; + var adjustedValue = val - calculatedScale.graphMin; + var scalingFactor = CapValue(adjustedValue / outerValue, 1, 0); + return (scaleHop * calculatedScale.steps) * scalingFactor; + } else { // logarithmic scale +// return CapValue(log10(val) * scaleHop - calculateOrderOfMagnitude(calculatedScale.graphMin) * scaleHop, undefined, 0); + return CapValue(log10(val) * scaleHop - log10(calculatedScale.graphMin) * scaleHop, undefined, 0); + } + }; + + function animationLoop(config, drawScale, drawData, ctx, clrx, clry, clrwidth, clrheight, midPosX, midPosY, borderX, borderY, data) { + var cntiter = 0; + var animationCount = 1; + var multAnim = 1; + if (config.animationStartValue < 0 || config.animationStartValue > 1) config.animation.StartValue = 0; + if (config.animationStopValue < 0 || config.animationStopValue > 1) config.animation.StopValue = 1; + if (config.animationStopValue < config.animationStartValue) config.animationStopValue = config.animationStartValue; + if (isIE() < 9 && isIE() != false) config.animation = false; + var animFrameAmount = (config.animation) ? 1 / CapValue(config.animationSteps, Number.MAX_VALUE, 1) : 1, + easingFunction = animationOptions[config.animationEasing], + percentAnimComplete = (config.animation) ? 0 : 1; + if (config.animation && config.animationStartValue > 0 && config.animationStartValue <= 1) { + while (percentAnimComplete < config.animationStartValue) { + cntiter++; + percentAnimComplete += animFrameAmount; + } + } + var beginAnim = cntiter; + var beginAnimPct = percentAnimComplete; + if (typeof drawScale !== "function") drawScale = function() {}; + if (config.clearRect) requestAnimFrame(animLoop); + else animLoop(); + + function animateFrame() { + var easeAdjustedAnimationPercent = (config.animation) ? CapValue(easingFunction(percentAnimComplete), null, 0) : 1; + if (1 * cntiter >= 1 * CapValue(config.animationSteps, Number.MAX_VALUE, 1) || config.animation == false || ctx.firstPass==3 || ctx.firstPass==4 || ctx.firstPass==8 || ctx.firstPass==9) easeAdjustedAnimationPercent = 1; + else if (easeAdjustedAnimationPercent >= 1) easeAdjustedAnimationPercent = 0.9999; + if (config.animation && !(isIE() < 9 && isIE() != false) && config.clearRect) ctx.clearRect(clrx, clry, clrwidth, clrheight); + dispCrossImage(ctx, config, midPosX, midPosY, borderX, borderY, false, data, easeAdjustedAnimationPercent, cntiter); + dispCrossText(ctx, config, midPosX, midPosY, borderX, borderY, false, data, easeAdjustedAnimationPercent, cntiter); + if (config.scaleOverlay) { + drawData(easeAdjustedAnimationPercent); + drawScale(); + } else { + drawScale(); + drawData(easeAdjustedAnimationPercent); + } + dispCrossImage(ctx, config, midPosX, midPosY, borderX, borderY, true, data, easeAdjustedAnimationPercent, cntiter); + dispCrossText(ctx, config, midPosX, midPosY, borderX, borderY, true, data, easeAdjustedAnimationPercent, cntiter); + }; + + function animLoop() { + //We need to check if the animation is incomplete (less than 1), or complete (1). + cntiter += multAnim; + percentAnimComplete += multAnim * animFrameAmount; + if (cntiter == config.animationSteps || config.animation == false || ctx.firstPass==3 || ctx.firstPass==4 || ctx.firstPass==8 || ctx.firstPass==9) percentAnimComplete = 1; + else if (percentAnimComplete >= 1) percentAnimComplete = 0.999; + animateFrame(); + //Stop the loop continuing forever + if (multAnim == -1 && cntiter <= beginAnim) { + if (typeof config.onAnimationComplete == "function" && ctx.runanimationcompletefunction==true) config.onAnimationComplete(ctx, config, data, 0, animationCount + 1); + multAnim = 1; + requestAnimFrame(animLoop); + } else if (percentAnimComplete < config.animationStopValue) { + requestAnimFrame(animLoop); + } else { + if ((animationCount < config.animationCount || config.animationCount == 0) && (ctx.firstPass ==1 || ctx.firstPass!=2)) { + animationCount++; + if (config.animationBackward && multAnim == 1) { + percentAnimComplete -= animFrameAmount; + multAnim = -1; + } else { + multAnim = 1; + cntiter = beginAnim - 1; + percentAnimComplete = beginAnimPct - animFrameAmount; + } + window.setTimeout(animLoop, config.animationPauseTime*1000); + } else { + if(!testRedraw(ctx,data,config) ) { + if (typeof config.onAnimationComplete == "function" && ctx.runanimationcompletefunction==true) { + config.onAnimationComplete(ctx, config, data, 1, animationCount + 1); + ctx.runanimationcompletefunction=false; + } + } + } + + } + }; + }; + //Declare global functions to be called within this namespace here. + // shim layer with setTimeout fallback + var requestAnimFrame = (function() { + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(callback) { + window.setTimeout(callback, 1000 / 60); + }; + })(); + + function calculateScale(axis, config, maxSteps, minSteps, maxValue, minValue, labelTemplateString) { + var graphMin, graphMax, graphRange, stepValue, numberOfSteps, valueRange, rangeOrderOfMagnitude, decimalNum; + var logarithmic, yAxisMinimumInterval; + if (axis == 2) { + logarithmic = config.logarithmic2; + yAxisMinimumInterval = config.yAxisMinimumInterval2; + } else { + logarithmic = config.logarithmic; + yAxisMinimumInterval = config.yAxisMinimumInterval; + } + + if (!logarithmic) { // no logarithmic scale + valueRange = maxValue - minValue; + rangeOrderOfMagnitude = calculateOrderOfMagnitude(valueRange); + if(Math.abs(minValue)>config.zeroValue)graphMin = Math.floor(minValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude); + else graphMin=0; + if(Math.abs(maxValue)>config.zeroValue)graphMax = Math.ceil(maxValue / (1 * Math.pow(10, rangeOrderOfMagnitude))) * Math.pow(10, rangeOrderOfMagnitude); + else graphMax=0; + if (typeof yAxisMinimumInterval == "number") { + if(graphMax>=0) { + graphMin = graphMin - (graphMin % yAxisMinimumInterval); + while (graphMin > minValue) graphMin = graphMin - yAxisMinimumInterval; + if (graphMax % yAxisMinimumInterval > config.zeroValue && graphMax % yAxisMinimumInterval < yAxisMinimumInterval - config.zeroValue) { + graphMax = roundScale(config, (1 + Math.floor(graphMax / yAxisMinimumInterval)) * yAxisMinimumInterval); + } + while (graphMax < maxValue) graphMax = graphMax + yAxisMinimumInterval; + } + } + } else { // logarithmic scale + if(minValue==maxValue)maxValue=maxValue+1; + if(minValue==0)minValue=0.01; + var minMag = calculateOrderOfMagnitude(minValue); + var maxMag = calculateOrderOfMagnitude(maxValue) + 1; + graphMin = Math.pow(10, minMag); + graphMax = Math.pow(10, maxMag); + rangeOrderOfMagnitude = maxMag - minMag; + } + graphRange = graphMax - graphMin; + stepValue = Math.pow(10, rangeOrderOfMagnitude); + numberOfSteps = Math.round(graphRange / stepValue); + if (!logarithmic) { // no logarithmic scale + //Compare number of steps to the max and min for that size graph, and add in half steps if need be. + var stopLoop = false; + while (!stopLoop && (numberOfSteps < minSteps || numberOfSteps > maxSteps)) { + if (numberOfSteps < minSteps) { + if (typeof yAxisMinimumInterval == "number") { + if (stepValue / 2 < yAxisMinimumInterval) stopLoop = true; + } + if (!stopLoop) { + stepValue /= 2; + numberOfSteps = Math.round(graphRange / stepValue); + } + } else { + stepValue *= 2; + numberOfSteps = Math.round(graphRange / stepValue); + } + } + + if (typeof yAxisMinimumInterval == "number") { + if (stepValue < yAxisMinimumInterval) { + stepValue = yAxisMinimumInterval; + numberOfSteps = Math.ceil(graphRange / stepValue); + } + if (stepValue % yAxisMinimumInterval > config.zeroValue && stepValue % yAxisMinimumInterval < yAxisMinimumInterval - config.zeroValue) { + if ((2 * stepValue) % yAxisMinimumInterval < config.zeroValue || (2 * stepValue) % yAxisMinimumInterval > yAxisMinimumInterval - config.zeroValue) { + stepValue = 2 * stepValue; + numberOfSteps = Math.ceil(graphRange / stepValue); + } else { + stepValue = roundScale(config, (1 + Math.floor(stepValue / yAxisMinimumInterval)) * yAxisMinimumInterval); + numberOfSteps = Math.ceil(graphRange / stepValue); + } + } + } + if(config.graphMaximized==true || config.graphMaximized=="bottom" || typeof config.graphMin!=="undefined") { + while (graphMin+stepValue < minValue && numberOfSteps>=3){graphMin+=stepValue;numberOfSteps--}; + } + if(config.graphMaximized==true || config.graphMaximized=="top" || typeof config.graphMax!=="undefined") { + + while (graphMin+(numberOfSteps-1)*stepValue >= maxValue && numberOfSteps>=3) numberOfSteps--; + } + } else { // logarithmic scale + numberOfSteps = rangeOrderOfMagnitude; // so scale is 10,100,1000,... + } + var labels = []; + populateLabels(1, config, labelTemplateString, labels, numberOfSteps, graphMin, graphMax, stepValue); + return { + steps: numberOfSteps, + stepValue: stepValue, + graphMin: graphMin, + labels: labels, + maxValue: maxValue + } + }; + + function roundScale(config, value) { + var scldec = 0; + var sscl = "" + config.yAxisMinimumInterval; + if (sscl.indexOf(".") > 0) { + scldec = sscl.substr(sscl.indexOf(".")).length; + } + return (Math.round(value * Math.pow(10, scldec)) / Math.pow(10, scldec)); + } ; + + function calculateOrderOfMagnitude(val) { + if (val==0)return 0; + return Math.floor(Math.log(val) / Math.LN10); + }; + //Populate an array of all the labels by interpolating the string. + function populateLabels(axis, config, labelTemplateString, labels, numberOfSteps, graphMin, graphMax, stepValue) { + var logarithmic; + if (axis == 2) { + logarithmic = config.logarithmic2; + fmtYLabel = config.fmtYLabel2; + } else { + logarithmic = config.logarithmic; + fmtYLabel = config.fmtYLabel; + } + if (labelTemplateString) { + //Fix floating point errors by setting to fixed the on the same decimal as the stepValue. + var i; + if (!logarithmic) { // no logarithmic scale + for (i = 0; i < numberOfSteps + 1; i++) { + labels.push(tmpl(labelTemplateString, { + value: fmtChartJS(config, 1 * ((graphMin + (stepValue * i)).toFixed(getDecimalPlaces(stepValue))), fmtYLabel) + },config)); + } + } else { // logarithmic scale 10,100,1000,... + var value = graphMin; + for (i = 0; i < numberOfSteps + 1; i++) { + labels.push(tmpl(labelTemplateString, { + value: fmtChartJS(config, 1 * value.toFixed(getDecimalPlaces(value)), fmtYLabel) + },config)); + value *= 10; + } + } + } + }; + //Max value from array + function Max(array) { + return Math.max.apply(Math, array); + }; + //Min value from array + function Min(array) { + return Math.min.apply(Math, array); + }; + //Default if undefined + function Default(userDeclared, valueIfFalse) { + if (!userDeclared) { + return valueIfFalse; + } else { + return userDeclared; + } + }; + //Apply cap a value at a high or low number + function CapValue(valueToCap, maxValue, minValue) { + if (isNumber(maxValue)) { + if (valueToCap > maxValue) { + return maxValue; + } + } + if (isNumber(minValue)) { + if (valueToCap < minValue) { + return minValue; + } + } + return valueToCap; + }; + + function getDecimalPlaces(num) { + var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); + if (!match) { + return 0; + } + return Math.max( + 0, + (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0) + ); + }; + + function mergeChartConfig(defaults, userDefined) { + var returnObj = {}; + for (var attrname in defaults) { + returnObj[attrname] = defaults[attrname]; + } + for (var attrnameBis in userDefined) { + returnObj[attrnameBis] = userDefined[attrnameBis]; + } + return returnObj; + }; + //Javascript micro templating by John Resig - source at http://ejohn.org/blog/javascript-micro-templating/ + var cache = {}; + + function tmpl(str, data,config) { + newstr=str; + if(newstr.substr(0,config.templatesOpenTag.length)==config.templatesOpenTag)newstr="<%="+newstr.substr(config.templatesOpenTag.length,newstr.length-config.templatesOpenTag.length); + if(newstr.substr(newstr.length-config.templatesCloseTag.length,config.templatesCloseTag.length)==config.templatesCloseTag)newstr=newstr.substr(0,newstr.length-config.templatesCloseTag.length)+"%>"; + return tmplpart2(newstr,data); + } + + function tmplpart2(str, data) { + // Figure out if we're getting a template, or if we need to + // load the template - and be sure to cache the result. + var fn = !/\W/.test(str) ? + cache[str] = cache[str] || + tmplpart2(document.getElementById(str).innerHTML) : + // Generate a reusable function that will serve as a template + // generator (and which will be cached). + new Function("obj", + "var p=[],print=function(){p.push.apply(p,arguments);};" + + // Introduce the data as local variables using with(){} + "with(obj){p.push('" + + // Convert the template into pure JavaScript + str + .replace(/[\r\t\n]/g, " ") + .split("<%").join("\t") + .replace(/((^|%>)[^\t]*)'/g, "$1\r") + .replace(/\t=(.*?)%>/g, "',$1,'") + .split("\t").join("');") + .split("%>").join("p.push('") + .split("\r").join("\\'") + "');}return p.join('');"); + // Provide some basic currying to the user + return data ? fn(data) : fn; + }; + + function dispCrossText(ctx, config, posX, posY, borderX, borderY, overlay, data, animPC, cntiter) { + var i, disptxt, txtposx, txtposy, textAlign, textBaseline; + for (i = 0; i < config.crossText.length; i++) { + if (config.crossText[i] != "" && config.crossTextOverlay[Min([i, config.crossTextOverlay.length - 1])] == overlay && ((cntiter == 1 && config.crossTextIter[Min([i, config.crossTextIter.length - 1])] == "first") || config.crossTextIter[Min([i, config.crossTextIter.length - 1])] == cntiter || config.crossTextIter[Min([i, config.crossTextIter.length - 1])] == "all" || (animPC == 1 && config.crossTextIter[Min([i, config.crossTextIter.length - 1])] == "last"))) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.crossTextFontStyle[Min([i, config.crossTextFontStyle.length - 1])] + " " + (Math.ceil(ctx.chartTextScale*config.crossTextFontSize[Min([i, config.crossTextFontSize.length - 1])])).toString() + "px " + config.crossTextFontFamily[Min([i, config.crossTextFontFamily.length - 1])]; + ctx.fillStyle = config.crossTextFontColor[Min([i, config.crossTextFontColor.length - 1])]; + textAlign = config.crossTextAlign[Min([i, config.crossTextAlign.length - 1])]; + textBaseline = config.crossTextBaseline[Min([i, config.crossTextBaseline.length - 1])]; + txtposx = 1 * Math.ceil(ctx.chartSpaceScale*config.crossTextPosX[Min([i, config.crossTextPosX.length - 1])]); + txtposy = 1 * Math.ceil(ctx.chartSpaceScale*config.crossTextPosY[Min([i, config.crossTextPosY.length - 1])]); + switch (1 * config.crossTextRelativePosX[Min([i, config.crossTextRelativePosX.length - 1])]) { + case 0: + if (textAlign == "default") textAlign = "left"; + break; + case 1: + txtposx += borderX; + if (textAlign == "default") textAlign = "right"; + break; + case 2: + txtposx += posX; + if (textAlign == "default") textAlign = "center"; + break; + case -2: + txtposx += context.canvas.width / 2; + if (textAlign == "default") textAlign = "center"; + break; + case 3: + txtposx += txtposx + 2 * posX - borderX; + if (textAlign == "default") textAlign = "left"; + break; + case 4: + txtposx += context.canvas.width; + if (textAlign == "default") textAlign = "right"; + break; + default: + txtposx += posX; + if (textAlign == "default") textAlign = "center"; + break; + } + switch (1 * config.crossTextRelativePosY[Min([i, config.crossTextRelativePosY.length - 1])]) { + case 0: + if (textBaseline == "default") textBaseline = "top"; + break; + case 3: + txtposy += borderY; + if (textBaseline == "default") textBaseline = "top"; + break; + case 2: + txtposy += posY; + if (textBaseline == "default") textBaseline = "middle"; + break; + case -2: + txtposy += context.canvas.height / 2; + if (textBaseline == "default") textBaseline = "middle"; + break; + case 1: + txtposy += txtposy + 2 * posY - borderY; + if (textBaseline == "default") textBaseline = "bottom"; + break; + case 4: + txtposy += context.canvas.height; + if (textBaseline == "default") textBaseline = "bottom"; + break; + default: + txtposy += posY; + if (textBaseline == "default") textBaseline = "middle"; + break; + } + ctx.textAlign = textAlign; + ctx.textBaseline = textBaseline; + ctx.translate(1 * txtposx, 1 * txtposy); + ctx.rotate(Math.PI * config.crossTextAngle[Min([i, config.crossTextAngle.length - 1])] / 180); + if (config.crossText[i].substring(0, 1) == "%") { + if (typeof config.crossTextFunction == "function") disptxt = config.crossTextFunction(i, config.crossText[i], ctx, config, posX, posY, borderX, borderY, overlay, data, animPC); + } else disptxt = config.crossText[i]; + + setTextBordersAndBackground(ctx,disptxt,Math.ceil(ctx.chartTextScale*config.crossTextFontSize[Min([i, config.crossTextFontSize.length - 1])]),0,0,config.crossTextBorders[Min([i, config.crossTextBorders.length - 1])],config.crossTextBordersColor[Min([i, config.crossTextBordersColor.length - 1])],Math.ceil(ctx.chartLineScale*config.crossTextBordersWidth[Min([i, config.crossTextBordersWidth.length - 1])]),Math.ceil(ctx.chartSpaceScale*config.crossTextBordersXSpace[Min([i, config.crossTextBordersXSpace.length - 1])]),Math.ceil(ctx.chartSpaceScale*config.crossTextBordersYSpace[Min([i, config.crossTextBordersYSpace.length - 1])]),config.crossTextBordersStyle[Min([i, config.crossTextBordersStyle.length - 1])],config.crossTextBackgroundColor[Min([i, config.crossTextBackgroundColor.length - 1])],"CROSSTEXT"); + ctx.fillTextMultiLine(disptxt, 0, 0, ctx.textBaseline, Math.ceil(ctx.chartTextScale*config.crossTextFontSize[Min([i, config.crossTextFontSize.length - 1])]),true); + ctx.restore(); + } + } + }; + + function dispCrossImage(ctx, config, posX, posY, borderX, borderY, overlay, data, animPC, cntiter) { + var i, disptxt, imageposx, imageposy, imageAlign, imageBaseline; + for (i = 0; i < config.crossImage.length; i++) { + if (typeof config.crossImage[i] != "undefined" && config.crossImageOverlay[Min([i, config.crossImageOverlay.length - 1])] == overlay && ((cntiter == -1 && config.crossImageIter[Min([i, config.crossImageIter.length - 1])] == "background") || (cntiter == 1 && config.crossImageIter[Min([i, config.crossImageIter.length - 1])] == "first") || config.crossImageIter[Min([i, config.crossImageIter.length - 1])] == cntiter || (cntiter != -1 && config.crossImageIter[Min([i, config.crossImageIter.length - 1])] == "all") || (animPC == 1 && config.crossImageIter[Min([i, config.crossImageIter.length - 1])] == "last"))) { + ctx.save(); + ctx.beginPath(); + imageAlign = config.crossImageAlign[Min([i, config.crossImageAlign.length - 1])]; + imageBaseline = config.crossImageBaseline[Min([i, config.crossImageBaseline.length - 1])]; + imageposx = 1 * Math.ceil(ctx.chartSpaceScale*config.crossImagePosX[Min([i, config.crossImagePosX.length - 1])]); + imageposy = 1 * Math.ceil(ctx.chartSpaceScale*config.crossImagePosY[Min([i, config.crossImagePosY.length - 1])]); + switch (1 * config.crossImageRelativePosX[Min([i, config.crossImageRelativePosX.length - 1])]) { + case 0: + if (imageAlign == "default") imageAlign = "left"; + break; + case 1: + imageposx += borderX; + if (imageAlign == "default") imageAlign = "right"; + break; + case 2: + imageposx += posX; + if (imageAlign == "default") imageAlign = "center"; + break; + case -2: + imageposx += context.canvas.width / 2; + if (imageAlign == "default") imageAlign = "center"; + break; + case 3: + imageposx += imageposx + 2 * posX - borderX; + if (imageAlign == "default") imageAlign = "left"; + break; + case 4: + imageposx += context.canvas.width; + if (imageAlign == "default") imageAlign = "right"; + break; + default: + imageposx += posX; + if (imageAlign == "default") imageAlign = "center"; + break; + } + switch (1 * config.crossImageRelativePosY[Min([i, config.crossImageRelativePosY.length - 1])]) { + case 0: + if (imageBaseline == "default") imageBaseline = "top"; + break; + case 3: + imageposy += borderY; + if (imageBaseline == "default") imageBaseline = "top"; + break; + case 2: + imageposy += posY; + if (imageBaseline == "default") imageBaseline = "middle"; + break; + case -2: + imageposy += context.canvas.height / 2; + if (imageBaseline == "default") imageBaseline = "middle"; + break; + case 1: + imageposy += imageposy + 2 * posY - borderY; + if (imageBaseline == "default") imageBaseline = "bottom"; + break; + case 4: + imageposy += context.canvas.height; + if (imageBaseline == "default") imageBaseline = "bottom"; + break; + default: + imageposy += posY; + if (imageBaseline == "default") imageBaseline = "middle"; + break; + } + var imageWidth = config.crossImage[i].width; + switch (imageAlign) { + case "left": + break; + case "right": + imageposx -= imageWidth; + break; + case "center": + imageposx -= (imageWidth / 2); + break; + default: + break; + } + var imageHeight = config.crossImage[i].height; + switch (imageBaseline) { + case "top": + break; + case "bottom": + imageposy -= imageHeight; + break; + case "middle": + imageposy -= (imageHeight / 2); + break; + default: + break; + } + ctx.translate(1 * imageposx, 1 * imageposy); + ctx.rotate(Math.PI * config.crossImageAngle[Min([i, config.crossImageAngle.length - 1])] / 180); + ctx.drawImage(config.crossImage[i], 0, 0); + ctx.restore(); + } + } + }; + //**************************************************************************************** + function setMeasures(data, config, ctx, height, width, ylabels, ylabels2, reverseLegend, reverseAxis, drawAxis, drawLegendOnData, legendBox, typegraph) { + if (config.canvasBackgroundColor != "none") ctx.canvas.style.background = config.canvasBackgroundColor; + var borderWidth = 0; + var xAxisLabelPos = 0; + var graphTitleHeight = 0; + var graphTitlePosY = 0; + var graphSubTitleHeight = 0; + var graphSubTitlePosY = 0; + var footNoteHeight = 0; + var footNotePosY = 0; + var yAxisUnitHeight = 0; + var yAxisUnitPosY = 0; + var widestLegend = 0; + var nbeltLegend = 0; + var nbLegendLines = 0; + var nbLegendCols = 0; + var spaceLegendHeight = 0; + var xFirstLegendTextPos = 0; + var yFirstLegendTextPos = 0; + var xLegendBorderPos = 0; + var yLegendBorderPos = 0; + var yAxisLabelWidth = 0; + var yAxisLabelPosLeft = 0; + var yAxisLabelPosRight = 0; + var xAxisLabelHeight = 0; + var xLabelHeight = 0; + var widestXLabel = 1; + var highestXLabel = 1; + var widestYLabel = 0; + var highestYLabel = 1; + var widestYLabel2 = 0; + var highestYLabel2 = 1; + var leftNotUsableSize = 0; + var rightNotUsableSize = 0; + var rotateLabels = 0; + var xLabelPos = 0; + var legendBorderWidth = 0; + var legendBorderHeight = 0; + + ctx.widthAtSetMeasures=width; + ctx.heightAtSetMeasures=height; + + // Borders + if (config.canvasBorders) borderWidth = Math.ceil(ctx.chartLineScale*config.canvasBordersWidth); + // compute widest X label + var textMsr,i; + if (drawAxis) { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + for (i = 0; i < data.labels.length; i++) { + textMsr = ctx.measureTextMultiLine(fmtChartJS(config, data.labels[i], config.fmtXLabel), (Math.ceil(ctx.chartTextScale*config.scaleFontSize))); + //If the text length is longer - make that equal to longest text! + widestXLabel = (textMsr.textWidth > widestXLabel) ? textMsr.textWidth : widestXLabel; + highestXLabel = (textMsr.textHeight > highestXLabel) ? textMsr.textHeight : highestXLabel; + } + if (widestXLabel < Math.ceil(ctx.chartTextScale*config.xScaleLabelsMinimumWidth)) { + widestXLabel = Math.ceil(ctx.chartTextScale*config.xScaleLabelsMinimumWidth); + } + } + // compute Y Label Width + if (drawAxis) { + widestYLabel = 1; + if (ylabels != null && ylabels != "nihil") { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + for (i = ylabels.length - 1; i >= 0; i--) { + if (typeof(ylabels[i]) == "string") { + if (ylabels[i].trim() != "") { + textMsr = ctx.measureTextMultiLine(fmtChartJS(config, ylabels[i], config.fmtYLabel), (Math.ceil(ctx.chartTextScale*config.scaleFontSize))); + //If the text length is longer - make that equal to longest text! + widestYLabel = (textMsr.textWidth > widestYLabel) ? textMsr.textWidth : widestYLabel; + highestYLabel = (textMsr.textHeight > highestYLabel) ? textMsr.textHeight : highestYLabel; + } + } + } + } + if (widestYLabel < Math.ceil(ctx.chartTextScale*config.yScaleLabelsMinimumWidth)) { + widestYLabel = Math.ceil(ctx.chartTextScale*config.yScaleLabelsMinimumWidth); + } + widestYLabel2 = 1; + if (ylabels2 != null && config.yAxisRight) { + ctx.font = config.scaleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.scaleFontSize)).toString() + "px " + config.scaleFontFamily; + for (i = ylabels2.length - 1; i >= 0; i--) { + if (typeof(ylabels2[i]) == "string") { + if (ylabels2[i].trim() != "") { + textMsr = ctx.measureTextMultiLine(fmtChartJS(config, ylabels2[i], config.fmtYLabel2), (Math.ceil(ctx.chartTextScale*config.scaleFontSize))); + //If the text length is longer - make that equal to longest text! + widestYLabel2 = (textMsr.textWidth > widestYLabel2) ? textMsr.textWidth : widestYLabel2; + highestYLabel2 = (textMsr.textHeight > highestYLabel2) ? textMsr.textHeight : highestYLabel2; + } + } + } + } else { + widestYLabel2 = widestYLabel; + } + if (widestYLabel2 < Math.ceil(ctx.chartTextScale*config.yScaleLabelsMinimumWidth)) { + widestYLabel2 = Math.ceil(ctx.chartTextScale*config.yScaleLabelsMinimumWidth); + } + } + // yAxisLabel + leftNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + rightNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceRight); + if (drawAxis) { + if (typeof(config.yAxisLabel) != "undefined") { + if (config.yAxisLabel.trim() != "") { + yAxisLabelWidth = (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)) * (config.yAxisLabel.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.yAxisLabelSpaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisLabelSpaceRight); + yAxisLabelPosLeft = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisLabelSpaceLeft) + (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)); + yAxisLabelPosRight = width - borderWidth - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - Math.ceil(ctx.chartSpaceScale*config.yAxisLabelSpaceLeft) - (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)); + } + if(config.yAxisLabelBackgroundColor !="none" || config.yAxisLabelBorders) { + yAxisLabelWidth+=2*(Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersYSpace)); + yAxisLabelPosLeft+=Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersYSpace); + yAxisLabelPosRight-=Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersYSpace); + } + + if(config.graphTitleBorders) { + yAxisLabelWidth+=2*(Math.ceil(ctx.chartLineScale*config.yAxisLabelBordersWidth)); + yAxisLabelPosLeft+=Math.ceil(ctx.chartLineScale*config.yAxisLabelBordersWidth); + yAxisLabelPosRight-=Math.ceil(ctx.chartLineScale*config.yAxisLabelBordersWidth); + } + } + if (config.yAxisLeft) { + if (reverseAxis == false) leftNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + yAxisLabelWidth + widestYLabel + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight); + else leftNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + yAxisLabelWidth + widestXLabel + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight); + } + if (config.yAxisRight) { + if (reverseAxis == false) rightNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceRight) + yAxisLabelWidth + widestYLabel2 + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight); + else rightNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceRight) + yAxisLabelWidth + widestXLabel + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceLeft) + Math.ceil(ctx.chartSpaceScale*config.yAxisSpaceRight); + } + } + availableWidth = width - leftNotUsableSize - rightNotUsableSize; + // Title + if (config.graphTitle.trim() != "") { + graphTitleHeight = (Math.ceil(ctx.chartTextScale*config.graphTitleFontSize)) * (config.graphTitle.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.graphTitleSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.graphTitleSpaceAfter); + graphTitlePosY = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceTop) + graphTitleHeight - Math.ceil(ctx.chartSpaceScale*config.graphTitleSpaceAfter); + if(config.graphTitleBackgroundColor !="none" || config.graphTitleBorders) { + graphTitleHeight+=2*(Math.ceil(ctx.chartSpaceScale*config.graphTitleBordersYSpace)); + graphTitlePosY+=Math.ceil(ctx.chartSpaceScale*config.graphTitleBordersYSpace); + } + + if(config.graphTitleBorders) { + graphTitleHeight+=2*(Math.ceil(ctx.chartLineScale*config.graphTitleBordersWidth)); + graphTitlePosY+=Math.ceil(ctx.chartLineScale*config.graphTitleBordersWidth); + } + } + // subTitle + if (config.graphSubTitle.trim() != "") { + graphSubTitleHeight = (Math.ceil(ctx.chartTextScale*config.graphSubTitleFontSize)) * (config.graphSubTitle.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.graphSubTitleSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.graphSubTitleSpaceAfter); + graphSubTitlePosY = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceTop) + graphTitleHeight + graphSubTitleHeight - Math.ceil(ctx.chartSpaceScale*config.graphSubTitleSpaceAfter); + if(config.graphSubTitleBackgroundColor !="none" || config.graphSubTitleBorders) { + graphSubTitleHeight+=2*(Math.ceil(ctx.chartSpaceScale*config.graphSubTitleBordersYSpace)); + graphSubTitlePosY+=Math.ceil(ctx.chartSpaceScale*config.graphSubTitleBordersYSpace); + } + + if(config.graphSubTitleBorders) { + graphSubTitleHeight+=2*(Math.ceil(ctx.chartLineScale*config.graphSubTitleBordersWidth)); + graphSubTitlePosY+=Math.ceil(ctx.chartLineScale*config.graphSubTitleBordersWidth); + } + } + // yAxisUnit + if (drawAxis) { + if (config.yAxisUnit.trim() != "") { + yAxisUnitHeight = (Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)) * (config.yAxisUnit.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.yAxisUnitSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.yAxisUnitSpaceAfter); + yAxisUnitPosY = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceTop) + graphTitleHeight + graphSubTitleHeight + yAxisUnitHeight - Math.ceil(ctx.chartSpaceScale*config.yAxisUnitSpaceAfter); + } + if(config.yAxisUnitBackgroundColor !="none" || config.yAxisUnitBorders) { + yAxisUnitHeight+=2*(Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersYSpace)); + yAxisUnitPosY+=Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersYSpace); + } + + if(config.yAxisUnitBorders) { + yAxisUnitHeight+=2*(Math.ceil(ctx.chartLineScale*config.yAxisUnitBordersWidth)); + yAxisUnitPosY+=Math.ceil(ctx.chartLineScale*config.yAxisUnitBordersWidth); + } + + + } + topNotUsableSize = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceTop) + graphTitleHeight + graphSubTitleHeight + yAxisUnitHeight + Math.ceil(ctx.chartTextScale*config.graphSpaceBefore); + // footNote + if (typeof(config.footNote) != "undefined") { + if (config.footNote.trim() != "") { + footNoteHeight = (Math.ceil(ctx.chartTextScale*config.footNoteFontSize)) * (config.footNote.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.footNoteSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.footNoteSpaceAfter); + footNotePosY = height - Math.ceil(ctx.chartSpaceScale*config.spaceBottom) - borderWidth - Math.ceil(ctx.chartSpaceScale*config.footNoteSpaceAfter); + if(config.footNoteBackgroundColor !="none" || config.footNoteBorders) { + footNoteHeight+=2*(Math.ceil(ctx.chartSpaceScale*config.footNoteBordersYSpace)); + footNotePosY-=Math.ceil(ctx.chartSpaceScale*config.footNoteBordersYSpace); + } + if(config.footNoteBorders) { + footNoteHeight+=2*(Math.ceil(ctx.chartLineScale*config.footNoteBordersWidth)); + footNotePosY-=Math.ceil(ctx.chartLineScale*config.footNoteBordersWidth); + } + } + } + + // xAxisLabel + if (drawAxis) { + if (typeof(config.xAxisLabel) != "undefined") { + if (config.xAxisLabel.trim() != "") { + xAxisLabelHeight = (Math.ceil(ctx.chartTextScale*config.xAxisFontSize)) * (config.xAxisLabel.split("\n").length || 1) + Math.ceil(ctx.chartSpaceScale*config.xAxisLabelSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.xAxisLabelSpaceAfter); + xAxisLabelPos = height - borderWidth - Math.ceil(ctx.chartSpaceScale*config.spaceBottom) - footNoteHeight - Math.ceil(ctx.chartSpaceScale*config.xAxisLabelSpaceAfter); + if(config.xAxisLabelBackgroundColor !="none" || config.footNoteBorders) { + xAxisLabelHeight+=2*(Math.ceil(ctx.chartSpaceScale*config.xAxisLabelBordersYSpace)); + xAxisLabelPos-=Math.ceil(ctx.chartSpaceScale*config.xAxisLabelBordersYSpace); + } + if(config.footNoteBorders) { + xAxisLabelHeight+=2*(Math.ceil(ctx.chartLineScale*config.xAxisLabelBordersWidth)); + xAxisLabelPos-=Math.ceil(ctx.chartLineScale*config.xAxisLabelBordersWidth); + } + } + } + } + + bottomNotUsableHeightWithoutXLabels = borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceBottom) + footNoteHeight + xAxisLabelHeight + Math.ceil(ctx.chartTextScale*config.graphSpaceAfter); + + // compute space for Legend + if (typeof(config.legend) != "undefined") { + if (config.legend == true) { + ctx.font = config.legendFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.legendFontSize)).toString() + "px " + config.legendFontFamily; + var textLength; + if (drawLegendOnData) { + for (i = data.datasets.length - 1; i >= 0; i--) { + if (typeof(data.datasets[i].title) == "string") { + if (data.datasets[i].title.trim() != "") { + nbeltLegend++; + textLength = ctx.measureText(fmtChartJS(config, data.datasets[i].title, config.fmtLegend)).width; + //If the text length is longer - make that equal to longest text! + widestLegend = (textLength > widestLegend) ? textLength : widestLegend; + } + } + } + } else { + for (i = data.length - 1; i >= 0; i--) { + if (typeof(data[i].title) == "string") { + if (data[i].title.trim() != "") { + nbeltLegend++; + textLength = ctx.measureText(fmtChartJS(config, data[i].title, config.fmtLegend)).width; + //If the text length is longer - make that equal to longest text! + widestLegend = (textLength > widestLegend) ? textLength : widestLegend; + } + } + } + } + if (nbeltLegend > 1 || (nbeltLegend == 1 && config.showSingleLegend)) { + widestLegend += Math.ceil(ctx.chartTextScale*config.legendBlockSize) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenBoxAndText); + if(config.legendPosY==1 || config.legendPosY==2 || config.legendPosY==3) { + availableLegendWidth = availableWidth- Math.ceil(ctx.chartSpaceScale*Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText)) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText); + } else { + availableLegendWidth = width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - 2 * (borderWidth) - Math.ceil(ctx.chartSpaceScale*Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText)) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText); + } + if (config.legendBorders == true) availableLegendWidth -= 2 * (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceRight); + maxLegendOnLine = Min([Math.floor((availableLegendWidth + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))),config.maxLegendCols]); + nbLegendLines = Math.ceil(nbeltLegend / maxLegendOnLine); + nbLegendCols = Math.ceil(nbeltLegend / nbLegendLines); + + var legendHeight = nbLegendLines * ((Math.ceil(ctx.chartTextScale*config.legendFontSize)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextVertical)) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextVertical) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceAfterText); + + switch (config.legendPosY) { + case 0: + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + spaceLegendHeight = legendHeight; + if (config.legendBorders == true) { + yLegendBorderPos = topNotUsableSize + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2); + yFirstLegendTextPos = yLegendBorderPos + (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText)+(Math.ceil(ctx.chartTextScale*config.legendFontSize)); + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } else { + yFirstLegendTextPos = topNotUsableSize + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2); + } + if(yAxisUnitHeight>0) { + yAxisUnitPosY+=spaceLegendHeight; + if(config.legendBorders==true)yLegendBorderPos-=yAxisUnitHeight; + yFirstLegendTextPos-=yAxisUnitHeight; + } + topNotUsableSize += spaceLegendHeight; + break; + case 1: + spaceLegendHeight = legendHeight; + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + yFirstLegendTextPos = topNotUsableSize + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText)+(Math.ceil(ctx.chartTextScale*config.legendFontSize)); + if (config.legendBorders == true) { + yFirstLegendTextPos += Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore)+Math.ceil(ctx.chartLineScale*config.legendBordersWidth); + yLegendBorderPos = yFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) - (Math.ceil(ctx.chartTextScale*config.legendFontSize)) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) /2 ); + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } + break; + case 2: + spaceLegendHeight = legendHeight; + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + yFirstLegendTextPos = topNotUsableSize + (height - topNotUsableSize - bottomNotUsableHeightWithoutXLabels - spaceLegendHeight) /2 + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText)+(Math.ceil(ctx.chartTextScale*config.legendFontSize)); + if (config.legendBorders == true) { + yFirstLegendTextPos += Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + yLegendBorderPos = yFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) - (Math.ceil(ctx.chartTextScale*config.legendFontSize)) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) /2 ); + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } + break; + case -2: + spaceLegendHeight = legendHeight; + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + yFirstLegendTextPos = (height - spaceLegendHeight) /2 + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText)+(Math.ceil(ctx.chartTextScale*config.legendFontSize)); + if (config.legendBorders == true) { + yFirstLegendTextPos += Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + yLegendBorderPos = yFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) - (Math.ceil(ctx.chartTextScale*config.legendFontSize)) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) /2 ); + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } + break; + case 3: + spaceLegendHeight = legendHeight; + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + availableHeight = height - topNotUsableSize - bottomNotUsableHeightWithoutXLabels; + yFirstLegendTextPos = topNotUsableSize + availableHeight - spaceLegendHeight + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText)+(Math.ceil(ctx.chartTextScale*config.legendFontSize)); + if (config.legendBorders == true) { + yFirstLegendTextPos -= (Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter)+Math.ceil(ctx.chartLineScale*config.legendBordersWidth)); + yLegendBorderPos = yFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) - (Math.ceil(ctx.chartTextScale*config.legendFontSize)) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) /2 ); + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } + break; + default: + spaceLegendHeight = legendHeight; + yFirstLegendTextPos = height - borderWidth - Math.ceil(ctx.chartSpaceScale*config.spaceBottom) - footNoteHeight - spaceLegendHeight + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBeforeText) + (Math.ceil(ctx.chartTextScale*config.legendFontSize)); + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + if (config.legendBorders == true) { + spaceLegendHeight += 2 * Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + yFirstLegendTextPos -= (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter)); + yLegendBorderPos = Math.floor(height - borderWidth - Math.ceil(ctx.chartSpaceScale*config.spaceBottom) - footNoteHeight - spaceLegendHeight + (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore)); + xLegendBorderPos = Math.floor(xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) - (Math.ceil(ctx.chartLineScale*config.legendBordersWidth) / 2)); + legendBorderHeight = Math.ceil(spaceLegendHeight - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceBefore) - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceAfter); + legendBorderWidth = Math.ceil(nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal))) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) + Math.ceil(ctx.chartLineScale*config.legendBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + } + xAxisLabelPos -= spaceLegendHeight; + bottomNotUsableHeightWithoutXLabels +=spaceLegendHeight; + break; + } + var fullLegendWidth=Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) + nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) +Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + if (config.legendBorders == true) { + fullLegendWidth+=2*Math.ceil(ctx.chartLineScale*config.legendBordersWidth)+Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft)+Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceRight); + } + + switch (config.legendPosX) { + case 0: + xFirstLegendTextPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + config.canvasBorders * Math.ceil(ctx.chartLineScale*config.canvasBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + if (config.legendBorders == true) { + xFirstLegendTextPos += (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2)+Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft); + xLegendBorderPos = Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + config.canvasBorders * Math.ceil(ctx.chartLineScale*config.canvasBordersWidth) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft); + } + if((config.legendPosY>=1 && config.legendPosY <=3) || config.legendPosY==-2) { + leftNotUsableSize+=fullLegendWidth; + yAxisLabelPosLeft+=fullLegendWidth; + } + break; + case 1: + xFirstLegendTextPos = leftNotUsableSize + Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText); + if (config.legendBorders == true) { + xLegendBorderPos = xFirstLegendTextPos; + xFirstLegendTextPos += (Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2) +Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft); + } + break; + case 2: + xFirstLegendTextPos = leftNotUsableSize + (width - rightNotUsableSize - leftNotUsableSize)/2 - (Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText)-Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText)) - (nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) / 2; + if (config.legendBorders == true) { + xFirstLegendTextPos -= ((Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceRight)); + xLegendBorderPos = xFirstLegendTextPos - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2 - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) ; + } + break; + case 3: + + xFirstLegendTextPos = width - rightNotUsableSize - Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) / 2; + if (config.legendBorders == true) { + xFirstLegendTextPos -= ((Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2) + Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceRight)); + xLegendBorderPos = xFirstLegendTextPos - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2 - Math.ceil(ctx.chartSpaceScale*config.legendSpaceLeftText) ; + } + break; + case 4: + xFirstLegendTextPos = width - Math.ceil(ctx.chartSpaceScale*config.spaceRight) - config.canvasBorders * Math.ceil(ctx.chartLineScale*config.canvasBordersWidth) - Math.ceil(ctx.chartSpaceScale*config.legendSpaceRightText) - nbLegendCols * (widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal) / 2; + if (config.legendBorders == true) { + xFirstLegendTextPos -= ((Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2)+Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceRight)); + xLegendBorderPos = xFirstLegendTextPos - Math.ceil(ctx.chartSpaceScale*config.legendBordersSpaceLeft) - Math.ceil(ctx.chartLineScale*config.legendBordersWidth)/2; + } + if((config.legendPosY>=1 && config.legendPosY <=3) || config.legendPosY==-2) { + rightNotUsableSize+=fullLegendWidth; + yAxisLabelPosRight-=fullLegendWidth; + } + break; + + default: + break; + } + if(config.legendBorders==true) { + yLegendBorderPos+=Math.ceil(ctx.chartSpaceScale*config.legendYPadding); + xLegendBorderPos+=Math.ceil(ctx.chartSpaceScale*config.legendXPadding); + + } + yFirstLegendTextPos+=Math.ceil(ctx.chartSpaceScale*config.legendYPadding); + xFirstLegendTextPos+=Math.ceil(ctx.chartSpaceScale*config.legendXPadding); + + } + } + } + xLabelWidth = 0; + bottomNotUsableHeightWithXLabels = bottomNotUsableHeightWithoutXLabels; + if (drawAxis && (config.xAxisBottom || config.xAxisTop)) { + var widestLabel,highestLabel; + if (reverseAxis == false) { + widestLabel = widestXLabel; + highestLabel = highestXLabel; + nblab = data.labels.length; + } else { + widestLabel = widestYLabel; + highestLabel = highestYLabel; + nblab = ylabels.length; + } + if (config.rotateLabels == "smart") { + rotateLabels = 0; + if ((availableWidth + Math.ceil(ctx.chartTextScale*config.xAxisSpaceBetweenLabels)) / nblab < (widestLabel + Math.ceil(ctx.chartTextScale*config.xAxisSpaceBetweenLabels))) { + rotateLabels = 45; + if (availableWidth / nblab < Math.abs(Math.cos(rotateLabels * Math.PI / 180) * widestLabel)) { + rotateLabels = 90; + } + } + } else { + rotateLabels = config.rotateLabels + if (rotateLabels < 0) rotateLabels = 0; + if (rotateLabels > 180) rotateLabels = 180; + } + if (rotateLabels > 90) rotateLabels += 180; + xLabelHeight = Math.abs(Math.sin(rotateLabels * Math.PI / 180) * widestLabel) + Math.abs(Math.sin((rotateLabels + 90) * Math.PI / 180) * highestLabel) + Math.ceil(ctx.chartSpaceScale*config.xAxisSpaceBefore) + Math.ceil(ctx.chartSpaceScale*config.xAxisSpaceAfter); + xLabelPos = height - borderWidth - Math.ceil(ctx.chartSpaceScale*config.spaceBottom) - footNoteHeight - xAxisLabelHeight - (xLabelHeight - Math.ceil(ctx.chartSpaceScale*config.xAxisSpaceBefore)) - Math.ceil(ctx.chartTextScale*config.graphSpaceAfter); + xLabelWidth = Math.abs(Math.cos(rotateLabels * Math.PI / 180) * widestLabel) + Math.abs(Math.cos((rotateLabels + 90) * Math.PI / 180) * highestLabel); + leftNotUsableSize = Max([leftNotUsableSize, borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + xLabelWidth / 2]); + rightNotUsableSize = Max([rightNotUsableSize, borderWidth + Math.ceil(ctx.chartSpaceScale*config.spaceRight) + xLabelWidth / 2]); + availableWidth = width - leftNotUsableSize - rightNotUsableSize; + if (config.legend && config.xAxisBottom && config.legendPosY==4) { + xLabelPos-=spaceLegendHeight; + } + bottomNotUsableHeightWithXLabels = bottomNotUsableHeightWithoutXLabels + xLabelHeight ; + } else { + availableWidth = width - leftNotUsableSize - rightNotUsableSize; + } + + availableHeight = height - topNotUsableSize - bottomNotUsableHeightWithXLabels; + + // ----------------------- DRAW EXTERNAL ELEMENTS ------------------------------------------------- + dispCrossImage(ctx, config, width / 2, height / 2, width / 2, height / 2, false, data, -1, -1); + if (ylabels != "nihil") { + // Draw Borders + if (borderWidth > 0) { + ctx.save(); + ctx.beginPath(); + ctx.lineWidth = 2 * borderWidth; + ctx.setLineDash(lineStyleFn(config.canvasBordersStyle)); + ctx.strokeStyle = config.canvasBordersColor; + ctx.moveTo(0, 0); + ctx.lineTo(0, height); + ctx.lineTo(width, height); + ctx.lineTo(width, 0); + ctx.lineTo(0, 0); + ctx.stroke(); + ctx.setLineDash([]); + ctx.restore(); + } + // Draw Graph Title + if (graphTitleHeight > 0) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.graphTitleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.graphTitleFontSize)).toString() + "px " + config.graphTitleFontFamily; + ctx.fillStyle = config.graphTitleFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + + setTextBordersAndBackground(ctx,config.graphTitle,(Math.ceil(ctx.chartTextScale*config.graphTitleFontSize)),Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight)) / 2,graphTitlePosY,config.graphTitleBorders,config.graphTitleBordersColor,Math.ceil(ctx.chartLineScale*config.graphTitleBordersWidth),Math.ceil(ctx.chartSpaceScale*config.graphTitleBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.graphTitleBordersYSpace),config.graphTitleBordersStyle,config.graphTitleBackgroundColor,"GRAPHTITLE"); + + ctx.translate(Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight)) / 2, graphTitlePosY); + ctx.fillTextMultiLine(config.graphTitle, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.graphTitleFontSize)),true); + + ctx.stroke(); + ctx.restore(); + } + // Draw Graph Sub-Title + if (graphSubTitleHeight > 0) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.graphSubTitleFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.graphSubTitleFontSize)).toString() + "px " + config.graphSubTitleFontFamily; + ctx.fillStyle = config.graphSubTitleFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + setTextBordersAndBackground(ctx,config.graphSubTitle,(Math.ceil(ctx.chartTextScale*config.graphSubTitleFontSize)),Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight)) / 2,graphSubTitlePosY,config.graphSubTitleBorders,config.graphSubTitleBordersColor,Math.ceil(ctx.chartLineScale*config.graphSubTitleBordersWidth),Math.ceil(ctx.chartSpaceScale*config.graphSubTitleBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.graphSubTitleBordersYSpace),config.graphSubTitleBordersStyle,config.graphSubTitleBackgroundColor,"GRAPHSUBTITLE"); + + ctx.translate(Math.ceil(ctx.chartSpaceScale*config.spaceLeft) + (width - Math.ceil(ctx.chartSpaceScale*config.spaceLeft) - Math.ceil(ctx.chartSpaceScale*config.spaceRight)) / 2, graphSubTitlePosY); + ctx.fillTextMultiLine(config.graphSubTitle, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.graphSubTitleFontSize)),true); + ctx.stroke(); + ctx.restore(); + } + // Draw Y Axis Unit + if (yAxisUnitHeight > 0) { + if (config.yAxisLeft) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.yAxisUnitFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)).toString() + "px " + config.yAxisUnitFontFamily; + ctx.fillStyle = config.yAxisUnitFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + + setTextBordersAndBackground(ctx,config.yAxisUnit,(Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)),leftNotUsableSize, yAxisUnitPosY,config.yAxisUnitBorders,config.yAxisUnitBordersColor,Math.ceil(ctx.chartLineScale*config.yAxisUnitBordersWidth),Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersYSpace),config.yAxisUnitBordersStyle,config.yAxisUnitBackgroundColor,"YAXISUNIT"); + ctx.translate(leftNotUsableSize, yAxisUnitPosY); + ctx.fillTextMultiLine(config.yAxisUnit, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)),true); + ctx.stroke(); + ctx.restore(); + } + if (config.yAxisRight) { + if (config.yAxisUnit2 == '') config.yAxisUnit2 = config.yAxisUnit; + ctx.save(); + ctx.beginPath(); + ctx.font = config.yAxisUnitFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)).toString() + "px " + config.yAxisUnitFontFamily; + ctx.fillStyle = config.yAxisUnitFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + setTextBordersAndBackground(ctx,config.yAxisUnit2,(Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)),width - rightNotUsableSize, yAxisUnitPosY,config.yAxisUnitBorders,config.yAxisUnitBordersColor,Math.ceil(ctx.chartLineScale*config.yAxisUnitBordersWidth),Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.yAxisUnitBordersYSpace),config.yAxisUnitBordersStyle,config.yAxisUnitBackgroundColor,"YAXISUNIT"); + ctx.translate(width - rightNotUsableSize, yAxisUnitPosY); + ctx.fillTextMultiLine(config.yAxisUnit2, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.yAxisUnitFontSize)),true); + ctx.stroke(); + ctx.restore(); + } + } + // Draw Y Axis Label + if (yAxisLabelWidth > 0) { + if (config.yAxisLeft) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.yAxisFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)).toString() + "px " + config.yAxisFontFamily; + ctx.fillStyle = config.yAxisFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + + ctx.translate(yAxisLabelPosLeft, topNotUsableSize + (availableHeight / 2)); + ctx.rotate(-(90 * (Math.PI / 180))); + setTextBordersAndBackground(ctx,config.yAxisLabel,(Math.ceil(ctx.chartTextScale*config.yAxisFontSize)), 0,0, config.yAxisLabelBorders,config.yAxisLabelBordersColor,Math.ceil(ctx.chartLineScale*config.yAxisLabelBordersWidth),Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersYSpace),config.yAxisLabelBordersStyle,config.yAxisLabelBackgroundColor,"YAXISLABELLEFT"); + ctx.fillTextMultiLine(config.yAxisLabel, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)),false); + ctx.stroke(); + ctx.restore(); + } + if (config.yAxisRight) { + if (config.yAxisLabel2 == '') config.yAxisLabel2 = config.yAxisLabel; + ctx.save(); + ctx.beginPath(); + ctx.font = config.yAxisFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)).toString() + "px " + config.yAxisFontFamily; + ctx.fillStyle = config.yAxisFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + ctx.translate(yAxisLabelPosRight, topNotUsableSize + (availableHeight / 2)); + ctx.rotate(+(90 * (Math.PI / 180))); + setTextBordersAndBackground(ctx,config.yAxisLabel2,(Math.ceil(ctx.chartTextScale*config.yAxisFontSize)), 0,0, config.yAxisLabelBorders,config.yAxisLabelBordersColor,Math.ceil(ctx.chartLineScale*config.yAxisLabelBordersWidth),Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.yAxisLabelBordersYSpace),config.yAxisLabelBordersStyle,config.yAxisLabelBackgroundColor,"YAXISLABELLEFT"); + ctx.fillTextMultiLine(config.yAxisLabel2, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.yAxisFontSize)),false); + ctx.stroke(); + ctx.restore(); + } + } + // Draw X Axis Label + if (xAxisLabelHeight > 0) { + if (config.xAxisBottom) { + ctx.save(); + ctx.beginPath(); + ctx.font = config.xAxisFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.xAxisFontSize)).toString() + "px " + config.xAxisFontFamily; + ctx.fillStyle = config.xAxisFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + setTextBordersAndBackground(ctx,config.xAxisLabel,(Math.ceil(ctx.chartTextScale*config.xAxisFontSize)),leftNotUsableSize + (availableWidth / 2), xAxisLabelPos,config.xAxisLabelBorders,config.xAxisLabelBordersColor,Math.ceil(ctx.chartLineScale*config.xAxisLabelBordersWidth),Math.ceil(ctx.chartSpaceScale*config.xAxisLabelBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.xAxisLabelBordersYSpace),config.xAxisLabelBordersStyle,config.xAxisLabelBackgroundColor,"XAXISLABEL"); + ctx.translate(leftNotUsableSize + (availableWidth / 2), xAxisLabelPos); + ctx.fillTextMultiLine(config.xAxisLabel, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.xAxisFontSize)),true); + ctx.stroke(); + ctx.restore(); + } + } + // Draw Legend + var legendMsr; + if (nbeltLegend > 1 || (nbeltLegend == 1 && config.showSingleLegend)) { + legendMsr={dispLegend : true, xLegendBorderPos : xLegendBorderPos, + yLegendBorderPos : yLegendBorderPos, legendBorderWidth : legendBorderWidth, legendBorderHeight : legendBorderHeight, + nbLegendCols: nbLegendCols, xFirstLegendTextPos : xFirstLegendTextPos , yFirstLegendTextPos : yFirstLegendTextPos, + drawLegendOnData : drawLegendOnData, reverseLegend : reverseLegend, legendBox : legendBox, widestLegend : widestLegend }; + if(config.legendPosY==0 || config.legendPosY==4 || config.legendPosX==0 || config.legendPosX==4) { + + drawLegend(legendMsr,data,config,ctx,typegraph); + legendMsr={dispLegend : false}; + } + } else { + legendMsr={dispLegend : false }; + } + // Draw FootNote + if (config.footNote.trim() != "") { + ctx.save(); + ctx.font = config.footNoteFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.footNoteFontSize)).toString() + "px " + config.footNoteFontFamily; + ctx.fillStyle = config.footNoteFontColor; + ctx.textAlign = "center"; + ctx.textBaseline = "bottom"; + + setTextBordersAndBackground(ctx,config.footNote,(Math.ceil(ctx.chartTextScale*config.footNoteFontSize)),leftNotUsableSize + (availableWidth / 2), footNotePosY,config.footNoteBorders,config.footNoteBordersColor,Math.ceil(ctx.chartLineScale*config.footNoteBordersWidth),Math.ceil(ctx.chartSpaceScale*config.footNoteBordersXSpace),Math.ceil(ctx.chartSpaceScale*config.footNoteBordersYSpace),config.footNoteBordersStyle,config.footNoteBackgroundColor,"FOOTNOTE"); + + ctx.translate(leftNotUsableSize + (availableWidth / 2), footNotePosY); + ctx.fillTextMultiLine(config.footNote, 0, 0, ctx.textBaseline, (Math.ceil(ctx.chartTextScale*config.footNoteFontSize)),true); + ctx.stroke(); + ctx.restore(); + } + } + clrx = leftNotUsableSize; + clrwidth = availableWidth; + clry = topNotUsableSize; + clrheight = availableHeight; + return { + leftNotUsableSize: leftNotUsableSize, + rightNotUsableSize: rightNotUsableSize, + availableWidth: availableWidth, + topNotUsableSize: topNotUsableSize, + bottomNotUsableHeightWithoutXLabels: bottomNotUsableHeightWithoutXLabels, + bottomNotUsableHeightWithXLabels: bottomNotUsableHeightWithXLabels, + availableHeight: availableHeight, + widestXLabel: widestXLabel, + highestXLabel: highestXLabel, + widestYLabel: widestYLabel, + widestYLabel2: widestYLabel2, + highestYLabel: highestYLabel, + rotateLabels: rotateLabels, + xLabelPos: xLabelPos, + clrx: clrx, + clry: clry, + clrwidth: clrwidth, + clrheight: clrheight, + legendMsr : legendMsr + }; + }; + + // Function for drawing lines (BarLine|Line) + + function drawLinesDataset(animPc, data, config, ctx, statData,vars) { + var y1,y2,y3,diffnb,diffnbj,fact, currentAnimPc; + var pts=[]; + + for (var i = 0; i < data.datasets.length; i++) { + if(statData[i][0].tpchart!="Line")continue; + if (statData[i].length == 0) continue; + if (statData[i][0].firstNotMissing == -1) continue; + + ctx.save(); + ctx.beginPath(); + + prevAnimPc={ mainVal:0 , subVal : 0,animVal : 0 }; + var firstpt=-1; + var lastxPos=-1; + for (var j = statData[i][0].firstNotMissing; j <= statData[i][0].lastNotMissing; j++) { + if(prevAnimPc.animVal==0 && j>statData[i][0].firstNotMissing) continue; + currentAnimPc = animationCorrection(animPc, data, config, i, j, 0); + if (currentAnimPc.mainVal == 0 && (prevAnimPc.mainVal > 0 && firstpt !=-1)) { + +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + if(config.extrapolateMissingData) { + y1=statData[i][statData[i][j].prevNotMissing].yAxisPos - prevAnimPc.mainVal*statData[i][statData[i][j].prevNotMissing].yPosOffset; + y2=statData[i][j].yAxisPos - prevAnimPc.mainVal*statData[i][statData[i][j-1].nextNotMissing].yPosOffset; + diffnb=statData[i][j-1].nextNotMissing-statData[i][j].prevNotMissing; + diffnbj=(j-1)-statData[i][j].prevNotMissing; + fact=(diffnbj+prevAnimPc.subVal)/diffnb; + y3=y1+fact*(y2-y1); + traceLine(pts,ctx,statData[i][j-1].xPos + prevAnimPc.subVal*(statData[i][j].xPos-statData[i][j-1].xPos) , y3,config,data,statData,i); + closebz(pts,ctx,config,i); +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + ctx.strokeStyle = "rgba(0,0,0,0)"; + if(config.datasetFill) { + ctx.lineTo(statData[i][j-1].xPos + prevAnimPc.subVal*(statData[i][j].xPos-statData[i][j-1].xPos) , statData[i][j].yAxisPos ); + ctx.lineTo(statData[i][firstpt].xPos, statData[i][firstpt].xAxisPosY-statData[i][0].zeroY); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc.mainVal, xPosLeft : statData[i][0].xPos, yPosBottom : Math.max(statData[i][0].yAxisPos,statData[i][0].yAxisPos- ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lminvalue_offset), xPosRight : statData[i][data.datasets[i].data.length-1].xPos, yPosTop : Math.min(statData[i][0].yAxisPos, statData[i][0].yAxisPos - ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lmaxvalue_offset)} ); + ctx.fill(); + firstpt=-1; + } + } else if (!(typeof statData[i][j].value == "undefined")) { + traceLine(pts,ctx,statData[i][j-1].xPos + prevAnimPc.subVal*(statData[i][j].xPos-statData[i][j-1].xPos) , statData[i][j].yAxisPos - prevAnimPc.mainVal*statData[i][statData[i][j-1].nextNotMissing].yPosOffset,config,data,statData,i); + closebz(pts,ctx,config,i); +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + ctx.strokeStyle = "rgba(0,0,0,0)"; + if(config.datasetFill) { + ctx.lineTo(statData[i][j-1].xPos + prevAnimPc.subVal*(statData[i][j].xPos-statData[i][j-1].xPos) , statData[i][j].yAxisPos ); + ctx.lineTo(statData[i][firstpt].xPos, statData[i][firstpt].xAxisPosY-statData[i][0].zeroY); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc.mainVal, xPosLeft : statData[i][0].xPos, yPosBottom : Math.max(statData[i][0].yAxisPos,statData[i][0].yAxisPos- ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lminvalue_offset), xPosRight : statData[i][data.datasets[i].data.length-1].xPos, yPosTop : Math.min(statData[i][0].yAxisPos, statData[i][0].yAxisPos - ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lmaxvalue_offset)} ); + ctx.fill(); + } + } + prevAnimPc = currentAnimPc; + continue; + } else if(currentAnimPc.totVal ==0) { +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + ctx.strokeStyle = "rgba(0,0,0,0)"; + } else { +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + } + + prevAnimPc = currentAnimPc; + + switch(typeof data.datasets[i].data[j]) { + case "undefined" : + if (!config.extrapolateMissingData) { + if(firstpt==-1) continue; + closebz(pts,ctx,config,i); +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + if (config.datasetFill && firstpt != -1) { + lastxPos=-1; + ctx.strokeStyle = "rgba(0,0,0,0)"; + ctx.lineTo(statData[i][j-1].xPos, statData[i][j-1].yAxisPos); + ctx.lineTo(statData[i][firstpt].xPos, statData[i][firstpt].yAxisPos); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,j,{animationValue: currentAnimPc.mainVal, xPosLeft : statData[i][0].xPos, yPosBottom : Math.max(statData[i][0].yAxisPos,statData[i][0].yAxisPos- ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lminvalue_offset), xPosRight : statData[i][data.datasets[i].data.length-1].xPos, yPosTop : Math.min(statData[i][0].yAxisPos, statData[i][0].yAxisPos - ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lmaxvalue_offset)} ); + ctx.fill(); + } + ctx.beginPath(); + prevAnimPc={ mainVal:0 , subVal : 0 }; + firstpt=-1; + } else if (currentAnimPc.subVal > 0) { + lastxPos=statData[i][j].xPos + currentAnimPc.subVal*(statData[i][j+1].xPos-statData[i][j].xPos); + y1=statData[i][statData[i][j+1].prevNotMissing].yAxisPos - statData[i][statData[i][j+1].prevNotMissing].yPosOffset; + y2=statData[i][statData[i][j].nextNotMissing].yAxisPos - statData[i][statData[i][j].nextNotMissing].yPosOffset; + diffnb=statData[i][j].nextNotMissing-statData[i][j+1].prevNotMissing; + diffnbj=(j)-statData[i][j+1].prevNotMissing; + fact=(diffnbj+prevAnimPc.subVal)/diffnb; + y3=y1+fact*(y2-y1); + traceLine(pts,ctx,statData[i][j].xPos + currentAnimPc.subVal*(statData[i][j+1].xPos-statData[i][j].xPos), y3,config,data,statData,i); + } + break; + default : + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.datasetStrokeWidth); + if (firstpt==-1) { + firstpt=j; + ctx.beginPath(); + ctx.moveTo(statData[i][j].xPos, statData[i][j].yAxisPos - currentAnimPc.mainVal * statData[i][j].yPosOffset); + initbz(pts,statData[i][j].xPos, statData[i][j].yAxisPos - currentAnimPc.mainVal * statData[i][j].yPosOffset,i); + lastxPos=statData[i][j].xPos; + } else { + lastxPos=statData[i][j].xPos; + traceLine(pts,ctx,statData[i][j].xPos, statData[i][j].yAxisPos - currentAnimPc.mainVal * statData[i][j].yPosOffset,config,data,statData,i); + } + + if (currentAnimPc.subVal > 0 && statData[i][j].nextNotMissing !=-1 && (config.extrapolateMissing || statData[i][j].nextNotMissing==j+1)) { + lastxPos=statData[i][j].xPos + currentAnimPc.subVal*(statData[i][j+1].xPos-statData[i][j].xPos); + y1=statData[i][statData[i][j+1].prevNotMissing].yAxisPos - statData[i][statData[i][j+1].prevNotMissing].yPosOffset; + y2=statData[i][statData[i][j].nextNotMissing].yAxisPos - statData[i][statData[i][j].nextNotMissing].yPosOffset; + y3=y1+currentAnimPc.subVal*(y2-y1); + traceLine(pts,ctx,statData[i][j].xPos + currentAnimPc.subVal*(statData[i][j+1].xPos-statData[i][j].xPos), y3,config,data,statData,i); + } + break + } + } + closebz(pts,ctx,config,i); +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + ctx.stroke(); + ctx.setLineDash([]); + if (config.datasetFill) { + if (firstpt>=0 ) { + ctx.strokeStyle = "rgba(0,0,0,0)"; + ctx.lineTo(lastxPos, statData[i][0].xAxisPosY-statData[i][0].zeroY); + ctx.lineTo(statData[i][firstpt].xPos, statData[i][firstpt].xAxisPosY-statData[i][0].zeroY); + ctx.closePath(); + ctx.fillStyle=setOptionValue(1,"COLOR",ctx,data,statData,data.datasets[i].fillColor,config.defaultFillColor,i,-1,{animationValue: currentAnimPc.mainVal, xPosLeft : statData[i][0].xPos, yPosBottom : Math.max(statData[i][0].yAxisPos,statData[i][0].yAxisPos- ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lminvalue_offset), xPosRight : statData[i][data.datasets[i].data.length-1].xPos, yPosTop : Math.min(statData[i][0].yAxisPos, statData[i][0].yAxisPos - ((config.animationLeftToRight) ? 1 : 1*currentAnimPc.mainVal) * statData[i][0].lmaxvalue_offset)} ); + ctx.fill(); + } + } + ctx.restore(); + if (config.pointDot && animPc >= 1) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (!(typeof(data.datasets[i].data[j]) == 'undefined')) { + currentAnimPc = animationCorrection(animPc, data, config, i, j, 0); + if (currentAnimPc.mainVal > 0 || !config.animationLeftToRight) { + ctx.beginPath(); + ctx.fillStyle=setOptionValue(1,"MARKERFILLCOLOR",ctx,data,statData,data.datasets[i].pointColor,config.defaultStrokeColor,i,j,{nullvalue: true} ); + ctx.strokeStyle=setOptionValue(1,"MARKERSTROKESTYLE",ctx,data,statData,data.datasets[i].pointStrokeColor,config.defaultStrokeColor,i,j,{nullvalue: true} ); + ctx.lineWidth=setOptionValue(ctx.chartLineScale,"MARKERLINEWIDTH",ctx,data,statData,data.datasets[i].pointDotStrokeWidth,config.pointDotStrokeWidth,i,j,{nullvalue: true} ); + var markerShape=setOptionValue(1,"MARKERSHAPE",ctx,data,statData,data.datasets[i].markerShape,config.markerShape,i,j,{nullvalue: true} ); + var markerRadius=setOptionValue(ctx.chartSpaceScale,"MARKERRADIUS",ctx,data,statData,data.datasets[i].pointDotRadius,config.pointDotRadius,i,j,{nullvalue: true} ); + var markerStrokeStyle=setOptionValue(1,"MARKERSTROKESTYLE",ctx,data,statData,data.datasets[i].pointDotStrokeStyle,config.pointDotStrokeStyle,i,j,{nullvalue: true} ); + drawMarker(ctx, statData[i][j].xPos , statData[i][j].yAxisPos - currentAnimPc.mainVal * statData[i][j].yPosOffset, markerShape,markerRadius,markerStrokeStyle); + } + } + } + } + + if (animPc >= config.animationStopValue) { + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; + if(setOptionValue(1,"ANNOTATEDISPLAY",ctx,data,statData,undefined,config.annotateDisplay,i,j,{nullValue : true})) { + jsGraphAnnotate[ctx.ChartNewId][jsGraphAnnotate[ctx.ChartNewId].length] = ["POINT", i, j, statData]; + } + if (setOptionValue(1,"INGRAPHDATASHOW",ctx,data,statData,undefined,config.inGraphDataShow,i,j,{nullValue : true})) { + ctx.save(); + ctx.textAlign = setOptionValue(1,"INGRAPHDATAALIGN",ctx,data,statData,undefined,config.inGraphDataAlign,i,j,{nullValue: true }); + ctx.textBaseline = setOptionValue(1,"INGRAPHDATAVALIGN",ctx,data,statData,undefined,config.inGraphDataVAlign,i,j,{nullValue : true} ); + ctx.font = setOptionValue(1,"INGRAPHDATAFONTSTYLE",ctx,data,statData,undefined,config.inGraphDataFontStyle,i,j,{nullValue : true} ) + ' ' + setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ) + 'px ' + setOptionValue(1,"INGRAPHDATAFONTFAMILY",ctx,data,statData,undefined,config.inGraphDataFontFamily,i,j,{nullValue : true} ); + ctx.fillStyle = setOptionValue(1,"INGRAPHDATAFONTCOLOR",ctx,data,statData,undefined,config.inGraphDataFontColor,i,j,{nullValue : true} ); + var paddingTextX = setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGX",ctx,data,statData,undefined,config.inGraphDataPaddingX,i,j,{nullValue : true} ), + paddingTextY = setOptionValue(ctx.chartSpaceScale,"INGRAPHDATAPADDINGY",ctx,data,statData,undefined,config.inGraphDataPaddingY,i,j,{nullValue : true} ); + var dispString = tmplbis(setOptionValue(1,"INGRAPHDATATMPL",ctx,data,statData,undefined,config.inGraphDataTmpl,i,j,{nullValue : true} ), statData[i][j],config); + ctx.translate(statData[i][j].xPos + paddingTextX, statData[i][j].yAxisPos - currentAnimPc.mainVal * statData[i][j].yPosOffset - paddingTextY); + ctx.rotate(setOptionValue(1,"INGRAPHDATAROTATE",ctx,data,statData,undefined,config.inGraphDataRotate,i,j,{nullValue : true} ) * (Math.PI / 180)); + setTextBordersAndBackground(ctx,dispString,setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),0,0,setOptionValue(1,"INGRAPHDATABORDERS",ctx,data,statData,undefined,config.inGraphDataBorders,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSCOLOR",ctx,data,statData,undefined,config.inGraphDataBordersColor,i,j,{nullValue : true} ),setOptionValue(ctx.chartLineScale,"INGRAPHDATABORDERSWIDTH",ctx,data,statData,undefined,config.inGraphDataBordersWidth,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSXSPACE",ctx,data,statData,undefined,config.inGraphDataBordersXSpace,i,j,{nullValue : true} ),setOptionValue(ctx.chartSpaceScale,"INGRAPHDATABORDERSYSPACE",ctx,data,statData,undefined,config.inGraphDataBordersYSpace,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABORDERSSTYLE",ctx,data,statData,undefined,config.inGraphDataBordersStyle,i,j,{nullValue : true} ),setOptionValue(1,"INGRAPHDATABACKGROUNDCOLOR",ctx,data,statData,undefined,config.inGraphDataBackgroundColor,i,j,{nullValue : true} ),"INGRAPHDATA"); + ctx.fillTextMultiLine(dispString, 0, 0, ctx.textBaseline, setOptionValue(ctx.chartTextScale,"INGRAPHDATAFONTSIZE",ctx,data,statData,undefined,config.inGraphDataFontSize,i,j,{nullValue : true} ),true); + ctx.restore(); + } + } + } + }; + + + + function initbz(pts,xpos,ypos,i) { + if (setOptionValue(1,"BEZIERCURVE",ctx,data,statData,undefined,config.bezierCurve,i,-1,{nullValue : true})) { + pts.length=0; + pts.push(xpos);pts.push(ypos); + } + } ; + + function traceLine(pts,ctx,xpos,ypos,config,data,statData,i) { + if (setOptionValue(1,"BEZIERCURVE",ctx,data,statData,undefined,config.bezierCurve,i,-1,{nullValue : true})) { + pts.push(xpos); pts.push(ypos); + } else { + ctx.lineTo(xpos,ypos); + } + } ; + + function closebz(pts,ctx,config,i){ + + if(setOptionValue(1,"BEZIERCURVE",ctx,data,statData,undefined,config.bezierCurve,i,-1,{nullValue : true})) { + minimumpos= statData[i][0].xAxisPosY; + maximumpos= statData[i][0].xAxisPosY - statData[i][0].calculatedScale.steps*statData[i][0].scaleHop; + drawSpline(ctx,pts,setOptionValue(1,"BEZIERCURVETENSION",ctx,data,statData,undefined,config.bezierCurveTension,i,-1,{nullValue : true}),minimumpos,maximumpos); + pts.length=0; + } + }; + + //Props to Rob Spencer at scaled innovation for his post on splining between points + //http://scaledinnovation.com/analytics/splines/aboutSplines.html + + function getControlPoints(x0,y0,x1,y1,x2,y2,t){ + // x0,y0,x1,y1 are the coordinates of the end (knot) pts of this segment + // x2,y2 is the next knot -- not connected here but needed to calculate p2 + // p1 is the control point calculated here, from x1 back toward x0. + // p2 is the next control point, calculated here and returned to become the + // next segment's p1. + // t is the 'tension' which controls how far the control points spread. + + // Scaling factors: distances from this knot to the previous and following knots. + var d01=Math.sqrt(Math.pow(x1-x0,2)+Math.pow(y1-y0,2)); + var d12=Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)); + + var fa=t*d01/(d01+d12); + var fb=t-fa; + + var p1x=x1+fa*(x0-x2); + var p1y=y1+fa*(y0-y2); + + var p2x=x1-fb*(x0-x2); + var p2y=y1-fb*(y0-y2); + + return [p1x,p1y,p2x,p2y] + }; + + function drawSpline(ctx,pts,t,minimumpos,maximumpos){ + var cp=[]; // array of control points, as x0,y0,x1,y1,... + var n=pts.length; + + pts.push(2*pts[n-2]-pts[n-4]); + pts.push(2*pts[n-1]-pts[n-3]); + + if (n==4){ + ctx.moveTo(pts[0],pts[1]); + ctx.lineTo(pts[2],pts[3]); + return; + } + // Draw an open curve, not connected at the ends + for(var ti=0;ti<n-2;ti+=2){ + cp=cp.concat(getControlPoints(pts[ti],pts[ti+1],pts[ti+2],pts[ti+3],pts[ti+4],pts[ti+5],t)); + } + // For first is a simple quadratics. + + ctx.beginPath(); + ctx.strokeStyle=setOptionValue(1,"STROKECOLOR",ctx,data,statData,data.datasets[i].strokeColor,config.defaultStrokeColor,i,j,{nullvalue : null} ); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.datasetStrokeWidth); + ctx.moveTo(pts[0],pts[1]); + ctx.quadraticCurveTo(cp[0],Math.max(Math.min(cp[1],minimumpos),maximumpos),pts[2],pts[3]); + +// ctx.setLineDash(lineStyleFn(config.datasetStrokeStyle)); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LINEDASH",ctx,data,statData,data.datasets[i].datasetStrokeStyle,config.datasetStrokeStyle,i,j,{nullvalue : null} ))); + for(ti=2;ti<pts.length-3;ti+=2){ + y1=Math.max(Math.min(cp[2*ti-1],minimumpos),maximumpos); + y2=Math.max(Math.min(cp[2*ti+1],minimumpos),maximumpos); + ctx.bezierCurveTo(cp[2*ti-2],y1,cp[2*ti],y2,pts[ti+2],pts[ti+3]); + } + ctx.stroke(); + }; + ctx.setLineDash([]); + }; + + function log10(val) { + return Math.log(val) / Math.LN10; + }; + + function setRect(ctx, config) { + if (config.clearRect) { + if (!config.multiGraph) { + clear(ctx); + ctx.clearRect(0, 0, width, height); + } + } else { + clear(ctx); + ctx.clearRect(0, 0, width, height); + + ctx.fillStyle = config.savePngBackgroundColor; + ctx.strokeStyle = config.savePngBackgroundColor; + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(0, ctx.canvas.height); + ctx.lineTo(ctx.canvas.width, ctx.canvas.height); + ctx.lineTo(ctx.canvas.width, 0); + ctx.lineTo(0, 0); + ctx.stroke(); + ctx.fill(); + } + }; + + function defMouse(ctx, data, config) { + var todoannotate=false; + if(typeof config.annotateDisplay=="function") { todoannotate=true; + } else if(typeof config.annotateDisplay == "object") { + for(var j=0;j<config.annotateDisplay.length;j++) if (config.annotateDisplay[j]) todoannotate=true; + } else todoannotage=config.annotateDisplay; + + if (isBooleanOptionTrue(undefined,config.annotateDisplay)) { + if (cursorDivCreated == false) oCursor = new makeCursorObj('divCursor'); + if (isIE() < 9 && isIE() != false) ctx.canvas.attachEvent("on" + config.annotateFunction.split(' ')[0], function(event) { + if ((config.annotateFunction.split(' ')[1] == "left" && event.which == 1) || + (config.annotateFunction.split(' ')[1] == "middle" && event.which == 2) || + (config.annotateFunction.split(' ')[1] == "right" && event.which == 3) || + (typeof(config.annotateFunction.split(' ')[1]) != "string")) doMouseAction(config, ctx, event, data, "annotate", config.mouseDownRight) + }); + else ctx.canvas.addEventListener(config.annotateFunction.split(' ')[0], function(event) { + if ((config.annotateFunction.split(' ')[1] == "left" && event.which == 1) || + (config.annotateFunction.split(' ')[1] == "middle" && event.which == 2) || + (config.annotateFunction.split(' ')[1] == "right" && event.which == 3) || + (typeof(config.annotateFunction.split(' ')[1]) != "string")) doMouseAction(config, ctx, event, data, "annotate", config.mouseDownRight) + }, false); + } + if (config.savePng) { + if (isIE() < 9 && isIE() != false) ctx.canvas.attachEvent("on" + config.savePngFunction.split(' ')[0], function(event) { + if ((config.savePngFunction.split(' ')[1] == "left" && event.which == 1) || + (config.savePngFunction.split(' ')[1] == "middle" && event.which == 2) || + (config.savePngFunction.split(' ')[1] == "right" && event.which == 3) || + (typeof(config.savePngFunction.split(' ')[1]) != "string")) saveCanvas(ctx, data, config); + }); + else ctx.canvas.addEventListener(config.savePngFunction.split(' ')[0], function(event) { + if ((config.savePngFunction.split(' ')[1] == "left" && event.which == 1) || + (config.savePngFunction.split(' ')[1] == "middle" && event.which == 2) || + (config.savePngFunction.split(' ')[1] == "right" && event.which == 3) || + (typeof(config.savePngFunction.split(' ')[1]) != "string")) saveCanvas(ctx, data, config); + }, false); + } + + if (isIE() < 9 && isIE() != false) ctx.canvas.attachEvent("onmousewheel", function(event) { + if (cursorDivCreated) document.getElementById('divCursor').style.display = 'none'; + }); + else ctx.canvas.addEventListener("DOMMouseScroll", function(event) { + if (cursorDivCreated) document.getElementById('divCursor').style.display = 'none'; + }, false); + + function add_event_listener(type, func, chk) + { + if(typeof func != 'function') + return; + + function do_func(event) { + if (chk == null || chk(event)) doMouseAction(config,ctx,event,data,"mouseaction",func); + }; + + var hash = type+' '+func.name; + if(hash in ctx._eventListeners) { + if(ctx.canvas.removeEventListener) + ctx.canvas.removeEventListener(type, ctx._eventListeners[hash]); + else if(ctx.canvas.detachEvent) + ctx.canvas.detachEvent(type, ctx._eventListeners[hash]); + } + + ctx._eventListeners[hash] = do_func; + + if(ctx.canvas.addEventListener) { + if(type=="mousewheel") type="DOMMouseScroll"; + ctx.canvas.addEventListener(type, do_func, false); + } else if(ctx.canvas.attachEvent) { + ctx.canvas.attachEvent("on"+type, do_func); + } + }; + + add_event_listener("mousedown", config.mouseDownLeft, function(e) { return e.which == 1; }); + add_event_listener("mousedown", config.mouseDownMiddle, function(e) { return e.which == 2; }); + add_event_listener("mousedown", config.mouseDownRight, function(e) { return e.which == 3; }); + add_event_listener("mousemove", config.mouseMove); + add_event_listener("mouseout", config.mouseOut); + add_event_listener("mousewheel", config.mouseWheel); + }; +}; + + + +function animationCorrection(animationValue, data, config, vdata, vsubdata, addone) { + var animValue = animationValue; + var animSubValue = 0; + if (vsubdata != -1) { + if (animValue < 1 && (vdata < (config.animationStartWithDataset - 1) && (config.animationStartWithDataset - 1) != -1)) { + animValue = 1; + } + if (animValue < 1 && (vsubdata < (config.animationStartWithData - 1) && (config.animationStartWithData - 1) != -1)) { + animValue = 1; + } + var totreat = 1; + var newAnimationValue = animationValue; + if (animValue < 1 && config.animationByDataset) { + animValue = 0; + totreat = 0; + var startDataset = (config.animationStartWithDataset - 1); + if ((config.animationStartWithDataset - 1) == -1) startDataset = 0 + var nbstepsperdatasets = config.animationSteps / (data.datasets.length - startDataset); + if (animationValue >= (vdata - startDataset + 1) * nbstepsperdatasets / config.animationSteps) animValue = 1; + else if (animationValue >= (vdata - startDataset) * nbstepsperdatasets / config.animationSteps) { + var redAnimationValue = animationValue - (vdata - startDataset) * nbstepsperdatasets / config.animationSteps; + if (!config.animationLeftToRight) { + animValue = redAnimationValue * (data.datasets.length - startDataset); + } else { + newAnimationValue = redAnimationValue * (data.datasets.length - startDataset); + } + totreat = 1; + } + } + if (totreat == 1 && animValue < 1 && config.animationLeftToRight) { + animValue = 0; + var startSub = (config.animationStartWithData - 1); + if ((config.animationStartWithData - 1) == -1) startSub = 0 + var nbstepspervalue = config.animationSteps / (data.datasets[vdata].data.length - startSub - 1 + addone); + if (newAnimationValue >= (vsubdata - startSub) * nbstepspervalue / config.animationSteps) { + animValue = 1; + if (newAnimationValue <= (vsubdata + 1 - startSub) * nbstepspervalue / config.animationSteps) { + animSubValue = (data.datasets[vdata].data.length - startSub - 1) * (newAnimationValue - ((vsubdata - startSub) * nbstepspervalue / config.animationSteps)); + } + } + } + } else { + if (animValue < 1 && (vdata < (config.animationStartWithData - 1))) { + animValue = 1; + } + } + return { + mainVal: animValue, + subVal: animSubValue, + animVal: animValue + animSubValue + }; +}; + + +function drawLegend(legendMsr,data,config,ctx,typegraph) { + if (config.legendBorders == true) { + ctx.save(); + ctx.setLineDash(lineStyleFn(config.legendBordersStyle)); + ctx.beginPath(); + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.legendBordersWidth); + ctx.strokeStyle = config.legendBordersColors; + ctx.moveTo(legendMsr.xLegendBorderPos, legendMsr.yLegendBorderPos); + ctx.lineTo(legendMsr.xLegendBorderPos, legendMsr.yLegendBorderPos + legendMsr.legendBorderHeight); + ctx.lineTo(legendMsr.xLegendBorderPos + legendMsr.legendBorderWidth, legendMsr.yLegendBorderPos + legendMsr.legendBorderHeight); + ctx.lineTo(legendMsr.xLegendBorderPos + legendMsr.legendBorderWidth, legendMsr.yLegendBorderPos); + ctx.lineTo(legendMsr.xLegendBorderPos, legendMsr.yLegendBorderPos); + //ctx.lineTo(legendMsr.xLegendBorderPos + legendMsr.legendBorderWidth, legendMsr.yLegendBorderPos); + //ctx.lineTo(legendMsr.xLegendBorderPos, legendMsr.yLegendBorderPos); + //ctx.lineTo(legendMsr.xLegendBorderPos, legendMsr.yLegendBorderPos + legendMsr.legendBorderHeight); + + + ctx.stroke(); + ctx.closePath(); + ctx.setLineDash([]); + + ctx.fillStyle = "rgba(0,0,0,0)"; // config.legendFillColor; + ctx.fillStyle = config.legendFillColor; + ctx.fill(); + ctx.restore(); + } + nbcols = legendMsr.nbLegendCols - 1; + ypos = legendMsr.yFirstLegendTextPos - ((Math.ceil(ctx.chartTextScale*config.legendFontSize)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextVertical)); + xpos = 0; + if (legendMsr.drawLegendOnData) fromi = data.datasets.length; + else fromi = data.length; + for (var i = fromi - 1; i >= 0; i--) { + orderi = i; + if (legendMsr.reverseLegend) { + if (legendMsr.drawLegendOnData) orderi = data.datasets.length - i - 1; + else orderi = data.length - i - 1; + } + if (legendMsr.drawLegendOnData) tpof = typeof(data.datasets[orderi].title); + else tpof = typeof(data[orderi].title) + if (tpof == "string") { + if (legendMsr.drawLegendOnData) lgtxt = fmtChartJS(config, data.datasets[orderi].title, config.fmtLegend).trim(); + else lgtxt = fmtChartJS(config, data[orderi].title, config.fmtLegend).trim(); + if (lgtxt != "") { + nbcols++; + if (nbcols == legendMsr.nbLegendCols) { + nbcols = 0; + xpos = legendMsr.xFirstLegendTextPos; + ypos += (Math.ceil(ctx.chartTextScale*config.legendFontSize)) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextVertical); + } else { + xpos += legendMsr.widestLegend + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenTextHorizontal); + } + ctx.save(); + ctx.beginPath(); + var lgdbox=legendMsr.legendBox; + if(ctx.tpchart=="Bar") if (data.datasets[orderi].type=="Line" && !config.datasetFill) lgdbox=false; + if (lgdbox) { + ctx.lineWidth = Math.ceil(ctx.chartLineScale*config.datasetStrokeWidth); + ctx.beginPath(); + if (legendMsr.drawLegendOnData) { + ctx.strokeStyle=setOptionValue(1,"LEGENDSTROKECOLOR",ctx,data,undefined,data.datasets[orderi].strokeColor,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LEGENDLINEDASH",ctx,data,undefined,data.datasets[orderi].datasetStrokeStyle,config.datasetStrokeStyle,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ))); + + } else { + ctx.strokeStyle=setOptionValue(1,"LEGENDSTROKECOLOR",ctx,data,undefined,data[orderi].strokeColor,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LEGENDSEGMENTTROKESTYLE",ctx,data,undefined,data[orderi].segmentStrokeStyle,config.segmentStrokeStyle,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ))); + } + ctx.moveTo(xpos, ypos); + ctx.lineTo(xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), ypos); + ctx.lineTo(xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))); + ctx.lineTo(xpos, ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))); + ctx.lineTo(xpos, ypos); + ctx.stroke(); + ctx.closePath(); + if (legendMsr.drawLegendOnData) { + ctx.fillStyle=setOptionValue(1,"LEGENDFILLCOLOR",ctx,data,undefined,data.datasets[orderi].fillColor,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + } else { + ctx.fillStyle=setOptionValue(1,"LEGENDFILLCOLOR",ctx,data,undefined,data[orderi].color,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + } + ctx.fill(); + } else { + ctx.lineWidth = config.legendColorIndicatorStrokeWidth ? + config.legendColorIndicatorStrokeWidth : Math.ceil(ctx.chartLineScale*config.datasetStrokeWidth); + if (config.legendColorIndicatorStrokeWidth && config.legendColorIndicatorStrokeWidth > (Math.ceil(ctx.chartTextScale*config.legendFontSize))) { + ctx.lineWidth = (Math.ceil(ctx.chartTextScale*config.legendFontSize)); + } + if (legendMsr.drawLegendOnData) { + ctx.strokeStyle=setOptionValue(1,"LEGENDSTROKECOLOR",ctx,data,undefined,data.datasets[orderi].strokeColor,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LEGENDLINEDASH",ctx,data,undefined,data.datasets[orderi].datasetStrokeStyle,config.datasetStrokeStyle,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ))); + } else { + ctx.strokeStyle=setOptionValue(1,"LEGENDSTROKECOLOR",ctx,data,undefined,data[orderi].strokeColor,config.defaultFillColor,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ); + ctx.setLineDash(lineStyleFn(setOptionValue(1,"LEGENDSEGMENTTROKESTYLE",ctx,data,undefined,data[orderi].segmentStrokeStyle,config.segmentStrokeStyle,orderi,-1,{animationValue: 1, xPosLeft : xpos, yPosBottom : ypos, xPosRight : xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize), yPosTop : ypos - (Math.ceil(ctx.chartTextScale*config.legendFontSize))} ))); + } + + ctx.moveTo(xpos + 2, ypos - ((Math.ceil(ctx.chartTextScale*config.legendFontSize)) / 2)); + ctx.lineTo(xpos + 2 + Math.ceil(ctx.chartTextScale*config.legendBlockSize), ypos - ((Math.ceil(ctx.chartTextScale*config.legendFontSize)) / 2)); + ctx.stroke(); + + + ctx.fill(); + + if(config.pointDot) { + ctx.beginPath(); + ctx.fillStyle=setOptionValue(1,"LEGENDMARKERFILLCOLOR",ctx,data,undefined,data.datasets[orderi].pointColor,config.defaultStrokeColor,orderi,-1,{nullvalue: true} ); + ctx.strokeStyle=setOptionValue(1,"LEGENDMARKERSTROKESTYLE",ctx,data,undefined,data.datasets[orderi].pointStrokeColor,config.defaultStrokeColor,orderi,-1,{nullvalue: true} ); + ctx.lineWidth=setOptionValue(ctx.chartLineScale,"LEGENDMARKERLINEWIDTH",ctx,data,undefined,data.datasets[orderi].pointDotStrokeWidth,config.pointDotStrokeWidth,orderi,-1,{nullvalue: true} ); + + var markerShape=setOptionValue(1,"LEGENDMARKERSHAPE",ctx,data,undefined,data.datasets[orderi].markerShape,config.markerShape,orderi,-1,{nullvalue: true} ); + var markerRadius=setOptionValue(ctx.chartSpaceScale,"LEGENDMARKERRADIUS",ctx,data,undefined,data.datasets[orderi].pointDotRadius,config.pointDotRadius,orderi,-1,{nullvalue: true} ); + var markerStrokeStyle=setOptionValue(1,"LEGENDMARKERSTROKESTYLE",ctx,data,undefined,data.datasets[orderi].pointDotStrokeStyle,config.pointDotStrokeStyle,orderi,-1,{nullvalue: true} ); + drawMarker(ctx,xpos + 2 + Math.ceil(ctx.chartTextScale*config.legendBlockSize)/2, ypos - ((Math.ceil(ctx.chartTextScale*config.legendFontSize)) / 2), markerShape,markerRadius,markerStrokeStyle); + } + ctx.fill(); + + } + ctx.restore(); + ctx.save(); + ctx.beginPath(); + ctx.font = config.legendFontStyle + " " + (Math.ceil(ctx.chartTextScale*config.legendFontSize)).toString() + "px " + config.legendFontFamily; + ctx.fillStyle = setOptionValue(1,"LEGENDFONTCOLOR",ctx,data,undefined,undefined,config.legendFontColor,orderi,-1,{nullvalue: true} ); + ctx.textAlign = "left"; + ctx.textBaseline = "bottom"; + ctx.translate(xpos + Math.ceil(ctx.chartTextScale*config.legendBlockSize) + Math.ceil(ctx.chartSpaceScale*config.legendSpaceBetweenBoxAndText), ypos); + ctx.fillText(lgtxt, 0, 0); + ctx.restore(); + } + } + } +}; + +function drawMarker(ctx,xpos,ypos,marker,markersize,markerStrokeStyle) { + ctx.setLineDash(lineStyleFn(markerStrokeStyle)); + switch (marker) { + case "square": + ctx.rect(xpos-markersize,ypos-markersize,2*markersize,2*markersize); + ctx.stroke(); + ctx.fill(); + ctx.setLineDash([]); + break; + case "triangle": + pointA_x=0; + pointA_y=2/3*markersize; + ctx.moveTo(xpos,ypos-pointA_y); + ctx.lineTo(xpos+pointA_y*Math.sin(4/3),ypos+pointA_y*Math.cos(4/3)); + ctx.lineTo(xpos-pointA_y*Math.sin(4/3),ypos+pointA_y*Math.cos(4/3)); + ctx.lineTo(xpos,ypos-pointA_y); + ctx.stroke(); + ctx.fill(); + ctx.setLineDash([]); + break; + case "diamond": + ctx.moveTo(xpos, ypos+markersize); + ctx.lineTo(xpos+markersize, ypos); + ctx.lineTo(xpos, ypos-markersize); + ctx.lineTo(xpos-markersize, ypos); + ctx.lineTo(xpos, ypos+markersize); + ctx.stroke(); + ctx.fill(); + ctx.setLineDash([]); + break; + case "plus": + ctx.moveTo(xpos, ypos-markersize); + ctx.lineTo(xpos, ypos+markersize); + ctx.moveTo(xpos-markersize, ypos); + ctx.lineTo(xpos+markersize, ypos); + ctx.stroke(); + ctx.setLineDash([]); + break; + case "cross": + ctx.moveTo(xpos-markersize, ypos-markersize); + ctx.lineTo(xpos+markersize, ypos+markersize); + ctx.moveTo(xpos-markersize, ypos+markersize); + ctx.lineTo(xpos+markersize, ypos-markersize); + ctx.stroke(); + ctx.setLineDash([]); + break; + case "circle": + default: + ctx.arc(xpos, ypos, markersize, 0, 2*Math.PI * 1, true); + ctx.stroke(); + ctx.fill(); + ctx.setLineDash([]); + break; + } +}; + +function initPassVariableData_part1(data,config,ctx) { +var i,j,result, mxvalue ,mnvalue, cumvalue, totvalue,lmaxvalue,lminvalue,lgtxt,lgtxt2,tp,prevpos,firstNotMissingi,lastNotMissingi,firstNotMissingj,lastNotMissingj,grandtotal; +switch(ctx.tpchart) { + case "Pie" : + case "Doughnut" : + case "PolarArea" : + + result=[]; + var segmentAngle,cumulativeAngle,realCumulativeAngle; + + cumulativeAngle = (((-config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + realCumulativeAngle = (((config.startAngle * (Math.PI / 180) + 2 * Math.PI) % (2 * Math.PI)) + 2* Math.PI) % (2* Math.PI) ; + + startAngle=cumulativeAngle; + totvalue = 0; + notemptyval=0; + var firstNotMissing = -1; + var lastNotMissing = -1; + var prevNotMissing = -1; + mxvalue=-Number.MAX_VALUE; + mnvalue=Number.MAX_VALUE; + for (i = 0; i < data.length; i++) { + if(ctx.tpchart != "PolarArea" && 1*data[i].value<0)continue; + if (!(typeof(data[i].value) == 'undefined')) { + if(firstNotMissing==-1)firstNotMissing=i; + mxvalue=Math.max(mxvalue,1*data[i].value); + mnvalue=Math.min(mnvalue,1*data[i].value); + notemptyval++; + totvalue += 1 * data[i].value; + lastNotMissing=i; + } + } + + cumvalue=0; + var prevMissing=-1; + for(i=0;i<data.length;i++) { + if (typeof(data[i].title) == "string") lgtxt = data[i].title.trim(); + else lgtxt = ""; + if (!(typeof(data[i].value) == 'undefined') && (ctx.tpchart == "PolarArea" || 1*data[i].value>=0)) { + if(ctx.tpchart=="PolarArea") { if(notemptyval>0)segmentAngle= (Math.PI *2)/notemptyval; else segmentAngle=0; } + else segmentAngle = (1 * data[i].value / totvalue) * (Math.PI * 2); + if (segmentAngle >= Math.PI * 2) segmentAngle = Math.PI * 2 - 0.001; // bug on Android when segmentAngle is >= 2*PI; + cumvalue += 1 * data[i].value; + result[i]= { + config: config, + v1: fmtChartJS(config, lgtxt, config.fmtV1), + v2: fmtChartJS(config, 1 * data[i].value, config.fmtV2), + v3: fmtChartJS(config, cumvalue, config.fmtV3), + v4: fmtChartJS(config, totvalue, config.fmtV4), + v5: fmtChartJS(config, segmentAngle, config.fmtV5), + v6: roundToWithThousands(config, fmtChartJS(config, 100 * data[i].value / totvalue, config.fmtV6), config.roundPct), + v7 : 0, + v8 : 0, + v9 : 0, + v10 : 0, + v11: fmtChartJS(config, cumulativeAngle - segmentAngle, config.fmtV11), + v12: fmtChartJS(config, cumulativeAngle, config.fmtV12), + v13: fmtChartJS(config, i, config.fmtV13), + lgtxt: lgtxt, + datavalue: 1 * data[i].value, + cumvalue: cumvalue, + totvalue: totvalue, + segmentAngle: segmentAngle, + firstAngle : startAngle, + pctvalue: 100 * data[i].value / totvalue, + startAngle: cumulativeAngle, + realStartAngle : realCumulativeAngle, + endAngle: cumulativeAngle+segmentAngle, + maxvalue : mxvalue, + minvalue : mnvalue, + i: i, + firstNotMissing : firstNotMissing, + lastNotMissing : lastNotMissing, + prevNotMissing : prevNotMissing, + prevMissing : prevMissing, + nextNotMissing : -1, + radiusOffset : 0, + midPosX : 0, + midPosY : 0, + int_radius : 0, + ext_radius : 0, + data: data + }; + cumulativeAngle += segmentAngle; + realCumulativeAngle -= segmentAngle; + if(prevNotMissing != -1) result[prevNotMissing].nextNotMissing=i; + prevNotMissing = i; + } else { + result[i]={ + v1:lgtxt, + maxvalue : mxvalue, + minvalue : mnvalue, + i: i, + firstNotMissing : firstNotMissing, + lastNotMissing : lastNotMissing, + prevNotMissing : prevNotMissing + }; + prevMissing=i; + } + } + break; + case "Bar" : + case "Line" : + case "HorizontalBar" : + case "StackedBar" : + case "HorizontalStackedBar" : + case "Radar" : + var axis; + result=[]; + mxvalue=[]; + mxvalue[0]=[]; + mxvalue[1]=[]; + mnvalue=[]; + mnvalue[0]=[]; + mnvalue[1]=[]; + cumvalue=[]; + cumvalue[0]=[]; + cumvalue[1]=[]; + totvalue=[]; + totvalue[0]=[]; + totvalue[1]=[]; + lmaxvalue=[]; + lmaxvalue[0]=[]; + lmaxvalue[1]=[]; + lminvalue=[]; + lminvalue[0]=[]; + lminvalue[1]=[]; + prevpos=[]; + firstNotMissingi=[]; + lastNotMissingi=[]; + firstNotMissingj=[]; + lastNotMissingj=[]; + prevpos[0]=[]; + prevpos[1]=[]; + grandtotal=0; + + for (i = 0; i < data.datasets.length; i++) { + // BUG when all data are missing ! + if (typeof data.datasets[i].xPos != "undefined" && tpdraw(ctx,data.datasets[i])=="Line") { + for(j=data.datasets[i].data.length;j<data.datasets[i].xPos.length;j++)data.datasets[i].data.push(undefined); + } else { + for(j=data.datasets[i].data.length;j<data.labels.length;j++)data.datasets[i].data.push(undefined); + } + + + if(data.datasets[i].axis == 2) axis=0;else axis=1; + result[i]=[]; + lmaxvalue[0][i]=-Number.MAX_VALUE; + lmaxvalue[1][i]=-Number.MAX_VALUE; + lminvalue[0][i]=Number.MAX_VALUE; + lminvalue[1][i]=Number.MAX_VALUE; + firstNotMissingi[i]=-1; + lastNotMissingi[i]=-1; + for (j = 0; j < data.datasets[i].data.length; j++) { + + if(typeof firstNotMissingj[j]== "undefined"){ + firstNotMissingj[j]=-1; + lastNotMissingj[j]=-1; + totvalue[0][j] = 0; + mxvalue[0][j]=-Number.MAX_VALUE; + mnvalue[0][j]=Number.MAX_VALUE; + totvalue[1][j] = 0; + mxvalue[1][j]=-Number.MAX_VALUE; + mnvalue[1][j]=Number.MAX_VALUE; + } + if (!(typeof data.datasets[i].data[j] == 'undefined')) { + grandtotal += 1 * data.datasets[i].data[j]; + if(firstNotMissingi[i]==-1)firstNotMissingi[i]=j; + lastNotMissingi[i]=j; + if(firstNotMissingj[j]==-1)firstNotMissingj[j]=i; + lastNotMissingj[j]=i; + totvalue[axis][j] += 1 * data.datasets[i].data[j]; + mxvalue[axis][j] =Math.max(mxvalue[axis][j],1 * data.datasets[i].data[j]); + mnvalue[axis][j] =Math.min(mnvalue[axis][j],1 * data.datasets[i].data[j]); + lmaxvalue[axis][i] =Math.max(lmaxvalue[axis][i],1 * data.datasets[i].data[j]); + lminvalue[axis][i] =Math.min(lminvalue[axis][i],1 * data.datasets[i].data[j]); + } + } + } + + for (i = 0; i < data.datasets.length; i++) { + if(data.datasets[i].axis == 2) axis=0;else axis=1; + if (typeof(data.datasets[i].title) == "string") lgtxt = data.datasets[i].title.trim(); + else lgtxt = ""; + var prevnotemptyj=-1; + var prevemptyj=-1; + for (j = 0; j < data.datasets[i].data.length; j++) { + + if(typeof cumvalue[0][j]== "undefined"){cumvalue[0][j] = 0; prevpos[0][j]=-1;cumvalue[1][j] = 0; prevpos[1][j]=-1; } + lgtxt2 = ""; + if (typeof data.datasets[i].xPos != "undefined") { + if (!(typeof data.datasets[i].xPos[j] == "undefined")) lgtxt2 = data.datasets[i].xPos[j]; + } + if (lgtxt2 == "" && !(typeof(data.labels[j]) == "undefined")) lgtxt2 = data.labels[j]; + if (typeof lgtxt2 == "string") lgtxt2 = lgtxt2.trim(); + +// if (!(typeof(data.datasets[i].data[j]) == 'undefined') && data.datasets[i].data[j] != 0) { + if (!(typeof(data.datasets[i].data[j]) == 'undefined') ) { + cumvalue[axis][j]+=1*data.datasets[i].data[j]; + switch(tpdraw(ctx,data.datasets[i])) { + case "Bar" : + case "StackedBar" : + case "HorizontalBar" : + case "HorizontalStackedBar" : + result[i][j]= { + config: config, + v1: fmtChartJS(config, lgtxt, config.fmtV1), + v2: fmtChartJS(config, lgtxt2, config.fmtV2), + v3: fmtChartJS(config, 1 * data.datasets[i].data[j], config.fmtV3), + v4: fmtChartJS(config, cumvalue[axis][j], config.fmtV4), + v5: fmtChartJS(config, totvalue[axis][j], config.fmtV5), + v6: roundToWithThousands(config, fmtChartJS(config, 100 * data.datasets[i].data[j] / totvalue[axis][j], config.fmtV6), config.roundPct), + v6T: roundToWithThousands(config, fmtChartJS(config, 100 * data.datasets[i].data[j] / grandtotal, config.fmtV6T), config.roundPct), + v11: fmtChartJS(config, i, config.fmtV11), + v12: fmtChartJS(config, j, config.fmtV12), + lgtxt: lgtxt, + lgtxt2: lgtxt2, + datavalue: 1 * data.datasets[i].data[j], + cumvalue: cumvalue[axis][j], + totvalue: totvalue[axis][j], + pctvalue: 100 * data.datasets[i].data[j] / totvalue[axis][j], + pctvalueT: 100 * data.datasets[i].data[j] / grandtotal, + maxvalue : mxvalue[axis][j], + minvalue : mnvalue[axis][j], + lmaxvalue : lmaxvalue[axis][i], + lminvalue : lminvalue[axis][i], + grandtotal : grandtotal, + firstNotMissing : firstNotMissingj[j], + lastNotMissing : lastNotMissingj[j], + prevNotMissing : prevnotemptyj, + prevMissing : prevemptyj, + nextNotMissing : -1, + j: j, + i: i, + data: data + }; + if(1 * data.datasets[i].data[j]==0 && (tpdraw(ctx,data.datasets[i])=="HorizontalStackedBar" || tpdraw(ctx,data.datasets[i])=="StackedBar"))result[i][j].v3=""; + break; + case "Line" : + case "Radar" : + result[i][j]= { + config: config, + v1: fmtChartJS(config, lgtxt, config.fmtV1), + v2: fmtChartJS(config, lgtxt2, config.fmtV2), + v3: fmtChartJS(config, 1 * data.datasets[i].data[j], config.fmtV3), + v5: fmtChartJS(config, 1 * data.datasets[i].data[j], config.fmtV5), + v6: fmtChartJS(config, mxvalue[axis][j], config.fmtV6), + v7: fmtChartJS(config, totvalue[axis][j], config.fmtV7), + v8: roundToWithThousands(config, fmtChartJS(config, 100 * data.datasets[i].data[j] / totvalue[axis][j], config.fmtV8), config.roundPct), + v8T: roundToWithThousands(config, fmtChartJS(config, 100 * data.datasets[i].data[j] / grandtotal, config.fmtV8T), config.roundPct), + v11: fmtChartJS(config, i, config.fmtV11), + v12: fmtChartJS(config, j, config.fmtV12), + lgtxt: lgtxt, + lgtxt2: lgtxt2, + datavalue: 1 * data.datasets[i].data[j], + diffnext: 1 * data.datasets[i].data[j], + pctvalue: 100 * data.datasets[i].data[j] / totvalue[axis][j], + pctvalueT: 100 * data.datasets[i].data[j] / grandtotal, + totvalue : totvalue[axis][j], + cumvalue: cumvalue[axis][j], + maxvalue : mxvalue[axis][j], + minvalue : mnvalue[axis][j], + lmaxvalue : lmaxvalue[axis][i], + lminvalue : lminvalue[axis][i], + grandtotal : grandtotal, + firstNotMissing : firstNotMissingi[i], + lastNotMissing : lastNotMissingi[i], + prevNotMissing : prevnotemptyj, + prevMissing : prevemptyj, + nextNotMissing : -1, + j: j, + i: i, + data: data + }; + if(prevpos[axis][j]>=0){ + result[i][j].v4=fmtChartJS(config, (prevpos[axis][j] != -1 ? 1 * data.datasets[i].data[j]-result[prevpos[axis][j]][j].datavalue : 1 * data.datasets[i].data[j]), config.fmtV4); + result[i][j].diffprev=(prevpos[axis][j] != -1 ? 1 * data.datasets[i].data[j]-result[prevpos[axis][j]][j].datavalue : 1 * data.datasets[i].data[j]); + result[prevpos[axis][j]][j].diffnext=data.datasets[prevpos[axis][j]].data[j] - data.datasets[i].data[j]; + result[prevpos[axis][j]][j].v5=result[prevpos[axis][j]][j].diffnext; + } else { + result[i][j].v4=1 * data.datasets[i].data[j]; + + } + prevpos[axis][j]=i; + break; + default: + break; + } + if(!(typeof(data.datasets[i].data[j]) == 'undefined')) { + if(prevnotemptyj!= -1) {for(k=prevnotemptyj;k<j;k++) result[i][k].nextNotMissing=j;} + prevnotemptyj=j; + } + } else { + prevemptyj=j; + switch(tpdraw(ctx,data.datasets[i])) { + case "Bar" : + case "StackedBar" : + case "HorizontalBar" : + case "HorizontalStackedBar" : + result[i][j] ={ + v1:lgtxt, + lmaxvalue : lmaxvalue[axis][i], + lminvalue : lminvalue[axis][i], + firstNotMissing : firstNotMissingj[j], + lastNotMissing : lastNotMissingj[j], + prevNotMissing : prevnotemptyj, + prevMissing : prevemptyj, + grandtotal : grandtotal + }; + break; + case "Line" : + case "Radar" : + result[i][j] ={ + v1:lgtxt, + lmaxvalue : lmaxvalue[axis][i], + lminvalue : lminvalue[axis][i], + firstNotMissing : firstNotMissingi[i], + lastNotMissing : lastNotMissingi[i], + prevNotMissing : prevnotemptyj, + prevMissing : prevemptyj, + grandtotal : grandtotal + }; + break; + } + } + } + } + break; + default: + break; + } + + +return result; + +}; + +function initPassVariableData_part2(statData,data,config,ctx,othervars) { + +var realbars=0; +var i,j; +switch(ctx.tpchart) { + case "Pie" : + case "Doughnut" : + case "PolarArea" : + for(i=0;i<data.length;i++) { + statData[i].v7= fmtChartJS(config, othervars.midPosX, config.fmtV7); + statData[i].v8= fmtChartJS(config, othervars.midPosY, config.fmtV8), + statData[i].v9= fmtChartJS(config, othervars.int_radius, config.fmtV9); + statData[i].v10= fmtChartJS(config, othervars.ext_radius, config.fmtV10); + if(ctx.tpchart=="PolarArea") { + statData[i].radiusOffset= calculateOffset(config.logarithmic, 1 * data[i].value, othervars.calculatedScale, othervars.scaleHop); + statData[i].v10= fmtChartJS(config, statData[i].radiusOffset, config.fmtV10); + } + else { + statData[i].v10= fmtChartJS(config, othervars.ext_radius, config.fmtV10); + statData[i].radiusOffset=othervars.ext_radius; + } + statData[i].midPosX= othervars.midPosX; + statData[i].midPosY= othervars.midPosY; + statData[i].int_radius= othervars.int_radius; + statData[i].ext_radius= othervars.ext_radius; + } + break; + case "Radar" : + case "Line" : + case "Bar" : + case "StackedBar" : + case "HorizontalBar" : + case "HorizontalStackedBar" : + var tempp = new Array(data.datasets.length); + var tempn = new Array(data.datasets.length); + for (i = 0; i < data.datasets.length; i++) { + switch(tpdraw(ctx,data.datasets[i])) { + case "Line" : + for (j = 0; j < data.datasets[i].data.length; j++) { + statData[i][j].xAxisPosY = othervars.xAxisPosY; + statData[i][j].yAxisPosX = othervars.yAxisPosX; + statData[i][j].valueHop = othervars.valueHop; + statData[i][j].nbValueHop = othervars.nbValueHop; + if (data.datasets[i].axis == 2) { + statData[i][j].scaleHop = othervars.scaleHop2; + statData[i][j].zeroY = othervars.zeroY2; + statData[i][j].calculatedScale = othervars.calculatedScale2; + statData[i][j].logarithmic = othervars.logarithmic2; + } else { + statData[i][j].scaleHop = othervars.scaleHop; + statData[i][j].zeroY = othervars.zeroY; + statData[i][j].calculatedScale = othervars.calculatedScale; + statData[i][j].logarithmic = othervars.logarithmic; + } + statData[i][j].xPos=xPos(i,j,data,othervars.yAxisPosX,othervars.valueHop,othervars.nbValueHop); + statData[i][j].yAxisPos=othervars.xAxisPosY - statData[i][j].zeroY; + if(ctx.tpchart=="Bar") { + statData[i][j].xPos+=(othervars.valueHop/2); + statData[i][j].yAxisPosX += (othervars.valueHop/2); + } + if(j==0) { + statData[i][j].lmaxvalue_offset=calculateOffset(statData[i][j].logarithmic, statData[i][j].lmaxvalue, statData[i][j].calculatedScale, statData[i][j].scaleHop) - statData[i][j].zeroY; + statData[i][j].lminvalue_offset=calculateOffset(statData[i][j].logarithmic, statData[i][j].lminvalue, statData[i][j].calculatedScale, statData[i][j].scaleHop) - statData[i][j].zeroY; + } else { + statData[i][j].lmaxvalue_offset=statData[i][0].lmaxvalue_offset; + statData[i][j].lminvalue_offset=statData[i][0].lminvalue_offset; + } + + if (!(typeof(data.datasets[i].data[j]) == 'undefined')) { + statData[i][j].yPosOffset= calculateOffset(statData[i][j].logarithmic, data.datasets[i].data[j], statData[i][j].calculatedScale, statData[i][j].scaleHop) - statData[i][j].zeroY; + statData[i][j].posY=statData[i][j].yAxisPos - statData[i][j].yPosOffset; + } + statData[i][j].posX=statData[i][j].xPos; + statData[i][j].v9= statData[i][j].xPos; + statData[i][j].v10=statData[i][j].posY; + + statData[i][j].annotateStartPosX = statData[i][j].xPos; + statData[i][j].annotateEndPosX = statData[i][j].xPos; + statData[i][j].annotateStartPosY = othervars.xAxisPosY; + statData[i][j].annotateEndPosY = othervars.xAxisPosY-othervars.msr.availableHeight; + statData[i][j].D1A=undefined; + statData[i][j].D1B=undefined; + } + break; + case "Radar" : + var rotationDegree = (2 * Math.PI) / data.datasets[0].data.length; + for (j = 0; j < data.datasets[i].data.length; j++) { + statData[i][j].midPosX = othervars.midPosX; + statData[i][j].midPosY = othervars.midPosY; + statData[i][j].int_radius= 0; + statData[i][j].ext_radius= othervars.maxSize; + statData[i][j].radiusOffset= othervars.maxSize; + statData[i][j].calculated_offset= calculateOffset(config.logarithmic, data.datasets[i].data[j], othervars.calculatedScale, othervars.scaleHop); + statData[i][j].offsetX=Math.cos(config.startAngle * Math.PI / 180 - j * rotationDegree) * statData[i][j].calculated_offset; + statData[i][j].offsetY=Math.sin(config.startAngle * Math.PI / 180 - j * rotationDegree) * statData[i][j].calculated_offset; + statData[i][j].v9=statData[i][j].midPosX + statData[i][j].offsetX; + statData[i][j].v10=statData[i][j].midPosY - statData[i][j].offsetY; + statData[i][j].posX=statData[i][j].midPosX + statData[i][j].offsetX; + statData[i][j].posY=statData[i][j].midPosY - statData[i][j].offsetY; + if(j==0)statData[i][j].calculated_offset_max=calculateOffset(config.logarithmic, statData[i][j].lmaxvalue, othervars.calculatedScale, othervars.scaleHop); + else statData[i][j].calculated_offset_max=statData[0][j].calculated_offset_max; + statData[i][j].annotateStartPosX = othervars.midPosX; + statData[i][j].annotateEndPosX = othervars.midPosX+Math.cos(config.startAngle * Math.PI / 180 - j * rotationDegree) * othervars.maxSize; + statData[i][j].annotateStartPosY = othervars.midPosY; + statData[i][j].annotateEndPosY = othervars.midPosY-Math.sin(config.startAngle * Math.PI / 180 - j * rotationDegree) * othervars.maxSize; + if(Math.abs(statData[i][j].annotateStartPosX-statData[i][j].annotateEndPosX)<config.zeroValue) { + statData[i][j].D1A=undefined; + statData[i][j].D1B=undefined; + statData[i][j].D2A=0; + } else { + statData[i][j].D1A=(statData[i][j].annotateStartPosY-statData[i][j].annotateEndPosY)/(statData[i][j].annotateStartPosX-statData[i][j].annotateEndPosX); + statData[i][j].D1B=-statData[i][j].D1A*statData[i][j].annotateStartPosX+statData[i][j].annotateStartPosY; + if(Math.abs(statData[i][j].D1A)>=config.zeroValue)statData[i][j].D2A=-(1/statData[i][j].D1A); + else statData[i][j].D2A=undefined; + } + + } + break; + case "Bar" : + for (j = 0; j < data.datasets[i].data.length; j++) { + statData[i][j].xPosLeft= othervars.yAxisPosX + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) + othervars.valueHop * j + othervars.barWidth * realbars + Math.ceil(ctx.chartSpaceScale*config.barDatasetSpacing) * realbars + Math.ceil(ctx.chartLineScale*config.barStrokeWidth) * realbars; + statData[i][j].xPosRight = statData[i][j].xPosLeft + othervars.barWidth; + statData[i][j].yPosBottom =othervars.xAxisPosY - othervars.zeroY + statData[i][j].barHeight=calculateOffset(config.logarithmic, 1 * data.datasets[i].data[j], othervars.calculatedScale, othervars.scaleHop) - othervars.zeroY; + if (data.datasets[i].axis == 2) { + statData[i][j].yPosBottom =othervars.xAxisPosY - othervars.zeroY2; + statData[i][j].barHeight=calculateOffset(config.logarithmic2, 1 * data.datasets[i].data[j], othervars.calculatedScale2, othervars.scaleHop2) - othervars.zeroY2; + } else { + statData[i][j].yPosBottom =othervars.xAxisPosY - othervars.zeroY + statData[i][j].barHeight=calculateOffset(config.logarithmic, 1 * data.datasets[i].data[j], othervars.calculatedScale, othervars.scaleHop) - othervars.zeroY; + } + statData[i][j].yPosTop = statData[i][j].yPosBottom - statData[i][j].barHeight + (Math.ceil(ctx.chartLineScale*config.barStrokeWidth) / 2); + statData[i][j].v7=statData[i][j].xPosLeft; + statData[i][j].v8=statData[i][j].yPosBottom; + statData[i][j].v9=statData[i][j].xPosRight; + statData[i][j].v10=statData[i][j].yPosTop; + + } + realbars++; + break; + case "StackedBar" : + for (j = 0; j < data.datasets[i].data.length; j++) { + if (typeof tempp[j]=="undefined") { + tempp[j]=0; + tempn[j]=0; + zeroY= calculateOffset(config.logarithmic, 0 , othervars.calculatedScale, othervars.scaleHop); + } + if ((typeof data.datasets[i].data[j] == 'undefined')) continue; + statData[i][j].xPosLeft= othervars.yAxisPosX + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) + othervars.valueHop * j; + if (1*data.datasets[i].data[j]<0) { + statData[i][j].botval=tempn[j]; + statData[i][j].topval=tempn[j]+1*data.datasets[i].data[j] ; + tempn[j]=tempn[j]+1*data.datasets[i].data[j] ; + } else { + statData[i][j].botval=tempp[j]; + statData[i][j].topval=tempp[j]+1*data.datasets[i].data[j] ; + tempp[j]=tempp[j]+1*data.datasets[i].data[j] ; + } + statData[i][j].xPosRight = statData[i][j].xPosLeft + othervars.barWidth; + statData[i][j].botOffset = calculateOffset(config.logarithmic, statData[i][j].botval , othervars.calculatedScale, othervars.scaleHop); + statData[i][j].topOffset = calculateOffset(config.logarithmic, statData[i][j].topval , othervars.calculatedScale, othervars.scaleHop); + statData[i][j].yPosBottom =othervars.xAxisPosY - statData[i][j].botOffset; + statData[i][j].yPosTop = othervars.xAxisPosY - statData[i][j].topOffset; + // treat spaceBetweenBar + if(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar) > 0) + { + if(1*data.datasets[i].data[j]<0) { + statData[i][j].yPosBottom+=Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar); + if(tempn[j]==1*data.datasets[i].data[j])statData[i][j].yPosBottom-=(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar)/2); + if(statData[i][j].yPosTop<statData[i][j].yPosBottom)statData[i][j].yPosBottom=statData[i][j].yPosTop; + } else if (1*data.datasets[i].data[j]>0) { + statData[i][j].yPosBottom-=Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar); + if(tempp[j]==1*data.datasets[i].data[j])statData[i][j].yPosBottom+=(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar)/2); + if(statData[i][j].yPosTop>statData[i][j].yPosBottom)statData[i][j].yPosBottom=statData[i][j].yPosTop; + } + } + statData[i][j].v7=statData[i][j].xPosLeft; + statData[i][j].v8=statData[i][j].yPosBottom; + statData[i][j].v9=statData[i][j].xPosRight; + statData[i][j].v10=statData[i][j].yPosTop; + } + break; + case "HorizontalBar" : + for (j = 0; j < data.datasets[i].data.length; j++) { + statData[i][j].xPosLeft= othervars.yAxisPosX + othervars.zeroY; + statData[i][j].yPosTop=othervars.xAxisPosY + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) - othervars.scaleHop * (j + 1) + othervars.barWidth * i + Math.ceil(ctx.chartSpaceScale*config.barDatasetSpacing) * i + Math.ceil(ctx.chartLineScale*config.barStrokeWidth) * i; + statData[i][j].yPosBottom=statData[i][j].yPosTop+othervars.barWidth; + statData[i][j].barWidth = calculateOffset(config.logarithmic, 1 * data.datasets[i].data[j], othervars.calculatedScale, othervars.valueHop) - othervars.zeroY; + statData[i][j].xPosRight = statData[i][j].xPosLeft + statData[i][j].barWidth; + + statData[i][j].v7=statData[i][j].xPosLeft; + statData[i][j].v8=statData[i][j].yPosBottom; + statData[i][j].v9=statData[i][j].xPosRight; + statData[i][j].v10=statData[i][j].yPosTop; + } + break; + case "HorizontalStackedBar" : + for (j = 0; j < data.datasets[i].data.length; j++) { + if (i == 0) { + tempp[j]=0; + tempn[j]=0; + } + if (typeof(data.datasets[i].data[j]) == 'undefined') continue; +// if ((typeof(data.datasets[i].data[j]) == 'undefined') || 1*data.datasets[i].data[j] == 0 ) continue; + + statData[i][j].xPosLeft= othervars.yAxisPosX + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) + othervars.valueHop * j; + if (1*data.datasets[i].data[j]<0) { + statData[i][j].leftval=tempn[j]; + statData[i][j].rightval=tempn[j]+1*data.datasets[i].data[j] ; + tempn[j]=tempn[j]+1*data.datasets[i].data[j] ; + } else { + statData[i][j].leftval=tempp[j]; + statData[i][j].rightval=tempp[j]+1*data.datasets[i].data[j] ; + tempp[j]=tempp[j]+1*data.datasets[i].data[j] ; + } + statData[i][j].rightOffset = HorizontalCalculateOffset(statData[i][j].rightval , othervars.calculatedScale, othervars.valueHop); + statData[i][j].leftOffset = HorizontalCalculateOffset(statData[i][j].leftval , othervars.calculatedScale, othervars.valueHop); + statData[i][j].xPosRight = othervars.yAxisPosX + statData[i][j].rightOffset; + statData[i][j].xPosLeft = othervars.yAxisPosX + statData[i][j].leftOffset; + statData[i][j].yPosTop =othervars.xAxisPosY + Math.ceil(ctx.chartSpaceScale*config.barValueSpacing) - othervars.scaleHop * (j + 1); + statData[i][j].yPosBottom = statData[i][j].yPosTop+othervars.barWidth; + // treat spaceBetweenBar + if(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar) > 0) + { + if(1*data.datasets[i].data[j]<0) { + statData[i][j].xPosLeft-=Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar); + if(tempn[j]==1*data.datasets[i].data[j])statData[i][j].xPosLeft+=(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar)/2); + if(statData[i][j].xPosLeft<statData[i][j].xPosRight)statData[i][j].xPosLeft=statData[i][j].xPosRight; + } else if (1*data.datasets[i].data[j]>0) { + statData[i][j].xPosLeft+=Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar); + if(tempp[j]==1*data.datasets[i].data[j])statData[i][j].xPosLeft-=(Math.ceil(ctx.chartSpaceScale*config.spaceBetweenBar)/2); + if(statData[i][j].xPosLeft>statData[i][j].xPosRight)statData[i][j].xPosLeft=statData[i][j].xPosRight; + } + } + + statData[i][j].v7=statData[i][j].xPosLeft; + statData[i][j].v8=statData[i][j].yPosBottom; + statData[i][j].v9=statData[i][j].xPosRight; + statData[i][j].v10=statData[i][j].yPosTop; + } + break; + default : + break; + } + } + +} ; + + + + function xPos(ival, iteration, data,yAxisPosX,valueHop,nbValueHop) { + if (typeof data.datasets[ival].xPos == "object") { + if (!(typeof data.datasets[ival].xPos[Math.floor(iteration + config.zeroValue)] == "undefined")) { + var width = valueHop * nbValueHop; + var deb = (typeof data.xBegin != "undefined") ? data.xBegin : 1 * data.labels[0]; + var fin = (typeof data.xEnd != "undefined") ? data.xEnd : 1 * data.labels[data.labels.length - 1]; + if (fin <= deb) fin = deb + 100; + if (1 * data.datasets[ival].xPos[Math.floor(iteration + config.zeroValue)] >= deb && data.datasets[ival].xPos[Math.floor(iteration + config.zeroValue)] <= fin) { + var p1 = yAxisPosX + width * ((1 * data.datasets[ival].xPos[Math.floor(iteration + config.zeroValue)] - deb) / (fin - deb)); + var p2 = p1; + if (Math.abs(iteration - Math.floor(iteration + config.zeroValue)) > config.zeroValue) { + p2 = xPos(ival, Math.ceil(iteration - config.zeroValue), data); + } + return p1 + (iteration - Math.floor(iteration + config.zeroValue)) * (p2 - p1); + } + } + } + return yAxisPosX + (valueHop * iteration); + }; + + + function calculateOrderOfMagnitude(val) { + return Math.floor(Math.log(val) / Math.LN10); + }; + + function calculateOffset(logarithmic, val, calculatedScale, scaleHop) { + if (!logarithmic) { // no logarithmic scale + var outerValue = calculatedScale.steps * calculatedScale.stepValue; + var adjustedValue = val - calculatedScale.graphMin; + var scalingFactor = CapValue(adjustedValue / outerValue, 1, 0); + return (scaleHop * calculatedScale.steps) * scalingFactor; + } else { // logarithmic scale +// return CapValue(log10(val) * scaleHop - calculateOrderOfMagnitude(calculatedScale.graphMin) * scaleHop, undefined, 0); + return CapValue(log10(val) * scaleHop - log10(calculatedScale.graphMin) * scaleHop, undefined, 0); + } + }; + + function HorizontalCalculateOffset(val, calculatedScale, scaleHop) { + var outerValue = calculatedScale.steps * calculatedScale.stepValue; + var adjustedValue = val - calculatedScale.graphMin; + var scalingFactor = CapValue(adjustedValue / outerValue, 1, 0); + return (scaleHop * calculatedScale.steps) * scalingFactor; + }; + + //Apply cap a value at a high or low number + function CapValue(valueToCap, maxValue, minValue) { + if (isNumber(maxValue)) { + if (valueToCap > maxValue) { + return maxValue; + } + } + if (isNumber(minValue)) { + if (valueToCap < minValue) { + return minValue; + } + } + return valueToCap; + }; + function log10(val) { + return Math.log(val) / Math.LN10; + }; +}; + +function isBooleanOptionTrue(optionVar,defaultvalue) { + var j; + if(typeof optionvar == "undefined") { + if(typeof defaultvalue=="function") return true; + else if(typeof defaultvalue == "object") { + for(j=0;j<defaultvalue.length;j++) if (defaultvalue[j])return true; + return false; + } + else return defaultvalue; + } + if(typeof optionvar=="function") return true; + else if(typeof optionvar == "object") { + for(j=0;j<optionvar.length;j++) if (optionvar[j])return true; + return false; + } else return optionvar; +}; + +function setOptionValue(rescale,reference,ctx,data,statData,optionvar,defaultvalue,posi,posj,othervars) { + var rv; + if(typeof optionvar == "undefined") { + if(typeof defaultvalue=="function") return defaultvalue(reference,ctx,data,statData,posi,posj,othervars); + else if(typeof defaultvalue == "object") { + if(posj==-1)rv=defaultvalue[Math.min(defaultvalue.length-1,Math.max(0,posi))]; + else rv=defaultvalue[Math.min(defaultvalue.length-1,Math.max(0,posj))]; + } + else { + rv=defaultvalue; + } + if(rescale!=1)rv=Math.ceil(rv*rescale); + return rv; + } + if(typeof optionvar=="function") rv=optionvar(reference,ctx,data,statData,posi,posj,othervars); + else if(typeof optionvar == "object") { + if (posj==-1)rv=optionvar[Math.min(optionvar.length-1,Math.max(0,posi))]; + else rv=optionvar[Math.min(optionvar.length-1,Math.max(0,posj))]; + } + else rv=optionvar; + if(rescale!=1)rv=Math.ceil(rv*rescale); + return rv; + +}; + +function tpdraw(ctx,dataval) { + switch(ctx.tpchart) { + case "Bar" : + if (dataval.type=="Line") { tp="Line";} + else {tp=ctx.tpchart;} + break; + default : + tp=ctx.tpchart; + break; + } + return tp; +}; + +function setTextBordersAndBackground(ctx,text,fontsize,xpos,ypos,borders,borderscolor,borderswidth,bordersxspace,bordersyspace,bordersstyle,backgroundcolor,optiongroup) { + var textHeight,textWidth; + // compute text width and text height; + if(typeof text != "string") { + var txt=text.toString(); + textHeight= fontsize * (txt.split("\n").length || 1); + textWidth = ctx.measureText(txt).width; + } else { + textHeight= fontsize * (text.split("\n").length || 1); + textWidth = ctx.measureText(text).width; + } + + + // compute xright, xleft, ytop, ybot; + + var xright, xleft, ytop, ybot; + if(ctx.textAlign=="center") { + xright=-textWidth/2; + xleft=textWidth/2; + } else if(ctx.textAlign=="left") { + xright=0; + xleft=textWidth; + } else if(ctx.textAlign=="right") { + xright=-textWidth; + xleft=0; + } + + if(ctx.textBaseline=="top") { + ytop=0; + ybottom=textHeight; + } else if (ctx.textBaseline=="center" || ctx.textBaseline=="middle") { + ytop=-textHeight/2; + ybottom=textHeight/2; + } else if (ctx.textBaseline=="bottom") { + ytop=-textHeight; + ybottom=0; + } + + ctx.save(); + ctx.beginPath(); + ctx.translate(xpos,ypos); + + if(backgroundcolor != "none") { + + ctx.save(); + ctx.fillStyle=backgroundcolor; + ctx.fillRect(xright-bordersxspace,ybottom+bordersyspace,xleft-xright+2*bordersxspace,ytop-ybottom-2*bordersyspace); + ctx.stroke(); + ctx.restore(); + ctx.fillStyle="black"; + } + + // draw border; + if (borders) { + ctx.save(); + ctx.lineWidth = borderswidth; + ctx.strokeStyle= borderscolor; + ctx.fillStyle= borderscolor; + ctx.setLineDash(lineStyleFn(bordersstyle)); + ctx.rect(xright-borderswidth/2-bordersxspace,ytop-borderswidth/2-bordersyspace,xleft-xright+borderswidth+2*bordersxspace,ybottom-ytop+borderswidth+2*bordersyspace); + ctx.stroke(); + ctx.setLineDash([]); + ctx.restore(); + } + + ctx.restore(); +}; diff --git a/comiccontrol/includes/dragndrop.js b/comiccontrol/includes/dragndrop.js new file mode 100644 index 0000000..90cb38d --- /dev/null +++ b/comiccontrol/includes/dragndrop.js @@ -0,0 +1,56 @@ +//drag and drop script + +document.onmousemove = mouseMove; +document.onmouseup = mouseUp; + +var dragObject = null; +var mouseOffset = null; + +function getMouseOffset(target, ev){ + ev = ev || window.event; + + var docPos = getPosition(target); + var mousePos = mouseCoords(ev); + return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y}; +} + +function getPosition(e){ + var left = 0; + var top = 0; + + while (e.offsetParent){ + left += e.offsetLeft; + top += e.offsetTop; + e = e.offsetParent; + } + + left += e.offsetLeft; + top += e.offsetTop; + + return {x:left, y:top}; +} + +function mouseMove(ev){ + ev = ev || window.event; + var mousePos = mouseCoords(ev); + + if(dragObject){ + dragObject.style.position = 'absolute'; + dragObject.style.top = mousePos.y - mouseOffset.y; + dragObject.style.left = mousePos.x - mouseOffset.x; + + return false; + } +} +function mouseUp(){ + dragObject = null; +} + +function makeDraggable(item){ + if(!item) return; + item.onmousedown = function(ev){ + dragObject = this; + mouseOffset = getMouseOffset(this, ev); + return false; + } +} diff --git a/comiccontrol/includes/footer.php b/comiccontrol/includes/footer.php new file mode 100644 index 0000000..9943ff0 --- /dev/null +++ b/comiccontrol/includes/footer.php @@ -0,0 +1,3 @@ +</div> +</body> +</html> diff --git a/comiccontrol/includes/header.php b/comiccontrol/includes/header.php new file mode 100644 index 0000000..b54522a --- /dev/null +++ b/comiccontrol/includes/header.php @@ -0,0 +1,67 @@ +<? +include('dbconfig.php'); +include('initialize.php'); +include('functions.php'); +if(!authCheck()) header("Location:" . $root . "login.php"); +//set $_GET variables + +$moduleid = sanitizeAlphanumeric($_GET['moduleid']); +$do = sanitizeAlphanumeric($_GET['do']); + +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>ComicControl.</title> +<link rel="stylesheet" type="text/css" href="<?=$root?>comiccontrol.css" /> +<script type="text/javascript" src="<?=$root?>includes/jquery.js"></script> +<script type="text/javascript" src="<?=$root?>tinymce/js/tinymce/tinymce.min.js"></script> +<script type="text/javascript"> +tinymce.init({ + selector: "textarea", + menubar: "tools table format view insert edit", + plugins: "image link table textcolor media jbimages code", + height : 400, + menu : { + edit : {title : 'Edit' , items : 'code | undo redo | cut copy paste pastetext | selectall'}, + insert : {title : 'Insert', items : 'link media image jbimages | hr'}, + view : {title : 'View' , items : 'visualaid'}, + format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'}, + table : {title : 'Table' , items : 'inserttable tableprops deletetable | cell row column'}, + tools : {title : 'Tools' , items : 'spellchecker code'} + }, + relative_urls: false + }); +</script> +</head> +<body> +<div id="header"><a href="index.php">ComicControl.</a><a id="logout" href="login.php?action=logout">Logout</div></div> +<div id="menu"> +<ul> +<? + $break = Explode('/', $_SERVER['PHP_SELF']); + $pfile = $break[count($break) - 1]; + $query="SELECT * FROM cc_" . $tableprefix . "modules"; + $result=$z->query($query); + while($row = $result->fetch_assoc()) + { + if($row['type'] != "custom"){ + if(isset($_GET['id']) && $_GET['id'] == $row['id']) + { echo '<li class="selected"><a href="edit.php?moduleid='.$row['id'].'">'.$row['title'].'</a></li>'; } + else + { echo '<li><a href="edit.php?moduleid='.$row['id'].'">'.$row['title'].'</a></li>'; } + } + } + echo '<li'; + if($pfile == "imageupload.php") echo ' class="selected"'; + echo '><a href="imageupload.php">Image Upload</a></li>'; + $filearr = explode("/",dirname(__FILE__)); + $inputfilename = "/" . $filearr[1] . "/" . $filearr[2] . "/inputaddata.php"; + if(file_exists($inputfilename)){ + echo '<li><a href="viewadstats.php">' . $lang['adstats'] . '</a></li>'; + } +?> +</ul> +</div> +<div id="content">
\ No newline at end of file diff --git a/comiccontrol/includes/jquery.js b/comiccontrol/includes/jquery.js new file mode 100644 index 0000000..e5ace11 --- /dev/null +++ b/comiccontrol/includes/jquery.js @@ -0,0 +1,4 @@ +/*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ +!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="<div class='a'></div><div class='a i'></div>",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="<select msallowclip=''><option selected=''></option></select>",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++d<b;)a.push(d);return a})}},d.pseudos.nth=d.pseudos.eq;for(b in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})d.pseudos[b]=lb(b);for(b in{submit:!0,reset:!0})d.pseudos[b]=mb(b);function pb(){}pb.prototype=d.filters=d.pseudos,d.setFilters=new pb,g=fb.tokenize=function(a,b){var c,e,f,g,h,i,j,k=z[a+" "];if(k)return b?0:k.slice(0);h=a,i=[],j=d.preFilter;while(h){(!c||(e=S.exec(h)))&&(e&&(h=h.slice(e[0].length)||h),i.push(f=[])),c=!1,(e=T.exec(h))&&(c=e.shift(),f.push({value:c,type:e[0].replace(R," ")}),h=h.slice(c.length));for(g in d.filter)!(e=X[g].exec(h))||j[g]&&!(e=j[g](e))||(c=e.shift(),f.push({value:c,type:g,matches:e}),h=h.slice(c.length));if(!c)break}return b?h.length:h?fb.error(a):z(a,i).slice(0)};function qb(a){for(var b=0,c=a.length,d="";c>b;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="<a href='#'></a>","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="<input/>",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+Math.random()}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b) +},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?n.queue(this[0],a):void 0===b?this:this.each(function(){var c=n.queue(this,a,b);n._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&n.dequeue(this,a)})},dequeue:function(a){return this.each(function(){n.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=n.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=L.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var Q=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,R=["Top","Right","Bottom","Left"],S=function(a,b){return a=b||a,"none"===n.css(a,"display")||!n.contains(a.ownerDocument,a)},T=/^(?:checkbox|radio)$/i;!function(){var a=l.createDocumentFragment(),b=a.appendChild(l.createElement("div")),c=l.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h<b.length&&g.push({elem:this,handlers:b.slice(h)}),g},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){return null==a.which&&(a.which=null!=b.charCode?b.charCode:b.keyCode),a}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,b){var c,d,e,f=b.button;return null==a.pageX&&null!=b.clientX&&(c=a.target.ownerDocument||l,d=c.documentElement,e=c.body,a.pageX=b.clientX+(d&&d.scrollLeft||e&&e.scrollLeft||0)-(d&&d.clientLeft||e&&e.clientLeft||0),a.pageY=b.clientY+(d&&d.scrollTop||e&&e.scrollTop||0)-(d&&d.clientTop||e&&e.clientTop||0)),a.which||void 0===f||(a.which=1&f?1:2&f?3:4&f?2:0),a}},fix:function(a){if(a[n.expando])return a;var b,c,d,e=a.type,f=a,g=this.fixHooks[e];g||(this.fixHooks[e]=g=W.test(e)?this.mouseHooks:V.test(e)?this.keyHooks:{}),d=g.props?this.props.concat(g.props):this.props,a=new n.Event(f),b=d.length;while(b--)c=d[b],a[c]=f[c];return a.target||(a.target=l),3===a.target.nodeType&&(a.target=a.target.parentNode),g.filter?g.filter(a,f):a},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==_()&&this.focus?(this.focus(),!1):void 0},delegateType:"focusin"},blur:{trigger:function(){return this===_()&&this.blur?(this.blur(),!1):void 0},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&n.nodeName(this,"input")?(this.click(),!1):void 0},_default:function(a){return n.nodeName(a.target,"a")}},beforeunload:{postDispatch:function(a){void 0!==a.result&&a.originalEvent&&(a.originalEvent.returnValue=a.result)}}},simulate:function(a,b,c,d){var e=n.extend(new n.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?n.event.trigger(e,null,b):n.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},n.removeEvent=function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)},n.Event=function(a,b){return this instanceof n.Event?(a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||void 0===a.defaultPrevented&&a.returnValue===!1?Z:$):this.type=a,b&&n.extend(this,b),this.timeStamp=a&&a.timeStamp||n.now(),void(this[n.expando]=!0)):new n.Event(a,b)},n.Event.prototype={isDefaultPrevented:$,isPropagationStopped:$,isImmediatePropagationStopped:$,preventDefault:function(){var a=this.originalEvent;this.isDefaultPrevented=Z,a&&a.preventDefault&&a.preventDefault()},stopPropagation:function(){var a=this.originalEvent;this.isPropagationStopped=Z,a&&a.stopPropagation&&a.stopPropagation()},stopImmediatePropagation:function(){var a=this.originalEvent;this.isImmediatePropagationStopped=Z,a&&a.stopImmediatePropagation&&a.stopImmediatePropagation(),this.stopPropagation()}},n.each({mouseenter:"mouseover",mouseleave:"mouseout",pointerenter:"pointerover",pointerleave:"pointerout"},function(a,b){n.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c,d=this,e=a.relatedTarget,f=a.handleObj;return(!e||e!==d&&!n.contains(d,e))&&(a.type=f.origType,c=f.handler.apply(this,arguments),a.type=b),c}}}),k.focusinBubbles||n.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){n.event.simulate(b,a.target,n.event.fix(a),!0)};n.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=L.access(d,b);e||d.addEventListener(a,c,!0),L.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=L.access(d,b)-1;e?L.access(d,b,e):(d.removeEventListener(a,c,!0),L.remove(d,b))}}}),n.fn.extend({on:function(a,b,c,d,e){var f,g;if("object"==typeof a){"string"!=typeof b&&(c=c||b,b=void 0);for(g in a)this.on(g,b,c,a[g],e);return this}if(null==c&&null==d?(d=b,c=b=void 0):null==d&&("string"==typeof b?(d=c,c=void 0):(d=c,c=b,b=void 0)),d===!1)d=$;else if(!d)return this;return 1===e&&(f=d,d=function(a){return n().off(a),f.apply(this,arguments)},d.guid=f.guid||(f.guid=n.guid++)),this.each(function(){n.event.add(this,a,d,c,b)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,b,c){var d,e;if(a&&a.preventDefault&&a.handleObj)return d=a.handleObj,n(a.delegateTarget).off(d.namespace?d.origType+"."+d.namespace:d.origType,d.selector,d.handler),this;if("object"==typeof a){for(e in a)this.off(e,b,a[e]);return this}return(b===!1||"function"==typeof b)&&(c=b,b=void 0),c===!1&&(c=$),this.each(function(){n.event.remove(this,a,c,b)})},trigger:function(a,b){return this.each(function(){n.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];return c?n.event.trigger(a,b,c,!0):void 0}});var ab=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,ib={option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],col:[2,"<table><colgroup>","</colgroup></table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1></$2>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1></$2>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("<iframe frameborder='0' width='0' height='0'/>")).appendTo(b.documentElement),b=qb[0].contentDocument,b.write(),b.close(),c=sb(a,b),qb.detach()),rb[a]=c),c}var ub=/^margin/,vb=new RegExp("^("+Q+")(?!px)[a-z%]+$","i"),wb=function(a){return a.ownerDocument.defaultView.getComputedStyle(a,null)};function xb(a,b,c){var d,e,f,g,h=a.style;return c=c||wb(a),c&&(g=c.getPropertyValue(b)||c[b]),c&&(""!==g||n.contains(a.ownerDocument,a)||(g=n.style(a,b)),vb.test(g)&&ub.test(b)&&(d=h.width,e=h.minWidth,f=h.maxWidth,h.minWidth=h.maxWidth=h.width=g,g=c.width,h.width=d,h.minWidth=e,h.maxWidth=f)),void 0!==g?g+"":g}function yb(a,b){return{get:function(){return a()?void delete this.get:(this.get=b).apply(this,arguments)}}}!function(){var b,c,d=l.documentElement,e=l.createElement("div"),f=l.createElement("div");if(f.style){f.style.backgroundClip="content-box",f.cloneNode(!0).style.backgroundClip="",k.clearCloneStyle="content-box"===f.style.backgroundClip,e.style.cssText="border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;position:absolute",e.appendChild(f);function g(){f.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:block;margin-top:1%;top:1%;border:1px;padding:1px;width:4px;position:absolute",f.innerHTML="",d.appendChild(e);var g=a.getComputedStyle(f,null);b="1%"!==g.top,c="4px"===g.width,d.removeChild(e)}a.getComputedStyle&&n.extend(k,{pixelPosition:function(){return g(),b},boxSizingReliable:function(){return null==c&&g(),c},reliableMarginRight:function(){var b,c=f.appendChild(l.createElement("div"));return c.style.cssText=f.style.cssText="-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;display:block;margin:0;border:0;padding:0",c.style.marginRight=c.style.width="0",f.style.width="1px",d.appendChild(e),b=!parseFloat(a.getComputedStyle(c,null).marginRight),d.removeChild(e),b}})}}(),n.swap=function(a,b,c,d){var e,f,g={};for(f in b)g[f]=a.style[f],a.style[f]=b[f];e=c.apply(a,d||[]);for(f in b)a.style[f]=g[f];return e};var zb=/^(none|table(?!-c[ea]).+)/,Ab=new RegExp("^("+Q+")(.*)$","i"),Bb=new RegExp("^([+-])=("+Q+")","i"),Cb={position:"absolute",visibility:"hidden",display:"block"},Db={letterSpacing:"0",fontWeight:"400"},Eb=["Webkit","O","Moz","ms"];function Fb(a,b){if(b in a)return b;var c=b[0].toUpperCase()+b.slice(1),d=b,e=Eb.length;while(e--)if(b=Eb[e]+c,b in a)return b;return d}function Gb(a,b,c){var d=Ab.exec(b);return d?Math.max(0,d[1]-(c||0))+(d[2]||"px"):b}function Hb(a,b,c,d,e){for(var f=c===(d?"border":"content")?4:"width"===b?1:0,g=0;4>f;f+=2)"margin"===c&&(g+=n.css(a,c+R[f],!0,e)),d?("content"===c&&(g-=n.css(a,"padding"+R[f],!0,e)),"margin"!==c&&(g-=n.css(a,"border"+R[f]+"Width",!0,e))):(g+=n.css(a,"padding"+R[f],!0,e),"padding"!==c&&(g+=n.css(a,"border"+R[f]+"Width",!0,e)));return g}function Ib(a,b,c){var d=!0,e="width"===b?a.offsetWidth:a.offsetHeight,f=wb(a),g="border-box"===n.css(a,"boxSizing",!1,f);if(0>=e||null==e){if(e=xb(a,b,f),(0>e||null==e)&&(e=a.style[b]),vb.test(e))return e;d=g&&(k.boxSizingReliable()||e===a.style[b]),e=parseFloat(e)||0}return e+Hb(a,b,c||(g?"border":"content"),d,f)+"px"}function Jb(a,b){for(var c,d,e,f=[],g=0,h=a.length;h>g;g++)d=a[g],d.style&&(f[g]=L.get(d,"olddisplay"),c=d.style.display,b?(f[g]||"none"!==c||(d.style.display=""),""===d.style.display&&S(d)&&(f[g]=L.access(d,"olddisplay",tb(d.nodeName)))):(e=S(d),"none"===c&&e||L.set(d,"olddisplay",e?c:n.css(d,"display"))));for(g=0;h>g;g++)d=a[g],d.style&&(b&&"none"!==d.style.display&&""!==d.style.display||(d.style.display=b?f[g]||"":"none"));return a}n.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=xb(a,"opacity");return""===c?"1":c}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(a,b,c,d){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var e,f,g,h=n.camelCase(b),i=a.style;return b=n.cssProps[h]||(n.cssProps[h]=Fb(i,h)),g=n.cssHooks[b]||n.cssHooks[h],void 0===c?g&&"get"in g&&void 0!==(e=g.get(a,!1,d))?e:i[b]:(f=typeof c,"string"===f&&(e=Bb.exec(c))&&(c=(e[1]+1)*e[2]+parseFloat(n.css(a,b)),f="number"),null!=c&&c===c&&("number"!==f||n.cssNumber[h]||(c+="px"),k.clearCloneStyle||""!==c||0!==b.indexOf("background")||(i[b]="inherit"),g&&"set"in g&&void 0===(c=g.set(a,c,d))||(i[b]=c)),void 0)}},css:function(a,b,c,d){var e,f,g,h=n.camelCase(b);return b=n.cssProps[h]||(n.cssProps[h]=Fb(a.style,h)),g=n.cssHooks[b]||n.cssHooks[h],g&&"get"in g&&(e=g.get(a,!0,c)),void 0===e&&(e=xb(a,b,d)),"normal"===e&&b in Db&&(e=Db[b]),""===c||c?(f=parseFloat(e),c===!0||n.isNumeric(f)?f||0:e):e}}),n.each(["height","width"],function(a,b){n.cssHooks[b]={get:function(a,c,d){return c?zb.test(n.css(a,"display"))&&0===a.offsetWidth?n.swap(a,Cb,function(){return Ib(a,b,d)}):Ib(a,b,d):void 0},set:function(a,c,d){var e=d&&wb(a);return Gb(a,c,d?Hb(a,b,d,"border-box"===n.css(a,"boxSizing",!1,e),e):0)}}}),n.cssHooks.marginRight=yb(k.reliableMarginRight,function(a,b){return b?n.swap(a,{display:"inline-block"},xb,[a,"marginRight"]):void 0}),n.each({margin:"",padding:"",border:"Width"},function(a,b){n.cssHooks[a+b]={expand:function(c){for(var d=0,e={},f="string"==typeof c?c.split(" "):[c];4>d;d++)e[a+R[d]+b]=f[d]||f[d-2]||f[0];return e}},ub.test(a)||(n.cssHooks[a+b].set=Gb)}),n.fn.extend({css:function(a,b){return J(this,function(a,b,c){var d,e,f={},g=0;if(n.isArray(b)){for(d=wb(a),e=b.length;e>g;g++)f[b[g]]=n.css(a,b[g],!1,d);return f}return void 0!==c?n.style(a,b,c):n.css(a,b)},a,b,arguments.length>1)},show:function(){return Jb(this,!0)},hide:function(){return Jb(this)},toggle:function(a){return"boolean"==typeof a?a?this.show():this.hide():this.each(function(){S(this)?n(this).show():n(this).hide()})}});function Kb(a,b,c,d,e){return new Kb.prototype.init(a,b,c,d,e)}n.Tween=Kb,Kb.prototype={constructor:Kb,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||"swing",this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(n.cssNumber[c]?"":"px")},cur:function(){var a=Kb.propHooks[this.prop];return a&&a.get?a.get(this):Kb.propHooks._default.get(this)},run:function(a){var b,c=Kb.propHooks[this.prop];return this.pos=b=this.options.duration?n.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Kb.propHooks._default.set(this),this}},Kb.prototype.init.prototype=Kb.prototype,Kb.propHooks={_default:{get:function(a){var b;return null==a.elem[a.prop]||a.elem.style&&null!=a.elem.style[a.prop]?(b=n.css(a.elem,a.prop,""),b&&"auto"!==b?b:0):a.elem[a.prop]},set:function(a){n.fx.step[a.prop]?n.fx.step[a.prop](a):a.elem.style&&(null!=a.elem.style[n.cssProps[a.prop]]||n.cssHooks[a.prop])?n.style(a.elem,a.prop,a.now+a.unit):a.elem[a.prop]=a.now}}},Kb.propHooks.scrollTop=Kb.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},n.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2}},n.fx=Kb.prototype.init,n.fx.step={};var Lb,Mb,Nb=/^(?:toggle|show|hide)$/,Ob=new RegExp("^(?:([+-])=|)("+Q+")([a-z%]*)$","i"),Pb=/queueHooks$/,Qb=[Vb],Rb={"*":[function(a,b){var c=this.createTween(a,b),d=c.cur(),e=Ob.exec(b),f=e&&e[3]||(n.cssNumber[a]?"":"px"),g=(n.cssNumber[a]||"px"!==f&&+d)&&Ob.exec(n.css(c.elem,a)),h=1,i=20;if(g&&g[3]!==f){f=f||g[3],e=e||[],g=+d||1;do h=h||".5",g/=h,n.style(c.elem,a,g+f);while(h!==(h=c.cur()/d)&&1!==h&&--i)}return e&&(g=c.start=+g||+d||0,c.unit=f,c.end=e[1]?g+(e[1]+1)*e[2]:+e[2]),c}]};function Sb(){return setTimeout(function(){Lb=void 0}),Lb=n.now()}function Tb(a,b){var c,d=0,e={height:a};for(b=b?1:0;4>d;d+=2-b)c=R[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function Ub(a,b,c){for(var d,e=(Rb[b]||[]).concat(Rb["*"]),f=0,g=e.length;g>f;f++)if(d=e[f].call(c,b,a))return d}function Vb(a,b,c){var d,e,f,g,h,i,j,k,l=this,m={},o=a.style,p=a.nodeType&&S(a),q=L.get(a,"fxshow");c.queue||(h=n._queueHooks(a,"fx"),null==h.unqueued&&(h.unqueued=0,i=h.empty.fire,h.empty.fire=function(){h.unqueued||i()}),h.unqueued++,l.always(function(){l.always(function(){h.unqueued--,n.queue(a,"fx").length||h.empty.fire()})})),1===a.nodeType&&("height"in b||"width"in b)&&(c.overflow=[o.overflow,o.overflowX,o.overflowY],j=n.css(a,"display"),k="none"===j?L.get(a,"olddisplay")||tb(a.nodeName):j,"inline"===k&&"none"===n.css(a,"float")&&(o.display="inline-block")),c.overflow&&(o.overflow="hidden",l.always(function(){o.overflow=c.overflow[0],o.overflowX=c.overflow[1],o.overflowY=c.overflow[2]}));for(d in b)if(e=b[d],Nb.exec(e)){if(delete b[d],f=f||"toggle"===e,e===(p?"hide":"show")){if("show"!==e||!q||void 0===q[d])continue;p=!0}m[d]=q&&q[d]||n.style(a,d)}else j=void 0;if(n.isEmptyObject(m))"inline"===("none"===j?tb(a.nodeName):j)&&(o.display=j);else{q?"hidden"in q&&(p=q.hidden):q=L.access(a,"fxshow",{}),f&&(q.hidden=!p),p?n(a).show():l.done(function(){n(a).hide()}),l.done(function(){var b;L.remove(a,"fxshow");for(b in m)n.style(a,b,m[b])});for(d in m)g=Ub(p?q[d]:0,d,l),d in q||(q[d]=g.start,p&&(g.end=g.start,g.start="width"===d||"height"===d?1:0))}}function Wb(a,b){var c,d,e,f,g;for(c in a)if(d=n.camelCase(c),e=b[d],f=a[c],n.isArray(f)&&(e=f[1],f=a[c]=f[0]),c!==d&&(a[d]=f,delete a[c]),g=n.cssHooks[d],g&&"expand"in g){f=g.expand(f),delete a[d];for(c in f)c in a||(a[c]=f[c],b[c]=e)}else b[d]=e}function Xb(a,b,c){var d,e,f=0,g=Qb.length,h=n.Deferred().always(function(){delete i.elem}),i=function(){if(e)return!1;for(var b=Lb||Sb(),c=Math.max(0,j.startTime+j.duration-b),d=c/j.duration||0,f=1-d,g=0,i=j.tweens.length;i>g;g++)j.tweens[g].run(f);return h.notifyWith(a,[j,f,c]),1>f&&i?c:(h.resolveWith(a,[j]),!1)},j=h.promise({elem:a,props:n.extend({},b),opts:n.extend(!0,{specialEasing:{}},c),originalProperties:b,originalOptions:c,startTime:Lb||Sb(),duration:c.duration,tweens:[],createTween:function(b,c){var d=n.Tween(a,j.opts,b,c,j.opts.specialEasing[b]||j.opts.easing);return j.tweens.push(d),d},stop:function(b){var c=0,d=b?j.tweens.length:0;if(e)return this;for(e=!0;d>c;c++)j.tweens[c].run(1);return b?h.resolveWith(a,[j,b]):h.rejectWith(a,[j,b]),this}}),k=j.props;for(Wb(k,j.opts.specialEasing);g>f;f++)if(d=Qb[f].call(j,a,k,j.opts))return d;return n.map(k,Ub,j),n.isFunction(j.opts.start)&&j.opts.start.call(a,j),n.fx.timer(n.extend(i,{elem:a,anim:j,queue:j.opts.queue})),j.progress(j.opts.progress).done(j.opts.done,j.opts.complete).fail(j.opts.fail).always(j.opts.always)}n.Animation=n.extend(Xb,{tweener:function(a,b){n.isFunction(a)?(b=a,a=["*"]):a=a.split(" ");for(var c,d=0,e=a.length;e>d;d++)c=a[d],Rb[c]=Rb[c]||[],Rb[c].unshift(b)},prefilter:function(a,b){b?Qb.unshift(a):Qb.push(a)}}),n.speed=function(a,b,c){var d=a&&"object"==typeof a?n.extend({},a):{complete:c||!c&&b||n.isFunction(a)&&a,duration:a,easing:c&&b||b&&!n.isFunction(b)&&b};return d.duration=n.fx.off?0:"number"==typeof d.duration?d.duration:d.duration in n.fx.speeds?n.fx.speeds[d.duration]:n.fx.speeds._default,(null==d.queue||d.queue===!0)&&(d.queue="fx"),d.old=d.complete,d.complete=function(){n.isFunction(d.old)&&d.old.call(this),d.queue&&n.dequeue(this,d.queue)},d},n.fn.extend({fadeTo:function(a,b,c,d){return this.filter(S).css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){var e=n.isEmptyObject(a),f=n.speed(b,c,d),g=function(){var b=Xb(this,n.extend({},a),f);(e||L.get(this,"finish"))&&b.stop(!0)};return g.finish=g,e||f.queue===!1?this.each(g):this.queue(f.queue,g)},stop:function(a,b,c){var d=function(a){var b=a.stop;delete a.stop,b(c)};return"string"!=typeof a&&(c=b,b=a,a=void 0),b&&a!==!1&&this.queue(a||"fx",[]),this.each(function(){var b=!0,e=null!=a&&a+"queueHooks",f=n.timers,g=L.get(this);if(e)g[e]&&g[e].stop&&d(g[e]);else for(e in g)g[e]&&g[e].stop&&Pb.test(e)&&d(g[e]);for(e=f.length;e--;)f[e].elem!==this||null!=a&&f[e].queue!==a||(f[e].anim.stop(c),b=!1,f.splice(e,1));(b||!c)&&n.dequeue(this,a)})},finish:function(a){return a!==!1&&(a=a||"fx"),this.each(function(){var b,c=L.get(this),d=c[a+"queue"],e=c[a+"queueHooks"],f=n.timers,g=d?d.length:0;for(c.finish=!0,n.queue(this,a,[]),e&&e.stop&&e.stop.call(this,!0),b=f.length;b--;)f[b].elem===this&&f[b].queue===a&&(f[b].anim.stop(!0),f.splice(b,1));for(b=0;g>b;b++)d[b]&&d[b].finish&&d[b].finish.call(this);delete c.finish})}}),n.each(["toggle","show","hide"],function(a,b){var c=n.fn[b];n.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,arguments):this.animate(Tb(b,!0),a,d,e)}}),n.each({slideDown:Tb("show"),slideUp:Tb("hide"),slideToggle:Tb("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){n.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),n.timers=[],n.fx.tick=function(){var a,b=0,c=n.timers;for(Lb=n.now();b<c.length;b++)a=c[b],a()||c[b]!==a||c.splice(b--,1);c.length||n.fx.stop(),Lb=void 0},n.fx.timer=function(a){n.timers.push(a),a()?n.fx.start():n.timers.pop()},n.fx.interval=13,n.fx.start=function(){Mb||(Mb=setInterval(n.fx.tick,n.fx.interval))},n.fx.stop=function(){clearInterval(Mb),Mb=null},n.fx.speeds={slow:600,fast:200,_default:400},n.fn.delay=function(a,b){return a=n.fx?n.fx.speeds[a]||a:a,b=b||"fx",this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},function(){var a=l.createElement("input"),b=l.createElement("select"),c=b.appendChild(l.createElement("option"));a.type="checkbox",k.checkOn=""!==a.value,k.optSelected=c.selected,b.disabled=!0,k.optDisabled=!c.disabled,a=l.createElement("input"),a.value="t",a.type="radio",k.radioValue="t"===a.value}();var Yb,Zb,$b=n.expr.attrHandle;n.fn.extend({attr:function(a,b){return J(this,n.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){n.removeAttr(this,a)})}}),n.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(a&&3!==f&&8!==f&&2!==f)return typeof a.getAttribute===U?n.prop(a,b,c):(1===f&&n.isXMLDoc(a)||(b=b.toLowerCase(),d=n.attrHooks[b]||(n.expr.match.bool.test(b)?Zb:Yb)),void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?void 0:e):null!==c?d&&"set"in d&&void 0!==(e=d.set(a,c,b))?e:(a.setAttribute(b,c+""),c):void n.removeAttr(a,b)) +},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(E);if(f&&1===a.nodeType)while(c=f[e++])d=n.propFix[c]||c,n.expr.match.bool.test(c)&&(a[d]=!1),a.removeAttribute(c)},attrHooks:{type:{set:function(a,b){if(!k.radioValue&&"radio"===b&&n.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),Zb={set:function(a,b,c){return b===!1?n.removeAttr(a,c):a.setAttribute(c,c),c}},n.each(n.expr.match.bool.source.match(/\w+/g),function(a,b){var c=$b[b]||n.find.attr;$b[b]=function(a,b,d){var e,f;return d||(f=$b[b],$b[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,$b[b]=f),e}});var _b=/^(?:input|select|textarea|button)$/i;n.fn.extend({prop:function(a,b){return J(this,n.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[n.propFix[a]||a]})}}),n.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!n.isXMLDoc(a),f&&(b=n.propFix[b]||b,e=n.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){return a.hasAttribute("tabindex")||_b.test(a.nodeName)||a.href?a.tabIndex:-1}}}}),k.optSelected||(n.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null}}),n.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){n.propFix[this.toLowerCase()]=this});var ac=/[\t\r\n\f]/g;n.fn.extend({addClass:function(a){var b,c,d,e,f,g,h="string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).addClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ac," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=n.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0===arguments.length||"string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).removeClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ac," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?n.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(n.isFunction(a)?function(c){n(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=n(this),f=a.match(E)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===U||"boolean"===c)&&(this.className&&L.set(this,"__className__",this.className),this.className=this.className||a===!1?"":L.get(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(ac," ").indexOf(b)>=0)return!0;return!1}});var bc=/\r/g;n.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=n.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,n(this).val()):a,null==e?e="":"number"==typeof e?e+="":n.isArray(e)&&(e=n.map(e,function(a){return null==a?"":a+""})),b=n.valHooks[this.type]||n.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=n.valHooks[e.type]||n.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(bc,""):null==c?"":c)}}}),n.extend({valHooks:{option:{get:function(a){var b=n.find.attr(a,"value");return null!=b?b:n.trim(n.text(a))}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],!(!c.selected&&i!==e||(k.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.parentNode.disabled&&n.nodeName(c.parentNode,"optgroup"))){if(b=n(c).val(),f)return b;g.push(b)}return g},set:function(a,b){var c,d,e=a.options,f=n.makeArray(b),g=e.length;while(g--)d=e[g],(d.selected=n.inArray(d.value,f)>=0)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),n.each(["radio","checkbox"],function(){n.valHooks[this]={set:function(a,b){return n.isArray(b)?a.checked=n.inArray(n(a).val(),b)>=0:void 0}},k.checkOn||(n.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})}),n.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){n.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),n.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return 1===arguments.length?this.off(a,"**"):this.off(b,a||"**",c)}});var cc=n.now(),dc=/\?/;n.parseJSON=function(a){return JSON.parse(a+"")},n.parseXML=function(a){var b,c;if(!a||"string"!=typeof a)return null;try{c=new DOMParser,b=c.parseFromString(a,"text/xml")}catch(d){b=void 0}return(!b||b.getElementsByTagName("parsererror").length)&&n.error("Invalid XML: "+a),b};var ec,fc,gc=/#.*$/,hc=/([?&])_=[^&]*/,ic=/^(.*?):[ \t]*([^\r\n]*)$/gm,jc=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,kc=/^(?:GET|HEAD)$/,lc=/^\/\//,mc=/^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,nc={},oc={},pc="*/".concat("*");try{fc=location.href}catch(qc){fc=l.createElement("a"),fc.href="",fc=fc.href}ec=mc.exec(fc.toLowerCase())||[];function rc(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(E)||[];if(n.isFunction(c))while(d=f[e++])"+"===d[0]?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function sc(a,b,c,d){var e={},f=a===oc;function g(h){var i;return e[h]=!0,n.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function tc(a,b){var c,d,e=n.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&n.extend(!0,a,d),a}function uc(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader("Content-Type"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+" "+i[0]]){f=e;break}g||(g=e)}f=f||g}return f?(f!==i[0]&&i.unshift(f),c[f]):void 0}function vc(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}n.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:fc,type:"GET",isLocal:jc.test(ec[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":pc,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":n.parseJSON,"text xml":n.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?tc(tc(a,n.ajaxSettings),b):tc(n.ajaxSettings,a)},ajaxPrefilter:rc(nc),ajaxTransport:rc(oc),ajax:function(a,b){"object"==typeof a&&(b=a,a=void 0),b=b||{};var c,d,e,f,g,h,i,j,k=n.ajaxSetup({},b),l=k.context||k,m=k.context&&(l.nodeType||l.jquery)?n(l):n.event,o=n.Deferred(),p=n.Callbacks("once memory"),q=k.statusCode||{},r={},s={},t=0,u="canceled",v={readyState:0,getResponseHeader:function(a){var b;if(2===t){if(!f){f={};while(b=ic.exec(e))f[b[1].toLowerCase()]=b[2]}b=f[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return 2===t?e:null},setRequestHeader:function(a,b){var c=a.toLowerCase();return t||(a=s[c]=s[c]||a,r[a]=b),this},overrideMimeType:function(a){return t||(k.mimeType=a),this},statusCode:function(a){var b;if(a)if(2>t)for(b in a)q[b]=[q[b],a[b]];else v.always(a[v.status]);return this},abort:function(a){var b=a||u;return c&&c.abort(b),x(0,b),this}};if(o.promise(v).complete=p.add,v.success=v.done,v.error=v.fail,k.url=((a||k.url||fc)+"").replace(gc,"").replace(lc,ec[1]+"//"),k.type=b.method||b.type||k.method||k.type,k.dataTypes=n.trim(k.dataType||"*").toLowerCase().match(E)||[""],null==k.crossDomain&&(h=mc.exec(k.url.toLowerCase()),k.crossDomain=!(!h||h[1]===ec[1]&&h[2]===ec[2]&&(h[3]||("http:"===h[1]?"80":"443"))===(ec[3]||("http:"===ec[1]?"80":"443")))),k.data&&k.processData&&"string"!=typeof k.data&&(k.data=n.param(k.data,k.traditional)),sc(nc,k,b,v),2===t)return v;i=k.global,i&&0===n.active++&&n.event.trigger("ajaxStart"),k.type=k.type.toUpperCase(),k.hasContent=!kc.test(k.type),d=k.url,k.hasContent||(k.data&&(d=k.url+=(dc.test(d)?"&":"?")+k.data,delete k.data),k.cache===!1&&(k.url=hc.test(d)?d.replace(hc,"$1_="+cc++):d+(dc.test(d)?"&":"?")+"_="+cc++)),k.ifModified&&(n.lastModified[d]&&v.setRequestHeader("If-Modified-Since",n.lastModified[d]),n.etag[d]&&v.setRequestHeader("If-None-Match",n.etag[d])),(k.data&&k.hasContent&&k.contentType!==!1||b.contentType)&&v.setRequestHeader("Content-Type",k.contentType),v.setRequestHeader("Accept",k.dataTypes[0]&&k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+pc+"; q=0.01":""):k.accepts["*"]);for(j in k.headers)v.setRequestHeader(j,k.headers[j]);if(k.beforeSend&&(k.beforeSend.call(l,v,k)===!1||2===t))return v.abort();u="abort";for(j in{success:1,error:1,complete:1})v[j](k[j]);if(c=sc(oc,k,b,v)){v.readyState=1,i&&m.trigger("ajaxSend",[v,k]),k.async&&k.timeout>0&&(g=setTimeout(function(){v.abort("timeout")},k.timeout));try{t=1,c.send(r,x)}catch(w){if(!(2>t))throw w;x(-1,w)}}else x(-1,"No Transport");function x(a,b,f,h){var j,r,s,u,w,x=b;2!==t&&(t=2,g&&clearTimeout(g),c=void 0,e=h||"",v.readyState=a>0?4:0,j=a>=200&&300>a||304===a,f&&(u=uc(k,v,f)),u=vc(k,u,v,j),j?(k.ifModified&&(w=v.getResponseHeader("Last-Modified"),w&&(n.lastModified[d]=w),w=v.getResponseHeader("etag"),w&&(n.etag[d]=w)),204===a||"HEAD"===k.type?x="nocontent":304===a?x="notmodified":(x=u.state,r=u.data,s=u.error,j=!s)):(s=x,(a||!x)&&(x="error",0>a&&(a=0))),v.status=a,v.statusText=(b||x)+"",j?o.resolveWith(l,[r,x,v]):o.rejectWith(l,[v,x,s]),v.statusCode(q),q=void 0,i&&m.trigger(j?"ajaxSuccess":"ajaxError",[v,k,j?r:s]),p.fireWith(l,[v,x]),i&&(m.trigger("ajaxComplete",[v,k]),--n.active||n.event.trigger("ajaxStop")))}return v},getJSON:function(a,b,c){return n.get(a,b,c,"json")},getScript:function(a,b){return n.get(a,void 0,b,"script")}}),n.each(["get","post"],function(a,b){n[b]=function(a,c,d,e){return n.isFunction(c)&&(e=e||d,d=c,c=void 0),n.ajax({url:a,type:b,dataType:e,data:c,success:d})}}),n.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){n.fn[b]=function(a){return this.on(b,a)}}),n._evalUrl=function(a){return n.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})},n.fn.extend({wrapAll:function(a){var b;return n.isFunction(a)?this.each(function(b){n(this).wrapAll(a.call(this,b))}):(this[0]&&(b=n(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this)},wrapInner:function(a){return this.each(n.isFunction(a)?function(b){n(this).wrapInner(a.call(this,b))}:function(){var b=n(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=n.isFunction(a);return this.each(function(c){n(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){n.nodeName(this,"body")||n(this).replaceWith(this.childNodes)}).end()}}),n.expr.filters.hidden=function(a){return a.offsetWidth<=0&&a.offsetHeight<=0},n.expr.filters.visible=function(a){return!n.expr.filters.hidden(a)};var wc=/%20/g,xc=/\[\]$/,yc=/\r?\n/g,zc=/^(?:submit|button|image|reset|file)$/i,Ac=/^(?:input|select|textarea|keygen)/i;function Bc(a,b,c,d){var e;if(n.isArray(b))n.each(b,function(b,e){c||xc.test(a)?d(a,e):Bc(a+"["+("object"==typeof e?b:"")+"]",e,c,d)});else if(c||"object"!==n.type(b))d(a,b);else for(e in b)Bc(a+"["+e+"]",b[e],c,d)}n.param=function(a,b){var c,d=[],e=function(a,b){b=n.isFunction(b)?b():null==b?"":b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};if(void 0===b&&(b=n.ajaxSettings&&n.ajaxSettings.traditional),n.isArray(a)||a.jquery&&!n.isPlainObject(a))n.each(a,function(){e(this.name,this.value)});else for(c in a)Bc(c,a[c],b,e);return d.join("&").replace(wc,"+")},n.fn.extend({serialize:function(){return n.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=n.prop(this,"elements");return a?n.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!n(this).is(":disabled")&&Ac.test(this.nodeName)&&!zc.test(a)&&(this.checked||!T.test(a))}).map(function(a,b){var c=n(this).val();return null==c?null:n.isArray(c)?n.map(c,function(a){return{name:b.name,value:a.replace(yc,"\r\n")}}):{name:b.name,value:c.replace(yc,"\r\n")}}).get()}}),n.ajaxSettings.xhr=function(){try{return new XMLHttpRequest}catch(a){}};var Cc=0,Dc={},Ec={0:200,1223:204},Fc=n.ajaxSettings.xhr();a.ActiveXObject&&n(a).on("unload",function(){for(var a in Dc)Dc[a]()}),k.cors=!!Fc&&"withCredentials"in Fc,k.ajax=Fc=!!Fc,n.ajaxTransport(function(a){var b;return k.cors||Fc&&!a.crossDomain?{send:function(c,d){var e,f=a.xhr(),g=++Cc;if(f.open(a.type,a.url,a.async,a.username,a.password),a.xhrFields)for(e in a.xhrFields)f[e]=a.xhrFields[e];a.mimeType&&f.overrideMimeType&&f.overrideMimeType(a.mimeType),a.crossDomain||c["X-Requested-With"]||(c["X-Requested-With"]="XMLHttpRequest");for(e in c)f.setRequestHeader(e,c[e]);b=function(a){return function(){b&&(delete Dc[g],b=f.onload=f.onerror=null,"abort"===a?f.abort():"error"===a?d(f.status,f.statusText):d(Ec[f.status]||f.status,f.statusText,"string"==typeof f.responseText?{text:f.responseText}:void 0,f.getAllResponseHeaders()))}},f.onload=b(),f.onerror=b("error"),b=Dc[g]=b("abort");try{f.send(a.hasContent&&a.data||null)}catch(h){if(b)throw h}},abort:function(){b&&b()}}:void 0}),n.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){return n.globalEval(a),a}}}),n.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET")}),n.ajaxTransport("script",function(a){if(a.crossDomain){var b,c;return{send:function(d,e){b=n("<script>").prop({async:!0,charset:a.scriptCharset,src:a.url}).on("load error",c=function(a){b.remove(),c=null,a&&e("error"===a.type?404:200,a.type)}),l.head.appendChild(b[0])},abort:function(){c&&c()}}}});var Gc=[],Hc=/(=)\?(?=&|$)|\?\?/;n.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=Gc.pop()||n.expando+"_"+cc++;return this[a]=!0,a}}),n.ajaxPrefilter("json jsonp",function(b,c,d){var e,f,g,h=b.jsonp!==!1&&(Hc.test(b.url)?"url":"string"==typeof b.data&&!(b.contentType||"").indexOf("application/x-www-form-urlencoded")&&Hc.test(b.data)&&"data");return h||"jsonp"===b.dataTypes[0]?(e=b.jsonpCallback=n.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,h?b[h]=b[h].replace(Hc,"$1"+e):b.jsonp!==!1&&(b.url+=(dc.test(b.url)?"&":"?")+b.jsonp+"="+e),b.converters["script json"]=function(){return g||n.error(e+" was not called"),g[0]},b.dataTypes[0]="json",f=a[e],a[e]=function(){g=arguments},d.always(function(){a[e]=f,b[e]&&(b.jsonpCallback=c.jsonpCallback,Gc.push(e)),g&&n.isFunction(f)&&f(g[0]),g=f=void 0}),"script"):void 0}),n.parseHTML=function(a,b,c){if(!a||"string"!=typeof a)return null;"boolean"==typeof b&&(c=b,b=!1),b=b||l;var d=v.exec(a),e=!c&&[];return d?[b.createElement(d[1])]:(d=n.buildFragment([a],b,e),e&&e.length&&n(e).remove(),n.merge([],d.childNodes))};var Ic=n.fn.load;n.fn.load=function(a,b,c){if("string"!=typeof a&&Ic)return Ic.apply(this,arguments);var d,e,f,g=this,h=a.indexOf(" ");return h>=0&&(d=n.trim(a.slice(h)),a=a.slice(0,h)),n.isFunction(b)?(c=b,b=void 0):b&&"object"==typeof b&&(e="POST"),g.length>0&&n.ajax({url:a,type:e,dataType:"html",data:b}).done(function(a){f=arguments,g.html(d?n("<div>").append(n.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,f||[a.responseText,b,a])}),this},n.expr.filters.animated=function(a){return n.grep(n.timers,function(b){return a===b.elem}).length};var Jc=a.document.documentElement;function Kc(a){return n.isWindow(a)?a:9===a.nodeType&&a.defaultView}n.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=n.css(a,"position"),l=n(a),m={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=n.css(a,"top"),i=n.css(a,"left"),j=("absolute"===k||"fixed"===k)&&(f+i).indexOf("auto")>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),n.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(m.top=b.top-h.top+g),null!=b.left&&(m.left=b.left-h.left+e),"using"in b?b.using.call(a,m):l.css(m)}},n.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){n.offset.setOffset(this,a,b)});var b,c,d=this[0],e={top:0,left:0},f=d&&d.ownerDocument;if(f)return b=f.documentElement,n.contains(b,d)?(typeof d.getBoundingClientRect!==U&&(e=d.getBoundingClientRect()),c=Kc(f),{top:e.top+c.pageYOffset-b.clientTop,left:e.left+c.pageXOffset-b.clientLeft}):e},position:function(){if(this[0]){var a,b,c=this[0],d={top:0,left:0};return"fixed"===n.css(c,"position")?b=c.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),n.nodeName(a[0],"html")||(d=a.offset()),d.top+=n.css(a[0],"borderTopWidth",!0),d.left+=n.css(a[0],"borderLeftWidth",!0)),{top:b.top-d.top-n.css(c,"marginTop",!0),left:b.left-d.left-n.css(c,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||Jc;while(a&&!n.nodeName(a,"html")&&"static"===n.css(a,"position"))a=a.offsetParent;return a||Jc})}}),n.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){var d="pageYOffset"===c;n.fn[b]=function(e){return J(this,function(b,e,f){var g=Kc(b);return void 0===f?g?g[c]:b[e]:void(g?g.scrollTo(d?a.pageXOffset:f,d?f:a.pageYOffset):b[e]=f)},b,e,arguments.length,null)}}),n.each(["top","left"],function(a,b){n.cssHooks[b]=yb(k.pixelPosition,function(a,c){return c?(c=xb(a,b),vb.test(c)?n(a).position()[b]+"px":c):void 0})}),n.each({Height:"height",Width:"width"},function(a,b){n.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){n.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return J(this,function(b,c,d){var e;return n.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?n.css(b,c,g):n.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),n.fn.size=function(){return this.length},n.fn.andSelf=n.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return n});var Lc=a.jQuery,Mc=a.$;return n.noConflict=function(b){return a.$===n&&(a.$=Mc),b&&a.jQuery===n&&(a.jQuery=Lc),n},typeof b===U&&(a.jQuery=a.$=n),n}); diff --git a/comiccontrol/includes/lightGallery.css b/comiccontrol/includes/lightGallery.css new file mode 100644 index 0000000..ce9ab4d --- /dev/null +++ b/comiccontrol/includes/lightGallery.css @@ -0,0 +1,629 @@ +/*clearfix*/ +.group { + *zoom: 1; +} +.group:before, .group:after { + display: table; + content: ""; + line-height: 0; +} +.group:after { + clear: both; +} +/*/clearfix*/ + + +/** /font-icons if you are not using font icons you can just remove this part/**/ +@font-face { + font-family: 'Slide-icons'; + src: url('../fonts/Slide-icons.eot'); +} +@font-face { + font-family: 'Slide-icons'; + src: url(data:application/font-woff;charset=utf-8;base64,d09GRk9UVE8AAAWcAAsAAAAACSgAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABDRkYgAAABCAAAAm4AAAQxqzjSYEZGVE0AAAN4AAAAGgAAABxmWaSOR0RFRgAAA5QAAAAdAAAAIAAzAARPUy8yAAADtAAAAEsAAABgL/bcQGNtYXAAAAQAAAAAPQAAAVLgL/LNaGVhZAAABEAAAAAuAAAANv3vdhloaGVhAAAEcAAAAB4AAAAkBBD/5GhtdHgAAASQAAAAEgAAABIFOwBxbWF4cAAABKQAAAAGAAAABgAGUABuYW1lAAAErAAAAOEAAAGw7pftcnBvc3QAAAWQAAAADAAAACAAAwAAeJx9VE1oE1EQnpfsJutmSWNMQoUoWxB/qmIKnkKJWKvXQlOwhx5E7SEo9WCEHNKAJqVbn8RLzvEgKEUPCgoiIi3YHkWw2mO9CBb8O1SzurXjvLfrJiqEhXkzwzffm/nee8tAUYAxZuQvFs5PHi6cuzR1GVgAGORsM2D3Be1ehRtBbii7ddiZjyPnvmOE+QW7YRfVNNzpSQPE0vBwexqMtNIbh7Dg0KAHUrAL9sARyF6ZKpzKZDK0nMwMHHeXIXc54S7DHU109gPAZpnF5th1xiEkiANgsFpgNDATPB3ldlHZbNiNcBTZ/JNRZBPFZ0nE6mw/GT6MUC6tiPCgihA6Vkb8sXCNI35bGxRuTcYa4vqZIWlUP1sVoCx3Yyqd1gTNIUH4RhJ6rILAxw9yN/bwghVSt56rLoCyFY6gmy8kwENJwjYrlItPVauOuDWyhqDEzlKFIuvIIrAHfTJbr2uSWpgFOVvFHVDQc5dftK751P3CeyuNp8Uf/DL3tal5rFKLuiX2MxGdL00azJHKOWLcrZF3MmtZWhThNRWwx62XSYTF/d8Rc6sR2iFyNYS4MWNSzaeJA+RWfkqjCYBO5tV71bIkjTssUVe5bykrhrXqWqnZ1m9a6rfk61emfu+Px8iIA8zf/SrDNr4s8csd+Gbzn+mXOtWK3rPHkqbeGkuZuvNIGudo9wRdvDkald0Yj9HFy89vtvsgjw7/Pxm9Kf+SEfGj86HU/frlVn6RwgP7CLVRTZDCFZt6j99edcWGSPmz5h4BLO5d73bIzVL7OdTkc8j6O5MIdiPBkzcNnZ7zDvF/2OYkWvSFI78BSE0QpgAAeJxjYGBgZACCk535hiD6XIbUOhgNAD+3BfAAAHicY2BkYGDgA2IJBhBgYmAEQlYgZgHzGAAEgQA4AAAAeJxjYGZiYJzAwMrAwejDmMbAwOAOpb8ySDK0MDAwMbAyM8CBAILJEJDmmsLg8EDqAwPjg/8PGPQYHzAoNDAwMMIVKAAhIwATaAw5AHicY2BgYGaAYBkGRgYQ8AHyGMF8FgYDIM0BhEwgiQeyHxj+/wezpCAs+RcCjFBdYMDIxoDMHZEAAP1aCcoAAAB4nGNgZGBgAGLNvbqy8fw2Xxm4mRhA4FyG1DoE/f8BEwPjAyCXgwEsDQAB0gmnAAB4nGNgZGBgfPD/AYMeEwMDwz8GIAkUQQHMAG3nA/YAAAIAAAAAAAAAAgAAUQClACAAlgAAAABQAAAGAAB4nI2PMW7CQBBFn8FGIkQpo5RbIFHZsjciEhyAMg0SFwALrYS8kuEMOQLH4BgcgGPkAKnz7UxBkYKVVvPmz5/ZWeCZMwndSZjwZjwgozQeMuPLOJXnapyJv41HTJIXOZN0LOW17+p4wBNT4yGffBin8lyMM/HNeCT+Yc2BwI6aXHFLpOEI60PY1XnYxkbJnW7Kqs9PfWzZq9vhKfQPx1L3/6l/Nc9c6kLXy1/xrnGxOa1iu6+dL0q3dHevK/PzfJH7spLxkW03qrZSQ191eqHbi03dHkNsXFWUD835BcvqQqwAAAB4nGNgZsALAAB9AAQ=) format('woff'), url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAANAIAAAwBQRkZUTWZZpI4AAAboAAAAHEdERUYANQAGAAAGyAAAACBPUy8yL9TcHwAAAVgAAABWY21hcOAx89QAAAHMAAABUmdhc3D//wADAAAGwAAAAAhnbHlmlq1ZxgAAAzQAAAGAaGVhZP3vdhkAAADcAAAANmhoZWEEEP/mAAABFAAAACRobXR4BeoAcQAAAbAAAAAabG9jYQEyAOAAAAMgAAAAEm1heHAAUwAnAAABOAAAACBuYW1l7pftcgAABLQAAAGwcG9zdCBfgkMAAAZkAAAAWgABAAAAAQAAZVgBDF8PPPUACwIAAAAAAM5oGq4AAAAAzmgargAA/+ACAAHgAAAACAACAAAAAAAAAAEAAAHg/+AALgIAAAD+AAIAAAEAAAAAAAAAAAAAAAAAAAAFAAEAAAAIACQACQAAAAAAAgAAAAEAAQAAAEAAAAAAAAAAAQIAAZAABQAIAUwBZgAAAEcBTAFmAAAA9QAZAIQAAAIABQMAAAAAAAAAAAAAEAAAAAAAAAAAAAAAUGZFZABA4BrwAAHg/+AALgHgACCAAAABAAAAAAAAAgAAAAAAAAAAqgAAAAAAAAIAAFEAqgAgAJYAAAAAAAMAAAADAAAAHAABAAAAAABMAAMAAQAAABwABAAwAAAACAAIAAIAAAAA4B3wAP//AAAAAOAa8AD//wAAH+oQAwABAAAAAAAAAAAAAAEGAAABAAAAAAAAAAECAAAAAgAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAEIAZACeAMAAAAABAAD/4AIAAeAAAgAAEQEhAgD+AAHg/gAAAAAAAQBRADYBrwGKAB0AAAE2NC8BJg8BJyYPAQYUHwEHBh8BFj8BFxY/ATYvAQGqBAQXCwx8fAwLFwQEfX0LCxcLDHx8DAsXCwt9AVwFDQUXCwt9fQsLFwUNBXx8DAsXCwt9fQsLFwsMfAABAKoABQGeAbYAEQAAEyYPAQYfAQcGHwEWMj8BNjQn1AwLEwsLrKwLCxMFDQXBCAgBtgsLEwsMrKwMCxMFBcEJGAkAAAkAIAAAAeABwAADAAcACwAPABMAFwAbAB8AIwAAEzMVIyUzFSMnMxUjBzMVIyUzFSMnMxUjBzMVIyUzFSMnMxUjIICAAUCAgKCAgKCAgAFAgICggICggIABQICAoICAAcCAgICAgCCAgICAgCCAgICAgAAAAQCWAAoBjwG2ABEAAAE2LwEmDwEGFB8BFj8BNjQvAQGKCwsTDAvBCQnBCwsUBAStAYwMCxMLC8EJGAnBCwsTBQ0FrAAAAAwAlgABAAAAAAABAAsAGAABAAAAAAACAAUAMAABAAAAAAADACcAhgABAAAAAAAEAAsAxgABAAAAAAAFAAsA6gABAAAAAAAGAAsBDgADAAEECQABABYAAAADAAEECQACAAoAJAADAAEECQADAE4ANgADAAEECQAEABYArgADAAEECQAFABYA0gADAAEECQAGABYA9gBTAGwAaQBkAGUALQBpAGMAbwBuAHMAAFNsaWRlLWljb25zAABpAGMAbwBuAHMAAGljb25zAABGAG8AbgB0AEYAbwByAGcAZQAgADIALgAwACAAOgAgAFMAbABpAGQAZQAtAGkAYwBvAG4AcwAgADoAIAAyADUALQA5AC0AMgAwADEAMwAARm9udEZvcmdlIDIuMCA6IFNsaWRlLWljb25zIDogMjUtOS0yMDEzAABTAGwAaQBkAGUALQBpAGMAbwBuAHMAAFNsaWRlLWljb25zAABWAGUAcgBzAGkAbwBuACAAMQAuADAAAFZlcnNpb24gMS4wAABTAGwAaQBkAGUALQBpAGMAbwBuAHMAAFNsaWRlLWljb25zAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAABAAIBAgEDAQQBBQEGB3VuaUYwMDAHdW5pRTAxQQd1bmlFMDFCB3VuaUUwMUMHdW5pRTAxRAAAAAAAAf//AAIAAQAAAA4AAAAYAAAAAAACAAEAAwAHAAEABAAAAAIAAAAAAAEAAAAAyYlvMQAAAADOaBquAAAAAM5oGq4=) format('truetype'); + font-weight: normal; + font-style: normal; +} +[data-icon]:before { + font-family: 'Slide-icons'; + content: attr(data-icon); + speak: none; + font-weight: normal; + font-variant: normal; + text-transform: none; + line-height: 1; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +/** / End of font-icons /**/ + + + + +.lightGallery { + overflow: hidden!important; +} +#lightGallery-Gallery img { + border: none!important; +} +#lightGallery-outer { + width: 100%; + height: 100%; + position: fixed; + top: 0; + left: 0; + z-index: 99999!important; + overflow: hidden; + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; + opacity: 1; + -webkit-transition: opacity 0.35s ease; + -moz-transition: opacity 0.35s ease; + -o-transition: opacity 0.35s ease; + -ms-transition: opacity 0.35s ease; + transition: opacity 0.35s ease; + background: #0d0d0d; +} +#lightGallery-outer .lightGallery-slide{ + position: relative; +} +/*lightGallery starting effects*/ +#lightGallery-Gallery.opacity { + opacity: 1; + transition: opacity 1s ease 0s; + -moz-transition: opacity 1s ease 0s; + -webkit-transition: opacity 1s ease 0s; + -o-transition: opacity 1s ease 0s; + -ms-transition: opacity 1s ease 0s; +} +#lightGallery-Gallery.opacity .thumb_cont { + opacity: 1; +} +#lightGallery-Gallery.fadeM { + opacity: 0; + transition: opacity 0.5s ease 0s; + -moz-transition: opacity 0.5s ease 0s; + -webkit-transition: opacity 0.5s ease 0s; + -o-transition: opacity 0.5s ease 0s; + -ms-transition: opacity 0.5s ease 0s; +} +/*lightGallery starting effects*/ + + +/*lightGallery core*/ +#lightGallery-Gallery { + height: 100%; + opacity: 0; + width: 100%; + position: relative; + transition: opacity 1s ease 0s; + -moz-transition: opacity 1s ease 0s; + -webkit-transition: opacity 1s ease 0s; + -o-transition: opacity 1s ease 0s; + -ms-transition: opacity 1s ease 0s; +} +/**/ +#lightGallery-slider { + height: 100%; + left: 0; + top: 0; + width: 100%; + position: absolute; + white-space: nowrap; +} +/**/ +#lightGallery-slider .lightGallery-slide { + background: url(../img/loading.gif) no-repeat scroll center center transparent; + display: inline-block; + height: 100%; + text-align: center; + width: 100%; +} +#lightGallery-slider .lightGallery-slide.complete { + background-image: none; +} +#lightGallery-Gallery.showAfterLoad .lightGallery-slide > * { + opacity: 0; +} +#lightGallery-Gallery.showAfterLoad .lightGallery-slide.complete > * { + opacity: 1; +} +#lightGallery-slider.slide .lightGallery-slide, #lightGallery-slider.useLeft .lightGallery-slide { + position: absolute; + opacity: 0.4; +} +#lightGallery-slider.fadeM .lightGallery-slide { + position: absolute; + left: 0; + opacity: 0; +} +#lightGallery-slider.animate .lightGallery-slide { + position: absolute; + left: 0; +} +#lightGallery-slider.fadeM .current { + opacity: 1; + z-index: 9; +} +#lightGallery-slider .lightGallery-slide:before { + content: ""; + display: inline-block; + height: 50%; + width: 1px; + margin-right: -1px; +} +#lightGallery-Gallery.opacity .lightGallery-slide .object{ + transform: scale3d(1, 1, 1); + -moz-transform: scale3d(1, 1, 1); + -ms-transform: scale3d(1, 1, 1); + -webkit-transform: scale3d(1, 1, 1); + -o-transform: scale3d(1, 1, 1); +} +.lightGallery-slide .object{ + transform: scale3d(0.5, 0.5, 0.5); + -moz-transform: scale3d(0.5, 0.5, 0.5); + -ms-transform: scale3d(0.5, 0.5, 0.5); + -webkit-transform: scale3d(0.5, 0.5, 0.5); + -o-transform: scale3d(0.5, 0.5, 0.5); + -webkit-transition: -webkit-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 0.5s ease 0s; + -moz-transition: -moz-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 0.5s ease 0s; + -o-transition: -o-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 0.5s ease 0s; + -ms-transition: -ms-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 0.5s ease 0s; + transition: transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 0.5s ease 0s; +} +#lightGallery-Gallery.fadeM .lightGallery-slide .object{ + transform: scale3d(0.5, 0.5, 0.5); + -moz-transform: scale3d(0.5, 0.5, 0.5); + -ms-transform: scale3d(0.5, 0.5, 0.5); + -webkit-transform: scale3d(0.5, 0.5, 0.5); + -o-transform: scale3d(0.5, 0.5, 0.5); +} +#lightGallery-slider.fadeM.on .current { + opacity: 1; + transition: opacity 0.5s ease 0s; + -moz-transition: opacity 0.5s ease 0s; + -webkit-transition: opacity 0.5s ease 0s; + -o-transition: opacity 0.5s ease 0s; + -ms-transition: opacity 0.5s ease 0s; +} +#lightGallery-slider.fadeM .lightGallery-slide { + transition: opacity 0.4s ease 0s; + -moz-transition: opacity 0.4s ease 0s; + -webkit-transition: opacity 0.4s ease 0s; + -o-transition: opacity 0.4s ease 0s; + -ms-transition: opacity 0.4s ease 0s; +} +#lightGallery-slider.slide .lightGallery-slide { + transform: translate3d(100%, 0px, 0px); + -moz-transform: translate3d(100%, 0px, 0px); + -ms-transform: translate3d(100%, 0px, 0px); + -webkit-transform: translate3d(100%, 0px, 0px); + -o-transform: translate3d(100%, 0px, 0px); +} +#lightGallery-slider.slide.on .lightGallery-slide { + opacity: 0; +} +#lightGallery-slider.slide .lightGallery-slide.current { + opacity: 1 !important; + transform: translate3d(0px, 0px, 0px) !important; + -moz-transform: translate3d(0px, 0px, 0px) !important; + -ms-transform: translate3d(0px, 0px, 0px) !important; + -webkit-transform: translate3d(0px, 0px, 0px) !important; + -o-transform: translate3d(0px, 0px, 0px) !important; +} +#lightGallery-slider.slide .lightGallery-slide.prevSlide { + opacity: 0; + transform: translate3d(-100%, 0px, 0px); + -moz-transform: translate3d(-100%, 0px, 0px); + -ms-transform: translate3d(-100%, 0px, 0px); + -webkit-transform: translate3d(-100%, 0px, 0px); + -o-transform: translate3d(-100%, 0px, 0px); +} +#lightGallery-slider.slide .lightGallery-slide.nextSlide { + opacity: 0; + transform: translate3d(100%, 0px, 0px); + -moz-transform: translate3d(100%, 0px, 0px); + -ms-transform: translate3d(100%, 0px, 0px); + -webkit-transform: translate3d(100%, 0px, 0px); + -o-transform: translate3d(100%, 0px, 0px); +} +#lightGallery-slider.useLeft .lightGallery-slide { + left: 100%; +} +#lightGallery-slider.useLeft.on .lightGallery-slide { + opacity: 0; +} +#lightGallery-slider.useLeft .lightGallery-slide.current { + opacity: 1 !important; + left: 0% !important; +} +#lightGallery-slider.useLeft .lightGallery-slide.prevSlide { + opacity: 0; + left: -100%; +} +#lightGallery-slider.useLeft .lightGallery-slide.nextSlide { + opacity: 0; + left: 100%; +} +#lightGallery-slider.slide.on .lightGallery-slide, #lightGallery-slider.slide.on .current, #lightGallery-slider.slide.on .prevSlide, #lightGallery-slider.slide.on .nextSlide { + -webkit-transition: -webkit-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 1s ease 0s; + -moz-transition: -moz-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 1s ease 0s; + -o-transition: -o-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 1s ease 0s; + -ms-transition: -ms-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 1s ease 0s; + transition: transform 1s cubic-bezier(0, 0, 0.25, 1) 0s, opacity 1s ease 0s; +} +#lightGallery-slider.speed .lightGallery-slide, #lightGallery-slider.speed .current, #lightGallery-slider.speed .prevSlide, #lightGallery-slider.speed .nextSlide { + transition-duration: inherit !important; + -moz-transition-duration: inherit !important; + -webkit-transition-duration: inherit !important; + -o-transition-duration: inherit !important; + -ms-transition-duration: inherit !important; +} +#lightGallery-slider.timing .lightGallery-slide, #lightGallery-slider.timing .current, #lightGallery-slider.timing .prevSlide, #lightGallery-slider.timing .nextSlide { + transition-timing-function: inherit !important; + -moz-transition-timing-function: inherit !important; + -webkit-transition-timing-function: inherit !important; + -o-transition-timing-function: inherit !important; + -ms-transition-timing-function: inherit !important; +} +#lightGallery-slider .lightGallery-slide img { + display: inline-block; + max-height: 100%; + max-width: 100%; + cursor: -moz-grabbing; + cursor: grab; + cursor: -webkit-grab; + margin: 0; + padding: 0; + width: auto; + height: auto; + vertical-align: middle; +} +#lightGallery-Gallery .thumb_cont .thumb_inner { + -webkit-transition: -webkit-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s; + -moz-transition: -moz-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s; + -o-transition: -o-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s; + -ms-transition: -ms-transform 1s cubic-bezier(0, 0, 0.25, 1) 0s; + transition: transform 1s cubic-bezier(0, 0, 0.25, 1) 0s; +} + @-webkit-keyframes rightEnd { + 0% { +left: 0; +} + 50% { +left: -30px; +} + 100% { +left: 0; +} +} +@keyframes rightEnd { + 0% { +left: 0; +} + 50% { +left: -30px; +} + 100% { +left: 0; +} +} +@-webkit-keyframes leftEnd { + 0% { +left: 0; +} + 50% { +left: 30px; +} + 100% { +left: 0; +} +} +@keyframes leftEnd { + 0% { +left: 0; +} + 50% { +left: 30px; +} + 100% { +left: 0; +} +} +.lightGallery-slide .object.rightEnd { + -webkit-animation: rightEnd 0.3s; + animation: rightEnd 0.3s; + position: relative; +} +.lightGallery-slide .object.leftEnd { + -webkit-animation: leftEnd 0.3s; + animation: leftEnd 0.3s; + position: relative; +} +/*lightGallery core*/ + + +/*action*/ +#lightGallery-action { + bottom: 20px; + position: fixed; + left: 50%; + margin-left: -30px; + z-index: 9; + -webkit-backface-visibility: hidden; +} +#lightGallery-action.hasThumb { + margin-left: -46px; +} + +#lightGallery-action a { + margin: 0 3px 0 0 !important; + -webkit-border-radius: 2px; + -moz-border-radius: 2px; + border-radius: 2px; + position: relative; + top: auto; + left: auto; + bottom: auto; + right: auto; + display: inline-block !important; + display: inline-block; + vertical-align: middle; + *display: inline; + *zoom: 1; + background-color: #000; + background-color: rgba(0, 0, 0, 0.65); + font-size: 16px; + width: 28px; + height: 28px; + font-family: 'Slide-icons'; + color: #FFF; + cursor: pointer; +} +#lightGallery-action a.disabled { + opacity: 0.6; + filter: alpha(opacity=60); + cursor: default; + background-color: #000; + background-color: rgba(0, 0, 0, 0.65) !important; +} +#lightGallery-action a:hover, #lightGallery-action a:focus { + background-color: #000; + background-color: rgba(0, 0, 0, 0.85); +} +#lightGallery-action a#lightGallery-prev:before, #lightGallery-action a#lightGallery-next:after { + left: 5px; + bottom: 3px; + position: absolute; +} +#lightGallery-action a#lightGallery-prev:before { + content: "\e01d"; +} +#lightGallery-action a#lightGallery-next:after { + content: "\e01b"; +} +#lightGallery-action a.cLthumb:after { + font-family: 'Slide-icons'; + content: "\e01c"; + left: 6px; + bottom: 4px; + font-size: 16px; + position: absolute; +} +/*action*/ + +/*counter*/ +#lightGallery_counter { + bottom: 52px; + text-align: center; + width: 100%; + position: absolute; + z-index: 9; + color: #FFFFFF; +} +/*lightGallery Thumb*/ +#lightGallery-Gallery .thumb_cont { + position: absolute; + bottom: 0; + width: 100%; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + background-color: #000000; + -webkit-transition: max-height 0.4s ease-in-out; + -moz-transition: max-height 0.4s ease-in-out; + -o-transition: max-height 0.4s ease-in-out; + -ms-transition: max-height 0.4s ease-in-out; + transition: max-height 0.4s ease-in-out; + z-index: 9; + max-height: 0; + opacity: 0; +} +#lightGallery-Gallery.open .thumb_cont { + max-height: 350px; +} +#lightGallery-Gallery .thumb_cont .thumb_inner { + margin-left: -12px; + padding: 12px; + max-height: 290px; + overflow-y: auto; + -webkit-box-sizing: content-box; + -moz-box-sizing: content-box; + box-sizing: content-box; +} +#lightGallery-Gallery .thumb_cont .thumb_info { + background-color: #333; + padding: 7px 20px; +} +#lightGallery-Gallery .thumb_cont .thumb_info .count { + color: #ffffff; + font-weight: bold; + font-size: 12px; +} +#lightGallery-Gallery .thumb_cont .thumb_info .close { + color: #FFFFFF; + display: block; + float: right !important; + width: 28px; + position: relative; + height: 28px; + border-radius: 2px; + margin-top: -4px; + background-color: #000; + background-color: rgba(0, 0, 0, 0.65); + -webkit-transition: background-color 0.3s ease 0s; + -moz-transition: background-color 0.3s ease 0s; + -o-transition: background-color 0.3s ease 0s; + -ms-transition: background-color 0.3s ease 0s; + transition: background-color 0.3s ease 0s; + z-index: 1090; + cursor: pointer; +} +#lightGallery-Gallery .thumb_cont .thumb_info .close i:after { + left: 6px; + position: absolute; + top: 4px; +} +#lightGallery-Gallery .thumb_cont .thumb_info .close i:after, #lightGallery-close:after { + content: "\e01a"; + font-family: 'Slide-icons'; + font-style: normal; + font-size: 16px; +} +#lightGallery-Gallery .thumb_cont .thumb_info .close:hover { + text-decoration: none; + background-color: #000; + background-color: rgba(0, 0, 0, 1); +} +#lightGallery-Gallery .thumb_cont .thumb { + display: inline-block !important; + vertical-align: middle; + text-align: center; + *display: inline; + /* IE7 inline-block hack */ + + *zoom: 1; + margin-bottom: 4px; + height: 50px; + width: 50px; + opacity: 0.6; + filter: alpha(opacity=60); + overflow: hidden; + border-radius: 3px; + cursor: pointer; + -webkit-transition: border-color linear .2s, opacity linear .2s; + -moz-transition: border-color linear .2s, opacity linear .2s; + -o-transition: border-color linear .2s, opacity linear .2s; + -ms-transition: border-color linear .2s, opacity linear .2s; + transition: border-color linear .2s, opacity linear .2s; +} +@media (min-width: 800px) { +#lightGallery-Gallery .thumb_cont .thumb { + width: 94px; + height: 94px; +} +} +#lightGallery-Gallery .thumb_cont .thumb > img { + height: auto; + max-width: 100%; +} +#lightGallery-Gallery .thumb_cont .thumb.active, #lightGallery-Gallery .thumb_cont .thumb:hover { + opacity: 1; + filter: alpha(opacity=100); + border-color: #ffffff; +} +/*lightGallery Thumb*/ + +/*lightGallery Video*/ +#lightGallery-slider .video_cont { + display: inline-block; + max-height: 100%; + max-width: 100%; + margin: 0; + padding: 0; + width: auto; + height: auto; + vertical-align: middle; +} +#lightGallery-slider .video_cont { + background: none; + max-width: 1140px; + max-height: 100%; + width: 100%; + box-sizing: border-box; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; +} +#lightGallery-slider .video { + width: 100%; + height: 0; + padding-bottom: 56.25%; + overflow: hidden; + position: relative; +} +#lightGallery-slider .video .object { + width: 100%!important; + height: 100%!important; + position: absolute; + top: 0; + left: 0; +} +/*lightGallery Video*/ + + + + + + +/*lightGallery Close*/ +#lightGallery-close { + color: #FFFFFF; + height: 28px; + position: absolute; + right: 20px; + top: 20px; + width: 28px; + z-index: 1090; + cursor: pointer; + background-color: #000; + border-radius: 2px; + background-color: #000; + background-color: rgba(0, 0, 0, 0.65); + -webkit-transition: background-color 0.3s ease; + -moz-transition: background-color 0.3s ease; + -o-transition: background-color 0.3s ease; + -ms-transition: background-color 0.3s ease; + transition: background-color 0.3s ease; + -webkit-backface-visibility: hidden; +} +#lightGallery-close:after { + position: absolute; + right: 6px; + top: 3px; +} +#lightGallery-close:hover { + text-decoration: none; + background-color: #000; +} +.customHtml { + background: none repeat scroll 0 0 black; + background: none repeat scroll 0 0 rgba(0, 0, 0, 0.75); + color: #fff; + font-family: Arial, sans-serif; + height: 70px; + left: 0; + position: absolute; + right: 0; + top: 0; + z-index: 9; +} +.customHtml p { + font-size: 14px; +} +.customHtml > h4 { + font-family: Arial, sans-serif; + font-weight: bold; + margin-bottom: 5px; + margin-top: 15px; +} diff --git a/comiccontrol/includes/lightGallery.js b/comiccontrol/includes/lightGallery.js new file mode 100644 index 0000000..3d934e3 --- /dev/null +++ b/comiccontrol/includes/lightGallery.js @@ -0,0 +1,781 @@ +/** ========================================================== + +* jquery lightGallery.js v1.1.4 +* http://sachinchoolur.github.io/lightGallery/ +* Released under the MIT License - http://opensource.org/licenses/mit-license.html ---- FREE ---- + +=========================================================/**/ +; +(function($) { + "use strict"; + $.fn.lightGallery = function(options) { + var defaults = { + mode: 'slide', + useCSS: true, + cssEasing: 'ease', //'cubic-bezier(0.25, 0, 0.25, 1)',// + easing: 'linear', //'for jquery animation',// + speed: 600, + addClass: '', + + closable: true, + loop: false, + auto: false, + pause: 4000, + escKey: true, + controls: true, + hideControlOnEnd: false, + + preload: 1, //number of preload slides. will exicute only after the current slide is fully loaded. ex:// you clicked on 4th image and if preload = 1 then 3rd slide and 5th slide will be loaded in the background after the 4th slide is fully loaded.. if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ... + showAfterLoad: true, + selector: null, + index: false, + + lang: { + allPhotos: 'All photos' + }, + counter: false, + + exThumbImage: false, + thumbnail: true, + showThumbByDefault:false, + animateThumb: true, + currentPagerPosition: 'middle', + thumbWidth: 100, + thumbMargin: 5, + + + mobileSrc: false, + mobileSrcMaxWidth: 640, + swipeThreshold: 50, + enableTouch: true, + enableDrag: true, + + vimeoColor: 'CCCCCC', + videoAutoplay: true, + videoMaxWidth: '855px', + + dynamic: false, + dynamicEl: [], + //callbacks + + onOpen: function(plugin) {}, + onSlideBefore: function(plugin) {}, + onSlideAfter: function(plugin) {}, + onSlideNext: function(plugin) {}, + onSlidePrev: function(plugin) {}, + onBeforeClose: function(plugin) {}, + onCloseAfter: function(plugin) {} + }, + el = $(this), + plugin = this, + $children = null, + index = 0, + isActive = false, + lightGalleryOn = false, + isTouch = document.createTouch !== undefined || ('ontouchstart' in window) || ('onmsgesturechange' in window) || navigator.msMaxTouchPoints, + $gallery, $galleryCont, $slider, $slide, $prev, $next, prevIndex, $thumb_cont, $thumb, windowWidth, interval, usingThumb = false, + aTiming = false, + aSpeed = false; + var settings = $.extend(true, {}, defaults, options); + var lightGallery = { + init: function() { + el.each(function() { + var $this = $(this); + if (settings.dynamic) { + $children = settings.dynamicEl; + index = 0; + prevIndex = index; + setUp.init(index); + } else { + if (settings.selector !== null) { + $children = $(settings.selector); + } else { + $children = $this.children(); + } + $children.on('click', function(e) { + if (settings.selector !== null) { + $children = $(settings.selector); + } else { + $children = $this.children(); + } + e.preventDefault(); + e.stopPropagation(); + index = $children.index(this); + prevIndex = index; + setUp.init(index); + }); + } + }); + } + }; + var setUp = { + init: function() { + isActive = true; + this.structure(); + this.getWidth(); + this.closeSlide(); + this.autoStart(); + this.counter(); + this.slideTo(); + this.buildThumbnail(); + this.keyPress(); + if (settings.index) { + this.slide(settings.index); + this.animateThumb(settings.index); + } else { + this.slide(index); + this.animateThumb(index); + } + if (settings.enableDrag) { + this.touch(); + }; + if (settings.enableTouch) { + this.enableTouch(); + } + + setTimeout(function() { + $gallery.addClass('opacity'); + }, 50); + }, + structure: function() { + $('body').append('<div id="lightGallery-outer" class="' + settings.addClass + '"><div id="lightGallery-Gallery"><div id="lightGallery-slider"></div><a id="lightGallery-close" class="close"></a></div></div>').addClass('lightGallery'); + $galleryCont = $('#lightGallery-outer'); + $gallery = $('#lightGallery-Gallery'); + if (settings.showAfterLoad === true) { + $gallery.addClass('showAfterLoad'); + } + $slider = $gallery.find('#lightGallery-slider'); + var slideList = ''; + if (settings.dynamic) { + for (var i = 0; i < settings.dynamicEl.length; i++) { + slideList += '<div class="lightGallery-slide"></div>'; + } + } else { + $children.each(function() { + slideList += '<div class="lightGallery-slide"></div>'; + }); + } + $slider.append(slideList); + $slide = $gallery.find('.lightGallery-slide'); + }, + closeSlide: function() { + var $this = this; + if (settings.closable) { + $('#lightGallery-outer') + .on('click', function(event) { + if ($(event.target).is('.lightGallery-slide')) { + plugin.destroy(false); + } + }); + } + $('#lightGallery-close').bind('click touchend', function() { + plugin.destroy(false); + }); + }, + getWidth: function() { + var resizeWindow = function() { + windowWidth = $(window).width(); + }; + $(window).bind('resize.lightGallery', resizeWindow()); + }, + doCss: function() { + var support = function() { + var transition = ['transition', 'MozTransition', 'WebkitTransition', 'OTransition', 'msTransition', 'KhtmlTransition']; + var root = document.documentElement; + for (var i = 0; i < transition.length; i++) { + if (transition[i] in root.style) { + return true; + } + } + }; + if (settings.useCSS && support()) { + return true; + } + return false; + }, + enableTouch: function() { + var $this = this; + if (isTouch) { + var startCoords = {}, + endCoords = {}; + $('body').on('touchstart.lightGallery', function(e) { + endCoords = e.originalEvent.targetTouches[0]; + startCoords.pageX = e.originalEvent.targetTouches[0].pageX; + startCoords.pageY = e.originalEvent.targetTouches[0].pageY; + }); + $('body').on('touchmove.lightGallery', function(e) { + var orig = e.originalEvent; + endCoords = orig.targetTouches[0]; + e.preventDefault(); + }); + $('body').on('touchend.lightGallery', function(e) { + var distance = endCoords.pageX - startCoords.pageX, + swipeThreshold = settings.swipeThreshold; + if (distance >= swipeThreshold) { + $this.prevSlide(); + clearInterval(interval); + } else if (distance <= -swipeThreshold) { + $this.nextSlide(); + clearInterval(interval); + } + }); + } + }, + touch: function() { + var xStart, xEnd; + var $this = this; + $('.lightGallery').bind('mousedown', function(e) { + e.stopPropagation(); + e.preventDefault(); + xStart = e.pageX; + }); + $('.lightGallery').bind('mouseup', function(e) { + e.stopPropagation(); + e.preventDefault(); + xEnd = e.pageX; + if (xEnd - xStart > 20) { + $this.prevSlide(); + } else if (xStart - xEnd > 20) { + $this.nextSlide(); + } + }); + }, + isVideo: function(src, index) { + var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9_\-]+)/i); + var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i); + var iframe = false; + if (settings.dynamic) { + if (settings.dynamicEl[index].iframe == 'true') { + iframe = true; + } + } else { + if ($children.eq(index).attr('data-iframe') == 'true') { + iframe = true; + } + } + if (youtube || vimeo || iframe) { + return true; + } + }, + loadVideo: function(src, _id) { + var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9_\-]+)/i); + var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i); + var video = ''; + var a = ''; + if (youtube) { + if (settings.videoAutoplay === true && lightGalleryOn === false) { + a = '?autoplay=1&rel=0&wmode=opaque'; + } else { + a = '?wmode=opaque'; + } + video = '<iframe class="object" width="560" height="315" src="//www.youtube.com/embed/' + youtube[1] + a + '" frameborder="0" allowfullscreen></iframe>'; + } else if (vimeo) { + if (settings.videoAutoplay === true && lightGalleryOn === false) { + a = 'autoplay=1&'; + } else { + a = ''; + } + video = '<iframe class="object" id="video' + _id + '" width="560" height="315" src="http://player.vimeo.com/video/' + vimeo[1] + '?' + a + 'byline=0&portrait=0&color=' + settings.vimeoColor + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; + } else { + video = '<iframe class="object" frameborder="0" src="' + src + '" allowfullscreen="true"></iframe>'; + } + return '<div class="video_cont" style="max-width:' + settings.videoMaxWidth + ' !important;"><div class="video">' + video + '</div></div>'; + }, + addHtml: function(index) { + var dataSubHtml = null; + if (settings.dynamic) { + dataSubHtml = settings.dynamicEl[index]['sub-html']; + } else { + dataSubHtml = $children.eq(index).attr('data-sub-html'); + } + if (typeof dataSubHtml !== 'undefined' && dataSubHtml !== null) { + var fL = dataSubHtml.substring(0, 1); + if (fL == '.' || fL == '#') { + dataSubHtml = $(dataSubHtml).html(); + } else { + dataSubHtml = dataSubHtml; + } + $slide.eq(index).append(dataSubHtml); + } + }, + preload: function(index) { + var newIndex = index; + for (var k = 0; k <= settings.preload; k++) { + if (k >= $children.length - index) { + break; + } + this.loadContent(newIndex + k, true); + } + for (var h = 0; h <= settings.preload; h++) { + if (newIndex - h < 0) { + break; + } + this.loadContent(newIndex - h, true); + } + }, + loadObj: function(r, index) { + var $this = this; + $slide.eq(index).find('.object').on('load error', function() { + $slide.eq(index).addClass('complete'); + }); + if (r === false) { + if (!$slide.eq(index).hasClass('complete')) { + $slide.eq(index).find('.object').on('load error', function() { + $this.preload(index); + }); + } else { + $this.preload(index); + } + } + }, + loadContent: function(index, rec) { + var $this = this; + var i, j, l = $children.length - index; + var src; + + if (settings.preload > $children.length) { + settings.preload = $children.length; + } + if (settings.mobileSrc === true && windowWidth <= settings.mobileSrcMaxWidth) { + if (settings.dynamic) { + src = settings.dynamicEl[index].mobileSrc; + } else { + src = $children.eq(index).attr('data-responsive-src'); + } + } else { + if (settings.dynamic) { + src = settings.dynamicEl[index].src; + } else { + src = $children.eq(index).attr('data-src'); + } + } + var time = 0; + if (rec === true) { + time = settings.speed + 400; + } + + + + + if (typeof src !== 'undefined' && src !== '') { + if (!$this.isVideo(src, index)) { + setTimeout(function() { + if (!$slide.eq(index).hasClass('loaded')) { + $slide.eq(index).prepend('<img class="object" src="' + src + '" />'); + $this.addHtml(index); + $slide.eq(index).addClass('loaded'); + } + $this.loadObj(rec, index); + }, time); + } else { + setTimeout(function() { + if (!$slide.eq(index).hasClass('loaded')) { + $slide.eq(index).prepend($this.loadVideo(src, index)); + $this.addHtml(index); + $slide.eq(index).addClass('loaded'); + + if (settings.auto && settings.videoAutoplay === true) { + clearInterval(interval); + } + } + $this.loadObj(rec, index); + }, time); + + } + } else { + setTimeout(function() { + if (!$slide.eq(index).hasClass('loaded')) { + var dataHtml = null; + if (settings.dynamic) { + dataHtml = settings.dynamicEl[index].html; + } else { + dataHtml = $children.eq(index).attr('data-html'); + } + if (typeof dataHtml !== 'undefined' && dataHtml !== null) { + var fL = dataHtml.substring(0, 1); + if (fL == '.' || fL == '#') { + dataHtml = $(dataHtml).html(); + } else { + dataHtml = dataHtml; + } + } + if (typeof dataHtml !== 'undefined' && dataHtml !== null) { + $slide.eq(index).append('<div class="video_cont" style="max-width:' + settings.videoMaxWidth + ' !important;"><div class="video">'+dataHtml+'</div></div>'); + } + $this.addHtml(index); + $slide.eq(index).addClass('loaded complete'); + + if (settings.auto && settings.videoAutoplay === true) { + clearInterval(interval); + } + } + $this.loadObj(rec, index); + }, time); + } + + }, + counter: function() { + if (settings.counter === true) { + var slideCount = $("#lightGallery-slider > div").length; + $gallery.append("<div id='lightGallery_counter'><span id='lightGallery_counter_current'></span> / <span id='lightGallery_counter_all'>" + slideCount + "</span></div>"); + } + }, + buildThumbnail: function() { + if (settings.thumbnail === true && $children.length > 1) { + var $this = this, + $close = ''; + if (!settings.showThumbByDefault) { + $close = '<span class="close ib"><i class="bUi-iCn-rMv-16" aria-hidden="true"></i></span>'; + } + $gallery.append('<div class="thumb_cont"><div class="thumb_info">'+$close+'</div><div class="thumb_inner"></div></div>'); + $thumb_cont = $gallery.find('.thumb_cont'); + $prev.after('<a class="cLthumb"></a>'); + $prev.parent().addClass('hasThumb'); + $gallery.find('.cLthumb').bind('click touchend', function() { + $gallery.addClass('open'); + if ($this.doCss() && settings.mode === 'slide') { + $slide.eq(index).prevAll().removeClass('nextSlide').addClass('prevSlide'); + $slide.eq(index).nextAll().removeClass('prevSlide').addClass('nextSlide'); + } + }); + $gallery.find('.thumb_cont .close').bind('click touchend', function() { + $gallery.removeClass('open'); + }); + var thumbInfo = $gallery.find('.thumb_info'); + var $thumb_inner = $gallery.find('.thumb_inner'); + var thumbList = ''; + var thumbImg; + if (settings.dynamic) { + for (var i = 0; i < settings.dynamicEl.length; i++) { + thumbImg = settings.dynamicEl[i].thumb; + thumbList += '<div class="thumb"><img src="' + thumbImg + '" /></div>'; + } + } else { + $children.each(function() { + if (settings.exThumbImage === false || typeof $(this).attr(settings.exThumbImage) == 'undefined' || $(this).attr(settings.exThumbImage) === null) { + thumbImg = $(this).find('img').attr('src'); + } else { + thumbImg = $(this).attr(settings.exThumbImage); + } + thumbList += '<div class="thumb"><img src="' + thumbImg + '" /></div>'; + }); + } + $thumb_inner.append(thumbList); + $thumb = $thumb_inner.find('.thumb'); + $thumb.css({ + 'margin-right': settings.thumbMargin + 'px', + 'width': settings.thumbWidth + 'px' + }); + if (settings.animateThumb === true) { + var width = ($children.length * (settings.thumbWidth + settings.thumbMargin)); + $gallery.find('.thumb_inner').css({ + 'width': width + 'px', + 'position': 'relative', + 'transition-duration': settings.speed + 'ms' + }); + } + $thumb.bind('click touchend', function() { + usingThumb = true; + var index = $(this).index(); + $thumb.removeClass('active'); + $(this).addClass('active'); + $this.slide(index); + $this.animateThumb(index); + clearInterval(interval); + }); + thumbInfo.prepend('<span class="ib count">' + settings.lang.allPhotos + ' (' + $thumb.length + ')</span>'); + if (settings.showThumbByDefault) { + $gallery.addClass('open'); + } + } + }, + animateThumb: function(index) { + if (settings.animateThumb === true) { + var thumb_contW = $gallery.find('.thumb_cont').width(); + var position; + switch (settings.currentPagerPosition) { + case 'left': + position = 0; + break; + case 'middle': + position = (thumb_contW / 2) - (settings.thumbWidth / 2); + break; + case 'right': + position = thumb_contW - settings.thumbWidth; + } + var left = ((settings.thumbWidth + settings.thumbMargin) * index - 1) - position; + var width = ($children.length * (settings.thumbWidth + settings.thumbMargin)); + if (left > (width - thumb_contW)) { + left = width - thumb_contW; + } + if (left < 0) { + left = 0; + } + if (this.doCss()) { + $gallery.find('.thumb_inner').css('transform', 'translate3d(-' + left + 'px, 0px, 0px)'); + } else { + $gallery.find('.thumb_inner').animate({ + left: -left + "px" + }, settings.speed); + } + } + }, + slideTo: function() { + var $this = this; + if (settings.controls === true && $children.length > 1) { + $gallery.append('<div id="lightGallery-action"><a id="lightGallery-prev"></a><a id="lightGallery-next"></a></div>'); + $prev = $gallery.find('#lightGallery-prev'); + $next = $gallery.find('#lightGallery-next'); + $prev.bind('click', function() { + $this.prevSlide(); + clearInterval(interval); + }); + $next.bind('click', function() { + $this.nextSlide(); + clearInterval(interval); + }); + } + }, + autoStart: function() { + var $this = this; + if (settings.auto === true) { + interval = setInterval(function() { + if (index + 1 < $children.length) { + index = index; + } else { + index = -1; + } + index++; + $this.slide(index); + }, settings.pause); + } + }, + keyPress: function() { + var $this = this; + $(window).bind('keyup.lightGallery', function(e) { + e.preventDefault(); + e.stopPropagation(); + if (e.keyCode === 37) { + $this.prevSlide(); + clearInterval(interval); + } + if (e.keyCode === 38 && settings.thumbnail === true && $children.length > 1) { + if (!$gallery.hasClass('open')) { + if ($this.doCss() && settings.mode === 'slide') { + $slide.eq(index).prevAll().removeClass('nextSlide').addClass('prevSlide'); + $slide.eq(index).nextAll().removeClass('prevSlide').addClass('nextSlide'); + } + $gallery.addClass('open'); + } + } else if (e.keyCode === 39) { + $this.nextSlide(); + clearInterval(interval); + } + if (e.keyCode === 40 && settings.thumbnail === true && $children.length > 1 && !settings.showThumbByDefault) { + if ($gallery.hasClass('open')) { + $gallery.removeClass('open'); + } + } else if (settings.escKey === true && e.keyCode === 27) { + if (!settings.showThumbByDefault && $gallery.hasClass('open')) { + $gallery.removeClass('open'); + } else { + plugin.destroy(false); + } + } + }); + }, + nextSlide: function() { + var $this = this; + index = $slide.index($slide.eq(prevIndex)); + if (index + 1 < $children.length) { + index++; + $this.slide(index); + } else { + if (settings.loop) { + index = 0; + $this.slide(index); + } else if (settings.thumbnail === true && $children.length > 1 && !settings.showThumbByDefault) { + $gallery.addClass('open'); + } else { + $slide.eq(index).find('.object').addClass('rightEnd'); + setTimeout(function() { + $slide.find('.object').removeClass('rightEnd'); + }, 400); + } + } + $this.animateThumb(index); + settings.onSlideNext.call(this, plugin); + }, + prevSlide: function() { + var $this = this; + index = $slide.index($slide.eq(prevIndex)); + if (index > 0) { + index--; + $this.slide(index); + } else { + if (settings.loop) { + index = $children.length - 1; + $this.slide(index); + } else if (settings.thumbnail === true && $children.length > 1 && !settings.showThumbByDefault) { + $gallery.addClass('open'); + } else{ + $slide.eq(index).find('.object').addClass('leftEnd'); + setTimeout(function() { + $slide.find('.object').removeClass('leftEnd'); + }, 400); + } + } + $this.animateThumb(index); + settings.onSlidePrev.call(this, plugin); + }, + slide: function(index) { + var $this = this; + if (lightGalleryOn) { + setTimeout(function() { + $this.loadContent(index, false); + }, settings.speed + 400); + if (!$slider.hasClass('on')) { + $slider.addClass('on'); + } + if (this.doCss() && settings.speed !== '') { + if (!$slider.hasClass('speed')) { + $slider.addClass('speed'); + } + if (aSpeed === false) { + $slider.css('transition-duration', settings.speed + 'ms'); + aSpeed = true; + } + } + if (this.doCss() && settings.cssEasing !== '') { + if (!$slider.hasClass('timing')) { + $slider.addClass('timing'); + } + if (aTiming === false) { + $slider.css('transition-timing-function', settings.cssEasing); + aTiming = true; + } + } + settings.onSlideBefore.call(this, plugin); + } else { + $this.loadContent(index, false); + } + if (settings.mode === 'slide') { + var isiPad = navigator.userAgent.match(/iPad/i) !== null; + if (this.doCss() && !$slider.hasClass('slide') && !isiPad) { + $slider.addClass('slide'); + } else if (this.doCss() && !$slider.hasClass('useLeft') && isiPad) { + $slider.addClass('useLeft'); + } + /* if(this.doCss()){ + $slider.css({ 'transform' : 'translate3d('+(-index*100)+'%, 0px, 0px)' }); + }*/ + if (!this.doCss() && !lightGalleryOn) { + $slider.css({ + left: (-index * 100) + '%' + }); + //$slide.eq(index).css('transition','none'); + } else if (!this.doCss() && lightGalleryOn) { + $slider.animate({ + left: (-index * 100) + '%' + }, settings.speed, settings.easing); + } + } else if (settings.mode === 'fade') { + if (this.doCss() && !$slider.hasClass('fadeM')) { + $slider.addClass('fadeM'); + } else if (!this.doCss() && !$slider.hasClass('animate')) { + $slider.addClass('animate'); + } + if (!this.doCss() && !lightGalleryOn) { + $slide.fadeOut(100); + $slide.eq(index).fadeIn(100); + } else if (!this.doCss() && lightGalleryOn) { + $slide.eq(prevIndex).fadeOut(settings.speed, settings.easing); + $slide.eq(index).fadeIn(settings.speed, settings.easing); + } + } + if (index + 1 >= $children.length && settings.auto && settings.loop === false) { + clearInterval(interval); + } + $slide.eq(prevIndex).removeClass('current'); + $slide.eq(index).addClass('current'); + if (this.doCss() && settings.mode === 'slide') { + if (usingThumb === false) { + $('.prevSlide').removeClass('prevSlide'); + $('.nextSlide').removeClass('nextSlide'); + $slide.eq(index - 1).addClass('prevSlide'); + $slide.eq(index + 1).addClass('nextSlide'); + } else { + $slide.eq(index).prevAll().removeClass('nextSlide').addClass('prevSlide'); + $slide.eq(index).nextAll().removeClass('prevSlide').addClass('nextSlide'); + } + } + if (settings.thumbnail === true && $children.length > 1) { + $thumb.removeClass('active'); + $thumb.eq(index).addClass('active'); + } + if (settings.controls && settings.hideControlOnEnd && settings.loop === false && $children.length > 1) { + var l = $children.length; + l = parseInt(l) - 1; + if (index === 0) { + $prev.addClass('disabled'); + $next.removeClass('disabled'); + } else if (index === l) { + $prev.removeClass('disabled'); + $next.addClass('disabled'); + } else { + $prev.add($next).removeClass('disabled'); + } + } + prevIndex = index; + lightGalleryOn === false ? settings.onOpen.call(this, plugin) : settings.onSlideAfter.call(this, plugin); + setTimeout(function() { + lightGalleryOn = true; + }); + usingThumb = false; + if (settings.counter) { + $("#lightGallery_counter_current").text(index + 1); + } + $(window).bind('resize.lightGallery', function() { + setTimeout(function() { + $this.animateThumb(index); + }, 200); + }); + } + }; + plugin.isActive = function() { + if (isActive === true) { + return true; + } else { + return false; + } + + }; + plugin.destroy = function(d) { + isActive = false; + d = typeof d !== 'undefined' ? false : true; + settings.onBeforeClose.call(this, plugin); + var lightGalleryOnT = lightGalleryOn; + lightGalleryOn = false; + aTiming = false; + aSpeed = false; + usingThumb = false; + clearInterval(interval); + if (d === true) { + $children.off('click touch touchstart'); + } + $('.lightGallery').off('mousedown mouseup'); + $('body').off('touchstart.lightGallery touchmove.lightGallery touchend.lightGallery'); + $(window).off('resize.lightGallery keyup.lightGallery'); + if (lightGalleryOnT === true) { + $gallery.addClass('fadeM'); + setTimeout(function() { + $galleryCont.remove(); + $('body').removeClass('lightGallery'); + }, 500); + } + settings.onCloseAfter.call(this, plugin); + }; + lightGallery.init(); + return this; + }; +}(jQuery));
\ No newline at end of file |