/*
 TeeChart(tm) for JavaScript(tm)
 @fileOverview TeeChart for JavaScript(tm)
 v1.4 December 2012
 Copyright(c) 2012 by Steema Software SL. All Rights Reserved.
 http://www.steema.com

 Licensed with commercial and non-commercial attributes,
 specifically: http://www.steema.com/licensing/html5

 JavaScript is a trademark of Oracle Corporation.
*/
var Tee=Tee||{};
(function(){function u(t,r,e){var a,b,c=r,d,g,f;do if(d=c.links){g=d.length;for(b=0;b<g;b++){a=d[b].dimension;do{f=t;do if(a==f)return d[b].searchDimension=d[b].dimension,e.push(d[b]),d[b];while(f=f.parent);if((f=u(t,a,e))||(f=u(a,t,e)))return e.unshift(d[b]),f}while(a=a.parent)}}while(c=c.parent);d=r.subDimensions;for(b=0;b<d.length;b++)if(f=u(t,d[b],e))return f;return null}"undefined"!==typeof exports&&(exports.Tee=Tee);Tee.Data=function(){function t(e,a){if(a)for(var b=0,c=a.length,b=0;b<c;b++)e.push({id:a[b],
value:0,count:0})}this.datasets=[];this.addDataSet=function(e,a,b,c){a&&a.implementation&&(a=r(a));e=new Tee.Data.Dimension(e,b,c);e.object=a;e.dataset=e;e.dimensions=[];e.engine=this;this.datasets.push(e);return e};this.addJSON=function(e,a,b,c){return this.addDataSet(e,JSON.parse(a),b,c)};this.applyStyle=function(e,a){switch(a){case 0:e.panel.transparent=!1,e.panel.format.round.x=0,e.panel.format.round.y=0,e.panel.format.stroke.size=2,e.panel.format.stroke.fill="darkgray"}};this.groupOther=function(e,
a,b){var c,d=e.values.length,g,f;if(d>a){f=0;g=d-a;for(c=a;c<d;c++)f+=e.values[c];e.values[a-1]=f;e.labels[a-1]=b;e.values.splice(a,g);e.labels.splice(a,g);e.code.splice(a,g);return g}return-1};this.slider=function(e,a,b,c,d,g){var f=new Tee.Slider(e);f.min=0;f.max=a.length-1;f.step=1;f.position=f.min;f.useRange=!1;f.thumbSize=12;f.horizontal=!0;f.bounds.x=b;f.bounds.y=c;f.bounds.width=d;f.bounds.height=g;e.tools.add(f);return f};var r=function(e){var a={},b;if(1==e.nodeType){if(0<e.attributes.length)for(var c=
0;c<e.attributes.length;c++)b=e.attributes.item(c),a[b.nodeName]=b.value}else 3==e.nodeType&&(a=e.nodeValue);if(e.hasChildNodes())for(c=0;c<e.childNodes.length;c++){b=e.childNodes.item(c);var d=b.nodeName;if("undefined"==typeof a[d])"#text"===d?b.hasChildNodes()?a[d]=r(b):(b=b.nodeValue.trim(),""!==b&&(a=b)):"xml"==d?a=r(b):a[d]=r(b);else{if("undefined"==typeof a[d].push){var g=a[d];a[d]=[];a[d].push(g)}a[d].push(r(b))}}return a};this.loadXMLDoc=function(e){var a=window.XMLHttpRequest?new XMLHttpRequest:
new ActiveXObject("Microsoft.XMLHTTP");a.open("GET",e,!1);a.send();return a.responseXML};this.loadXMLString=function(e){window.DOMParser?(parser=new DOMParser,xmlDoc=parser.parseFromString(e,"text/xml")):(xmlDoc=new ActiveXObject("Microsoft.XMLDOM"),xmlDoc.async=!1,xmlDoc.loadXML(e));return xmlDoc};this.queryDim=function(e,a,b){var c=e.dimension.getLinksTo(a),d,g;if(c){var f=c[0];e.initDims();var i="function"===typeof e.name?e.name:null;e.dimension.traverse(function(d,l){var m=null;if(!e.name||e.consider(d))if(a?
null===f.field&&a==f.dimension?m=a.hasID?a.parent?a.data[a.id]:d[a.id]:a==e.dimension?l||b.length:a.field?d[a.field]:l:(m=a.searchAcross(c,d))&&a.hasID&&(m=m[a.id]):(m=e.dimension.title,m||(m=e.dimension.dataset.object,e.dimension.field&&(m=m[e.dimension.field]))),null!==m&&(!a||a.nulls||""!==m)){var g=-1,s,h=i?i(d):e.name?d[e.name]:d;"undefined"===typeof h?h=null:("number"!==typeof h&&(h=parseFloat(h)),h!==h&&(h=null));if(null!==h){a&&a.datetime&&(m=a.datePart(m));for(s=0;s<b.length;s++)if(b[s].id==
m){g=s;if(0===b[g].count)b[g].count=1,b[g].value=h;else{s=e.measure;var k=h,j=b[g];j.count++;switch(s){case "sum":case "average":j.value+=k;break;case "high":if(1==j.count||k>j.value)j.value=k;break;case "low":if(1==j.count||k<j.value)j.value=k}}break}-1==g&&b.push({id:m,value:h,count:1})}}return!0});if("count"==e.measure)for(d=0;d<b.length;d++)g=b[d],g.value=g.count;else if("average"==e.measure)for(d=0;d<b.length;d++)g=b[d],0<g.count&&(g.value/=g.count);return!0}return!1};this.query=function(e,a){var b,
c,d,g,f,i=[],n,l,m,v,s;c=a instanceof Array?a:[a];g=e instanceof Array?e:[e];v=g.length;if(0<v)if(n=(s=g[0])?s.selected:null,m=[],n)m=n instanceof Array?n:[n];else if(s&&(s.id||s.field))m=s.getIds();for(n=0;n<c.length;n++)if(b=c[n]){for(l=v-1;0<=l;l--)if(d=g[l],0<l){if(d){var h=d.selected,k;if(h)if(h instanceof Array||(h=[h]),d.selectedInclude)k=h;else{k=d.getIds();for(f=0;f<h.length;f++)k.splice(k.indexOf(h[f]),1)}else k=d.getIds();for(var j=0;j<k.length;j++)if(d.selected=k[j],d.nulls||""!==d.selected)if(f=
[],t(f,m),this.queryDim(b,g[l-1],f,d)){var p;if(!(p=d.nulls)){p=0;for(var q=void 0,q=0;q<f.length;q++)p+=f[q].count;p=0<p}p&&i.push({metric:b,dimension:d,values:f,master:d.selected,masterdim:g[l-1]})}d.selected=h;break}}else f=[],t(f,m),this.queryDim(b,d,f)&&i.push({metric:b,dimension:d,values:f,master:null});if(0<v&&s&&!s.nulls)for(d=0;d<i[0].values.length;){for(b=l=0;b<i.length;b++)l+=i[b].values[d].count;if(0===l)for(b=0;b<i.length;b++)i[b].values.splice(d,1);else d++}}return i};this.Chart=function(e,
a){function b(a,b){var c=0,d;for(d=0;d<a.length;d++)c+=a[d].data.values[b];return c}var c=new Tee.Chart(e);c.engine=this;c.panel.margins.left=0;var d=new Tee.ToolTip(c);d.render="dom";c.tools.add(d);d.ongettext=function(a,b,c,d){var a="",f=c.data.labels;1<c.chart.series.count()&&(a="<br/>"+c.title);c.data.x&&(a+="<br/>"+c.data.x[d]);return b+" "+(0<f.length?f[d]:"")+a};var g=new Tee.Animation;g.onstart=function(){this.s.fill="yellow"};g.onstop=function(){this.s.fill=this.old};g.duration=100;g.animateHover=
function(a){this.s=a.series.items[0].hover.stroke;this.old=this.s.fill;this.animate(a)};c.title.text=a;c.guessStyle=function(a){return this.defaultStyle?this.defaultStyle:30<a.length?Tee.Line:Tee.Bar};c.newSeries=function(a,b){var d=b.values,f=b.dimension,g=b.master;b.masterdim||(g=g&&f&&f.id?g[f.id]:b.master||b.metric.title);var e=c.guessStyle(d),h=c.addSeries(new e),k=h.data;h.title=""+(g||"(none)");h.marks.style="value";h.cursor="pointer";k.values=[];k.labels=[];k.code=[];var j;j=c.series.items.length;
var g=[],p,q;f&&f.titles&&u(f.titles,f,g);if(1<j){var r=c.series.items[j-2].data;for(q=0;q<r.values.length;q++)k.values.push(0),k.labels.push(r.labels[q]),k.code.push(r.code[q]);for(q=0;q<d.length;q++)j=d[q],p=r.code.indexOf(j.id),-1==p?(k.values.push(j.value),p=f&&f.titles?(p=f.searchAcross(g,j.id))?p[f.titles.id]:"":j.id[f.id],k.labels.push(p),k.code.push(j.id)):k.values[p]=j.value}else for(q=0;q<d.length;q++)j=d[q],k.values.push(j.value),p=f&&f.titles?(p=f.searchAcross(g,j.id))?p[f.titles.id]:
"":""+j.id,k.labels.push(p),k.code.push(j.id);e==Tee.CircularGauge&&h.setValue(h.data.values[0]);if(this.onnewseries)this.onnewseries(this,h);return h};c.defaultStyle=null;c.animateChanges=!1;c.setSeriesStyle=function(a){if(!a||""===a||"auto"===a)this.defaultStyle=null;else{var b=this.series,c,d;this.defaultStyle=d="string"===typeof a?eval(a):a;for(var f=0;f<b.items.length;f++)c=b.items[f].data,a=new d,a.setChart(a,this),a.format.fill=b.items[f].format.fill,a.data=c,b.items[f]=a;this.draw()}};c.fill=
function(a,b,c){this.fillQuery(this.engine.query(a,b),a,b,c)};c.fillQuery=function(a,b,d,f){var g,e,h,k=c.series.items;c.series.items=[];if(a){for(g=0;g<a.length;g++){e=a[g];h=e.metric;this.newSeries(h,e).onclick=c.engine._onclickseries;if(""===c.title.text||"undefined"===typeof c.title.text)c.title.text=h.dimension.title;d instanceof Array||(c.legend.title.text=h.title+"\n"+h.measure,c.legend.title.format.font.textAlign="right");if((e=b instanceof Array?b[0]:b)&&e!=h.dataset)c.axes.bottom.title.text=
e.datetime?e.title+" "+e.dateKeys[e.datetime.selected]:e.title}0<a.length&&(c.axes.left.title.text=a[0].metric.title)}a=this.sort;""!==a.sortBy&&this.sortData(a.sortBy,"ascending"===a.order);""!==a.series&&this.sortSeries("ascending"==a.series);if(c.animateChanges&&k.length==c.series.items.length){var a=c.series.items[0],j=a.data.values;if(k[0].prototype==a.prototype&&k[0].data.values.length==j.length){var p=j.slice(0),q,a=new Tee.Animation(c,function(a){for(var b=0;b<j.length;b++)q=k[0].data.values[b],
j[b]=q+(p[b]-q)*a}),b=c.axes.left.automatic;c.axes.left.automatic=!1;a.duration=150;a.animate();c.axes.left.automatic=b}}f||c.draw()};this.applyStyle(c,0);c.animateClick=function(){g.animateHover(c)};this.onclickseries=null;this._onclickseries=function(a,b){var c=a.chart;c.onclickseries&&(c.animateClick(),c.onclickseries(a,b))};c.setSeriesPalette=function(a,b){var c=a.palette,d=a.count(),f=a.data.code,g;c.colors=Array(d);for(var e=0;e<d;e++)g=f[e],b.isSelected(g)||(c.colors[e]="silver")};c.sortData=
function(a,c){var d,f=this.series.count(),g=this.series.items[0];if(0<f){if(1<f&&"values"==a){var f=g.data.values.length,e=this.series.items;d=Array(f);for(g=0;g<f;g++)d[g]=g;d.sort(function(a,d){var f=b(e,a),g=b(e,d);return c?f-g:g-f})}else d=this.series.items[0].doSort(a,c);this.series.each(function(a){for(var b={values:[],labels:[],code:[]},c=a.data,f,g=0;g<c.values.length;g++)f=d[g],b.values.push(c.values[f]),b.labels.push(c.labels[f]),b.code.push(c.code[f]);a.data=b})}};c.sortSeries=function(a){var b=
this.series.items,c=b.length;if(!(2>c)){for(var d=Array(c),f,g,e=a?-1:1,k=a?1:-1,a=0;a<c;a++)d[a]=a;d.sort(function(a,c){f=b[a].title.toLowerCase();g=b[c].title.toLowerCase();return f<g?e:f==g?0:k});for(var j=Array(c),a=0;a<c;a++)j[a]=b[d[a]];this.series.items=j}};c.groupOther=function(a){this.series.each(function(b){var c=Engine.groupOther(b.data,a,"Other");-1<c&&(b.data.code[c]=null,b.data.code.splice(0,c))})};c.totalPoints=function(){var a=0;this.series.each(function(b){a+=b.data.values.length});
return a};c.sort={sortBy:"",order:"descending",series:"ascending"};c.setPositionPercent=function(a,b,c,d){var f=self.innerHeight?self.innerHeight:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body?document.body.clientHeight:0,g=self.innerHeight?self.innerWidth:document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientWidth:document.body?document.body.clientWidth:0,e=this.canvas,c=c*0.01*g|0,d=d*0.01*
f|0;e.style.position="absolute";e.style.left=0.01*a*g+"px";e.style.top=0.01*b*f+"px";e.style.width=c+"px";e.style.height=d+"px";e.setAttribute("width",c);e.setAttribute("height",d);this.bounds.width=c;this.bounds.height=d;this.draw()};if(Tee.SeriesAnimation){d=c.animation=new Tee.SeriesAnimation(c);d.kind="zoomin";d.duration=300;var f=new Tee.FadeAnimation(c);f.fade.series=!0;d.items.push(f)}return c}};Tee.Data.Metric=function(t,r,e){this.name=e;this.title=r||e;this.dimension=t;var a=(this.dataset=
t.dataset).engine;this.measure="sum";this.initDims=function(){var b,c=a.datasets.length,d,g,f,e,n=this.dimension;this.allDims=[];for(b=0;b<c;b++){g=a.datasets[b].dimensions;f=g.length;for(d=0;d<f;d++)e=g[d],n!=e&&(!n.hasParent(e)&&e.anySelected())&&(e._link=e.dataset==n.dataset?null:n.getLinksTo(e),this.allDims.push(e))}};this.consider=function(a){var c,d=this.allDims.length,g,f;for(c=0;c<d;c++){g=this.allDims[c];if(g._link){f=a;for(var e=0;e<g._link.length;e++)f=g.search(g._link[e],f);f&&g.id&&(f=
f[g.id])}else f=a[g.field];if("undefined"===typeof f||null===f)return!1;g.datetime&&(f=g.datePart(f));if(!g.inSelected(f))return!1}return!0}};Tee.Data.Dimension=function(t,r,e){this.engine=this.parent=this.dataset=null;this.subDimensions=[];this.field=r;this.id=e;this.title=t||r;this.nulls=!0;this.hasID="undefined"!==typeof e&&null!==e&&""!==e;this.metrics=[];this.links=[];this.select=this.selected=null;this.selectedInclude=!0;this.dateKeys={c:"Century",x:"Decade",y:"Year",m:"Month",w:"Weekday",d:"Day"};
this.addDimension=function(a,b,c){return this.addSubDimension(this,a,b,c)};this.addSubDimension=function(a,b,c,d){b=new Tee.Data.Dimension(b,c,d);b.engine=this.engine;if(b.parent=a)b.dataset=a.dataset,b.dataset&&(b.index=b.dataset.dimensions.push(b)),a.subDimensions.push(b);return b};this.addMetric=function(a,b,c){a=new Tee.Data.Metric(this,a,b);c&&(a.measure=c);this.metrics.push(a);return a};this.addLink=function(a,b,c){a={field:a,dimension:b,datasetField:c,parent:this};this.links.push(a);return a};
this.hasParent=function(a){for(var b=this.parent;b;){if(b==a)return!0;b=b.parent}return!1};this.inSelected=function(a){return this.select?this.select(a):this.selected instanceof Array?this.selectedInclude?-1!=this.selected.indexOf(a):-1==this.selected.indexOf(a):this.selectedInclude?this.selected==a:this.selected!=a};this.get=function(a){var b=this.id,c,d=this.datetime,e=this;this.traverse(function(f){d&&(f=e.datePart(f));return a==(b?f[b]:f)?(c=f,!1):!0});return c};this.datePart=function(a){var b=
this.datetime,c=b.selected;if("string"==typeof a){var d=a.match(/(\d+)/g);if("y"==c)return d[b.yearField||2];if("m"==c)return d[b.monthField||0];if("x"==c)return 10*(parseInt(d[2],10)/10|0);if("d"==c)return d[b.dayField||1];if("w"==c)return(new Date(a)).getDay()}else if(a instanceof Date){if("y"==c)return a.getFullYear();if("m"==c)return a.getMonth()+1;if("x"==c)return 10*(a.getFullYear()/10|0);if("d"==c)return a.getDate();if("w"==c)return a.getDay()}return a};this.getValues=function(){var a=[],b=
this.field,c=this.id,d=this;this.traverse(function(e){c&&(e=b?e[b]:e[c]);d.datetime&&(e=d.datePart(e));-1==a.indexOf(e)&&a.push(e);return!0});return a};this.getIds=function(){var a=[],b,c=this.id,d=this.field,e=this;(this.parent?this.parent:this).traverse(function(f){b=c?f[c]:d?f[d]:f;e.datetime&&(b=e.datePart(b));(e.nulls||b)&&-1==a.indexOf(b)&&a.push(b);return!0});return a};this.isSelected=function(a){return this.select?this.select(a):this.selected?this.inSelected(a):!0};this.anySelected=function(){if(this.select)return!0;
var a=this.selected;if(null!==a&&"undefined"!=typeof a)if(a instanceof Array)for(var b=0;b<a.length;b++){if(a[b])return!0}else return!0;return!1};this.toggleSelected=function(a,b){this.selected||(this.selected=[]);var c=a.data.code[b],d=this.selected.indexOf(c);-1===d?this.selected.push(c):(this.selected.splice(d,1),0===this.selected.length&&(this.selected=null));a.chart.setSeriesPalette(a,this)};this.traverse=function(a){function b(d,e){var i,n;i=c[e];n=i.anySelected();var l=i.field?d[i.field]:d,
m=i.parent?d:l;if(!n||i.isSelected(i.id?m[i.id]:m))if(i.data=m,l instanceof Array)if(n=l.length,0<e)for(i=0;i<n;i++){if(!b(l[i],e-1))return!1}else for(i=0;i<n;i++){if(!a(l[i],i))return!1}else if(0<e){a:if(l&&"object"===typeof l){var r=Object.keys(l),s=r.length,h=c[0],k=h.anySelected();for(i=0;i<s;i++)if(m=r[i],!k||h.isSelected(m))if(n=l[m],h.data=n,!a(n,m)){l=!1;break a}l=!0}else l=a(l,void 0);if(!l)return!1}else if(!a(m))return!1;return!0}var c=[],d=this;do c.push(d);while(d=d.parent);(d=this.dataset.object)&&
b(d,c.length-1)};this.searchAcross=function(a,b){for(var c=b,d=this,e=0;e<a.length;e++)c=d.search(a[e],c,0<e),e<a.length-1&&(d=a[e+1].parent,a[e+1].searchDimension=d);c&&this.engine.cache&&(b.cache||(b.cache=[]),b.cache[this.index]||(b.cache[this.index]=c));return c};this.search=function(a,b,c){if(b.cache&&b.cache[this.index])return b.cache[this.index];var d=null,e,f,i=a.search,n=c?a.field:a.datasetField,c=c?a.datasetField:a.field,l=c instanceof Array;if(l){e=[];for(f=0;f<c.length;f++)e.push(b[c[f]])}else e=
b[c];a=a.searchDimension||a.dimension;do if(a.traverse(function(a){if(i){if(i(a,b))return d=a,!1}else if(l){var c=!0;for(f=0;f<e.length;f++)if(a[n[f]]!==e[f]){c=!1;break}if(c)return d=a,!1}else if(a[n]==e)return d=a,!1;return!0}),d){if(a.dataset!==this.dataset)return d;if(a!==this)if(a.parent)a=a.parent,d=a.data;else break}else break;while(a!==this);return d?this.id?d:d[this.field]:null};this.getLinksTo=function(a){if(!a||a==this.dataset||a.dataset==this.dataset)return[{field:null,dimension:a,datasetField:null,
parent:this}];var b=[],c=u(a,this,b);c||(c=u(this,a,b));return c?b:null}}}).call(this);
