diff --git a/lib/core/amd/mtchart.core.amd.js b/lib/core/amd/mtchart.core.amd.js index 9f37e74..9a88a9a 100644 --- a/lib/core/amd/mtchart.core.amd.js +++ b/lib/core/amd/mtchart.core.amd.js @@ -9,2281 +9,2293 @@ }(this, function ($) { var ChartAPI = (function (global, $) { - "use strict"; - var jQuery = $; - var ChartAPI = {}; - var MT = global.MT = global.MT || {}; - MT.ChartAPI = ChartAPI; - - ChartAPI.Data = {}; - -/** - * return back cloned data to callback. - * @param {!jQuery} jQuery ajax/deffered object - * @param {=jQuery} jQuery objecto of container element to attach ajax response status message which is required when this keyword has context(not null). - * @param {Function} callback function - * @param {=Object} current context - * @return {object} - */ -ChartAPI.Data.getData = function (obj, $container, callback, that) { - var cloneData, status, def, errorClassName; - if (obj) { - obj.done(function (data) { - if (!cloneData) { - if (typeof data === 'string') { - cloneData = data.toString(); - } else if (jQuery.isArray(data)) { - cloneData = jQuery.map(data, function (v) { - return jQuery.extend({}, v); - }); - } else { - cloneData = jQuery.extend({}, data); + "use strict"; + var jQuery = $; + var ChartAPI = {}; + var MT = global.MT = global.MT || {}; + MT.ChartAPI = ChartAPI; + + ChartAPI.Data = {}; + + /** + * return back cloned data to callback. + * @param {!jQuery} jQuery ajax/deffered object + * @param {=jQuery} jQuery objecto of container element to attach ajax response status message which is required when this keyword has context(not null). + * @param {Function} callback function + * @param {=Object} current context + * @return {object} + */ + ChartAPI.Data.getData = function (obj, $container, callback, that) { + var cloneData, status, def, errorClassName; + if (obj) { + obj.done(function (data) { + if (!cloneData) { + if (typeof data === 'string') { + cloneData = data.toString(); + } else if (jQuery.isArray(data)) { + cloneData = jQuery.map(data, function (v) { + return jQuery.extend({}, v); + }); + } else { + cloneData = jQuery.extend({}, data); + } + } + callback(cloneData); + }) + .fail(function (e) { + status = { + '404': 'Data is not found', + '403': 'Data is forbidden to access' + }; + def = 'Some error occured in the data fetching process'; + errorClassName = e.status ? 'error-' + e.status : 'error-unknown'; + if (that) { + that.$errormsg = jQuery('
' + (status[e.status] || def) + '
') + .appendTo($container); + } + }) + .always(function () { + if (that && that.$progress && that.$progress.parent().length > 0) { + that.$progress.remove(); + } + }) + .progress(function () { + if (that && (!that.$progress || that.$progress.parent().length === 0)) { + that.$progress = jQuery('
fetching data...
') + .appendTo($container); + } + }); + } + }; + /** + * @param {!object} JSON data to filter + * @param {!Date|number} maximum threshold value for filtering + * @param {!Date|number} minimum threshold value for filtering + * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + * @param {=number} the number of set of Y data + * @param {boolean} true if you do not want to unify data into a weekly data. + * @return {object} filtered JSON data + */ + ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { + var str, hash = {}; + + yLength = yLength || 1; + jQuery.each(data, function (i, v) { + var td, key; + td = ChartAPI.Date.parse(v.x); + if (td && td >= min && td <= max) { + if (noConcat) { + key = ChartAPI.Date.createId(td, 'daily'); + hash[key] = v; + } else { + if (u === 'weekly') { + td = ChartAPI.Date.getWeekStartday(td); + } + key = ChartAPI.Date.createId(td, u); + if (hash[key]) { + for (i = 0; i < yLength; i++) { + str = i ? 'y' + i : 'y'; + hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); + } + } else { /* clone the object to prevent changing original */ + hash[key] = jQuery.extend({}, v); + } + } } + }); + return hash; + }; + + ChartAPI.Date = {}; + + /** + * return the week start day + * @param {!Date} + * @return Date + */ + ChartAPI.Date.getWeekStartday = function (d) { + return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); + }; + + /** + * return Date string array with padding zero which is for ISO 8601 string + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Array.} + */ + ChartAPI.Date.zeroPadArray = function (d, unit) { + var array; + ({ + 'yearly': function () { + array = [d.getFullYear()]; + }, + 'monthly': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'quarter': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'weekly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; + }, + 'daily': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; + }, + 'hourly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; + } + })[unit](); + return jQuery.map(array, function (v) { + v = v.toString(); + return v.length === 1 ? '0' + v : v; + }); + }; + + /** + * return uniformalized Date string to use kinds of Date ID + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createId = function (d, u) { + return ChartAPI.Date.zeroPadArray(d, u).join(''); + }; + + /** + * return uniformalized Date string to use kinds of Date label + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createXLabel = function (d, u) { + var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); + if (u === 'hourly') { + hour = array.pop(); + str = array.join('-') + ' ' + hour + ':00'; + } else { + str = array.join('-'); } - callback(cloneData); - }) - .fail(function (e) { - status = { - '404': 'Data is not found', - '403': 'Data is forbidden to access' - }; - def = 'Some error occured in the data fetching process'; - errorClassName = e.status ? 'error-' + e.status : 'error-unknown'; - if (that) { - that.$errormsg = jQuery('
' + (status[e.status] || def) + '
') - .appendTo($container); - } - }) - .always(function () { - if (that && that.$progress && that.$progress.parent().length > 0) { - that.$progress.remove(); - } - }) - .progress(function () { - if (that && (!that.$progress || that.$progress.parent().length === 0)) { - that.$progress = jQuery('
fetching data...
') - .appendTo($container); - } - }); - } -}; -/** - * @param {!object} JSON data to filter - * @param {!Date|number} maximum threshold value for filtering - * @param {!Date|number} minimum threshold value for filtering - * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - * @param {=number} the number of set of Y data - * @param {boolean} true if you do not want to unify data into a weekly data. - * @return {object} filtered JSON data - */ -ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { - var str, hash = {}; - - yLength = yLength || 1; - jQuery.each(data, function (i, v) { - var td, key; - td = ChartAPI.Date.parse(v.x); - if (td && td >= min && td <= max) { - if (noConcat) { - key = ChartAPI.Date.createId(td, 'daily'); - hash[key] = v; + return str; + }; + + /** + * parse argument and return back Date object + * reformeded date string and try again when Date.parser returns NaN or Invalid + * @param {Date|number|string|null} + * @return {Date|null} + */ + ChartAPI.Date.parse = function (d) { + var date; + if (!d || d instanceof Date) { + date = d || null; + } else if (typeof d === 'number') { + date = new Date(d); } else { - if (u === 'weekly') { - td = ChartAPI.Date.getWeekStartday(td); + date = new Date(Date.parse(d.toString())); + } + if (date && /NaN|Invalid Date/.test(date.toString())) { + date = d.replace(/-/g, '/').split('+')[0]; + if (date.split('/').length === 1) { + // parse the string like 20130305T00:00:00 + date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); + date = [date[1], date[2], date[3]].join('/'); } - key = ChartAPI.Date.createId(td, u); - if (hash[key]) { - for (i = 0; i < yLength; i++) { - str = i ? 'y' + i : 'y'; - hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); - } - } else { /* clone the object to prevent changing original */ - hash[key] = jQuery.extend({}, v); + if (date.split('/').length === 2) { + date = date + '/01'; } + date = jQuery.each(date.split('/'), function (i, v) { + return v.length === 1 ? '0' + v : v; + }).join('/'); + date = new Date(Date.parse(date)); } - } - }); - return hash; -}; - - ChartAPI.Date = {}; - -/** - * return the week start day - * @param {!Date} - * @return Date - */ -ChartAPI.Date.getWeekStartday = function (d) { - return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); -}; - -/** - * return Date string array with padding zero which is for ISO 8601 string - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Array.} - */ -ChartAPI.Date.zeroPadArray = function (d, unit) { - var array; - ({ - 'yearly': function () { - array = [d.getFullYear()]; - }, - 'monthly': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'quarter': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'weekly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; - }, - 'daily': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; - }, - 'hourly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; - } - })[unit](); - return jQuery.map(array, function (v) { - v = v.toString(); - return v.length === 1 ? '0' + v : v; - }); -}; - -/** - * return uniformalized Date string to use kinds of Date ID - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createId = function (d, u) { - return ChartAPI.Date.zeroPadArray(d, u).join(''); -}; - -/** - * return uniformalized Date string to use kinds of Date label - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createXLabel = function (d, u) { - var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); - if (u === 'hourly') { - hour = array.pop(); - str = array.join('-') + ' ' + hour + ':00'; - } else { - str = array.join('-'); - } - return str; -}; - -/** - * parse argument and return back Date object - * reformeded date string and try again when Date.parser returns NaN or Invalid - * @param {Date|number|string|null} - * @return {Date|null} - */ -ChartAPI.Date.parse = function (d) { - var date; - if (!d || d instanceof Date) { - date = d || null; - } else if (typeof d === 'number') { - date = new Date(d); - } else { - date = new Date(Date.parse(d.toString())); - } - if (date && /NaN|Invalid Date/.test(date.toString())) { - date = d.replace(/-/g, '/').split('+')[0]; - if (date.split('/').length === 1) { - // parse the string like 20130305T00:00:00 - date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); - date = [date[1], date[2], date[3]].join('/'); - } - if (date.split('/').length === 2) { - date = date + '/01'; - } - date = jQuery.each(date.split('/'), function (i, v) { - return v.length === 1 ? '0' + v : v; - }).join('/'); - date = new Date(Date.parse(date)); - } - return date; -}; - -/** - * @param {!Date} - * @param {!number} number of data - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} calculates as start date when true - * @return {Date} - */ -ChartAPI.Date.calcDate = function (date, l, u, sym) { - var y, m, d, h; - y = date.getFullYear(); - m = date.getMonth(); - d = date.getDate(); - h = 0; - l = l - 1; - sym = sym ? -1 : 1; - ({ - 'yearly': function () { - y = y + (sym * l); - }, - 'monthly': function () { - m = m + (sym * l); - }, - 'quarter': function () { - m = m + (sym * l * 4); - }, - 'weekly': function () { - d = d + (sym * l * 7) - date.getDay(); - }, - 'daily': function () { - d = d + (sym * l); - }, - 'hourly': function () { - h = date.getHours() + (sym * l); - } - })[u](); - return new Date(y, m, d, h); -}; - - ChartAPI.Range = {}; -/** - * return unified Range data object (plain object which does not have prototyped method) - * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.factory = function (obj) { - var fn; - obj = obj || {}; - obj.maxLength = obj.maxLength || 90; - obj.dataType = obj.dataType || 'timeline'; - obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); - fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; - return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); -}; - -ChartAPI.Range.generate = ChartAPI.Range.factory; - -/** - * @param {string|null} data type - * @return {boolean} - */ -ChartAPI.Range.isTimeline = function (dataType) { - return !dataType || dataType === 'timeline'; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { - unit = unit || 'monthly'; - length = length || (unit === 'hourly' ? 24 : 10); - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = maxLength; - } - - s = ChartAPI.Date.parse(s); - e = ChartAPI.Date.parse(e); - - if (!s && !e) { - e = ChartAPI.Range.getEndDate(new Date(), unit); - } - - if (!s) { - s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); - } - if (!e) { - e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); - } - if (e > new Date()) { - e = new Date(); - } - if (s > e) { - s = e; - } - length = ChartAPI.Range.getLength(s, e, unit); - if (length > maxLength) { - length = maxLength; - s = ChartAPI.Date.calcDate(e, length, unit, true); - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - unit: unit, - dataType: dataType, - max: ChartAPI.Range.getEndDate(e, unit), - min: ChartAPI.Range.getStartDate(s, unit), - isTimeline: true - }; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { - length = length || 10; - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = Math.min(length, maxLength); - } - - if (!s && !e) { - s = 0; - e = length - 1; - } - - s = parseInt(s, 10) || (s === 0 ? 0 : null); - e = parseInt(e, 10) || (e === 0 ? 0 : null); - - if (s === null) { - s = e - length; - if (s < 0) { - s = 0; - } - } - if (e === null) { - e = s + length; - } - if (s > e) { - s = e; - } - length = e - s + 1; - if (length > maxLength) { - length = maxLength; - s = e - maxLength; - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - dataType: dataType, - unit: null, - max: e, - min: s, - isTimeline: false - }; -}; - -/** - * return start date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getStartDate = function (d, unit) { - var start, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - start = new Date(year, 0, 1, 0, 0, 0); - }, - 'monthly': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'quarter': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'weekly': function () { - start = new Date(year, month, date - d.getDay(), 0, 0, 0); - }, - 'daily': function () { - start = new Date(year, month, date, 0, 0, 0); - }, - 'hourly': function () { - start = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return start; -}; - -/** - * return end date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getEndDate = function (d, unit) { - var end, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - end = new Date(year, 11, 31, 23, 59, 59); - }, - 'monthly': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'quarter': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'weekly': function () { - end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); - }, - 'daily': function () { - end = new Date(year, month, date, 23, 59, 59); - }, - 'hourly': function () { - end = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return end < new Date() ? end : new Date(); -}; - -/** - * return next date against the desinated range unit - * @param {Date} start date - * @param {Date} end date - * @param {number} increment number from start date - * @param {string} data u - * @return {Date} - */ -ChartAPI.Range.getNextDate = function (s, e, i, u) { - var d, year = s.getFullYear(), - month = s.getMonth(), - date = s.getDate(); - ({ - 'yearly': function (i) { - d = new Date(year + i, 0, 1); - }, - 'monthly': function (i) { - d = new Date(year, month + i, 1); - }, - 'quarter': function (i) { - d = new Date(year, month + i * 4, 1); - }, - 'weekly': function (i) { - d = new Date(year, month, date + i * 7 - s.getDay()); - }, - 'daily': function (i) { - d = new Date(year, month, date + i); - }, - 'hourly': function (i) { - d = new Date(year, month, date, s.getHours() + i); - } - })[u](i); - return d < e ? d : null; -}; - -/** - * return max and min value in JSON data - * @param {!object} JSON data - * @param {=boolean} true when data type is timeline - * @return {{max:number, min:number}} - */ -ChartAPI.Range.getDataRange = function (data, isTimeline) { - var map, max, min; - - if (isTimeline) { - map = jQuery.map(data, function (v) { - return ChartAPI.Date.parse(v.x) - .valueOf(); - }); - max = Math.max.apply(null, map); - min = Math.min.apply(null, map); - } else { - min = 0; - max = data.length - 1; - } - - return { - max: max, - min: min - }; -}; - -/** - * return number of data between start and end date - * @param {!Date} - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {number} - */ -ChartAPI.Range.getLength = function (s, e, u) { - var length; - ({ - 'yearly': function () { - length = Math.ceil(e.getFullYear() - s.getFullYear()); - }, - 'monthly': function () { - length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); - }, - 'quarter': function () { - length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); - }, - 'weekly': function () { - length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); - }, - 'daily': function () { - length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); - }, - 'hourly': function () { - length = Math.ceil((e - s) / (60 * 60 * 1000)); - } - })[u](); - return length > 0 ? length + 1 : 1; -}; - - /** - * Creates Graph Object - * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this - * $container is the jQuery object to which the graph append - * $('#graphContainer').trigger('APPEND_TO',[$container]) - * you want to update graph as well, fire UPDATE event like the same manner above. - * - * @param {object} graph setings - * @param {object} object including range settings - * @return {jQuery} return container jQuery object - * @constructor - */ -ChartAPI.Graph = function (config, range) { - this.config = $.extend({ - type: 'morris.bar', - staticPath: '', - data: 'graph.json' - }, config); - - this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config.yLength = parseInt(this.config.yLength, 10) || 1; - - this.range = ChartAPI.Range.generate(range); - - if (typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - this.graphData = {}; - this.graphData[this.range.unit] = $.Deferred(); - - this.getData($.proxy(function (data) { - this.graphData[this.range.unit].resolve(this.generateGraphData(data)); - }, this)); - - this.$graphContainer = $('
'); - - /** - * @return {jQuery} return jQuery object for chaining - * update graph - */ - this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { - this.update_(newRange, unit); - return $(this.$graphContainer); - }, this)); - - this.$graphContainer.on('REMOVE', $.proxy(function () { - this.remove_(); - }, this)); - - // IE8 fires resize event even when document.body.innerWidht/innerHeight changing - // so check window.width and update only when window.width changing. - var windowWidth = $(window).width(); - this.updateFunc = $.proxy(function () { - if (windowWidth && windowWidth !== $(window).width()) { - windowWidth = $(window).width(); - this.update_(); - } - }, this); - - if (config.autoResize) { - $(window).on('orientationchange debouncedresize', this.updateFunc); - } - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback - */ - this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback - */ - this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - - /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining - */ - this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { - this.$graphContainer.appendTo(container); - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (this.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.start <= v.timestamp && v.timestamp <= this.range.end; - }, this)); - } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + return date; + }; + + /** + * @param {!Date} + * @param {!number} number of data + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} calculates as start date when true + * @return {Date} + */ + ChartAPI.Date.calcDate = function (date, l, u, sym) { + var y, m, d, h; + y = date.getFullYear(); + m = date.getMonth(); + d = date.getDate(); + h = 0; + l = l - 1; + sym = sym ? -1 : 1; + ({ + 'yearly': function () { + y = y + (sym * l); + }, + 'monthly': function () { + m = m + (sym * l); + }, + 'quarter': function () { + m = m + (sym * l * 4); + }, + 'weekly': function () { + d = d + (sym * l * 7) - date.getDay(); + }, + 'daily': function () { + d = d + (sym * l); + }, + 'hourly': function () { + h = date.getHours() + (sym * l); + } + })[u](); + return new Date(y, m, d, h); + }; + + ChartAPI.Range = {}; + /** + * return unified Range data object (plain object which does not have prototyped method) + * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.factory = function (obj) { + var fn; + obj = obj || {}; + obj.maxLength = obj.maxLength || 90; + obj.dataType = obj.dataType || 'timeline'; + obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); + fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; + return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); + }; + + ChartAPI.Range.generate = ChartAPI.Range.factory; + + /** + * @param {string|null} data type + * @return {boolean} + */ + ChartAPI.Range.isTimeline = function (dataType) { + return !dataType || dataType === 'timeline'; + }; + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { + unit = unit || 'monthly'; + length = length || (unit === 'hourly' ? 24 : 10); + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = maxLength; } - this.draw_(filteredData); - }, this)); - return $(this.$graphContainer); - }, this)); - - return this.$graphContainer; -}; - -/** - * call getData function for getting graph JSON data - * @param {Function} callback function recieve graph JSON data - */ -ChartAPI.Graph.prototype.getData = function (callback) { - ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); -}; - -/** - * return data label array with array indexes - * @param {!Array.} array of indexes - * @param {!Array.} graph JSON data - * @return {Array.} - */ -ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''); - $.each(data, function (i, v) { - total = total + parseInt((v[str] || v.value || 0), 10); - }); - return total; -}; - -/** - * return the delta number and className between last and last second count - * @param {!object} graph JSON data - * @param {!number} number of set of Y data - * @return {y:[number,string],y1:[number,string]} - */ -ChartAPI.Graph.prototype.getDelta_ = function (data, index) { - var e, s, delta, key, length = data.length; - - key = 'y' + (index || ''); - e = data[length - 1]; - s = data[length - 2]; - delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; - return delta === undefined ? '' : delta; -}; - -ChartAPI.Graph.presetColors = function () { - return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; -}; - -ChartAPI.Graph.getChartColors = function (colors, type) { - var func = { - 'reverse': function (arr) { - return arr.reverse(); - }, - 'shuffle': function (arr) { - var i, j, length, tmp; - length = arr.length; - for (i = 0; i < length; i++) { - j = Math.floor(Math.random() * length); - tmp = arr[i]; - arr[i] = arr[j]; - arr[j] = tmp; - } - return arr; - }, - 'def': function (arr) { - return arr; - } - }; - return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); -}; - -ChartAPI.Graph.cachedChartColors = {}; -ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { - return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); -}; - -/** - * Draw Graph - * @param {!Array.} graph data - * @param {=string} graph type (bar|line|area|donut) - * @return nothing - */ -ChartAPI.Graph.prototype.draw_ = function (data) { - var arr = this.config.type.split('.'); - var lib = arr[0]; - var method = arr[1]; - var config = this.config; - - if (config.label) { - if (this.labelTemplate) { - this.generateLabel(this.labelTemplate); - } else { - if (config.label.template) { - var labelTemplate = config.label.template; - if (window.require && typeof require === 'function') { - var templateType = config.label.type; - require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); - }, this)); - } else { - var dfd = $.get(config.staticPath + labelTemplate, 'text'); - ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); - }, this)); + + s = ChartAPI.Date.parse(s); + e = ChartAPI.Date.parse(e); + + if (!s && !e) { + e = ChartAPI.Range.getEndDate(new Date(), unit); + } + + if (!s) { + s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); + } + if (!e) { + e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); + } + if (e > new Date()) { + e = new Date(); + } + if (s > e) { + s = e; + } + length = ChartAPI.Range.getLength(s, e, unit); + if (length > maxLength) { + length = maxLength; + s = ChartAPI.Date.calcDate(e, length, unit, true); + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + unit: unit, + dataType: dataType, + max: ChartAPI.Range.getEndDate(e, unit), + min: ChartAPI.Range.getStartDate(s, unit), + isTimeline: true + }; + }; + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { + length = length || 10; + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = Math.min(length, maxLength); + } + + if (!s && !e) { + s = 0; + e = length - 1; + } + + s = parseInt(s, 10) || (s === 0 ? 0 : null); + e = parseInt(e, 10) || (e === 0 ? 0 : null); + + if (s === null) { + s = e - length; + if (s < 0) { + s = 0; + } + } + if (e === null) { + e = s + length; + } + if (s > e) { + s = e; + } + length = e - s + 1; + if (length > maxLength) { + length = maxLength; + s = e - maxLength; + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + dataType: dataType, + unit: null, + max: e, + min: s, + isTimeline: false + }; + }; + + /** + * return start date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} + */ + ChartAPI.Range.getStartDate = function (d, unit) { + var start, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + start = new Date(year, 0, 1, 0, 0, 0); + }, + 'monthly': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'quarter': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'weekly': function () { + start = new Date(year, month, date - d.getDay(), 0, 0, 0); + }, + 'daily': function () { + start = new Date(year, month, date, 0, 0, 0); + }, + 'hourly': function () { + start = new Date(year, month, date, d.getHours(), 0, 0); + } + })[unit](); + return start; + }; + + /** + * return end date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} + */ + ChartAPI.Range.getEndDate = function (d, unit) { + var end, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + end = new Date(year, 11, 31, 23, 59, 59); + }, + 'monthly': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'quarter': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'weekly': function () { + end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); + }, + 'daily': function () { + end = new Date(year, month, date, 23, 59, 59); + }, + 'hourly': function () { + end = new Date(year, month, date, d.getHours(), 0, 0); } + })[unit](); + return end < new Date() ? end : new Date(); + }; + + /** + * return next date against the desinated range unit + * @param {Date} start date + * @param {Date} end date + * @param {number} increment number from start date + * @param {string} data u + * @return {Date} + */ + ChartAPI.Range.getNextDate = function (s, e, i, u) { + var d, year = s.getFullYear(), + month = s.getMonth(), + date = s.getDate(); + ({ + 'yearly': function (i) { + d = new Date(year + i, 0, 1); + }, + 'monthly': function (i) { + d = new Date(year, month + i, 1); + }, + 'quarter': function (i) { + d = new Date(year, month + i * 4, 1); + }, + 'weekly': function (i) { + d = new Date(year, month, date + i * 7 - s.getDay()); + }, + 'daily': function (i) { + d = new Date(year, month, date + i); + }, + 'hourly': function (i) { + d = new Date(year, month, date, s.getHours() + i); + } + })[u](i); + return d < e ? d : null; + }; + + /** + * return max and min value in JSON data + * @param {!object} JSON data + * @param {=boolean} true when data type is timeline + * @return {{max:number, min:number}} + */ + ChartAPI.Range.getDataRange = function (data, isTimeline) { + var map, max, min; + + if (isTimeline) { + map = jQuery.map(data, function (v) { + return ChartAPI.Date.parse(v.x) + .valueOf(); + }); + max = Math.max.apply(null, map); + min = Math.min.apply(null, map); } else { - this.labelTemplate = ''; - this.generateLabel(this.labelTemplate); + min = 0; + max = data.length - 1; } - } - } - - if (config.fallback && config.fallback.test) { - if (!ChartAPI.Graph.test[config.fallback.test]()) { - arr = config.fallback.type.split('.'); - lib = arr[0]; - method = arr[1]; - config = $.extend(config, config.fallback); - } - } - - if (config.chartColors && typeof config.chartColors === 'string') { - config.chartColors = config.chartColors.split(','); - } - - this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); -}; - -ChartAPI.Graph.test = {}; - -ChartAPI.Graph.test.canvas = function () { - var elem = document.createElement('canvas'); - return elem.getContext && elem.getContext('2d'); -}; - -ChartAPI.Graph.test.svg = function () { - var ns = { - 'svg': 'http://www.w3.org/2000/svg' - }; - return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; -}; - -/* - * this test checks suport both VML and SVG since we only use VML for SVG fallback - */ -ChartAPI.Graph.test.vml = function () { - var vmlSupported; - var svgSupported = ChartAPI.Graph.test.svg(); - // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser - if (!svgSupported) { - var a = document.body.appendChild(document.createElement('div')); - a.innerHTML = ''; - var b = a.firstChild; - b.style.behavior = "url(#default#VML)"; - vmlSupported = b ? typeof b.adj === "object" : true; - a.parentNode.removeChild(a); - } - return (svgSupported || vmlSupported); -}; - -ChartAPI.Graph.prototype.generateLabel = function (template) { - var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, - yLength = this.config.label.yLength || this.config.yLength, - dfd; - - var finalize = $.proxy(function () { - this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); - - this.getData($.proxy(function (data) { - for (var i = 0; i < yLength; i++) { - if (!this.config.label.hideTotalCount) { - this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + + return { + max: max, + min: min + }; + }; + + /** + * return number of data between start and end date + * @param {!Date} + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {number} + */ + ChartAPI.Range.getLength = function (s, e, u) { + var length; + ({ + 'yearly': function () { + length = Math.ceil(e.getFullYear() - s.getFullYear()); + }, + 'monthly': function () { + length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); + }, + 'quarter': function () { + length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); + }, + 'weekly': function () { + length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); + }, + 'daily': function () { + length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); + }, + 'hourly': function () { + length = Math.ceil((e - s) / (60 * 60 * 1000)); } - if (!this.config.label.hideDeltaCount && this.range.isTimeline) { - this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + })[u](); + return length > 0 ? length + 1 : 1; + }; + + /** + * Creates Graph Object + * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this + * $container is the jQuery object to which the graph append + * $('#graphContainer').trigger('APPEND_TO',[$container]) + * you want to update graph as well, fire UPDATE event like the same manner above. + * + * @param {object} graph setings + * @param {object} object including range settings + * @return {jQuery} return container jQuery object + * @constructor + */ + ChartAPI.Graph = function (config, range) { + this.config = $.extend({ + type: 'morris.bar', + staticPath: '', + data: 'graph.json' + }, config); + + this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config.yLength = parseInt(this.config.yLength, 10) || 1; + + this.range = ChartAPI.Range.generate(range); + + if (typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); + } else { + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); + } + + this.graphData = {}; + this.graphData[this.range.unit] = $.Deferred(); + + this.getData($.proxy(function (data) { + this.graphData[this.range.unit].resolve(this.generateGraphData(data)); + }, this)); + + this.$graphContainer = $('
'); + + /** + * @return {jQuery} return jQuery object for chaining + * update graph + */ + this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { + this.update_(newRange, unit); + return $(this.$graphContainer); + }, this)); + + this.$graphContainer.on('REMOVE', $.proxy(function () { + this.remove_(); + }, this)); + + // IE8 fires resize event even when document.body.innerWidht/innerHeight changing + // so check window.width and update only when window.width changing. + var windowWidth = $(window).width(); + this.updateFunc = $.proxy(function () { + if (windowWidth && windowWidth !== $(window).width()) { + windowWidth = $(window).width(); + this.update_(); } + }, this); + + if (config.autoResize) { + $(window).on('orientationchange debouncedresize', this.updateFunc); } - }, this)); - }, this); - - if (data && typeof data === 'string') { - dfd = $.getJSON(this.config.staticPath + data); - } else { - dfd = $.Deferred(); - dfd.resolve(data); - } - - dfd.done(function (data) { - if (template && typeof template === 'function') { - template = template(data); - finalize(); - } else if (window._) { - template = _.template(template, data); - finalize(); - } else { - template = template; - finalize(); - } - }); -}; - -/** - * update Graph - * @param {=Array.} - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Graph.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.range = ChartAPI.Range.generate({ - 'start': (newRange[0] || this.range.start), - 'end': (newRange[1] || this.range.end), - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': (unit || this.range.unit), - 'dataType': this.range.dataType, - 'autoSized': this.range.autoSized - }); - - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (that.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this), this)); + return $(this.$graphContainer); }, this)); - } else { - filteredData = data.slice(this.range.min, this.range.max + 1); - } - this.draw_(filteredData); - }, this)); -}; - -ChartAPI.Graph.prototype.remove_ = function () { - if (this.config.autoResize) { - $(window).off('orientationchange debouncedresize', this.updateFunc); - } - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.$graphContainer.remove(); -}; - -ChartAPI.Graph.prototype.generateGraphData = function (data) { - var i, j, td, key, range = this.range, - start = range.start, - end = range.end, - u = range.unit, - length = range.length, - array = [], - yLength = this.config.yLength || 1, - filteredData, obj, str; - if (this.range.isTimeline) { - var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); - start = new Date(Math.min(this.range.min, dataRange.min)); - end = new Date(Math.max(this.range.max, dataRange.max)); - length = ChartAPI.Range.getLength(start, end, u); - filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); - - for (i = 0; i < length; i++) { - td = ChartAPI.Range.getNextDate(start, end, i, u); - if (td) { - key = ChartAPI.Date.createId(td, u); - obj = { - timestamp: td.valueOf(), - x: ChartAPI.Date.createXLabel(td, u) - }; - for (j = 0; j < yLength; j++) { - str = 'y' + (j || ''); - obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this), this)); + return $(this.$graphContainer); + }, this)); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { + this.$graphContainer.appendTo(container); + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (this.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.start <= v.timestamp && v.timestamp <= this.range.end; + }, this)); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } + this.draw_(filteredData); + }, this)); + return $(this.$graphContainer); + }, this)); + + return this.$graphContainer; + }; + + /** + * call getData function for getting graph JSON data + * @param {Function} callback function recieve graph JSON data + */ + ChartAPI.Graph.prototype.getData = function (callback) { + ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); + }; + + /** + * return data label array with array indexes + * @param {!Array.} array of indexes + * @param {!Array.} graph JSON data + * @return {Array.} + */ + ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''); + $.each(data, function (i, v) { + total = total + parseInt((v[str] || v.value || 0), 10); + }); + return total; + }; + + /** + * return the delta number and className between last and last second count + * @param {!object} graph JSON data + * @param {!number} number of set of Y data + * @return {y:[number,string],y1:[number,string]} + */ + ChartAPI.Graph.prototype.getDelta_ = function (data, index) { + var e, s, delta, key, length = data.length; + + key = 'y' + (index || ''); + e = data[length - 1]; + s = data[length - 2]; + delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; + return delta === undefined ? '' : delta; + }; + + ChartAPI.Graph.presetColors = function () { + return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; + }; + + ChartAPI.Graph.getChartColors = function (colors, type) { + var func = { + 'reverse': function (arr) { + return arr.reverse(); + }, + 'shuffle': function (arr) { + var i, j, length, tmp; + length = arr.length; + for (i = 0; i < length; i++) { + j = Math.floor(Math.random() * length); + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + return arr; + }, + 'def': function (arr) { + return arr; } - array.push(obj); + }; + return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); + }; + + ChartAPI.Graph.cachedChartColors = {}; + ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { + return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); + }; + + /** + * Draw Graph + * @param {!Array.} graph data + * @param {=string} graph type (bar|line|area|donut) + * @return nothing + */ + ChartAPI.Graph.prototype.draw_ = function (data) { + var arr = this.config.type.split('.'); + var lib = arr[0]; + var method = arr[1]; + var config = this.config; + + if (config.label) { + if (this.labelTemplate) { + this.generateLabel(this.labelTemplate); + } else { + if (config.label.template) { + var labelTemplate = config.label.template; + if (window.require && typeof require === 'function') { + var templateType = config.label.type; + require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } else { + var dfd = $.get(config.staticPath + labelTemplate, 'text'); + ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } + } else { + this.labelTemplate = ''; + this.generateLabel(this.labelTemplate); + } + } + } + + if (config.fallback && config.fallback.test) { + if (!ChartAPI.Graph.test[config.fallback.test]()) { + arr = config.fallback.type.split('.'); + lib = arr[0]; + method = arr[1]; + config = $.extend(config, config.fallback); + } + } + + if (config.chartColors && typeof config.chartColors === 'string') { + config.chartColors = config.chartColors.split(','); + } + + this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); + }; + + ChartAPI.Graph.test = {}; + + ChartAPI.Graph.test.canvas = function () { + var elem = document.createElement('canvas'); + return elem.getContext && elem.getContext('2d'); + }; + + ChartAPI.Graph.test.svg = function () { + var ns = { + 'svg': 'http://www.w3.org/2000/svg' + }; + return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; + }; + + /* + * this test checks suport both VML and SVG since we only use VML for SVG fallback + */ + ChartAPI.Graph.test.vml = function () { + var vmlSupported; + var svgSupported = ChartAPI.Graph.test.svg(); + // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser + if (!svgSupported) { + var a = document.body.appendChild(document.createElement('div')); + a.innerHTML = ''; + var b = a.firstChild; + b.style.behavior = "url(#default#VML)"; + vmlSupported = b ? typeof b.adj === "object" : true; + a.parentNode.removeChild(a); + } + return (svgSupported || vmlSupported); + }; + + ChartAPI.Graph.prototype.generateLabel = function (template) { + var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, + yLength = this.config.label.yLength || this.config.yLength, + dfd; + + var finalize = $.proxy(function () { + this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); + + this.getData($.proxy(function (data) { + for (var i = 0; i < yLength; i++) { + if (!this.config.label.hideTotalCount) { + this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + } + if (!this.config.label.hideDeltaCount && this.range.isTimeline) { + this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + } + } + }, this)); + }, this); + + if (data && typeof data === 'string') { + dfd = $.getJSON(this.config.staticPath + data); } else { - break; + dfd = $.Deferred(); + dfd.resolve(data); } - } - } else { - array = data; - } - if (this.config.type === 'morris.donut') { - $.each(array, function (i, v) { - $.extend(v, { - label: (v.xLabel || v.x), - value: v.y + + dfd.done(function (data) { + if (template && typeof template === 'function') { + template = template(data); + finalize(); + } else if (window._) { + template = _.template(template, data); + finalize(); + } else { + template = template; + finalize(); + } }); - }); - } - return array; -}; - - /** - * @param {!jQuery} - jQuery object to which attach label element(typically graph container) - * @param {!number} length of set of data to use - * @param {=string} html string to use label - * @constructor - */ -ChartAPI.Graph.Labels = function ($container, yLength, template) { - var i, key; - - this.$labelContainer = $('
'); - if (template) { - $('
').html(template).prependTo(this.$labelContainer); - } - - this.totals = {}; - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); - } - - this.$labelContainer.appendTo($container); -}; - -/** - * remove label container - */ -ChartAPI.Graph.Labels.prototype.remove = function () { - this.$labelContainer.remove(); -}; - -/** - * get ChartAPI.Graph.Labels.Total object - * @param {=number} the number of Y data set - * @return {ChartAPI.Graph.Labels.Total} - */ -ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { - return this.totals['y' + (i || '')]; -}; - -/** - * @constructor - * @param {!jQuery} jQuery object to attach - * @param {!number} number for identify what Y data is associated with - */ -ChartAPI.Graph.Labels.Total = function (container, index) { - this.index = index; - this.$totalContainer = jQuery('
').appendTo(container); -}; - -/** - * create element for displaying total count and append its container - * @param {!number} total count - */ -ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { - jQuery('' + count + ' ').appendTo(this.$totalContainer); -}; - -/** - * create element for displaying delta - * @param {!number} delta count - */ -ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { - var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; - - jQuery('(' + delta + ')').appendTo(this.$totalContainer); -}; - - ChartAPI.Graph.css = {}; - -ChartAPI.Graph.css.Base = function (data, config) { - this.len = data.length; - this.$graphEl = $('
'); -}; - -ChartAPI.Graph.css.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { - if (config.width) { - this.$graphEl.css({ - 'width': config.width, - 'max-width': '100%', - 'margin': '0 auto' - }); - } - - var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], - barBackgroundColor = config.barBackgroundColor || '#f0f0f0', - dateColor = config.dateColor || '#999999', - dateColorSaturday = config.dateColorSaturday || dateColor, - dateColorSunday = config.dateColorSunday || dateColor, - labelColor = config.labelColor || '#999999', - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, - createCSSGraphBarEl = function () { - return $('
'); - }, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - label = $.map(data, function (d) { - return { - value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), - weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null + }; + + /** + * update Graph + * @param {=Array.} + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.Graph.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); } - }), - maxY = Math.max.apply(null, dataY) || 1, - yLabel = config.yLabel || dataY, - width, $el, $background, $bar, $count, $date; - - for (var i = this.len; i > 0;) { - i = i - 1; - width = Math.floor((dataY[i] / maxY) * 100) - 15; - $el = createCSSGraphBarEl(); - $background = $el.find('.css-graph-bar-background'); - $background.css({ - 'background-color': barBackgroundColor - }); - - if (config.showDate) { - $date = $el.find('.css-graph-date'); - $date.text(label[i].value).css({ - 'color': dateColor, - 'font-size': dateLabelSize + 'px', - 'line-height': barWidth + 'px' + if (this.labels) { + this.labels.remove(); + } + this.range = ChartAPI.Range.generate({ + 'start': (newRange[0] || this.range.start), + 'end': (newRange[1] || this.range.end), + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': (unit || this.range.unit), + 'dataType': this.range.dataType, + 'autoSized': this.range.autoSized }); - if (label[i].weekday === 6) { - $date.addClass('saturday').css({ - 'color': dateColorSaturday + + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (that.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + }, this)); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } + this.draw_(filteredData); + }, this)); + }; + + ChartAPI.Graph.prototype.remove_ = function () { + if (this.config.autoResize) { + $(window).off('orientationchange debouncedresize', this.updateFunc); + } + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); + } + if (this.labels) { + this.labels.remove(); + } + this.$graphContainer.remove(); + }; + + ChartAPI.Graph.prototype.generateGraphData = function (data) { + var i, j, td, key, range = this.range, + start = range.start, + end = range.end, + u = range.unit, + length = range.length, + array = [], + yLength = this.config.yLength || 1, + filteredData, obj, str; + if (this.range.isTimeline) { + var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); + start = new Date(Math.min(this.range.min, dataRange.min)); + end = new Date(Math.max(this.range.max, dataRange.max)); + length = ChartAPI.Range.getLength(start, end, u); + filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); + + for (i = 0; i < length; i++) { + td = ChartAPI.Range.getNextDate(start, end, i, u); + if (td) { + key = ChartAPI.Date.createId(td, u); + obj = { + timestamp: td.valueOf(), + x: ChartAPI.Date.createXLabel(td, u) + }; + for (j = 0; j < yLength; j++) { + str = 'y' + (j || ''); + obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; + } + array.push(obj); + } else { + break; + } + } + } else { + array = data; + } + if (this.config.type === 'morris.donut') { + $.each(array, function (i, v) { + $.extend(v, { + label: (v.xLabel || v.x), + value: v.y + }); }); - } else if (label[i].weekday === 0) { - $date.addClass('sunday').css({ - 'color': dateColorSunday - }) } - - $el.find('.css-graph-bar-container').css({ - 'margin-left': barMarginLeft + 'px' - }); - } - - $bar = $el.find('.css-graph-bar'); - $bar.css({ - 'width': width + '%', - 'background-color': barColor - }); - $count = $el.find('.css-graph-bar-count'); - $count.text(yLabel[i]).css({ - 'color': labelColor, - 'font-size': labelSize + 'px', - 'line-height': barWidth + 'px' - }); - $el.appendTo(this.$graphEl); - } - - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { - var yLength = config.yLength, - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateColor = config.dateColor || '#999999', - barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - labelColors = config.labelColors, - labelClasses = config.labelClasses, - i, j, - d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; - - for (i = 0; i < this.len; i++) { - d = data[i]; - dataY = []; - totalY = 0; - totalWidth = 0; - for (j = 0; j < yLength; j++) { - dataY.push(d['y' + (j || '')]); - totalY = totalY + parseInt(d['y' + (j || '')], 10); - } - - $barContainer = $('
').appendTo(this.$graphEl); - if (config.showDate && d.x) { - label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); - $date = $('
' + label + '
').appendTo($barContainer); - } - - $el = $('
').appendTo($barContainer); - - if (config.showDate) { - $el.css({ - 'margin-left': barMarginLeft + 'px' - }); - } - - for (j = 0; j < yLength; j++) { - width = Math.floor((dataY[j] / totalY) * 1000) / 10; - - if (width) { - if (yLength === j) { - width = 100 - totalWidth; + return array; + }; + + /** + * @param {!jQuery} + jQuery object to which attach label element(typically graph container) + * @param {!number} length of set of data to use + * @param {=string} html string to use label + * @constructor + */ + ChartAPI.Graph.Labels = function ($container, yLength, template) { + var i, key; + + this.$labelContainer = $('
'); + if (template) { + $('
').html(template).prependTo(this.$labelContainer); + } + + this.totals = {}; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); + } + + this.$labelContainer.appendTo($container); + }; + + /** + * remove label container + */ + ChartAPI.Graph.Labels.prototype.remove = function () { + this.$labelContainer.remove(); + }; + + /** + * get ChartAPI.Graph.Labels.Total object + * @param {=number} the number of Y data set + * @return {ChartAPI.Graph.Labels.Total} + */ + ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { + return this.totals['y' + (i || '')]; + }; + + /** + * @constructor + * @param {!jQuery} jQuery object to attach + * @param {!number} number for identify what Y data is associated with + */ + ChartAPI.Graph.Labels.Total = function (container, index) { + this.index = index; + this.$totalContainer = jQuery('
').appendTo(container); + }; + + /** + * create element for displaying total count and append its container + * @param {!number} total count + */ + ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { + jQuery('' + count + ' ').appendTo(this.$totalContainer); + }; + + /** + * create element for displaying delta + * @param {!number} delta count + */ + ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { + var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; + + jQuery('(' + delta + ')').appendTo(this.$totalContainer); + }; + + ChartAPI.Graph.css = {}; + + ChartAPI.Graph.css.Base = function (data, config) { + this.len = data.length; + this.$graphEl = $('
'); + }; + + ChartAPI.Graph.css.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { + if (config.width) { + this.$graphEl.css({ + 'width': config.width, + 'max-width': '100%', + 'margin': '0 auto' + }); + } + + var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], + barBackgroundColor = config.barBackgroundColor || '#f0f0f0', + dateColor = config.dateColor || '#999999', + dateColorSaturday = config.dateColorSaturday || dateColor, + dateColorSunday = config.dateColorSunday || dateColor, + labelColor = config.labelColor || '#999999', + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, + createCSSGraphBarEl = function () { + return $('
'); + }, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + label = $.map(data, function (d) { + return { + value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), + weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null + } + }), + maxY = Math.max.apply(null, dataY) || 1, + yLabel = config.yLabel || dataY, + width, $el, $background, $bar, $count, $date; + + for (var i = this.len; i > 0;) { + i = i - 1; + width = Math.floor((dataY[i] / maxY) * 100) - 15; + $el = createCSSGraphBarEl(); + $background = $el.find('.css-graph-bar-background'); + $background.css({ + 'background-color': barBackgroundColor + }); + + if (config.showDate) { + $date = $el.find('.css-graph-date'); + $date.text(label[i].value).css({ + 'color': dateColor, + 'font-size': dateLabelSize + 'px', + 'line-height': barWidth + 'px' + }); + if (label[i].weekday === 6) { + $date.addClass('saturday').css({ + 'color': dateColorSaturday + }); + } else if (label[i].weekday === 0) { + $date.addClass('sunday').css({ + 'color': dateColorSunday + }) + } + + $el.find('.css-graph-bar-container').css({ + 'margin-left': barMarginLeft + 'px' + }); } - totalWidth = totalWidth + width; - - $bar = $('
'); + + $bar = $el.find('.css-graph-bar'); $bar.css({ 'width': width + '%', - 'background-color': barColors[j] + 'background-color': barColor }); - - if (config.showCount) { - $bar.text(dataY[j]); + $count = $el.find('.css-graph-bar-count'); + $count.text(yLabel[i]).css({ + 'color': labelColor, + 'font-size': labelSize + 'px', + 'line-height': barWidth + 'px' + }); + $el.appendTo(this.$graphEl); + } + + this.$graphEl.appendTo($container); + }; + + ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { + var yLength = config.yLength, + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateColor = config.dateColor || '#999999', + barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + labelColors = config.labelColors, + labelClasses = config.labelClasses, + i, j, + d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; + + for (i = 0; i < this.len; i++) { + d = data[i]; + dataY = []; + totalY = 0; + totalWidth = 0; + for (j = 0; j < yLength; j++) { + dataY.push(d['y' + (j || '')]); + totalY = totalY + parseInt(d['y' + (j || '')], 10); } - - if (labelClasses && labelClasses[j]) { - $bar.addClass(labelClasses[j]); + + $barContainer = $('
').appendTo(this.$graphEl); + if (config.showDate && d.x) { + label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); + $date = $('
' + label + '
').appendTo($barContainer); } - - if (labelColors && labelColors[j]) { - $bar.css({ - 'color': labelColors[j] + + $el = $('
').appendTo($barContainer); + + if (config.showDate) { + $el.css({ + 'margin-left': barMarginLeft + 'px' }); } - - $bar.appendTo($el); + + for (j = 0; j < yLength; j++) { + width = Math.floor((dataY[j] / totalY) * 1000) / 10; + + if (width) { + if (yLength === j) { + width = 100 - totalWidth; + } + totalWidth = totalWidth + width; + + $bar = $('
'); + $bar.css({ + 'width': width + '%', + 'background-color': barColors[j] + }); + + if (config.showCount) { + $bar.text(dataY[j]); + } + + if (labelClasses && labelClasses[j]) { + $bar.addClass(labelClasses[j]); + } + + if (labelColors && labelColors[j]) { + $bar.css({ + 'color': labelColors[j] + }); + } + + $bar.appendTo($el); + } + } + + $el.appendTo($barContainer); } - } - - $el.appendTo($barContainer); - } - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { - var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); - var method = config.type.slice(config.type.lastIndexOf('.') + 1); - cssGraph[method](data, config, range, $container); - return cssGraph; -}; - - ChartAPI.Graph.easel = {}; - -ChartAPI.Graph.easel.Base = function (data, config, range, $container) { - this.data = data; - this.config = config; - this.range = range; - this.$container = $container; - if (!window.createjs && typeof window.require === 'function') { - require(['easeljs'], $.proxy(function () { - this.buildCanvas(createjs); - }, this)); - } else { - var width = parseInt((config.width || $container.width()), 10); - - if (width) { - this.buildCanvas(createjs); - } else { - setTimeout($.proxy(function () { - this.buildCanvas(createjs); - }, this), 100); - } - } -}; - -ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { - this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; - this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; - - this.$canvas = $('').appendTo(this.$container); - this.canvas = this.$canvas.get(0); - this.canvas.getContext('2d'); - - this.stage = this.graph = new createjs.Stage(this.canvas); - this.stage.update(); - var method = this.config.type.split('.')[1]; - this[method](this.data, this.config); -}; - -ChartAPI.Graph.easel.Base.prototype.remove = function () { - this.$canvas.remove(); -}; - -ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { - var length = data.length, - barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, - barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - barColor = this.convertColor(barColors[0], barColorAlpha), - barMargin = parseInt(config.barMargin, 10) || 10, - barContentWidth = Math.floor(this.width / length), - barWidth = barContentWidth - barMargin, - leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - maxY = Math.max.apply(null, dataY) || 1, - shape, - bar, - x, - y, - barHeight; - - for (var i = 0; i < length; i++) { - shape = new createjs.Shape(); - bar = shape.graphics; - x = i * barContentWidth + leftMargin; - barHeight = Math.floor(dataY[i] / maxY * this.height); - y = this.height - barHeight; - - bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); - this.stage.addChild(shape); - } - this.stage.update(); -}; - -ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { - var length = data.length, - lineWidth = parseInt(config.lineWidth, 10) || 8, - yLength = config.yLength || 1, - lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - lineColorsAlpha = config.chartColorsAlpha || [null], - pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - pointerColorsAlpha = config.pointerColorsAlpha || [null], - pointerRadius = config.pointerRadius || 10, - paddingTop = lineWidth / 2, - paddingBottom = lineWidth / 2, - count = (length - 1) * 2, - moveX = Math.floor(this.width / length) / 2, - paddingLeft = (this.width - (moveX * count)) / 2, - height = this.height, - canvasInnerHeight, - dataYs = [], - dataY, - mapfunc = function (d) { - return parseInt(d['y' + (i || '')], 10); + this.$graphEl.appendTo($container); }; - - if (config.drawPointer) { - paddingBottom = paddingBottom + pointerRadius; - } - - canvasInnerHeight = this.height - (paddingTop + paddingBottom); - - for (var i = 0; i < yLength; i++) { - dataY = $.map(data, mapfunc); - dataYs.push(dataY); - } - - var dataYAll = []; - $.each(dataYs, function (i, dataY) { - dataYAll = dataYAll.concat(dataY); - }); - - var maxY = Math.max.apply(null, dataYAll) || 1, - moveYs = []; - - var generateMoveY = function (dataY) { - var moveY = []; - $.each(dataY, function (i, y) { - if (i > 0) { - var prevY = dataY[i - 1]; - var medium = prevY + Math.floor((y - prevY) / 2); - - medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY = moveY.concat([medium, y]); + + ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { + var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); + var method = config.type.slice(config.type.lastIndexOf('.') + 1); + cssGraph[method](data, config, range, $container); + return cssGraph; + }; + + ChartAPI.Graph.easel = {}; + + ChartAPI.Graph.easel.Base = function (data, config, range, $container) { + this.data = data; + this.config = config; + this.range = range; + this.$container = $container; + if (!window.createjs && typeof window.require === 'function') { + require(['easeljs'], $.proxy(function () { + this.buildCanvas(createjs); + }, this)); } else { - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY.push(y); + var width = parseInt((config.width || $container.width()), 10); + + if (width) { + this.buildCanvas(createjs); + } else { + setTimeout($.proxy(function () { + this.buildCanvas(createjs); + }, this), 100); + } } - }); - return moveY; - }; - - $.each(dataYs, function (i, dataY) { - moveYs.push(generateMoveY(dataY)); - }); - - var lineColor, - shapes = [], - lines = [], - x = paddingLeft, - y, - circles = [], - pointerColor; - - for (i = 0; i < yLength; i++) { - lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); - shapes[i] = new createjs.Shape(); - lines[i] = shapes[i].graphics; - y = height - moveYs[i][0]; - lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); - this.stage.addChild(shapes[i]); - if (config.drawPointer) { - pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); - circles[i] = new createjs.Shape(); - circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); - this.stage.addChild(circles[i]); - } - } - - var stage = this.stage; - - var tick = function (e) { - // if we are on the last frame of animation then remove the tick listener: - count = count - 1; - if (count === 0) { - createjs.Ticker.removeEventListener("tick", tick); - } - - x = x + moveX; - - var moveY; - for (var i = 0; i < yLength; i++) { - moveY = moveYs[i]; - y = height - moveY[moveY.length - count - 1]; - lines[i].lineTo(x, y); + }; + + ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { + this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; + this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; + + this.$canvas = $('').appendTo(this.$container); + this.canvas = this.$canvas.get(0); + this.canvas.getContext('2d'); + + this.stage = this.graph = new createjs.Stage(this.canvas); + this.stage.update(); + var method = this.config.type.split('.')[1]; + this[method](this.data, this.config); + }; + + ChartAPI.Graph.easel.Base.prototype.remove = function () { + this.$canvas.remove(); + }; + + ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { + var length = data.length, + barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, + barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + barColor = this.convertColor(barColors[0], barColorAlpha), + barMargin = parseInt(config.barMargin, 10) || 10, + barContentWidth = Math.floor(this.width / length), + barWidth = barContentWidth - barMargin, + leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + maxY = Math.max.apply(null, dataY) || 1, + shape, + bar, + x, + y, + barHeight; + + for (var i = 0; i < length; i++) { + shape = new createjs.Shape(); + bar = shape.graphics; + x = i * barContentWidth + leftMargin; + barHeight = Math.floor(dataY[i] / maxY * this.height); + y = this.height - barHeight; + + bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); + this.stage.addChild(shape); + } + this.stage.update(); + }; + + ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { + var length = data.length, + lineWidth = parseInt(config.lineWidth, 10) || 8, + yLength = config.yLength || 1, + lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + lineColorsAlpha = config.chartColorsAlpha || [null], + pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + pointerColorsAlpha = config.pointerColorsAlpha || [null], + pointerRadius = config.pointerRadius || 10, + paddingTop = lineWidth / 2, + paddingBottom = lineWidth / 2, + count = (length - 1) * 2, + moveX = Math.floor(this.width / length) / 2, + paddingLeft = (this.width - (moveX * count)) / 2, + height = this.height, + canvasInnerHeight, + dataYs = [], + dataY, + mapfunc = function (d) { + return parseInt(d['y' + (i || '')], 10); + }; + if (config.drawPointer) { - circles[i].x = x; - circles[i].y = Math.max(y, pointerRadius); + paddingBottom = paddingBottom + pointerRadius; } - } - - stage.update(e); - }; - - createjs.Ticker.useRAF = true; - createjs.Ticker.setFPS(30); - createjs.Ticker.addEventListener('tick', tick); -}; - -ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { - if (str.indexOf('#') !== -1) { - var r = parseInt(str.substr(1, 2), 16), - g = parseInt(str.substr(3, 2), 16), - b = parseInt(str.substr(5, 2), 16); - - if (alpha) { - str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; - } else { - str = 'rgb(' + [r, g, b].join(',') + ')'; - } - } else if (str.indexOf('rgb') !== -1) { - // wrap rgb/rgba string - if (str.split(',').length < 4) { - str = 'rgb(' + str + ')'; - } else { - str = 'rgba(' + str + ')'; - } - } - return str; -}; - -ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { - var count = 0; - - var splitData = function (length, data) { - length = length || 1; - var map = $.map(data, function (d) { - var obj = { - x: d.x - }, key, val; - - for (var i = 0; i < length; i++) { - key = 'y' + (i || ''); - val = 'y' + (count + i || ''); - obj[key] = d[val]; - } - return obj; - }); - count = count + length; - return map; - }; - - var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - - $.each(config.mix, $.proxy(function (index, conf) { - var colors = { - chartColors: chartColors.slice(count, count + conf.yLength) - }; - var partialData = splitData(conf.yLength, data); - conf = $.extend({}, config, colors, conf); - this[conf.type](partialData, conf); - }, this)); -}; - -ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { - if (ChartAPI.Graph.test.canvas()) { - var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); - return easelGraph; - } else { - console.warn('EaselJS graph requires for HTML5 Canvas capability'); - $container.trigger('REMOVE'); - } -}; - - ChartAPI.Graph.morris = {}; - -ChartAPI.Graph.morris.Base = function (data, config, range, $container) { - if (!window.Morris && typeof window.require === 'function') { - require(['raphael', 'morris'], $.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this)); - } else { - var width = config.width || $container.width(); - if (width) { - this.build_(Morris, data, config, range, $container); - } else { - setTimeout($.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this), 100); - } - } -}; - -ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { - var i, - graphDefaults, graphConfig, - method = config.type.split('.')[1], - yLength = config.yLength, - width = config.width || $container.width() || 300, - height = config.height || $container.height() || 300; - - this.$graphEl = $('
').css({ - 'height': height + 'px', - 'width': width + 'px' - }).prependTo($container); - - config = $.extend({}, config, { - element: config.id, - data: data, - xkey: 'x', - labels: this.getYLabels_(yLength, config.labels), - ykeys: this.getYKeys_(yLength), - ymax: this.getYMax_(data, method, yLength), - ymin: config.ymin || 0, - lineWidth: parseInt(config.lineWidth, 10) || 6, - pointSize: parseInt(config.pointSize, 10) || 6, - smooth: config.smooth || false - }); - - config.barColors = config.barColors || this.getChartColors(config); - config.colors = config.colors || this.getChartColors(config); - config.lineColors = config.lineColors || this.getChartColors(config); - config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); - - config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; - if (!config.pointStrokeColors.length) { - for (i = 0; i < yLength; i++) { - config.pointStrokeColors.push('none'); - } - } - - graphDefaults = { - element: null, - data: null, - xkey: 'x', - labels: [], - ykeys: [], - - // gridDefaults - dateFormat: null, - axes: true, - grid: true, - gridLineColor: '#aaa', - gridStrokeWidth: 0.5, - gridTextColor: '#888', - gridTextSize: 12, - hideHover: false, - hoverCallback: null, - yLabelFormat: null, - numLines: 5, - padding: 25, - parseTime: true, - postUnits: '', - preUnits: '', - ymax: 'auto', - ymin: 'auto 0', - goals: [], - goalStrokeWidth: 1.0, - goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], - events: [], - eventStrokeWidth: 1.0, - eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], - - // Line defaults - lineWidth: 3, - pointSize: 4, - lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - pointWidths: [1], - pointStrokeColors: ['#ffffff'], - pointFillColors: [], - smooth: true, - xLabels: 'auto', - xLabelFormat: null, - xLabelMargin: 50, - continuousLine: true, - - // Bar defaults - barSizeRatio: 0.75, - barGap: 3, - barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - - // Donut defaults - colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], - backgroundColor: '#FFFFFF', - labelColor: '#000000', - formatter: Morris.commas - }; - - graphConfig = {}; - $.each(config, function (key, value) { - if (graphDefaults[key] !== undefined) { - graphConfig[key] = value; - } - }); - - // IE8(VML) occured error setting smooth false - if (!ChartAPI.Graph.test.svg) { - graphConfig.smooth = true; - } - - // shows percentage as Y label when graph method is donut - if (method === 'donut') { - var totalCount = this.getTotalCount_(data, i); - - graphConfig.formatter = function (y) { - var str = y = (y + '').replace(/,/g, ''); - if (!config.noCommaOnYLabel) { - while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); + + canvasInnerHeight = this.height - (paddingTop + paddingBottom); + + for (var i = 0; i < yLength; i++) { + dataY = $.map(data, mapfunc); + dataYs.push(dataY); + } + + var dataYAll = []; + $.each(dataYs, function (i, dataY) { + dataYAll = dataYAll.concat(dataY); + }); + + var maxY = Math.max.apply(null, dataYAll) || 1, + moveYs = []; + + var generateMoveY = function (dataY) { + var moveY = []; + $.each(dataY, function (i, y) { + if (i > 0) { + var prevY = dataY[i - 1]; + var medium = prevY + Math.floor((y - prevY) / 2); + + medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY = moveY.concat([medium, y]); + } else { + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY.push(y); + } + }); + return moveY; + }; + + $.each(dataYs, function (i, dataY) { + moveYs.push(generateMoveY(dataY)); + }); + + var lineColor, + shapes = [], + lines = [], + x = paddingLeft, + y, + circles = [], + pointerColor; + + for (i = 0; i < yLength; i++) { + lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); + shapes[i] = new createjs.Shape(); + lines[i] = shapes[i].graphics; + y = height - moveYs[i][0]; + lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); + this.stage.addChild(shapes[i]); + if (config.drawPointer) { + pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); + circles[i] = new createjs.Shape(); + circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); + this.stage.addChild(circles[i]); + } + } + + var stage = this.stage; + + var tick = function (e) { + // if we are on the last frame of animation then remove the tick listener: + count = count - 1; + if (count === 0) { + createjs.Ticker.removeEventListener("tick", tick); + } + + x = x + moveX; + + var moveY; + for (var i = 0; i < yLength; i++) { + moveY = moveYs[i]; + y = height - moveY[moveY.length - count - 1]; + lines[i].lineTo(x, y); + if (config.drawPointer) { + circles[i].x = x; + circles[i].y = Math.max(y, pointerRadius); + } + } + + stage.update(e); + }; + + createjs.Ticker.useRAF = true; + createjs.Ticker.setFPS(30); + createjs.Ticker.addEventListener('tick', tick); + }; + + ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { + if (str.indexOf('#') !== -1) { + var r = parseInt(str.substr(1, 2), 16), + g = parseInt(str.substr(3, 2), 16), + b = parseInt(str.substr(5, 2), 16); + + if (alpha) { + str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; + } else { + str = 'rgb(' + [r, g, b].join(',') + ')'; + } + } else if (str.indexOf('rgb') !== -1) { + // wrap rgb/rgba string + if (str.split(',').length < 4) { + str = 'rgb(' + str + ')'; + } else { + str = 'rgba(' + str + ')'; + } + } + return str; + }; + + ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { + var count = 0; + + var splitData = function (length, data) { + length = length || 1; + var map = $.map(data, function (d) { + var obj = { + x: d.x + }, key, val; + + for (var i = 0; i < length; i++) { + key = 'y' + (i || ''); + val = 'y' + (count + i || ''); + obj[key] = d[val]; + } + return obj; + }); + count = count + length; + return map; + }; + + var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); + + $.each(config.mix, $.proxy(function (index, conf) { + var colors = { + chartColors: chartColors.slice(count, count + conf.yLength) + }; + var partialData = splitData(conf.yLength, data); + conf = $.extend({}, config, colors, conf); + this[conf.type](partialData, conf); + }, this)); + }; + + ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { + if (ChartAPI.Graph.test.canvas()) { + var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); + return easelGraph; + } else { + console.warn('EaselJS graph requires for HTML5 Canvas capability'); + $container.trigger('REMOVE'); + } + }; + + ChartAPI.Graph.morris = {}; + + ChartAPI.Graph.morris.Base = function (data, config, range, $container) { + if (!window.Morris && typeof window.require === 'function') { + require(['raphael', 'morris'], $.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this)); + } else { + var width = config.width || $container.width(); + if (width) { + this.build_(Morris, data, config, range, $container); + } else { + setTimeout($.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this), 100); + } + } + }; + + ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { + var i, + graphDefaults, graphConfig, + method = config.type.split('.')[1], + yLength = config.yLength, + width = config.width || $container.width() || 300, + height = config.height || $container.height() || 300; + + this.$graphEl = $('
').css({ + 'height': height + 'px', + 'width': width + 'px' + }).prependTo($container); + + config = $.extend({}, config, { + element: config.id, + data: data, + xkey: 'x', + labels: this.getYLabels_(yLength, config.labels), + ykeys: this.getYKeys_(yLength), + ymax: this.getYMax_(data, method, yLength), + ymin: config.ymin || 0, + lineWidth: parseInt(config.lineWidth, 10) || 6, + pointSize: parseInt(config.pointSize, 10) || 6, + smooth: config.smooth || false + }); + + config.barColors = config.barColors || this.getChartColors(config); + config.colors = config.colors || this.getChartColors(config); + config.lineColors = config.lineColors || this.getChartColors(config); + config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); + + config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; + if (!config.pointStrokeColors.length) { + for (i = 0; i < yLength; i++) { + config.pointStrokeColors.push('none'); + } + } + + graphDefaults = { + element: null, + data: null, + xkey: 'x', + labels: [], + ykeys: [], + + // gridDefaults + dateFormat: null, + axes: true, + grid: true, + gridLineColor: '#aaa', + gridStrokeWidth: 0.5, + gridTextColor: '#888', + gridTextSize: 12, + hideHover: false, + hoverCallback: null, + yLabelFormat: null, + numLines: 5, + padding: 25, + parseTime: true, + postUnits: '', + preUnits: '', + ymax: 'auto', + ymin: 'auto 0', + goals: [], + goalStrokeWidth: 1.0, + goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], + events: [], + eventStrokeWidth: 1.0, + eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], + + // Line defaults + lineWidth: 3, + pointSize: 4, + lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + pointWidths: [1], + pointStrokeColors: ['#ffffff'], + pointFillColors: [], + smooth: true, + xLabels: 'auto', + xLabelFormat: null, + xLabelMargin: 50, + continuousLine: true, + + // Bar defaults + barSizeRatio: 0.75, + barGap: 3, + barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + + // Donut defaults + colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], + backgroundColor: '#FFFFFF', + labelColor: '#000000', + formatter: Morris.commas + }; + + graphConfig = {}; + $.each(config, function (key, value) { + if (graphDefaults[key] !== undefined) { + graphConfig[key] = value; + } + }); + + // IE8(VML) occured error setting smooth false + if (!ChartAPI.Graph.test.svg) { + graphConfig.smooth = true; + } + + // shows percentage as Y label when graph method is donut + if (method === 'donut') { + var totalCount = this.getTotalCount_(data, i); + + graphConfig.formatter = function (y) { + var str = y = (y + '').replace(/,/g, ''); + if (!config.noCommaOnYLabel) { + while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); + } + var percent = Math.ceil((y / totalCount * 10000)) / 100; + + var ret; + if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { + ret = config.donutsFormatter(str, percent + '%', y); + } else { + ret = str + '(' + percent + '%)'; + } + + return ret; + }; + } + + var M = ({ + 'bar': Morris.Bar, + 'line': Morris.Line, + 'donut': Morris.Donut, + 'area': Morris.Area + })[method]; + + this.graph = new M(graphConfig); + }; + + /** + * get maximum value among the desinated Y data set + * @param {!Array.} graph data to get max Y + * @param {!number} number of set of Y data + * @return {number} return the number of maxY for graph + */ + ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { + var i, maxY, array, sum, key; + + if (method !== 'area') { + array = []; + $.each(data, function (index, value) { + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + array.push(parseInt(value[key], 10)); + } + }); + maxY = Math.max.apply(null, array); + } else { + maxY = Math.max.apply(null, $.map(data, function (value) { + sum = 0; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + sum = sum + parseInt(value[key], 10); + } + return sum; + })); + } + + if (!maxY) { + maxY = 1; + } + + if (maxY % 2 !== 0) { + maxY = maxY + 1; } - var percent = Math.ceil((y / totalCount * 10000)) / 100; - - var ret; - if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { - ret = config.donutsFormatter(str, percent + '%', y); - } else { - ret = str + '(' + percent + '%)'; + + return maxY; + }; + + ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { + if (!this.chartColors) { + this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); } - - return ret; + return this.chartColors; }; - } - - var M = ({ - 'bar': Morris.Bar, - 'line': Morris.Line, - 'donut': Morris.Donut, - 'area': Morris.Area - })[method]; - - this.graph = new M(graphConfig); -}; - -/** - * get maximum value among the desinated Y data set - * @param {!Array.} graph data to get max Y - * @param {!number} number of set of Y data - * @return {number} return the number of maxY for graph - */ -ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { - var i, maxY, array, sum, key; - - if (method !== 'area') { - array = []; - $.each(data, function (index, value) { + + /** + * return YKeys array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { + var i, array = []; for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - array.push(parseInt(value[key], 10)); + array.push('y' + (i || '')); } - }); - maxY = Math.max.apply(null, array); - } else { - maxY = Math.max.apply(null, $.map(data, function (value) { - sum = 0; + return array; + }; + + /** + * return YLables array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { + var i, array = []; + yLabel = yLabel ? yLabel.split(/,/) : []; for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - sum = sum + parseInt(value[key], 10); + array.push((yLabel[i] || 'Count')); } - return sum; - })); - } - - if (!maxY) { - maxY = 1; - } - - if (maxY % 2 !== 0) { - maxY = maxY + 1; - } - - return maxY; -}; - -ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { - if (!this.chartColors) { - this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - } - return this.chartColors; -}; - -/** - * return YKeys array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { - var i, array = []; - for (i = 0; i < yLength; i++) { - array.push('y' + (i || '')); - } - return array; -}; - -/** - * return YLables array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { - var i, array = []; - yLabel = yLabel ? yLabel.split(/,/) : []; - for (i = 0; i < yLength; i++) { - array.push((yLabel[i] || 'Count')); - } - return array; -}; - -/** - * caliculate the number of horizental lines in graph - * @param {!number} maximum value among the Y data set. - * @return {number} - */ -ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { - var numlines; - if (maxY >= 18) { - numlines = 9; - } else if (maxY === 2) { - numlines = 3; - } else { - numlines = (maxY / 2) + 1; - - } - numlines = Math.min((numlines || 1), Math.floor(height / 56)); - - return numlines; -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''), - num; - $.each(data, function (i, v) { - num = v[str] || v.value || 0; - if (typeof num === 'string') { - num = parseFloat(num.replace(/,/g, ''), 10); - } - total = total + num; - }); - return total; -}; - -ChartAPI.Graph.morris.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { - if (ChartAPI.Graph.test.vml()) { - var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); - return morrisGraph; - } else { - console.warn('Morris graph requires for SVG/VML capability'); - $container.trigger('REMOVE'); - } -}; - - /** - * create Slider Object - * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this - * $('.container').trigger('APPEND_SLIDER') - * - * @param {object} slider setings - * @param {object} range object - * @param {jQuery} jQuery object of graph/list container element for getting data range - * @param {Array.} array of jQuery object to fire update event - * @param { - Array. < jQuery > - } - array of jQuery object to fire event - for getting amount labels(this event fired when range is timeline) - * @return {object} jQuery object of slider container for chaining - * @constructor - */ -ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { - if (!$.ui || !$.ui.slider) { - throw 'ChartAPI.Slider requied jQuery UI Slider'; - } - var that = this; - this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - this.range = ChartAPI.Range.generate(range); - this.$dataRangeTarget = $dataRangeTarget; - this.$sliderContainer = $('
'); - - this.eventTargetList = { - update: this.initEventTarget(), - amount: this.initEventTarget() - }; - - $.each(updateTarget, function (i, v) { - that.eventTargetList.update.add(v); - }); - - $.each(amountTarget, function (i, v) { - that.eventTargetList.amount.add(v); - }); - - /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object to attach slider - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('APPEND_TO', function (e, $container) { - that.$container = $container; - that.draw_($container); - return $(this); - }); - - /** - * for building slider UI - * @param {object} jQuery event object - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('BUILD_SLIDER', function () { - that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { - that.buildSlider(dataRange.min, dataRange.max); - }); - return $(this); - }); - - /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object of container for graph|list object to get data range - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { - that.$dataRangeTarget = $target; - return $(this); - }); - - /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to add event target - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].add($target); - }); - return $(this); - }); - - /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to remove from event targets - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].remove($target); - }); - return $(this); - }); - - - this.$sliderContainer.on('ERASE', function () { - that.erase_(); - return $(this); - }); - - this.$sliderContainer.on('REDRAW', function () { - var $this = $(this); - $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); - return $(this); - }); - - this.$sliderContainer.on('UPDATE', function (e, values) { - that.$slider("values", values); - that.updateSliderAmount(values); - return $(this); - }); - - return this.$sliderContainer; -}; - -/** - * return event target object encapsulated target array - * @return {{add:Function, remove:Function, get:Function}} - */ -ChartAPI.Slider.prototype.initEventTarget = function () { - var target = []; - return { - add: function (newTarget) { - target.push(newTarget); - }, - remove: function (removeTarget) { - target = $.grep(target, function (v) { - return v !== removeTarget; + return array; + }; + + /** + * caliculate the number of horizental lines in graph + * @param {!number} maximum value among the Y data set. + * @return {number} + */ + ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { + var numlines; + if (maxY >= 18) { + numlines = 9; + } else if (maxY === 2) { + numlines = 3; + } else { + numlines = (maxY / 2) + 1; + + } + numlines = Math.min((numlines || 1), Math.floor(height / 56)); + + return numlines; + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''), + num; + $.each(data, function (i, v) { + num = v[str] || v.value || 0; + if (typeof num === 'string') { + num = parseFloat(num.replace(/,/g, ''), 10); + } + total = total + num; }); - }, - get: function () { - return target; - } - }; -}; - -/** - * build Slider UI - * @param {number} number of the left slider handler position - * @param {number} number of the right slider handler position - * @param {{max:number, min:number}} Object which has max and min values - * @return nothing - */ -ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { - var that = this; - values = values || [this.range.min, this.range.max]; - - if (this.$slider) { - this.$slider.destroy(); - this.$slider.remove(); - } - this.$slider = $('
').slider({ - 'range': true, - 'min': sliderMin, - 'max': sliderMax, - 'values': values, - 'slide': function (e, ui) { - that.updateSliderAmount(ui.values, ui); - }, - 'stop': function (e, ui) { - that.updateGraphAndList(ui.values); - } - }).appendTo(that.$sliderContainer); - - if (!this.config.hideSliderAmount) { - this.$amount = $('
'); - - if (!this.config.appendSliderAmountBottom) { - this.$amount.prependTo(this.$sliderContainer); - } else { - this.$amount.appendTo(this.$sliderContainer); - } - - this.updateSliderAmount(values); - } -}; - -/** - * append Slider container to desinated element - * @param {jQuery} - * @return nothing - */ -ChartAPI.Slider.prototype.draw_ = function ($container) { - this.$sliderContainer.appendTo($container); -}; - -/** - * erase Slider by removing the container - * if you want to redraw Slider, trigger 'REDRAW' for the slider container. - */ -ChartAPI.Slider.prototype.erase_ = function () { - if (this.$slider) { - this.$slider.destroy(); - } - this.$sliderContainer.html(''); -}; - -/** - * update Slider Amount contents - * @param {Array.} values of slider position - * @param {object} ui object returned from Slider event - */ -ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { - var s, e, u, newRange, maxLength = this.range.maxLength, - $amount = this.$amount; - - if (this.range.isTimeline) { - s = ChartAPI.Date.parse(values[0]); - e = ChartAPI.Date.parse(values[1]); - u = this.range.unit; - - newRange = ChartAPI.Range.getLength(s, e, u); - - if (ui && newRange > maxLength) { - if (ui.value === ui.values[0]) { - e = ChartAPI.Date.calcDate(s, maxLength, u, false); - this.$slider.slider('values', 1, e.valueOf()); + return total; + }; + + ChartAPI.Graph.morris.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { + if (ChartAPI.Graph.test.vml()) { + var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); + return morrisGraph; } else { - s = ChartAPI.Date.calcDate(e, maxLength, u, true); - this.$slider.slider('values', 0, s.valueOf()); + console.warn('Morris graph requires for SVG/VML capability'); + $container.trigger('REMOVE'); } - } - - if ($amount) { - $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); - } - } else { - s = values[0]; - e = values[1]; - if ((e - s) > maxLength) { - if (ui.value === ui.values[0]) { - e = maxLength - s; - this.$slider.slider('values', 1, e); + }; + + /** + * create Slider Object + * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this + * $('.container').trigger('APPEND_SLIDER') + * + * @param {object} slider setings + * @param {object} range object + * @param {jQuery} jQuery object of graph/list container element for getting data range + * @param {Array.} array of jQuery object to fire update event + * @param { + Array. < jQuery > + } + array of jQuery object to fire event + for getting amount labels(this event fired when range is timeline) + * @return {object} jQuery object of slider container for chaining + * @constructor + */ + ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { + if (!$.ui || !$.ui.slider) { + throw 'ChartAPI.Slider requied jQuery UI Slider'; + } + var that = this; + this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + this.range = ChartAPI.Range.generate(range); + this.$dataRangeTarget = $dataRangeTarget; + this.$sliderContainer = $('
'); + + this.eventTargetList = { + update: this.initEventTarget(), + amount: this.initEventTarget() + }; + + $.each(updateTarget, function (i, v) { + that.eventTargetList.update.add(v); + }); + + $.each(amountTarget, function (i, v) { + that.eventTargetList.amount.add(v); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object to attach slider + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('APPEND_TO', function (e, $container) { + that.$container = $container; + that.draw_($container); + return $(this); + }); + + /** + * for building slider UI + * @param {object} jQuery event object + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('BUILD_SLIDER', function () { + that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { + that.buildSlider(dataRange.min, dataRange.max); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object of container for graph|list object to get data range + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { + that.$dataRangeTarget = $target; + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to add event target + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].add($target); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to remove from event targets + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].remove($target); + }); + return $(this); + }); + + + this.$sliderContainer.on('ERASE', function () { + that.erase_(); + return $(this); + }); + + this.$sliderContainer.on('REDRAW', function () { + var $this = $(this); + $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); + return $(this); + }); + + this.$sliderContainer.on('UPDATE', function (e, values) { + that.$slider("values", values); + that.updateSliderAmount(values); + return $(this); + }); + + return this.$sliderContainer; + }; + + /** + * return event target object encapsulated target array + * @return {{add:Function, remove:Function, get:Function}} + */ + ChartAPI.Slider.prototype.initEventTarget = function () { + var target = []; + return { + add: function (newTarget) { + target.push(newTarget); + }, + remove: function (removeTarget) { + target = $.grep(target, function (v) { + return v !== removeTarget; + }); + }, + get: function () { + return target; + } + }; + }; + + /** + * build Slider UI + * @param {number} number of the left slider handler position + * @param {number} number of the right slider handler position + * @param {{max:number, min:number}} Object which has max and min values + * @return nothing + */ + ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { + var options, defaultCallback, events = ['change', 'create', 'slide', 'start', 'stop'], that = this; + values = values || [this.range.min, this.range.max]; + + if (this.$slider) { + this.$slider.destroy(); + this.$slider.remove(); + } + options = { + 'range': true, + 'min': sliderMin, + 'max': sliderMax, + 'values': values, + 'slide': function (e, ui) { + that.updateSliderAmount(ui.values, ui); + }, + 'stop': function (e, ui) { + that.updateGraphAndList(ui.values); + } + }; + events.forEach(function(value) { + if (that.config.callback[value]) { + defaultCallback = options[value]; + options[value] = function(e, ui) { + that.config.callback[value](e, ui); + if (defaultCallback) { + defaultCallback(e, ui); + } + }; + } + }); + this.$slider = $('
').slider(options).appendTo(that.$sliderContainer); + + if (!this.config.hideSliderAmount) { + this.$amount = $('
'); + + if (!this.config.appendSliderAmountBottom) { + this.$amount.prependTo(this.$sliderContainer); + } else { + this.$amount.appendTo(this.$sliderContainer); + } + + this.updateSliderAmount(values); + } + }; + + /** + * append Slider container to desinated element + * @param {jQuery} + * @return nothing + */ + ChartAPI.Slider.prototype.draw_ = function ($container) { + this.$sliderContainer.appendTo($container); + }; + + /** + * erase Slider by removing the container + * if you want to redraw Slider, trigger 'REDRAW' for the slider container. + */ + ChartAPI.Slider.prototype.erase_ = function () { + if (this.$slider) { + this.$slider.destroy(); + } + this.$sliderContainer.html(''); + }; + + /** + * update Slider Amount contents + * @param {Array.} values of slider position + * @param {object} ui object returned from Slider event + */ + ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { + var s, e, u, newRange, maxLength = this.range.maxLength, + $amount = this.$amount; + + if (this.range.isTimeline) { + s = ChartAPI.Date.parse(values[0]); + e = ChartAPI.Date.parse(values[1]); + u = this.range.unit; + + newRange = ChartAPI.Range.getLength(s, e, u); + + if (ui && newRange > maxLength) { + if (ui.value === ui.values[0]) { + e = ChartAPI.Date.calcDate(s, maxLength, u, false); + this.$slider.slider('values', 1, e.valueOf()); + } else { + s = ChartAPI.Date.calcDate(e, maxLength, u, true); + this.$slider.slider('values', 0, s.valueOf()); + } + } + + if ($amount) { + $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); + } } else { - s = e - maxLength; - this.$slider.slider('values', 0, s); - } - } - if ($amount) { - $.each(this.eventTargetList.amount.get(), function (i, $target) { - $target.trigger('GET_LABEL', [ - [s, e], - function (a) { - $amount.text([a[0], a[1]].join(' - ')); + s = values[0]; + e = values[1]; + if ((e - s) > maxLength) { + if (ui.value === ui.values[0]) { + e = maxLength - s; + this.$slider.slider('values', 1, e); + } else { + s = e - maxLength; + this.$slider.slider('values', 0, s); } - ]); + } + if ($amount) { + $.each(this.eventTargetList.amount.get(), function (i, $target) { + $target.trigger('GET_LABEL', [ + [s, e], + function (a) { + $amount.text([a[0], a[1]].join(' - ')); + } + ]); + }); + } + } + }; + + /** + * @param {Array.} values of slider handler position + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { + $.each(this.eventTargetList.update.get(), function (i, $target) { + $target.trigger('UPDATE', [values, newUnit]); }); - } - } -}; - -/** - * @param {Array.} values of slider handler position - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { - $.each(this.eventTargetList.update.get(), function (i, $target) { - $target.trigger('UPDATE', [values, newUnit]); - }); -}; - -/** - * update slider handlers position - * @param {number} index of slider handler (left is 0, right is 1) - * @param {number} value of slider handler position - */ -ChartAPI.Slider.prototype.update_ = function (index, value) { - this.$slider.slider('values', index, value); -}; - - /** - * create List Object - * If you want to draw list, fire APPEND_LIST event for its container Element like this - * $('.container').trigger('APPEND_LIST') - * - * @param {object} list setings - * @param {object} range object - * @return {jQuery} return jQuery object for chaining - * @constructor - */ -ChartAPI.List = function (config, range) { - this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - - this.config.staticPath = this.config.staticPath || ''; - - if (this.config.data && typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - if (this.config.template) { - if (window.require && typeof require === 'function') { - var templateType = this.config.type || 'text'; - this.template_ = $.Deferred(); - require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { - this.template_.resolve(template); - }, this)); - } else { - this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); - } - - this.range = ChartAPI.Range.generate(range); - - this.$listContainer = $('
'); - - this.$listContainer.on('UPDATE', $.proxy(function (e, range) { - this.update_(range); - }, this)); - + }; + /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback + * update slider handlers position + * @param {number} index of slider handler (left is 0, right is 1) + * @param {number} value of slider handler position */ - this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); - }, this)); - return this.$listContainer; - }, this)); - + ChartAPI.Slider.prototype.update_ = function (index, value) { + this.$slider.slider('values', index, value); + }; + /** + * create List Object + * If you want to draw list, fire APPEND_LIST event for its container Element like this + * $('.container').trigger('APPEND_LIST') + * + * @param {object} list setings + * @param {object} range object * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback + * @constructor */ - - this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); - }, this)); - return this.$listContainer; - }, this)); - + ChartAPI.List = function (config, range) { + this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + + this.config.staticPath = this.config.staticPath || ''; + + if (this.config.data && typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); + } else { + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); + } + + if (this.config.template) { + if (window.require && typeof require === 'function') { + var templateType = this.config.type || 'text'; + this.template_ = $.Deferred(); + require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { + this.template_.resolve(template); + }, this)); + } else { + this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); + } + + this.range = ChartAPI.Range.generate(range); + + this.$listContainer = $('
'); + + this.$listContainer.on('UPDATE', $.proxy(function (e, range) { + this.update_(range); + }, this)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this)); + return this.$listContainer; + }, this)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + + this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this)); + return this.$listContainer; + }, this)); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + + this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { + this.$listContainer.appendTo($container); + this.getData($.proxy(function (data) { + this.draw_(data); + }, this)); + return this.$listContainer; + }, this)); + + return this.$listContainer; + } + }; + /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining + * get list data JSON + * @param {!Function} callback function which recieve jSON data */ - - this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { - this.$listContainer.appendTo($container); - this.getData($.proxy(function (data) { - this.draw_(data); - }, this)); - return this.$listContainer; - }, this)); - - return this.$listContainer; - } -}; - -/** - * get list data JSON - * @param {!Function} callback function which recieve jSON data - */ -ChartAPI.List.prototype.getData = function (callback) { - if (this.config.data) { - ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); - } else { - callback(); - } -}; - -/** - * get list template string - * @param {!Function} callback function which recieve template string - */ -ChartAPI.List.prototype.getTemplate = function (callback) { - ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); -}; - -/** - * generate html using template string - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.draw_ = function (data) { - var that = this; - this.getTemplate(function (templateString) { - data = that.createListData(data); - that.$listContainer.html(_.template(templateString, data)); - }); -}; - -/** - * provide x label data for slider - * @param {!Array.} array of index to get data - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * @param {!object} list JSON data - * @return {object} filtered data for using list template - */ -ChartAPI.List.prototype.createListData = function (data) { - var filteredData = ''; - if (data) { - if (this.range.isTimeline) { - filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); - } else { - filteredData = data.slice(this.range.min, this.range.max + 1); - } - } - return { - 'data': filteredData - }; -}; - -/** - * update list template - * @param {=Array.} array of number - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.List.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - unit = unit || this.range.unit; - this.range = ChartAPI.Range.generate({ - 'start': newRange[0] || this.range.start, - 'end': newRange[1] || this.range.end, - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': unit, - 'dataType': this.range.dataType - }); - this.getData(function (data) { - that.draw_(data); - }); -}; - - /** - * builder funciton. return jQuery object for chaining and triggering events - * @return {jQuery} - */ -ChartAPI.Build = function (settings) { - var $container; - if (typeof settings === 'string' && (/\.json$/).test(settings)) { - $container = $('
'); - ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { - settings.$container = $container; - ChartAPI.Build_(settings).trigger('APPEND'); - }); - } else { - $container = ChartAPI.Build_(settings).trigger('APPEND'); - } - return $container; -}; - -/** - * internal method for building graph|slider|list objects - * @param {Object} settings - * @param {=jQuery} jQuery object to attach graph|slider|list object - */ -ChartAPI.Build_ = function (settings) { - var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; - - $container = settings.$container || $('
'); - - sliderUpdateTarget = []; - - if (settings.graph) { - $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); - sliderUpdateTarget.push($graphContainer); - } - - if (settings.list) { - $listContainer = new ChartAPI.List(settings.list, settings.range); - if (settings.list.data) { - sliderUpdateTarget.push($listContainer); - } - } - - if (settings.graph && settings.graph.type !== 'donut') { - dataRangeTarget = $graphContainer; - sliderAmountTarget = [$graphContainer]; - } else { - dataRangeTarget = $listContainer; - sliderAmountTarget = [$listContainer]; - } - - var isSmartPhone = function () { - var userAgent = window.navigator ? window.navigator.userAgent : ''; - return (/android|iphone|ipod|ipad/i).test(userAgent); - }; - - if (settings.slider && (settings.slider.force || !isSmartPhone())) { - $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); - } - - $container.on('APPEND', function () { - if ($graphContainer) { - $graphContainer.trigger('APPEND_TO', [$container]); - } - if ($sliderContainer) { - $sliderContainer.trigger('BUILD_SLIDER') - .trigger('APPEND_TO', [$container]); - } - if ($listContainer) { - $listContainer.trigger('APPEND_TO', [$container]); - } - }); - - $container.on('GET_CONTAINER', function (e, type, callback) { - callback({ - 'graph': $graphContainer, - 'slider': $sliderContainer, - 'list': $listContainer - }[type]); - }); - - return $container; -}; - - - return ChartAPI; -})(this, jQuery); - + ChartAPI.List.prototype.getData = function (callback) { + if (this.config.data) { + ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); + } else { + callback(); + } + }; + + /** + * get list template string + * @param {!Function} callback function which recieve template string + */ + ChartAPI.List.prototype.getTemplate = function (callback) { + ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); + }; + + /** + * generate html using template string + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.draw_ = function (data) { + var that = this; + this.getTemplate(function (templateString) { + data = that.createListData(data); + that.$listContainer.html(_.template(templateString, data)); + }); + }; + + /** + * provide x label data for slider + * @param {!Array.} array of index to get data + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * @param {!object} list JSON data + * @return {object} filtered data for using list template + */ + ChartAPI.List.prototype.createListData = function (data) { + var filteredData = ''; + if (data) { + if (this.range.isTimeline) { + filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } + } + return { + 'data': filteredData + }; + }; + + /** + * update list template + * @param {=Array.} array of number + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.List.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + unit = unit || this.range.unit; + this.range = ChartAPI.Range.generate({ + 'start': newRange[0] || this.range.start, + 'end': newRange[1] || this.range.end, + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': unit, + 'dataType': this.range.dataType + }); + this.getData(function (data) { + that.draw_(data); + }); + }; + + /** + * builder funciton. return jQuery object for chaining and triggering events + * @return {jQuery} + */ + ChartAPI.Build = function (settings) { + var $container; + if (typeof settings === 'string' && (/\.json$/).test(settings)) { + $container = $('
'); + ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { + settings.$container = $container; + ChartAPI.Build_(settings).trigger('APPEND'); + }); + } else { + $container = ChartAPI.Build_(settings).trigger('APPEND'); + } + return $container; + }; + + /** + * internal method for building graph|slider|list objects + * @param {Object} settings + * @param {=jQuery} jQuery object to attach graph|slider|list object + */ + ChartAPI.Build_ = function (settings) { + var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; + + $container = settings.$container || $('
'); + + sliderUpdateTarget = []; + + if (settings.graph) { + $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); + sliderUpdateTarget.push($graphContainer); + } + + if (settings.list) { + $listContainer = new ChartAPI.List(settings.list, settings.range); + if (settings.list.data) { + sliderUpdateTarget.push($listContainer); + } + } + + if (settings.graph && settings.graph.type !== 'donut') { + dataRangeTarget = $graphContainer; + sliderAmountTarget = [$graphContainer]; + } else { + dataRangeTarget = $listContainer; + sliderAmountTarget = [$listContainer]; + } + + var isSmartPhone = function () { + var userAgent = window.navigator ? window.navigator.userAgent : ''; + return (/android|iphone|ipod|ipad/i).test(userAgent); + }; + + if (settings.slider && (settings.slider.force || !isSmartPhone())) { + $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); + } + + $container.on('APPEND', function () { + if ($graphContainer) { + $graphContainer.trigger('APPEND_TO', [$container]); + } + if ($sliderContainer) { + $sliderContainer.trigger('BUILD_SLIDER') + .trigger('APPEND_TO', [$container]); + } + if ($listContainer) { + $listContainer.trigger('APPEND_TO', [$container]); + } + }); + + $container.on('GET_CONTAINER', function (e, type, callback) { + callback({ + 'graph': $graphContainer, + 'slider': $sliderContainer, + 'list': $listContainer + }[type]); + }); + + return $container; + }; + + + return ChartAPI; + })(this, jQuery); + return MT.ChartAPI; })); diff --git a/lib/core/amd/mtchart.core.amd.min.js b/lib/core/amd/mtchart.core.amd.min.js index eeab9cb..304b018 100644 --- a/lib/core/amd/mtchart.core.amd.min.js +++ b/lib/core/amd/mtchart.core.amd.min.js @@ -1,2 +1,2 @@ -(function(t,e){if("object"==typeof exports){var a=require("jquery");module.exports=e(a)}else"function"==typeof define&&define.amd&&define(["jquery"],e)})(this,function(){(function(t,e){"use strict";var a=e,r={},n=t.MT=t.MT||{};n.ChartAPI=r;r.Data={};r.Data.getData=function(t,e,r,n){var i,o,s,h;t&&t.done(function(t){i||(i="string"==typeof t?""+t:a.isArray(t)?a.map(t,function(t){return a.extend({},t)}):a.extend({},t));r(i)}).fail(function(t){o={404:"Data is not found",403:"Data is forbidden to access"};s="Some error occured in the data fetching process";h=t.status?"error-"+t.status:"error-unknown";n&&(n.$errormsg=a('
'+(o[t.status]||s)+"
").appendTo(e))}).always(function(){n&&n.$progress&&n.$progress.parent().length>0&&n.$progress.remove()}).progress(function(){!n||n.$progress&&0!==n.$progress.parent().length||(n.$progress=a('
fetching data...
').appendTo(e))})};r.Data.filterData=function(t,e,n,i,o,s){var h,l={};o=o||1;a.each(t,function(t,c){var p,u;p=r.Date.parse(c.x);if(p&&p>=n&&e>=p)if(s){u=r.Date.createId(p,"daily");l[u]=c}else{"weekly"===i&&(p=r.Date.getWeekStartday(p));u=r.Date.createId(p,i);if(l[u])for(t=0;o>t;t++){h=t?"y"+t:"y";l[u][h]=parseInt(l[u][h],10)+parseInt(c[h],10)}else l[u]=a.extend({},c)}});return l};r.Date={};r.Date.getWeekStartday=function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay())};r.Date.zeroPadArray=function(t,e){var r;({yearly:function(){r=[t.getFullYear()]},monthly:function(){r=[t.getFullYear(),t.getMonth()+1]},quarter:function(){r=[t.getFullYear(),t.getMonth()+1]},weekly:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate()-t.getDay()]},daily:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate()]},hourly:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours()]}})[e]();return a.map(r,function(t){t=""+t;return 1===t.length?"0"+t:t})};r.Date.createId=function(t,e){return r.Date.zeroPadArray(t,e).join("")};r.Date.createXLabel=function(t,e){var a,n,i=r.Date.zeroPadArray(t,e);if("hourly"===e){a=i.pop();n=i.join("-")+" "+a+":00"}else n=i.join("-");return n};r.Date.parse=function(t){var e;e=!t||t instanceof Date?t||null:"number"==typeof t?new Date(t):new Date(Date.parse(""+t));if(e&&/NaN|Invalid Date/.test(""+e)){e=t.replace(/-/g,"/").split("+")[0];if(1===e.split("/").length){e=t.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/);e=[e[1],e[2],e[3]].join("/")}2===e.split("/").length&&(e+="/01");e=a.each(e.split("/"),function(t,e){return 1===e.length?"0"+e:e}).join("/");e=new Date(Date.parse(e))}return e};r.Date.calcDate=function(t,e,a,r){var n,i,o,s;n=t.getFullYear();i=t.getMonth();o=t.getDate();s=0;e-=1;r=r?-1:1;({yearly:function(){n+=r*e},monthly:function(){i+=r*e},quarter:function(){i+=4*r*e},weekly:function(){o=o+7*r*e-t.getDay()},daily:function(){o+=r*e},hourly:function(){s=t.getHours()+r*e}})[a]();return new Date(n,i,o,s)};r.Range={};r.Range.factory=function(t){var e;t=t||{};t.maxLength=t.maxLength||90;t.dataType=t.dataType||"timeline";t.isTimeline=r.Range.isTimeline(t.dataType);e=t.isTimeline?r.Range.calcDate:r.Range.calcNum;return e(t.start,t.end,t.length,t.maxLength,t.unit,t.dataType,t.autoSized)};r.Range.generate=r.Range.factory;r.Range.isTimeline=function(t){return!t||"timeline"===t};r.Range.calcDate=function(t,e,n,i,o,s,h){o=o||"monthly";n=n||("hourly"===o?24:10);if(h){var l=a(window).width();i=Math.min(Math.ceil(.021875*l),i);n=i}t=r.Date.parse(t);e=r.Date.parse(e);t||e||(e=r.Range.getEndDate(new Date,o));t||(t=r.Range.getStartDate(r.Date.calcDate(e,n,o,!0),o));e||(e=r.Range.getEndDate(r.Date.calcDate(t,n,o,!1),o));e>new Date&&(e=new Date);t>e&&(t=e);n=r.Range.getLength(t,e,o);if(n>i){n=i;t=r.Date.calcDate(e,n,o,!0)}return{start:t,end:e,length:n,maxLength:i,unit:o,dataType:s,max:r.Range.getEndDate(e,o),min:r.Range.getStartDate(t,o),isTimeline:!0}};r.Range.calcNum=function(t,e,r,n,i,o,s){r=r||10;if(s){var h=a(window).width();n=Math.min(Math.ceil(.021875*h),n);r=Math.min(r,n)}if(!t&&!e){t=0;e=r-1}t=parseInt(t,10)||(0===t?0:null);e=parseInt(e,10)||(0===e?0:null);if(null===t){t=e-r;0>t&&(t=0)}null===e&&(e=t+r);t>e&&(t=e);r=e-t+1;if(r>n){r=n;t=e-n}return{start:t,end:e,length:r,maxLength:n,dataType:o,unit:null,max:e,min:t,isTimeline:!1}};r.Range.getStartDate=function(t,e){var a,r=t.getFullYear(),n=t.getMonth(),i=t.getDate();({yearly:function(){a=new Date(r,0,1,0,0,0)},monthly:function(){a=new Date(r,n,1,0,0,0)},quarter:function(){a=new Date(r,n,1,0,0,0)},weekly:function(){a=new Date(r,n,i-t.getDay(),0,0,0)},daily:function(){a=new Date(r,n,i,0,0,0)},hourly:function(){a=new Date(r,n,i,t.getHours(),0,0)}})[e]();return a};r.Range.getEndDate=function(t,e){var a,r=t.getFullYear(),n=t.getMonth(),i=t.getDate();({yearly:function(){a=new Date(r,11,31,23,59,59)},monthly:function(){a=new Date(new Date(r,n+1,1,0,0,0).valueOf()-1)},quarter:function(){a=new Date(new Date(r,n+1,1,0,0,0).valueOf()-1)},weekly:function(){a=new Date(r,n,i-t.getDay()+6,23,59,59)},daily:function(){a=new Date(r,n,i,23,59,59)},hourly:function(){a=new Date(r,n,i,t.getHours(),0,0)}})[e]();return new Date>a?a:new Date};r.Range.getNextDate=function(t,e,a,r){var n,i=t.getFullYear(),o=t.getMonth(),s=t.getDate();({yearly:function(t){n=new Date(i+t,0,1)},monthly:function(t){n=new Date(i,o+t,1)},quarter:function(t){n=new Date(i,o+4*t,1)},weekly:function(e){n=new Date(i,o,s+7*e-t.getDay())},daily:function(t){n=new Date(i,o,s+t)},hourly:function(e){n=new Date(i,o,s,t.getHours()+e)}})[r](a);return e>n?n:null};r.Range.getDataRange=function(t,e){var n,i,o;if(e){n=a.map(t,function(t){return r.Date.parse(t.x).valueOf()});i=Math.max.apply(null,n);o=Math.min.apply(null,n)}else{o=0;i=t.length-1}return{max:i,min:o}};r.Range.getLength=function(t,e,a){var n;({yearly:function(){n=Math.ceil(e.getFullYear()-t.getFullYear())},monthly:function(){n=Math.ceil(12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))},quarter:function(){n=Math.ceil((12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))/4)},weekly:function(){n=Math.ceil((r.Date.getWeekStartday(e)-r.Date.getWeekStartday(t))/6048e5)},daily:function(){n=Math.ceil((e-t)/864e5)},hourly:function(){n=Math.ceil((e-t)/36e5)}})[a]();return n>0?n+1:1};r.Graph=function(t,a){this.config=e.extend({type:"morris.bar",staticPath:"",data:"graph.json"},t);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=r.Range.generate(a);if("string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=e.Deferred();this.getData(e.proxy(function(t){this.graphData[this.range.unit].resolve(this.generateGraphData(t))},this));this.$graphContainer=e('
');this.$graphContainer.on("UPDATE",e.proxy(function(t,a,r){this.update_(a,r);return e(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",e.proxy(function(){this.remove_()},this));var n=e(window).width();this.updateFunc=e.proxy(function(){if(n&&n!==e(window).width()){n=e(window).width();this.update_()}},this);t.autoResize&&e(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",e.proxy(function(t,a){e.proxy(this.getData(e.proxy(function(t){a(r.Range.getDataRange(t,this.range.isTimeline))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",e.proxy(function(t,a,r){e.proxy(this.getData(e.proxy(function(t){r(this.getDataLabelByIndex(a,t))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",e.proxy(function(t,a){this.$graphContainer.appendTo(a);this.graphData[this.range.unit].done(e.proxy(function(t){var a;a=this.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.start<=t.timestamp&&t.timestamp<=this.range.end},this)):t.slice(this.range.min,this.range.max+1);this.draw_(a)},this));return e(this.$graphContainer)},this));return this.$graphContainer};r.Graph.prototype.getData=function(t){r.Data.getData(this.origData_,this.$graphContainer,t,this)};r.Graph.prototype.getDataLabelByIndex=function(t,a){var r=this.config.dataLabel||"x";return e.map(t,function(t){return a[t][r]})};r.Graph.prototype.getTotalCount_=function(t,a){var r=0,n="y"+(a||"");e.each(t,function(t,e){r+=parseInt(e[n]||e.value||0,10)});return r};r.Graph.prototype.getDelta_=function(t,e){var a,r,n,i,o=t.length;i="y"+(e||"");a=t[o-1];r=t[o-2];n=r&&a&&r[i]?a[i]-r[i]:a[i];return void 0===n?"":n};r.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};r.Graph.getChartColors=function(t,e){var a={reverse:function(t){return t.reverse()},shuffle:function(t){var e,a,r,n;r=t.length;for(e=0;r>e;e++){a=Math.floor(Math.random()*r);n=t[e];t[e]=t[a];t[a]=n}return t},def:function(t){return t}};return a[e||"def"](t||r.Graph.presetColors())};r.Graph.cachedChartColors={};r.Graph.getCachedChartColors=function(t,e,a){return r.Graph.cachedChartColors[t]=r.Graph.cachedChartColors[t]||r.Graph.getChartColors(e,a)};r.Graph.prototype.draw_=function(t){var a=this.config.type.split("."),n=a[0],i=a[1],o=this.config;if(o.label)if(this.labelTemplate)this.generateLabel(this.labelTemplate);else if(o.label.template){var s=o.label.template;if(window.require&&"function"==typeof require){var h=o.label.type;require([h+"!"+o.staticPath+s],e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}else{var l=e.get(o.staticPath+s,"text");r.Data.getData(l,this.$graphContainer,e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}}else{this.labelTemplate='';this.generateLabel(this.labelTemplate)}if(o.fallback&&o.fallback.test&&!r.Graph.test[o.fallback.test]()){a=o.fallback.type.split(".");n=a[0];i=a[1];o=e.extend(o,o.fallback)}o.chartColors&&"string"==typeof o.chartColors&&(o.chartColors=o.chartColors.split(","));this.graphObject=r.Graph[n][i](t,o,this.range,this.$graphContainer)};r.Graph.test={};r.Graph.test.canvas=function(){var t=document.createElement("canvas");return t.getContext&&t.getContext("2d")};r.Graph.test.svg=function(){var t={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(t.svg,"svg").createSVGRect};r.Graph.test.vml=function(){var t,e=r.Graph.test.svg();if(!e){var a=document.body.appendChild(document.createElement("div"));a.innerHTML='';var n=a.firstChild;n.style.behavior="url(#default#VML)";t=n?"object"==typeof n.adj:!0;a.parentNode.removeChild(a)}return e||t};r.Graph.prototype.generateLabel=function(t){var a,n=this.config.label.template&&this.config.label.data?this.config.label.data:{},i=this.config.label.yLength||this.config.yLength,o=e.proxy(function(){this.labels=new r.Graph.Labels(this.$graphContainer,i,t);this.getData(e.proxy(function(t){for(var e=0;i>e;e++){this.config.label.hideTotalCount||this.labels.getTotalObject(e).createTotalCount(this.getTotalCount_(t,e));!this.config.label.hideDeltaCount&&this.range.isTimeline&&this.labels.getTotalObject(e).createDeltaCount(this.getDelta_(t,e))}},this))},this);if(n&&"string"==typeof n)a=e.getJSON(this.config.staticPath+n);else{a=e.Deferred();a.resolve(n)}a.done(function(e){if(t&&"function"==typeof t){t=t(e);o()}else if(window._){t=_.template(t,e);o()}else{t=t;o()}})};r.Graph.prototype.update_=function(t,a){var n=this;t=t||[];this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.range=r.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:a||this.range.unit,dataType:this.range.dataType,autoSized:this.range.autoSized});this.graphData[this.range.unit].done(e.proxy(function(t){var a;a=n.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.min<=t.timestamp&&t.timestamp<=this.range.max},this)):t.slice(this.range.min,this.range.max+1);this.draw_(a)},this))};r.Graph.prototype.remove_=function(){this.config.autoResize&&e(window).off("orientationchange debouncedresize",this.updateFunc);this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.$graphContainer.remove()};r.Graph.prototype.generateGraphData=function(t){var a,n,i,o,s,h,l,c=this.range,p=c.start,u=c.end,g=c.unit,d=c.length,f=[],y=this.config.yLength||1;if(this.range.isTimeline){var m=r.Range.getDataRange(t,this.range.isTimeline);p=new Date(Math.min(this.range.min,m.min));u=new Date(Math.max(this.range.max,m.max));d=r.Range.getLength(p,u,g);s=r.Data.filterData(t,m.max,m.min,g,y);for(a=0;d>a;a++){i=r.Range.getNextDate(p,u,a,g);if(!i)break;o=r.Date.createId(i,g);h={timestamp:i.valueOf(),x:r.Date.createXLabel(i,g)};for(n=0;y>n;n++){l="y"+(n||"");h[l]=s[o]?s[o][l]||0:0}f.push(h)}}else f=t;"morris.donut"===this.config.type&&e.each(f,function(t,a){e.extend(a,{label:a.xLabel||a.x,value:a.y})});return f};r.Graph.Labels=function(t,a,n){var i,o;this.$labelContainer=e('
');n&&e('
').html(n).prependTo(this.$labelContainer);this.totals={};for(i=0;a>i;i++){o="y"+(i||"");this.totals[o]=new r.Graph.Labels.Total(this.$labelContainer,i)}this.$labelContainer.appendTo(t)};r.Graph.Labels.prototype.remove=function(){this.$labelContainer.remove()};r.Graph.Labels.prototype.getTotalObject=function(t){return this.totals["y"+(t||"")]};r.Graph.Labels.Total=function(t,e){this.index=e;this.$totalContainer=a('
').appendTo(t)};r.Graph.Labels.Total.prototype.createTotalCount=function(t){a('"+t+" ").appendTo(this.$totalContainer)};r.Graph.Labels.Total.prototype.createDeltaCount=function(t){var e=t?0>t?"minus ":"plus ":"zero ";a('('+t+")").appendTo(this.$totalContainer)};r.Graph.css={};r.Graph.css.Base=function(t,a){this.len=t.length;this.$graphEl=e('
')};r.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};r.Graph.css.Base.prototype.horizontalBar=function(t,a,n,i){a.width&&this.$graphEl.css({width:a.width,"max-width":"100%",margin:"0 auto"});for(var o,s,h,l,c,p,u=a.barColor||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod)[1],g=a.barBackgroundColor||"#f0f0f0",d=a.dateColor||"#999999",f=a.dateColorSaturday||d,y=a.dateColorSunday||d,m=a.labelColor||"#999999",v=parseInt(a.barWidth,10)||30,D=parseInt(a.barMarginLeft,10)||30,C=parseInt(a.barInterval,10)||5,b=parseInt(a.labelSize,10)||.45*v,x=parseInt(a.dateLabelSize,10)||b,w=function(){return e('
')},T=e.map(t,function(t){return parseInt(t.y,10)}),L=e.map(t,function(t){return{value:""+parseInt(t.x.substr(t.x.lastIndexOf("-")+1),10),weekday:r.Date.parse(t.x)?r.Date.parse(t.x).getDay():null}}),$=Math.max.apply(null,T)||1,G=a.yLabel||T,M=this.len;M>0;){M-=1;o=Math.floor(100*(T[M]/$))-15;s=w();h=s.find(".css-graph-bar-background");h.css({"background-color":g});if(a.showDate){p=s.find(".css-graph-date");p.text(L[M].value).css({color:d,"font-size":x+"px","line-height":v+"px"});6===L[M].weekday?p.addClass("saturday").css({color:f}):0===L[M].weekday&&p.addClass("sunday").css({color:y});s.find(".css-graph-bar-container").css({"margin-left":D+"px"})}l=s.find(".css-graph-bar");l.css({width:o+"%","background-color":u});c=s.find(".css-graph-bar-count");c.text(G[M]).css({color:m,"font-size":b+"px","line-height":v+"px"});s.appendTo(this.$graphEl)}this.$graphEl.appendTo(i)};r.Graph.css.Base.prototype.ratioHorizontalBar=function(t,a,n,i){var o,s,h,l,c,p,u,g,d,f,y,m,v=a.yLength,D=parseInt(a.barWidth,10)||30,C=parseInt(a.barMarginLeft,10)||30,b=parseInt(a.barInterval,10)||5,x=parseInt(a.labelSize,10)||.45*D,w=a.dateColor||"#999999",T=a.barColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),L=a.labelColors,$=a.labelClasses;for(o=0;this.len>o;o++){h=t[o];l=[];c=0;m=0;for(s=0;v>s;s++){l.push(h["y"+(s||"")]);c+=parseInt(h["y"+(s||"")],10)}p=e('
').appendTo(this.$graphEl);if(a.showDate&&h.x){d=""+parseInt(h.x.substr(h.x.lastIndexOf("-")+1),10);f=e('
'+d+"
").appendTo(p)}u=e('
').appendTo(p);a.showDate&&u.css({"margin-left":C+"px"});for(s=0;v>s;s++){y=Math.floor(1e3*(l[s]/c))/10;if(y){v===s&&(y=100-m);m+=y;g=e('
');g.css({width:y+"%","background-color":T[s]});a.showCount&&g.text(l[s]);$&&$[s]&&g.addClass($[s]);L&&L[s]&&g.css({color:L[s]});g.appendTo(u)}}u.appendTo(p)}this.$graphEl.appendTo(i)};r.Graph.css.horizontalBar=r.Graph.css.ratioHorizontalBar=function(t,e,a,n){var i=new r.Graph.css.Base(t,e,a,n),o=e.type.slice(e.type.lastIndexOf(".")+1);i[o](t,e,a,n);return i};r.Graph.easel={};r.Graph.easel.Base=function(t,a,r,n){this.data=t;this.config=a;this.range=r;this.$container=n;if(window.createjs||"function"!=typeof window.require){var i=parseInt(a.width||n.width(),10);i?this.buildCanvas(createjs):setTimeout(e.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],e.proxy(function(){this.buildCanvas(createjs)},this))};r.Graph.easel.Base.prototype.buildCanvas=function(t){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=e('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new t.Stage(this.canvas);this.stage.update();var a=this.config.type.split(".")[1];this[a](this.data,this.config)};r.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};r.Graph.easel.Base.prototype.bar=function(t,a){for(var n,i,o,s,h,l=t.length,c=a.chartColorsAlpha?a.chartColorsAlpha[0]:1,p=a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),u=this.convertColor(p[0],c),g=parseInt(a.barMargin,10)||10,d=Math.floor(this.width/l),f=d-g,y=Math.floor((this.width-d*l)/2)+g/2,m=e.map(t,function(t){return parseInt(t.y,10)}),v=Math.max.apply(null,m)||1,D=0;l>D;D++){n=new createjs.Shape;i=n.graphics;o=D*d+y;h=Math.floor(m[D]/v*this.height);s=this.height-h;i.beginFill(u).drawRect(o,s,f,h);this.stage.addChild(n)}this.stage.update()};r.Graph.easel.Base.prototype.motionLine=function(t,a){var n,i,o=t.length,s=parseInt(a.lineWidth,10)||8,h=a.yLength||1,l=a.lineColors||a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),c=a.chartColorsAlpha||[null],p=a.pointerColors||a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),u=a.pointerColorsAlpha||[null],g=a.pointerRadius||10,d=s/2,f=s/2,y=2*(o-1),m=Math.floor(this.width/o)/2,v=(this.width-m*y)/2,D=this.height,C=[],b=function(t){return parseInt(t["y"+(x||"")],10)};a.drawPointer&&(f+=g);n=this.height-(d+f);for(var x=0;h>x;x++){i=e.map(t,b);C.push(i)}var w=[];e.each(C,function(t,e){w=w.concat(e)});var T=Math.max.apply(null,w)||1,L=[],$=function(t){var a=[];e.each(t,function(e,r){if(e>0){var i=t[e-1],o=i+Math.floor((r-i)/2);o=Math.floor(o/T*n)+f;r=Math.floor(r/T*n)+f;a=a.concat([o,r])}else{r=Math.floor(r/T*n)+f;a.push(r)}});return a};e.each(C,function(t,e){L.push($(e))});var G,M,_,E=[],S=[],A=v,I=[];for(x=0;h>x;x++){G=this.convertColor(l[x],c[x]);E[x]=new createjs.Shape;S[x]=E[x].graphics;M=D-L[x][0];S[x].setStrokeStyle(s).beginStroke(G).moveTo(A,M);this.stage.addChild(E[x]);if(a.drawPointer){_=this.convertColor(p[x],u[x]);I[x]=new createjs.Shape;I[x].graphics.beginFill(_).drawCircle(0,0,g);this.stage.addChild(I[x])}}var R=this.stage,F=function(t){y-=1;0===y&&createjs.Ticker.removeEventListener("tick",F);A+=m;for(var e,r=0;h>r;r++){e=L[r];M=D-e[e.length-y-1];S[r].lineTo(A,M);if(a.drawPointer){I[r].x=A;I[r].y=Math.max(M,g)}}R.update(t)};createjs.Ticker.useRAF=!0;createjs.Ticker.setFPS(30);createjs.Ticker.addEventListener("tick",F)};r.Graph.easel.Base.prototype.convertColor=function(t,e){if(-1!==t.indexOf("#")){var a=parseInt(t.substr(1,2),16),r=parseInt(t.substr(3,2),16),n=parseInt(t.substr(5,2),16);t=e?"rgba("+[a,r,n,e].join(",")+")":"rgb("+[a,r,n].join(",")+")"}else-1!==t.indexOf("rgb")&&(t=4>t.split(",").length?"rgb("+t+")":"rgba("+t+")");return t};r.Graph.easel.Base.prototype.mix=function(t,a){var n=0,i=function(t,a){t=t||1;var r=e.map(a,function(e){for(var a,r,i={x:e.x},o=0;t>o;o++){a="y"+(o||"");r="y"+(n+o||"");i[a]=e[r]}return i});n+=t;return r},o=a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod);e.each(a.mix,e.proxy(function(r,s){var h={chartColors:o.slice(n,n+s.yLength)},l=i(s.yLength,t);s=e.extend({},a,h,s);this[s.type](l,s)},this))};r.Graph.easel.bar=r.Graph.easel.motionLine=r.Graph.easel.mix=function(t,e,a,n){if(r.Graph.test.canvas()){var i=new r.Graph.easel.Base(t,e,a,n);return i}console.warn("EaselJS graph requires for HTML5 Canvas capability");n.trigger("REMOVE")};r.Graph.morris={};r.Graph.morris.Base=function(t,a,r,n){if(window.Morris||"function"!=typeof window.require){var i=a.width||n.width();i?this.build_(Morris,t,a,r,n):setTimeout(e.proxy(function(){this.build_(Morris,t,a,r,n)},this),100)}else require(["raphael","morris"],e.proxy(function(){this.build_(Morris,t,a,r,n)},this))};r.Graph.morris.Base.prototype.build_=function(t,a,n,i,o){var s,h,l,c=n.type.split(".")[1],p=n.yLength,u=n.width||o.width()||300,g=n.height||o.height()||300;this.$graphEl=e('
').css({height:g+"px",width:u+"px"}).prependTo(o);n=e.extend({},n,{element:n.id,data:a,xkey:"x",labels:this.getYLabels_(p,n.labels),ykeys:this.getYKeys_(p),ymax:this.getYMax_(a,c,p),ymin:n.ymin||0,lineWidth:parseInt(n.lineWidth,10)||6,pointSize:parseInt(n.pointSize,10)||6,smooth:n.smooth||!1});n.barColors=n.barColors||this.getChartColors(n);n.colors=n.colors||this.getChartColors(n);n.lineColors=n.lineColors||this.getChartColors(n);n.numLines=parseInt(n.numLines,10)||this.getNumLines_(n.ymax,g);n.pointStrokeColors=n.pointStrokeColors?n.pointStrokeColors.split(/,/):[];if(!n.pointStrokeColors.length)for(s=0;p>s;s++)n.pointStrokeColors.push("none");h={element:null,data:null,xkey:"x",labels:[],ykeys:[],dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,hideHover:!1,hoverCallback:null,yLabelFormat:null,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"],lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:50,continuousLine:!0,barSizeRatio:.75,barGap:3,barColors:["#0b62a4","#7a92a3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],backgroundColor:"#FFFFFF",labelColor:"#000000",formatter:t.commas};l={};e.each(n,function(t,e){void 0!==h[t]&&(l[t]=e)});r.Graph.test.svg||(l.smooth=!0);if("donut"===c){var d=this.getTotalCount_(a,s);l.formatter=function(t){var e=t=(t+"").replace(/,/g,"");if(!n.noCommaOnYLabel)for(;e!=(e=e.replace(/^(-?\d+)(\d{3})/,"$1,$2")););var a,r=Math.ceil(1e4*(t/d))/100;a=n.donutsFormatter&&"function"==typeof n.donutsFormatter?n.donutsFormatter(e,r+"%",t):e+"("+r+"%)";return a}}var f={bar:t.Bar,line:t.Line,donut:t.Donut,area:t.Area}[c];this.graph=new f(l)};r.Graph.morris.Base.prototype.getYMax_=function(t,a,r){var n,i,o,s,h;if("area"!==a){o=[];e.each(t,function(t,e){for(n=0;r>n;n++){h="y"+(n||"");o.push(parseInt(e[h],10))}});i=Math.max.apply(null,o)}else i=Math.max.apply(null,e.map(t,function(t){s=0;for(n=0;r>n;n++){h="y"+(n||"");s+=parseInt(t[h],10)}return s}));i||(i=1);0!==i%2&&(i+=1);return i};r.Graph.morris.Base.prototype.getChartColors=function(t){this.chartColors||(this.chartColors=t.chartColors||r.Graph.getCachedChartColors(t.id,null,t.chartColorsMethod));return this.chartColors};r.Graph.morris.Base.prototype.getYKeys_=function(t){var e,a=[];for(e=0;t>e;e++)a.push("y"+(e||""));return a};r.Graph.morris.Base.prototype.getYLabels_=function(t,e){var a,r=[];e=e?e.split(/,/):[];for(a=0;t>a;a++)r.push(e[a]||"Count");return r};r.Graph.morris.Base.prototype.getNumLines_=function(t,e){var a;a=t>=18?9:2===t?3:t/2+1;a=Math.min(a||1,Math.floor(e/56));return a};r.Graph.morris.Base.prototype.getTotalCount_=function(t,a){var r,n=0,i="y"+(a||"");e.each(t,function(t,e){r=e[i]||e.value||0;"string"==typeof r&&(r=parseFloat(r.replace(/,/g,""),10));n+=r});return n};r.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};r.Graph.morris.bar=r.Graph.morris.line=r.Graph.morris.donut=r.Graph.morris.area=function(t,e,a,n){if(r.Graph.test.vml()){var i=new r.Graph.morris.Base(t,e,a,n);return i}console.warn("Morris graph requires for SVG/VML capability");n.trigger("REMOVE")};r.Slider=function(t,a,n,i,o){if(!e.ui||!e.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var s=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.range=r.Range.generate(a);this.$dataRangeTarget=n;this.$sliderContainer=e('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};e.each(i,function(t,e){s.eventTargetList.update.add(e)});e.each(o,function(t,e){s.eventTargetList.amount.add(e)});this.$sliderContainer.on("APPEND_TO",function(t,a){s.$container=a;s.draw_(a);return e(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){s.$dataRangeTarget.trigger("GET_DATA_RANGE",function(t){s.buildSlider(t.min,t.max)});return e(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(t,a){s.$dataRangeTarget=a;return e(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(t,a,r){r=e.isArray(r)?r:[r];e.each(r,function(t,e){s.eventTargetList[a].add(e)});return e(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(t,a,r){r=e.isArray(r)?r:[r];e.each(r,function(t,e){s.eventTargetList[a].remove(e)});return e(this)});this.$sliderContainer.on("ERASE",function(){s.erase_();return e(this)});this.$sliderContainer.on("REDRAW",function(){var t=e(this);t.trigger("BUILD_SLIDER").trigger("APPEND_TO",[s.$container]);return e(this)});this.$sliderContainer.on("UPDATE",function(t,a){s.$slider("values",a);s.updateSliderAmount(a);return e(this)});return this.$sliderContainer};r.Slider.prototype.initEventTarget=function(){var t=[];return{add:function(e){t.push(e)},remove:function(a){t=e.grep(t,function(t){return t!==a})},get:function(){return t}}};r.Slider.prototype.buildSlider=function(t,a,r){var n=this;r=r||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}this.$slider=e('
').slider({range:!0,min:t,max:a,values:r,slide:function(t,e){n.updateSliderAmount(e.values,e)},stop:function(t,e){n.updateGraphAndList(e.values)}}).appendTo(n.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=e('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(r)}};r.Slider.prototype.draw_=function(t){this.$sliderContainer.appendTo(t)};r.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};r.Slider.prototype.updateSliderAmount=function(t,a){var n,i,o,s,h=this.range.maxLength,l=this.$amount;if(this.range.isTimeline){n=r.Date.parse(t[0]);i=r.Date.parse(t[1]);o=this.range.unit;s=r.Range.getLength(n,i,o);if(a&&s>h)if(a.value===a.values[0]){i=r.Date.calcDate(n,h,o,!1);this.$slider.slider("values",1,i.valueOf())}else{n=r.Date.calcDate(i,h,o,!0);this.$slider.slider("values",0,n.valueOf())}l&&l.text([r.Date.createXLabel(n,o),r.Date.createXLabel(i,o)].join(" - "))}else{n=t[0];i=t[1];if(i-n>h)if(a.value===a.values[0]){i=h-n;this.$slider.slider("values",1,i)}else{n=i-h;this.$slider.slider("values",0,n)}l&&e.each(this.eventTargetList.amount.get(),function(t,e){e.trigger("GET_LABEL",[[n,i],function(t){l.text([t[0],t[1]].join(" - "))}])})}};r.Slider.prototype.updateGraphAndList=function(t,a){e.each(this.eventTargetList.update.get(),function(e,r){r.trigger("UPDATE",[t,a])})};r.Slider.prototype.update_=function(t,e){this.$slider.slider("values",t,e)};r.List=function(t,a){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var n=this.config.type||"text";this.template_=e.Deferred();require([n+"!"+this.config.staticPath+this.config.template],e.proxy(function(t){this.template_.resolve(t)},this))}else this.template_=e.get(this.config.staticPath+this.config.template,"text");this.range=r.Range.generate(a);this.$listContainer=e('
');this.$listContainer.on("UPDATE",e.proxy(function(t,e){this.update_(e)},this));this.$listContainer.on("GET_DATA_RANGE",e.proxy(function(t,a){this.getData(e.proxy(function(t){a(r.Range.getDataRange(t,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",e.proxy(function(t,a,r){this.getData(e.proxy(function(t){r(this.getDataLabelByIndex(a,t))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",e.proxy(function(t,a){this.$listContainer.appendTo(a);this.getData(e.proxy(function(t){this.draw_(t)},this));return this.$listContainer},this));return this.$listContainer}};r.List.prototype.getData=function(t){this.config.data?r.Data.getData(this.origData_,this.$listContainer,t,this):t()};r.List.prototype.getTemplate=function(t){r.Data.getData(this.template_,this.$listContainer,t,this)};r.List.prototype.draw_=function(t){var e=this;this.getTemplate(function(a){t=e.createListData(t);e.$listContainer.html(_.template(a,t))})};r.List.prototype.getDataLabelByIndex=function(t,a){var r=this.config.dataLabel||"x";return e.map(t,function(t){return a[t][r]})};r.List.prototype.createListData=function(t){var e="";t&&(e=this.range.isTimeline?r.Data.filterData(t,this.range.max,this.range.min,this.range.unit,1,!0):t.slice(this.range.min,this.range.max+1));return{data:e}};r.List.prototype.update_=function(t,e){var a=this;t=t||[];e=e||this.range.unit;this.range=r.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:e,dataType:this.range.dataType});this.getData(function(t){a.draw_(t)})};r.Build=function(t){var a;if("string"==typeof t&&/\.json$/.test(t)){a=e('
');r.Data.getData(e.getJSON(t),null,function(t){t.$container=a;r.Build_(t).trigger("APPEND")})}else a=r.Build_(t).trigger("APPEND");return a};r.Build_=function(t){var a,n,i,o,s,h,l;a=t.$container||e('
'); -h=[];if(t.graph){n=new r.Graph(t.graph,t.range);h.push(n)}if(t.list){o=new r.List(t.list,t.range);t.list.data&&h.push(o)}if(t.graph&&"donut"!==t.graph.type){s=n;l=[n]}else{s=o;l=[o]}var c=function(){var t=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(t)};!t.slider||!t.slider.force&&c()||(i=new r.Slider(t.slider,t.range,s,h,l));a.on("APPEND",function(){n&&n.trigger("APPEND_TO",[a]);i&&i.trigger("BUILD_SLIDER").trigger("APPEND_TO",[a]);o&&o.trigger("APPEND_TO",[a])});a.on("GET_CONTAINER",function(t,e,a){a({graph:n,slider:i,list:o}[e])});return a};return r})(this,jQuery);return MT.ChartAPI}); \ No newline at end of file +!function(a,b){if("object"==typeof exports){var c=require("jquery");module.exports=b(c)}else"function"==typeof define&&define.amd&&define(["jquery"],b)}(this,function(a){!function(a,b){"use strict";var c=b,d={};(a.MT=a.MT||{}).ChartAPI=d;d.Data={};d.Data.getData=function(a,b,d,e){var f,g,h,i;a&&a.done(function(a){f||(f="string"==typeof a?""+a:c.isArray(a)?c.map(a,function(a){return c.extend({},a)}):c.extend({},a));d(f)}).fail(function(a){g={404:"Data is not found",403:"Data is forbidden to access"};h="Some error occured in the data fetching process";i=a.status?"error-"+a.status:"error-unknown";e&&(e.$errormsg=c('
'+(g[a.status]||h)+"
").appendTo(b))}).always(function(){e&&e.$progress&&e.$progress.parent().length>0&&e.$progress.remove()}).progress(function(){!e||e.$progress&&0!==e.$progress.parent().length||(e.$progress=c('
fetching data...
').appendTo(b))})};d.Data.filterData=function(a,b,e,f,g,h){var i,j={};g=g||1;c.each(a,function(a,k){var l,m;l=d.Date.parse(k.x);if(l&&l>=e&&l<=b)if(h){m=d.Date.createId(l,"daily");j[m]=k}else{"weekly"===f&&(l=d.Date.getWeekStartday(l));m=d.Date.createId(l,f);if(j[m])for(a=0;anew Date&&(b=new Date);a>b&&(a=b);e=d.Range.getLength(a,b,g);if(e>f){e=f;a=d.Date.calcDate(b,e,g,!0)}return{start:a,end:b,length:e,maxLength:f,unit:g,dataType:h,max:d.Range.getEndDate(b,g),min:d.Range.getStartDate(a,g),isTimeline:!0}};d.Range.calcNum=function(a,b,d,e,f,g,h){d=d||10;if(h){var i=c(window).width();e=Math.min(Math.ceil(.021875*i),e);d=Math.min(d,e)}if(!a&&!b){a=0;b=d-1}a=parseInt(a,10)||(0===a?0:null);b=parseInt(b,10)||(0===b?0:null);if(null===a){a=b-d;a<0&&(a=0)}null===b&&(b=a+d);a>b&&(a=b);d=b-a+1;if(d>e){d=e;a=b-e}return{start:a,end:b,length:d,maxLength:e,dataType:g,unit:null,max:b,min:a,isTimeline:!1}};d.Range.getStartDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,0,1,0,0,0)},monthly:function(){c=new Date(d,e,1,0,0,0)},quarter:function(){c=new Date(d,e,1,0,0,0)},weekly:function(){c=new Date(d,e,f-a.getDay(),0,0,0)},daily:function(){c=new Date(d,e,f,0,0,0)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c};d.Range.getEndDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,11,31,23,59,59)},monthly:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},quarter:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},weekly:function(){c=new Date(d,e,f-a.getDay()+6,23,59,59)},daily:function(){c=new Date(d,e,f,23,59,59)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c0?e+1:1};d.Graph=function(a,c){this.config=b.extend({type:"morris.bar",staticPath:"",data:"graph.json"},a);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=d.Range.generate(c);if("string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=b.Deferred();this.getData(b.proxy(function(a){this.graphData[this.range.unit].resolve(this.generateGraphData(a))},this));this.$graphContainer=b('
');this.$graphContainer.on("UPDATE",b.proxy(function(a,c,d){this.update_(c,d);return b(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",b.proxy(function(){this.remove_()},this));var e=b(window).width();this.updateFunc=b.proxy(function(){if(e&&e!==b(window).width()){e=b(window).width();this.update_()}},this);a.autoResize&&b(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){b.proxy(this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",b.proxy(function(a,c,d){b.proxy(this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",b.proxy(function(a,c){this.$graphContainer.appendTo(c);this.graphData[this.range.unit].done(b.proxy(function(a){var c;c=this.range.isTimeline?b.grep(a,b.proxy(function(a){return this.range.start<=a.timestamp&&a.timestamp<=this.range.end},this)):a.slice(this.range.min,this.range.max+1);this.draw_(c)},this));return b(this.$graphContainer)},this));return this.$graphContainer};d.Graph.prototype.getData=function(a){d.Data.getData(this.origData_,this.$graphContainer,a,this)};d.Graph.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.Graph.prototype.getTotalCount_=function(a,c){var d=0,e="y"+(c||"");b.each(a,function(a,b){d+=parseInt(b[e]||b.value||0,10)});return d};d.Graph.prototype.getDelta_=function(a,b){var c,d,e,f,g=a.length;f="y"+(b||"");c=a[g-1];d=a[g-2];e=d&&c&&d[f]?c[f]-d[f]:c[f];return void 0===e?"":e};d.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};d.Graph.getChartColors=function(a,b){return{reverse:function(a){return a.reverse()},shuffle:function(a){var b,c,d,e;d=a.length;for(b=0;b';this.generateLabel(this.labelTemplate)}if(g.fallback&&g.fallback.test&&!d.Graph.test[g.fallback.test]()){c=g.fallback.type.split(".");e=c[0];f=c[1];g=b.extend(g,g.fallback)}g.chartColors&&"string"==typeof g.chartColors&&(g.chartColors=g.chartColors.split(","));this.graphObject=d.Graph[e][f](a,g,this.range,this.$graphContainer)};d.Graph.test={};d.Graph.test.canvas=function(){var a=document.createElement("canvas");return a.getContext&&a.getContext("2d")};d.Graph.test.svg=function(){var a={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(a.svg,"svg").createSVGRect};d.Graph.test.vml=function(){var a,b=d.Graph.test.svg();if(!b){var c=document.body.appendChild(document.createElement("div"));c.innerHTML='';var e=c.firstChild;e.style.behavior="url(#default#VML)";a=!e||"object"==typeof e.adj;c.parentNode.removeChild(c)}return b||a};d.Graph.prototype.generateLabel=function(a){var c,e=this.config.label.template&&this.config.label.data?this.config.label.data:{},f=this.config.label.yLength||this.config.yLength,g=b.proxy(function(){this.labels=new d.Graph.Labels(this.$graphContainer,f,a);this.getData(b.proxy(function(a){for(var b=0;b
');e&&b('
').html(e).prependTo(this.$labelContainer);this.totals={};for(f=0;f
').appendTo(a)};d.Graph.Labels.Total.prototype.createTotalCount=function(a){c('"+a+" ").appendTo(this.$totalContainer)};d.Graph.Labels.Total.prototype.createDeltaCount=function(a){var b=a?a<0?"minus ":"plus ":"zero ";c('('+a+")").appendTo(this.$totalContainer)};d.Graph.css={};d.Graph.css.Base=function(a,c){this.len=a.length;this.$graphEl=b('
')};d.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.css.Base.prototype.horizontalBar=function(a,c,e,f){c.width&&this.$graphEl.css({width:c.width,"max-width":"100%",margin:"0 auto"});for(var g,h,i,j,k,l,m=c.barColor||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod)[1],n=c.barBackgroundColor||"#f0f0f0",o=c.dateColor||"#999999",p=c.dateColorSaturday||o,q=c.dateColorSunday||o,r=c.labelColor||"#999999",s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=parseInt(c.dateLabelSize,10)||v,x=function(){return b('
')},y=b.map(a,function(a){return parseInt(a.y,10)}),z=b.map(a,function(a){return{value:""+parseInt(a.x.substr(a.x.lastIndexOf("-")+1),10),weekday:d.Date.parse(a.x)?d.Date.parse(a.x).getDay():null}}),A=Math.max.apply(null,y)||1,B=c.yLabel||y,C=this.len;C>0;){C-=1;g=Math.floor(y[C]/A*100)-15;h=x();i=h.find(".css-graph-bar-background");i.css({"background-color":n});if(c.showDate){l=h.find(".css-graph-date");l.text(z[C].value).css({color:o,"font-size":w+"px","line-height":s+"px"});6===z[C].weekday?l.addClass("saturday").css({color:p}):0===z[C].weekday&&l.addClass("sunday").css({color:q});h.find(".css-graph-bar-container").css({"margin-left":t+"px"})}j=h.find(".css-graph-bar");j.css({width:g+"%","background-color":m});k=h.find(".css-graph-bar-count");k.text(B[C]).css({color:r,"font-size":v+"px","line-height":s+"px"});h.appendTo(this.$graphEl)}this.$graphEl.appendTo(f)};d.Graph.css.Base.prototype.ratioHorizontalBar=function(a,c,e,f){var g,h,i,j,k,l,m,n,o,p,q,r=c.yLength,s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=c.dateColor||"#999999",x=c.barColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),y=c.labelColors,z=c.labelClasses;for(g=0;g
').appendTo(this.$graphEl);if(c.showDate&&i.x){o=""+parseInt(i.x.substr(i.x.lastIndexOf("-")+1),10);b('
'+o+"
").appendTo(l)}m=b('
').appendTo(l);c.showDate&&m.css({"margin-left":t+"px"});for(h=0;h
');n.css({width:p+"%","background-color":x[h]});c.showCount&&n.text(j[h]);z&&z[h]&&n.addClass(z[h]);y&&y[h]&&n.css({color:y[h]});n.appendTo(m)}}m.appendTo(l)}this.$graphEl.appendTo(f)};d.Graph.css.horizontalBar=d.Graph.css.ratioHorizontalBar=function(a,b,c,e){var f=new d.Graph.css.Base(a,b,c,e);f[b.type.slice(b.type.lastIndexOf(".")+1)](a,b,c,e);return f};d.Graph.easel={};d.Graph.easel.Base=function(a,c,d,e){this.data=a;this.config=c;this.range=d;this.$container=e;if(window.createjs||"function"!=typeof window.require){parseInt(c.width||e.width(),10)?this.buildCanvas(createjs):setTimeout(b.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],b.proxy(function(){this.buildCanvas(createjs)},this))};d.Graph.easel.Base.prototype.buildCanvas=function(a){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=b('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new a.Stage(this.canvas);this.stage.update();this[this.config.type.split(".")[1]](this.data,this.config)};d.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};d.Graph.easel.Base.prototype.bar=function(a,c){for(var e,f,g,h,i,j=a.length,k=c.chartColorsAlpha?c.chartColorsAlpha[0]:1,l=c.chartColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),m=this.convertColor(l[0],k),n=parseInt(c.barMargin,10)||10,o=Math.floor(this.width/j),p=o-n,q=Math.floor((this.width-o*j)/2)+n/2,r=b.map(a,function(a){return parseInt(a.y,10)}),s=Math.max.apply(null,r)||1,t=0;t0){var f=a[b-1],g=f+Math.floor((d-f)/2);g=Math.floor(g/y*e)+p;d=Math.floor(d/y*e)+p;c=c.concat([g,d])}else{d=Math.floor(d/y*e)+p;c.push(d)}});return c};b.each(u,function(a,b){z.push(A(b))});var B,C,D,E=[],F=[],G=s,H=[];for(w=0;w
').css({height:n+"px",width:m+"px"}).prependTo(g);e=b.extend({},e,{element:e.id,data:c,xkey:"x",labels:this.getYLabels_(l,e.labels),ykeys:this.getYKeys_(l),ymax:this.getYMax_(c,k,l),ymin:e.ymin||0,lineWidth:parseInt(e.lineWidth,10)||6,pointSize:parseInt(e.pointSize,10)||6,smooth:e.smooth||!1});e.barColors=e.barColors||this.getChartColors(e);e.colors=e.colors||this.getChartColors(e);e.lineColors=e.lineColors||this.getChartColors(e);e.numLines=parseInt(e.numLines,10)||this.getNumLines_(e.ymax,n);e.pointStrokeColors=e.pointStrokeColors?e.pointStrokeColors.split(/,/):[];if(!e.pointStrokeColors.length)for(h=0;h=18?9:2===a?3:a/2+1;c=Math.min(c||1,Math.floor(b/56));return c};d.Graph.morris.Base.prototype.getTotalCount_=function(a,c){var d,e=0,f="y"+(c||"");b.each(a,function(a,b){d=b[f]||b.value||0;"string"==typeof d&&(d=parseFloat(d.replace(/,/g,""),10));e+=d});return e};d.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.morris.bar=d.Graph.morris.line=d.Graph.morris.donut=d.Graph.morris.area=function(a,b,c,e){if(d.Graph.test.vml()){return new d.Graph.morris.Base(a,b,c,e)}console.warn("Morris graph requires for SVG/VML capability");e.trigger("REMOVE")};d.Slider=function(a,c,e,f,g){if(!b.ui||!b.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var h=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.range=d.Range.generate(c);this.$dataRangeTarget=e;this.$sliderContainer=b('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};b.each(f,function(a,b){h.eventTargetList.update.add(b)});b.each(g,function(a,b){h.eventTargetList.amount.add(b)});this.$sliderContainer.on("APPEND_TO",function(a,c){h.$container=c;h.draw_(c);return b(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){h.$dataRangeTarget.trigger("GET_DATA_RANGE",function(a){h.buildSlider(a.min,a.max)});return b(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(a,c){h.$dataRangeTarget=c;return b(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].add(b)});return b(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].remove(b)});return b(this)});this.$sliderContainer.on("ERASE",function(){h.erase_();return b(this)});this.$sliderContainer.on("REDRAW",function(){b(this).trigger("BUILD_SLIDER").trigger("APPEND_TO",[h.$container]);return b(this)});this.$sliderContainer.on("UPDATE",function(a,c){h.$slider("values",c);h.updateSliderAmount(c);return b(this)});return this.$sliderContainer};d.Slider.prototype.initEventTarget=function(){var a=[];return{add:function(b){a.push(b)},remove:function(c){a=b.grep(a,function(a){return a!==c})},get:function(){return a}}};d.Slider.prototype.buildSlider=function(a,c,d){var e,f,g=["change","create","slide","start","stop"],h=this;d=d||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}e={range:!0,min:a,max:c,values:d,slide:function(a,b){h.updateSliderAmount(b.values,b)},stop:function(a,b){h.updateGraphAndList(b.values)}};g.forEach(function(a){if(h.config.callback[a]){f=e[a];e[a]=function(b,c){h.config.callback[a](b,c);f&&f(b,c)}}});this.$slider=b('
').slider(e).appendTo(h.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=b('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(d)}};d.Slider.prototype.draw_=function(a){this.$sliderContainer.appendTo(a)};d.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};d.Slider.prototype.updateSliderAmount=function(a,c){var e,f,g,h,i=this.range.maxLength,j=this.$amount;if(this.range.isTimeline){e=d.Date.parse(a[0]);f=d.Date.parse(a[1]);g=this.range.unit;h=d.Range.getLength(e,f,g);if(c&&h>i)if(c.value===c.values[0]){f=d.Date.calcDate(e,i,g,!1);this.$slider.slider("values",1,f.valueOf())}else{e=d.Date.calcDate(f,i,g,!0);this.$slider.slider("values",0,e.valueOf())}j&&j.text([d.Date.createXLabel(e,g),d.Date.createXLabel(f,g)].join(" - "))}else{e=a[0];f=a[1];if(f-e>i)if(c.value===c.values[0]){f=i-e;this.$slider.slider("values",1,f)}else{e=f-i;this.$slider.slider("values",0,e)}j&&b.each(this.eventTargetList.amount.get(),function(a,b){b.trigger("GET_LABEL",[[e,f],function(a){j.text([a[0],a[1]].join(" - "))}])})}};d.Slider.prototype.updateGraphAndList=function(a,c){b.each(this.eventTargetList.update.get(),function(b,d){d.trigger("UPDATE",[a,c])})};d.Slider.prototype.update_=function(a,b){this.$slider.slider("values",a,b)};d.List=function(a,c){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var e=this.config.type||"text";this.template_=b.Deferred();require([e+"!"+this.config.staticPath+this.config.template],b.proxy(function(a){this.template_.resolve(a)},this))}else this.template_=b.get(this.config.staticPath+this.config.template,"text");this.range=d.Range.generate(c);this.$listContainer=b('
');this.$listContainer.on("UPDATE",b.proxy(function(a,b){this.update_(b)},this));this.$listContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",b.proxy(function(a,c,d){this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",b.proxy(function(a,c){this.$listContainer.appendTo(c);this.getData(b.proxy(function(a){this.draw_(a)},this));return this.$listContainer},this));return this.$listContainer}};d.List.prototype.getData=function(a){this.config.data?d.Data.getData(this.origData_,this.$listContainer,a,this):a()};d.List.prototype.getTemplate=function(a){d.Data.getData(this.template_,this.$listContainer,a,this)};d.List.prototype.draw_=function(a){var b=this;this.getTemplate(function(c){a=b.createListData(a);b.$listContainer.html(_.template(c,a))})};d.List.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.List.prototype.createListData=function(a){var b="";a&&(b=this.range.isTimeline?d.Data.filterData(a,this.range.max,this.range.min,this.range.unit,1,!0):a.slice(this.range.min,this.range.max+1));return{data:b}};d.List.prototype.update_=function(a,b){var c=this;a=a||[];b=b||this.range.unit;this.range=d.Range.generate({start:a[0]||this.range.start,end:a[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:b,dataType:this.range.dataType});this.getData(function(a){c.draw_(a)})};d.Build=function(a){var c;if("string"==typeof a&&/\.json$/.test(a)){c=b('
');d.Data.getData(b.getJSON(a),null,function(a){a.$container=c;d.Build_(a).trigger("APPEND")}) +}else c=d.Build_(a).trigger("APPEND");return c};d.Build_=function(a){var c,e,f,g,h,i,j;c=a.$container||b('
');i=[];if(a.graph){e=new d.Graph(a.graph,a.range);i.push(e)}if(a.list){g=new d.List(a.list,a.range);a.list.data&&i.push(g)}if(a.graph&&"donut"!==a.graph.type){h=e;j=[e]}else{h=g;j=[g]}var k=function(){var a=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(a)};!a.slider||!a.slider.force&&k()||(f=new d.Slider(a.slider,a.range,h,i,j));c.on("APPEND",function(){e&&e.trigger("APPEND_TO",[c]);f&&f.trigger("BUILD_SLIDER").trigger("APPEND_TO",[c]);g&&g.trigger("APPEND_TO",[c])});c.on("GET_CONTAINER",function(a,b,c){c({graph:e,slider:f,list:g}[b])});return c};return d}(this,jQuery);return MT.ChartAPI}); \ No newline at end of file diff --git a/lib/core/mtchart.core.js b/lib/core/mtchart.core.js index d1738a7..de8f875 100644 --- a/lib/core/mtchart.core.js +++ b/lib/core/mtchart.core.js @@ -6,2270 +6,2282 @@ var ChartAPI = (function (global, $) { MT.ChartAPI = ChartAPI; ChartAPI.Data = {}; - -/** - * return back cloned data to callback. - * @param {!jQuery} jQuery ajax/deffered object - * @param {=jQuery} jQuery objecto of container element to attach ajax response status message which is required when this keyword has context(not null). - * @param {Function} callback function - * @param {=Object} current context - * @return {object} - */ -ChartAPI.Data.getData = function (obj, $container, callback, that) { - var cloneData, status, def, errorClassName; - if (obj) { - obj.done(function (data) { - if (!cloneData) { - if (typeof data === 'string') { - cloneData = data.toString(); - } else if (jQuery.isArray(data)) { - cloneData = jQuery.map(data, function (v) { - return jQuery.extend({}, v); - }); - } else { - cloneData = jQuery.extend({}, data); + + /** + * return back cloned data to callback. + * @param {!jQuery} jQuery ajax/deffered object + * @param {=jQuery} jQuery objecto of container element to attach ajax response status message which is required when this keyword has context(not null). + * @param {Function} callback function + * @param {=Object} current context + * @return {object} + */ + ChartAPI.Data.getData = function (obj, $container, callback, that) { + var cloneData, status, def, errorClassName; + if (obj) { + obj.done(function (data) { + if (!cloneData) { + if (typeof data === 'string') { + cloneData = data.toString(); + } else if (jQuery.isArray(data)) { + cloneData = jQuery.map(data, function (v) { + return jQuery.extend({}, v); + }); + } else { + cloneData = jQuery.extend({}, data); + } } - } - callback(cloneData); - }) - .fail(function (e) { - status = { - '404': 'Data is not found', - '403': 'Data is forbidden to access' - }; - def = 'Some error occured in the data fetching process'; - errorClassName = e.status ? 'error-' + e.status : 'error-unknown'; - if (that) { - that.$errormsg = jQuery('
' + (status[e.status] || def) + '
') - .appendTo($container); - } - }) - .always(function () { - if (that && that.$progress && that.$progress.parent().length > 0) { - that.$progress.remove(); - } - }) - .progress(function () { - if (that && (!that.$progress || that.$progress.parent().length === 0)) { - that.$progress = jQuery('
fetching data...
') - .appendTo($container); - } - }); - } -}; -/** - * @param {!object} JSON data to filter - * @param {!Date|number} maximum threshold value for filtering - * @param {!Date|number} minimum threshold value for filtering - * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - * @param {=number} the number of set of Y data - * @param {boolean} true if you do not want to unify data into a weekly data. - * @return {object} filtered JSON data - */ -ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { - var str, hash = {}; - - yLength = yLength || 1; - jQuery.each(data, function (i, v) { - var td, key; - td = ChartAPI.Date.parse(v.x); - if (td && td >= min && td <= max) { - if (noConcat) { - key = ChartAPI.Date.createId(td, 'daily'); - hash[key] = v; - } else { - if (u === 'weekly') { - td = ChartAPI.Date.getWeekStartday(td); + callback(cloneData); + }) + .fail(function (e) { + status = { + '404': 'Data is not found', + '403': 'Data is forbidden to access' + }; + def = 'Some error occured in the data fetching process'; + errorClassName = e.status ? 'error-' + e.status : 'error-unknown'; + if (that) { + that.$errormsg = jQuery('
' + (status[e.status] || def) + '
') + .appendTo($container); + } + }) + .always(function () { + if (that && that.$progress && that.$progress.parent().length > 0) { + that.$progress.remove(); } - key = ChartAPI.Date.createId(td, u); - if (hash[key]) { - for (i = 0; i < yLength; i++) { - str = i ? 'y' + i : 'y'; - hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); + }) + .progress(function () { + if (that && (!that.$progress || that.$progress.parent().length === 0)) { + that.$progress = jQuery('
fetching data...
') + .appendTo($container); + } + }); + } + }; + /** + * @param {!object} JSON data to filter + * @param {!Date|number} maximum threshold value for filtering + * @param {!Date|number} minimum threshold value for filtering + * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + * @param {=number} the number of set of Y data + * @param {boolean} true if you do not want to unify data into a weekly data. + * @return {object} filtered JSON data + */ + ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { + var str, hash = {}; + + yLength = yLength || 1; + jQuery.each(data, function (i, v) { + var td, key; + td = ChartAPI.Date.parse(v.x); + if (td && td >= min && td <= max) { + if (noConcat) { + key = ChartAPI.Date.createId(td, 'daily'); + hash[key] = v; + } else { + if (u === 'weekly') { + td = ChartAPI.Date.getWeekStartday(td); + } + key = ChartAPI.Date.createId(td, u); + if (hash[key]) { + for (i = 0; i < yLength; i++) { + str = i ? 'y' + i : 'y'; + hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); + } + } else { /* clone the object to prevent changing original */ + hash[key] = jQuery.extend({}, v); } - } else { /* clone the object to prevent changing original */ - hash[key] = jQuery.extend({}, v); } } - } - }); - return hash; -}; - + }); + return hash; + }; + ChartAPI.Date = {}; - -/** - * return the week start day - * @param {!Date} - * @return Date - */ -ChartAPI.Date.getWeekStartday = function (d) { - return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); -}; - -/** - * return Date string array with padding zero which is for ISO 8601 string - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Array.} - */ -ChartAPI.Date.zeroPadArray = function (d, unit) { - var array; - ({ - 'yearly': function () { - array = [d.getFullYear()]; - }, - 'monthly': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'quarter': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'weekly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; - }, - 'daily': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; - }, - 'hourly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; - } - })[unit](); - return jQuery.map(array, function (v) { - v = v.toString(); - return v.length === 1 ? '0' + v : v; - }); -}; - -/** - * return uniformalized Date string to use kinds of Date ID - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createId = function (d, u) { - return ChartAPI.Date.zeroPadArray(d, u).join(''); -}; - -/** - * return uniformalized Date string to use kinds of Date label - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createXLabel = function (d, u) { - var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); - if (u === 'hourly') { - hour = array.pop(); - str = array.join('-') + ' ' + hour + ':00'; - } else { - str = array.join('-'); - } - return str; -}; - -/** - * parse argument and return back Date object - * reformeded date string and try again when Date.parser returns NaN or Invalid - * @param {Date|number|string|null} - * @return {Date|null} - */ -ChartAPI.Date.parse = function (d) { - var date; - if (!d || d instanceof Date) { - date = d || null; - } else if (typeof d === 'number') { - date = new Date(d); - } else { - date = new Date(Date.parse(d.toString())); - } - if (date && /NaN|Invalid Date/.test(date.toString())) { - date = d.replace(/-/g, '/').split('+')[0]; - if (date.split('/').length === 1) { - // parse the string like 20130305T00:00:00 - date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); - date = [date[1], date[2], date[3]].join('/'); - } - if (date.split('/').length === 2) { - date = date + '/01'; - } - date = jQuery.each(date.split('/'), function (i, v) { + + /** + * return the week start day + * @param {!Date} + * @return Date + */ + ChartAPI.Date.getWeekStartday = function (d) { + return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); + }; + + /** + * return Date string array with padding zero which is for ISO 8601 string + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Array.} + */ + ChartAPI.Date.zeroPadArray = function (d, unit) { + var array; + ({ + 'yearly': function () { + array = [d.getFullYear()]; + }, + 'monthly': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'quarter': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'weekly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; + }, + 'daily': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; + }, + 'hourly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; + } + })[unit](); + return jQuery.map(array, function (v) { + v = v.toString(); return v.length === 1 ? '0' + v : v; - }).join('/'); - date = new Date(Date.parse(date)); - } - return date; -}; - -/** - * @param {!Date} - * @param {!number} number of data - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} calculates as start date when true - * @return {Date} - */ -ChartAPI.Date.calcDate = function (date, l, u, sym) { - var y, m, d, h; - y = date.getFullYear(); - m = date.getMonth(); - d = date.getDate(); - h = 0; - l = l - 1; - sym = sym ? -1 : 1; - ({ - 'yearly': function () { - y = y + (sym * l); - }, - 'monthly': function () { - m = m + (sym * l); - }, - 'quarter': function () { - m = m + (sym * l * 4); - }, - 'weekly': function () { - d = d + (sym * l * 7) - date.getDay(); - }, - 'daily': function () { - d = d + (sym * l); - }, - 'hourly': function () { - h = date.getHours() + (sym * l); - } - })[u](); - return new Date(y, m, d, h); -}; - + }); + }; + + /** + * return uniformalized Date string to use kinds of Date ID + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createId = function (d, u) { + return ChartAPI.Date.zeroPadArray(d, u).join(''); + }; + + /** + * return uniformalized Date string to use kinds of Date label + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createXLabel = function (d, u) { + var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); + if (u === 'hourly') { + hour = array.pop(); + str = array.join('-') + ' ' + hour + ':00'; + } else { + str = array.join('-'); + } + return str; + }; + + /** + * parse argument and return back Date object + * reformeded date string and try again when Date.parser returns NaN or Invalid + * @param {Date|number|string|null} + * @return {Date|null} + */ + ChartAPI.Date.parse = function (d) { + var date; + if (!d || d instanceof Date) { + date = d || null; + } else if (typeof d === 'number') { + date = new Date(d); + } else { + date = new Date(Date.parse(d.toString())); + } + if (date && /NaN|Invalid Date/.test(date.toString())) { + date = d.replace(/-/g, '/').split('+')[0]; + if (date.split('/').length === 1) { + // parse the string like 20130305T00:00:00 + date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); + date = [date[1], date[2], date[3]].join('/'); + } + if (date.split('/').length === 2) { + date = date + '/01'; + } + date = jQuery.each(date.split('/'), function (i, v) { + return v.length === 1 ? '0' + v : v; + }).join('/'); + date = new Date(Date.parse(date)); + } + return date; + }; + + /** + * @param {!Date} + * @param {!number} number of data + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} calculates as start date when true + * @return {Date} + */ + ChartAPI.Date.calcDate = function (date, l, u, sym) { + var y, m, d, h; + y = date.getFullYear(); + m = date.getMonth(); + d = date.getDate(); + h = 0; + l = l - 1; + sym = sym ? -1 : 1; + ({ + 'yearly': function () { + y = y + (sym * l); + }, + 'monthly': function () { + m = m + (sym * l); + }, + 'quarter': function () { + m = m + (sym * l * 4); + }, + 'weekly': function () { + d = d + (sym * l * 7) - date.getDay(); + }, + 'daily': function () { + d = d + (sym * l); + }, + 'hourly': function () { + h = date.getHours() + (sym * l); + } + })[u](); + return new Date(y, m, d, h); + }; + ChartAPI.Range = {}; -/** - * return unified Range data object (plain object which does not have prototyped method) - * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.factory = function (obj) { - var fn; - obj = obj || {}; - obj.maxLength = obj.maxLength || 90; - obj.dataType = obj.dataType || 'timeline'; - obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); - fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; - return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); -}; - -ChartAPI.Range.generate = ChartAPI.Range.factory; - -/** - * @param {string|null} data type - * @return {boolean} - */ -ChartAPI.Range.isTimeline = function (dataType) { - return !dataType || dataType === 'timeline'; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { - unit = unit || 'monthly'; - length = length || (unit === 'hourly' ? 24 : 10); - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = maxLength; - } - - s = ChartAPI.Date.parse(s); - e = ChartAPI.Date.parse(e); - - if (!s && !e) { - e = ChartAPI.Range.getEndDate(new Date(), unit); - } - - if (!s) { - s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); - } - if (!e) { - e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); - } - if (e > new Date()) { - e = new Date(); - } - if (s > e) { - s = e; - } - length = ChartAPI.Range.getLength(s, e, unit); - if (length > maxLength) { - length = maxLength; - s = ChartAPI.Date.calcDate(e, length, unit, true); - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - unit: unit, - dataType: dataType, - max: ChartAPI.Range.getEndDate(e, unit), - min: ChartAPI.Range.getStartDate(s, unit), - isTimeline: true - }; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { - length = length || 10; - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = Math.min(length, maxLength); - } - - if (!s && !e) { - s = 0; - e = length - 1; - } - - s = parseInt(s, 10) || (s === 0 ? 0 : null); - e = parseInt(e, 10) || (e === 0 ? 0 : null); - - if (s === null) { - s = e - length; - if (s < 0) { + /** + * return unified Range data object (plain object which does not have prototyped method) + * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.factory = function (obj) { + var fn; + obj = obj || {}; + obj.maxLength = obj.maxLength || 90; + obj.dataType = obj.dataType || 'timeline'; + obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); + fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; + return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); + }; + + ChartAPI.Range.generate = ChartAPI.Range.factory; + + /** + * @param {string|null} data type + * @return {boolean} + */ + ChartAPI.Range.isTimeline = function (dataType) { + return !dataType || dataType === 'timeline'; + }; + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { + unit = unit || 'monthly'; + length = length || (unit === 'hourly' ? 24 : 10); + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = maxLength; + } + + s = ChartAPI.Date.parse(s); + e = ChartAPI.Date.parse(e); + + if (!s && !e) { + e = ChartAPI.Range.getEndDate(new Date(), unit); + } + + if (!s) { + s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); + } + if (!e) { + e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); + } + if (e > new Date()) { + e = new Date(); + } + if (s > e) { + s = e; + } + length = ChartAPI.Range.getLength(s, e, unit); + if (length > maxLength) { + length = maxLength; + s = ChartAPI.Date.calcDate(e, length, unit, true); + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + unit: unit, + dataType: dataType, + max: ChartAPI.Range.getEndDate(e, unit), + min: ChartAPI.Range.getStartDate(s, unit), + isTimeline: true + }; + }; + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { + length = length || 10; + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = Math.min(length, maxLength); + } + + if (!s && !e) { s = 0; + e = length - 1; } - } - if (e === null) { - e = s + length; - } - if (s > e) { - s = e; - } - length = e - s + 1; - if (length > maxLength) { - length = maxLength; - s = e - maxLength; - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - dataType: dataType, - unit: null, - max: e, - min: s, - isTimeline: false - }; -}; - -/** - * return start date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getStartDate = function (d, unit) { - var start, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - start = new Date(year, 0, 1, 0, 0, 0); - }, - 'monthly': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'quarter': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'weekly': function () { - start = new Date(year, month, date - d.getDay(), 0, 0, 0); - }, - 'daily': function () { - start = new Date(year, month, date, 0, 0, 0); - }, - 'hourly': function () { - start = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return start; -}; - -/** - * return end date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getEndDate = function (d, unit) { - var end, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - end = new Date(year, 11, 31, 23, 59, 59); - }, - 'monthly': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'quarter': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'weekly': function () { - end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); - }, - 'daily': function () { - end = new Date(year, month, date, 23, 59, 59); - }, - 'hourly': function () { - end = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return end < new Date() ? end : new Date(); -}; - -/** - * return next date against the desinated range unit - * @param {Date} start date - * @param {Date} end date - * @param {number} increment number from start date - * @param {string} data u - * @return {Date} - */ -ChartAPI.Range.getNextDate = function (s, e, i, u) { - var d, year = s.getFullYear(), - month = s.getMonth(), - date = s.getDate(); - ({ - 'yearly': function (i) { - d = new Date(year + i, 0, 1); - }, - 'monthly': function (i) { - d = new Date(year, month + i, 1); - }, - 'quarter': function (i) { - d = new Date(year, month + i * 4, 1); - }, - 'weekly': function (i) { - d = new Date(year, month, date + i * 7 - s.getDay()); - }, - 'daily': function (i) { - d = new Date(year, month, date + i); - }, - 'hourly': function (i) { - d = new Date(year, month, date, s.getHours() + i); - } - })[u](i); - return d < e ? d : null; -}; - -/** - * return max and min value in JSON data - * @param {!object} JSON data - * @param {=boolean} true when data type is timeline - * @return {{max:number, min:number}} - */ -ChartAPI.Range.getDataRange = function (data, isTimeline) { - var map, max, min; - - if (isTimeline) { - map = jQuery.map(data, function (v) { - return ChartAPI.Date.parse(v.x) - .valueOf(); - }); - max = Math.max.apply(null, map); - min = Math.min.apply(null, map); - } else { - min = 0; - max = data.length - 1; - } - - return { - max: max, - min: min + + s = parseInt(s, 10) || (s === 0 ? 0 : null); + e = parseInt(e, 10) || (e === 0 ? 0 : null); + + if (s === null) { + s = e - length; + if (s < 0) { + s = 0; + } + } + if (e === null) { + e = s + length; + } + if (s > e) { + s = e; + } + length = e - s + 1; + if (length > maxLength) { + length = maxLength; + s = e - maxLength; + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + dataType: dataType, + unit: null, + max: e, + min: s, + isTimeline: false + }; }; -}; - -/** - * return number of data between start and end date - * @param {!Date} - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {number} - */ -ChartAPI.Range.getLength = function (s, e, u) { - var length; - ({ - 'yearly': function () { - length = Math.ceil(e.getFullYear() - s.getFullYear()); - }, - 'monthly': function () { - length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); - }, - 'quarter': function () { - length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); - }, - 'weekly': function () { - length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); - }, - 'daily': function () { - length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); - }, - 'hourly': function () { - length = Math.ceil((e - s) / (60 * 60 * 1000)); - } - })[u](); - return length > 0 ? length + 1 : 1; -}; - + /** - * Creates Graph Object - * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this - * $container is the jQuery object to which the graph append - * $('#graphContainer').trigger('APPEND_TO',[$container]) - * you want to update graph as well, fire UPDATE event like the same manner above. - * - * @param {object} graph setings - * @param {object} object including range settings - * @return {jQuery} return container jQuery object - * @constructor - */ -ChartAPI.Graph = function (config, range) { - this.config = $.extend({ - type: 'morris.bar', - staticPath: '', - data: 'graph.json' - }, config); - - this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config.yLength = parseInt(this.config.yLength, 10) || 1; - - this.range = ChartAPI.Range.generate(range); - - if (typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - this.graphData = {}; - this.graphData[this.range.unit] = $.Deferred(); - - this.getData($.proxy(function (data) { - this.graphData[this.range.unit].resolve(this.generateGraphData(data)); - }, this)); - - this.$graphContainer = $('
'); - + * return start date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} + */ + ChartAPI.Range.getStartDate = function (d, unit) { + var start, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + start = new Date(year, 0, 1, 0, 0, 0); + }, + 'monthly': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'quarter': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'weekly': function () { + start = new Date(year, month, date - d.getDay(), 0, 0, 0); + }, + 'daily': function () { + start = new Date(year, month, date, 0, 0, 0); + }, + 'hourly': function () { + start = new Date(year, month, date, d.getHours(), 0, 0); + } + })[unit](); + return start; + }; + /** - * @return {jQuery} return jQuery object for chaining - * update graph + * return end date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} */ - this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { - this.update_(newRange, unit); - return $(this.$graphContainer); - }, this)); - - this.$graphContainer.on('REMOVE', $.proxy(function () { - this.remove_(); - }, this)); - - // IE8 fires resize event even when document.body.innerWidht/innerHeight changing - // so check window.width and update only when window.width changing. - var windowWidth = $(window).width(); - this.updateFunc = $.proxy(function () { - if (windowWidth && windowWidth !== $(window).width()) { - windowWidth = $(window).width(); - this.update_(); - } - }, this); - - if (config.autoResize) { - $(window).on('orientationchange debouncedresize', this.updateFunc); - } - + ChartAPI.Range.getEndDate = function (d, unit) { + var end, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + end = new Date(year, 11, 31, 23, 59, 59); + }, + 'monthly': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'quarter': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'weekly': function () { + end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); + }, + 'daily': function () { + end = new Date(year, month, date, 23, 59, 59); + }, + 'hourly': function () { + end = new Date(year, month, date, d.getHours(), 0, 0); + } + })[unit](); + return end < new Date() ? end : new Date(); + }; + /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback + * return next date against the desinated range unit + * @param {Date} start date + * @param {Date} end date + * @param {number} increment number from start date + * @param {string} data u + * @return {Date} */ - this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - + ChartAPI.Range.getNextDate = function (s, e, i, u) { + var d, year = s.getFullYear(), + month = s.getMonth(), + date = s.getDate(); + ({ + 'yearly': function (i) { + d = new Date(year + i, 0, 1); + }, + 'monthly': function (i) { + d = new Date(year, month + i, 1); + }, + 'quarter': function (i) { + d = new Date(year, month + i * 4, 1); + }, + 'weekly': function (i) { + d = new Date(year, month, date + i * 7 - s.getDay()); + }, + 'daily': function (i) { + d = new Date(year, month, date + i); + }, + 'hourly': function (i) { + d = new Date(year, month, date, s.getHours() + i); + } + })[u](i); + return d < e ? d : null; + }; + /** - * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback + * return max and min value in JSON data + * @param {!object} JSON data + * @param {=boolean} true when data type is timeline + * @return {{max:number, min:number}} */ - this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - + ChartAPI.Range.getDataRange = function (data, isTimeline) { + var map, max, min; + + if (isTimeline) { + map = jQuery.map(data, function (v) { + return ChartAPI.Date.parse(v.x) + .valueOf(); + }); + max = Math.max.apply(null, map); + min = Math.min.apply(null, map); + } else { + min = 0; + max = data.length - 1; + } + + return { + max: max, + min: min + }; + }; + /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining + * return number of data between start and end date + * @param {!Date} + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {number} */ - this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { - this.$graphContainer.appendTo(container); - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (this.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.start <= v.timestamp && v.timestamp <= this.range.end; - }, this)); - } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + ChartAPI.Range.getLength = function (s, e, u) { + var length; + ({ + 'yearly': function () { + length = Math.ceil(e.getFullYear() - s.getFullYear()); + }, + 'monthly': function () { + length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); + }, + 'quarter': function () { + length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); + }, + 'weekly': function () { + length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); + }, + 'daily': function () { + length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); + }, + 'hourly': function () { + length = Math.ceil((e - s) / (60 * 60 * 1000)); } - this.draw_(filteredData); + })[u](); + return length > 0 ? length + 1 : 1; + }; + + /** + * Creates Graph Object + * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this + * $container is the jQuery object to which the graph append + * $('#graphContainer').trigger('APPEND_TO',[$container]) + * you want to update graph as well, fire UPDATE event like the same manner above. + * + * @param {object} graph setings + * @param {object} object including range settings + * @return {jQuery} return container jQuery object + * @constructor + */ + ChartAPI.Graph = function (config, range) { + this.config = $.extend({ + type: 'morris.bar', + staticPath: '', + data: 'graph.json' + }, config); + + this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config.yLength = parseInt(this.config.yLength, 10) || 1; + + this.range = ChartAPI.Range.generate(range); + + if (typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); + } else { + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); + } + + this.graphData = {}; + this.graphData[this.range.unit] = $.Deferred(); + + this.getData($.proxy(function (data) { + this.graphData[this.range.unit].resolve(this.generateGraphData(data)); }, this)); - return $(this.$graphContainer); - }, this)); - - return this.$graphContainer; -}; - -/** - * call getData function for getting graph JSON data - * @param {Function} callback function recieve graph JSON data - */ -ChartAPI.Graph.prototype.getData = function (callback) { - ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); -}; - -/** - * return data label array with array indexes - * @param {!Array.} array of indexes - * @param {!Array.} graph JSON data - * @return {Array.} - */ -ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''); - $.each(data, function (i, v) { - total = total + parseInt((v[str] || v.value || 0), 10); - }); - return total; -}; - -/** - * return the delta number and className between last and last second count - * @param {!object} graph JSON data - * @param {!number} number of set of Y data - * @return {y:[number,string],y1:[number,string]} - */ -ChartAPI.Graph.prototype.getDelta_ = function (data, index) { - var e, s, delta, key, length = data.length; - - key = 'y' + (index || ''); - e = data[length - 1]; - s = data[length - 2]; - delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; - return delta === undefined ? '' : delta; -}; - -ChartAPI.Graph.presetColors = function () { - return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; -}; - -ChartAPI.Graph.getChartColors = function (colors, type) { - var func = { - 'reverse': function (arr) { - return arr.reverse(); - }, - 'shuffle': function (arr) { - var i, j, length, tmp; - length = arr.length; - for (i = 0; i < length; i++) { - j = Math.floor(Math.random() * length); - tmp = arr[i]; - arr[i] = arr[j]; - arr[j] = tmp; + + this.$graphContainer = $('
'); + + /** + * @return {jQuery} return jQuery object for chaining + * update graph + */ + this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { + this.update_(newRange, unit); + return $(this.$graphContainer); + }, this)); + + this.$graphContainer.on('REMOVE', $.proxy(function () { + this.remove_(); + }, this)); + + // IE8 fires resize event even when document.body.innerWidht/innerHeight changing + // so check window.width and update only when window.width changing. + var windowWidth = $(window).width(); + this.updateFunc = $.proxy(function () { + if (windowWidth && windowWidth !== $(window).width()) { + windowWidth = $(window).width(); + this.update_(); } - return arr; - }, - 'def': function (arr) { - return arr; + }, this); + + if (config.autoResize) { + $(window).on('orientationchange debouncedresize', this.updateFunc); } - }; - return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); -}; - -ChartAPI.Graph.cachedChartColors = {}; -ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { - return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); -}; - -/** - * Draw Graph - * @param {!Array.} graph data - * @param {=string} graph type (bar|line|area|donut) - * @return nothing - */ -ChartAPI.Graph.prototype.draw_ = function (data) { - var arr = this.config.type.split('.'); - var lib = arr[0]; - var method = arr[1]; - var config = this.config; - - if (config.label) { - if (this.labelTemplate) { - this.generateLabel(this.labelTemplate); - } else { - if (config.label.template) { - var labelTemplate = config.label.template; - if (window.require && typeof require === 'function') { - var templateType = config.label.type; - require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this), this)); + return $(this.$graphContainer); + }, this)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this), this)); + return $(this.$graphContainer); + }, this)); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { + this.$graphContainer.appendTo(container); + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (this.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.start <= v.timestamp && v.timestamp <= this.range.end; }, this)); } else { - var dfd = $.get(config.staticPath + labelTemplate, 'text'); - ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); - }, this)); + filteredData = data.slice(this.range.min, this.range.max + 1); } - } else { - this.labelTemplate = ''; - this.generateLabel(this.labelTemplate); - } - } - } - - if (config.fallback && config.fallback.test) { - if (!ChartAPI.Graph.test[config.fallback.test]()) { - arr = config.fallback.type.split('.'); - lib = arr[0]; - method = arr[1]; - config = $.extend(config, config.fallback); - } - } - - if (config.chartColors && typeof config.chartColors === 'string') { - config.chartColors = config.chartColors.split(','); - } - - this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); -}; - -ChartAPI.Graph.test = {}; - -ChartAPI.Graph.test.canvas = function () { - var elem = document.createElement('canvas'); - return elem.getContext && elem.getContext('2d'); -}; - -ChartAPI.Graph.test.svg = function () { - var ns = { - 'svg': 'http://www.w3.org/2000/svg' + this.draw_(filteredData); + }, this)); + return $(this.$graphContainer); + }, this)); + + return this.$graphContainer; }; - return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; -}; - -/* - * this test checks suport both VML and SVG since we only use VML for SVG fallback - */ -ChartAPI.Graph.test.vml = function () { - var vmlSupported; - var svgSupported = ChartAPI.Graph.test.svg(); - // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser - if (!svgSupported) { - var a = document.body.appendChild(document.createElement('div')); - a.innerHTML = ''; - var b = a.firstChild; - b.style.behavior = "url(#default#VML)"; - vmlSupported = b ? typeof b.adj === "object" : true; - a.parentNode.removeChild(a); - } - return (svgSupported || vmlSupported); -}; - -ChartAPI.Graph.prototype.generateLabel = function (template) { - var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, - yLength = this.config.label.yLength || this.config.yLength, - dfd; - - var finalize = $.proxy(function () { - this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); - - this.getData($.proxy(function (data) { - for (var i = 0; i < yLength; i++) { - if (!this.config.label.hideTotalCount) { - this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + + /** + * call getData function for getting graph JSON data + * @param {Function} callback function recieve graph JSON data + */ + ChartAPI.Graph.prototype.getData = function (callback) { + ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); + }; + + /** + * return data label array with array indexes + * @param {!Array.} array of indexes + * @param {!Array.} graph JSON data + * @return {Array.} + */ + ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''); + $.each(data, function (i, v) { + total = total + parseInt((v[str] || v.value || 0), 10); + }); + return total; + }; + + /** + * return the delta number and className between last and last second count + * @param {!object} graph JSON data + * @param {!number} number of set of Y data + * @return {y:[number,string],y1:[number,string]} + */ + ChartAPI.Graph.prototype.getDelta_ = function (data, index) { + var e, s, delta, key, length = data.length; + + key = 'y' + (index || ''); + e = data[length - 1]; + s = data[length - 2]; + delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; + return delta === undefined ? '' : delta; + }; + + ChartAPI.Graph.presetColors = function () { + return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; + }; + + ChartAPI.Graph.getChartColors = function (colors, type) { + var func = { + 'reverse': function (arr) { + return arr.reverse(); + }, + 'shuffle': function (arr) { + var i, j, length, tmp; + length = arr.length; + for (i = 0; i < length; i++) { + j = Math.floor(Math.random() * length); + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } - if (!this.config.label.hideDeltaCount && this.range.isTimeline) { - this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + return arr; + }, + 'def': function (arr) { + return arr; + } + }; + return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); + }; + + ChartAPI.Graph.cachedChartColors = {}; + ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { + return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); + }; + + /** + * Draw Graph + * @param {!Array.} graph data + * @param {=string} graph type (bar|line|area|donut) + * @return nothing + */ + ChartAPI.Graph.prototype.draw_ = function (data) { + var arr = this.config.type.split('.'); + var lib = arr[0]; + var method = arr[1]; + var config = this.config; + + if (config.label) { + if (this.labelTemplate) { + this.generateLabel(this.labelTemplate); + } else { + if (config.label.template) { + var labelTemplate = config.label.template; + if (window.require && typeof require === 'function') { + var templateType = config.label.type; + require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } else { + var dfd = $.get(config.staticPath + labelTemplate, 'text'); + ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } + } else { + this.labelTemplate = ''; + this.generateLabel(this.labelTemplate); } } - }, this)); - }, this); - - if (data && typeof data === 'string') { - dfd = $.getJSON(this.config.staticPath + data); - } else { - dfd = $.Deferred(); - dfd.resolve(data); - } - - dfd.done(function (data) { - if (template && typeof template === 'function') { - template = template(data); - finalize(); - } else if (window._) { - template = _.template(template, data); - finalize(); - } else { - template = template; - finalize(); } - }); -}; - -/** - * update Graph - * @param {=Array.} - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Graph.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.range = ChartAPI.Range.generate({ - 'start': (newRange[0] || this.range.start), - 'end': (newRange[1] || this.range.end), - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': (unit || this.range.unit), - 'dataType': this.range.dataType, - 'autoSized': this.range.autoSized - }); - - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (that.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + + if (config.fallback && config.fallback.test) { + if (!ChartAPI.Graph.test[config.fallback.test]()) { + arr = config.fallback.type.split('.'); + lib = arr[0]; + method = arr[1]; + config = $.extend(config, config.fallback); + } + } + + if (config.chartColors && typeof config.chartColors === 'string') { + config.chartColors = config.chartColors.split(','); + } + + this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); + }; + + ChartAPI.Graph.test = {}; + + ChartAPI.Graph.test.canvas = function () { + var elem = document.createElement('canvas'); + return elem.getContext && elem.getContext('2d'); + }; + + ChartAPI.Graph.test.svg = function () { + var ns = { + 'svg': 'http://www.w3.org/2000/svg' + }; + return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; + }; + + /* + * this test checks suport both VML and SVG since we only use VML for SVG fallback + */ + ChartAPI.Graph.test.vml = function () { + var vmlSupported; + var svgSupported = ChartAPI.Graph.test.svg(); + // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser + if (!svgSupported) { + var a = document.body.appendChild(document.createElement('div')); + a.innerHTML = ''; + var b = a.firstChild; + b.style.behavior = "url(#default#VML)"; + vmlSupported = b ? typeof b.adj === "object" : true; + a.parentNode.removeChild(a); + } + return (svgSupported || vmlSupported); + }; + + ChartAPI.Graph.prototype.generateLabel = function (template) { + var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, + yLength = this.config.label.yLength || this.config.yLength, + dfd; + + var finalize = $.proxy(function () { + this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); + + this.getData($.proxy(function (data) { + for (var i = 0; i < yLength; i++) { + if (!this.config.label.hideTotalCount) { + this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + } + if (!this.config.label.hideDeltaCount && this.range.isTimeline) { + this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + } + } }, this)); + }, this); + + if (data && typeof data === 'string') { + dfd = $.getJSON(this.config.staticPath + data); } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + dfd = $.Deferred(); + dfd.resolve(data); } - this.draw_(filteredData); - }, this)); -}; - -ChartAPI.Graph.prototype.remove_ = function () { - if (this.config.autoResize) { - $(window).off('orientationchange debouncedresize', this.updateFunc); - } - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.$graphContainer.remove(); -}; - -ChartAPI.Graph.prototype.generateGraphData = function (data) { - var i, j, td, key, range = this.range, - start = range.start, - end = range.end, - u = range.unit, - length = range.length, - array = [], - yLength = this.config.yLength || 1, - filteredData, obj, str; - if (this.range.isTimeline) { - var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); - start = new Date(Math.min(this.range.min, dataRange.min)); - end = new Date(Math.max(this.range.max, dataRange.max)); - length = ChartAPI.Range.getLength(start, end, u); - filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); - - for (i = 0; i < length; i++) { - td = ChartAPI.Range.getNextDate(start, end, i, u); - if (td) { - key = ChartAPI.Date.createId(td, u); - obj = { - timestamp: td.valueOf(), - x: ChartAPI.Date.createXLabel(td, u) - }; - for (j = 0; j < yLength; j++) { - str = 'y' + (j || ''); - obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; - } - array.push(obj); + + dfd.done(function (data) { + if (template && typeof template === 'function') { + template = template(data); + finalize(); + } else if (window._) { + template = _.template(template, data); + finalize(); } else { - break; + template = template; + finalize(); } - } - } else { - array = data; - } - if (this.config.type === 'morris.donut') { - $.each(array, function (i, v) { - $.extend(v, { - label: (v.xLabel || v.x), - value: v.y - }); }); - } - return array; -}; - + }; + /** - * @param {!jQuery} - jQuery object to which attach label element(typically graph container) - * @param {!number} length of set of data to use - * @param {=string} html string to use label - * @constructor - */ -ChartAPI.Graph.Labels = function ($container, yLength, template) { - var i, key; - - this.$labelContainer = $('
'); - if (template) { - $('
').html(template).prependTo(this.$labelContainer); - } - - this.totals = {}; - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); - } - - this.$labelContainer.appendTo($container); -}; - -/** - * remove label container - */ -ChartAPI.Graph.Labels.prototype.remove = function () { - this.$labelContainer.remove(); -}; - -/** - * get ChartAPI.Graph.Labels.Total object - * @param {=number} the number of Y data set - * @return {ChartAPI.Graph.Labels.Total} - */ -ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { - return this.totals['y' + (i || '')]; -}; - -/** - * @constructor - * @param {!jQuery} jQuery object to attach - * @param {!number} number for identify what Y data is associated with - */ -ChartAPI.Graph.Labels.Total = function (container, index) { - this.index = index; - this.$totalContainer = jQuery('
').appendTo(container); -}; - -/** - * create element for displaying total count and append its container - * @param {!number} total count - */ -ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { - jQuery('' + count + ' ').appendTo(this.$totalContainer); -}; - -/** - * create element for displaying delta - * @param {!number} delta count - */ -ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { - var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; - - jQuery('(' + delta + ')').appendTo(this.$totalContainer); -}; - - ChartAPI.Graph.css = {}; - -ChartAPI.Graph.css.Base = function (data, config) { - this.len = data.length; - this.$graphEl = $('
'); -}; - -ChartAPI.Graph.css.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { - if (config.width) { - this.$graphEl.css({ - 'width': config.width, - 'max-width': '100%', - 'margin': '0 auto' + * update Graph + * @param {=Array.} + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.Graph.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); + } + if (this.labels) { + this.labels.remove(); + } + this.range = ChartAPI.Range.generate({ + 'start': (newRange[0] || this.range.start), + 'end': (newRange[1] || this.range.end), + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': (unit || this.range.unit), + 'dataType': this.range.dataType, + 'autoSized': this.range.autoSized }); - } - - var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], - barBackgroundColor = config.barBackgroundColor || '#f0f0f0', - dateColor = config.dateColor || '#999999', - dateColorSaturday = config.dateColorSaturday || dateColor, - dateColorSunday = config.dateColorSunday || dateColor, - labelColor = config.labelColor || '#999999', - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, - createCSSGraphBarEl = function () { - return $('
'); - }, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - label = $.map(data, function (d) { - return { - value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), - weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null + + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (that.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + }, this)); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); } - }), - maxY = Math.max.apply(null, dataY) || 1, - yLabel = config.yLabel || dataY, - width, $el, $background, $bar, $count, $date; - - for (var i = this.len; i > 0;) { - i = i - 1; - width = Math.floor((dataY[i] / maxY) * 100) - 15; - $el = createCSSGraphBarEl(); - $background = $el.find('.css-graph-bar-background'); - $background.css({ - 'background-color': barBackgroundColor - }); - - if (config.showDate) { - $date = $el.find('.css-graph-date'); - $date.text(label[i].value).css({ - 'color': dateColor, - 'font-size': dateLabelSize + 'px', - 'line-height': barWidth + 'px' - }); - if (label[i].weekday === 6) { - $date.addClass('saturday').css({ - 'color': dateColorSaturday - }); - } else if (label[i].weekday === 0) { - $date.addClass('sunday').css({ - 'color': dateColorSunday - }) + this.draw_(filteredData); + }, this)); + }; + + ChartAPI.Graph.prototype.remove_ = function () { + if (this.config.autoResize) { + $(window).off('orientationchange debouncedresize', this.updateFunc); + } + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); + } + if (this.labels) { + this.labels.remove(); + } + this.$graphContainer.remove(); + }; + + ChartAPI.Graph.prototype.generateGraphData = function (data) { + var i, j, td, key, range = this.range, + start = range.start, + end = range.end, + u = range.unit, + length = range.length, + array = [], + yLength = this.config.yLength || 1, + filteredData, obj, str; + if (this.range.isTimeline) { + var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); + start = new Date(Math.min(this.range.min, dataRange.min)); + end = new Date(Math.max(this.range.max, dataRange.max)); + length = ChartAPI.Range.getLength(start, end, u); + filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); + + for (i = 0; i < length; i++) { + td = ChartAPI.Range.getNextDate(start, end, i, u); + if (td) { + key = ChartAPI.Date.createId(td, u); + obj = { + timestamp: td.valueOf(), + x: ChartAPI.Date.createXLabel(td, u) + }; + for (j = 0; j < yLength; j++) { + str = 'y' + (j || ''); + obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; + } + array.push(obj); + } else { + break; + } } - - $el.find('.css-graph-bar-container').css({ - 'margin-left': barMarginLeft + 'px' + } else { + array = data; + } + if (this.config.type === 'morris.donut') { + $.each(array, function (i, v) { + $.extend(v, { + label: (v.xLabel || v.x), + value: v.y + }); }); } - - $bar = $el.find('.css-graph-bar'); - $bar.css({ - 'width': width + '%', - 'background-color': barColor - }); - $count = $el.find('.css-graph-bar-count'); - $count.text(yLabel[i]).css({ - 'color': labelColor, - 'font-size': labelSize + 'px', - 'line-height': barWidth + 'px' - }); - $el.appendTo(this.$graphEl); - } - - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { - var yLength = config.yLength, - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateColor = config.dateColor || '#999999', - barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - labelColors = config.labelColors, - labelClasses = config.labelClasses, - i, j, - d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; - - for (i = 0; i < this.len; i++) { - d = data[i]; - dataY = []; - totalY = 0; - totalWidth = 0; - for (j = 0; j < yLength; j++) { - dataY.push(d['y' + (j || '')]); - totalY = totalY + parseInt(d['y' + (j || '')], 10); + return array; + }; + + /** + * @param {!jQuery} + jQuery object to which attach label element(typically graph container) + * @param {!number} length of set of data to use + * @param {=string} html string to use label + * @constructor + */ + ChartAPI.Graph.Labels = function ($container, yLength, template) { + var i, key; + + this.$labelContainer = $('
'); + if (template) { + $('
').html(template).prependTo(this.$labelContainer); } - - $barContainer = $('
').appendTo(this.$graphEl); - if (config.showDate && d.x) { - label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); - $date = $('
' + label + '
').appendTo($barContainer); + + this.totals = {}; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); } - - $el = $('
').appendTo($barContainer); - - if (config.showDate) { - $el.css({ - 'margin-left': barMarginLeft + 'px' + + this.$labelContainer.appendTo($container); + }; + + /** + * remove label container + */ + ChartAPI.Graph.Labels.prototype.remove = function () { + this.$labelContainer.remove(); + }; + + /** + * get ChartAPI.Graph.Labels.Total object + * @param {=number} the number of Y data set + * @return {ChartAPI.Graph.Labels.Total} + */ + ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { + return this.totals['y' + (i || '')]; + }; + + /** + * @constructor + * @param {!jQuery} jQuery object to attach + * @param {!number} number for identify what Y data is associated with + */ + ChartAPI.Graph.Labels.Total = function (container, index) { + this.index = index; + this.$totalContainer = jQuery('
').appendTo(container); + }; + + /** + * create element for displaying total count and append its container + * @param {!number} total count + */ + ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { + jQuery('' + count + ' ').appendTo(this.$totalContainer); + }; + + /** + * create element for displaying delta + * @param {!number} delta count + */ + ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { + var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; + + jQuery('(' + delta + ')').appendTo(this.$totalContainer); + }; + + ChartAPI.Graph.css = {}; + + ChartAPI.Graph.css.Base = function (data, config) { + this.len = data.length; + this.$graphEl = $('
'); + }; + + ChartAPI.Graph.css.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { + if (config.width) { + this.$graphEl.css({ + 'width': config.width, + 'max-width': '100%', + 'margin': '0 auto' }); } - - for (j = 0; j < yLength; j++) { - width = Math.floor((dataY[j] / totalY) * 1000) / 10; - - if (width) { - if (yLength === j) { - width = 100 - totalWidth; + + var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], + barBackgroundColor = config.barBackgroundColor || '#f0f0f0', + dateColor = config.dateColor || '#999999', + dateColorSaturday = config.dateColorSaturday || dateColor, + dateColorSunday = config.dateColorSunday || dateColor, + labelColor = config.labelColor || '#999999', + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, + createCSSGraphBarEl = function () { + return $('
'); + }, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + label = $.map(data, function (d) { + return { + value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), + weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null } - totalWidth = totalWidth + width; - - $bar = $('
'); - $bar.css({ - 'width': width + '%', - 'background-color': barColors[j] + }), + maxY = Math.max.apply(null, dataY) || 1, + yLabel = config.yLabel || dataY, + width, $el, $background, $bar, $count, $date; + + for (var i = this.len; i > 0;) { + i = i - 1; + width = Math.floor((dataY[i] / maxY) * 100) - 15; + $el = createCSSGraphBarEl(); + $background = $el.find('.css-graph-bar-background'); + $background.css({ + 'background-color': barBackgroundColor + }); + + if (config.showDate) { + $date = $el.find('.css-graph-date'); + $date.text(label[i].value).css({ + 'color': dateColor, + 'font-size': dateLabelSize + 'px', + 'line-height': barWidth + 'px' }); - - if (config.showCount) { - $bar.text(dataY[j]); - } - - if (labelClasses && labelClasses[j]) { - $bar.addClass(labelClasses[j]); + if (label[i].weekday === 6) { + $date.addClass('saturday').css({ + 'color': dateColorSaturday + }); + } else if (label[i].weekday === 0) { + $date.addClass('sunday').css({ + 'color': dateColorSunday + }) } - - if (labelColors && labelColors[j]) { + + $el.find('.css-graph-bar-container').css({ + 'margin-left': barMarginLeft + 'px' + }); + } + + $bar = $el.find('.css-graph-bar'); + $bar.css({ + 'width': width + '%', + 'background-color': barColor + }); + $count = $el.find('.css-graph-bar-count'); + $count.text(yLabel[i]).css({ + 'color': labelColor, + 'font-size': labelSize + 'px', + 'line-height': barWidth + 'px' + }); + $el.appendTo(this.$graphEl); + } + + this.$graphEl.appendTo($container); + }; + + ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { + var yLength = config.yLength, + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateColor = config.dateColor || '#999999', + barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + labelColors = config.labelColors, + labelClasses = config.labelClasses, + i, j, + d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; + + for (i = 0; i < this.len; i++) { + d = data[i]; + dataY = []; + totalY = 0; + totalWidth = 0; + for (j = 0; j < yLength; j++) { + dataY.push(d['y' + (j || '')]); + totalY = totalY + parseInt(d['y' + (j || '')], 10); + } + + $barContainer = $('
').appendTo(this.$graphEl); + if (config.showDate && d.x) { + label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); + $date = $('
' + label + '
').appendTo($barContainer); + } + + $el = $('
').appendTo($barContainer); + + if (config.showDate) { + $el.css({ + 'margin-left': barMarginLeft + 'px' + }); + } + + for (j = 0; j < yLength; j++) { + width = Math.floor((dataY[j] / totalY) * 1000) / 10; + + if (width) { + if (yLength === j) { + width = 100 - totalWidth; + } + totalWidth = totalWidth + width; + + $bar = $('
'); $bar.css({ - 'color': labelColors[j] + 'width': width + '%', + 'background-color': barColors[j] }); + + if (config.showCount) { + $bar.text(dataY[j]); + } + + if (labelClasses && labelClasses[j]) { + $bar.addClass(labelClasses[j]); + } + + if (labelColors && labelColors[j]) { + $bar.css({ + 'color': labelColors[j] + }); + } + + $bar.appendTo($el); } - - $bar.appendTo($el); } + + $el.appendTo($barContainer); } - - $el.appendTo($barContainer); - } - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { - var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); - var method = config.type.slice(config.type.lastIndexOf('.') + 1); - cssGraph[method](data, config, range, $container); - return cssGraph; -}; - + this.$graphEl.appendTo($container); + }; + + ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { + var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); + var method = config.type.slice(config.type.lastIndexOf('.') + 1); + cssGraph[method](data, config, range, $container); + return cssGraph; + }; + ChartAPI.Graph.easel = {}; - -ChartAPI.Graph.easel.Base = function (data, config, range, $container) { - this.data = data; - this.config = config; - this.range = range; - this.$container = $container; - if (!window.createjs && typeof window.require === 'function') { - require(['easeljs'], $.proxy(function () { - this.buildCanvas(createjs); - }, this)); - } else { - var width = parseInt((config.width || $container.width()), 10); - - if (width) { - this.buildCanvas(createjs); + + ChartAPI.Graph.easel.Base = function (data, config, range, $container) { + this.data = data; + this.config = config; + this.range = range; + this.$container = $container; + if (!window.createjs && typeof window.require === 'function') { + require(['easeljs'], $.proxy(function () { + this.buildCanvas(createjs); + }, this)); } else { - setTimeout($.proxy(function () { + var width = parseInt((config.width || $container.width()), 10); + + if (width) { this.buildCanvas(createjs); - }, this), 100); - } - } -}; - -ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { - this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; - this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; - - this.$canvas = $('').appendTo(this.$container); - this.canvas = this.$canvas.get(0); - this.canvas.getContext('2d'); - - this.stage = this.graph = new createjs.Stage(this.canvas); - this.stage.update(); - var method = this.config.type.split('.')[1]; - this[method](this.data, this.config); -}; - -ChartAPI.Graph.easel.Base.prototype.remove = function () { - this.$canvas.remove(); -}; - -ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { - var length = data.length, - barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, - barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - barColor = this.convertColor(barColors[0], barColorAlpha), - barMargin = parseInt(config.barMargin, 10) || 10, - barContentWidth = Math.floor(this.width / length), - barWidth = barContentWidth - barMargin, - leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - maxY = Math.max.apply(null, dataY) || 1, - shape, - bar, - x, - y, - barHeight; - - for (var i = 0; i < length; i++) { - shape = new createjs.Shape(); - bar = shape.graphics; - x = i * barContentWidth + leftMargin; - barHeight = Math.floor(dataY[i] / maxY * this.height); - y = this.height - barHeight; - - bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); - this.stage.addChild(shape); - } - this.stage.update(); -}; - -ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { - var length = data.length, - lineWidth = parseInt(config.lineWidth, 10) || 8, - yLength = config.yLength || 1, - lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - lineColorsAlpha = config.chartColorsAlpha || [null], - pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - pointerColorsAlpha = config.pointerColorsAlpha || [null], - pointerRadius = config.pointerRadius || 10, - paddingTop = lineWidth / 2, - paddingBottom = lineWidth / 2, - count = (length - 1) * 2, - moveX = Math.floor(this.width / length) / 2, - paddingLeft = (this.width - (moveX * count)) / 2, - height = this.height, - canvasInnerHeight, - dataYs = [], - dataY, - mapfunc = function (d) { - return parseInt(d['y' + (i || '')], 10); - }; - - if (config.drawPointer) { - paddingBottom = paddingBottom + pointerRadius; - } - - canvasInnerHeight = this.height - (paddingTop + paddingBottom); - - for (var i = 0; i < yLength; i++) { - dataY = $.map(data, mapfunc); - dataYs.push(dataY); - } - - var dataYAll = []; - $.each(dataYs, function (i, dataY) { - dataYAll = dataYAll.concat(dataY); - }); - - var maxY = Math.max.apply(null, dataYAll) || 1, - moveYs = []; - - var generateMoveY = function (dataY) { - var moveY = []; - $.each(dataY, function (i, y) { - if (i > 0) { - var prevY = dataY[i - 1]; - var medium = prevY + Math.floor((y - prevY) / 2); - - medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY = moveY.concat([medium, y]); } else { - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY.push(y); + setTimeout($.proxy(function () { + this.buildCanvas(createjs); + }, this), 100); } - }); - return moveY; + } }; - - $.each(dataYs, function (i, dataY) { - moveYs.push(generateMoveY(dataY)); - }); - - var lineColor, - shapes = [], - lines = [], - x = paddingLeft, - y, - circles = [], - pointerColor; - - for (i = 0; i < yLength; i++) { - lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); - shapes[i] = new createjs.Shape(); - lines[i] = shapes[i].graphics; - y = height - moveYs[i][0]; - lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); - this.stage.addChild(shapes[i]); - if (config.drawPointer) { - pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); - circles[i] = new createjs.Shape(); - circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); - this.stage.addChild(circles[i]); + + ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { + this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; + this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; + + this.$canvas = $('').appendTo(this.$container); + this.canvas = this.$canvas.get(0); + this.canvas.getContext('2d'); + + this.stage = this.graph = new createjs.Stage(this.canvas); + this.stage.update(); + var method = this.config.type.split('.')[1]; + this[method](this.data, this.config); + }; + + ChartAPI.Graph.easel.Base.prototype.remove = function () { + this.$canvas.remove(); + }; + + ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { + var length = data.length, + barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, + barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + barColor = this.convertColor(barColors[0], barColorAlpha), + barMargin = parseInt(config.barMargin, 10) || 10, + barContentWidth = Math.floor(this.width / length), + barWidth = barContentWidth - barMargin, + leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + maxY = Math.max.apply(null, dataY) || 1, + shape, + bar, + x, + y, + barHeight; + + for (var i = 0; i < length; i++) { + shape = new createjs.Shape(); + bar = shape.graphics; + x = i * barContentWidth + leftMargin; + barHeight = Math.floor(dataY[i] / maxY * this.height); + y = this.height - barHeight; + + bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); + this.stage.addChild(shape); } - } - - var stage = this.stage; - - var tick = function (e) { - // if we are on the last frame of animation then remove the tick listener: - count = count - 1; - if (count === 0) { - createjs.Ticker.removeEventListener("tick", tick); + this.stage.update(); + }; + + ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { + var length = data.length, + lineWidth = parseInt(config.lineWidth, 10) || 8, + yLength = config.yLength || 1, + lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + lineColorsAlpha = config.chartColorsAlpha || [null], + pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + pointerColorsAlpha = config.pointerColorsAlpha || [null], + pointerRadius = config.pointerRadius || 10, + paddingTop = lineWidth / 2, + paddingBottom = lineWidth / 2, + count = (length - 1) * 2, + moveX = Math.floor(this.width / length) / 2, + paddingLeft = (this.width - (moveX * count)) / 2, + height = this.height, + canvasInnerHeight, + dataYs = [], + dataY, + mapfunc = function (d) { + return parseInt(d['y' + (i || '')], 10); + }; + + if (config.drawPointer) { + paddingBottom = paddingBottom + pointerRadius; } - - x = x + moveX; - - var moveY; + + canvasInnerHeight = this.height - (paddingTop + paddingBottom); + for (var i = 0; i < yLength; i++) { - moveY = moveYs[i]; - y = height - moveY[moveY.length - count - 1]; - lines[i].lineTo(x, y); + dataY = $.map(data, mapfunc); + dataYs.push(dataY); + } + + var dataYAll = []; + $.each(dataYs, function (i, dataY) { + dataYAll = dataYAll.concat(dataY); + }); + + var maxY = Math.max.apply(null, dataYAll) || 1, + moveYs = []; + + var generateMoveY = function (dataY) { + var moveY = []; + $.each(dataY, function (i, y) { + if (i > 0) { + var prevY = dataY[i - 1]; + var medium = prevY + Math.floor((y - prevY) / 2); + + medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY = moveY.concat([medium, y]); + } else { + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY.push(y); + } + }); + return moveY; + }; + + $.each(dataYs, function (i, dataY) { + moveYs.push(generateMoveY(dataY)); + }); + + var lineColor, + shapes = [], + lines = [], + x = paddingLeft, + y, + circles = [], + pointerColor; + + for (i = 0; i < yLength; i++) { + lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); + shapes[i] = new createjs.Shape(); + lines[i] = shapes[i].graphics; + y = height - moveYs[i][0]; + lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); + this.stage.addChild(shapes[i]); if (config.drawPointer) { - circles[i].x = x; - circles[i].y = Math.max(y, pointerRadius); + pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); + circles[i] = new createjs.Shape(); + circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); + this.stage.addChild(circles[i]); } } - - stage.update(e); + + var stage = this.stage; + + var tick = function (e) { + // if we are on the last frame of animation then remove the tick listener: + count = count - 1; + if (count === 0) { + createjs.Ticker.removeEventListener("tick", tick); + } + + x = x + moveX; + + var moveY; + for (var i = 0; i < yLength; i++) { + moveY = moveYs[i]; + y = height - moveY[moveY.length - count - 1]; + lines[i].lineTo(x, y); + if (config.drawPointer) { + circles[i].x = x; + circles[i].y = Math.max(y, pointerRadius); + } + } + + stage.update(e); + }; + + createjs.Ticker.useRAF = true; + createjs.Ticker.setFPS(30); + createjs.Ticker.addEventListener('tick', tick); }; - - createjs.Ticker.useRAF = true; - createjs.Ticker.setFPS(30); - createjs.Ticker.addEventListener('tick', tick); -}; - -ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { - if (str.indexOf('#') !== -1) { - var r = parseInt(str.substr(1, 2), 16), - g = parseInt(str.substr(3, 2), 16), - b = parseInt(str.substr(5, 2), 16); - - if (alpha) { - str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; + + ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { + if (str.indexOf('#') !== -1) { + var r = parseInt(str.substr(1, 2), 16), + g = parseInt(str.substr(3, 2), 16), + b = parseInt(str.substr(5, 2), 16); + + if (alpha) { + str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; + } else { + str = 'rgb(' + [r, g, b].join(',') + ')'; + } + } else if (str.indexOf('rgb') !== -1) { + // wrap rgb/rgba string + if (str.split(',').length < 4) { + str = 'rgb(' + str + ')'; + } else { + str = 'rgba(' + str + ')'; + } + } + return str; + }; + + ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { + var count = 0; + + var splitData = function (length, data) { + length = length || 1; + var map = $.map(data, function (d) { + var obj = { + x: d.x + }, key, val; + + for (var i = 0; i < length; i++) { + key = 'y' + (i || ''); + val = 'y' + (count + i || ''); + obj[key] = d[val]; + } + return obj; + }); + count = count + length; + return map; + }; + + var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); + + $.each(config.mix, $.proxy(function (index, conf) { + var colors = { + chartColors: chartColors.slice(count, count + conf.yLength) + }; + var partialData = splitData(conf.yLength, data); + conf = $.extend({}, config, colors, conf); + this[conf.type](partialData, conf); + }, this)); + }; + + ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { + if (ChartAPI.Graph.test.canvas()) { + var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); + return easelGraph; } else { - str = 'rgb(' + [r, g, b].join(',') + ')'; + console.warn('EaselJS graph requires for HTML5 Canvas capability'); + $container.trigger('REMOVE'); } - } else if (str.indexOf('rgb') !== -1) { - // wrap rgb/rgba string - if (str.split(',').length < 4) { - str = 'rgb(' + str + ')'; + }; + + ChartAPI.Graph.morris = {}; + + ChartAPI.Graph.morris.Base = function (data, config, range, $container) { + if (!window.Morris && typeof window.require === 'function') { + require(['raphael', 'morris'], $.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this)); } else { - str = 'rgba(' + str + ')'; + var width = config.width || $container.width(); + if (width) { + this.build_(Morris, data, config, range, $container); + } else { + setTimeout($.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this), 100); + } } - } - return str; -}; - -ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { - var count = 0; - - var splitData = function (length, data) { - length = length || 1; - var map = $.map(data, function (d) { - var obj = { - x: d.x - }, key, val; - - for (var i = 0; i < length; i++) { - key = 'y' + (i || ''); - val = 'y' + (count + i || ''); - obj[key] = d[val]; + }; + + ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { + var i, + graphDefaults, graphConfig, + method = config.type.split('.')[1], + yLength = config.yLength, + width = config.width || $container.width() || 300, + height = config.height || $container.height() || 300; + + this.$graphEl = $('
').css({ + 'height': height + 'px', + 'width': width + 'px' + }).prependTo($container); + + config = $.extend({}, config, { + element: config.id, + data: data, + xkey: 'x', + labels: this.getYLabels_(yLength, config.labels), + ykeys: this.getYKeys_(yLength), + ymax: this.getYMax_(data, method, yLength), + ymin: config.ymin || 0, + lineWidth: parseInt(config.lineWidth, 10) || 6, + pointSize: parseInt(config.pointSize, 10) || 6, + smooth: config.smooth || false + }); + + config.barColors = config.barColors || this.getChartColors(config); + config.colors = config.colors || this.getChartColors(config); + config.lineColors = config.lineColors || this.getChartColors(config); + config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); + + config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; + if (!config.pointStrokeColors.length) { + for (i = 0; i < yLength; i++) { + config.pointStrokeColors.push('none'); + } + } + + graphDefaults = { + element: null, + data: null, + xkey: 'x', + labels: [], + ykeys: [], + + // gridDefaults + dateFormat: null, + axes: true, + grid: true, + gridLineColor: '#aaa', + gridStrokeWidth: 0.5, + gridTextColor: '#888', + gridTextSize: 12, + hideHover: false, + hoverCallback: null, + yLabelFormat: null, + numLines: 5, + padding: 25, + parseTime: true, + postUnits: '', + preUnits: '', + ymax: 'auto', + ymin: 'auto 0', + goals: [], + goalStrokeWidth: 1.0, + goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], + events: [], + eventStrokeWidth: 1.0, + eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], + + // Line defaults + lineWidth: 3, + pointSize: 4, + lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + pointWidths: [1], + pointStrokeColors: ['#ffffff'], + pointFillColors: [], + smooth: true, + xLabels: 'auto', + xLabelFormat: null, + xLabelMargin: 50, + continuousLine: true, + + // Bar defaults + barSizeRatio: 0.75, + barGap: 3, + barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + + // Donut defaults + colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], + backgroundColor: '#FFFFFF', + labelColor: '#000000', + formatter: Morris.commas + }; + + graphConfig = {}; + $.each(config, function (key, value) { + if (graphDefaults[key] !== undefined) { + graphConfig[key] = value; } - return obj; }); - count = count + length; - return map; + + // IE8(VML) occured error setting smooth false + if (!ChartAPI.Graph.test.svg) { + graphConfig.smooth = true; + } + + // shows percentage as Y label when graph method is donut + if (method === 'donut') { + var totalCount = this.getTotalCount_(data, i); + + graphConfig.formatter = function (y) { + var str = y = (y + '').replace(/,/g, ''); + if (!config.noCommaOnYLabel) { + while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); + } + var percent = Math.ceil((y / totalCount * 10000)) / 100; + + var ret; + if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { + ret = config.donutsFormatter(str, percent + '%', y); + } else { + ret = str + '(' + percent + '%)'; + } + + return ret; + }; + } + + var M = ({ + 'bar': Morris.Bar, + 'line': Morris.Line, + 'donut': Morris.Donut, + 'area': Morris.Area + })[method]; + + this.graph = new M(graphConfig); }; - - var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - - $.each(config.mix, $.proxy(function (index, conf) { - var colors = { - chartColors: chartColors.slice(count, count + conf.yLength) - }; - var partialData = splitData(conf.yLength, data); - conf = $.extend({}, config, colors, conf); - this[conf.type](partialData, conf); - }, this)); -}; - -ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { - if (ChartAPI.Graph.test.canvas()) { - var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); - return easelGraph; - } else { - console.warn('EaselJS graph requires for HTML5 Canvas capability'); - $container.trigger('REMOVE'); - } -}; - - ChartAPI.Graph.morris = {}; - -ChartAPI.Graph.morris.Base = function (data, config, range, $container) { - if (!window.Morris && typeof window.require === 'function') { - require(['raphael', 'morris'], $.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this)); - } else { - var width = config.width || $container.width(); - if (width) { - this.build_(Morris, data, config, range, $container); + + /** + * get maximum value among the desinated Y data set + * @param {!Array.} graph data to get max Y + * @param {!number} number of set of Y data + * @return {number} return the number of maxY for graph + */ + ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { + var i, maxY, array, sum, key; + + if (method !== 'area') { + array = []; + $.each(data, function (index, value) { + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + array.push(parseInt(value[key], 10)); + } + }); + maxY = Math.max.apply(null, array); + } else { + maxY = Math.max.apply(null, $.map(data, function (value) { + sum = 0; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + sum = sum + parseInt(value[key], 10); + } + return sum; + })); + } + + if (!maxY) { + maxY = 1; + } + + if (maxY % 2 !== 0) { + maxY = maxY + 1; + } + + return maxY; + }; + + ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { + if (!this.chartColors) { + this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); + } + return this.chartColors; + }; + + /** + * return YKeys array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { + var i, array = []; + for (i = 0; i < yLength; i++) { + array.push('y' + (i || '')); + } + return array; + }; + + /** + * return YLables array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { + var i, array = []; + yLabel = yLabel ? yLabel.split(/,/) : []; + for (i = 0; i < yLength; i++) { + array.push((yLabel[i] || 'Count')); + } + return array; + }; + + /** + * caliculate the number of horizental lines in graph + * @param {!number} maximum value among the Y data set. + * @return {number} + */ + ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { + var numlines; + if (maxY >= 18) { + numlines = 9; + } else if (maxY === 2) { + numlines = 3; + } else { + numlines = (maxY / 2) + 1; + + } + numlines = Math.min((numlines || 1), Math.floor(height / 56)); + + return numlines; + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''), + num; + $.each(data, function (i, v) { + num = v[str] || v.value || 0; + if (typeof num === 'string') { + num = parseFloat(num.replace(/,/g, ''), 10); + } + total = total + num; + }); + return total; + }; + + ChartAPI.Graph.morris.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { + if (ChartAPI.Graph.test.vml()) { + var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); + return morrisGraph; } else { - setTimeout($.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this), 100); - } - } -}; - -ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { - var i, - graphDefaults, graphConfig, - method = config.type.split('.')[1], - yLength = config.yLength, - width = config.width || $container.width() || 300, - height = config.height || $container.height() || 300; - - this.$graphEl = $('
').css({ - 'height': height + 'px', - 'width': width + 'px' - }).prependTo($container); - - config = $.extend({}, config, { - element: config.id, - data: data, - xkey: 'x', - labels: this.getYLabels_(yLength, config.labels), - ykeys: this.getYKeys_(yLength), - ymax: this.getYMax_(data, method, yLength), - ymin: config.ymin || 0, - lineWidth: parseInt(config.lineWidth, 10) || 6, - pointSize: parseInt(config.pointSize, 10) || 6, - smooth: config.smooth || false - }); - - config.barColors = config.barColors || this.getChartColors(config); - config.colors = config.colors || this.getChartColors(config); - config.lineColors = config.lineColors || this.getChartColors(config); - config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); - - config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; - if (!config.pointStrokeColors.length) { - for (i = 0; i < yLength; i++) { - config.pointStrokeColors.push('none'); + console.warn('Morris graph requires for SVG/VML capability'); + $container.trigger('REMOVE'); } - } - - graphDefaults = { - element: null, - data: null, - xkey: 'x', - labels: [], - ykeys: [], - - // gridDefaults - dateFormat: null, - axes: true, - grid: true, - gridLineColor: '#aaa', - gridStrokeWidth: 0.5, - gridTextColor: '#888', - gridTextSize: 12, - hideHover: false, - hoverCallback: null, - yLabelFormat: null, - numLines: 5, - padding: 25, - parseTime: true, - postUnits: '', - preUnits: '', - ymax: 'auto', - ymin: 'auto 0', - goals: [], - goalStrokeWidth: 1.0, - goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], - events: [], - eventStrokeWidth: 1.0, - eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], - - // Line defaults - lineWidth: 3, - pointSize: 4, - lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - pointWidths: [1], - pointStrokeColors: ['#ffffff'], - pointFillColors: [], - smooth: true, - xLabels: 'auto', - xLabelFormat: null, - xLabelMargin: 50, - continuousLine: true, - - // Bar defaults - barSizeRatio: 0.75, - barGap: 3, - barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - - // Donut defaults - colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], - backgroundColor: '#FFFFFF', - labelColor: '#000000', - formatter: Morris.commas }; - - graphConfig = {}; - $.each(config, function (key, value) { - if (graphDefaults[key] !== undefined) { - graphConfig[key] = value; + + /** + * create Slider Object + * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this + * $('.container').trigger('APPEND_SLIDER') + * + * @param {object} slider setings + * @param {object} range object + * @param {jQuery} jQuery object of graph/list container element for getting data range + * @param {Array.} array of jQuery object to fire update event + * @param { + Array. < jQuery > + } + array of jQuery object to fire event + for getting amount labels(this event fired when range is timeline) + * @return {object} jQuery object of slider container for chaining + * @constructor + */ + ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { + if (!$.ui || !$.ui.slider) { + throw 'ChartAPI.Slider requied jQuery UI Slider'; } - }); - - // IE8(VML) occured error setting smooth false - if (!ChartAPI.Graph.test.svg) { - graphConfig.smooth = true; - } - - // shows percentage as Y label when graph method is donut - if (method === 'donut') { - var totalCount = this.getTotalCount_(data, i); - - graphConfig.formatter = function (y) { - var str = y = (y + '').replace(/,/g, ''); - if (!config.noCommaOnYLabel) { - while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); + var that = this; + this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + this.range = ChartAPI.Range.generate(range); + this.$dataRangeTarget = $dataRangeTarget; + this.$sliderContainer = $('
'); + + this.eventTargetList = { + update: this.initEventTarget(), + amount: this.initEventTarget() + }; + + $.each(updateTarget, function (i, v) { + that.eventTargetList.update.add(v); + }); + + $.each(amountTarget, function (i, v) { + that.eventTargetList.amount.add(v); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object to attach slider + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('APPEND_TO', function (e, $container) { + that.$container = $container; + that.draw_($container); + return $(this); + }); + + /** + * for building slider UI + * @param {object} jQuery event object + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('BUILD_SLIDER', function () { + that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { + that.buildSlider(dataRange.min, dataRange.max); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object of container for graph|list object to get data range + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { + that.$dataRangeTarget = $target; + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to add event target + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].add($target); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to remove from event targets + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].remove($target); + }); + return $(this); + }); + + + this.$sliderContainer.on('ERASE', function () { + that.erase_(); + return $(this); + }); + + this.$sliderContainer.on('REDRAW', function () { + var $this = $(this); + $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); + return $(this); + }); + + this.$sliderContainer.on('UPDATE', function (e, values) { + that.$slider("values", values); + that.updateSliderAmount(values); + return $(this); + }); + + return this.$sliderContainer; + }; + + /** + * return event target object encapsulated target array + * @return {{add:Function, remove:Function, get:Function}} + */ + ChartAPI.Slider.prototype.initEventTarget = function () { + var target = []; + return { + add: function (newTarget) { + target.push(newTarget); + }, + remove: function (removeTarget) { + target = $.grep(target, function (v) { + return v !== removeTarget; + }); + }, + get: function () { + return target; } - var percent = Math.ceil((y / totalCount * 10000)) / 100; - - var ret; - if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { - ret = config.donutsFormatter(str, percent + '%', y); - } else { - ret = str + '(' + percent + '%)'; + }; + }; + + /** + * build Slider UI + * @param {number} number of the left slider handler position + * @param {number} number of the right slider handler position + * @param {{max:number, min:number}} Object which has max and min values + * @return nothing + */ + ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { + var options, defaultCallback, events = ['change', 'create', 'slide', 'start', 'stop'], that = this; + values = values || [this.range.min, this.range.max]; + + if (this.$slider) { + this.$slider.destroy(); + this.$slider.remove(); + } + options = { + 'range': true, + 'min': sliderMin, + 'max': sliderMax, + 'values': values, + 'slide': function (e, ui) { + that.updateSliderAmount(ui.values, ui); + }, + 'stop': function (e, ui) { + that.updateGraphAndList(ui.values); } - - return ret; }; - } - - var M = ({ - 'bar': Morris.Bar, - 'line': Morris.Line, - 'donut': Morris.Donut, - 'area': Morris.Area - })[method]; - - this.graph = new M(graphConfig); -}; - -/** - * get maximum value among the desinated Y data set - * @param {!Array.} graph data to get max Y - * @param {!number} number of set of Y data - * @return {number} return the number of maxY for graph - */ -ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { - var i, maxY, array, sum, key; - - if (method !== 'area') { - array = []; - $.each(data, function (index, value) { - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - array.push(parseInt(value[key], 10)); + events.forEach(function(value) { + if (that.config.callback[value]) { + defaultCallback = options[value]; + options[value] = function(e, ui) { + that.config.callback[value](e, ui); + if (defaultCallback) { + defaultCallback(e, ui); + } + }; } }); - maxY = Math.max.apply(null, array); - } else { - maxY = Math.max.apply(null, $.map(data, function (value) { - sum = 0; - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - sum = sum + parseInt(value[key], 10); + this.$slider = $('
').slider(options).appendTo(that.$sliderContainer); + + if (!this.config.hideSliderAmount) { + this.$amount = $('
'); + + if (!this.config.appendSliderAmountBottom) { + this.$amount.prependTo(this.$sliderContainer); + } else { + this.$amount.appendTo(this.$sliderContainer); } - return sum; - })); - } - - if (!maxY) { - maxY = 1; - } - - if (maxY % 2 !== 0) { - maxY = maxY + 1; - } - - return maxY; -}; - -ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { - if (!this.chartColors) { - this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - } - return this.chartColors; -}; - -/** - * return YKeys array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { - var i, array = []; - for (i = 0; i < yLength; i++) { - array.push('y' + (i || '')); - } - return array; -}; - -/** - * return YLables array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { - var i, array = []; - yLabel = yLabel ? yLabel.split(/,/) : []; - for (i = 0; i < yLength; i++) { - array.push((yLabel[i] || 'Count')); - } - return array; -}; - -/** - * caliculate the number of horizental lines in graph - * @param {!number} maximum value among the Y data set. - * @return {number} - */ -ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { - var numlines; - if (maxY >= 18) { - numlines = 9; - } else if (maxY === 2) { - numlines = 3; - } else { - numlines = (maxY / 2) + 1; - - } - numlines = Math.min((numlines || 1), Math.floor(height / 56)); - - return numlines; -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''), - num; - $.each(data, function (i, v) { - num = v[str] || v.value || 0; - if (typeof num === 'string') { - num = parseFloat(num.replace(/,/g, ''), 10); - } - total = total + num; - }); - return total; -}; - -ChartAPI.Graph.morris.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { - if (ChartAPI.Graph.test.vml()) { - var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); - return morrisGraph; - } else { - console.warn('Morris graph requires for SVG/VML capability'); - $container.trigger('REMOVE'); - } -}; - - /** - * create Slider Object - * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this - * $('.container').trigger('APPEND_SLIDER') - * - * @param {object} slider setings - * @param {object} range object - * @param {jQuery} jQuery object of graph/list container element for getting data range - * @param {Array.} array of jQuery object to fire update event - * @param { - Array. < jQuery > - } - array of jQuery object to fire event - for getting amount labels(this event fired when range is timeline) - * @return {object} jQuery object of slider container for chaining - * @constructor - */ -ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { - if (!$.ui || !$.ui.slider) { - throw 'ChartAPI.Slider requied jQuery UI Slider'; - } - var that = this; - this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - this.range = ChartAPI.Range.generate(range); - this.$dataRangeTarget = $dataRangeTarget; - this.$sliderContainer = $('
'); - - this.eventTargetList = { - update: this.initEventTarget(), - amount: this.initEventTarget() + + this.updateSliderAmount(values); + } }; - - $.each(updateTarget, function (i, v) { - that.eventTargetList.update.add(v); - }); - - $.each(amountTarget, function (i, v) { - that.eventTargetList.amount.add(v); - }); - + /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object to attach slider - * @return {jQuery} return jQuery object for chaining + * append Slider container to desinated element + * @param {jQuery} + * @return nothing */ - this.$sliderContainer.on('APPEND_TO', function (e, $container) { - that.$container = $container; - that.draw_($container); - return $(this); - }); - + ChartAPI.Slider.prototype.draw_ = function ($container) { + this.$sliderContainer.appendTo($container); + }; + /** - * for building slider UI - * @param {object} jQuery event object - * @return {jQuery} return jQuery object for chaining + * erase Slider by removing the container + * if you want to redraw Slider, trigger 'REDRAW' for the slider container. */ - this.$sliderContainer.on('BUILD_SLIDER', function () { - that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { - that.buildSlider(dataRange.min, dataRange.max); - }); - return $(this); - }); - + ChartAPI.Slider.prototype.erase_ = function () { + if (this.$slider) { + this.$slider.destroy(); + } + this.$sliderContainer.html(''); + }; + /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object of container for graph|list object to get data range - * @return {jQuery} return jQuery object for chaining + * update Slider Amount contents + * @param {Array.} values of slider position + * @param {object} ui object returned from Slider event */ - this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { - that.$dataRangeTarget = $target; - return $(this); - }); - + ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { + var s, e, u, newRange, maxLength = this.range.maxLength, + $amount = this.$amount; + + if (this.range.isTimeline) { + s = ChartAPI.Date.parse(values[0]); + e = ChartAPI.Date.parse(values[1]); + u = this.range.unit; + + newRange = ChartAPI.Range.getLength(s, e, u); + + if (ui && newRange > maxLength) { + if (ui.value === ui.values[0]) { + e = ChartAPI.Date.calcDate(s, maxLength, u, false); + this.$slider.slider('values', 1, e.valueOf()); + } else { + s = ChartAPI.Date.calcDate(e, maxLength, u, true); + this.$slider.slider('values', 0, s.valueOf()); + } + } + + if ($amount) { + $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); + } + } else { + s = values[0]; + e = values[1]; + if ((e - s) > maxLength) { + if (ui.value === ui.values[0]) { + e = maxLength - s; + this.$slider.slider('values', 1, e); + } else { + s = e - maxLength; + this.$slider.slider('values', 0, s); + } + } + if ($amount) { + $.each(this.eventTargetList.amount.get(), function (i, $target) { + $target.trigger('GET_LABEL', [ + [s, e], + function (a) { + $amount.text([a[0], a[1]].join(' - ')); + } + ]); + }); + } + } + }; + /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to add event target - * @return {jQuery} return jQuery object for chaining + * @param {Array.} values of slider handler position + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) */ - this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].add($target); + ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { + $.each(this.eventTargetList.update.get(), function (i, $target) { + $target.trigger('UPDATE', [values, newUnit]); }); - return $(this); - }); - + }; + /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to remove from event targets - * @return {jQuery} return jQuery object for chaining + * update slider handlers position + * @param {number} index of slider handler (left is 0, right is 1) + * @param {number} value of slider handler position */ - this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].remove($target); - }); - return $(this); - }); - - - this.$sliderContainer.on('ERASE', function () { - that.erase_(); - return $(this); - }); - - this.$sliderContainer.on('REDRAW', function () { - var $this = $(this); - $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); - return $(this); - }); - - this.$sliderContainer.on('UPDATE', function (e, values) { - that.$slider("values", values); - that.updateSliderAmount(values); - return $(this); - }); - - return this.$sliderContainer; -}; - -/** - * return event target object encapsulated target array - * @return {{add:Function, remove:Function, get:Function}} - */ -ChartAPI.Slider.prototype.initEventTarget = function () { - var target = []; - return { - add: function (newTarget) { - target.push(newTarget); - }, - remove: function (removeTarget) { - target = $.grep(target, function (v) { - return v !== removeTarget; - }); - }, - get: function () { - return target; - } + ChartAPI.Slider.prototype.update_ = function (index, value) { + this.$slider.slider('values', index, value); }; -}; - -/** - * build Slider UI - * @param {number} number of the left slider handler position - * @param {number} number of the right slider handler position - * @param {{max:number, min:number}} Object which has max and min values - * @return nothing - */ -ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { - var that = this; - values = values || [this.range.min, this.range.max]; - - if (this.$slider) { - this.$slider.destroy(); - this.$slider.remove(); - } - this.$slider = $('
').slider({ - 'range': true, - 'min': sliderMin, - 'max': sliderMax, - 'values': values, - 'slide': function (e, ui) { - that.updateSliderAmount(ui.values, ui); - }, - 'stop': function (e, ui) { - that.updateGraphAndList(ui.values); - } - }).appendTo(that.$sliderContainer); - - if (!this.config.hideSliderAmount) { - this.$amount = $('
'); - - if (!this.config.appendSliderAmountBottom) { - this.$amount.prependTo(this.$sliderContainer); + + /** + * create List Object + * If you want to draw list, fire APPEND_LIST event for its container Element like this + * $('.container').trigger('APPEND_LIST') + * + * @param {object} list setings + * @param {object} range object + * @return {jQuery} return jQuery object for chaining + * @constructor + */ + ChartAPI.List = function (config, range) { + this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + + this.config.staticPath = this.config.staticPath || ''; + + if (this.config.data && typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); } else { - this.$amount.appendTo(this.$sliderContainer); - } - - this.updateSliderAmount(values); - } -}; - -/** - * append Slider container to desinated element - * @param {jQuery} - * @return nothing - */ -ChartAPI.Slider.prototype.draw_ = function ($container) { - this.$sliderContainer.appendTo($container); -}; - -/** - * erase Slider by removing the container - * if you want to redraw Slider, trigger 'REDRAW' for the slider container. - */ -ChartAPI.Slider.prototype.erase_ = function () { - if (this.$slider) { - this.$slider.destroy(); - } - this.$sliderContainer.html(''); -}; - -/** - * update Slider Amount contents - * @param {Array.} values of slider position - * @param {object} ui object returned from Slider event - */ -ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { - var s, e, u, newRange, maxLength = this.range.maxLength, - $amount = this.$amount; - - if (this.range.isTimeline) { - s = ChartAPI.Date.parse(values[0]); - e = ChartAPI.Date.parse(values[1]); - u = this.range.unit; - - newRange = ChartAPI.Range.getLength(s, e, u); - - if (ui && newRange > maxLength) { - if (ui.value === ui.values[0]) { - e = ChartAPI.Date.calcDate(s, maxLength, u, false); - this.$slider.slider('values', 1, e.valueOf()); - } else { - s = ChartAPI.Date.calcDate(e, maxLength, u, true); - this.$slider.slider('values', 0, s.valueOf()); - } + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); } - - if ($amount) { - $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); - } - } else { - s = values[0]; - e = values[1]; - if ((e - s) > maxLength) { - if (ui.value === ui.values[0]) { - e = maxLength - s; - this.$slider.slider('values', 1, e); + + if (this.config.template) { + if (window.require && typeof require === 'function') { + var templateType = this.config.type || 'text'; + this.template_ = $.Deferred(); + require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { + this.template_.resolve(template); + }, this)); } else { - s = e - maxLength; - this.$slider.slider('values', 0, s); + this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); } - } - if ($amount) { - $.each(this.eventTargetList.amount.get(), function (i, $target) { - $target.trigger('GET_LABEL', [ - [s, e], - function (a) { - $amount.text([a[0], a[1]].join(' - ')); - } - ]); - }); - } - } -}; - -/** - * @param {Array.} values of slider handler position - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { - $.each(this.eventTargetList.update.get(), function (i, $target) { - $target.trigger('UPDATE', [values, newUnit]); - }); -}; - -/** - * update slider handlers position - * @param {number} index of slider handler (left is 0, right is 1) - * @param {number} value of slider handler position - */ -ChartAPI.Slider.prototype.update_ = function (index, value) { - this.$slider.slider('values', index, value); -}; - - /** - * create List Object - * If you want to draw list, fire APPEND_LIST event for its container Element like this - * $('.container').trigger('APPEND_LIST') - * - * @param {object} list setings - * @param {object} range object - * @return {jQuery} return jQuery object for chaining - * @constructor - */ -ChartAPI.List = function (config, range) { - this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - - this.config.staticPath = this.config.staticPath || ''; - - if (this.config.data && typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - if (this.config.template) { - if (window.require && typeof require === 'function') { - var templateType = this.config.type || 'text'; - this.template_ = $.Deferred(); - require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { - this.template_.resolve(template); + + this.range = ChartAPI.Range.generate(range); + + this.$listContainer = $('
'); + + this.$listContainer.on('UPDATE', $.proxy(function (e, range) { + this.update_(range); }, this)); - } else { - this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); - } - - this.range = ChartAPI.Range.generate(range); - - this.$listContainer = $('
'); - - this.$listContainer.on('UPDATE', $.proxy(function (e, range) { - this.update_(range); - }, this)); - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback - */ - this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this)); + return this.$listContainer; }, this)); - return this.$listContainer; - }, this)); - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback - */ - - this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + + this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this)); + return this.$listContainer; }, this)); - return this.$listContainer; - }, this)); - - /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining - */ - - this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { - this.$listContainer.appendTo($container); - this.getData($.proxy(function (data) { - this.draw_(data); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + + this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { + this.$listContainer.appendTo($container); + this.getData($.proxy(function (data) { + this.draw_(data); + }, this)); + return this.$listContainer; }, this)); + return this.$listContainer; - }, this)); - - return this.$listContainer; - } -}; - -/** - * get list data JSON - * @param {!Function} callback function which recieve jSON data - */ -ChartAPI.List.prototype.getData = function (callback) { - if (this.config.data) { - ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); - } else { - callback(); - } -}; - -/** - * get list template string - * @param {!Function} callback function which recieve template string - */ -ChartAPI.List.prototype.getTemplate = function (callback) { - ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); -}; - -/** - * generate html using template string - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.draw_ = function (data) { - var that = this; - this.getTemplate(function (templateString) { - data = that.createListData(data); - that.$listContainer.html(_.template(templateString, data)); - }); -}; - -/** - * provide x label data for slider - * @param {!Array.} array of index to get data - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * @param {!object} list JSON data - * @return {object} filtered data for using list template - */ -ChartAPI.List.prototype.createListData = function (data) { - var filteredData = ''; - if (data) { - if (this.range.isTimeline) { - filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); + } + }; + + /** + * get list data JSON + * @param {!Function} callback function which recieve jSON data + */ + ChartAPI.List.prototype.getData = function (callback) { + if (this.config.data) { + ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + callback(); } - } - return { - 'data': filteredData }; -}; - -/** - * update list template - * @param {=Array.} array of number - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.List.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - unit = unit || this.range.unit; - this.range = ChartAPI.Range.generate({ - 'start': newRange[0] || this.range.start, - 'end': newRange[1] || this.range.end, - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': unit, - 'dataType': this.range.dataType - }); - this.getData(function (data) { - that.draw_(data); - }); -}; - + + /** + * get list template string + * @param {!Function} callback function which recieve template string + */ + ChartAPI.List.prototype.getTemplate = function (callback) { + ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); + }; + /** - * builder funciton. return jQuery object for chaining and triggering events - * @return {jQuery} - */ -ChartAPI.Build = function (settings) { - var $container; - if (typeof settings === 'string' && (/\.json$/).test(settings)) { - $container = $('
'); - ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { - settings.$container = $container; - ChartAPI.Build_(settings).trigger('APPEND'); + * generate html using template string + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.draw_ = function (data) { + var that = this; + this.getTemplate(function (templateString) { + data = that.createListData(data); + that.$listContainer.html(_.template(templateString, data)); }); - } else { - $container = ChartAPI.Build_(settings).trigger('APPEND'); - } - return $container; -}; - -/** - * internal method for building graph|slider|list objects - * @param {Object} settings - * @param {=jQuery} jQuery object to attach graph|slider|list object - */ -ChartAPI.Build_ = function (settings) { - var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; - - $container = settings.$container || $('
'); - - sliderUpdateTarget = []; - - if (settings.graph) { - $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); - sliderUpdateTarget.push($graphContainer); - } - - if (settings.list) { - $listContainer = new ChartAPI.List(settings.list, settings.range); - if (settings.list.data) { - sliderUpdateTarget.push($listContainer); + }; + + /** + * provide x label data for slider + * @param {!Array.} array of index to get data + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * @param {!object} list JSON data + * @return {object} filtered data for using list template + */ + ChartAPI.List.prototype.createListData = function (data) { + var filteredData = ''; + if (data) { + if (this.range.isTimeline) { + filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } } - } - - if (settings.graph && settings.graph.type !== 'donut') { - dataRangeTarget = $graphContainer; - sliderAmountTarget = [$graphContainer]; - } else { - dataRangeTarget = $listContainer; - sliderAmountTarget = [$listContainer]; - } - - var isSmartPhone = function () { - var userAgent = window.navigator ? window.navigator.userAgent : ''; - return (/android|iphone|ipod|ipad/i).test(userAgent); + return { + 'data': filteredData + }; }; - - if (settings.slider && (settings.slider.force || !isSmartPhone())) { - $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); - } - - $container.on('APPEND', function () { - if ($graphContainer) { - $graphContainer.trigger('APPEND_TO', [$container]); + + /** + * update list template + * @param {=Array.} array of number + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.List.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + unit = unit || this.range.unit; + this.range = ChartAPI.Range.generate({ + 'start': newRange[0] || this.range.start, + 'end': newRange[1] || this.range.end, + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': unit, + 'dataType': this.range.dataType + }); + this.getData(function (data) { + that.draw_(data); + }); + }; + + /** + * builder funciton. return jQuery object for chaining and triggering events + * @return {jQuery} + */ + ChartAPI.Build = function (settings) { + var $container; + if (typeof settings === 'string' && (/\.json$/).test(settings)) { + $container = $('
'); + ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { + settings.$container = $container; + ChartAPI.Build_(settings).trigger('APPEND'); + }); + } else { + $container = ChartAPI.Build_(settings).trigger('APPEND'); + } + return $container; + }; + + /** + * internal method for building graph|slider|list objects + * @param {Object} settings + * @param {=jQuery} jQuery object to attach graph|slider|list object + */ + ChartAPI.Build_ = function (settings) { + var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; + + $container = settings.$container || $('
'); + + sliderUpdateTarget = []; + + if (settings.graph) { + $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); + sliderUpdateTarget.push($graphContainer); } - if ($sliderContainer) { - $sliderContainer.trigger('BUILD_SLIDER') - .trigger('APPEND_TO', [$container]); + + if (settings.list) { + $listContainer = new ChartAPI.List(settings.list, settings.range); + if (settings.list.data) { + sliderUpdateTarget.push($listContainer); + } } - if ($listContainer) { - $listContainer.trigger('APPEND_TO', [$container]); + + if (settings.graph && settings.graph.type !== 'donut') { + dataRangeTarget = $graphContainer; + sliderAmountTarget = [$graphContainer]; + } else { + dataRangeTarget = $listContainer; + sliderAmountTarget = [$listContainer]; } - }); - - $container.on('GET_CONTAINER', function (e, type, callback) { - callback({ - 'graph': $graphContainer, - 'slider': $sliderContainer, - 'list': $listContainer - }[type]); - }); - - return $container; -}; - + + var isSmartPhone = function () { + var userAgent = window.navigator ? window.navigator.userAgent : ''; + return (/android|iphone|ipod|ipad/i).test(userAgent); + }; + + if (settings.slider && (settings.slider.force || !isSmartPhone())) { + $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); + } + + $container.on('APPEND', function () { + if ($graphContainer) { + $graphContainer.trigger('APPEND_TO', [$container]); + } + if ($sliderContainer) { + $sliderContainer.trigger('BUILD_SLIDER') + .trigger('APPEND_TO', [$container]); + } + if ($listContainer) { + $listContainer.trigger('APPEND_TO', [$container]); + } + }); + + $container.on('GET_CONTAINER', function (e, type, callback) { + callback({ + 'graph': $graphContainer, + 'slider': $sliderContainer, + 'list': $listContainer + }[type]); + }); + + return $container; + }; + return ChartAPI; })(this, jQuery); diff --git a/lib/core/mtchart.core.min.js b/lib/core/mtchart.core.min.js index bbf96b0..cf112f0 100644 --- a/lib/core/mtchart.core.min.js +++ b/lib/core/mtchart.core.min.js @@ -1,2 +1,2 @@ -var ChartAPI=function(t,e){"use strict";var a=e,r={},n=t.MT=t.MT||{};n.ChartAPI=r;r.Data={};r.Data.getData=function(t,e,r,n){var i,o,s,h;t&&t.done(function(t){i||(i="string"==typeof t?""+t:a.isArray(t)?a.map(t,function(t){return a.extend({},t)}):a.extend({},t));r(i)}).fail(function(t){o={404:"Data is not found",403:"Data is forbidden to access"};s="Some error occured in the data fetching process";h=t.status?"error-"+t.status:"error-unknown";n&&(n.$errormsg=a('
'+(o[t.status]||s)+"
").appendTo(e))}).always(function(){n&&n.$progress&&n.$progress.parent().length>0&&n.$progress.remove()}).progress(function(){!n||n.$progress&&0!==n.$progress.parent().length||(n.$progress=a('
fetching data...
').appendTo(e))})};r.Data.filterData=function(t,e,n,i,o,s){var h,l={};o=o||1;a.each(t,function(t,c){var p,u;p=r.Date.parse(c.x);if(p&&p>=n&&e>=p)if(s){u=r.Date.createId(p,"daily");l[u]=c}else{"weekly"===i&&(p=r.Date.getWeekStartday(p));u=r.Date.createId(p,i);if(l[u])for(t=0;o>t;t++){h=t?"y"+t:"y";l[u][h]=parseInt(l[u][h],10)+parseInt(c[h],10)}else l[u]=a.extend({},c)}});return l};r.Date={};r.Date.getWeekStartday=function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay())};r.Date.zeroPadArray=function(t,e){var r;({yearly:function(){r=[t.getFullYear()]},monthly:function(){r=[t.getFullYear(),t.getMonth()+1]},quarter:function(){r=[t.getFullYear(),t.getMonth()+1]},weekly:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate()-t.getDay()]},daily:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate()]},hourly:function(){r=[t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours()]}})[e]();return a.map(r,function(t){t=""+t;return 1===t.length?"0"+t:t})};r.Date.createId=function(t,e){return r.Date.zeroPadArray(t,e).join("")};r.Date.createXLabel=function(t,e){var a,n,i=r.Date.zeroPadArray(t,e);if("hourly"===e){a=i.pop();n=i.join("-")+" "+a+":00"}else n=i.join("-");return n};r.Date.parse=function(t){var e;e=!t||t instanceof Date?t||null:"number"==typeof t?new Date(t):new Date(Date.parse(""+t));if(e&&/NaN|Invalid Date/.test(""+e)){e=t.replace(/-/g,"/").split("+")[0];if(1===e.split("/").length){e=t.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/);e=[e[1],e[2],e[3]].join("/")}2===e.split("/").length&&(e+="/01");e=a.each(e.split("/"),function(t,e){return 1===e.length?"0"+e:e}).join("/");e=new Date(Date.parse(e))}return e};r.Date.calcDate=function(t,e,a,r){var n,i,o,s;n=t.getFullYear();i=t.getMonth();o=t.getDate();s=0;e-=1;r=r?-1:1;({yearly:function(){n+=r*e},monthly:function(){i+=r*e},quarter:function(){i+=4*r*e},weekly:function(){o=o+7*r*e-t.getDay()},daily:function(){o+=r*e},hourly:function(){s=t.getHours()+r*e}})[a]();return new Date(n,i,o,s)};r.Range={};r.Range.factory=function(t){var e;t=t||{};t.maxLength=t.maxLength||90;t.dataType=t.dataType||"timeline";t.isTimeline=r.Range.isTimeline(t.dataType);e=t.isTimeline?r.Range.calcDate:r.Range.calcNum;return e(t.start,t.end,t.length,t.maxLength,t.unit,t.dataType,t.autoSized)};r.Range.generate=r.Range.factory;r.Range.isTimeline=function(t){return!t||"timeline"===t};r.Range.calcDate=function(t,e,n,i,o,s,h){o=o||"monthly";n=n||("hourly"===o?24:10);if(h){var l=a(window).width();i=Math.min(Math.ceil(.021875*l),i);n=i}t=r.Date.parse(t);e=r.Date.parse(e);t||e||(e=r.Range.getEndDate(new Date,o));t||(t=r.Range.getStartDate(r.Date.calcDate(e,n,o,!0),o));e||(e=r.Range.getEndDate(r.Date.calcDate(t,n,o,!1),o));e>new Date&&(e=new Date);t>e&&(t=e);n=r.Range.getLength(t,e,o);if(n>i){n=i;t=r.Date.calcDate(e,n,o,!0)}return{start:t,end:e,length:n,maxLength:i,unit:o,dataType:s,max:r.Range.getEndDate(e,o),min:r.Range.getStartDate(t,o),isTimeline:!0}};r.Range.calcNum=function(t,e,r,n,i,o,s){r=r||10;if(s){var h=a(window).width();n=Math.min(Math.ceil(.021875*h),n);r=Math.min(r,n)}if(!t&&!e){t=0;e=r-1}t=parseInt(t,10)||(0===t?0:null);e=parseInt(e,10)||(0===e?0:null);if(null===t){t=e-r;0>t&&(t=0)}null===e&&(e=t+r);t>e&&(t=e);r=e-t+1;if(r>n){r=n;t=e-n}return{start:t,end:e,length:r,maxLength:n,dataType:o,unit:null,max:e,min:t,isTimeline:!1}};r.Range.getStartDate=function(t,e){var a,r=t.getFullYear(),n=t.getMonth(),i=t.getDate();({yearly:function(){a=new Date(r,0,1,0,0,0)},monthly:function(){a=new Date(r,n,1,0,0,0)},quarter:function(){a=new Date(r,n,1,0,0,0)},weekly:function(){a=new Date(r,n,i-t.getDay(),0,0,0)},daily:function(){a=new Date(r,n,i,0,0,0)},hourly:function(){a=new Date(r,n,i,t.getHours(),0,0)}})[e]();return a};r.Range.getEndDate=function(t,e){var a,r=t.getFullYear(),n=t.getMonth(),i=t.getDate();({yearly:function(){a=new Date(r,11,31,23,59,59)},monthly:function(){a=new Date(new Date(r,n+1,1,0,0,0).valueOf()-1)},quarter:function(){a=new Date(new Date(r,n+1,1,0,0,0).valueOf()-1)},weekly:function(){a=new Date(r,n,i-t.getDay()+6,23,59,59)},daily:function(){a=new Date(r,n,i,23,59,59)},hourly:function(){a=new Date(r,n,i,t.getHours(),0,0)}})[e]();return new Date>a?a:new Date};r.Range.getNextDate=function(t,e,a,r){var n,i=t.getFullYear(),o=t.getMonth(),s=t.getDate();({yearly:function(t){n=new Date(i+t,0,1)},monthly:function(t){n=new Date(i,o+t,1)},quarter:function(t){n=new Date(i,o+4*t,1)},weekly:function(e){n=new Date(i,o,s+7*e-t.getDay())},daily:function(t){n=new Date(i,o,s+t)},hourly:function(e){n=new Date(i,o,s,t.getHours()+e)}})[r](a);return e>n?n:null};r.Range.getDataRange=function(t,e){var n,i,o;if(e){n=a.map(t,function(t){return r.Date.parse(t.x).valueOf()});i=Math.max.apply(null,n);o=Math.min.apply(null,n)}else{o=0;i=t.length-1}return{max:i,min:o}};r.Range.getLength=function(t,e,a){var n;({yearly:function(){n=Math.ceil(e.getFullYear()-t.getFullYear())},monthly:function(){n=Math.ceil(12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))},quarter:function(){n=Math.ceil((12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))/4)},weekly:function(){n=Math.ceil((r.Date.getWeekStartday(e)-r.Date.getWeekStartday(t))/6048e5)},daily:function(){n=Math.ceil((e-t)/864e5)},hourly:function(){n=Math.ceil((e-t)/36e5)}})[a]();return n>0?n+1:1};r.Graph=function(t,a){this.config=e.extend({type:"morris.bar",staticPath:"",data:"graph.json"},t);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=r.Range.generate(a);if("string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=e.Deferred();this.getData(e.proxy(function(t){this.graphData[this.range.unit].resolve(this.generateGraphData(t))},this));this.$graphContainer=e('
');this.$graphContainer.on("UPDATE",e.proxy(function(t,a,r){this.update_(a,r);return e(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",e.proxy(function(){this.remove_()},this));var n=e(window).width();this.updateFunc=e.proxy(function(){if(n&&n!==e(window).width()){n=e(window).width();this.update_()}},this);t.autoResize&&e(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",e.proxy(function(t,a){e.proxy(this.getData(e.proxy(function(t){a(r.Range.getDataRange(t,this.range.isTimeline))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",e.proxy(function(t,a,r){e.proxy(this.getData(e.proxy(function(t){r(this.getDataLabelByIndex(a,t))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",e.proxy(function(t,a){this.$graphContainer.appendTo(a);this.graphData[this.range.unit].done(e.proxy(function(t){var a;a=this.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.start<=t.timestamp&&t.timestamp<=this.range.end},this)):t.slice(this.range.min,this.range.max+1);this.draw_(a)},this));return e(this.$graphContainer)},this));return this.$graphContainer};r.Graph.prototype.getData=function(t){r.Data.getData(this.origData_,this.$graphContainer,t,this)};r.Graph.prototype.getDataLabelByIndex=function(t,a){var r=this.config.dataLabel||"x";return e.map(t,function(t){return a[t][r]})};r.Graph.prototype.getTotalCount_=function(t,a){var r=0,n="y"+(a||"");e.each(t,function(t,e){r+=parseInt(e[n]||e.value||0,10)});return r};r.Graph.prototype.getDelta_=function(t,e){var a,r,n,i,o=t.length;i="y"+(e||"");a=t[o-1];r=t[o-2];n=r&&a&&r[i]?a[i]-r[i]:a[i];return void 0===n?"":n};r.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};r.Graph.getChartColors=function(t,e){var a={reverse:function(t){return t.reverse()},shuffle:function(t){var e,a,r,n;r=t.length;for(e=0;r>e;e++){a=Math.floor(Math.random()*r);n=t[e];t[e]=t[a];t[a]=n}return t},def:function(t){return t}};return a[e||"def"](t||r.Graph.presetColors())};r.Graph.cachedChartColors={};r.Graph.getCachedChartColors=function(t,e,a){return r.Graph.cachedChartColors[t]=r.Graph.cachedChartColors[t]||r.Graph.getChartColors(e,a)};r.Graph.prototype.draw_=function(t){var a=this.config.type.split("."),n=a[0],i=a[1],o=this.config;if(o.label)if(this.labelTemplate)this.generateLabel(this.labelTemplate);else if(o.label.template){var s=o.label.template;if(window.require&&"function"==typeof require){var h=o.label.type;require([h+"!"+o.staticPath+s],e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}else{var l=e.get(o.staticPath+s,"text");r.Data.getData(l,this.$graphContainer,e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}}else{this.labelTemplate='';this.generateLabel(this.labelTemplate)}if(o.fallback&&o.fallback.test&&!r.Graph.test[o.fallback.test]()){a=o.fallback.type.split(".");n=a[0];i=a[1];o=e.extend(o,o.fallback)}o.chartColors&&"string"==typeof o.chartColors&&(o.chartColors=o.chartColors.split(","));this.graphObject=r.Graph[n][i](t,o,this.range,this.$graphContainer)};r.Graph.test={};r.Graph.test.canvas=function(){var t=document.createElement("canvas");return t.getContext&&t.getContext("2d")};r.Graph.test.svg=function(){var t={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(t.svg,"svg").createSVGRect};r.Graph.test.vml=function(){var t,e=r.Graph.test.svg();if(!e){var a=document.body.appendChild(document.createElement("div"));a.innerHTML='';var n=a.firstChild;n.style.behavior="url(#default#VML)";t=n?"object"==typeof n.adj:!0;a.parentNode.removeChild(a)}return e||t};r.Graph.prototype.generateLabel=function(t){var a,n=this.config.label.template&&this.config.label.data?this.config.label.data:{},i=this.config.label.yLength||this.config.yLength,o=e.proxy(function(){this.labels=new r.Graph.Labels(this.$graphContainer,i,t);this.getData(e.proxy(function(t){for(var e=0;i>e;e++){this.config.label.hideTotalCount||this.labels.getTotalObject(e).createTotalCount(this.getTotalCount_(t,e));!this.config.label.hideDeltaCount&&this.range.isTimeline&&this.labels.getTotalObject(e).createDeltaCount(this.getDelta_(t,e))}},this))},this);if(n&&"string"==typeof n)a=e.getJSON(this.config.staticPath+n);else{a=e.Deferred();a.resolve(n)}a.done(function(e){if(t&&"function"==typeof t){t=t(e);o()}else if(window._){t=_.template(t,e);o()}else{t=t;o()}})};r.Graph.prototype.update_=function(t,a){var n=this;t=t||[];this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.range=r.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:a||this.range.unit,dataType:this.range.dataType,autoSized:this.range.autoSized});this.graphData[this.range.unit].done(e.proxy(function(t){var a;a=n.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.min<=t.timestamp&&t.timestamp<=this.range.max},this)):t.slice(this.range.min,this.range.max+1);this.draw_(a)},this))};r.Graph.prototype.remove_=function(){this.config.autoResize&&e(window).off("orientationchange debouncedresize",this.updateFunc);this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.$graphContainer.remove()};r.Graph.prototype.generateGraphData=function(t){var a,n,i,o,s,h,l,c=this.range,p=c.start,u=c.end,g=c.unit,d=c.length,f=[],y=this.config.yLength||1;if(this.range.isTimeline){var m=r.Range.getDataRange(t,this.range.isTimeline);p=new Date(Math.min(this.range.min,m.min));u=new Date(Math.max(this.range.max,m.max));d=r.Range.getLength(p,u,g);s=r.Data.filterData(t,m.max,m.min,g,y);for(a=0;d>a;a++){i=r.Range.getNextDate(p,u,a,g);if(!i)break;o=r.Date.createId(i,g);h={timestamp:i.valueOf(),x:r.Date.createXLabel(i,g)};for(n=0;y>n;n++){l="y"+(n||"");h[l]=s[o]?s[o][l]||0:0}f.push(h)}}else f=t;"morris.donut"===this.config.type&&e.each(f,function(t,a){e.extend(a,{label:a.xLabel||a.x,value:a.y})});return f};r.Graph.Labels=function(t,a,n){var i,o;this.$labelContainer=e('
');n&&e('
').html(n).prependTo(this.$labelContainer);this.totals={};for(i=0;a>i;i++){o="y"+(i||"");this.totals[o]=new r.Graph.Labels.Total(this.$labelContainer,i)}this.$labelContainer.appendTo(t)};r.Graph.Labels.prototype.remove=function(){this.$labelContainer.remove()};r.Graph.Labels.prototype.getTotalObject=function(t){return this.totals["y"+(t||"")]};r.Graph.Labels.Total=function(t,e){this.index=e;this.$totalContainer=a('
').appendTo(t)};r.Graph.Labels.Total.prototype.createTotalCount=function(t){a('"+t+" ").appendTo(this.$totalContainer)};r.Graph.Labels.Total.prototype.createDeltaCount=function(t){var e=t?0>t?"minus ":"plus ":"zero ";a('('+t+")").appendTo(this.$totalContainer)};r.Graph.css={};r.Graph.css.Base=function(t,a){this.len=t.length;this.$graphEl=e('
')};r.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};r.Graph.css.Base.prototype.horizontalBar=function(t,a,n,i){a.width&&this.$graphEl.css({width:a.width,"max-width":"100%",margin:"0 auto"});for(var o,s,h,l,c,p,u=a.barColor||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod)[1],g=a.barBackgroundColor||"#f0f0f0",d=a.dateColor||"#999999",f=a.dateColorSaturday||d,y=a.dateColorSunday||d,m=a.labelColor||"#999999",v=parseInt(a.barWidth,10)||30,D=parseInt(a.barMarginLeft,10)||30,C=parseInt(a.barInterval,10)||5,b=parseInt(a.labelSize,10)||.45*v,x=parseInt(a.dateLabelSize,10)||b,w=function(){return e('
')},T=e.map(t,function(t){return parseInt(t.y,10)}),L=e.map(t,function(t){return{value:""+parseInt(t.x.substr(t.x.lastIndexOf("-")+1),10),weekday:r.Date.parse(t.x)?r.Date.parse(t.x).getDay():null}}),$=Math.max.apply(null,T)||1,G=a.yLabel||T,M=this.len;M>0;){M-=1;o=Math.floor(100*(T[M]/$))-15;s=w();h=s.find(".css-graph-bar-background");h.css({"background-color":g});if(a.showDate){p=s.find(".css-graph-date");p.text(L[M].value).css({color:d,"font-size":x+"px","line-height":v+"px"});6===L[M].weekday?p.addClass("saturday").css({color:f}):0===L[M].weekday&&p.addClass("sunday").css({color:y});s.find(".css-graph-bar-container").css({"margin-left":D+"px"})}l=s.find(".css-graph-bar");l.css({width:o+"%","background-color":u});c=s.find(".css-graph-bar-count");c.text(G[M]).css({color:m,"font-size":b+"px","line-height":v+"px"});s.appendTo(this.$graphEl)}this.$graphEl.appendTo(i)};r.Graph.css.Base.prototype.ratioHorizontalBar=function(t,a,n,i){var o,s,h,l,c,p,u,g,d,f,y,m,v=a.yLength,D=parseInt(a.barWidth,10)||30,C=parseInt(a.barMarginLeft,10)||30,b=parseInt(a.barInterval,10)||5,x=parseInt(a.labelSize,10)||.45*D,w=a.dateColor||"#999999",T=a.barColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),L=a.labelColors,$=a.labelClasses;for(o=0;this.len>o;o++){h=t[o];l=[];c=0;m=0;for(s=0;v>s;s++){l.push(h["y"+(s||"")]);c+=parseInt(h["y"+(s||"")],10)}p=e('
').appendTo(this.$graphEl);if(a.showDate&&h.x){d=""+parseInt(h.x.substr(h.x.lastIndexOf("-")+1),10);f=e('
'+d+"
").appendTo(p)}u=e('
').appendTo(p);a.showDate&&u.css({"margin-left":C+"px"});for(s=0;v>s;s++){y=Math.floor(1e3*(l[s]/c))/10;if(y){v===s&&(y=100-m);m+=y;g=e('
');g.css({width:y+"%","background-color":T[s]});a.showCount&&g.text(l[s]);$&&$[s]&&g.addClass($[s]);L&&L[s]&&g.css({color:L[s]});g.appendTo(u)}}u.appendTo(p)}this.$graphEl.appendTo(i)};r.Graph.css.horizontalBar=r.Graph.css.ratioHorizontalBar=function(t,e,a,n){var i=new r.Graph.css.Base(t,e,a,n),o=e.type.slice(e.type.lastIndexOf(".")+1);i[o](t,e,a,n);return i};r.Graph.easel={};r.Graph.easel.Base=function(t,a,r,n){this.data=t;this.config=a;this.range=r;this.$container=n;if(window.createjs||"function"!=typeof window.require){var i=parseInt(a.width||n.width(),10);i?this.buildCanvas(createjs):setTimeout(e.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],e.proxy(function(){this.buildCanvas(createjs)},this))};r.Graph.easel.Base.prototype.buildCanvas=function(t){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=e('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new t.Stage(this.canvas);this.stage.update();var a=this.config.type.split(".")[1];this[a](this.data,this.config)};r.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};r.Graph.easel.Base.prototype.bar=function(t,a){for(var n,i,o,s,h,l=t.length,c=a.chartColorsAlpha?a.chartColorsAlpha[0]:1,p=a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),u=this.convertColor(p[0],c),g=parseInt(a.barMargin,10)||10,d=Math.floor(this.width/l),f=d-g,y=Math.floor((this.width-d*l)/2)+g/2,m=e.map(t,function(t){return parseInt(t.y,10)}),v=Math.max.apply(null,m)||1,D=0;l>D;D++){n=new createjs.Shape;i=n.graphics;o=D*d+y;h=Math.floor(m[D]/v*this.height);s=this.height-h;i.beginFill(u).drawRect(o,s,f,h);this.stage.addChild(n)}this.stage.update()};r.Graph.easel.Base.prototype.motionLine=function(t,a){var n,i,o=t.length,s=parseInt(a.lineWidth,10)||8,h=a.yLength||1,l=a.lineColors||a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),c=a.chartColorsAlpha||[null],p=a.pointerColors||a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod),u=a.pointerColorsAlpha||[null],g=a.pointerRadius||10,d=s/2,f=s/2,y=2*(o-1),m=Math.floor(this.width/o)/2,v=(this.width-m*y)/2,D=this.height,C=[],b=function(t){return parseInt(t["y"+(x||"")],10)};a.drawPointer&&(f+=g);n=this.height-(d+f);for(var x=0;h>x;x++){i=e.map(t,b);C.push(i)}var w=[];e.each(C,function(t,e){w=w.concat(e)});var T=Math.max.apply(null,w)||1,L=[],$=function(t){var a=[];e.each(t,function(e,r){if(e>0){var i=t[e-1],o=i+Math.floor((r-i)/2);o=Math.floor(o/T*n)+f;r=Math.floor(r/T*n)+f;a=a.concat([o,r])}else{r=Math.floor(r/T*n)+f;a.push(r)}});return a};e.each(C,function(t,e){L.push($(e))});var G,M,_,E=[],S=[],A=v,I=[];for(x=0;h>x;x++){G=this.convertColor(l[x],c[x]);E[x]=new createjs.Shape;S[x]=E[x].graphics;M=D-L[x][0];S[x].setStrokeStyle(s).beginStroke(G).moveTo(A,M);this.stage.addChild(E[x]);if(a.drawPointer){_=this.convertColor(p[x],u[x]);I[x]=new createjs.Shape;I[x].graphics.beginFill(_).drawCircle(0,0,g);this.stage.addChild(I[x])}}var R=this.stage,F=function(t){y-=1;0===y&&createjs.Ticker.removeEventListener("tick",F);A+=m;for(var e,r=0;h>r;r++){e=L[r];M=D-e[e.length-y-1];S[r].lineTo(A,M);if(a.drawPointer){I[r].x=A;I[r].y=Math.max(M,g)}}R.update(t)};createjs.Ticker.useRAF=!0;createjs.Ticker.setFPS(30);createjs.Ticker.addEventListener("tick",F)};r.Graph.easel.Base.prototype.convertColor=function(t,e){if(-1!==t.indexOf("#")){var a=parseInt(t.substr(1,2),16),r=parseInt(t.substr(3,2),16),n=parseInt(t.substr(5,2),16);t=e?"rgba("+[a,r,n,e].join(",")+")":"rgb("+[a,r,n].join(",")+")"}else-1!==t.indexOf("rgb")&&(t=4>t.split(",").length?"rgb("+t+")":"rgba("+t+")");return t};r.Graph.easel.Base.prototype.mix=function(t,a){var n=0,i=function(t,a){t=t||1;var r=e.map(a,function(e){for(var a,r,i={x:e.x},o=0;t>o;o++){a="y"+(o||"");r="y"+(n+o||"");i[a]=e[r]}return i});n+=t;return r},o=a.chartColors||r.Graph.getCachedChartColors(a.id,null,a.chartColorsMethod);e.each(a.mix,e.proxy(function(r,s){var h={chartColors:o.slice(n,n+s.yLength)},l=i(s.yLength,t);s=e.extend({},a,h,s);this[s.type](l,s)},this))};r.Graph.easel.bar=r.Graph.easel.motionLine=r.Graph.easel.mix=function(t,e,a,n){if(r.Graph.test.canvas()){var i=new r.Graph.easel.Base(t,e,a,n);return i}console.warn("EaselJS graph requires for HTML5 Canvas capability");n.trigger("REMOVE")};r.Graph.morris={};r.Graph.morris.Base=function(t,a,r,n){if(window.Morris||"function"!=typeof window.require){var i=a.width||n.width();i?this.build_(Morris,t,a,r,n):setTimeout(e.proxy(function(){this.build_(Morris,t,a,r,n)},this),100)}else require(["raphael","morris"],e.proxy(function(){this.build_(Morris,t,a,r,n)},this))};r.Graph.morris.Base.prototype.build_=function(t,a,n,i,o){var s,h,l,c=n.type.split(".")[1],p=n.yLength,u=n.width||o.width()||300,g=n.height||o.height()||300;this.$graphEl=e('
').css({height:g+"px",width:u+"px"}).prependTo(o);n=e.extend({},n,{element:n.id,data:a,xkey:"x",labels:this.getYLabels_(p,n.labels),ykeys:this.getYKeys_(p),ymax:this.getYMax_(a,c,p),ymin:n.ymin||0,lineWidth:parseInt(n.lineWidth,10)||6,pointSize:parseInt(n.pointSize,10)||6,smooth:n.smooth||!1});n.barColors=n.barColors||this.getChartColors(n);n.colors=n.colors||this.getChartColors(n);n.lineColors=n.lineColors||this.getChartColors(n);n.numLines=parseInt(n.numLines,10)||this.getNumLines_(n.ymax,g);n.pointStrokeColors=n.pointStrokeColors?n.pointStrokeColors.split(/,/):[];if(!n.pointStrokeColors.length)for(s=0;p>s;s++)n.pointStrokeColors.push("none");h={element:null,data:null,xkey:"x",labels:[],ykeys:[],dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,hideHover:!1,hoverCallback:null,yLabelFormat:null,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"],lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:50,continuousLine:!0,barSizeRatio:.75,barGap:3,barColors:["#0b62a4","#7a92a3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],backgroundColor:"#FFFFFF",labelColor:"#000000",formatter:t.commas};l={};e.each(n,function(t,e){void 0!==h[t]&&(l[t]=e)});r.Graph.test.svg||(l.smooth=!0);if("donut"===c){var d=this.getTotalCount_(a,s);l.formatter=function(t){var e=t=(t+"").replace(/,/g,"");if(!n.noCommaOnYLabel)for(;e!=(e=e.replace(/^(-?\d+)(\d{3})/,"$1,$2")););var a,r=Math.ceil(1e4*(t/d))/100;a=n.donutsFormatter&&"function"==typeof n.donutsFormatter?n.donutsFormatter(e,r+"%",t):e+"("+r+"%)";return a}}var f={bar:t.Bar,line:t.Line,donut:t.Donut,area:t.Area}[c];this.graph=new f(l)};r.Graph.morris.Base.prototype.getYMax_=function(t,a,r){var n,i,o,s,h;if("area"!==a){o=[];e.each(t,function(t,e){for(n=0;r>n;n++){h="y"+(n||"");o.push(parseInt(e[h],10))}});i=Math.max.apply(null,o)}else i=Math.max.apply(null,e.map(t,function(t){s=0;for(n=0;r>n;n++){h="y"+(n||"");s+=parseInt(t[h],10)}return s}));i||(i=1);0!==i%2&&(i+=1);return i};r.Graph.morris.Base.prototype.getChartColors=function(t){this.chartColors||(this.chartColors=t.chartColors||r.Graph.getCachedChartColors(t.id,null,t.chartColorsMethod));return this.chartColors};r.Graph.morris.Base.prototype.getYKeys_=function(t){var e,a=[];for(e=0;t>e;e++)a.push("y"+(e||""));return a};r.Graph.morris.Base.prototype.getYLabels_=function(t,e){var a,r=[];e=e?e.split(/,/):[];for(a=0;t>a;a++)r.push(e[a]||"Count");return r};r.Graph.morris.Base.prototype.getNumLines_=function(t,e){var a;a=t>=18?9:2===t?3:t/2+1;a=Math.min(a||1,Math.floor(e/56));return a};r.Graph.morris.Base.prototype.getTotalCount_=function(t,a){var r,n=0,i="y"+(a||"");e.each(t,function(t,e){r=e[i]||e.value||0;"string"==typeof r&&(r=parseFloat(r.replace(/,/g,""),10));n+=r});return n};r.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};r.Graph.morris.bar=r.Graph.morris.line=r.Graph.morris.donut=r.Graph.morris.area=function(t,e,a,n){if(r.Graph.test.vml()){var i=new r.Graph.morris.Base(t,e,a,n);return i}console.warn("Morris graph requires for SVG/VML capability");n.trigger("REMOVE")};r.Slider=function(t,a,n,i,o){if(!e.ui||!e.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var s=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.range=r.Range.generate(a);this.$dataRangeTarget=n;this.$sliderContainer=e('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};e.each(i,function(t,e){s.eventTargetList.update.add(e)});e.each(o,function(t,e){s.eventTargetList.amount.add(e)});this.$sliderContainer.on("APPEND_TO",function(t,a){s.$container=a;s.draw_(a);return e(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){s.$dataRangeTarget.trigger("GET_DATA_RANGE",function(t){s.buildSlider(t.min,t.max)});return e(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(t,a){s.$dataRangeTarget=a;return e(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(t,a,r){r=e.isArray(r)?r:[r];e.each(r,function(t,e){s.eventTargetList[a].add(e)});return e(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(t,a,r){r=e.isArray(r)?r:[r];e.each(r,function(t,e){s.eventTargetList[a].remove(e)});return e(this)});this.$sliderContainer.on("ERASE",function(){s.erase_();return e(this)});this.$sliderContainer.on("REDRAW",function(){var t=e(this);t.trigger("BUILD_SLIDER").trigger("APPEND_TO",[s.$container]);return e(this)});this.$sliderContainer.on("UPDATE",function(t,a){s.$slider("values",a);s.updateSliderAmount(a);return e(this)});return this.$sliderContainer};r.Slider.prototype.initEventTarget=function(){var t=[];return{add:function(e){t.push(e)},remove:function(a){t=e.grep(t,function(t){return t!==a})},get:function(){return t}}};r.Slider.prototype.buildSlider=function(t,a,r){var n=this;r=r||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}this.$slider=e('
').slider({range:!0,min:t,max:a,values:r,slide:function(t,e){n.updateSliderAmount(e.values,e)},stop:function(t,e){n.updateGraphAndList(e.values)}}).appendTo(n.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=e('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(r)}};r.Slider.prototype.draw_=function(t){this.$sliderContainer.appendTo(t)};r.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};r.Slider.prototype.updateSliderAmount=function(t,a){var n,i,o,s,h=this.range.maxLength,l=this.$amount;if(this.range.isTimeline){n=r.Date.parse(t[0]);i=r.Date.parse(t[1]);o=this.range.unit;s=r.Range.getLength(n,i,o);if(a&&s>h)if(a.value===a.values[0]){i=r.Date.calcDate(n,h,o,!1);this.$slider.slider("values",1,i.valueOf())}else{n=r.Date.calcDate(i,h,o,!0);this.$slider.slider("values",0,n.valueOf())}l&&l.text([r.Date.createXLabel(n,o),r.Date.createXLabel(i,o)].join(" - "))}else{n=t[0];i=t[1];if(i-n>h)if(a.value===a.values[0]){i=h-n;this.$slider.slider("values",1,i)}else{n=i-h;this.$slider.slider("values",0,n)}l&&e.each(this.eventTargetList.amount.get(),function(t,e){e.trigger("GET_LABEL",[[n,i],function(t){l.text([t[0],t[1]].join(" - "))}])})}};r.Slider.prototype.updateGraphAndList=function(t,a){e.each(this.eventTargetList.update.get(),function(e,r){r.trigger("UPDATE",[t,a])})};r.Slider.prototype.update_=function(t,e){this.$slider.slider("values",t,e)};r.List=function(t,a){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var n=this.config.type||"text";this.template_=e.Deferred();require([n+"!"+this.config.staticPath+this.config.template],e.proxy(function(t){this.template_.resolve(t)},this))}else this.template_=e.get(this.config.staticPath+this.config.template,"text");this.range=r.Range.generate(a);this.$listContainer=e('
');this.$listContainer.on("UPDATE",e.proxy(function(t,e){this.update_(e)},this));this.$listContainer.on("GET_DATA_RANGE",e.proxy(function(t,a){this.getData(e.proxy(function(t){a(r.Range.getDataRange(t,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",e.proxy(function(t,a,r){this.getData(e.proxy(function(t){r(this.getDataLabelByIndex(a,t))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",e.proxy(function(t,a){this.$listContainer.appendTo(a);this.getData(e.proxy(function(t){this.draw_(t)},this));return this.$listContainer},this));return this.$listContainer}};r.List.prototype.getData=function(t){this.config.data?r.Data.getData(this.origData_,this.$listContainer,t,this):t()};r.List.prototype.getTemplate=function(t){r.Data.getData(this.template_,this.$listContainer,t,this)};r.List.prototype.draw_=function(t){var e=this;this.getTemplate(function(a){t=e.createListData(t);e.$listContainer.html(_.template(a,t))})};r.List.prototype.getDataLabelByIndex=function(t,a){var r=this.config.dataLabel||"x";return e.map(t,function(t){return a[t][r]})};r.List.prototype.createListData=function(t){var e="";t&&(e=this.range.isTimeline?r.Data.filterData(t,this.range.max,this.range.min,this.range.unit,1,!0):t.slice(this.range.min,this.range.max+1));return{data:e}};r.List.prototype.update_=function(t,e){var a=this;t=t||[];e=e||this.range.unit;this.range=r.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:e,dataType:this.range.dataType});this.getData(function(t){a.draw_(t)})};r.Build=function(t){var a;if("string"==typeof t&&/\.json$/.test(t)){a=e('
');r.Data.getData(e.getJSON(t),null,function(t){t.$container=a;r.Build_(t).trigger("APPEND")})}else a=r.Build_(t).trigger("APPEND");return a};r.Build_=function(t){var a,n,i,o,s,h,l;a=t.$container||e('
');h=[];if(t.graph){n=new r.Graph(t.graph,t.range);h.push(n)}if(t.list){o=new r.List(t.list,t.range);t.list.data&&h.push(o) -}if(t.graph&&"donut"!==t.graph.type){s=n;l=[n]}else{s=o;l=[o]}var c=function(){var t=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(t)};!t.slider||!t.slider.force&&c()||(i=new r.Slider(t.slider,t.range,s,h,l));a.on("APPEND",function(){n&&n.trigger("APPEND_TO",[a]);i&&i.trigger("BUILD_SLIDER").trigger("APPEND_TO",[a]);o&&o.trigger("APPEND_TO",[a])});a.on("GET_CONTAINER",function(t,e,a){a({graph:n,slider:i,list:o}[e])});return a};return r}(this,jQuery); \ No newline at end of file +var ChartAPI=function(a,b){"use strict";var c=b,d={};(a.MT=a.MT||{}).ChartAPI=d;d.Data={};d.Data.getData=function(a,b,d,e){var f,g,h,i;a&&a.done(function(a){f||(f="string"==typeof a?""+a:c.isArray(a)?c.map(a,function(a){return c.extend({},a)}):c.extend({},a));d(f)}).fail(function(a){g={404:"Data is not found",403:"Data is forbidden to access"};h="Some error occured in the data fetching process";i=a.status?"error-"+a.status:"error-unknown";e&&(e.$errormsg=c('
'+(g[a.status]||h)+"
").appendTo(b))}).always(function(){e&&e.$progress&&e.$progress.parent().length>0&&e.$progress.remove()}).progress(function(){!e||e.$progress&&0!==e.$progress.parent().length||(e.$progress=c('
fetching data...
').appendTo(b))})};d.Data.filterData=function(a,b,e,f,g,h){var i,j={};g=g||1;c.each(a,function(a,k){var l,m;l=d.Date.parse(k.x);if(l&&l>=e&&l<=b)if(h){m=d.Date.createId(l,"daily");j[m]=k}else{"weekly"===f&&(l=d.Date.getWeekStartday(l));m=d.Date.createId(l,f);if(j[m])for(a=0;anew Date&&(b=new Date);a>b&&(a=b);e=d.Range.getLength(a,b,g);if(e>f){e=f;a=d.Date.calcDate(b,e,g,!0)}return{start:a,end:b,length:e,maxLength:f,unit:g,dataType:h,max:d.Range.getEndDate(b,g),min:d.Range.getStartDate(a,g),isTimeline:!0}};d.Range.calcNum=function(a,b,d,e,f,g,h){d=d||10;if(h){var i=c(window).width();e=Math.min(Math.ceil(.021875*i),e);d=Math.min(d,e)}if(!a&&!b){a=0;b=d-1}a=parseInt(a,10)||(0===a?0:null);b=parseInt(b,10)||(0===b?0:null);if(null===a){a=b-d;a<0&&(a=0)}null===b&&(b=a+d);a>b&&(a=b);d=b-a+1;if(d>e){d=e;a=b-e}return{start:a,end:b,length:d,maxLength:e,dataType:g,unit:null,max:b,min:a,isTimeline:!1}};d.Range.getStartDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,0,1,0,0,0)},monthly:function(){c=new Date(d,e,1,0,0,0)},quarter:function(){c=new Date(d,e,1,0,0,0)},weekly:function(){c=new Date(d,e,f-a.getDay(),0,0,0)},daily:function(){c=new Date(d,e,f,0,0,0)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c};d.Range.getEndDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,11,31,23,59,59)},monthly:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},quarter:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},weekly:function(){c=new Date(d,e,f-a.getDay()+6,23,59,59)},daily:function(){c=new Date(d,e,f,23,59,59)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c0?e+1:1};d.Graph=function(a,c){this.config=b.extend({type:"morris.bar",staticPath:"",data:"graph.json"},a);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=d.Range.generate(c);if("string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=b.Deferred();this.getData(b.proxy(function(a){this.graphData[this.range.unit].resolve(this.generateGraphData(a))},this));this.$graphContainer=b('
');this.$graphContainer.on("UPDATE",b.proxy(function(a,c,d){this.update_(c,d);return b(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",b.proxy(function(){this.remove_()},this));var e=b(window).width();this.updateFunc=b.proxy(function(){if(e&&e!==b(window).width()){e=b(window).width();this.update_()}},this);a.autoResize&&b(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){b.proxy(this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",b.proxy(function(a,c,d){b.proxy(this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",b.proxy(function(a,c){this.$graphContainer.appendTo(c);this.graphData[this.range.unit].done(b.proxy(function(a){var c;c=this.range.isTimeline?b.grep(a,b.proxy(function(a){return this.range.start<=a.timestamp&&a.timestamp<=this.range.end},this)):a.slice(this.range.min,this.range.max+1);this.draw_(c)},this));return b(this.$graphContainer)},this));return this.$graphContainer};d.Graph.prototype.getData=function(a){d.Data.getData(this.origData_,this.$graphContainer,a,this)};d.Graph.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.Graph.prototype.getTotalCount_=function(a,c){var d=0,e="y"+(c||"");b.each(a,function(a,b){d+=parseInt(b[e]||b.value||0,10)});return d};d.Graph.prototype.getDelta_=function(a,b){var c,d,e,f,g=a.length;f="y"+(b||"");c=a[g-1];d=a[g-2];e=d&&c&&d[f]?c[f]-d[f]:c[f];return void 0===e?"":e};d.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};d.Graph.getChartColors=function(a,b){return{reverse:function(a){return a.reverse()},shuffle:function(a){var b,c,d,e;d=a.length;for(b=0;b';this.generateLabel(this.labelTemplate)}if(g.fallback&&g.fallback.test&&!d.Graph.test[g.fallback.test]()){c=g.fallback.type.split(".");e=c[0];f=c[1];g=b.extend(g,g.fallback)}g.chartColors&&"string"==typeof g.chartColors&&(g.chartColors=g.chartColors.split(","));this.graphObject=d.Graph[e][f](a,g,this.range,this.$graphContainer)};d.Graph.test={};d.Graph.test.canvas=function(){var a=document.createElement("canvas");return a.getContext&&a.getContext("2d")};d.Graph.test.svg=function(){var a={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(a.svg,"svg").createSVGRect};d.Graph.test.vml=function(){var a,b=d.Graph.test.svg();if(!b){var c=document.body.appendChild(document.createElement("div"));c.innerHTML='';var e=c.firstChild;e.style.behavior="url(#default#VML)";a=!e||"object"==typeof e.adj;c.parentNode.removeChild(c)}return b||a};d.Graph.prototype.generateLabel=function(a){var c,e=this.config.label.template&&this.config.label.data?this.config.label.data:{},f=this.config.label.yLength||this.config.yLength,g=b.proxy(function(){this.labels=new d.Graph.Labels(this.$graphContainer,f,a);this.getData(b.proxy(function(a){for(var b=0;b
');e&&b('
').html(e).prependTo(this.$labelContainer);this.totals={};for(f=0;f
').appendTo(a)};d.Graph.Labels.Total.prototype.createTotalCount=function(a){c('"+a+" ").appendTo(this.$totalContainer)};d.Graph.Labels.Total.prototype.createDeltaCount=function(a){var b=a?a<0?"minus ":"plus ":"zero ";c('('+a+")").appendTo(this.$totalContainer)};d.Graph.css={};d.Graph.css.Base=function(a,c){this.len=a.length;this.$graphEl=b('
')};d.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.css.Base.prototype.horizontalBar=function(a,c,e,f){c.width&&this.$graphEl.css({width:c.width,"max-width":"100%",margin:"0 auto"});for(var g,h,i,j,k,l,m=c.barColor||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod)[1],n=c.barBackgroundColor||"#f0f0f0",o=c.dateColor||"#999999",p=c.dateColorSaturday||o,q=c.dateColorSunday||o,r=c.labelColor||"#999999",s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=parseInt(c.dateLabelSize,10)||v,x=function(){return b('
')},y=b.map(a,function(a){return parseInt(a.y,10)}),z=b.map(a,function(a){return{value:""+parseInt(a.x.substr(a.x.lastIndexOf("-")+1),10),weekday:d.Date.parse(a.x)?d.Date.parse(a.x).getDay():null}}),A=Math.max.apply(null,y)||1,B=c.yLabel||y,C=this.len;C>0;){C-=1;g=Math.floor(y[C]/A*100)-15;h=x();i=h.find(".css-graph-bar-background");i.css({"background-color":n});if(c.showDate){l=h.find(".css-graph-date");l.text(z[C].value).css({color:o,"font-size":w+"px","line-height":s+"px"});6===z[C].weekday?l.addClass("saturday").css({color:p}):0===z[C].weekday&&l.addClass("sunday").css({color:q});h.find(".css-graph-bar-container").css({"margin-left":t+"px"})}j=h.find(".css-graph-bar");j.css({width:g+"%","background-color":m});k=h.find(".css-graph-bar-count");k.text(B[C]).css({color:r,"font-size":v+"px","line-height":s+"px"});h.appendTo(this.$graphEl)}this.$graphEl.appendTo(f)};d.Graph.css.Base.prototype.ratioHorizontalBar=function(a,c,e,f){var g,h,i,j,k,l,m,n,o,p,q,r=c.yLength,s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=c.dateColor||"#999999",x=c.barColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),y=c.labelColors,z=c.labelClasses;for(g=0;g
').appendTo(this.$graphEl);if(c.showDate&&i.x){o=""+parseInt(i.x.substr(i.x.lastIndexOf("-")+1),10);b('
'+o+"
").appendTo(l)}m=b('
').appendTo(l);c.showDate&&m.css({"margin-left":t+"px"});for(h=0;h
');n.css({width:p+"%","background-color":x[h]});c.showCount&&n.text(j[h]);z&&z[h]&&n.addClass(z[h]);y&&y[h]&&n.css({color:y[h]});n.appendTo(m)}}m.appendTo(l)}this.$graphEl.appendTo(f)};d.Graph.css.horizontalBar=d.Graph.css.ratioHorizontalBar=function(a,b,c,e){var f=new d.Graph.css.Base(a,b,c,e);f[b.type.slice(b.type.lastIndexOf(".")+1)](a,b,c,e);return f};d.Graph.easel={};d.Graph.easel.Base=function(a,c,d,e){this.data=a;this.config=c;this.range=d;this.$container=e;if(window.createjs||"function"!=typeof window.require){parseInt(c.width||e.width(),10)?this.buildCanvas(createjs):setTimeout(b.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],b.proxy(function(){this.buildCanvas(createjs)},this))};d.Graph.easel.Base.prototype.buildCanvas=function(a){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=b('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new a.Stage(this.canvas);this.stage.update();this[this.config.type.split(".")[1]](this.data,this.config)};d.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};d.Graph.easel.Base.prototype.bar=function(a,c){for(var e,f,g,h,i,j=a.length,k=c.chartColorsAlpha?c.chartColorsAlpha[0]:1,l=c.chartColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),m=this.convertColor(l[0],k),n=parseInt(c.barMargin,10)||10,o=Math.floor(this.width/j),p=o-n,q=Math.floor((this.width-o*j)/2)+n/2,r=b.map(a,function(a){return parseInt(a.y,10)}),s=Math.max.apply(null,r)||1,t=0;t0){var f=a[b-1],g=f+Math.floor((d-f)/2);g=Math.floor(g/y*e)+p;d=Math.floor(d/y*e)+p;c=c.concat([g,d])}else{d=Math.floor(d/y*e)+p;c.push(d)}});return c};b.each(u,function(a,b){z.push(A(b))});var B,C,D,E=[],F=[],G=s,H=[];for(w=0;w
').css({height:n+"px",width:m+"px"}).prependTo(g);e=b.extend({},e,{element:e.id,data:c,xkey:"x",labels:this.getYLabels_(l,e.labels),ykeys:this.getYKeys_(l),ymax:this.getYMax_(c,k,l),ymin:e.ymin||0,lineWidth:parseInt(e.lineWidth,10)||6,pointSize:parseInt(e.pointSize,10)||6,smooth:e.smooth||!1});e.barColors=e.barColors||this.getChartColors(e);e.colors=e.colors||this.getChartColors(e);e.lineColors=e.lineColors||this.getChartColors(e);e.numLines=parseInt(e.numLines,10)||this.getNumLines_(e.ymax,n);e.pointStrokeColors=e.pointStrokeColors?e.pointStrokeColors.split(/,/):[];if(!e.pointStrokeColors.length)for(h=0;h=18?9:2===a?3:a/2+1;c=Math.min(c||1,Math.floor(b/56));return c};d.Graph.morris.Base.prototype.getTotalCount_=function(a,c){var d,e=0,f="y"+(c||"");b.each(a,function(a,b){d=b[f]||b.value||0;"string"==typeof d&&(d=parseFloat(d.replace(/,/g,""),10));e+=d});return e};d.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.morris.bar=d.Graph.morris.line=d.Graph.morris.donut=d.Graph.morris.area=function(a,b,c,e){if(d.Graph.test.vml()){return new d.Graph.morris.Base(a,b,c,e)}console.warn("Morris graph requires for SVG/VML capability");e.trigger("REMOVE")};d.Slider=function(a,c,e,f,g){if(!b.ui||!b.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var h=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.range=d.Range.generate(c);this.$dataRangeTarget=e;this.$sliderContainer=b('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};b.each(f,function(a,b){h.eventTargetList.update.add(b)});b.each(g,function(a,b){h.eventTargetList.amount.add(b)});this.$sliderContainer.on("APPEND_TO",function(a,c){h.$container=c;h.draw_(c);return b(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){h.$dataRangeTarget.trigger("GET_DATA_RANGE",function(a){h.buildSlider(a.min,a.max)});return b(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(a,c){h.$dataRangeTarget=c;return b(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].add(b)});return b(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].remove(b)});return b(this)});this.$sliderContainer.on("ERASE",function(){h.erase_();return b(this)});this.$sliderContainer.on("REDRAW",function(){b(this).trigger("BUILD_SLIDER").trigger("APPEND_TO",[h.$container]);return b(this)});this.$sliderContainer.on("UPDATE",function(a,c){h.$slider("values",c);h.updateSliderAmount(c);return b(this)});return this.$sliderContainer};d.Slider.prototype.initEventTarget=function(){var a=[];return{add:function(b){a.push(b)},remove:function(c){a=b.grep(a,function(a){return a!==c})},get:function(){return a}}};d.Slider.prototype.buildSlider=function(a,c,d){var e,f,g=["change","create","slide","start","stop"],h=this;d=d||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}e={range:!0,min:a,max:c,values:d,slide:function(a,b){h.updateSliderAmount(b.values,b)},stop:function(a,b){h.updateGraphAndList(b.values)}};g.forEach(function(a){if(h.config.callback[a]){f=e[a];e[a]=function(b,c){h.config.callback[a](b,c);f&&f(b,c)}}});this.$slider=b('
').slider(e).appendTo(h.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=b('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(d)}};d.Slider.prototype.draw_=function(a){this.$sliderContainer.appendTo(a)};d.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};d.Slider.prototype.updateSliderAmount=function(a,c){var e,f,g,h,i=this.range.maxLength,j=this.$amount;if(this.range.isTimeline){e=d.Date.parse(a[0]);f=d.Date.parse(a[1]);g=this.range.unit;h=d.Range.getLength(e,f,g);if(c&&h>i)if(c.value===c.values[0]){f=d.Date.calcDate(e,i,g,!1);this.$slider.slider("values",1,f.valueOf())}else{e=d.Date.calcDate(f,i,g,!0);this.$slider.slider("values",0,e.valueOf())}j&&j.text([d.Date.createXLabel(e,g),d.Date.createXLabel(f,g)].join(" - "))}else{e=a[0];f=a[1];if(f-e>i)if(c.value===c.values[0]){f=i-e;this.$slider.slider("values",1,f)}else{e=f-i;this.$slider.slider("values",0,e)}j&&b.each(this.eventTargetList.amount.get(),function(a,b){b.trigger("GET_LABEL",[[e,f],function(a){j.text([a[0],a[1]].join(" - "))}])})}};d.Slider.prototype.updateGraphAndList=function(a,c){b.each(this.eventTargetList.update.get(),function(b,d){d.trigger("UPDATE",[a,c])})};d.Slider.prototype.update_=function(a,b){this.$slider.slider("values",a,b)};d.List=function(a,c){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var e=this.config.type||"text";this.template_=b.Deferred();require([e+"!"+this.config.staticPath+this.config.template],b.proxy(function(a){this.template_.resolve(a)},this))}else this.template_=b.get(this.config.staticPath+this.config.template,"text");this.range=d.Range.generate(c);this.$listContainer=b('
');this.$listContainer.on("UPDATE",b.proxy(function(a,b){this.update_(b)},this));this.$listContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",b.proxy(function(a,c,d){this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",b.proxy(function(a,c){this.$listContainer.appendTo(c);this.getData(b.proxy(function(a){this.draw_(a)},this));return this.$listContainer},this));return this.$listContainer}};d.List.prototype.getData=function(a){this.config.data?d.Data.getData(this.origData_,this.$listContainer,a,this):a()};d.List.prototype.getTemplate=function(a){d.Data.getData(this.template_,this.$listContainer,a,this)};d.List.prototype.draw_=function(a){var b=this;this.getTemplate(function(c){a=b.createListData(a);b.$listContainer.html(_.template(c,a))})};d.List.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.List.prototype.createListData=function(a){var b="";a&&(b=this.range.isTimeline?d.Data.filterData(a,this.range.max,this.range.min,this.range.unit,1,!0):a.slice(this.range.min,this.range.max+1));return{data:b}};d.List.prototype.update_=function(a,b){var c=this;a=a||[];b=b||this.range.unit;this.range=d.Range.generate({start:a[0]||this.range.start,end:a[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:b,dataType:this.range.dataType});this.getData(function(a){c.draw_(a)})};d.Build=function(a){var c;if("string"==typeof a&&/\.json$/.test(a)){c=b('
');d.Data.getData(b.getJSON(a),null,function(a){a.$container=c;d.Build_(a).trigger("APPEND")})}else c=d.Build_(a).trigger("APPEND");return c};d.Build_=function(a){var c,e,f,g,h,i,j;c=a.$container||b('
');i=[];if(a.graph){ +e=new d.Graph(a.graph,a.range);i.push(e)}if(a.list){g=new d.List(a.list,a.range);a.list.data&&i.push(g)}if(a.graph&&"donut"!==a.graph.type){h=e;j=[e]}else{h=g;j=[g]}var k=function(){var a=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(a)};!a.slider||!a.slider.force&&k()||(f=new d.Slider(a.slider,a.range,h,i,j));c.on("APPEND",function(){e&&e.trigger("APPEND_TO",[c]);f&&f.trigger("BUILD_SLIDER").trigger("APPEND_TO",[c]);g&&g.trigger("APPEND_TO",[c])});c.on("GET_CONTAINER",function(a,b,c){c({graph:e,slider:f,list:g}[b])});return c};return d}(this,jQuery); \ No newline at end of file diff --git a/lib/mtchart.css b/lib/mtchart.css index 321eda0..a3e608a 100644 --- a/lib/mtchart.css +++ b/lib/mtchart.css @@ -1 +1 @@ -.morris-hover{position:absolute;z-index:1000}.morris-hover.morris-default-style{border-radius:10px;padding:6px;color:#666;background:rgba(255,255,255,.8);border:solid 2px rgba(230,230,230,.8);font-family:sans-serif;font-size:12px;text-align:center}.morris-hover.morris-default-style .morris-hover-row-label{font-weight:700;margin:.25em 0}.morris-hover.morris-default-style .morris-hover-point{white-space:nowrap;margin:.1em 0}@charset "utf-8";.graph-container{position:relative}.graph-labels{position:absolute;top:15px;left:40px;z-index:200;padding:10px;border:1px solid #ccc;border-radius:4px;background-color:transparent;background-color:rgba(255,255,255,.8);box-shadow:1px 1px 4px rgba(0,0,0,.1)}.graph-total{margin-top:.5em}.graph-total-count{font-weight:700;font-size:20px;line-height:20px;display:block;float:left;margin-right:.2em}.graph-total-count:first-child{margin-top:0}.graph-delta{font-size:12px;font-weight:400;line-height:20px;display:block;float:right}.graph-container .error,.list-container .error{margin:10px 10px 0;padding:10px;background-color:#FFA9A9;border-radius:4px}.graph-container .progress,.list-container .progress{margin:10px 10px 0;padding:10px;background-color:#f0f0f0;border-radius:4px}.minus{color:red}.plus{color:green}.slider-container .amount{padding:10px;margin:5px 0;border:1px solid #ccc;border-radius:4px}.list-container{padding:10px;border:1px solid #ccc;border-radius:4px;margin:10px}.list-container li{list-style-type:circle;margin:.5em 1.5em}.slider-container{padding:10px}.slider-container .ui-widget-content{border-color:#ccc}.morris-hover.morris-default-style{border-radius:4px;border:1px solid #ccc;box-shadow:1px 1px 4px rgba(0,0,0,.1);background-color:#fff;background-color:rgba(255,255,255,.8)}.css-graph-bar-container{position:relative}.css-graph-date{height:100%;float:left;width:30px;text-align:center}.css-graph-bar{display:block;height:100%;background-color:#ccc;position:absolute;z-index:101}.css-graph-bar-count{width:100%;height:100%;text-align:right;color:#fff;line-height:30px;padding-right:5px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.css-graph-bar-background{display:block;width:100%;height:100%;background-color:#003130;position:absolute;z-index:100}.css-graph-y{height:100%;float:left;padding:0 10px;text-align:left;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.css-graph-y:last-of-type{text-align:right}.css-graph-bar-container:before,.css-graph-bar-container:after,.css-graph-container:before,.css-graph-container:after,.graph-label:before,.graph-label:after,.graph-total:before,.graph-total:after{content:" ";display:table}.css-graph-container:after,.css-graph-bar-container:after,.graph-label:after,.graph-total:after{clear:both}.css-graph-container,.css-graph-bar-container,.graph-label,.graph-total{*zoom:1} \ No newline at end of file +@charset "utf-8";.morris-hover{position:absolute;z-index:1000}.morris-hover.morris-default-style{border-radius:10px;padding:6px;color:#666;background:rgba(255,255,255,.8);border:solid 2px rgba(230,230,230,.8);font-family:sans-serif;font-size:12px;text-align:center}.morris-hover.morris-default-style .morris-hover-row-label{font-weight:700;margin:.25em 0}.morris-hover.morris-default-style .morris-hover-point{white-space:nowrap;margin:.1em 0}.graph-container{position:relative}.graph-labels{position:absolute;top:15px;left:40px;z-index:200;padding:10px;border:1px solid #ccc;border-radius:4px;background-color:transparent;background-color:rgba(255,255,255,.8);box-shadow:1px 1px 4px rgba(0,0,0,.1)}.graph-total{margin-top:.5em}.graph-total-count{font-weight:700;font-size:20px;line-height:20px;display:block;float:left;margin-right:.2em}.graph-total-count:first-child{margin-top:0}.graph-delta{font-size:12px;font-weight:400;line-height:20px;display:block;float:right}.graph-container .error,.list-container .error{margin:10px 10px 0;padding:10px;background-color:#ffa9a9;border-radius:4px}.graph-container .progress,.list-container .progress{margin:10px 10px 0;padding:10px;background-color:#f0f0f0;border-radius:4px}.minus{color:red}.plus{color:green}.slider-container .amount{padding:10px;margin:5px 0;border:1px solid #ccc;border-radius:4px}.list-container{padding:10px;border:1px solid #ccc;border-radius:4px;margin:10px}.list-container li{list-style-type:circle;margin:.5em 1.5em}.slider-container{padding:10px}.slider-container .ui-widget-content{border-color:#ccc}.morris-hover.morris-default-style{border-radius:4px;border:1px solid #ccc;box-shadow:1px 1px 4px rgba(0,0,0,.1);background-color:#fff;background-color:rgba(255,255,255,.8)}.css-graph-bar-container{position:relative}.css-graph-date{height:100%;float:left;width:30px;text-align:center}.css-graph-bar{display:block;height:100%;background-color:#ccc;position:absolute;z-index:101}.css-graph-bar-count{width:100%;height:100%;text-align:right;color:#fff;line-height:30px;padding-right:5px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.css-graph-bar-background{display:block;width:100%;height:100%;background-color:#003130;position:absolute;z-index:100}.css-graph-y{height:100%;float:left;padding:0 10px;text-align:left;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.css-graph-y:last-of-type{text-align:right}.css-graph-bar-container:after,.css-graph-bar-container:before,.css-graph-container:after,.css-graph-container:before,.graph-label:after,.graph-label:before,.graph-total:after,.graph-total:before{content:" ";display:table}.css-graph-bar-container:after,.css-graph-container:after,.graph-label:after,.graph-total:after{clear:both} \ No newline at end of file diff --git a/lib/mtchart.js b/lib/mtchart.js index 3c67b74..62774c4 100644 --- a/lib/mtchart.js +++ b/lib/mtchart.js @@ -62,141 +62,141 @@ $special = $event.special.debouncedresize = { var elem = document.createElement('canvas'); if (elem.getContext && elem.getContext('2d')) { /* -* EaselJS -* Visit http://createjs.com/ for documentation, updates and examples. -* -* Copyright (c) 2011 gskinner.com, inc. -* -* Distributed under the terms of the MIT license. -* http://www.opensource.org/licenses/mit-license.html -* -* This notice shall be included in all copies or substantial portions of the Software. -*/ -this.createjs=this.createjs||{};(function(){var c=function(){throw"UID cannot be instantiated";};c._nextID=0;c.get=function(){return c._nextID++};createjs.UID=c})();this.createjs=this.createjs||{}; -(function(){var c=function(){this.initialize()},b=c.prototype;c.initialize=function(a){a.addEventListener=b.addEventListener;a.removeEventListener=b.removeEventListener;a.removeAllEventListeners=b.removeAllEventListeners;a.hasEventListener=b.hasEventListener;a.dispatchEvent=b.dispatchEvent};b._listeners=null;b.initialize=function(){};b.addEventListener=function(a,m){var b=this._listeners;b?this.removeEventListener(a,m):b=this._listeners={};var d=b[a];d||(d=b[a]=[]);d.push(m);return m};b.removeEventListener= -function(a,m){var b=this._listeners;if(b){var d=b[a];if(d)for(var e=0,c=d.length;ec._times.length)return-1;null==a&&(a=c.getFPS()|0);a=Math.min(c._times.length-1,a);return 1E3/((c._times[0]-c._times[a])/a)};c.setPaused=function(a){c._paused=a};c.getPaused=function(){return c._paused};c.getTime=function(a){return c._getTime()-c._startTime-(a?c._pausedTime:0)};c.getTicks=function(a){return c._ticks-(a? -c._pausedTicks:0)};c._handleAF=function(){c._rafActive=!1;c._setupTick();c._getTime()-c._lastTime>=0.97*(c._interval-1)&&c._tick()};c._handleTimeout=function(){c.timeoutID=null;c._setupTick();c._tick()};c._setupTick=function(){if(!(c._rafActive||null!=c.timeoutID)){if(c.useRAF){var a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(a){a(c._handleAF);c._rafActive=!0;return}}c.timeoutID= -setTimeout(c._handleTimeout,c._interval)}};c._tick=function(){var a=c._getTime();c._ticks++;var m=a-c._lastTime,b=c._paused;b&&(c._pausedTicks++,c._pausedTime+=m);c._lastTime=a;for(var d=c._pauseable,e=c._listeners.slice(),f=e?e.length:0,h=0;hthis.a&&0<=this.d&&(a.rotation+=0>=a.rotation?180:-180),a.skewX=a.skewY=0):(a.skewX=b/c.DEG_TO_RAD, -a.skewY=g/c.DEG_TO_RAD);return a};b.reinitialize=function(a,b,g,d,c,f,h,k,j){this.initialize(a,b,g,d,c,f);this.alpha=h||1;this.shadow=k;this.compositeOperation=j;return this};b.appendProperties=function(a,b,g){this.alpha*=a;this.shadow=b||this.shadow;this.compositeOperation=g||this.compositeOperation;return this};b.prependProperties=function(a,b,g){this.alpha*=a;this.shadow=this.shadow||b;this.compositeOperation=this.compositeOperation||g;return this};b.clone=function(){var a=new c(this.a,this.b, -this.c,this.d,this.tx,this.ty);a.shadow=this.shadow;a.alpha=this.alpha;a.compositeOperation=this.compositeOperation;return a};b.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};c.identity=new c(1,0,0,1,0,0);createjs.Matrix2D=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b){this.initialize(a,b)},b=c.prototype;b.x=0;b.y=0;b.initialize=function(a,b){this.x=null==a?0:a;this.y=null==b?0:b};b.clone=function(){return new c(this.x,this.y)};b.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};createjs.Point=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b,g,d){this.initialize(a,b,g,d)},b=c.prototype;b.x=0;b.y=0;b.width=0;b.height=0;b.initialize=function(a,b,g,d){this.x=null==a?0:a;this.y=null==b?0:b;this.width=null==g?0:g;this.height=null==d?0:d};b.clone=function(){return new c(this.x,this.y,this.width,this.height)};b.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};createjs.Rectangle=c})();this.createjs=this.createjs||{}; -(function(){var c=function(a,b,g,d,c,f,h){this.initialize(a,b,g,d,c,f,h)},b=c.prototype;b.target=null;b.overLabel=null;b.outLabel=null;b.downLabel=null;b.play=!1;b._isPressed=!1;b._isOver=!1;b.initialize=function(a,b,g,d,c,f,h){a.addEventListener&&(this.target=a,a.cursor="pointer",this.overLabel=null==g?"over":g,this.outLabel=null==b?"out":b,this.downLabel=null==d?"down":d,this.play=c,this.setEnabled(!0),this.handleEvent({}),f&&(h&&(f.actionsEnabled=!1,f.gotoAndStop&&f.gotoAndStop(h)),a.hitArea=f))}; -b.setEnabled=function(a){var b=this.target;a?(b.addEventListener("mouseover",this),b.addEventListener("mouseout",this),b.addEventListener("mousedown",this)):(b.removeEventListener("mouseover",this),b.removeEventListener("mouseout",this),b.removeEventListener("mousedown",this))};b.toString=function(){return"[ButtonHelper]"};b.handleEvent=function(a){var b=this.target,g=a.type;"mousedown"==g?(a.addEventListener("mouseup",this),this._isPressed=!0,a=this.downLabel):"mouseup"==g?(this._isPressed=!1,a= -this._isOver?this.overLabel:this.outLabel):"mouseover"==g?(this._isOver=!0,a=this._isPressed?this.downLabel:this.overLabel):(this._isOver=!1,a=this._isPressed?this.overLabel:this.outLabel);this.play?b.gotoAndPlay&&b.gotoAndPlay(a):b.gotoAndStop&&b.gotoAndStop(a)};createjs.ButtonHelper=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b,g,d){this.initialize(a,b,g,d)},b=c.prototype;c.identity=null;b.color=null;b.offsetX=0;b.offsetY=0;b.blur=0;b.initialize=function(a,b,g,d){this.color=a;this.offsetX=b;this.offsetY=g;this.blur=d};b.toString=function(){return"[Shadow]"};b.clone=function(){return new c(this.color,this.offsetX,this.offsetY,this.blur)};c.identity=new c("transparent",0,0,0);createjs.Shadow=c})();this.createjs=this.createjs||{}; -(function(){var c=function(a){this.initialize(a)},b=c.prototype;b.complete=!0;b.onComplete=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._animations=null;b._frames=null;b._images=null;b._data=null;b._loadCount=0;b._frameHeight=0;b._frameWidth=0;b._numFrames=0;b._regX=0;b._regY=0;b.initialize=function(a){var b,g,d;if(null!=a){if(a.images&&0<(g=a.images.length)){d= -this._images=[];for(b=0;bd.length||!1==a.next?null:null==a.next||!0==a.next?h:a.next;a.frequency||(a.frequency=1);this._animations.push(h);this._data[h]=a}}}};b.getNumFrames=function(a){if(null==a)return this._frames?this._frames.length:this._numFrames;a=this._data[a];return null==a?0:a.frames.length};b.getAnimations=function(){return this._animations.slice(0)};b.getAnimation=function(a){return this._data[a]};b.getFrame=function(a){var b;return this.complete&&this._frames&&(b=this._frames[a])?b:null}; -b.getFrameBounds=function(a){return(a=this.getFrame(a))?new createjs.Rectangle(-a.regX,-a.regY,a.rect.width,a.rect.height):null};b.toString=function(){return"[SpriteSheet]"};b.clone=function(){var a=new c;a.complete=this.complete;a._animations=this._animations;a._frames=this._frames;a._images=this._images;a._data=this._data;a._frameHeight=this._frameHeight;a._frameWidth=this._frameWidth;a._numFrames=this._numFrames;a._loadCount=this._loadCount;return a};b._handleImageLoad=function(){0==--this._loadCount&& -(this._calculateFrames(),this.complete=!0,this.onComplete&&this.onComplete(),this.dispatchEvent("complete"))};b._calculateFrames=function(){if(!(this._frames||0==this._frameWidth)){this._frames=[];for(var a=0,b=this._frameWidth,g=this._frameHeight,d=0,c=this._images;d>8&255,a=a>>16&255);return null==c?"rgb("+a+","+b+","+d+")":"rgba("+a+","+b+","+d+","+c+")"};b.getHSL=function(a,b,d,c){return null==c?"hsl("+a%360+","+b+"%,"+d+"%)":"hsla("+a%360+","+b+"%,"+d+"%,"+c+")"};b.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9, -K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,"0":52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63};b.STROKE_CAPS_MAP=["butt","round","square"];b.STROKE_JOINTS_MAP=["miter","round","bevel"];b._ctx=(createjs.createCanvas?createjs.createCanvas():document.createElement("canvas")).getContext("2d");b.beginCmd=new c(b._ctx.beginPath, -[],!1);b.fillCmd=new c(b._ctx.fill,[],!1);b.strokeCmd=new c(b._ctx.stroke,[],!1);a._strokeInstructions=null;a._strokeStyleInstructions=null;a._ignoreScaleStroke=!1;a._fillInstructions=null;a._instructions=null;a._oldInstructions=null;a._activeInstructions=null;a._active=!1;a._dirty=!1;a.initialize=function(){this.clear();this._ctx=b._ctx};a.isEmpty=function(){return!(this._instructions.length||this._oldInstructions.length||this._activeInstructions.length)};a.draw=function(a){this._dirty&&this._updateInstructions(); -for(var b=this._instructions,d=0,c=b.length;df&&(f*=n=-1);f>l&&(f=l);0>h&&(h*=q=-1);h>l&&(h=l);0>k&&(k*=p=-1);k>l&&(k=l);0>j&&(j*=s=-1);j>l&&(j=l);this._dirty=this._active=!0;var l=this._ctx.arcTo,r=this._ctx.lineTo;this._activeInstructions.push(new c(this._ctx.moveTo,[a+d-h,b]),new c(l,[a+d+h*q,b-h*q,a+d,b+h,h]),new c(r,[a+d,b+e-k]),new c(l,[a+d+k*p,b+e+k*p,a+d-k,b+e,k]),new c(r,[a+j,b+e]),new c(l,[a-j*s,b+e+j*s,a,b+e-j,j]),new c(r,[a,b+f]),new c(l,[a-f*n,b-f*n,a+f,b,f]),new c(this._ctx.closePath));return this};a.drawCircle= -function(a,b,d){this.arc(a,b,d,0,2*Math.PI);return this};a.drawEllipse=function(a,b,d,e){this._dirty=this._active=!0;var f=0.5522848*(d/2),h=0.5522848*(e/2),k=a+d,j=b+e;d=a+d/2;e=b+e/2;this._activeInstructions.push(new c(this._ctx.moveTo,[a,e]),new c(this._ctx.bezierCurveTo,[a,e-h,d-f,b,d,b]),new c(this._ctx.bezierCurveTo,[d+f,b,k,e-h,k,e]),new c(this._ctx.bezierCurveTo,[k,e+h,d+f,j,d,j]),new c(this._ctx.bezierCurveTo,[d-f,j,a,e+h,a,e]));return this};a.drawPolyStar=function(a,b,d,e,f,h){this._dirty= -this._active=!0;null==f&&(f=0);f=1-f;h=null==h?0:h/(180/Math.PI);var k=Math.PI/e;this._activeInstructions.push(new c(this._ctx.moveTo,[a+Math.cos(h)*d,b+Math.sin(h)*d]));for(var j=0;j>3,s=g[p];if(!s||q&3)throw"bad path data (@"+c+"): "+n;n=d[p];p||(k=j=0);h.length=0;c++;q=(q>>2&1)+2;for(p=0;p>5?-1:1,r=(r&31)<<6|l[a.charAt(c+1)];3==q&&(r=r<<6|l[a.charAt(c+2)]);r=u*r/10;p%2?k=r+=k:j=r+=j;h[p]=r;c+=q}s.apply(this,h)}return this};a.clone=function(){var a=new b;a._instructions=this._instructions.slice();a._activeInstructions=this._activeInstructions.slice(); -a._oldInstructions=this._oldInstructions.slice();this._fillInstructions&&(a._fillInstructions=this._fillInstructions.slice());this._strokeInstructions&&(a._strokeInstructions=this._strokeInstructions.slice());this._strokeStyleInstructions&&(a._strokeStyleInstructions=this._strokeStyleInstructions.slice());a._active=this._active;a._dirty=this._dirty;return a};a.toString=function(){return"[Graphics]"};a.mt=a.moveTo;a.lt=a.lineTo;a.at=a.arcTo;a.bt=a.bezierCurveTo;a.qt=a.quadraticCurveTo;a.a=a.arc;a.r= -a.rect;a.cp=a.closePath;a.c=a.clear;a.f=a.beginFill;a.lf=a.beginLinearGradientFill;a.rf=a.beginRadialGradientFill;a.bf=a.beginBitmapFill;a.ef=a.endFill;a.ss=a.setStrokeStyle;a.s=a.beginStroke;a.ls=a.beginLinearGradientStroke;a.rs=a.beginRadialGradientStroke;a.bs=a.beginBitmapStroke;a.es=a.endStroke;a.dr=a.drawRect;a.rr=a.drawRoundRect;a.rc=a.drawRoundRectComplex;a.dc=a.drawCircle;a.de=a.drawEllipse;a.dp=a.drawPolyStar;a.p=a.decodePath;a._updateInstructions=function(){this._instructions=this._oldInstructions.slice(); -this._instructions.push(b.beginCmd);this._instructions.push.apply(this._instructions,this._activeInstructions);this._fillInstructions&&this._instructions.push.apply(this._instructions,this._fillInstructions);this._strokeInstructions&&(this._strokeStyleInstructions&&this._instructions.push.apply(this._instructions,this._strokeStyleInstructions),this._instructions.push.apply(this._instructions,this._strokeInstructions),this._ignoreScaleStroke?this._instructions.push(new c(this._ctx.save,[],!1),new c(this._ctx.setTransform, -[1,0,0,1,0,0],!1),b.strokeCmd,new c(this._ctx.restore,[],!1)):this._instructions.push(b.strokeCmd))};a._newPath=function(){this._dirty&&this._updateInstructions();this._oldInstructions=this._instructions;this._activeInstructions=[];this._active=this._dirty=!1};a._setProp=function(a,b){this[a]=b};createjs.Graphics=b})();this.createjs=this.createjs||{}; -(function(){var c=function(){this.initialize()},b=c.prototype;c.suppressCrossDomainErrors=!1;c._hitTestCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");c._hitTestCanvas.width=c._hitTestCanvas.height=1;c._hitTestContext=c._hitTestCanvas.getContext("2d");c._nextCacheID=1;b.alpha=1;b.cacheCanvas=null;b.id=-1;b.mouseEnabled=!0;b.name=null;b.parent=null;b.regX=0;b.regY=0;b.rotation=0;b.scaleX=1;b.scaleY=1;b.skewX=0;b.skewY=0;b.shadow=null;b.visible=!0;b.x=0;b.y=0;b.compositeOperation= -null;b.snapToPixel=!1;b.onPress=null;b.onClick=null;b.onDoubleClick=null;b.onMouseOver=null;b.onMouseOut=null;b.onTick=null;b.filters=null;b.cacheID=0;b.mask=null;b.hitArea=null;b.cursor=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._cacheOffsetX=0;b._cacheOffsetY=0;b._cacheScale=1;b._cacheDataURLID=0;b._cacheDataURL=null;b._matrix=null;b.initialize=function(){this.id= -createjs.UID.get();this._matrix=new createjs.Matrix2D};b.isVisible=function(){return!(!this.visible||!(0d||d>this.children.length)return arguments[c-2];if(2a||a>this.children.length- -1)return!1;if(b=this.children[a])b.parent=null;this.children.splice(a,1);return!0};b.removeAllChildren=function(){for(var a=this.children;a.length;)a.pop().parent=null};b.getChildAt=function(a){return this.children[a]};b.getChildByName=function(a){for(var b=this.children,c=0,d=b.length;cb||b>=d)){for(var e=0;e=a)return;var b=this;this._mouseOverIntervalID=setInterval(function(){b._testMouseOver()},1E3/Math.min(50,a))};b.enableDOMEvents=function(a){null==a&&(a=!0);var b,c=this._eventListeners;if(!a&&c){for(b in c)a=c[b],a.t.removeEventListener(b,a.f);this._eventListeners=null}else if(a&&!c&&this.canvas){a=window.addEventListener?window:document;var d=this,c=this._eventListeners={};c.mouseup={t:a,f:function(a){d._handleMouseUp(a)}}; -c.mousemove={t:a,f:function(a){d._handleMouseMove(a)}};c.dblclick={t:a,f:function(a){d._handleDoubleClick(a)}};c.mousedown={t:this.canvas,f:function(a){d._handleMouseDown(a)}};for(b in c)a=c[b],a.t.addEventListener(b,a.f)}};b.clone=function(){var a=new c(null);this.cloneProps(a);return a};b.toString=function(){return"[Stage (name="+this.name+")]"};b._getPointerData=function(a){var b=this._pointerData[a];if(!b&&(b=this._pointerData[a]={x:0,y:0},null==this._primaryPointerID||-1==this._primaryPointerID))this._primaryPointerID= -a;return b};b._handleMouseMove=function(a){a||(a=window.event);this._handlePointerMove(-1,a,a.pageX,a.pageY)};b._handlePointerMove=function(a,b,c,d){if(this.canvas){var e=this._getPointerData(a),f=e.inBounds;this._updatePointerPosition(a,c,d);if(f||e.inBounds||this.mouseMoveOutside){if(this.onMouseMove||this.hasEventListener("stagemousemove"))c=new createjs.MouseEvent("stagemousemove",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseMove&&this.onMouseMove(c),this.dispatchEvent(c); -if((d=e.event)&&(d.onMouseMove||d.hasEventListener("mousemove")))c=new createjs.MouseEvent("mousemove",e.x,e.y,d.target,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onMouseMove&&d.onMouseMove(c),d.dispatchEvent(c,d.target)}}};b._updatePointerPosition=function(a,b,c){var d=this._getElementRect(this.canvas);b-=d.left;c-=d.top;var e=this.canvas.width,f=this.canvas.height;b/=(d.right-d.left)/e;c/=(d.bottom-d.top)/f;d=this._getPointerData(a);(d.inBounds=0<=b&&0<=c&&b<=e-1&&c<=f-1)?(d.x=b,d.y=c):this.mouseMoveOutside&& -(d.x=0>b?0:b>e-1?e-1:b,d.y=0>c?0:c>f-1?f-1:c);d.rawX=b;d.rawY=c;a==this._primaryPointerID&&(this.mouseX=d.x,this.mouseY=d.y,this.mouseInBounds=d.inBounds)};b._getElementRect=function(a){var b;try{b=a.getBoundingClientRect()}catch(c){b={top:a.offsetTop,left:a.offsetLeft,width:a.offsetWidth,height:a.offsetHeight}}var d=(window.pageXOffset||document.scrollLeft||0)-(document.clientLeft||document.body.clientLeft||0),e=(window.pageYOffset||document.scrollTop||0)-(document.clientTop||document.body.clientTop|| -0),f=window.getComputedStyle?getComputedStyle(a):a.currentStyle;a=parseInt(f.paddingLeft)+parseInt(f.borderLeftWidth);var h=parseInt(f.paddingTop)+parseInt(f.borderTopWidth),k=parseInt(f.paddingRight)+parseInt(f.borderRightWidth),f=parseInt(f.paddingBottom)+parseInt(f.borderBottomWidth);return{left:b.left+d+a,right:b.right+d-k,top:b.top+e+h,bottom:b.bottom+e-f}};b._handleMouseUp=function(a){this._handlePointerUp(-1,a,!1)};b._handlePointerUp=function(a,b,c){var d=this._getPointerData(a),e;if(this.onMouseMove|| -this.hasEventListener("stagemouseup"))e=new createjs.MouseEvent("stagemouseup",d.x,d.y,this,b,a,a==this._primaryPointerID,d.rawX,d.rawY),this.onMouseUp&&this.onMouseUp(e),this.dispatchEvent(e);var f=d.event;if(f&&(f.onMouseUp||f.hasEventListener("mouseup")))e=new createjs.MouseEvent("mouseup",d.x,d.y,f.target,b,a,a==this._primaryPointerID,d.rawX,d.rawY),f.onMouseUp&&f.onMouseUp(e),f.dispatchEvent(e,f.target);if((f=d.target)&&(f.onClick||f.hasEventListener("click"))&&this._getObjectsUnderPoint(d.x, -d.y,null,!0,this._mouseOverIntervalID?3:1)==f)e=new createjs.MouseEvent("click",d.x,d.y,f,b,a,a==this._primaryPointerID,d.rawX,d.rawY),f.onClick&&f.onClick(e),f.dispatchEvent(e);c?(a==this._primaryPointerID&&(this._primaryPointerID=null),delete this._pointerData[a]):d.event=d.target=null};b._handleMouseDown=function(a){this._handlePointerDown(-1,a,!1)};b._handlePointerDown=function(a,b,c,d){var e=this._getPointerData(a);null!=d&&this._updatePointerPosition(a,c,d);if(this.onMouseDown||this.hasEventListener("stagemousedown"))c= -new createjs.MouseEvent("stagemousedown",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseDown&&this.onMouseDown(c),this.dispatchEvent(c);if(d=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1))if(e.target=d,d.onPress||d.hasEventListener("mousedown"))if(c=new createjs.MouseEvent("mousedown",e.x,e.y,d,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onPress&&d.onPress(c),d.dispatchEvent(c),c.onMouseMove||c.onMouseUp||c.hasEventListener("mousemove")||c.hasEventListener("mouseup"))e.event= -c};b._testMouseOver=function(){if(-1==this._primaryPointerID&&!(this.mouseX==this._mouseOverX&&this.mouseY==this._mouseOverY&&this.mouseInBounds)){var a=null;this.mouseInBounds&&(a=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY);var b=this._mouseOverTarget;if(b!=a){var c=this._getPointerData(-1);if(b&&(b.onMouseOut||b.hasEventListener("mouseout"))){var d=new createjs.MouseEvent("mouseout",c.x,c.y,b,null,-1,c.rawX,c.rawY);b.onMouseOut&& -b.onMouseOut(d);b.dispatchEvent(d)}b&&(this.canvas.style.cursor="");if(a&&(a.onMouseOver||a.hasEventListener("mouseover")))d=new createjs.MouseEvent("mouseover",c.x,c.y,a,null,-1,c.rawX,c.rawY),a.onMouseOver&&a.onMouseOver(d),a.dispatchEvent(d);a&&(this.canvas.style.cursor=a.cursor||"");this._mouseOverTarget=a}}};b._handleDoubleClick=function(a){var b=this._getPointerData(-1),c=this._getObjectsUnderPoint(b.x,b.y,null,this._mouseOverIntervalID?3:1);if(c&&(c.onDoubleClick||c.hasEventListener("dblclick")))evt= -new createjs.MouseEvent("dblclick",b.x,b.y,c,a,-1,!0,b.rawX,b.rawY),c.onDoubleClick&&c.onDoubleClick(evt),c.dispatchEvent(evt)};createjs.Stage=c})();this.createjs=this.createjs||{}; -(function(){var c=function(a){this.initialize(a)},b=c.prototype=new createjs.DisplayObject;b.image=null;b.snapToPixel=!0;b.sourceRect=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();"string"==typeof a?(this.image=new Image,this.image.src=a):this.image=a};b.isVisible=function(){var a=this.cacheCanvas||this.image&&(this.image.complete||this.image.getContext||2<=this.image.readyState);return!(!this.visible||!(0=d){var e=a.next;this._dispatchAnimationEnd(a,b,c,e,d-1)||(e?this._goto(e):(this.paused=!0,this.currentAnimationFrame=a.frames.length-1,this.currentFrame= -a.frames[this.currentAnimationFrame]))}else this.currentFrame=a.frames[this.currentAnimationFrame];else d=this.spriteSheet.getNumFrames(),b>=d&&!this._dispatchAnimationEnd(a,b,c,d-1)&&(this.currentFrame=0)};b._dispatchAnimationEnd=function(a,b,c,d,e){var f=a?a.name:null;this.onAnimationEnd&&this.onAnimationEnd(this,f,d);this.dispatchEvent({type:"animationend",name:f,next:d});!c&&this.paused&&(this.currentAnimationFrame=e);return this.paused!=c||this._animation!=a||this.currentFrame!=b};b.DisplayObject_cloneProps= -b.cloneProps;b.cloneProps=function(a){this.DisplayObject_cloneProps(a);a.onAnimationEnd=this.onAnimationEnd;a.currentFrame=this.currentFrame;a.currentAnimation=this.currentAnimation;a.paused=this.paused;a.offset=this.offset;a._animation=this._animation;a.currentAnimationFrame=this.currentAnimationFrame};b._goto=function(a){if(isNaN(a)){var b=this.spriteSheet.getAnimation(a);b&&(this.currentAnimationFrame=0,this._animation=b,this.currentAnimation=a,this._normalizeFrame())}else this.currentAnimation= -this._animation=null,this.currentFrame=a};createjs.BitmapAnimation=c})();this.createjs=this.createjs||{}; -(function(){var c=function(a){this.initialize(a)},b=c.prototype=new createjs.DisplayObject;b.graphics=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();this.graphics=a?a:new createjs.Graphics};b.isVisible=function(){var a=this.cacheCanvas||this.graphics&&!this.graphics.isEmpty();return!(!this.visible||!(0this.lineWidth?(b&&this._drawTextLine(a,j,e*d),e++,j=k[l+1]):j+=k[l]+k[l+1];b&&this._drawTextLine(a,j,e*d)}e++}return e};b._drawTextLine=function(a,b,c){this.outline?a.strokeText(b,0,c,this.maxWidth||65535):a.fillText(b,0,c,this.maxWidth||65535)};createjs.Text=c})();this.createjs=this.createjs||{}; -(function(){var c=function(){throw"SpriteSheetUtils cannot be instantiated";};c._workingCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");c._workingContext=c._workingCanvas.getContext("2d");c.addFlippedFrames=function(b,a,m,g){if(a||m||g){var d=0;a&&c._flip(b,++d,!0,!1);m&&c._flip(b,++d,!1,!0);g&&c._flip(b,++d,!0,!0)}};c.extractFrame=function(b,a){isNaN(a)&&(a=b.getAnimation(a).frames[0]);var m=b.getFrame(a);if(!m)return null;var g=m.rect,d=c._workingCanvas;d.width= -g.width;d.height=g.height;c._workingContext.drawImage(m.image,g.x,g.y,g.width,g.height,0,0,g.width,g.height);m=new Image;m.src=d.toDataURL("image/png");return m};c.mergeAlpha=function(b,a,c){c||(c=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));c.width=Math.max(a.width,b.width);c.height=Math.max(a.height,b.height);var g=c.getContext("2d");g.save();g.drawImage(b,0,0);g.globalCompositeOperation="destination-in";g.drawImage(a,0,0);g.restore();return c};c._flip=function(b, -a,m,g){for(var d=b._images,e=c._workingCanvas,f=c._workingContext,h=d.length/a,k=0;kthis.maxHeight)throw c.ERR_DIMENSIONS;for(var d=0,e=0,f=0;g.length;){var h=this._fillRow(g,d,f,b,a);h.w>e&&(e=h.w);d+=h.h;if(!h.h||!g.length){var k=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");k.width=this._getSize(e,this.maxWidth);k.height=this._getSize(d,this.maxHeight);this._data.images[f]=k;h.h||(e=d=0,f++)}}};b._getSize=function(a,b){for(var c=4;Math.pow(2,++c)f)throw c.ERR_DIMENSIONS;t>h||k+p>f||(n.img=g,n.rect=new createjs.Rectangle(k,b,p,t),j=j||t,a.splice(l,1),d[n.index]=[k,b,p,t,g,Math.round(-r+q*s.regX-e),Math.round(-u+q*s.regY-e)],k+=p)}return{w:k,h:j}};b._endBuild=function(){this.spriteSheet=new createjs.SpriteSheet(this._data); -this._data=null;this.progress=1;this.onComplete&&this.onComplete(this);this.dispatchEvent("complete")};b._run=function(){for(var a=50*Math.max(0.01,Math.min(0.99,this.timeSlice||0.3)),b=(new Date).getTime()+a,c=!1;b>(new Date).getTime();)if(!this._drawNext()){c=!0;break}if(c)this._endBuild();else{var d=this;this._timerID=setTimeout(function(){d._run()},50-a)}a=this.progress=this._index/this._frames.length;this.onProgress&&this.onProgress(this,a);this.dispatchEvent({type:"progress",progress:a})};b._drawNext= -function(){var a=this._frames[this._index],b=a.scale*this._scale,c=a.rect,d=a.sourceRect,e=this._data.images[a.img].getContext("2d");a.funct&&a.funct.apply(a.scope,a.params);e.save();e.beginPath();e.rect(c.x,c.y,c.width,c.height);e.clip();e.translate(Math.ceil(c.x-d.x*b),Math.ceil(c.y-d.y*b));e.scale(b,b);a.source.draw(e);e.restore();return++this._indexc._times.length)return-1;null==a&&(a=c.getFPS()|0);a=Math.min(c._times.length-1,a);return 1E3/((c._times[0]-c._times[a])/a)};c.setPaused=function(a){c._paused=a};c.getPaused=function(){return c._paused};c.getTime=function(a){return c._getTime()-c._startTime-(a?c._pausedTime:0)};c.getTicks=function(a){return c._ticks-(a? + c._pausedTicks:0)};c._handleAF=function(){c._rafActive=!1;c._setupTick();c._getTime()-c._lastTime>=0.97*(c._interval-1)&&c._tick()};c._handleTimeout=function(){c.timeoutID=null;c._setupTick();c._tick()};c._setupTick=function(){if(!(c._rafActive||null!=c.timeoutID)){if(c.useRAF){var a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(a){a(c._handleAF);c._rafActive=!0;return}}c.timeoutID= + setTimeout(c._handleTimeout,c._interval)}};c._tick=function(){var a=c._getTime();c._ticks++;var m=a-c._lastTime,b=c._paused;b&&(c._pausedTicks++,c._pausedTime+=m);c._lastTime=a;for(var d=c._pauseable,e=c._listeners.slice(),f=e?e.length:0,h=0;hthis.a&&0<=this.d&&(a.rotation+=0>=a.rotation?180:-180),a.skewX=a.skewY=0):(a.skewX=b/c.DEG_TO_RAD, + a.skewY=g/c.DEG_TO_RAD);return a};b.reinitialize=function(a,b,g,d,c,f,h,k,j){this.initialize(a,b,g,d,c,f);this.alpha=h||1;this.shadow=k;this.compositeOperation=j;return this};b.appendProperties=function(a,b,g){this.alpha*=a;this.shadow=b||this.shadow;this.compositeOperation=g||this.compositeOperation;return this};b.prependProperties=function(a,b,g){this.alpha*=a;this.shadow=this.shadow||b;this.compositeOperation=this.compositeOperation||g;return this};b.clone=function(){var a=new c(this.a,this.b, + this.c,this.d,this.tx,this.ty);a.shadow=this.shadow;a.alpha=this.alpha;a.compositeOperation=this.compositeOperation;return a};b.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};c.identity=new c(1,0,0,1,0,0);createjs.Matrix2D=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b){this.initialize(a,b)},b=c.prototype;b.x=0;b.y=0;b.initialize=function(a,b){this.x=null==a?0:a;this.y=null==b?0:b};b.clone=function(){return new c(this.x,this.y)};b.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};createjs.Point=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b,g,d){this.initialize(a,b,g,d)},b=c.prototype;b.x=0;b.y=0;b.width=0;b.height=0;b.initialize=function(a,b,g,d){this.x=null==a?0:a;this.y=null==b?0:b;this.width=null==g?0:g;this.height=null==d?0:d};b.clone=function(){return new c(this.x,this.y,this.width,this.height)};b.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};createjs.Rectangle=c})();this.createjs=this.createjs||{}; + (function(){var c=function(a,b,g,d,c,f,h){this.initialize(a,b,g,d,c,f,h)},b=c.prototype;b.target=null;b.overLabel=null;b.outLabel=null;b.downLabel=null;b.play=!1;b._isPressed=!1;b._isOver=!1;b.initialize=function(a,b,g,d,c,f,h){a.addEventListener&&(this.target=a,a.cursor="pointer",this.overLabel=null==g?"over":g,this.outLabel=null==b?"out":b,this.downLabel=null==d?"down":d,this.play=c,this.setEnabled(!0),this.handleEvent({}),f&&(h&&(f.actionsEnabled=!1,f.gotoAndStop&&f.gotoAndStop(h)),a.hitArea=f))}; + b.setEnabled=function(a){var b=this.target;a?(b.addEventListener("mouseover",this),b.addEventListener("mouseout",this),b.addEventListener("mousedown",this)):(b.removeEventListener("mouseover",this),b.removeEventListener("mouseout",this),b.removeEventListener("mousedown",this))};b.toString=function(){return"[ButtonHelper]"};b.handleEvent=function(a){var b=this.target,g=a.type;"mousedown"==g?(a.addEventListener("mouseup",this),this._isPressed=!0,a=this.downLabel):"mouseup"==g?(this._isPressed=!1,a= + this._isOver?this.overLabel:this.outLabel):"mouseover"==g?(this._isOver=!0,a=this._isPressed?this.downLabel:this.overLabel):(this._isOver=!1,a=this._isPressed?this.overLabel:this.outLabel);this.play?b.gotoAndPlay&&b.gotoAndPlay(a):b.gotoAndStop&&b.gotoAndStop(a)};createjs.ButtonHelper=c})();this.createjs=this.createjs||{};(function(){var c=function(a,b,g,d){this.initialize(a,b,g,d)},b=c.prototype;c.identity=null;b.color=null;b.offsetX=0;b.offsetY=0;b.blur=0;b.initialize=function(a,b,g,d){this.color=a;this.offsetX=b;this.offsetY=g;this.blur=d};b.toString=function(){return"[Shadow]"};b.clone=function(){return new c(this.color,this.offsetX,this.offsetY,this.blur)};c.identity=new c("transparent",0,0,0);createjs.Shadow=c})();this.createjs=this.createjs||{}; + (function(){var c=function(a){this.initialize(a)},b=c.prototype;b.complete=!0;b.onComplete=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._animations=null;b._frames=null;b._images=null;b._data=null;b._loadCount=0;b._frameHeight=0;b._frameWidth=0;b._numFrames=0;b._regX=0;b._regY=0;b.initialize=function(a){var b,g,d;if(null!=a){if(a.images&&0<(g=a.images.length)){d= + this._images=[];for(b=0;bd.length||!1==a.next?null:null==a.next||!0==a.next?h:a.next;a.frequency||(a.frequency=1);this._animations.push(h);this._data[h]=a}}}};b.getNumFrames=function(a){if(null==a)return this._frames?this._frames.length:this._numFrames;a=this._data[a];return null==a?0:a.frames.length};b.getAnimations=function(){return this._animations.slice(0)};b.getAnimation=function(a){return this._data[a]};b.getFrame=function(a){var b;return this.complete&&this._frames&&(b=this._frames[a])?b:null}; + b.getFrameBounds=function(a){return(a=this.getFrame(a))?new createjs.Rectangle(-a.regX,-a.regY,a.rect.width,a.rect.height):null};b.toString=function(){return"[SpriteSheet]"};b.clone=function(){var a=new c;a.complete=this.complete;a._animations=this._animations;a._frames=this._frames;a._images=this._images;a._data=this._data;a._frameHeight=this._frameHeight;a._frameWidth=this._frameWidth;a._numFrames=this._numFrames;a._loadCount=this._loadCount;return a};b._handleImageLoad=function(){0==--this._loadCount&& + (this._calculateFrames(),this.complete=!0,this.onComplete&&this.onComplete(),this.dispatchEvent("complete"))};b._calculateFrames=function(){if(!(this._frames||0==this._frameWidth)){this._frames=[];for(var a=0,b=this._frameWidth,g=this._frameHeight,d=0,c=this._images;d>8&255,a=a>>16&255);return null==c?"rgb("+a+","+b+","+d+")":"rgba("+a+","+b+","+d+","+c+")"};b.getHSL=function(a,b,d,c){return null==c?"hsl("+a%360+","+b+"%,"+d+"%)":"hsla("+a%360+","+b+"%,"+d+"%,"+c+")"};b.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9, + K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,"0":52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63};b.STROKE_CAPS_MAP=["butt","round","square"];b.STROKE_JOINTS_MAP=["miter","round","bevel"];b._ctx=(createjs.createCanvas?createjs.createCanvas():document.createElement("canvas")).getContext("2d");b.beginCmd=new c(b._ctx.beginPath, + [],!1);b.fillCmd=new c(b._ctx.fill,[],!1);b.strokeCmd=new c(b._ctx.stroke,[],!1);a._strokeInstructions=null;a._strokeStyleInstructions=null;a._ignoreScaleStroke=!1;a._fillInstructions=null;a._instructions=null;a._oldInstructions=null;a._activeInstructions=null;a._active=!1;a._dirty=!1;a.initialize=function(){this.clear();this._ctx=b._ctx};a.isEmpty=function(){return!(this._instructions.length||this._oldInstructions.length||this._activeInstructions.length)};a.draw=function(a){this._dirty&&this._updateInstructions(); + for(var b=this._instructions,d=0,c=b.length;df&&(f*=n=-1);f>l&&(f=l);0>h&&(h*=q=-1);h>l&&(h=l);0>k&&(k*=p=-1);k>l&&(k=l);0>j&&(j*=s=-1);j>l&&(j=l);this._dirty=this._active=!0;var l=this._ctx.arcTo,r=this._ctx.lineTo;this._activeInstructions.push(new c(this._ctx.moveTo,[a+d-h,b]),new c(l,[a+d+h*q,b-h*q,a+d,b+h,h]),new c(r,[a+d,b+e-k]),new c(l,[a+d+k*p,b+e+k*p,a+d-k,b+e,k]),new c(r,[a+j,b+e]),new c(l,[a-j*s,b+e+j*s,a,b+e-j,j]),new c(r,[a,b+f]),new c(l,[a-f*n,b-f*n,a+f,b,f]),new c(this._ctx.closePath));return this};a.drawCircle= + function(a,b,d){this.arc(a,b,d,0,2*Math.PI);return this};a.drawEllipse=function(a,b,d,e){this._dirty=this._active=!0;var f=0.5522848*(d/2),h=0.5522848*(e/2),k=a+d,j=b+e;d=a+d/2;e=b+e/2;this._activeInstructions.push(new c(this._ctx.moveTo,[a,e]),new c(this._ctx.bezierCurveTo,[a,e-h,d-f,b,d,b]),new c(this._ctx.bezierCurveTo,[d+f,b,k,e-h,k,e]),new c(this._ctx.bezierCurveTo,[k,e+h,d+f,j,d,j]),new c(this._ctx.bezierCurveTo,[d-f,j,a,e+h,a,e]));return this};a.drawPolyStar=function(a,b,d,e,f,h){this._dirty= + this._active=!0;null==f&&(f=0);f=1-f;h=null==h?0:h/(180/Math.PI);var k=Math.PI/e;this._activeInstructions.push(new c(this._ctx.moveTo,[a+Math.cos(h)*d,b+Math.sin(h)*d]));for(var j=0;j>3,s=g[p];if(!s||q&3)throw"bad path data (@"+c+"): "+n;n=d[p];p||(k=j=0);h.length=0;c++;q=(q>>2&1)+2;for(p=0;p>5?-1:1,r=(r&31)<<6|l[a.charAt(c+1)];3==q&&(r=r<<6|l[a.charAt(c+2)]);r=u*r/10;p%2?k=r+=k:j=r+=j;h[p]=r;c+=q}s.apply(this,h)}return this};a.clone=function(){var a=new b;a._instructions=this._instructions.slice();a._activeInstructions=this._activeInstructions.slice(); + a._oldInstructions=this._oldInstructions.slice();this._fillInstructions&&(a._fillInstructions=this._fillInstructions.slice());this._strokeInstructions&&(a._strokeInstructions=this._strokeInstructions.slice());this._strokeStyleInstructions&&(a._strokeStyleInstructions=this._strokeStyleInstructions.slice());a._active=this._active;a._dirty=this._dirty;return a};a.toString=function(){return"[Graphics]"};a.mt=a.moveTo;a.lt=a.lineTo;a.at=a.arcTo;a.bt=a.bezierCurveTo;a.qt=a.quadraticCurveTo;a.a=a.arc;a.r= + a.rect;a.cp=a.closePath;a.c=a.clear;a.f=a.beginFill;a.lf=a.beginLinearGradientFill;a.rf=a.beginRadialGradientFill;a.bf=a.beginBitmapFill;a.ef=a.endFill;a.ss=a.setStrokeStyle;a.s=a.beginStroke;a.ls=a.beginLinearGradientStroke;a.rs=a.beginRadialGradientStroke;a.bs=a.beginBitmapStroke;a.es=a.endStroke;a.dr=a.drawRect;a.rr=a.drawRoundRect;a.rc=a.drawRoundRectComplex;a.dc=a.drawCircle;a.de=a.drawEllipse;a.dp=a.drawPolyStar;a.p=a.decodePath;a._updateInstructions=function(){this._instructions=this._oldInstructions.slice(); + this._instructions.push(b.beginCmd);this._instructions.push.apply(this._instructions,this._activeInstructions);this._fillInstructions&&this._instructions.push.apply(this._instructions,this._fillInstructions);this._strokeInstructions&&(this._strokeStyleInstructions&&this._instructions.push.apply(this._instructions,this._strokeStyleInstructions),this._instructions.push.apply(this._instructions,this._strokeInstructions),this._ignoreScaleStroke?this._instructions.push(new c(this._ctx.save,[],!1),new c(this._ctx.setTransform, + [1,0,0,1,0,0],!1),b.strokeCmd,new c(this._ctx.restore,[],!1)):this._instructions.push(b.strokeCmd))};a._newPath=function(){this._dirty&&this._updateInstructions();this._oldInstructions=this._instructions;this._activeInstructions=[];this._active=this._dirty=!1};a._setProp=function(a,b){this[a]=b};createjs.Graphics=b})();this.createjs=this.createjs||{}; + (function(){var c=function(){this.initialize()},b=c.prototype;c.suppressCrossDomainErrors=!1;c._hitTestCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");c._hitTestCanvas.width=c._hitTestCanvas.height=1;c._hitTestContext=c._hitTestCanvas.getContext("2d");c._nextCacheID=1;b.alpha=1;b.cacheCanvas=null;b.id=-1;b.mouseEnabled=!0;b.name=null;b.parent=null;b.regX=0;b.regY=0;b.rotation=0;b.scaleX=1;b.scaleY=1;b.skewX=0;b.skewY=0;b.shadow=null;b.visible=!0;b.x=0;b.y=0;b.compositeOperation= + null;b.snapToPixel=!1;b.onPress=null;b.onClick=null;b.onDoubleClick=null;b.onMouseOver=null;b.onMouseOut=null;b.onTick=null;b.filters=null;b.cacheID=0;b.mask=null;b.hitArea=null;b.cursor=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._cacheOffsetX=0;b._cacheOffsetY=0;b._cacheScale=1;b._cacheDataURLID=0;b._cacheDataURL=null;b._matrix=null;b.initialize=function(){this.id= + createjs.UID.get();this._matrix=new createjs.Matrix2D};b.isVisible=function(){return!(!this.visible||!(0d||d>this.children.length)return arguments[c-2];if(2a||a>this.children.length- + 1)return!1;if(b=this.children[a])b.parent=null;this.children.splice(a,1);return!0};b.removeAllChildren=function(){for(var a=this.children;a.length;)a.pop().parent=null};b.getChildAt=function(a){return this.children[a]};b.getChildByName=function(a){for(var b=this.children,c=0,d=b.length;cb||b>=d)){for(var e=0;e=a)return;var b=this;this._mouseOverIntervalID=setInterval(function(){b._testMouseOver()},1E3/Math.min(50,a))};b.enableDOMEvents=function(a){null==a&&(a=!0);var b,c=this._eventListeners;if(!a&&c){for(b in c)a=c[b],a.t.removeEventListener(b,a.f);this._eventListeners=null}else if(a&&!c&&this.canvas){a=window.addEventListener?window:document;var d=this,c=this._eventListeners={};c.mouseup={t:a,f:function(a){d._handleMouseUp(a)}}; + c.mousemove={t:a,f:function(a){d._handleMouseMove(a)}};c.dblclick={t:a,f:function(a){d._handleDoubleClick(a)}};c.mousedown={t:this.canvas,f:function(a){d._handleMouseDown(a)}};for(b in c)a=c[b],a.t.addEventListener(b,a.f)}};b.clone=function(){var a=new c(null);this.cloneProps(a);return a};b.toString=function(){return"[Stage (name="+this.name+")]"};b._getPointerData=function(a){var b=this._pointerData[a];if(!b&&(b=this._pointerData[a]={x:0,y:0},null==this._primaryPointerID||-1==this._primaryPointerID))this._primaryPointerID= + a;return b};b._handleMouseMove=function(a){a||(a=window.event);this._handlePointerMove(-1,a,a.pageX,a.pageY)};b._handlePointerMove=function(a,b,c,d){if(this.canvas){var e=this._getPointerData(a),f=e.inBounds;this._updatePointerPosition(a,c,d);if(f||e.inBounds||this.mouseMoveOutside){if(this.onMouseMove||this.hasEventListener("stagemousemove"))c=new createjs.MouseEvent("stagemousemove",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseMove&&this.onMouseMove(c),this.dispatchEvent(c); + if((d=e.event)&&(d.onMouseMove||d.hasEventListener("mousemove")))c=new createjs.MouseEvent("mousemove",e.x,e.y,d.target,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onMouseMove&&d.onMouseMove(c),d.dispatchEvent(c,d.target)}}};b._updatePointerPosition=function(a,b,c){var d=this._getElementRect(this.canvas);b-=d.left;c-=d.top;var e=this.canvas.width,f=this.canvas.height;b/=(d.right-d.left)/e;c/=(d.bottom-d.top)/f;d=this._getPointerData(a);(d.inBounds=0<=b&&0<=c&&b<=e-1&&c<=f-1)?(d.x=b,d.y=c):this.mouseMoveOutside&& + (d.x=0>b?0:b>e-1?e-1:b,d.y=0>c?0:c>f-1?f-1:c);d.rawX=b;d.rawY=c;a==this._primaryPointerID&&(this.mouseX=d.x,this.mouseY=d.y,this.mouseInBounds=d.inBounds)};b._getElementRect=function(a){var b;try{b=a.getBoundingClientRect()}catch(c){b={top:a.offsetTop,left:a.offsetLeft,width:a.offsetWidth,height:a.offsetHeight}}var d=(window.pageXOffset||document.scrollLeft||0)-(document.clientLeft||document.body.clientLeft||0),e=(window.pageYOffset||document.scrollTop||0)-(document.clientTop||document.body.clientTop|| + 0),f=window.getComputedStyle?getComputedStyle(a):a.currentStyle;a=parseInt(f.paddingLeft)+parseInt(f.borderLeftWidth);var h=parseInt(f.paddingTop)+parseInt(f.borderTopWidth),k=parseInt(f.paddingRight)+parseInt(f.borderRightWidth),f=parseInt(f.paddingBottom)+parseInt(f.borderBottomWidth);return{left:b.left+d+a,right:b.right+d-k,top:b.top+e+h,bottom:b.bottom+e-f}};b._handleMouseUp=function(a){this._handlePointerUp(-1,a,!1)};b._handlePointerUp=function(a,b,c){var d=this._getPointerData(a),e;if(this.onMouseMove|| + this.hasEventListener("stagemouseup"))e=new createjs.MouseEvent("stagemouseup",d.x,d.y,this,b,a,a==this._primaryPointerID,d.rawX,d.rawY),this.onMouseUp&&this.onMouseUp(e),this.dispatchEvent(e);var f=d.event;if(f&&(f.onMouseUp||f.hasEventListener("mouseup")))e=new createjs.MouseEvent("mouseup",d.x,d.y,f.target,b,a,a==this._primaryPointerID,d.rawX,d.rawY),f.onMouseUp&&f.onMouseUp(e),f.dispatchEvent(e,f.target);if((f=d.target)&&(f.onClick||f.hasEventListener("click"))&&this._getObjectsUnderPoint(d.x, + d.y,null,!0,this._mouseOverIntervalID?3:1)==f)e=new createjs.MouseEvent("click",d.x,d.y,f,b,a,a==this._primaryPointerID,d.rawX,d.rawY),f.onClick&&f.onClick(e),f.dispatchEvent(e);c?(a==this._primaryPointerID&&(this._primaryPointerID=null),delete this._pointerData[a]):d.event=d.target=null};b._handleMouseDown=function(a){this._handlePointerDown(-1,a,!1)};b._handlePointerDown=function(a,b,c,d){var e=this._getPointerData(a);null!=d&&this._updatePointerPosition(a,c,d);if(this.onMouseDown||this.hasEventListener("stagemousedown"))c= + new createjs.MouseEvent("stagemousedown",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseDown&&this.onMouseDown(c),this.dispatchEvent(c);if(d=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1))if(e.target=d,d.onPress||d.hasEventListener("mousedown"))if(c=new createjs.MouseEvent("mousedown",e.x,e.y,d,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onPress&&d.onPress(c),d.dispatchEvent(c),c.onMouseMove||c.onMouseUp||c.hasEventListener("mousemove")||c.hasEventListener("mouseup"))e.event= + c};b._testMouseOver=function(){if(-1==this._primaryPointerID&&!(this.mouseX==this._mouseOverX&&this.mouseY==this._mouseOverY&&this.mouseInBounds)){var a=null;this.mouseInBounds&&(a=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY);var b=this._mouseOverTarget;if(b!=a){var c=this._getPointerData(-1);if(b&&(b.onMouseOut||b.hasEventListener("mouseout"))){var d=new createjs.MouseEvent("mouseout",c.x,c.y,b,null,-1,c.rawX,c.rawY);b.onMouseOut&& + b.onMouseOut(d);b.dispatchEvent(d)}b&&(this.canvas.style.cursor="");if(a&&(a.onMouseOver||a.hasEventListener("mouseover")))d=new createjs.MouseEvent("mouseover",c.x,c.y,a,null,-1,c.rawX,c.rawY),a.onMouseOver&&a.onMouseOver(d),a.dispatchEvent(d);a&&(this.canvas.style.cursor=a.cursor||"");this._mouseOverTarget=a}}};b._handleDoubleClick=function(a){var b=this._getPointerData(-1),c=this._getObjectsUnderPoint(b.x,b.y,null,this._mouseOverIntervalID?3:1);if(c&&(c.onDoubleClick||c.hasEventListener("dblclick")))evt= + new createjs.MouseEvent("dblclick",b.x,b.y,c,a,-1,!0,b.rawX,b.rawY),c.onDoubleClick&&c.onDoubleClick(evt),c.dispatchEvent(evt)};createjs.Stage=c})();this.createjs=this.createjs||{}; + (function(){var c=function(a){this.initialize(a)},b=c.prototype=new createjs.DisplayObject;b.image=null;b.snapToPixel=!0;b.sourceRect=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();"string"==typeof a?(this.image=new Image,this.image.src=a):this.image=a};b.isVisible=function(){var a=this.cacheCanvas||this.image&&(this.image.complete||this.image.getContext||2<=this.image.readyState);return!(!this.visible||!(0=d){var e=a.next;this._dispatchAnimationEnd(a,b,c,e,d-1)||(e?this._goto(e):(this.paused=!0,this.currentAnimationFrame=a.frames.length-1,this.currentFrame= + a.frames[this.currentAnimationFrame]))}else this.currentFrame=a.frames[this.currentAnimationFrame];else d=this.spriteSheet.getNumFrames(),b>=d&&!this._dispatchAnimationEnd(a,b,c,d-1)&&(this.currentFrame=0)};b._dispatchAnimationEnd=function(a,b,c,d,e){var f=a?a.name:null;this.onAnimationEnd&&this.onAnimationEnd(this,f,d);this.dispatchEvent({type:"animationend",name:f,next:d});!c&&this.paused&&(this.currentAnimationFrame=e);return this.paused!=c||this._animation!=a||this.currentFrame!=b};b.DisplayObject_cloneProps= + b.cloneProps;b.cloneProps=function(a){this.DisplayObject_cloneProps(a);a.onAnimationEnd=this.onAnimationEnd;a.currentFrame=this.currentFrame;a.currentAnimation=this.currentAnimation;a.paused=this.paused;a.offset=this.offset;a._animation=this._animation;a.currentAnimationFrame=this.currentAnimationFrame};b._goto=function(a){if(isNaN(a)){var b=this.spriteSheet.getAnimation(a);b&&(this.currentAnimationFrame=0,this._animation=b,this.currentAnimation=a,this._normalizeFrame())}else this.currentAnimation= + this._animation=null,this.currentFrame=a};createjs.BitmapAnimation=c})();this.createjs=this.createjs||{}; + (function(){var c=function(a){this.initialize(a)},b=c.prototype=new createjs.DisplayObject;b.graphics=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();this.graphics=a?a:new createjs.Graphics};b.isVisible=function(){var a=this.cacheCanvas||this.graphics&&!this.graphics.isEmpty();return!(!this.visible||!(0this.lineWidth?(b&&this._drawTextLine(a,j,e*d),e++,j=k[l+1]):j+=k[l]+k[l+1];b&&this._drawTextLine(a,j,e*d)}e++}return e};b._drawTextLine=function(a,b,c){this.outline?a.strokeText(b,0,c,this.maxWidth||65535):a.fillText(b,0,c,this.maxWidth||65535)};createjs.Text=c})();this.createjs=this.createjs||{}; + (function(){var c=function(){throw"SpriteSheetUtils cannot be instantiated";};c._workingCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");c._workingContext=c._workingCanvas.getContext("2d");c.addFlippedFrames=function(b,a,m,g){if(a||m||g){var d=0;a&&c._flip(b,++d,!0,!1);m&&c._flip(b,++d,!1,!0);g&&c._flip(b,++d,!0,!0)}};c.extractFrame=function(b,a){isNaN(a)&&(a=b.getAnimation(a).frames[0]);var m=b.getFrame(a);if(!m)return null;var g=m.rect,d=c._workingCanvas;d.width= + g.width;d.height=g.height;c._workingContext.drawImage(m.image,g.x,g.y,g.width,g.height,0,0,g.width,g.height);m=new Image;m.src=d.toDataURL("image/png");return m};c.mergeAlpha=function(b,a,c){c||(c=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));c.width=Math.max(a.width,b.width);c.height=Math.max(a.height,b.height);var g=c.getContext("2d");g.save();g.drawImage(b,0,0);g.globalCompositeOperation="destination-in";g.drawImage(a,0,0);g.restore();return c};c._flip=function(b, + a,m,g){for(var d=b._images,e=c._workingCanvas,f=c._workingContext,h=d.length/a,k=0;kthis.maxHeight)throw c.ERR_DIMENSIONS;for(var d=0,e=0,f=0;g.length;){var h=this._fillRow(g,d,f,b,a);h.w>e&&(e=h.w);d+=h.h;if(!h.h||!g.length){var k=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");k.width=this._getSize(e,this.maxWidth);k.height=this._getSize(d,this.maxHeight);this._data.images[f]=k;h.h||(e=d=0,f++)}}};b._getSize=function(a,b){for(var c=4;Math.pow(2,++c)f)throw c.ERR_DIMENSIONS;t>h||k+p>f||(n.img=g,n.rect=new createjs.Rectangle(k,b,p,t),j=j||t,a.splice(l,1),d[n.index]=[k,b,p,t,g,Math.round(-r+q*s.regX-e),Math.round(-u+q*s.regY-e)],k+=p)}return{w:k,h:j}};b._endBuild=function(){this.spriteSheet=new createjs.SpriteSheet(this._data); + this._data=null;this.progress=1;this.onComplete&&this.onComplete(this);this.dispatchEvent("complete")};b._run=function(){for(var a=50*Math.max(0.01,Math.min(0.99,this.timeSlice||0.3)),b=(new Date).getTime()+a,c=!1;b>(new Date).getTime();)if(!this._drawNext()){c=!0;break}if(c)this._endBuild();else{var d=this;this._timerID=setTimeout(function(){d._run()},50-a)}a=this.progress=this._index/this._frames.length;this.onProgress&&this.onProgress(this,a);this.dispatchEvent({type:"progress",progress:a})};b._drawNext= + function(){var a=this._frames[this._index],b=a.scale*this._scale,c=a.rect,d=a.sourceRect,e=this._data.images[a.img].getContext("2d");a.funct&&a.funct.apply(a.scope,a.params);e.save();e.beginPath();e.rect(c.x,c.y,c.width,c.height);e.clip();e.translate(Math.ceil(c.x-d.x*b),Math.ceil(c.y-d.y*b));e.scale(b,b);a.source.draw(e);e.restore();return++this._index' + (status[e.status] || def) + '
') + .appendTo($container); + } + }) + .always(function () { + if (that && that.$progress && that.$progress.parent().length > 0) { + that.$progress.remove(); + } + }) + .progress(function () { + if (that && (!that.$progress || that.$progress.parent().length === 0)) { + that.$progress = jQuery('
fetching data...
') + .appendTo($container); + } + }); + } + }; + /** + * @param {!object} JSON data to filter + * @param {!Date|number} maximum threshold value for filtering + * @param {!Date|number} minimum threshold value for filtering + * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + * @param {=number} the number of set of Y data + * @param {boolean} true if you do not want to unify data into a weekly data. + * @return {object} filtered JSON data + */ + ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { + var str, hash = {}; + + yLength = yLength || 1; + jQuery.each(data, function (i, v) { + var td, key; + td = ChartAPI.Date.parse(v.x); + if (td && td >= min && td <= max) { + if (noConcat) { + key = ChartAPI.Date.createId(td, 'daily'); + hash[key] = v; } else { - cloneData = jQuery.extend({}, data); + if (u === 'weekly') { + td = ChartAPI.Date.getWeekStartday(td); + } + key = ChartAPI.Date.createId(td, u); + if (hash[key]) { + for (i = 0; i < yLength; i++) { + str = i ? 'y' + i : 'y'; + hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); + } + } else { /* clone the object to prevent changing original */ + hash[key] = jQuery.extend({}, v); + } } } - callback(cloneData); - }) - .fail(function (e) { - status = { - '404': 'Data is not found', - '403': 'Data is forbidden to access' - }; - def = 'Some error occured in the data fetching process'; - errorClassName = e.status ? 'error-' + e.status : 'error-unknown'; - if (that) { - that.$errormsg = jQuery('
' + (status[e.status] || def) + '
') - .appendTo($container); + }); + return hash; + }; + + ChartAPI.Date = {}; + + /** + * return the week start day + * @param {!Date} + * @return Date + */ + ChartAPI.Date.getWeekStartday = function (d) { + return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); + }; + + /** + * return Date string array with padding zero which is for ISO 8601 string + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Array.} + */ + ChartAPI.Date.zeroPadArray = function (d, unit) { + var array; + ({ + 'yearly': function () { + array = [d.getFullYear()]; + }, + 'monthly': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'quarter': function () { + array = [d.getFullYear(), d.getMonth() + 1]; + }, + 'weekly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; + }, + 'daily': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; + }, + 'hourly': function () { + array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; } - }) - .always(function () { - if (that && that.$progress && that.$progress.parent().length > 0) { - that.$progress.remove(); + })[unit](); + return jQuery.map(array, function (v) { + v = v.toString(); + return v.length === 1 ? '0' + v : v; + }); + }; + + /** + * return uniformalized Date string to use kinds of Date ID + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createId = function (d, u) { + return ChartAPI.Date.zeroPadArray(d, u).join(''); + }; + + /** + * return uniformalized Date string to use kinds of Date label + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {string} + */ + ChartAPI.Date.createXLabel = function (d, u) { + var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); + if (u === 'hourly') { + hour = array.pop(); + str = array.join('-') + ' ' + hour + ':00'; + } else { + str = array.join('-'); + } + return str; + }; + + /** + * parse argument and return back Date object + * reformeded date string and try again when Date.parser returns NaN or Invalid + * @param {Date|number|string|null} + * @return {Date|null} + */ + ChartAPI.Date.parse = function (d) { + var date; + if (!d || d instanceof Date) { + date = d || null; + } else if (typeof d === 'number') { + date = new Date(d); + } else { + date = new Date(Date.parse(d.toString())); + } + if (date && /NaN|Invalid Date/.test(date.toString())) { + date = d.replace(/-/g, '/').split('+')[0]; + if (date.split('/').length === 1) { + // parse the string like 20130305T00:00:00 + date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); + date = [date[1], date[2], date[3]].join('/'); } - }) - .progress(function () { - if (that && (!that.$progress || that.$progress.parent().length === 0)) { - that.$progress = jQuery('
fetching data...
') - .appendTo($container); + if (date.split('/').length === 2) { + date = date + '/01'; } - }); - } -}; -/** - * @param {!object} JSON data to filter - * @param {!Date|number} maximum threshold value for filtering - * @param {!Date|number} minimum threshold value for filtering - * @param {!string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - * @param {=number} the number of set of Y data - * @param {boolean} true if you do not want to unify data into a weekly data. - * @return {object} filtered JSON data - */ -ChartAPI.Data.filterData = function (data, max, min, u, yLength, noConcat) { - var str, hash = {}; - - yLength = yLength || 1; - jQuery.each(data, function (i, v) { - var td, key; - td = ChartAPI.Date.parse(v.x); - if (td && td >= min && td <= max) { - if (noConcat) { - key = ChartAPI.Date.createId(td, 'daily'); - hash[key] = v; - } else { - if (u === 'weekly') { - td = ChartAPI.Date.getWeekStartday(td); - } - key = ChartAPI.Date.createId(td, u); - if (hash[key]) { - for (i = 0; i < yLength; i++) { - str = i ? 'y' + i : 'y'; - hash[key][str] = parseInt(hash[key][str], 10) + parseInt(v[str], 10); - } - } else { /* clone the object to prevent changing original */ - hash[key] = jQuery.extend({}, v); - } + date = jQuery.each(date.split('/'), function (i, v) { + return v.length === 1 ? '0' + v : v; + }).join('/'); + date = new Date(Date.parse(date)); + } + return date; + }; + + /** + * @param {!Date} + * @param {!number} number of data + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} calculates as start date when true + * @return {Date} + */ + ChartAPI.Date.calcDate = function (date, l, u, sym) { + var y, m, d, h; + y = date.getFullYear(); + m = date.getMonth(); + d = date.getDate(); + h = 0; + l = l - 1; + sym = sym ? -1 : 1; + ({ + 'yearly': function () { + y = y + (sym * l); + }, + 'monthly': function () { + m = m + (sym * l); + }, + 'quarter': function () { + m = m + (sym * l * 4); + }, + 'weekly': function () { + d = d + (sym * l * 7) - date.getDay(); + }, + 'daily': function () { + d = d + (sym * l); + }, + 'hourly': function () { + h = date.getHours() + (sym * l); } + })[u](); + return new Date(y, m, d, h); + }; + + ChartAPI.Range = {}; + /** + * return unified Range data object (plain object which does not have prototyped method) + * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.factory = function (obj) { + var fn; + obj = obj || {}; + obj.maxLength = obj.maxLength || 90; + obj.dataType = obj.dataType || 'timeline'; + obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); + fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; + return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); + }; + + ChartAPI.Range.generate = ChartAPI.Range.factory; + + /** + * @param {string|null} data type + * @return {boolean} + */ + ChartAPI.Range.isTimeline = function (dataType) { + return !dataType || dataType === 'timeline'; + }; + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { + unit = unit || 'monthly'; + length = length || (unit === 'hourly' ? 24 : 10); + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = maxLength; } - }); - return hash; -}; - - ChartAPI.Date = {}; - -/** - * return the week start day - * @param {!Date} - * @return Date - */ -ChartAPI.Date.getWeekStartday = function (d) { - return new Date(d.getFullYear(), d.getMonth(), d.getDate() - d.getDay()); -}; - -/** - * return Date string array with padding zero which is for ISO 8601 string - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Array.} - */ -ChartAPI.Date.zeroPadArray = function (d, unit) { - var array; - ({ - 'yearly': function () { - array = [d.getFullYear()]; - }, - 'monthly': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'quarter': function () { - array = [d.getFullYear(), d.getMonth() + 1]; - }, - 'weekly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate() - d.getDay()]; - }, - 'daily': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate()]; - }, - 'hourly': function () { - array = [d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours()]; - } - })[unit](); - return jQuery.map(array, function (v) { - v = v.toString(); - return v.length === 1 ? '0' + v : v; - }); -}; - -/** - * return uniformalized Date string to use kinds of Date ID - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createId = function (d, u) { - return ChartAPI.Date.zeroPadArray(d, u).join(''); -}; - -/** - * return uniformalized Date string to use kinds of Date label - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {string} - */ -ChartAPI.Date.createXLabel = function (d, u) { - var hour, str, array = ChartAPI.Date.zeroPadArray(d, u); - if (u === 'hourly') { - hour = array.pop(); - str = array.join('-') + ' ' + hour + ':00'; - } else { - str = array.join('-'); - } - return str; -}; - -/** - * parse argument and return back Date object - * reformeded date string and try again when Date.parser returns NaN or Invalid - * @param {Date|number|string|null} - * @return {Date|null} - */ -ChartAPI.Date.parse = function (d) { - var date; - if (!d || d instanceof Date) { - date = d || null; - } else if (typeof d === 'number') { - date = new Date(d); - } else { - date = new Date(Date.parse(d.toString())); - } - if (date && /NaN|Invalid Date/.test(date.toString())) { - date = d.replace(/-/g, '/').split('+')[0]; - if (date.split('/').length === 1) { - // parse the string like 20130305T00:00:00 - date = d.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/); - date = [date[1], date[2], date[3]].join('/'); + + s = ChartAPI.Date.parse(s); + e = ChartAPI.Date.parse(e); + + if (!s && !e) { + e = ChartAPI.Range.getEndDate(new Date(), unit); } - if (date.split('/').length === 2) { - date = date + '/01'; + + if (!s) { + s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); } - date = jQuery.each(date.split('/'), function (i, v) { - return v.length === 1 ? '0' + v : v; - }).join('/'); - date = new Date(Date.parse(date)); - } - return date; -}; - -/** - * @param {!Date} - * @param {!number} number of data - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} calculates as start date when true - * @return {Date} - */ -ChartAPI.Date.calcDate = function (date, l, u, sym) { - var y, m, d, h; - y = date.getFullYear(); - m = date.getMonth(); - d = date.getDate(); - h = 0; - l = l - 1; - sym = sym ? -1 : 1; - ({ - 'yearly': function () { - y = y + (sym * l); - }, - 'monthly': function () { - m = m + (sym * l); - }, - 'quarter': function () { - m = m + (sym * l * 4); - }, - 'weekly': function () { - d = d + (sym * l * 7) - date.getDay(); - }, - 'daily': function () { - d = d + (sym * l); - }, - 'hourly': function () { - h = date.getHours() + (sym * l); - } - })[u](); - return new Date(y, m, d, h); -}; - - ChartAPI.Range = {}; -/** - * return unified Range data object (plain object which does not have prototyped method) - * @param {{start: string|number|Date|null, end: string|number|Date|null, length: string|number|null, maxLength: string|number|null, unit: string|null, dataType: string|null}} - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.factory = function (obj) { - var fn; - obj = obj || {}; - obj.maxLength = obj.maxLength || 90; - obj.dataType = obj.dataType || 'timeline'; - obj.isTimeline = ChartAPI.Range.isTimeline(obj.dataType); - fn = obj.isTimeline ? ChartAPI.Range.calcDate : ChartAPI.Range.calcNum; - return fn(obj.start, obj.end, obj.length, obj.maxLength, obj.unit, obj.dataType, obj.autoSized); -}; - -ChartAPI.Range.generate = ChartAPI.Range.factory; - -/** - * @param {string|null} data type - * @return {boolean} - */ -ChartAPI.Range.isTimeline = function (dataType) { - return !dataType || dataType === 'timeline'; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcDate = function (s, e, length, maxLength, unit, dataType, autoSized) { - unit = unit || 'monthly'; - length = length || (unit === 'hourly' ? 24 : 10); - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = maxLength; - } - - s = ChartAPI.Date.parse(s); - e = ChartAPI.Date.parse(e); - - if (!s && !e) { - e = ChartAPI.Range.getEndDate(new Date(), unit); - } - - if (!s) { - s = ChartAPI.Range.getStartDate(ChartAPI.Date.calcDate(e, length, unit, true), unit); - } - if (!e) { - e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); - } - if (e > new Date()) { - e = new Date(); - } - if (s > e) { - s = e; - } - length = ChartAPI.Range.getLength(s, e, unit); - if (length > maxLength) { - length = maxLength; - s = ChartAPI.Date.calcDate(e, length, unit, true); - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - unit: unit, - dataType: dataType, - max: ChartAPI.Range.getEndDate(e, unit), - min: ChartAPI.Range.getStartDate(s, unit), - isTimeline: true + if (!e) { + e = ChartAPI.Range.getEndDate(ChartAPI.Date.calcDate(s, length, unit, false), unit); + } + if (e > new Date()) { + e = new Date(); + } + if (s > e) { + s = e; + } + length = ChartAPI.Range.getLength(s, e, unit); + if (length > maxLength) { + length = maxLength; + s = ChartAPI.Date.calcDate(e, length, unit, true); + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + unit: unit, + dataType: dataType, + max: ChartAPI.Range.getEndDate(e, unit), + min: ChartAPI.Range.getStartDate(s, unit), + isTimeline: true + }; }; -}; - -/** - * @param {=Date|null} start date - * @param {=Date|null} end date - * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null - * @param {=number|null} maxinum length for data - * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {boolean} when true, auto caliculate length of data according to window width - * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} - */ -ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { - length = length || 10; - - if (autoSized) { - var width = jQuery(window).width(); - maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); - length = Math.min(length, maxLength); - } - - if (!s && !e) { - s = 0; - e = length - 1; - } - - s = parseInt(s, 10) || (s === 0 ? 0 : null); - e = parseInt(e, 10) || (e === 0 ? 0 : null); - - if (s === null) { - s = e - length; - if (s < 0) { + + /** + * @param {=Date|null} start date + * @param {=Date|null} end date + * @param {=number|null} length: number of data from start date or end date. length is required when both start and end dates are null + * @param {=number|null} maxinum length for data + * @param {=string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {boolean} when true, auto caliculate length of data according to window width + * @return {{start: Date, end: Date, length: number, maxLength: number, unit: string, dataType: string, max: Date|number, min: Date|number, isTimeline: boolean}} + */ + ChartAPI.Range.calcNum = function (s, e, length, maxLength, unit, dataType, autoSized) { + length = length || 10; + + if (autoSized) { + var width = jQuery(window).width(); + maxLength = Math.min(Math.ceil(width * 0.021875), maxLength); + length = Math.min(length, maxLength); + } + + if (!s && !e) { s = 0; + e = length - 1; } - } - if (e === null) { - e = s + length; - } - if (s > e) { - s = e; - } - length = e - s + 1; - if (length > maxLength) { - length = maxLength; - s = e - maxLength; - } - return { - start: s, - end: e, - length: length, - maxLength: maxLength, - dataType: dataType, - unit: null, - max: e, - min: s, - isTimeline: false - }; -}; - -/** - * return start date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getStartDate = function (d, unit) { - var start, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - start = new Date(year, 0, 1, 0, 0, 0); - }, - 'monthly': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'quarter': function () { - start = new Date(year, month, 1, 0, 0, 0); - }, - 'weekly': function () { - start = new Date(year, month, date - d.getDay(), 0, 0, 0); - }, - 'daily': function () { - start = new Date(year, month, date, 0, 0, 0); - }, - 'hourly': function () { - start = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return start; -}; - -/** - * return end date within the date's unit range - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @return {Date} - */ -ChartAPI.Range.getEndDate = function (d, unit) { - var end, year = d.getFullYear(), - month = d.getMonth(), - date = d.getDate(); - ({ - 'yearly': function () { - end = new Date(year, 11, 31, 23, 59, 59); - }, - 'monthly': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'quarter': function () { - end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); - }, - 'weekly': function () { - end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); - }, - 'daily': function () { - end = new Date(year, month, date, 23, 59, 59); - }, - 'hourly': function () { - end = new Date(year, month, date, d.getHours(), 0, 0); - } - })[unit](); - return end < new Date() ? end : new Date(); -}; - -/** - * return next date against the desinated range unit - * @param {Date} start date - * @param {Date} end date - * @param {number} increment number from start date - * @param {string} data u - * @return {Date} - */ -ChartAPI.Range.getNextDate = function (s, e, i, u) { - var d, year = s.getFullYear(), - month = s.getMonth(), - date = s.getDate(); - ({ - 'yearly': function (i) { - d = new Date(year + i, 0, 1); - }, - 'monthly': function (i) { - d = new Date(year, month + i, 1); - }, - 'quarter': function (i) { - d = new Date(year, month + i * 4, 1); - }, - 'weekly': function (i) { - d = new Date(year, month, date + i * 7 - s.getDay()); - }, - 'daily': function (i) { - d = new Date(year, month, date + i); - }, - 'hourly': function (i) { - d = new Date(year, month, date, s.getHours() + i); - } - })[u](i); - return d < e ? d : null; -}; - -/** - * return max and min value in JSON data - * @param {!object} JSON data - * @param {=boolean} true when data type is timeline - * @return {{max:number, min:number}} - */ -ChartAPI.Range.getDataRange = function (data, isTimeline) { - var map, max, min; - - if (isTimeline) { - map = jQuery.map(data, function (v) { - return ChartAPI.Date.parse(v.x) - .valueOf(); - }); - max = Math.max.apply(null, map); - min = Math.min.apply(null, map); - } else { - min = 0; - max = data.length - 1; - } - - return { - max: max, - min: min + + s = parseInt(s, 10) || (s === 0 ? 0 : null); + e = parseInt(e, 10) || (e === 0 ? 0 : null); + + if (s === null) { + s = e - length; + if (s < 0) { + s = 0; + } + } + if (e === null) { + e = s + length; + } + if (s > e) { + s = e; + } + length = e - s + 1; + if (length > maxLength) { + length = maxLength; + s = e - maxLength; + } + return { + start: s, + end: e, + length: length, + maxLength: maxLength, + dataType: dataType, + unit: null, + max: e, + min: s, + isTimeline: false + }; }; -}; - -/** - * return number of data between start and end date - * @param {!Date} - * @param {!Date} - * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) - * @param {number} - */ -ChartAPI.Range.getLength = function (s, e, u) { - var length; - ({ - 'yearly': function () { - length = Math.ceil(e.getFullYear() - s.getFullYear()); - }, - 'monthly': function () { - length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); - }, - 'quarter': function () { - length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); - }, - 'weekly': function () { - length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); - }, - 'daily': function () { - length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); - }, - 'hourly': function () { - length = Math.ceil((e - s) / (60 * 60 * 1000)); - } - })[u](); - return length > 0 ? length + 1 : 1; -}; - + /** - * Creates Graph Object - * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this - * $container is the jQuery object to which the graph append - * $('#graphContainer').trigger('APPEND_TO',[$container]) - * you want to update graph as well, fire UPDATE event like the same manner above. - * - * @param {object} graph setings - * @param {object} object including range settings - * @return {jQuery} return container jQuery object - * @constructor - */ -ChartAPI.Graph = function (config, range) { - this.config = $.extend({ - type: 'morris.bar', - staticPath: '', - data: 'graph.json' - }, config); - - this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config.yLength = parseInt(this.config.yLength, 10) || 1; - - this.range = ChartAPI.Range.generate(range); - - if (typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - this.graphData = {}; - this.graphData[this.range.unit] = $.Deferred(); - - this.getData($.proxy(function (data) { - this.graphData[this.range.unit].resolve(this.generateGraphData(data)); - }, this)); - - this.$graphContainer = $('
'); - + * return start date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} + */ + ChartAPI.Range.getStartDate = function (d, unit) { + var start, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + start = new Date(year, 0, 1, 0, 0, 0); + }, + 'monthly': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'quarter': function () { + start = new Date(year, month, 1, 0, 0, 0); + }, + 'weekly': function () { + start = new Date(year, month, date - d.getDay(), 0, 0, 0); + }, + 'daily': function () { + start = new Date(year, month, date, 0, 0, 0); + }, + 'hourly': function () { + start = new Date(year, month, date, d.getHours(), 0, 0); + } + })[unit](); + return start; + }; + /** - * @return {jQuery} return jQuery object for chaining - * update graph + * return end date within the date's unit range + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @return {Date} */ - this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { - this.update_(newRange, unit); - return $(this.$graphContainer); - }, this)); - - this.$graphContainer.on('REMOVE', $.proxy(function () { - this.remove_(); - }, this)); - - // IE8 fires resize event even when document.body.innerWidht/innerHeight changing - // so check window.width and update only when window.width changing. - var windowWidth = $(window).width(); - this.updateFunc = $.proxy(function () { - if (windowWidth && windowWidth !== $(window).width()) { - windowWidth = $(window).width(); - this.update_(); - } - }, this); - - if (config.autoResize) { - $(window).on('orientationchange debouncedresize', this.updateFunc); - } - + ChartAPI.Range.getEndDate = function (d, unit) { + var end, year = d.getFullYear(), + month = d.getMonth(), + date = d.getDate(); + ({ + 'yearly': function () { + end = new Date(year, 11, 31, 23, 59, 59); + }, + 'monthly': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'quarter': function () { + end = new Date(new Date(year, month + 1, 1, 0, 0, 0).valueOf() - 1); + }, + 'weekly': function () { + end = new Date(year, month, date - d.getDay() + 6, 23, 59, 59); + }, + 'daily': function () { + end = new Date(year, month, date, 23, 59, 59); + }, + 'hourly': function () { + end = new Date(year, month, date, d.getHours(), 0, 0); + } + })[unit](); + return end < new Date() ? end : new Date(); + }; + /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback + * return next date against the desinated range unit + * @param {Date} start date + * @param {Date} end date + * @param {number} increment number from start date + * @param {string} data u + * @return {Date} */ - this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - + ChartAPI.Range.getNextDate = function (s, e, i, u) { + var d, year = s.getFullYear(), + month = s.getMonth(), + date = s.getDate(); + ({ + 'yearly': function (i) { + d = new Date(year + i, 0, 1); + }, + 'monthly': function (i) { + d = new Date(year, month + i, 1); + }, + 'quarter': function (i) { + d = new Date(year, month + i * 4, 1); + }, + 'weekly': function (i) { + d = new Date(year, month, date + i * 7 - s.getDay()); + }, + 'daily': function (i) { + d = new Date(year, month, date + i); + }, + 'hourly': function (i) { + d = new Date(year, month, date, s.getHours() + i); + } + })[u](i); + return d < e ? d : null; + }; + /** - * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback + * return max and min value in JSON data + * @param {!object} JSON data + * @param {=boolean} true when data type is timeline + * @return {{max:number, min:number}} */ - this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - $.proxy(this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); - }, this), this)); - return $(this.$graphContainer); - }, this)); - + ChartAPI.Range.getDataRange = function (data, isTimeline) { + var map, max, min; + + if (isTimeline) { + map = jQuery.map(data, function (v) { + return ChartAPI.Date.parse(v.x) + .valueOf(); + }); + max = Math.max.apply(null, map); + min = Math.min.apply(null, map); + } else { + min = 0; + max = data.length - 1; + } + + return { + max: max, + min: min + }; + }; + /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining + * return number of data between start and end date + * @param {!Date} + * @param {!Date} + * @param {!string} unit type (yearly|quarter|monthly|weekly|daily|hourly) + * @param {number} */ - this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { - this.$graphContainer.appendTo(container); - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (this.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.start <= v.timestamp && v.timestamp <= this.range.end; - }, this)); - } else { - filteredData = data.slice(this.range.min, this.range.max + 1); - } - this.draw_(filteredData); - }, this)); - return $(this.$graphContainer); - }, this)); - - return this.$graphContainer; -}; - -/** - * call getData function for getting graph JSON data - * @param {Function} callback function recieve graph JSON data - */ -ChartAPI.Graph.prototype.getData = function (callback) { - ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); -}; - -/** - * return data label array with array indexes - * @param {!Array.} array of indexes - * @param {!Array.} graph JSON data - * @return {Array.} - */ -ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''); - $.each(data, function (i, v) { - total = total + parseInt((v[str] || v.value || 0), 10); - }); - return total; -}; - -/** - * return the delta number and className between last and last second count - * @param {!object} graph JSON data - * @param {!number} number of set of Y data - * @return {y:[number,string],y1:[number,string]} - */ -ChartAPI.Graph.prototype.getDelta_ = function (data, index) { - var e, s, delta, key, length = data.length; - - key = 'y' + (index || ''); - e = data[length - 1]; - s = data[length - 2]; - delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; - return delta === undefined ? '' : delta; -}; - -ChartAPI.Graph.presetColors = function () { - return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; -}; - -ChartAPI.Graph.getChartColors = function (colors, type) { - var func = { - 'reverse': function (arr) { - return arr.reverse(); - }, - 'shuffle': function (arr) { - var i, j, length, tmp; - length = arr.length; - for (i = 0; i < length; i++) { - j = Math.floor(Math.random() * length); - tmp = arr[i]; - arr[i] = arr[j]; - arr[j] = tmp; + ChartAPI.Range.getLength = function (s, e, u) { + var length; + ({ + 'yearly': function () { + length = Math.ceil(e.getFullYear() - s.getFullYear()); + }, + 'monthly': function () { + length = Math.ceil(e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())); + }, + 'quarter': function () { + length = Math.ceil((e.getFullYear() * 12 + e.getMonth() - (s.getFullYear() * 12 + s.getMonth())) / 4); + }, + 'weekly': function () { + length = Math.ceil((ChartAPI.Date.getWeekStartday(e) - ChartAPI.Date.getWeekStartday(s)) / (7 * 24 * 60 * 60 * 1000)); + }, + 'daily': function () { + length = Math.ceil((e - s) / (24 * 60 * 60 * 1000)); + }, + 'hourly': function () { + length = Math.ceil((e - s) / (60 * 60 * 1000)); } - return arr; - }, - 'def': function (arr) { - return arr; - } + })[u](); + return length > 0 ? length + 1 : 1; }; - return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); -}; - -ChartAPI.Graph.cachedChartColors = {}; -ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { - return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); -}; - -/** - * Draw Graph - * @param {!Array.} graph data - * @param {=string} graph type (bar|line|area|donut) - * @return nothing - */ -ChartAPI.Graph.prototype.draw_ = function (data) { - var arr = this.config.type.split('.'); - var lib = arr[0]; - var method = arr[1]; - var config = this.config; - - if (config.label) { - if (this.labelTemplate) { - this.generateLabel(this.labelTemplate); + + /** + * Creates Graph Object + * If you want to draw graph, fire APPEND_GRAPH event for its container Element like this + * $container is the jQuery object to which the graph append + * $('#graphContainer').trigger('APPEND_TO',[$container]) + * you want to update graph as well, fire UPDATE event like the same manner above. + * + * @param {object} graph setings + * @param {object} object including range settings + * @return {jQuery} return container jQuery object + * @constructor + */ + ChartAPI.Graph = function (config, range) { + this.config = $.extend({ + type: 'morris.bar', + staticPath: '', + data: 'graph.json' + }, config); + + this.config.id = 'graph-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config.yLength = parseInt(this.config.yLength, 10) || 1; + + this.range = ChartAPI.Range.generate(range); + + if (typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); } else { - if (config.label.template) { - var labelTemplate = config.label.template; - if (window.require && typeof require === 'function') { - var templateType = config.label.type; - require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); - }, this)); - } else { - var dfd = $.get(config.staticPath + labelTemplate, 'text'); - ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { - this.labelTemplate = template; - this.generateLabel(template); - }, this)); - } - } else { - this.labelTemplate = ''; - this.generateLabel(this.labelTemplate); - } + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); } - } - - if (config.fallback && config.fallback.test) { - if (!ChartAPI.Graph.test[config.fallback.test]()) { - arr = config.fallback.type.split('.'); - lib = arr[0]; - method = arr[1]; - config = $.extend(config, config.fallback); + + this.graphData = {}; + this.graphData[this.range.unit] = $.Deferred(); + + this.getData($.proxy(function (data) { + this.graphData[this.range.unit].resolve(this.generateGraphData(data)); + }, this)); + + this.$graphContainer = $('
'); + + /** + * @return {jQuery} return jQuery object for chaining + * update graph + */ + this.$graphContainer.on('UPDATE', $.proxy(function (e, newRange, unit) { + this.update_(newRange, unit); + return $(this.$graphContainer); + }, this)); + + this.$graphContainer.on('REMOVE', $.proxy(function () { + this.remove_(); + }, this)); + + // IE8 fires resize event even when document.body.innerWidht/innerHeight changing + // so check window.width and update only when window.width changing. + var windowWidth = $(window).width(); + this.updateFunc = $.proxy(function () { + if (windowWidth && windowWidth !== $(window).width()) { + windowWidth = $(window).width(); + this.update_(); + } + }, this); + + if (config.autoResize) { + $(window).on('orientationchange debouncedresize', this.updateFunc); } - } - - if (config.chartColors && typeof config.chartColors === 'string') { - config.chartColors = config.chartColors.split(','); - } - - this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); -}; - -ChartAPI.Graph.test = {}; - -ChartAPI.Graph.test.canvas = function () { - var elem = document.createElement('canvas'); - return elem.getContext && elem.getContext('2d'); -}; - -ChartAPI.Graph.test.svg = function () { - var ns = { - 'svg': 'http://www.w3.org/2000/svg' + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$graphContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this), this)); + return $(this.$graphContainer); + }, this)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + this.$graphContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + $.proxy(this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this), this)); + return $(this.$graphContainer); + }, this)); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + this.$graphContainer.on('APPEND_TO', $.proxy(function (e, container) { + this.$graphContainer.appendTo(container); + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (this.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.start <= v.timestamp && v.timestamp <= this.range.end; + }, this)); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } + this.draw_(filteredData); + }, this)); + return $(this.$graphContainer); + }, this)); + + return this.$graphContainer; }; - return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; -}; - -/* - * this test checks suport both VML and SVG since we only use VML for SVG fallback - */ -ChartAPI.Graph.test.vml = function () { - var vmlSupported; - var svgSupported = ChartAPI.Graph.test.svg(); - // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser - if (!svgSupported) { - var a = document.body.appendChild(document.createElement('div')); - a.innerHTML = ''; - var b = a.firstChild; - b.style.behavior = "url(#default#VML)"; - vmlSupported = b ? typeof b.adj === "object" : true; - a.parentNode.removeChild(a); - } - return (svgSupported || vmlSupported); -}; - -ChartAPI.Graph.prototype.generateLabel = function (template) { - var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, - yLength = this.config.label.yLength || this.config.yLength, - dfd; - - var finalize = $.proxy(function () { - this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); - - this.getData($.proxy(function (data) { - for (var i = 0; i < yLength; i++) { - if (!this.config.label.hideTotalCount) { - this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + + /** + * call getData function for getting graph JSON data + * @param {Function} callback function recieve graph JSON data + */ + ChartAPI.Graph.prototype.getData = function (callback) { + ChartAPI.Data.getData(this.origData_, this.$graphContainer, callback, this); + }; + + /** + * return data label array with array indexes + * @param {!Array.} array of indexes + * @param {!Array.} graph JSON data + * @return {Array.} + */ + ChartAPI.Graph.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''); + $.each(data, function (i, v) { + total = total + parseInt((v[str] || v.value || 0), 10); + }); + return total; + }; + + /** + * return the delta number and className between last and last second count + * @param {!object} graph JSON data + * @param {!number} number of set of Y data + * @return {y:[number,string],y1:[number,string]} + */ + ChartAPI.Graph.prototype.getDelta_ = function (data, index) { + var e, s, delta, key, length = data.length; + + key = 'y' + (index || ''); + e = data[length - 1]; + s = data[length - 2]; + delta = (s && e && s[key]) ? e[key] - s[key] : e[key]; + return delta === undefined ? '' : delta; + }; + + ChartAPI.Graph.presetColors = function () { + return ['#6AAC2B', '#FFBE00', '#CF6DD3', '#8F2CFF', '#2D85FF', '#5584D4', '#5ED2B8', '#9CCF41', '#F87085', '#2C8087', '#8EEC6A', '#FFE700', '#FF5E19', '#FF4040', '#976BD6', '#503D99', '#395595']; + }; + + ChartAPI.Graph.getChartColors = function (colors, type) { + var func = { + 'reverse': function (arr) { + return arr.reverse(); + }, + 'shuffle': function (arr) { + var i, j, length, tmp; + length = arr.length; + for (i = 0; i < length; i++) { + j = Math.floor(Math.random() * length); + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } - if (!this.config.label.hideDeltaCount && this.range.isTimeline) { - this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + return arr; + }, + 'def': function (arr) { + return arr; + } + }; + return func[(type || 'def')](colors || ChartAPI.Graph.presetColors()); + }; + + ChartAPI.Graph.cachedChartColors = {}; + ChartAPI.Graph.getCachedChartColors = function (graphId, colors, type) { + return ChartAPI.Graph.cachedChartColors[graphId] = ChartAPI.Graph.cachedChartColors[graphId] || ChartAPI.Graph.getChartColors(colors, type); + }; + + /** + * Draw Graph + * @param {!Array.} graph data + * @param {=string} graph type (bar|line|area|donut) + * @return nothing + */ + ChartAPI.Graph.prototype.draw_ = function (data) { + var arr = this.config.type.split('.'); + var lib = arr[0]; + var method = arr[1]; + var config = this.config; + + if (config.label) { + if (this.labelTemplate) { + this.generateLabel(this.labelTemplate); + } else { + if (config.label.template) { + var labelTemplate = config.label.template; + if (window.require && typeof require === 'function') { + var templateType = config.label.type; + require([templateType + '!' + config.staticPath + labelTemplate], $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } else { + var dfd = $.get(config.staticPath + labelTemplate, 'text'); + ChartAPI.Data.getData(dfd, this.$graphContainer, $.proxy(function (template) { + this.labelTemplate = template; + this.generateLabel(template); + }, this)); + } + } else { + this.labelTemplate = ''; + this.generateLabel(this.labelTemplate); } } - }, this)); - }, this); - - if (data && typeof data === 'string') { - dfd = $.getJSON(this.config.staticPath + data); - } else { - dfd = $.Deferred(); - dfd.resolve(data); - } - - dfd.done(function (data) { - if (template && typeof template === 'function') { - template = template(data); - finalize(); - } else if (window._) { - template = _.template(template, data); - finalize(); - } else { - template = template; - finalize(); } - }); -}; - -/** - * update Graph - * @param {=Array.} - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Graph.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.range = ChartAPI.Range.generate({ - 'start': (newRange[0] || this.range.start), - 'end': (newRange[1] || this.range.end), - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': (unit || this.range.unit), - 'dataType': this.range.dataType, - 'autoSized': this.range.autoSized - }); - - this.graphData[this.range.unit].done($.proxy(function (data) { - var filteredData; - if (that.range.isTimeline) { - filteredData = $.grep(data, $.proxy(function (v) { - return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + + if (config.fallback && config.fallback.test) { + if (!ChartAPI.Graph.test[config.fallback.test]()) { + arr = config.fallback.type.split('.'); + lib = arr[0]; + method = arr[1]; + config = $.extend(config, config.fallback); + } + } + + if (config.chartColors && typeof config.chartColors === 'string') { + config.chartColors = config.chartColors.split(','); + } + + this.graphObject = ChartAPI.Graph[lib][method](data, config, this.range, this.$graphContainer); + }; + + ChartAPI.Graph.test = {}; + + ChartAPI.Graph.test.canvas = function () { + var elem = document.createElement('canvas'); + return elem.getContext && elem.getContext('2d'); + }; + + ChartAPI.Graph.test.svg = function () { + var ns = { + 'svg': 'http://www.w3.org/2000/svg' + }; + return !!document.createElementNS && !! document.createElementNS(ns.svg, 'svg').createSVGRect; + }; + + /* + * this test checks suport both VML and SVG since we only use VML for SVG fallback + */ + ChartAPI.Graph.test.vml = function () { + var vmlSupported; + var svgSupported = ChartAPI.Graph.test.svg(); + // http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser + if (!svgSupported) { + var a = document.body.appendChild(document.createElement('div')); + a.innerHTML = ''; + var b = a.firstChild; + b.style.behavior = "url(#default#VML)"; + vmlSupported = b ? typeof b.adj === "object" : true; + a.parentNode.removeChild(a); + } + return (svgSupported || vmlSupported); + }; + + ChartAPI.Graph.prototype.generateLabel = function (template) { + var data = this.config.label.template && this.config.label.data ? this.config.label.data : {}, + yLength = this.config.label.yLength || this.config.yLength, + dfd; + + var finalize = $.proxy(function () { + this.labels = new ChartAPI.Graph.Labels(this.$graphContainer, yLength, template); + + this.getData($.proxy(function (data) { + for (var i = 0; i < yLength; i++) { + if (!this.config.label.hideTotalCount) { + this.labels.getTotalObject(i).createTotalCount(this.getTotalCount_(data, i)); + } + if (!this.config.label.hideDeltaCount && this.range.isTimeline) { + this.labels.getTotalObject(i).createDeltaCount(this.getDelta_(data, i)); + } + } }, this)); + }, this); + + if (data && typeof data === 'string') { + dfd = $.getJSON(this.config.staticPath + data); } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + dfd = $.Deferred(); + dfd.resolve(data); } - this.draw_(filteredData); - }, this)); -}; - -ChartAPI.Graph.prototype.remove_ = function () { - if (this.config.autoResize) { - $(window).off('orientationchange debouncedresize', this.updateFunc); - } - if (this.graphObject && this.graphObject.remove) { - this.graphObject.remove(); - } - if (this.labels) { - this.labels.remove(); - } - this.$graphContainer.remove(); -}; - -ChartAPI.Graph.prototype.generateGraphData = function (data) { - var i, j, td, key, range = this.range, - start = range.start, - end = range.end, - u = range.unit, - length = range.length, - array = [], - yLength = this.config.yLength || 1, - filteredData, obj, str; - if (this.range.isTimeline) { - var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); - start = new Date(Math.min(this.range.min, dataRange.min)); - end = new Date(Math.max(this.range.max, dataRange.max)); - length = ChartAPI.Range.getLength(start, end, u); - filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); - - for (i = 0; i < length; i++) { - td = ChartAPI.Range.getNextDate(start, end, i, u); - if (td) { - key = ChartAPI.Date.createId(td, u); - obj = { - timestamp: td.valueOf(), - x: ChartAPI.Date.createXLabel(td, u) - }; - for (j = 0; j < yLength; j++) { - str = 'y' + (j || ''); - obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; - } - array.push(obj); + + dfd.done(function (data) { + if (template && typeof template === 'function') { + template = template(data); + finalize(); + } else if (window._) { + template = _.template(template, data); + finalize(); } else { - break; + template = template; + finalize(); } - } - } else { - array = data; - } - if (this.config.type === 'morris.donut') { - $.each(array, function (i, v) { - $.extend(v, { - label: (v.xLabel || v.x), - value: v.y - }); }); - } - return array; -}; - + }; + /** - * @param {!jQuery} - jQuery object to which attach label element(typically graph container) - * @param {!number} length of set of data to use - * @param {=string} html string to use label - * @constructor - */ -ChartAPI.Graph.Labels = function ($container, yLength, template) { - var i, key; - - this.$labelContainer = $('
'); - if (template) { - $('
').html(template).prependTo(this.$labelContainer); - } - - this.totals = {}; - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); - } - - this.$labelContainer.appendTo($container); -}; - -/** - * remove label container - */ -ChartAPI.Graph.Labels.prototype.remove = function () { - this.$labelContainer.remove(); -}; - -/** - * get ChartAPI.Graph.Labels.Total object - * @param {=number} the number of Y data set - * @return {ChartAPI.Graph.Labels.Total} - */ -ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { - return this.totals['y' + (i || '')]; -}; - -/** - * @constructor - * @param {!jQuery} jQuery object to attach - * @param {!number} number for identify what Y data is associated with - */ -ChartAPI.Graph.Labels.Total = function (container, index) { - this.index = index; - this.$totalContainer = jQuery('
').appendTo(container); -}; - -/** - * create element for displaying total count and append its container - * @param {!number} total count - */ -ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { - jQuery('' + count + ' ').appendTo(this.$totalContainer); -}; - -/** - * create element for displaying delta - * @param {!number} delta count - */ -ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { - var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; - - jQuery('(' + delta + ')').appendTo(this.$totalContainer); -}; - - ChartAPI.Graph.css = {}; - -ChartAPI.Graph.css.Base = function (data, config) { - this.len = data.length; - this.$graphEl = $('
'); -}; - -ChartAPI.Graph.css.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { - if (config.width) { - this.$graphEl.css({ - 'width': config.width, - 'max-width': '100%', - 'margin': '0 auto' + * update Graph + * @param {=Array.} + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.Graph.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); + } + if (this.labels) { + this.labels.remove(); + } + this.range = ChartAPI.Range.generate({ + 'start': (newRange[0] || this.range.start), + 'end': (newRange[1] || this.range.end), + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': (unit || this.range.unit), + 'dataType': this.range.dataType, + 'autoSized': this.range.autoSized }); - } - - var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], - barBackgroundColor = config.barBackgroundColor || '#f0f0f0', - dateColor = config.dateColor || '#999999', - dateColorSaturday = config.dateColorSaturday || dateColor, - dateColorSunday = config.dateColorSunday || dateColor, - labelColor = config.labelColor || '#999999', - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, - createCSSGraphBarEl = function () { - return $('
'); - }, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - label = $.map(data, function (d) { - return { - value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), - weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null + + this.graphData[this.range.unit].done($.proxy(function (data) { + var filteredData; + if (that.range.isTimeline) { + filteredData = $.grep(data, $.proxy(function (v) { + return this.range.min <= v.timestamp && v.timestamp <= this.range.max; + }, this)); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); } - }), - maxY = Math.max.apply(null, dataY) || 1, - yLabel = config.yLabel || dataY, - width, $el, $background, $bar, $count, $date; - - for (var i = this.len; i > 0;) { - i = i - 1; - width = Math.floor((dataY[i] / maxY) * 100) - 15; - $el = createCSSGraphBarEl(); - $background = $el.find('.css-graph-bar-background'); - $background.css({ - 'background-color': barBackgroundColor - }); - - if (config.showDate) { - $date = $el.find('.css-graph-date'); - $date.text(label[i].value).css({ - 'color': dateColor, - 'font-size': dateLabelSize + 'px', - 'line-height': barWidth + 'px' - }); - if (label[i].weekday === 6) { - $date.addClass('saturday').css({ - 'color': dateColorSaturday - }); - } else if (label[i].weekday === 0) { - $date.addClass('sunday').css({ - 'color': dateColorSunday - }) + this.draw_(filteredData); + }, this)); + }; + + ChartAPI.Graph.prototype.remove_ = function () { + if (this.config.autoResize) { + $(window).off('orientationchange debouncedresize', this.updateFunc); + } + if (this.graphObject && this.graphObject.remove) { + this.graphObject.remove(); + } + if (this.labels) { + this.labels.remove(); + } + this.$graphContainer.remove(); + }; + + ChartAPI.Graph.prototype.generateGraphData = function (data) { + var i, j, td, key, range = this.range, + start = range.start, + end = range.end, + u = range.unit, + length = range.length, + array = [], + yLength = this.config.yLength || 1, + filteredData, obj, str; + if (this.range.isTimeline) { + var dataRange = ChartAPI.Range.getDataRange(data, this.range.isTimeline); + start = new Date(Math.min(this.range.min, dataRange.min)); + end = new Date(Math.max(this.range.max, dataRange.max)); + length = ChartAPI.Range.getLength(start, end, u); + filteredData = ChartAPI.Data.filterData(data, dataRange.max, dataRange.min, u, yLength); + + for (i = 0; i < length; i++) { + td = ChartAPI.Range.getNextDate(start, end, i, u); + if (td) { + key = ChartAPI.Date.createId(td, u); + obj = { + timestamp: td.valueOf(), + x: ChartAPI.Date.createXLabel(td, u) + }; + for (j = 0; j < yLength; j++) { + str = 'y' + (j || ''); + obj[str] = filteredData[key] ? (filteredData[key][str] || 0) : 0; + } + array.push(obj); + } else { + break; + } } - - $el.find('.css-graph-bar-container').css({ - 'margin-left': barMarginLeft + 'px' + } else { + array = data; + } + if (this.config.type === 'morris.donut') { + $.each(array, function (i, v) { + $.extend(v, { + label: (v.xLabel || v.x), + value: v.y + }); }); } - - $bar = $el.find('.css-graph-bar'); - $bar.css({ - 'width': width + '%', - 'background-color': barColor - }); - $count = $el.find('.css-graph-bar-count'); - $count.text(yLabel[i]).css({ - 'color': labelColor, - 'font-size': labelSize + 'px', - 'line-height': barWidth + 'px' - }); - $el.appendTo(this.$graphEl); - } - - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { - var yLength = config.yLength, - barWidth = parseInt(config.barWidth, 10) || 30, - barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, - barInterval = parseInt(config.barInterval, 10) || 5, - labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, - dateColor = config.dateColor || '#999999', - barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - labelColors = config.labelColors, - labelClasses = config.labelClasses, - i, j, - d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; - - for (i = 0; i < this.len; i++) { - d = data[i]; - dataY = []; - totalY = 0; - totalWidth = 0; - for (j = 0; j < yLength; j++) { - dataY.push(d['y' + (j || '')]); - totalY = totalY + parseInt(d['y' + (j || '')], 10); + return array; + }; + + /** + * @param {!jQuery} + jQuery object to which attach label element(typically graph container) + * @param {!number} length of set of data to use + * @param {=string} html string to use label + * @constructor + */ + ChartAPI.Graph.Labels = function ($container, yLength, template) { + var i, key; + + this.$labelContainer = $('
'); + if (template) { + $('
').html(template).prependTo(this.$labelContainer); } - - $barContainer = $('
').appendTo(this.$graphEl); - if (config.showDate && d.x) { - label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); - $date = $('
' + label + '
').appendTo($barContainer); + + this.totals = {}; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + this.totals[key] = new ChartAPI.Graph.Labels.Total(this.$labelContainer, i); } - - $el = $('
').appendTo($barContainer); - - if (config.showDate) { - $el.css({ - 'margin-left': barMarginLeft + 'px' + + this.$labelContainer.appendTo($container); + }; + + /** + * remove label container + */ + ChartAPI.Graph.Labels.prototype.remove = function () { + this.$labelContainer.remove(); + }; + + /** + * get ChartAPI.Graph.Labels.Total object + * @param {=number} the number of Y data set + * @return {ChartAPI.Graph.Labels.Total} + */ + ChartAPI.Graph.Labels.prototype.getTotalObject = function (i) { + return this.totals['y' + (i || '')]; + }; + + /** + * @constructor + * @param {!jQuery} jQuery object to attach + * @param {!number} number for identify what Y data is associated with + */ + ChartAPI.Graph.Labels.Total = function (container, index) { + this.index = index; + this.$totalContainer = jQuery('
').appendTo(container); + }; + + /** + * create element for displaying total count and append its container + * @param {!number} total count + */ + ChartAPI.Graph.Labels.Total.prototype.createTotalCount = function (count) { + jQuery('' + count + ' ').appendTo(this.$totalContainer); + }; + + /** + * create element for displaying delta + * @param {!number} delta count + */ + ChartAPI.Graph.Labels.Total.prototype.createDeltaCount = function (delta) { + var deltaClass = delta ? (delta < 0 ? 'minus ' : 'plus ') : 'zero '; + + jQuery('(' + delta + ')').appendTo(this.$totalContainer); + }; + + ChartAPI.Graph.css = {}; + + ChartAPI.Graph.css.Base = function (data, config) { + this.len = data.length; + this.$graphEl = $('
'); + }; + + ChartAPI.Graph.css.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.css.Base.prototype.horizontalBar = function (data, config, range, $container) { + if (config.width) { + this.$graphEl.css({ + 'width': config.width, + 'max-width': '100%', + 'margin': '0 auto' }); } - - for (j = 0; j < yLength; j++) { - width = Math.floor((dataY[j] / totalY) * 1000) / 10; - - if (width) { - if (yLength === j) { - width = 100 - totalWidth; + + var barColor = config.barColor || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod)[1], + barBackgroundColor = config.barBackgroundColor || '#f0f0f0', + dateColor = config.dateColor || '#999999', + dateColorSaturday = config.dateColorSaturday || dateColor, + dateColorSunday = config.dateColorSunday || dateColor, + labelColor = config.labelColor || '#999999', + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateLabelSize = parseInt(config.dateLabelSize, 10) || labelSize, + createCSSGraphBarEl = function () { + return $('
'); + }, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + label = $.map(data, function (d) { + return { + value: parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(), + weekday: ChartAPI.Date.parse(d.x) ? ChartAPI.Date.parse(d.x).getDay() : null } - totalWidth = totalWidth + width; - - $bar = $('
'); - $bar.css({ - 'width': width + '%', - 'background-color': barColors[j] + }), + maxY = Math.max.apply(null, dataY) || 1, + yLabel = config.yLabel || dataY, + width, $el, $background, $bar, $count, $date; + + for (var i = this.len; i > 0;) { + i = i - 1; + width = Math.floor((dataY[i] / maxY) * 100) - 15; + $el = createCSSGraphBarEl(); + $background = $el.find('.css-graph-bar-background'); + $background.css({ + 'background-color': barBackgroundColor + }); + + if (config.showDate) { + $date = $el.find('.css-graph-date'); + $date.text(label[i].value).css({ + 'color': dateColor, + 'font-size': dateLabelSize + 'px', + 'line-height': barWidth + 'px' }); - - if (config.showCount) { - $bar.text(dataY[j]); - } - - if (labelClasses && labelClasses[j]) { - $bar.addClass(labelClasses[j]); + if (label[i].weekday === 6) { + $date.addClass('saturday').css({ + 'color': dateColorSaturday + }); + } else if (label[i].weekday === 0) { + $date.addClass('sunday').css({ + 'color': dateColorSunday + }) } - - if (labelColors && labelColors[j]) { + + $el.find('.css-graph-bar-container').css({ + 'margin-left': barMarginLeft + 'px' + }); + } + + $bar = $el.find('.css-graph-bar'); + $bar.css({ + 'width': width + '%', + 'background-color': barColor + }); + $count = $el.find('.css-graph-bar-count'); + $count.text(yLabel[i]).css({ + 'color': labelColor, + 'font-size': labelSize + 'px', + 'line-height': barWidth + 'px' + }); + $el.appendTo(this.$graphEl); + } + + this.$graphEl.appendTo($container); + }; + + ChartAPI.Graph.css.Base.prototype.ratioHorizontalBar = function (data, config, range, $container) { + var yLength = config.yLength, + barWidth = parseInt(config.barWidth, 10) || 30, + barMarginLeft = parseInt(config.barMarginLeft, 10) || 30, + barInterval = parseInt(config.barInterval, 10) || 5, + labelSize = parseInt(config.labelSize, 10) || barWidth * 0.45, + dateColor = config.dateColor || '#999999', + barColors = config.barColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + labelColors = config.labelColors, + labelClasses = config.labelClasses, + i, j, + d, dataY, totalY, $barContainer, $el, $bar, label, $date, width, totalWidth; + + for (i = 0; i < this.len; i++) { + d = data[i]; + dataY = []; + totalY = 0; + totalWidth = 0; + for (j = 0; j < yLength; j++) { + dataY.push(d['y' + (j || '')]); + totalY = totalY + parseInt(d['y' + (j || '')], 10); + } + + $barContainer = $('
').appendTo(this.$graphEl); + if (config.showDate && d.x) { + label = parseInt(d.x.substr(d.x.lastIndexOf('-') + 1), 10).toString(); + $date = $('
' + label + '
').appendTo($barContainer); + } + + $el = $('
').appendTo($barContainer); + + if (config.showDate) { + $el.css({ + 'margin-left': barMarginLeft + 'px' + }); + } + + for (j = 0; j < yLength; j++) { + width = Math.floor((dataY[j] / totalY) * 1000) / 10; + + if (width) { + if (yLength === j) { + width = 100 - totalWidth; + } + totalWidth = totalWidth + width; + + $bar = $('
'); $bar.css({ - 'color': labelColors[j] + 'width': width + '%', + 'background-color': barColors[j] }); + + if (config.showCount) { + $bar.text(dataY[j]); + } + + if (labelClasses && labelClasses[j]) { + $bar.addClass(labelClasses[j]); + } + + if (labelColors && labelColors[j]) { + $bar.css({ + 'color': labelColors[j] + }); + } + + $bar.appendTo($el); } - - $bar.appendTo($el); } + + $el.appendTo($barContainer); } - - $el.appendTo($barContainer); - } - this.$graphEl.appendTo($container); -}; - -ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { - var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); - var method = config.type.slice(config.type.lastIndexOf('.') + 1); - cssGraph[method](data, config, range, $container); - return cssGraph; -}; - + this.$graphEl.appendTo($container); + }; + + ChartAPI.Graph.css.horizontalBar = ChartAPI.Graph.css.ratioHorizontalBar = function (data, config, range, $container) { + var cssGraph = new ChartAPI.Graph.css.Base(data, config, range, $container); + var method = config.type.slice(config.type.lastIndexOf('.') + 1); + cssGraph[method](data, config, range, $container); + return cssGraph; + }; + ChartAPI.Graph.easel = {}; - -ChartAPI.Graph.easel.Base = function (data, config, range, $container) { - this.data = data; - this.config = config; - this.range = range; - this.$container = $container; - if (!window.createjs && typeof window.require === 'function') { - require(['easeljs'], $.proxy(function () { - this.buildCanvas(createjs); - }, this)); - } else { - var width = parseInt((config.width || $container.width()), 10); - - if (width) { - this.buildCanvas(createjs); + + ChartAPI.Graph.easel.Base = function (data, config, range, $container) { + this.data = data; + this.config = config; + this.range = range; + this.$container = $container; + if (!window.createjs && typeof window.require === 'function') { + require(['easeljs'], $.proxy(function () { + this.buildCanvas(createjs); + }, this)); } else { - setTimeout($.proxy(function () { + var width = parseInt((config.width || $container.width()), 10); + + if (width) { this.buildCanvas(createjs); - }, this), 100); - } - } -}; - -ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { - this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; - this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; - - this.$canvas = $('').appendTo(this.$container); - this.canvas = this.$canvas.get(0); - this.canvas.getContext('2d'); - - this.stage = this.graph = new createjs.Stage(this.canvas); - this.stage.update(); - var method = this.config.type.split('.')[1]; - this[method](this.data, this.config); -}; - -ChartAPI.Graph.easel.Base.prototype.remove = function () { - this.$canvas.remove(); -}; - -ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { - var length = data.length, - barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, - barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - barColor = this.convertColor(barColors[0], barColorAlpha), - barMargin = parseInt(config.barMargin, 10) || 10, - barContentWidth = Math.floor(this.width / length), - barWidth = barContentWidth - barMargin, - leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, - dataY = $.map(data, function (d) { - return parseInt(d.y, 10); - }), - maxY = Math.max.apply(null, dataY) || 1, - shape, - bar, - x, - y, - barHeight; - - for (var i = 0; i < length; i++) { - shape = new createjs.Shape(); - bar = shape.graphics; - x = i * barContentWidth + leftMargin; - barHeight = Math.floor(dataY[i] / maxY * this.height); - y = this.height - barHeight; - - bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); - this.stage.addChild(shape); - } - this.stage.update(); -}; - -ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { - var length = data.length, - lineWidth = parseInt(config.lineWidth, 10) || 8, - yLength = config.yLength || 1, - lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - lineColorsAlpha = config.chartColorsAlpha || [null], - pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), - pointerColorsAlpha = config.pointerColorsAlpha || [null], - pointerRadius = config.pointerRadius || 10, - paddingTop = lineWidth / 2, - paddingBottom = lineWidth / 2, - count = (length - 1) * 2, - moveX = Math.floor(this.width / length) / 2, - paddingLeft = (this.width - (moveX * count)) / 2, - height = this.height, - canvasInnerHeight, - dataYs = [], - dataY, - mapfunc = function (d) { - return parseInt(d['y' + (i || '')], 10); - }; - - if (config.drawPointer) { - paddingBottom = paddingBottom + pointerRadius; - } - - canvasInnerHeight = this.height - (paddingTop + paddingBottom); - - for (var i = 0; i < yLength; i++) { - dataY = $.map(data, mapfunc); - dataYs.push(dataY); - } - - var dataYAll = []; - $.each(dataYs, function (i, dataY) { - dataYAll = dataYAll.concat(dataY); - }); - - var maxY = Math.max.apply(null, dataYAll) || 1, - moveYs = []; - - var generateMoveY = function (dataY) { - var moveY = []; - $.each(dataY, function (i, y) { - if (i > 0) { - var prevY = dataY[i - 1]; - var medium = prevY + Math.floor((y - prevY) / 2); - - medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY = moveY.concat([medium, y]); } else { - y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; - moveY.push(y); + setTimeout($.proxy(function () { + this.buildCanvas(createjs); + }, this), 100); } - }); - return moveY; + } }; - - $.each(dataYs, function (i, dataY) { - moveYs.push(generateMoveY(dataY)); - }); - - var lineColor, - shapes = [], - lines = [], - x = paddingLeft, - y, - circles = [], - pointerColor; - - for (i = 0; i < yLength; i++) { - lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); - shapes[i] = new createjs.Shape(); - lines[i] = shapes[i].graphics; - y = height - moveYs[i][0]; - lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); - this.stage.addChild(shapes[i]); - if (config.drawPointer) { - pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); - circles[i] = new createjs.Shape(); - circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); - this.stage.addChild(circles[i]); + + ChartAPI.Graph.easel.Base.prototype.buildCanvas = function (createjs) { + this.width = parseInt((this.config.width || this.$container.width()), 10) || 300; + this.height = parseInt((this.config.height || this.$container.height()), 10) || 300; + + this.$canvas = $('').appendTo(this.$container); + this.canvas = this.$canvas.get(0); + this.canvas.getContext('2d'); + + this.stage = this.graph = new createjs.Stage(this.canvas); + this.stage.update(); + var method = this.config.type.split('.')[1]; + this[method](this.data, this.config); + }; + + ChartAPI.Graph.easel.Base.prototype.remove = function () { + this.$canvas.remove(); + }; + + ChartAPI.Graph.easel.Base.prototype.bar = function (data, config) { + var length = data.length, + barColorAlpha = config.chartColorsAlpha ? config.chartColorsAlpha[0] : 1, + barColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + barColor = this.convertColor(barColors[0], barColorAlpha), + barMargin = parseInt(config.barMargin, 10) || 10, + barContentWidth = Math.floor(this.width / length), + barWidth = barContentWidth - barMargin, + leftMargin = Math.floor((this.width - (barContentWidth * length)) / 2) + barMargin / 2, + dataY = $.map(data, function (d) { + return parseInt(d.y, 10); + }), + maxY = Math.max.apply(null, dataY) || 1, + shape, + bar, + x, + y, + barHeight; + + for (var i = 0; i < length; i++) { + shape = new createjs.Shape(); + bar = shape.graphics; + x = i * barContentWidth + leftMargin; + barHeight = Math.floor(dataY[i] / maxY * this.height); + y = this.height - barHeight; + + bar.beginFill(barColor).drawRect(x, y, barWidth, barHeight); + this.stage.addChild(shape); } - } - - var stage = this.stage; - - var tick = function (e) { - // if we are on the last frame of animation then remove the tick listener: - count = count - 1; - if (count === 0) { - createjs.Ticker.removeEventListener("tick", tick); + this.stage.update(); + }; + + ChartAPI.Graph.easel.Base.prototype.motionLine = function (data, config) { + var length = data.length, + lineWidth = parseInt(config.lineWidth, 10) || 8, + yLength = config.yLength || 1, + lineColors = config.lineColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + lineColorsAlpha = config.chartColorsAlpha || [null], + pointerColors = config.pointerColors || config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod), + pointerColorsAlpha = config.pointerColorsAlpha || [null], + pointerRadius = config.pointerRadius || 10, + paddingTop = lineWidth / 2, + paddingBottom = lineWidth / 2, + count = (length - 1) * 2, + moveX = Math.floor(this.width / length) / 2, + paddingLeft = (this.width - (moveX * count)) / 2, + height = this.height, + canvasInnerHeight, + dataYs = [], + dataY, + mapfunc = function (d) { + return parseInt(d['y' + (i || '')], 10); + }; + + if (config.drawPointer) { + paddingBottom = paddingBottom + pointerRadius; } - - x = x + moveX; - - var moveY; + + canvasInnerHeight = this.height - (paddingTop + paddingBottom); + for (var i = 0; i < yLength; i++) { - moveY = moveYs[i]; - y = height - moveY[moveY.length - count - 1]; - lines[i].lineTo(x, y); + dataY = $.map(data, mapfunc); + dataYs.push(dataY); + } + + var dataYAll = []; + $.each(dataYs, function (i, dataY) { + dataYAll = dataYAll.concat(dataY); + }); + + var maxY = Math.max.apply(null, dataYAll) || 1, + moveYs = []; + + var generateMoveY = function (dataY) { + var moveY = []; + $.each(dataY, function (i, y) { + if (i > 0) { + var prevY = dataY[i - 1]; + var medium = prevY + Math.floor((y - prevY) / 2); + + medium = Math.floor((medium / maxY) * canvasInnerHeight) + paddingBottom; + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY = moveY.concat([medium, y]); + } else { + y = Math.floor((y / maxY) * canvasInnerHeight) + paddingBottom; + moveY.push(y); + } + }); + return moveY; + }; + + $.each(dataYs, function (i, dataY) { + moveYs.push(generateMoveY(dataY)); + }); + + var lineColor, + shapes = [], + lines = [], + x = paddingLeft, + y, + circles = [], + pointerColor; + + for (i = 0; i < yLength; i++) { + lineColor = this.convertColor(lineColors[i], lineColorsAlpha[i]); + shapes[i] = new createjs.Shape(); + lines[i] = shapes[i].graphics; + y = height - moveYs[i][0]; + lines[i].setStrokeStyle(lineWidth).beginStroke(lineColor).moveTo(x, y); + this.stage.addChild(shapes[i]); if (config.drawPointer) { - circles[i].x = x; - circles[i].y = Math.max(y, pointerRadius); + pointerColor = this.convertColor(pointerColors[i], pointerColorsAlpha[i]); + circles[i] = new createjs.Shape(); + circles[i].graphics.beginFill(pointerColor).drawCircle(0, 0, pointerRadius); + this.stage.addChild(circles[i]); } } - - stage.update(e); + + var stage = this.stage; + + var tick = function (e) { + // if we are on the last frame of animation then remove the tick listener: + count = count - 1; + if (count === 0) { + createjs.Ticker.removeEventListener("tick", tick); + } + + x = x + moveX; + + var moveY; + for (var i = 0; i < yLength; i++) { + moveY = moveYs[i]; + y = height - moveY[moveY.length - count - 1]; + lines[i].lineTo(x, y); + if (config.drawPointer) { + circles[i].x = x; + circles[i].y = Math.max(y, pointerRadius); + } + } + + stage.update(e); + }; + + createjs.Ticker.useRAF = true; + createjs.Ticker.setFPS(30); + createjs.Ticker.addEventListener('tick', tick); }; - - createjs.Ticker.useRAF = true; - createjs.Ticker.setFPS(30); - createjs.Ticker.addEventListener('tick', tick); -}; - -ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { - if (str.indexOf('#') !== -1) { - var r = parseInt(str.substr(1, 2), 16), - g = parseInt(str.substr(3, 2), 16), - b = parseInt(str.substr(5, 2), 16); - - if (alpha) { - str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; + + ChartAPI.Graph.easel.Base.prototype.convertColor = function (str, alpha) { + if (str.indexOf('#') !== -1) { + var r = parseInt(str.substr(1, 2), 16), + g = parseInt(str.substr(3, 2), 16), + b = parseInt(str.substr(5, 2), 16); + + if (alpha) { + str = 'rgba(' + [r, g, b, alpha].join(',') + ')'; + } else { + str = 'rgb(' + [r, g, b].join(',') + ')'; + } + } else if (str.indexOf('rgb') !== -1) { + // wrap rgb/rgba string + if (str.split(',').length < 4) { + str = 'rgb(' + str + ')'; + } else { + str = 'rgba(' + str + ')'; + } + } + return str; + }; + + ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { + var count = 0; + + var splitData = function (length, data) { + length = length || 1; + var map = $.map(data, function (d) { + var obj = { + x: d.x + }, key, val; + + for (var i = 0; i < length; i++) { + key = 'y' + (i || ''); + val = 'y' + (count + i || ''); + obj[key] = d[val]; + } + return obj; + }); + count = count + length; + return map; + }; + + var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); + + $.each(config.mix, $.proxy(function (index, conf) { + var colors = { + chartColors: chartColors.slice(count, count + conf.yLength) + }; + var partialData = splitData(conf.yLength, data); + conf = $.extend({}, config, colors, conf); + this[conf.type](partialData, conf); + }, this)); + }; + + ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { + if (ChartAPI.Graph.test.canvas()) { + var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); + return easelGraph; } else { - str = 'rgb(' + [r, g, b].join(',') + ')'; + console.warn('EaselJS graph requires for HTML5 Canvas capability'); + $container.trigger('REMOVE'); } - } else if (str.indexOf('rgb') !== -1) { - // wrap rgb/rgba string - if (str.split(',').length < 4) { - str = 'rgb(' + str + ')'; + }; + + ChartAPI.Graph.morris = {}; + + ChartAPI.Graph.morris.Base = function (data, config, range, $container) { + if (!window.Morris && typeof window.require === 'function') { + require(['raphael', 'morris'], $.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this)); } else { - str = 'rgba(' + str + ')'; + var width = config.width || $container.width(); + if (width) { + this.build_(Morris, data, config, range, $container); + } else { + setTimeout($.proxy(function () { + this.build_(Morris, data, config, range, $container); + }, this), 100); + } } - } - return str; -}; - -ChartAPI.Graph.easel.Base.prototype.mix = function (data, config) { - var count = 0; - - var splitData = function (length, data) { - length = length || 1; - var map = $.map(data, function (d) { - var obj = { - x: d.x - }, key, val; - - for (var i = 0; i < length; i++) { - key = 'y' + (i || ''); - val = 'y' + (count + i || ''); - obj[key] = d[val]; + }; + + ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { + var i, + graphDefaults, graphConfig, + method = config.type.split('.')[1], + yLength = config.yLength, + width = config.width || $container.width() || 300, + height = config.height || $container.height() || 300; + + this.$graphEl = $('
').css({ + 'height': height + 'px', + 'width': width + 'px' + }).prependTo($container); + + config = $.extend({}, config, { + element: config.id, + data: data, + xkey: 'x', + labels: this.getYLabels_(yLength, config.labels), + ykeys: this.getYKeys_(yLength), + ymax: this.getYMax_(data, method, yLength), + ymin: config.ymin || 0, + lineWidth: parseInt(config.lineWidth, 10) || 6, + pointSize: parseInt(config.pointSize, 10) || 6, + smooth: config.smooth || false + }); + + config.barColors = config.barColors || this.getChartColors(config); + config.colors = config.colors || this.getChartColors(config); + config.lineColors = config.lineColors || this.getChartColors(config); + config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); + + config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; + if (!config.pointStrokeColors.length) { + for (i = 0; i < yLength; i++) { + config.pointStrokeColors.push('none'); + } + } + + graphDefaults = { + element: null, + data: null, + xkey: 'x', + labels: [], + ykeys: [], + + // gridDefaults + dateFormat: null, + axes: true, + grid: true, + gridLineColor: '#aaa', + gridStrokeWidth: 0.5, + gridTextColor: '#888', + gridTextSize: 12, + hideHover: false, + hoverCallback: null, + yLabelFormat: null, + numLines: 5, + padding: 25, + parseTime: true, + postUnits: '', + preUnits: '', + ymax: 'auto', + ymin: 'auto 0', + goals: [], + goalStrokeWidth: 1.0, + goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], + events: [], + eventStrokeWidth: 1.0, + eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], + + // Line defaults + lineWidth: 3, + pointSize: 4, + lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + pointWidths: [1], + pointStrokeColors: ['#ffffff'], + pointFillColors: [], + smooth: true, + xLabels: 'auto', + xLabelFormat: null, + xLabelMargin: 50, + continuousLine: true, + + // Bar defaults + barSizeRatio: 0.75, + barGap: 3, + barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], + + // Donut defaults + colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], + backgroundColor: '#FFFFFF', + labelColor: '#000000', + formatter: Morris.commas + }; + + graphConfig = {}; + $.each(config, function (key, value) { + if (graphDefaults[key] !== undefined) { + graphConfig[key] = value; } - return obj; }); - count = count + length; - return map; + + // IE8(VML) occured error setting smooth false + if (!ChartAPI.Graph.test.svg) { + graphConfig.smooth = true; + } + + // shows percentage as Y label when graph method is donut + if (method === 'donut') { + var totalCount = this.getTotalCount_(data, i); + + graphConfig.formatter = function (y) { + var str = y = (y + '').replace(/,/g, ''); + if (!config.noCommaOnYLabel) { + while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); + } + var percent = Math.ceil((y / totalCount * 10000)) / 100; + + var ret; + if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { + ret = config.donutsFormatter(str, percent + '%', y); + } else { + ret = str + '(' + percent + '%)'; + } + + return ret; + }; + } + + var M = ({ + 'bar': Morris.Bar, + 'line': Morris.Line, + 'donut': Morris.Donut, + 'area': Morris.Area + })[method]; + + this.graph = new M(graphConfig); }; - - var chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - - $.each(config.mix, $.proxy(function (index, conf) { - var colors = { - chartColors: chartColors.slice(count, count + conf.yLength) - }; - var partialData = splitData(conf.yLength, data); - conf = $.extend({}, config, colors, conf); - this[conf.type](partialData, conf); - }, this)); -}; - -ChartAPI.Graph.easel.bar = ChartAPI.Graph.easel.motionLine = ChartAPI.Graph.easel.mix = function (data, config, range, $container) { - if (ChartAPI.Graph.test.canvas()) { - var easelGraph = new ChartAPI.Graph.easel.Base(data, config, range, $container); - return easelGraph; - } else { - console.warn('EaselJS graph requires for HTML5 Canvas capability'); - $container.trigger('REMOVE'); - } -}; - - ChartAPI.Graph.morris = {}; - -ChartAPI.Graph.morris.Base = function (data, config, range, $container) { - if (!window.Morris && typeof window.require === 'function') { - require(['raphael', 'morris'], $.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this)); - } else { - var width = config.width || $container.width(); - if (width) { - this.build_(Morris, data, config, range, $container); + + /** + * get maximum value among the desinated Y data set + * @param {!Array.} graph data to get max Y + * @param {!number} number of set of Y data + * @return {number} return the number of maxY for graph + */ + ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { + var i, maxY, array, sum, key; + + if (method !== 'area') { + array = []; + $.each(data, function (index, value) { + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + array.push(parseInt(value[key], 10)); + } + }); + maxY = Math.max.apply(null, array); } else { - setTimeout($.proxy(function () { - this.build_(Morris, data, config, range, $container); - }, this), 100); + maxY = Math.max.apply(null, $.map(data, function (value) { + sum = 0; + for (i = 0; i < yLength; i++) { + key = 'y' + (i || ''); + sum = sum + parseInt(value[key], 10); + } + return sum; + })); } - } -}; - -ChartAPI.Graph.morris.Base.prototype.build_ = function (Morris, data, config, range, $container) { - var i, - graphDefaults, graphConfig, - method = config.type.split('.')[1], - yLength = config.yLength, - width = config.width || $container.width() || 300, - height = config.height || $container.height() || 300; - - this.$graphEl = $('
').css({ - 'height': height + 'px', - 'width': width + 'px' - }).prependTo($container); - - config = $.extend({}, config, { - element: config.id, - data: data, - xkey: 'x', - labels: this.getYLabels_(yLength, config.labels), - ykeys: this.getYKeys_(yLength), - ymax: this.getYMax_(data, method, yLength), - ymin: config.ymin || 0, - lineWidth: parseInt(config.lineWidth, 10) || 6, - pointSize: parseInt(config.pointSize, 10) || 6, - smooth: config.smooth || false - }); - - config.barColors = config.barColors || this.getChartColors(config); - config.colors = config.colors || this.getChartColors(config); - config.lineColors = config.lineColors || this.getChartColors(config); - config.numLines = parseInt(config.numLines, 10) || this.getNumLines_(config.ymax, height); - - config.pointStrokeColors = config.pointStrokeColors ? config.pointStrokeColors.split(/,/) : []; - if (!config.pointStrokeColors.length) { + + if (!maxY) { + maxY = 1; + } + + if (maxY % 2 !== 0) { + maxY = maxY + 1; + } + + return maxY; + }; + + ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { + if (!this.chartColors) { + this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); + } + return this.chartColors; + }; + + /** + * return YKeys array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { + var i, array = []; for (i = 0; i < yLength; i++) { - config.pointStrokeColors.push('none'); + array.push('y' + (i || '')); } - } - - graphDefaults = { - element: null, - data: null, - xkey: 'x', - labels: [], - ykeys: [], - - // gridDefaults - dateFormat: null, - axes: true, - grid: true, - gridLineColor: '#aaa', - gridStrokeWidth: 0.5, - gridTextColor: '#888', - gridTextSize: 12, - hideHover: false, - hoverCallback: null, - yLabelFormat: null, - numLines: 5, - padding: 25, - parseTime: true, - postUnits: '', - preUnits: '', - ymax: 'auto', - ymin: 'auto 0', - goals: [], - goalStrokeWidth: 1.0, - goalLineColors: ['#666633', '#999966', '#cc6666', '#663333'], - events: [], - eventStrokeWidth: 1.0, - eventLineColors: ['#005a04', '#ccffbb', '#3a5f0b', '#005502'], - - // Line defaults - lineWidth: 3, - pointSize: 4, - lineColors: ['#0b62a4', '#7A92A3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - pointWidths: [1], - pointStrokeColors: ['#ffffff'], - pointFillColors: [], - smooth: true, - xLabels: 'auto', - xLabelFormat: null, - xLabelMargin: 50, - continuousLine: true, - - // Bar defaults - barSizeRatio: 0.75, - barGap: 3, - barColors: ['#0b62a4', '#7a92a3', '#4da74d', '#afd8f8', '#edc240', '#cb4b4b', '#9440ed'], - - // Donut defaults - colors: ['#0B62A4', '#3980B5', '#679DC6', '#95BBD7', '#B0CCE1', '#095791', '#095085', '#083E67', '#052C48', '#042135'], - backgroundColor: '#FFFFFF', - labelColor: '#000000', - formatter: Morris.commas + return array; }; - - graphConfig = {}; - $.each(config, function (key, value) { - if (graphDefaults[key] !== undefined) { - graphConfig[key] = value; + + /** + * return YLables array for graph setting + * @param {!number} number of set of y data + * @return {Array.} array of y key strings + */ + ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { + var i, array = []; + yLabel = yLabel ? yLabel.split(/,/) : []; + for (i = 0; i < yLength; i++) { + array.push((yLabel[i] || 'Count')); } - }); - - // IE8(VML) occured error setting smooth false - if (!ChartAPI.Graph.test.svg) { - graphConfig.smooth = true; - } - - // shows percentage as Y label when graph method is donut - if (method === 'donut') { - var totalCount = this.getTotalCount_(data, i); - - graphConfig.formatter = function (y) { - var str = y = (y + '').replace(/,/g, ''); - if (!config.noCommaOnYLabel) { - while (str != (str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2'))); - } - var percent = Math.ceil((y / totalCount * 10000)) / 100; - - var ret; - if (config.donutsFormatter && typeof config.donutsFormatter === 'function') { - ret = config.donutsFormatter(str, percent + '%', y); - } else { - ret = str + '(' + percent + '%)'; - } - - return ret; - }; - } - - var M = ({ - 'bar': Morris.Bar, - 'line': Morris.Line, - 'donut': Morris.Donut, - 'area': Morris.Area - })[method]; - - this.graph = new M(graphConfig); -}; - -/** - * get maximum value among the desinated Y data set - * @param {!Array.} graph data to get max Y - * @param {!number} number of set of Y data - * @return {number} return the number of maxY for graph - */ -ChartAPI.Graph.morris.Base.prototype.getYMax_ = function (data, method, yLength) { - var i, maxY, array, sum, key; - - if (method !== 'area') { - array = []; - $.each(data, function (index, value) { - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - array.push(parseInt(value[key], 10)); + return array; + }; + + /** + * caliculate the number of horizental lines in graph + * @param {!number} maximum value among the Y data set. + * @return {number} + */ + ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { + var numlines; + if (maxY >= 18) { + numlines = 9; + } else if (maxY === 2) { + numlines = 3; + } else { + numlines = (maxY / 2) + 1; + + } + numlines = Math.min((numlines || 1), Math.floor(height / 56)); + + return numlines; + }; + + /** + * get total count of desinated Y data set. + * @param {!object} graph JSON data + * @param {!number} the number of set of Y data + * @return {number} return the number of total count in current range + */ + ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { + var total = 0, + str = 'y' + (index || ''), + num; + $.each(data, function (i, v) { + num = v[str] || v.value || 0; + if (typeof num === 'string') { + num = parseFloat(num.replace(/,/g, ''), 10); } + total = total + num; }); - maxY = Math.max.apply(null, array); - } else { - maxY = Math.max.apply(null, $.map(data, function (value) { - sum = 0; - for (i = 0; i < yLength; i++) { - key = 'y' + (i || ''); - sum = sum + parseInt(value[key], 10); - } - return sum; - })); - } - - if (!maxY) { - maxY = 1; - } - - if (maxY % 2 !== 0) { - maxY = maxY + 1; - } - - return maxY; -}; - -ChartAPI.Graph.morris.Base.prototype.getChartColors = function (config) { - if (!this.chartColors) { - this.chartColors = config.chartColors || ChartAPI.Graph.getCachedChartColors(config.id, null, config.chartColorsMethod); - } - return this.chartColors; -}; - -/** - * return YKeys array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYKeys_ = function (yLength) { - var i, array = []; - for (i = 0; i < yLength; i++) { - array.push('y' + (i || '')); - } - return array; -}; - -/** - * return YLables array for graph setting - * @param {!number} number of set of y data - * @return {Array.} array of y key strings - */ -ChartAPI.Graph.morris.Base.prototype.getYLabels_ = function (yLength, yLabel) { - var i, array = []; - yLabel = yLabel ? yLabel.split(/,/) : []; - for (i = 0; i < yLength; i++) { - array.push((yLabel[i] || 'Count')); - } - return array; -}; - -/** - * caliculate the number of horizental lines in graph - * @param {!number} maximum value among the Y data set. - * @return {number} - */ -ChartAPI.Graph.morris.Base.prototype.getNumLines_ = function (maxY, height) { - var numlines; - if (maxY >= 18) { - numlines = 9; - } else if (maxY === 2) { - numlines = 3; - } else { - numlines = (maxY / 2) + 1; - - } - numlines = Math.min((numlines || 1), Math.floor(height / 56)); - - return numlines; -}; - -/** - * get total count of desinated Y data set. - * @param {!object} graph JSON data - * @param {!number} the number of set of Y data - * @return {number} return the number of total count in current range - */ -ChartAPI.Graph.morris.Base.prototype.getTotalCount_ = function (data, index) { - var total = 0, - str = 'y' + (index || ''), - num; - $.each(data, function (i, v) { - num = v[str] || v.value || 0; - if (typeof num === 'string') { - num = parseFloat(num.replace(/,/g, ''), 10); - } - total = total + num; - }); - return total; -}; - -ChartAPI.Graph.morris.Base.prototype.remove = function () { - this.$graphEl.remove(); -}; - -ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { - if (ChartAPI.Graph.test.vml()) { - var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); - return morrisGraph; - } else { - console.warn('Morris graph requires for SVG/VML capability'); - $container.trigger('REMOVE'); - } -}; - + return total; + }; + + ChartAPI.Graph.morris.Base.prototype.remove = function () { + this.$graphEl.remove(); + }; + + ChartAPI.Graph.morris.bar = ChartAPI.Graph.morris.line = ChartAPI.Graph.morris.donut = ChartAPI.Graph.morris.area = function (data, config, range, $container) { + if (ChartAPI.Graph.test.vml()) { + var morrisGraph = new ChartAPI.Graph.morris.Base(data, config, range, $container); + return morrisGraph; + } else { + console.warn('Morris graph requires for SVG/VML capability'); + $container.trigger('REMOVE'); + } + }; + /** - * create Slider Object - * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this - * $('.container').trigger('APPEND_SLIDER') - * - * @param {object} slider setings - * @param {object} range object - * @param {jQuery} jQuery object of graph/list container element for getting data range - * @param {Array.} array of jQuery object to fire update event - * @param { - Array. < jQuery > - } - array of jQuery object to fire event - for getting amount labels(this event fired when range is timeline) - * @return {object} jQuery object of slider container for chaining - * @constructor - */ -ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { - if (!$.ui || !$.ui.slider) { - throw 'ChartAPI.Slider requied jQuery UI Slider'; - } - var that = this; - this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - this.range = ChartAPI.Range.generate(range); - this.$dataRangeTarget = $dataRangeTarget; - this.$sliderContainer = $('
'); - - this.eventTargetList = { - update: this.initEventTarget(), - amount: this.initEventTarget() + * create Slider Object + * If you want to draw slider, fire APPEND_SLIDER event for its container Element like this + * $('.container').trigger('APPEND_SLIDER') + * + * @param {object} slider setings + * @param {object} range object + * @param {jQuery} jQuery object of graph/list container element for getting data range + * @param {Array.} array of jQuery object to fire update event + * @param { + Array. < jQuery > + } + array of jQuery object to fire event + for getting amount labels(this event fired when range is timeline) + * @return {object} jQuery object of slider container for chaining + * @constructor + */ + ChartAPI.Slider = function (config, range, $dataRangeTarget, updateTarget, amountTarget) { + if (!$.ui || !$.ui.slider) { + throw 'ChartAPI.Slider requied jQuery UI Slider'; + } + var that = this; + this.id = 'slider-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + this.range = ChartAPI.Range.generate(range); + this.$dataRangeTarget = $dataRangeTarget; + this.$sliderContainer = $('
'); + + this.eventTargetList = { + update: this.initEventTarget(), + amount: this.initEventTarget() + }; + + $.each(updateTarget, function (i, v) { + that.eventTargetList.update.add(v); + }); + + $.each(amountTarget, function (i, v) { + that.eventTargetList.amount.add(v); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object to attach slider + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('APPEND_TO', function (e, $container) { + that.$container = $container; + that.draw_($container); + return $(this); + }); + + /** + * for building slider UI + * @param {object} jQuery event object + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('BUILD_SLIDER', function () { + that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { + that.buildSlider(dataRange.min, dataRange.max); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {jQuery} jQuery object of container for graph|list object to get data range + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { + that.$dataRangeTarget = $target; + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to add event target + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].add($target); + }); + return $(this); + }); + + /** + * @param {object} jQuery event object + * @param {string} the type of event (update|amount) to fire on + * @param {Array.} array of jQuery object to remove from event targets + * @return {jQuery} return jQuery object for chaining + */ + this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { + $targets = $.isArray($targets) ? $targets : [$targets]; + $.each($targets, function (i, $target) { + that.eventTargetList[type].remove($target); + }); + return $(this); + }); + + + this.$sliderContainer.on('ERASE', function () { + that.erase_(); + return $(this); + }); + + this.$sliderContainer.on('REDRAW', function () { + var $this = $(this); + $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); + return $(this); + }); + + this.$sliderContainer.on('UPDATE', function (e, values) { + that.$slider("values", values); + that.updateSliderAmount(values); + return $(this); + }); + + return this.$sliderContainer; }; - - $.each(updateTarget, function (i, v) { - that.eventTargetList.update.add(v); - }); - - $.each(amountTarget, function (i, v) { - that.eventTargetList.amount.add(v); - }); - + /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object to attach slider - * @return {jQuery} return jQuery object for chaining + * return event target object encapsulated target array + * @return {{add:Function, remove:Function, get:Function}} */ - this.$sliderContainer.on('APPEND_TO', function (e, $container) { - that.$container = $container; - that.draw_($container); - return $(this); - }); - + ChartAPI.Slider.prototype.initEventTarget = function () { + var target = []; + return { + add: function (newTarget) { + target.push(newTarget); + }, + remove: function (removeTarget) { + target = $.grep(target, function (v) { + return v !== removeTarget; + }); + }, + get: function () { + return target; + } + }; + }; + /** - * for building slider UI - * @param {object} jQuery event object - * @return {jQuery} return jQuery object for chaining + * build Slider UI + * @param {number} number of the left slider handler position + * @param {number} number of the right slider handler position + * @param {{max:number, min:number}} Object which has max and min values + * @return nothing */ - this.$sliderContainer.on('BUILD_SLIDER', function () { - that.$dataRangeTarget.trigger('GET_DATA_RANGE', function (dataRange) { - that.buildSlider(dataRange.min, dataRange.max); + ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { + var options, defaultCallback, events = ['change', 'create', 'slide', 'start', 'stop'], that = this; + values = values || [this.range.min, this.range.max]; + + if (this.$slider) { + this.$slider.destroy(); + this.$slider.remove(); + } + options = { + 'range': true, + 'min': sliderMin, + 'max': sliderMax, + 'values': values, + 'slide': function (e, ui) { + that.updateSliderAmount(ui.values, ui); + }, + 'stop': function (e, ui) { + that.updateGraphAndList(ui.values); + } + }; + events.forEach(function(value) { + if (that.config.callback[value]) { + defaultCallback = options[value]; + options[value] = function(e, ui) { + that.config.callback[value](e, ui); + if (defaultCallback) { + defaultCallback(e, ui); + } + }; + } }); - return $(this); - }); - - /** - * @param {object} jQuery event object - * @param {jQuery} jQuery object of container for graph|list object to get data range - * @return {jQuery} return jQuery object for chaining - */ - this.$sliderContainer.on('SET_DATA_RANGE', function (e, $target) { - that.$dataRangeTarget = $target; - return $(this); - }); - + this.$slider = $('
').slider(options).appendTo(that.$sliderContainer); + + if (!this.config.hideSliderAmount) { + this.$amount = $('
'); + + if (!this.config.appendSliderAmountBottom) { + this.$amount.prependTo(this.$sliderContainer); + } else { + this.$amount.appendTo(this.$sliderContainer); + } + + this.updateSliderAmount(values); + } + }; + /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to add event target - * @return {jQuery} return jQuery object for chaining + * append Slider container to desinated element + * @param {jQuery} + * @return nothing */ - this.$sliderContainer.on('ADD_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].add($target); - }); - return $(this); - }); - + ChartAPI.Slider.prototype.draw_ = function ($container) { + this.$sliderContainer.appendTo($container); + }; + /** - * @param {object} jQuery event object - * @param {string} the type of event (update|amount) to fire on - * @param {Array.} array of jQuery object to remove from event targets - * @return {jQuery} return jQuery object for chaining + * erase Slider by removing the container + * if you want to redraw Slider, trigger 'REDRAW' for the slider container. */ - this.$sliderContainer.on('REMOVE_EVENT_LIST', function (e, type, $targets) { - $targets = $.isArray($targets) ? $targets : [$targets]; - $.each($targets, function (i, $target) { - that.eventTargetList[type].remove($target); - }); - return $(this); - }); - - - this.$sliderContainer.on('ERASE', function () { - that.erase_(); - return $(this); - }); - - this.$sliderContainer.on('REDRAW', function () { - var $this = $(this); - $this.trigger('BUILD_SLIDER').trigger('APPEND_TO', [that.$container]); - return $(this); - }); - - this.$sliderContainer.on('UPDATE', function (e, values) { - that.$slider("values", values); - that.updateSliderAmount(values); - return $(this); - }); - - return this.$sliderContainer; -}; - -/** - * return event target object encapsulated target array - * @return {{add:Function, remove:Function, get:Function}} - */ -ChartAPI.Slider.prototype.initEventTarget = function () { - var target = []; - return { - add: function (newTarget) { - target.push(newTarget); - }, - remove: function (removeTarget) { - target = $.grep(target, function (v) { - return v !== removeTarget; - }); - }, - get: function () { - return target; + ChartAPI.Slider.prototype.erase_ = function () { + if (this.$slider) { + this.$slider.destroy(); } + this.$sliderContainer.html(''); }; -}; - -/** - * build Slider UI - * @param {number} number of the left slider handler position - * @param {number} number of the right slider handler position - * @param {{max:number, min:number}} Object which has max and min values - * @return nothing - */ -ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { - var that = this; - values = values || [this.range.min, this.range.max]; - - if (this.$slider) { - this.$slider.destroy(); - this.$slider.remove(); - } - this.$slider = $('
').slider({ - 'range': true, - 'min': sliderMin, - 'max': sliderMax, - 'values': values, - 'slide': function (e, ui) { - that.updateSliderAmount(ui.values, ui); - }, - 'stop': function (e, ui) { - that.updateGraphAndList(ui.values); - } - }).appendTo(that.$sliderContainer); - - if (!this.config.hideSliderAmount) { - this.$amount = $('
'); - - if (!this.config.appendSliderAmountBottom) { - this.$amount.prependTo(this.$sliderContainer); + + /** + * update Slider Amount contents + * @param {Array.} values of slider position + * @param {object} ui object returned from Slider event + */ + ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { + var s, e, u, newRange, maxLength = this.range.maxLength, + $amount = this.$amount; + + if (this.range.isTimeline) { + s = ChartAPI.Date.parse(values[0]); + e = ChartAPI.Date.parse(values[1]); + u = this.range.unit; + + newRange = ChartAPI.Range.getLength(s, e, u); + + if (ui && newRange > maxLength) { + if (ui.value === ui.values[0]) { + e = ChartAPI.Date.calcDate(s, maxLength, u, false); + this.$slider.slider('values', 1, e.valueOf()); + } else { + s = ChartAPI.Date.calcDate(e, maxLength, u, true); + this.$slider.slider('values', 0, s.valueOf()); + } + } + + if ($amount) { + $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); + } } else { - this.$amount.appendTo(this.$sliderContainer); - } - - this.updateSliderAmount(values); - } -}; - -/** - * append Slider container to desinated element - * @param {jQuery} - * @return nothing - */ -ChartAPI.Slider.prototype.draw_ = function ($container) { - this.$sliderContainer.appendTo($container); -}; - -/** - * erase Slider by removing the container - * if you want to redraw Slider, trigger 'REDRAW' for the slider container. - */ -ChartAPI.Slider.prototype.erase_ = function () { - if (this.$slider) { - this.$slider.destroy(); - } - this.$sliderContainer.html(''); -}; - -/** - * update Slider Amount contents - * @param {Array.} values of slider position - * @param {object} ui object returned from Slider event - */ -ChartAPI.Slider.prototype.updateSliderAmount = function (values, ui) { - var s, e, u, newRange, maxLength = this.range.maxLength, - $amount = this.$amount; - - if (this.range.isTimeline) { - s = ChartAPI.Date.parse(values[0]); - e = ChartAPI.Date.parse(values[1]); - u = this.range.unit; - - newRange = ChartAPI.Range.getLength(s, e, u); - - if (ui && newRange > maxLength) { - if (ui.value === ui.values[0]) { - e = ChartAPI.Date.calcDate(s, maxLength, u, false); - this.$slider.slider('values', 1, e.valueOf()); - } else { - s = ChartAPI.Date.calcDate(e, maxLength, u, true); - this.$slider.slider('values', 0, s.valueOf()); + s = values[0]; + e = values[1]; + if ((e - s) > maxLength) { + if (ui.value === ui.values[0]) { + e = maxLength - s; + this.$slider.slider('values', 1, e); + } else { + s = e - maxLength; + this.$slider.slider('values', 0, s); + } } - } - - if ($amount) { - $amount.text([ChartAPI.Date.createXLabel(s, u), ChartAPI.Date.createXLabel(e, u)].join(' - ')); - } - } else { - s = values[0]; - e = values[1]; - if ((e - s) > maxLength) { - if (ui.value === ui.values[0]) { - e = maxLength - s; - this.$slider.slider('values', 1, e); - } else { - s = e - maxLength; - this.$slider.slider('values', 0, s); + if ($amount) { + $.each(this.eventTargetList.amount.get(), function (i, $target) { + $target.trigger('GET_LABEL', [ + [s, e], + function (a) { + $amount.text([a[0], a[1]].join(' - ')); + } + ]); + }); } } - if ($amount) { - $.each(this.eventTargetList.amount.get(), function (i, $target) { - $target.trigger('GET_LABEL', [ - [s, e], - function (a) { - $amount.text([a[0], a[1]].join(' - ')); - } - ]); - }); - } - } -}; - -/** - * @param {Array.} values of slider handler position - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { - $.each(this.eventTargetList.update.get(), function (i, $target) { - $target.trigger('UPDATE', [values, newUnit]); - }); -}; - -/** - * update slider handlers position - * @param {number} index of slider handler (left is 0, right is 1) - * @param {number} value of slider handler position - */ -ChartAPI.Slider.prototype.update_ = function (index, value) { - this.$slider.slider('values', index, value); -}; - + }; + /** - * create List Object - * If you want to draw list, fire APPEND_LIST event for its container Element like this - * $('.container').trigger('APPEND_LIST') - * - * @param {object} list setings - * @param {object} range object - * @return {jQuery} return jQuery object for chaining - * @constructor - */ -ChartAPI.List = function (config, range) { - this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); - this.config = config; - - this.config.staticPath = this.config.staticPath || ''; - - if (this.config.data && typeof this.config.data === 'string') { - this.origData_ = $.getJSON(this.config.staticPath + this.config.data); - } else { - this.origData_ = $.Deferred(); - this.origData_.resolve(this.config.data); - } - - if (this.config.template) { - if (window.require && typeof require === 'function') { - var templateType = this.config.type || 'text'; - this.template_ = $.Deferred(); - require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { - this.template_.resolve(template); - }, this)); + * @param {Array.} values of slider handler position + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.Slider.prototype.updateGraphAndList = function (values, newUnit) { + $.each(this.eventTargetList.update.get(), function (i, $target) { + $target.trigger('UPDATE', [values, newUnit]); + }); + }; + + /** + * update slider handlers position + * @param {number} index of slider handler (left is 0, right is 1) + * @param {number} value of slider handler position + */ + ChartAPI.Slider.prototype.update_ = function (index, value) { + this.$slider.slider('values', index, value); + }; + + /** + * create List Object + * If you want to draw list, fire APPEND_LIST event for its container Element like this + * $('.container').trigger('APPEND_LIST') + * + * @param {object} list setings + * @param {object} range object + * @return {jQuery} return jQuery object for chaining + * @constructor + */ + ChartAPI.List = function (config, range) { + this.id = 'list-' + (new Date()).valueOf() + Math.floor(Math.random() * 100); + this.config = config; + + this.config.staticPath = this.config.staticPath || ''; + + if (this.config.data && typeof this.config.data === 'string') { + this.origData_ = $.getJSON(this.config.staticPath + this.config.data); } else { - this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); + this.origData_ = $.Deferred(); + this.origData_.resolve(this.config.data); } - - this.range = ChartAPI.Range.generate(range); - - this.$listContainer = $('
'); - - this.$listContainer.on('UPDATE', $.proxy(function (e, range) { - this.update_(range); - }, this)); - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph data range to callback - */ - this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { - this.getData($.proxy(function (data) { - callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + + if (this.config.template) { + if (window.require && typeof require === 'function') { + var templateType = this.config.type || 'text'; + this.template_ = $.Deferred(); + require([templateType + '!' + this.config.staticPath + this.config.template], $.proxy(function (template) { + this.template_.resolve(template); + }, this)); + } else { + this.template_ = $.get(this.config.staticPath + this.config.template, 'text'); + } + + this.range = ChartAPI.Range.generate(range); + + this.$listContainer = $('
'); + + this.$listContainer.on('UPDATE', $.proxy(function (e, range) { + this.update_(range); }, this)); - return this.$listContainer; - }, this)); - - /** - * @return {jQuery} return jQuery object for chaining - * return back the graph label array to callback - */ - - this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { - this.getData($.proxy(function (data) { - callback(this.getDataLabelByIndex(indexArray, data)); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph data range to callback + */ + this.$listContainer.on('GET_DATA_RANGE', $.proxy(function (e, callback) { + this.getData($.proxy(function (data) { + callback(ChartAPI.Range.getDataRange(data, this.range.isTimeline)); + }, this)); + return this.$listContainer; }, this)); - return this.$listContainer; - }, this)); - - /** - * append graph container to the desinated container - * @return {jQuery} return jQuery object for chaining - */ - - this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { - this.$listContainer.appendTo($container); - this.getData($.proxy(function (data) { - this.draw_(data); + + /** + * @return {jQuery} return jQuery object for chaining + * return back the graph label array to callback + */ + + this.$listContainer.on('GET_LABEL', $.proxy(function (e, indexArray, callback) { + this.getData($.proxy(function (data) { + callback(this.getDataLabelByIndex(indexArray, data)); + }, this)); + return this.$listContainer; }, this)); + + /** + * append graph container to the desinated container + * @return {jQuery} return jQuery object for chaining + */ + + this.$listContainer.on('APPEND_TO', $.proxy(function (e, $container) { + this.$listContainer.appendTo($container); + this.getData($.proxy(function (data) { + this.draw_(data); + }, this)); + return this.$listContainer; + }, this)); + return this.$listContainer; - }, this)); - - return this.$listContainer; - } -}; - -/** - * get list data JSON - * @param {!Function} callback function which recieve jSON data - */ -ChartAPI.List.prototype.getData = function (callback) { - if (this.config.data) { - ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); - } else { - callback(); - } -}; - -/** - * get list template string - * @param {!Function} callback function which recieve template string - */ -ChartAPI.List.prototype.getTemplate = function (callback) { - ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); -}; - -/** - * generate html using template string - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.draw_ = function (data) { - var that = this; - this.getTemplate(function (templateString) { - data = that.createListData(data); - that.$listContainer.html(_.template(templateString, data)); - }); -}; - -/** - * provide x label data for slider - * @param {!Array.} array of index to get data - * @param {!object} list JSON data - */ -ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { - var label = this.config.dataLabel || 'x'; - return $.map(indexArray, function (i) { - return data[i][label]; - }); -}; - -/** - * @param {!object} list JSON data - * @return {object} filtered data for using list template - */ -ChartAPI.List.prototype.createListData = function (data) { - var filteredData = ''; - if (data) { - if (this.range.isTimeline) { - filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); + } + }; + + /** + * get list data JSON + * @param {!Function} callback function which recieve jSON data + */ + ChartAPI.List.prototype.getData = function (callback) { + if (this.config.data) { + ChartAPI.Data.getData(this.origData_, this.$listContainer, callback, this); } else { - filteredData = data.slice(this.range.min, this.range.max + 1); + callback(); } - } - return { - 'data': filteredData }; -}; - -/** - * update list template - * @param {=Array.} array of number - * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) - */ -ChartAPI.List.prototype.update_ = function (newRange, unit) { - var that = this; - newRange = newRange || []; - unit = unit || this.range.unit; - this.range = ChartAPI.Range.generate({ - 'start': newRange[0] || this.range.start, - 'end': newRange[1] || this.range.end, - 'length': null, - 'maxLength': this.range.maxLength, - 'unit': unit, - 'dataType': this.range.dataType - }); - this.getData(function (data) { - that.draw_(data); - }); -}; - + /** - * builder funciton. return jQuery object for chaining and triggering events - * @return {jQuery} - */ -ChartAPI.Build = function (settings) { - var $container; - if (typeof settings === 'string' && (/\.json$/).test(settings)) { - $container = $('
'); - ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { - settings.$container = $container; - ChartAPI.Build_(settings).trigger('APPEND'); + * get list template string + * @param {!Function} callback function which recieve template string + */ + ChartAPI.List.prototype.getTemplate = function (callback) { + ChartAPI.Data.getData(this.template_, this.$listContainer, callback, this); + }; + + /** + * generate html using template string + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.draw_ = function (data) { + var that = this; + this.getTemplate(function (templateString) { + data = that.createListData(data); + that.$listContainer.html(_.template(templateString, data)); }); - } else { - $container = ChartAPI.Build_(settings).trigger('APPEND'); - } - return $container; -}; - -/** - * internal method for building graph|slider|list objects - * @param {Object} settings - * @param {=jQuery} jQuery object to attach graph|slider|list object - */ -ChartAPI.Build_ = function (settings) { - var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; - - $container = settings.$container || $('
'); - - sliderUpdateTarget = []; - - if (settings.graph) { - $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); - sliderUpdateTarget.push($graphContainer); - } - - if (settings.list) { - $listContainer = new ChartAPI.List(settings.list, settings.range); - if (settings.list.data) { - sliderUpdateTarget.push($listContainer); + }; + + /** + * provide x label data for slider + * @param {!Array.} array of index to get data + * @param {!object} list JSON data + */ + ChartAPI.List.prototype.getDataLabelByIndex = function (indexArray, data) { + var label = this.config.dataLabel || 'x'; + return $.map(indexArray, function (i) { + return data[i][label]; + }); + }; + + /** + * @param {!object} list JSON data + * @return {object} filtered data for using list template + */ + ChartAPI.List.prototype.createListData = function (data) { + var filteredData = ''; + if (data) { + if (this.range.isTimeline) { + filteredData = ChartAPI.Data.filterData(data, this.range.max, this.range.min, this.range.unit, 1, true); + } else { + filteredData = data.slice(this.range.min, this.range.max + 1); + } } - } - - if (settings.graph && settings.graph.type !== 'donut') { - dataRangeTarget = $graphContainer; - sliderAmountTarget = [$graphContainer]; - } else { - dataRangeTarget = $listContainer; - sliderAmountTarget = [$listContainer]; - } - - var isSmartPhone = function () { - var userAgent = window.navigator ? window.navigator.userAgent : ''; - return (/android|iphone|ipod|ipad/i).test(userAgent); + return { + 'data': filteredData + }; }; - - if (settings.slider && (settings.slider.force || !isSmartPhone())) { - $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); - } - - $container.on('APPEND', function () { - if ($graphContainer) { - $graphContainer.trigger('APPEND_TO', [$container]); + + /** + * update list template + * @param {=Array.} array of number + * @param {=string} graph unit type (yearly|quater|monthly|weekly|daily|hourly) + */ + ChartAPI.List.prototype.update_ = function (newRange, unit) { + var that = this; + newRange = newRange || []; + unit = unit || this.range.unit; + this.range = ChartAPI.Range.generate({ + 'start': newRange[0] || this.range.start, + 'end': newRange[1] || this.range.end, + 'length': null, + 'maxLength': this.range.maxLength, + 'unit': unit, + 'dataType': this.range.dataType + }); + this.getData(function (data) { + that.draw_(data); + }); + }; + + /** + * builder funciton. return jQuery object for chaining and triggering events + * @return {jQuery} + */ + ChartAPI.Build = function (settings) { + var $container; + if (typeof settings === 'string' && (/\.json$/).test(settings)) { + $container = $('
'); + ChartAPI.Data.getData($.getJSON(settings), null, function (settings) { + settings.$container = $container; + ChartAPI.Build_(settings).trigger('APPEND'); + }); + } else { + $container = ChartAPI.Build_(settings).trigger('APPEND'); + } + return $container; + }; + + /** + * internal method for building graph|slider|list objects + * @param {Object} settings + * @param {=jQuery} jQuery object to attach graph|slider|list object + */ + ChartAPI.Build_ = function (settings) { + var $container, $graphContainer, $sliderContainer, $listContainer, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget; + + $container = settings.$container || $('
'); + + sliderUpdateTarget = []; + + if (settings.graph) { + $graphContainer = new ChartAPI.Graph(settings.graph, settings.range); + sliderUpdateTarget.push($graphContainer); } - if ($sliderContainer) { - $sliderContainer.trigger('BUILD_SLIDER') - .trigger('APPEND_TO', [$container]); + + if (settings.list) { + $listContainer = new ChartAPI.List(settings.list, settings.range); + if (settings.list.data) { + sliderUpdateTarget.push($listContainer); + } } - if ($listContainer) { - $listContainer.trigger('APPEND_TO', [$container]); + + if (settings.graph && settings.graph.type !== 'donut') { + dataRangeTarget = $graphContainer; + sliderAmountTarget = [$graphContainer]; + } else { + dataRangeTarget = $listContainer; + sliderAmountTarget = [$listContainer]; } - }); - - $container.on('GET_CONTAINER', function (e, type, callback) { - callback({ - 'graph': $graphContainer, - 'slider': $sliderContainer, - 'list': $listContainer - }[type]); - }); - - return $container; -}; - + + var isSmartPhone = function () { + var userAgent = window.navigator ? window.navigator.userAgent : ''; + return (/android|iphone|ipod|ipad/i).test(userAgent); + }; + + if (settings.slider && (settings.slider.force || !isSmartPhone())) { + $sliderContainer = new ChartAPI.Slider(settings.slider, settings.range, dataRangeTarget, sliderUpdateTarget, sliderAmountTarget); + } + + $container.on('APPEND', function () { + if ($graphContainer) { + $graphContainer.trigger('APPEND_TO', [$container]); + } + if ($sliderContainer) { + $sliderContainer.trigger('BUILD_SLIDER') + .trigger('APPEND_TO', [$container]); + } + if ($listContainer) { + $listContainer.trigger('APPEND_TO', [$container]); + } + }); + + $container.on('GET_CONTAINER', function (e, type, callback) { + callback({ + 'graph': $graphContainer, + 'slider': $sliderContainer, + 'list': $listContainer + }[type]); + }); + + return $container; + }; + return ChartAPI; })(this, jQuery); diff --git a/lib/mtchart.min.js b/lib/mtchart.min.js index 45a0b57..8294e80 100644 --- a/lib/mtchart.min.js +++ b/lib/mtchart.min.js @@ -1,7 +1,7 @@ -(function(t){var e,i,n=t.event;e=n.special.debouncedresize={setup:function(){t(this).on("resize",e.handler)},teardown:function(){t(this).off("resize",e.handler)},handler:function(t,r){var a=this,s=arguments,o=function(){t.type="debouncedresize";n.dispatch.apply(a,s)};i&&clearTimeout(i);r?o():i=setTimeout(o,e.threshold)},threshold:150}})(jQuery);(function(t){var e,i,n="0.4.2",r="hasOwnProperty",a=/[\.\/]/,s="*",o=function(){},h=function(t,e){return t-e},l={n:{}},u=function(t,n){t+="";var r,a=i,s=Array.prototype.slice.call(arguments,2),o=u.listeners(t),l=0,c=[],p={},d=[],f=e;e=t,i=0;for(var g=0,v=o.length;v>g;g++)"zIndex"in o[g]&&(c.push(o[g].zIndex),0>o[g].zIndex&&(p[o[g].zIndex]=o[g]));for(c.sort(h);0>c[l];)if(r=p[c[l++]],d.push(r.apply(n,s)),i)return i=a,d;for(g=0;v>g;g++)if(r=o[g],"zIndex"in r)if(r.zIndex==c[l]){if(d.push(r.apply(n,s)),i)break;do if(l++,r=p[c[l]],r&&d.push(r.apply(n,s)),i)break;while(r)}else p[r.zIndex]=r;else if(d.push(r.apply(n,s)),i)break;return i=a,e=f,d.length?d:null};u._events=l,u.listeners=function(t){var e,i,n,r,o,h,u,c,p=t.split(a),d=l,f=[d],g=[];for(r=0,o=p.length;o>r;r++){for(c=[],h=0,u=f.length;u>h;h++)for(d=f[h].n,i=[d[p[r]],d[s]],n=2;n--;)e=i[n],e&&(c.push(e),g=g.concat(e.f||[]));f=c}return g},u.on=function(t,e){if(t+="","function"!=typeof e)return function(){};for(var i=t.split(a),n=l,r=0,s=i.length;s>r;r++)n=n.n,n=n.hasOwnProperty(i[r])&&n[i[r]]||(n[i[r]]={n:{}});for(n.f=n.f||[],r=0,s=n.f.length;s>r;r++)if(n.f[r]==e)return o;return n.f.push(e),function(t){+t==+t&&(e.zIndex=+t)}},u.f=function(t){var e=[].slice.call(arguments,1);return function(){u.apply(null,[t,null].concat(e).concat([].slice.call(arguments,0)))}},u.stop=function(){i=1},u.nt=function(t){return t?RegExp("(?:\\.|\\/|^)"+t+"(?:\\.|\\/|$)").test(e):e},u.nts=function(){return e.split(a)},u.off=u.unbind=function(t,e){if(!t)return u._events=l={n:{}},void 0;var i,n,o,h,c,p,d,f=t.split(a),g=[l];for(h=0,c=f.length;c>h;h++)for(p=0;g.length>p;p+=o.length-2){if(o=[p,1],i=g[p].n,f[h]!=s)i[f[h]]&&o.push(i[f[h]]);else for(n in i)i[r](n)&&o.push(i[n]);g.splice.apply(g,o)}for(h=0,c=g.length;c>h;h++)for(i=g[h];i.n;){if(e){if(i.f){for(p=0,d=i.f.length;d>p;p++)if(i.f[p]==e){i.f.splice(p,1);break}!i.f.length&&delete i.f}for(n in i.n)if(i.n[r](n)&&i.n[n].f){var v=i.n[n].f;for(p=0,d=v.length;d>p;p++)if(v[p]==e){v.splice(p,1);break}!v.length&&delete i.n[n].f}}else{delete i.f;for(n in i.n)i.n[r](n)&&i.n[n].f&&delete i.n[n].f}i=i.n}},u.once=function(t,e){var i=function(){return u.unbind(t,i),e.apply(this,arguments)};return u.on(t,i)},u.version=n,u.toString=function(){return"You are running Eve "+n},"undefined"!=typeof module&&module.exports?module.exports=u:"undefined"!=typeof define?define("eve",[],function(){return u}):t.eve=u})(this),function(t,e){"function"==typeof define&&define.amd?define(["eve"],function(i){return e(t,i)}):e(t,t.eve)}(this,function(t,e){function i(t){if(i.is(t,"function"))return _?t():e.on("raphael.DOMload",t);if(i.is(t,q))return i._engine.create[E](i,t.splice(0,3+i.is(t[0],H))).add(t);var n=Array.prototype.slice.call(arguments,0);if(i.is(n[n.length-1],"function")){var r=n.pop();return _?r.call(i._engine.create[E](i,n)):e.on("raphael.DOMload",function(){r.call(i._engine.create[E](i,n))})}return i._engine.create[E](i,arguments)}function n(t){if(Object(t)!==t)return t;var e=new t.constructor;for(var i in t)t[T](i)&&(e[i]=n(t[i]));return e}function r(t,e){for(var i=0,n=t.length;n>i;i++)if(t[i]===e)return t.push(t.splice(i,1)[0])}function a(t,e,i){function n(){var a=Array.prototype.slice.call(arguments,0),s=a.join("␀"),o=n.cache=n.cache||{},h=n.count=n.count||[];return o[T](s)?(r(h,s),i?i(o[s]):o[s]):(h.length>=1e3&&delete o[h.shift()],h.push(s),o[s]=t[E](e,a),i?i(o[s]):o[s])}return n}function s(){return this.hex}function o(t,e){for(var i=[],n=0,r=t.length;r-2*!e>n;n+=2){var a=[{x:+t[n-2],y:+t[n-1]},{x:+t[n],y:+t[n+1]},{x:+t[n+2],y:+t[n+3]},{x:+t[n+4],y:+t[n+5]}];e?n?r-4==n?a[3]={x:+t[0],y:+t[1]}:r-2==n&&(a[2]={x:+t[0],y:+t[1]},a[3]={x:+t[2],y:+t[3]}):a[0]={x:+t[r-2],y:+t[r-1]}:r-4==n?a[3]=a[2]:n||(a[0]={x:+t[n],y:+t[n+1]}),i.push(["C",(-a[0].x+6*a[1].x+a[2].x)/6,(-a[0].y+6*a[1].y+a[2].y)/6,(a[1].x+6*a[2].x-a[3].x)/6,(a[1].y+6*a[2].y-a[3].y)/6,a[2].x,a[2].y])}return i}function h(t,e,i,n,r){var a=-3*e+9*i-9*n+3*r,s=t*a+6*e-12*i+6*n;return t*s-3*e+3*i}function l(t,e,i,n,r,a,s,o,l){null==l&&(l=1),l=l>1?1:0>l?0:l;for(var u=l/2,c=12,p=[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],d=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472],f=0,g=0;c>g;g++){var v=u*p[g]+u,m=h(v,t,i,r,s),y=h(v,e,n,a,o),x=m*m+y*y;f+=d[g]*j.sqrt(x)}return u*f}function u(t,e,i,n,r,a,s,o,h){if(!(0>h||h>l(t,e,i,n,r,a,s,o))){var u,c=1,p=c/2,d=c-p,f=.01;for(u=l(t,e,i,n,r,a,s,o,d);N(u-h)>f;)p/=2,d+=(h>u?1:-1)*p,u=l(t,e,i,n,r,a,s,o,d);return d}}function c(t,e,i,n,r,a,s,o){if(!($(t,i)$(r,s)||$(e,n)$(a,o))){var h=(t*n-e*i)*(r-s)-(t-i)*(r*o-a*s),l=(t*n-e*i)*(a-o)-(e-n)*(r*o-a*s),u=(t-i)*(a-o)-(e-n)*(r-s);if(u){var c=h/u,p=l/u,d=+c.toFixed(2),f=+p.toFixed(2);if(!(+z(t,i).toFixed(2)>d||d>+$(t,i).toFixed(2)||+z(r,s).toFixed(2)>d||d>+$(r,s).toFixed(2)||+z(e,n).toFixed(2)>f||f>+$(e,n).toFixed(2)||+z(a,o).toFixed(2)>f||f>+$(a,o).toFixed(2)))return{x:c,y:p}}}}function p(t,e,n){var r=i.bezierBBox(t),a=i.bezierBBox(e);if(!i.isBBoxIntersect(r,a))return n?0:[];for(var s=l.apply(0,t),o=l.apply(0,e),h=~~(s/5),u=~~(o/5),p=[],d=[],f={},g=n?0:[],v=0;h+1>v;v++){var m=i.findDotsAtSegment.apply(i,t.concat(v/h));p.push({x:m.x,y:m.y,t:v/h})}for(v=0;u+1>v;v++)m=i.findDotsAtSegment.apply(i,e.concat(v/u)),d.push({x:m.x,y:m.y,t:v/u});for(v=0;h>v;v++)for(var y=0;u>y;y++){var x=p[v],_=p[v+1],b=d[y],w=d[y+1],C=.001>N(_.x-x.x)?"y":"x",D=.001>N(w.x-b.x)?"y":"x",T=c(x.x,x.y,_.x,_.y,b.x,b.y,w.x,w.y);if(T){if(f[T.x.toFixed(4)]==T.y.toFixed(4))continue;f[T.x.toFixed(4)]=T.y.toFixed(4);var L=x.t+N((T[C]-x[C])/(_[C]-x[C]))*(_.t-x.t),k=b.t+N((T[D]-b[D])/(w[D]-b[D]))*(w.t-b.t);L>=0&&1>=L&&k>=0&&1>=k&&(n?g++:g.push({x:T.x,y:T.y,t1:L,t2:k}))}}return g}function d(t,e,n){t=i._path2curve(t),e=i._path2curve(e);for(var r,a,s,o,h,l,u,c,d,f,g=n?0:[],v=0,m=t.length;m>v;v++){var y=t[v];if("M"==y[0])r=h=y[1],a=l=y[2];else{"C"==y[0]?(d=[r,a].concat(y.slice(1)),r=d[6],a=d[7]):(d=[r,a,r,a,h,l,h,l],r=h,a=l);for(var x=0,_=e.length;_>x;x++){var b=e[x];if("M"==b[0])s=u=b[1],o=c=b[2];else{"C"==b[0]?(f=[s,o].concat(b.slice(1)),s=f[6],o=f[7]):(f=[s,o,s,o,u,c,u,c],s=u,o=c);var w=p(d,f,n);if(n)g+=w;else{for(var C=0,D=w.length;D>C;C++)w[C].segment1=v,w[C].segment2=x,w[C].bez1=d,w[C].bez2=f;g=g.concat(w)}}}}}return g}function f(t,e,i,n,r,a){null!=t?(this.a=+t,this.b=+e,this.c=+i,this.d=+n,this.e=+r,this.f=+a):(this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0)}function g(){return this.x+P+this.y+P+this.width+" × "+this.height}function v(t,e,i,n,r,a){function s(t){return((c*t+u)*t+l)*t}function o(t,e){var i=h(t,e);return((f*i+d)*i+p)*i}function h(t,e){var i,n,r,a,o,h;for(r=t,h=0;8>h;h++){if(a=s(r)-t,e>N(a))return r;if(o=(3*c*r+2*u)*r+l,1e-6>N(o))break;r-=a/o}if(i=0,n=1,r=t,i>r)return i;if(r>n)return n;for(;n>i;){if(a=s(r),e>N(a-t))return r;t>a?i=r:n=r,r=(n-i)/2+i}return r}var l=3*e,u=3*(n-e)-l,c=1-l-u,p=3*i,d=3*(r-i)-p,f=1-p-d;return o(t,1/(200*a))}function m(t,e){var i=[],n={};if(this.ms=e,this.times=1,t){for(var r in t)t[T](r)&&(n[Z(r)]=t[r],i.push(Z(r)));i.sort(ce)}this.anim=n,this.top=i[i.length-1],this.percents=i}function y(t,n,r,a,s,o){r=Z(r);var h,l,u,c,p,d,g=t.ms,m={},y={},x={};if(a)for(b=0,C=oi.length;C>b;b++){var _=oi[b];if(_.el.id==n.id&&_.anim==t){_.percent!=r?(oi.splice(b,1),u=1):l=_,n.attr(_.totalOrigin);break}}else a=+y;for(var b=0,C=t.percents.length;C>b;b++){if(t.percents[b]==r||t.percents[b]>a*t.top){r=t.percents[b],p=t.percents[b-1]||0,g=g/t.top*(r-p),c=t.percents[b+1],h=t.anim[r];break}a&&n.attr(t.anim[t.percents[b]])}if(h){if(l)l.initstatus=a,l.start=new Date-l.ms*a;else{for(var D in h)if(h[T](D)&&(ne[T](D)||n.paper.customAttributes[T](D)))switch(m[D]=n.attr(D),null==m[D]&&(m[D]=ie[D]),y[D]=h[D],ne[D]){case H:x[D]=(y[D]-m[D])/g;break;case"colour":m[D]=i.getRGB(m[D]);var L=i.getRGB(y[D]);x[D]={r:(L.r-m[D].r)/g,g:(L.g-m[D].g)/g,b:(L.b-m[D].b)/g};break;case"path":var k=Ge(m[D],y[D]),M=k[1];for(m[D]=k[0],x[D]=[],b=0,C=m[D].length;C>b;b++){x[D][b]=[0];for(var E=1,I=m[D][b].length;I>E;E++)x[D][b][E]=(M[b][E]-m[D][b][E])/g}break;case"transform":var A=n._,P=ze(A[D],y[D]);if(P)for(m[D]=P.from,y[D]=P.to,x[D]=[],x[D].real=!0,b=0,C=m[D].length;C>b;b++)for(x[D][b]=[m[D][b][0]],E=1,I=m[D][b].length;I>E;E++)x[D][b][E]=(y[D][b][E]-m[D][b][E])/g;else{var G=n.matrix||new f,R={_:{transform:A.transform},getBBox:function(){return n.getBBox(1)}};m[D]=[G.a,G.b,G.c,G.d,G.e,G.f],je(R,y[D]),y[D]=R._.transform,x[D]=[(R.matrix.a-G.a)/g,(R.matrix.b-G.b)/g,(R.matrix.c-G.c)/g,(R.matrix.d-G.d)/g,(R.matrix.e-G.e)/g,(R.matrix.f-G.f)/g]}break;case"csv":var O=B(h[D])[F](w),j=B(m[D])[F](w);if("clip-rect"==D)for(m[D]=j,x[D]=[],b=j.length;b--;)x[D][b]=(O[b]-m[D][b])/g;y[D]=O;break;default:for(O=[][S](h[D]),j=[][S](m[D]),x[D]=[],b=n.paper.customAttributes[D].length;b--;)x[D][b]=((O[b]||0)-(j[b]||0))/g}var $=h.easing,z=i.easing_formulas[$];if(!z)if(z=B($).match(Q),z&&5==z.length){var N=z;z=function(t){return v(t,+N[1],+N[2],+N[3],+N[4],g)}}else z=de;if(d=h.start||t.start||+new Date,_={anim:t,percent:r,timestamp:d,start:d+(t.del||0),status:0,initstatus:a||0,stop:!1,ms:g,easing:z,from:m,diff:x,to:y,el:n,callback:h.callback,prev:p,next:c,repeat:o||t.times,origin:n.attr(),totalOrigin:s},oi.push(_),a&&!l&&!u&&(_.stop=!0,_.start=new Date-g*a,1==oi.length))return li();u&&(_.start=new Date-_.ms*a),1==oi.length&&hi(li)}e("raphael.anim.start."+n.id,n,t)}}function x(t){for(var e=0;oi.length>e;e++)oi[e].el.paper==t&&oi.splice(e--,1)}i.version="2.1.0",i.eve=e;var _,b,w=/[, ]+/,C={circle:1,rect:1,path:1,ellipse:1,text:1,image:1},D=/\{(\d+)\}/g,T="hasOwnProperty",L={doc:document,win:t},k={was:Object.prototype[T].call(L.win,"Raphael"),is:L.win.Raphael},M=function(){this.ca=this.customAttributes={}},E="apply",S="concat",I="ontouchstart"in L.win||L.win.DocumentTouch&&L.doc instanceof DocumentTouch,A="",P=" ",B=String,F="split",G="click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[F](P),R={mousedown:"touchstart",mousemove:"touchmove",mouseup:"touchend"},O=B.prototype.toLowerCase,j=Math,$=j.max,z=j.min,N=j.abs,Y=j.pow,X=j.PI,H="number",W="string",q="array",U=Object.prototype.toString,V=(i._ISURL=/^url\(['"]?([^\)]+?)['"]?\)$/i,/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i),J={NaN:1,Infinity:1,"-Infinity":1},Q=/^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,K=j.round,Z=parseFloat,te=parseInt,ee=B.prototype.toUpperCase,ie=i._availableAttrs={"arrow-end":"none","arrow-start":"none",blur:0,"clip-rect":"0 0 1e9 1e9",cursor:"default",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/","letter-spacing":0,opacity:1,path:"M0,0",r:0,rx:0,ry:0,src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",transform:"",width:0,x:0,y:0},ne=i._availableAnimAttrs={blur:H,"clip-rect":"csv",cx:H,cy:H,fill:"colour","fill-opacity":H,"font-size":H,height:H,opacity:H,path:"path",r:H,rx:H,ry:H,stroke:"colour","stroke-opacity":H,"stroke-width":H,transform:"transform",width:H,x:H,y:H},re=/[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,ae={hs:1,rg:1},se=/,?([achlmqrstvxz]),?/gi,oe=/([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,he=/([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,le=/(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/gi,ue=(i._radial_gradient=/^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,{}),ce=function(t,e){return Z(t)-Z(e)},pe=function(){},de=function(t){return t},fe=i._rectPath=function(t,e,i,n,r){return r?[["M",t+r,e],["l",i-2*r,0],["a",r,r,0,0,1,r,r],["l",0,n-2*r],["a",r,r,0,0,1,-r,r],["l",2*r-i,0],["a",r,r,0,0,1,-r,-r],["l",0,2*r-n],["a",r,r,0,0,1,r,-r],["z"]]:[["M",t,e],["l",i,0],["l",0,n],["l",-i,0],["z"]]},ge=function(t,e,i,n){return null==n&&(n=i),[["M",t,e],["m",0,-n],["a",i,n,0,1,1,0,2*n],["a",i,n,0,1,1,0,-2*n],["z"]]},ve=i._getPath={path:function(t){return t.attr("path")},circle:function(t){var e=t.attrs;return ge(e.cx,e.cy,e.r)},ellipse:function(t){var e=t.attrs;return ge(e.cx,e.cy,e.rx,e.ry)},rect:function(t){var e=t.attrs;return fe(e.x,e.y,e.width,e.height,e.r)},image:function(t){var e=t.attrs;return fe(e.x,e.y,e.width,e.height)},text:function(t){var e=t._getBBox();return fe(e.x,e.y,e.width,e.height)},set:function(t){var e=t._getBBox();return fe(e.x,e.y,e.width,e.height)}},me=i.mapPath=function(t,e){if(!e)return t;var i,n,r,a,s,o,h;for(t=Ge(t),r=0,s=t.length;s>r;r++)for(h=t[r],a=1,o=h.length;o>a;a+=2)i=e.x(h[a],h[a+1]),n=e.y(h[a],h[a+1]),h[a]=i,h[a+1]=n;return t};if(i._g=L,i.type=L.win.SVGAngle||L.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")?"SVG":"VML","VML"==i.type){var ye,xe=L.doc.createElement("div");if(xe.innerHTML='',ye=xe.firstChild,ye.style.behavior="url(#default#VML)",!ye||"object"!=typeof ye.adj)return i.type=A;xe=null}i.svg=!(i.vml="VML"==i.type),i._Paper=M,i.fn=b=M.prototype=i.prototype,i._id=0,i._oid=0,i.is=function(t,e){return e=O.call(e),"finite"==e?!J[T](+t):"array"==e?t instanceof Array:"null"==e&&null===t||e==typeof t&&null!==t||"object"==e&&t===Object(t)||"array"==e&&Array.isArray&&Array.isArray(t)||U.call(t).slice(8,-1).toLowerCase()==e},i.angle=function(t,e,n,r,a,s){if(null==a){var o=t-n,h=e-r;return o||h?(180+180*j.atan2(-h,-o)/X+360)%360:0}return i.angle(t,e,a,s)-i.angle(n,r,a,s)},i.rad=function(t){return t%360*X/180},i.deg=function(t){return 180*t/X%360},i.snapTo=function(t,e,n){if(n=i.is(n,"finite")?n:10,i.is(t,q)){for(var r=t.length;r--;)if(n>=N(t[r]-e))return t[r]}else{t=+t;var a=e%t;if(n>a)return e-a;if(a>t-n)return e-a+t}return e},i.createUUID=function(t,e){return function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(t,e).toUpperCase()}}(/[xy]/g,function(t){var e=0|16*j.random(),i="x"==t?e:8|3&e;return i.toString(16)}),i.setWindow=function(t){e("raphael.setWindow",i,L.win,t),L.win=t,L.doc=L.win.document,i._engine.initWin&&i._engine.initWin(L.win)};var _e=function(t){if(i.vml){var e,n=/^\s+|\s+$/g;try{var r=new ActiveXObject("htmlfile");r.write(""),r.close(),e=r.body}catch(s){e=createPopup().document.body}var o=e.createTextRange();_e=a(function(t){try{e.style.color=B(t).replace(n,A);var i=o.queryCommandValue("ForeColor");return i=(255&i)<<16|65280&i|(16711680&i)>>>16,"#"+("000000"+i.toString(16)).slice(-6)}catch(r){return"none"}})}else{var h=L.doc.createElement("i");h.title="Raphaël Colour Picker",h.style.display="none",L.doc.body.appendChild(h),_e=a(function(t){return h.style.color=t,L.doc.defaultView.getComputedStyle(h,A).getPropertyValue("color")})}return _e(t)},be=function(){return"hsb("+[this.h,this.s,this.b]+")"},we=function(){return"hsl("+[this.h,this.s,this.l]+")"},Ce=function(){return this.hex},De=function(t,e,n){if(null==e&&i.is(t,"object")&&"r"in t&&"g"in t&&"b"in t&&(n=t.b,e=t.g,t=t.r),null==e&&i.is(t,W)){var r=i.getRGB(t);t=r.r,e=r.g,n=r.b}return(t>1||e>1||n>1)&&(t/=255,e/=255,n/=255),[t,e,n]},Te=function(t,e,n,r){t*=255,e*=255,n*=255;var a={r:t,g:e,b:n,hex:i.rgb(t,e,n),toString:Ce};return i.is(r,"finite")&&(a.opacity=r),a};i.color=function(t){var e;return i.is(t,"object")&&"h"in t&&"s"in t&&"b"in t?(e=i.hsb2rgb(t),t.r=e.r,t.g=e.g,t.b=e.b,t.hex=e.hex):i.is(t,"object")&&"h"in t&&"s"in t&&"l"in t?(e=i.hsl2rgb(t),t.r=e.r,t.g=e.g,t.b=e.b,t.hex=e.hex):(i.is(t,"string")&&(t=i.getRGB(t)),i.is(t,"object")&&"r"in t&&"g"in t&&"b"in t?(e=i.rgb2hsl(t),t.h=e.h,t.s=e.s,t.l=e.l,e=i.rgb2hsb(t),t.v=e.b):(t={hex:"none"},t.r=t.g=t.b=t.h=t.s=t.v=t.l=-1)),t.toString=Ce,t},i.hsb2rgb=function(t,e,i,n){this.is(t,"object")&&"h"in t&&"s"in t&&"b"in t&&(i=t.b,e=t.s,t=t.h,n=t.o),t*=360;var r,a,s,o,h;return t=t%360/60,h=i*e,o=h*(1-N(t%2-1)),r=a=s=i-h,t=~~t,r+=[h,o,0,0,o,h][t],a+=[o,h,h,o,0,0][t],s+=[0,0,o,h,h,o][t],Te(r,a,s,n)},i.hsl2rgb=function(t,e,i,n){this.is(t,"object")&&"h"in t&&"s"in t&&"l"in t&&(i=t.l,e=t.s,t=t.h),(t>1||e>1||i>1)&&(t/=360,e/=100,i/=100),t*=360;var r,a,s,o,h;return t=t%360/60,h=2*e*(.5>i?i:1-i),o=h*(1-N(t%2-1)),r=a=s=i-h/2,t=~~t,r+=[h,o,0,0,o,h][t],a+=[o,h,h,o,0,0][t],s+=[0,0,o,h,h,o][t],Te(r,a,s,n)},i.rgb2hsb=function(t,e,i){i=De(t,e,i),t=i[0],e=i[1],i=i[2];var n,r,a,s;return a=$(t,e,i),s=a-z(t,e,i),n=0==s?null:a==t?(e-i)/s:a==e?(i-t)/s+2:(t-e)/s+4,n=60*((n+360)%6)/360,r=0==s?0:s/a,{h:n,s:r,b:a,toString:be}},i.rgb2hsl=function(t,e,i){i=De(t,e,i),t=i[0],e=i[1],i=i[2];var n,r,a,s,o,h;return s=$(t,e,i),o=z(t,e,i),h=s-o,n=0==h?null:s==t?(e-i)/h:s==e?(i-t)/h+2:(t-e)/h+4,n=60*((n+360)%6)/360,a=(s+o)/2,r=0==h?0:.5>a?h/(2*a):h/(2-2*a),{h:n,s:r,l:a,toString:we}},i._path2string=function(){return this.join(",").replace(se,"$1")},i._preload=function(t,e){var i=L.doc.createElement("img");i.style.cssText="position:absolute;left:-9999em;top:-9999em",i.onload=function(){e.call(this),this.onload=null,L.doc.body.removeChild(this)},i.onerror=function(){L.doc.body.removeChild(this)},L.doc.body.appendChild(i),i.src=t},i.getRGB=a(function(t){if(!t||(t=B(t)).indexOf("-")+1)return{r:-1,g:-1,b:-1,hex:"none",error:1,toString:s};if("none"==t)return{r:-1,g:-1,b:-1,hex:"none",toString:s};!(ae[T](t.toLowerCase().substring(0,2))||"#"==t.charAt())&&(t=_e(t));var e,n,r,a,o,h,l=t.match(V);return l?(l[2]&&(r=te(l[2].substring(5),16),n=te(l[2].substring(3,5),16),e=te(l[2].substring(1,3),16)),l[3]&&(r=te((o=l[3].charAt(3))+o,16),n=te((o=l[3].charAt(2))+o,16),e=te((o=l[3].charAt(1))+o,16)),l[4]&&(h=l[4][F](re),e=Z(h[0]),"%"==h[0].slice(-1)&&(e*=2.55),n=Z(h[1]),"%"==h[1].slice(-1)&&(n*=2.55),r=Z(h[2]),"%"==h[2].slice(-1)&&(r*=2.55),"rgba"==l[1].toLowerCase().slice(0,4)&&(a=Z(h[3])),h[3]&&"%"==h[3].slice(-1)&&(a/=100)),l[5]?(h=l[5][F](re),e=Z(h[0]),"%"==h[0].slice(-1)&&(e*=2.55),n=Z(h[1]),"%"==h[1].slice(-1)&&(n*=2.55),r=Z(h[2]),"%"==h[2].slice(-1)&&(r*=2.55),("deg"==h[0].slice(-3)||"°"==h[0].slice(-1))&&(e/=360),"hsba"==l[1].toLowerCase().slice(0,4)&&(a=Z(h[3])),h[3]&&"%"==h[3].slice(-1)&&(a/=100),i.hsb2rgb(e,n,r,a)):l[6]?(h=l[6][F](re),e=Z(h[0]),"%"==h[0].slice(-1)&&(e*=2.55),n=Z(h[1]),"%"==h[1].slice(-1)&&(n*=2.55),r=Z(h[2]),"%"==h[2].slice(-1)&&(r*=2.55),("deg"==h[0].slice(-3)||"°"==h[0].slice(-1))&&(e/=360),"hsla"==l[1].toLowerCase().slice(0,4)&&(a=Z(h[3])),h[3]&&"%"==h[3].slice(-1)&&(a/=100),i.hsl2rgb(e,n,r,a)):(l={r:e,g:n,b:r,toString:s},l.hex="#"+(16777216|r|n<<8|e<<16).toString(16).slice(1),i.is(a,"finite")&&(l.opacity=a),l)):{r:-1,g:-1,b:-1,hex:"none",error:1,toString:s}},i),i.hsb=a(function(t,e,n){return i.hsb2rgb(t,e,n).hex}),i.hsl=a(function(t,e,n){return i.hsl2rgb(t,e,n).hex}),i.rgb=a(function(t,e,i){return"#"+(16777216|i|e<<8|t<<16).toString(16).slice(1)}),i.getColor=function(t){var e=this.getColor.start=this.getColor.start||{h:0,s:1,b:t||.75},i=this.hsb2rgb(e.h,e.s,e.b);return e.h+=.075,e.h>1&&(e.h=0,e.s-=.2,0>=e.s&&(this.getColor.start={h:0,s:1,b:e.b})),i.hex},i.getColor.reset=function(){delete this.start},i.parsePathString=function(t){if(!t)return null;var e=Le(t);if(e.arr)return Me(e.arr);var n={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},r=[];return i.is(t,q)&&i.is(t[0],q)&&(r=Me(t)),r.length||B(t).replace(oe,function(t,e,i){var a=[],s=e.toLowerCase();if(i.replace(le,function(t,e){e&&a.push(+e)}),"m"==s&&a.length>2&&(r.push([e][S](a.splice(0,2))),s="l",e="m"==e?"l":"L"),"r"==s)r.push([e][S](a));else for(;a.length>=n[s]&&(r.push([e][S](a.splice(0,n[s]))),n[s]););}),r.toString=i._path2string,e.arr=Me(r),r},i.parseTransformString=a(function(t){if(!t)return null;var e=[];return i.is(t,q)&&i.is(t[0],q)&&(e=Me(t)),e.length||B(t).replace(he,function(t,i,n){var r=[];O.call(i),n.replace(le,function(t,e){e&&r.push(+e)}),e.push([i][S](r))}),e.toString=i._path2string,e});var Le=function(t){var e=Le.ps=Le.ps||{};return e[t]?e[t].sleep=100:e[t]={sleep:100},setTimeout(function(){for(var i in e)e[T](i)&&i!=t&&(e[i].sleep--,!e[i].sleep&&delete e[i])}),e[t]};i.findDotsAtSegment=function(t,e,i,n,r,a,s,o,h){var l=1-h,u=Y(l,3),c=Y(l,2),p=h*h,d=p*h,f=u*t+3*c*h*i+3*l*h*h*r+d*s,g=u*e+3*c*h*n+3*l*h*h*a+d*o,v=t+2*h*(i-t)+p*(r-2*i+t),m=e+2*h*(n-e)+p*(a-2*n+e),y=i+2*h*(r-i)+p*(s-2*r+i),x=n+2*h*(a-n)+p*(o-2*a+n),_=l*t+h*i,b=l*e+h*n,w=l*r+h*s,C=l*a+h*o,D=90-180*j.atan2(v-y,m-x)/X;return(v>y||x>m)&&(D+=180),{x:f,y:g,m:{x:v,y:m},n:{x:y,y:x},start:{x:_,y:b},end:{x:w,y:C},alpha:D}},i.bezierBBox=function(t,e,n,r,a,s,o,h){i.is(t,"array")||(t=[t,e,n,r,a,s,o,h]);var l=Fe.apply(null,t);return{x:l.min.x,y:l.min.y,x2:l.max.x,y2:l.max.y,width:l.max.x-l.min.x,height:l.max.y-l.min.y}},i.isPointInsideBBox=function(t,e,i){return e>=t.x&&t.x2>=e&&i>=t.y&&t.y2>=i},i.isBBoxIntersect=function(t,e){var n=i.isPointInsideBBox;return n(e,t.x,t.y)||n(e,t.x2,t.y)||n(e,t.x,t.y2)||n(e,t.x2,t.y2)||n(t,e.x,e.y)||n(t,e.x2,e.y)||n(t,e.x,e.y2)||n(t,e.x2,e.y2)||(t.xe.x||e.xt.x)&&(t.ye.y||e.yt.y)},i.pathIntersection=function(t,e){return d(t,e)},i.pathIntersectionNumber=function(t,e){return d(t,e,1)},i.isPointInsidePath=function(t,e,n){var r=i.pathBBox(t);return i.isPointInsideBBox(r,e,n)&&1==d(t,[["M",e,n],["H",r.x2+10]],1)%2},i._removedFactory=function(t){return function(){e("raphael.log",null,"Raphaël: you are calling to method “"+t+"” of removed object",t)}};var ke=i.pathBBox=function(t){var e=Le(t);if(e.bbox)return n(e.bbox);if(!t)return{x:0,y:0,width:0,height:0,x2:0,y2:0};t=Ge(t);for(var i,r=0,a=0,s=[],o=[],h=0,l=t.length;l>h;h++)if(i=t[h],"M"==i[0])r=i[1],a=i[2],s.push(r),o.push(a);else{var u=Fe(r,a,i[1],i[2],i[3],i[4],i[5],i[6]);s=s[S](u.min.x,u.max.x),o=o[S](u.min.y,u.max.y),r=i[5],a=i[6]}var c=z[E](0,s),p=z[E](0,o),d=$[E](0,s),f=$[E](0,o),g=d-c,v=f-p,m={x:c,y:p,x2:d,y2:f,width:g,height:v,cx:c+g/2,cy:p+v/2};return e.bbox=n(m),m},Me=function(t){var e=n(t);return e.toString=i._path2string,e},Ee=i._pathToRelative=function(t){var e=Le(t);if(e.rel)return Me(e.rel);i.is(t,q)&&i.is(t&&t[0],q)||(t=i.parsePathString(t));var n=[],r=0,a=0,s=0,o=0,h=0;"M"==t[0][0]&&(r=t[0][1],a=t[0][2],s=r,o=a,h++,n.push(["M",r,a]));for(var l=h,u=t.length;u>l;l++){var c=n[l]=[],p=t[l];if(p[0]!=O.call(p[0]))switch(c[0]=O.call(p[0]),c[0]){case"a":c[1]=p[1],c[2]=p[2],c[3]=p[3],c[4]=p[4],c[5]=p[5],c[6]=+(p[6]-r).toFixed(3),c[7]=+(p[7]-a).toFixed(3);break;case"v":c[1]=+(p[1]-a).toFixed(3);break;case"m":s=p[1],o=p[2];default:for(var d=1,f=p.length;f>d;d++)c[d]=+(p[d]-(d%2?r:a)).toFixed(3)}else{c=n[l]=[],"m"==p[0]&&(s=p[1]+r,o=p[2]+a);for(var g=0,v=p.length;v>g;g++)n[l][g]=p[g]}var m=n[l].length;switch(n[l][0]){case"z":r=s,a=o;break;case"h":r+=+n[l][m-1];break;case"v":a+=+n[l][m-1];break;default:r+=+n[l][m-2],a+=+n[l][m-1]}}return n.toString=i._path2string,e.rel=Me(n),n},Se=i._pathToAbsolute=function(t){var e=Le(t);if(e.abs)return Me(e.abs);if(i.is(t,q)&&i.is(t&&t[0],q)||(t=i.parsePathString(t)),!t||!t.length)return[["M",0,0]];var n=[],r=0,a=0,s=0,h=0,l=0;"M"==t[0][0]&&(r=+t[0][1],a=+t[0][2],s=r,h=a,l++,n[0]=["M",r,a]);for(var u,c,p=3==t.length&&"M"==t[0][0]&&"R"==t[1][0].toUpperCase()&&"Z"==t[2][0].toUpperCase(),d=l,f=t.length;f>d;d++){if(n.push(u=[]),c=t[d],c[0]!=ee.call(c[0]))switch(u[0]=ee.call(c[0]),u[0]){case"A":u[1]=c[1],u[2]=c[2],u[3]=c[3],u[4]=c[4],u[5]=c[5],u[6]=+(c[6]+r),u[7]=+(c[7]+a);break;case"V":u[1]=+c[1]+a;break;case"H":u[1]=+c[1]+r;break;case"R":for(var g=[r,a][S](c.slice(1)),v=2,m=g.length;m>v;v++)g[v]=+g[v]+r,g[++v]=+g[v]+a;n.pop(),n=n[S](o(g,p));break;case"M":s=+c[1]+r,h=+c[2]+a;default:for(v=1,m=c.length;m>v;v++)u[v]=+c[v]+(v%2?r:a)}else if("R"==c[0])g=[r,a][S](c.slice(1)),n.pop(),n=n[S](o(g,p)),u=["R"][S](c.slice(-2));else for(var y=0,x=c.length;x>y;y++)u[y]=c[y];switch(u[0]){case"Z":r=s,a=h;break;case"H":r=u[1];break;case"V":a=u[1];break;case"M":s=u[u.length-2],h=u[u.length-1];default:r=u[u.length-2],a=u[u.length-1]}}return n.toString=i._path2string,e.abs=Me(n),n},Ie=function(t,e,i,n){return[t,e,i,n,i,n]},Ae=function(t,e,i,n,r,a){var s=1/3,o=2/3;return[s*t+o*i,s*e+o*n,s*r+o*i,s*a+o*n,r,a]},Pe=function(t,e,i,n,r,s,o,h,l,u){var c,p=120*X/180,d=X/180*(+r||0),f=[],g=a(function(t,e,i){var n=t*j.cos(i)-e*j.sin(i),r=t*j.sin(i)+e*j.cos(i);return{x:n,y:r}});if(u)D=u[0],T=u[1],w=u[2],C=u[3];else{c=g(t,e,-d),t=c.x,e=c.y,c=g(h,l,-d),h=c.x,l=c.y;var v=(j.cos(X/180*r),j.sin(X/180*r),(t-h)/2),m=(e-l)/2,y=v*v/(i*i)+m*m/(n*n);y>1&&(y=j.sqrt(y),i=y*i,n=y*n);var x=i*i,_=n*n,b=(s==o?-1:1)*j.sqrt(N((x*_-x*m*m-_*v*v)/(x*m*m+_*v*v))),w=b*i*m/n+(t+h)/2,C=b*-n*v/i+(e+l)/2,D=j.asin(((e-C)/n).toFixed(9)),T=j.asin(((l-C)/n).toFixed(9));D=w>t?X-D:D,T=w>h?X-T:T,0>D&&(D=2*X+D),0>T&&(T=2*X+T),o&&D>T&&(D-=2*X),!o&&T>D&&(T-=2*X)}var L=T-D;if(N(L)>p){var k=T,M=h,E=l;T=D+p*(o&&T>D?1:-1),h=w+i*j.cos(T),l=C+n*j.sin(T),f=Pe(h,l,i,n,r,0,o,M,E,[T,k,w,C])}L=T-D;var I=j.cos(D),A=j.sin(D),P=j.cos(T),B=j.sin(T),G=j.tan(L/4),R=4/3*i*G,O=4/3*n*G,$=[t,e],z=[t+R*A,e-O*I],Y=[h+R*B,l-O*P],H=[h,l];if(z[0]=2*$[0]-z[0],z[1]=2*$[1]-z[1],u)return[z,Y,H][S](f);f=[z,Y,H][S](f).join()[F](",");for(var W=[],q=0,U=f.length;U>q;q++)W[q]=q%2?g(f[q-1],f[q],d).y:g(f[q],f[q+1],d).x;return W},Be=function(t,e,i,n,r,a,s,o,h){var l=1-h;return{x:Y(l,3)*t+3*Y(l,2)*h*i+3*l*h*h*r+Y(h,3)*s,y:Y(l,3)*e+3*Y(l,2)*h*n+3*l*h*h*a+Y(h,3)*o}},Fe=a(function(t,e,i,n,r,a,s,o){var h,l=r-2*i+t-(s-2*r+i),u=2*(i-t)-2*(r-i),c=t-i,p=(-u+j.sqrt(u*u-4*l*c))/2/l,d=(-u-j.sqrt(u*u-4*l*c))/2/l,f=[e,o],g=[t,s];return N(p)>"1e12"&&(p=.5),N(d)>"1e12"&&(d=.5),p>0&&1>p&&(h=Be(t,e,i,n,r,a,s,o,p),g.push(h.x),f.push(h.y)),d>0&&1>d&&(h=Be(t,e,i,n,r,a,s,o,d),g.push(h.x),f.push(h.y)),l=a-2*n+e-(o-2*a+n),u=2*(n-e)-2*(a-n),c=e-n,p=(-u+j.sqrt(u*u-4*l*c))/2/l,d=(-u-j.sqrt(u*u-4*l*c))/2/l,N(p)>"1e12"&&(p=.5),N(d)>"1e12"&&(d=.5),p>0&&1>p&&(h=Be(t,e,i,n,r,a,s,o,p),g.push(h.x),f.push(h.y)),d>0&&1>d&&(h=Be(t,e,i,n,r,a,s,o,d),g.push(h.x),f.push(h.y)),{min:{x:z[E](0,g),y:z[E](0,f)},max:{x:$[E](0,g),y:$[E](0,f)}}}),Ge=i._path2curve=a(function(t,e){var i=!e&&Le(t);if(!e&&i.curve)return Me(i.curve);for(var n=Se(t),r=e&&Se(e),a={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},s={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},o=(function(t,e){var i,n;if(!t)return["C",e.x,e.y,e.x,e.y,e.x,e.y];switch(!(t[0]in{T:1,Q:1})&&(e.qx=e.qy=null),t[0]){case"M":e.X=t[1],e.Y=t[2];break;case"A":t=["C"][S](Pe[E](0,[e.x,e.y][S](t.slice(1))));break;case"S":i=e.x+(e.x-(e.bx||e.x)),n=e.y+(e.y-(e.by||e.y)),t=["C",i,n][S](t.slice(1));break;case"T":e.qx=e.x+(e.x-(e.qx||e.x)),e.qy=e.y+(e.y-(e.qy||e.y)),t=["C"][S](Ae(e.x,e.y,e.qx,e.qy,t[1],t[2]));break;case"Q":e.qx=t[1],e.qy=t[2],t=["C"][S](Ae(e.x,e.y,t[1],t[2],t[3],t[4]));break;case"L":t=["C"][S](Ie(e.x,e.y,t[1],t[2]));break;case"H":t=["C"][S](Ie(e.x,e.y,t[1],e.y));break;case"V":t=["C"][S](Ie(e.x,e.y,e.x,t[1]));break;case"Z":t=["C"][S](Ie(e.x,e.y,e.X,e.Y))}return t}),h=function(t,e){if(t[e].length>7){t[e].shift();for(var i=t[e];i.length;)t.splice(e++,0,["C"][S](i.splice(0,6)));t.splice(e,1),c=$(n.length,r&&r.length||0)}},l=function(t,e,i,a,s){t&&e&&"M"==t[s][0]&&"M"!=e[s][0]&&(e.splice(s,0,["M",a.x,a.y]),i.bx=0,i.by=0,i.x=t[s][1],i.y=t[s][2],c=$(n.length,r&&r.length||0))},u=0,c=$(n.length,r&&r.length||0);c>u;u++){n[u]=o(n[u],a),h(n,u),r&&(r[u]=o(r[u],s)),r&&h(r,u),l(n,r,a,s,u),l(r,n,s,a,u);var p=n[u],d=r&&r[u],f=p.length,g=r&&d.length;a.x=p[f-2],a.y=p[f-1],a.bx=Z(p[f-4])||a.x,a.by=Z(p[f-3])||a.y,s.bx=r&&(Z(d[g-4])||s.x),s.by=r&&(Z(d[g-3])||s.y),s.x=r&&d[g-2],s.y=r&&d[g-1]}return r||(i.curve=Me(n)),r?[n,r]:n},null,Me),Re=(i._parseDots=a(function(t){for(var e=[],n=0,r=t.length;r>n;n++){var a={},s=t[n].match(/^([^:]*):?([\d\.]*)/);if(a.color=i.getRGB(s[1]),a.color.error)return null;a.color=a.color.hex,s[2]&&(a.offset=s[2]+"%"),e.push(a)}for(n=1,r=e.length-1;r>n;n++)if(!e[n].offset){for(var o=Z(e[n-1].offset||0),h=0,l=n+1;r>l;l++)if(e[l].offset){h=e[l].offset;break}h||(h=100,l=r),h=Z(h);for(var u=(h-o)/(l-n+1);l>n;n++)o+=u,e[n].offset=o+"%"}return e}),i._tear=function(t,e){t==e.top&&(e.top=t.prev),t==e.bottom&&(e.bottom=t.next),t.next&&(t.next.prev=t.prev),t.prev&&(t.prev.next=t.next)}),Oe=(i._tofront=function(t,e){e.top!==t&&(Re(t,e),t.next=null,t.prev=e.top,e.top.next=t,e.top=t)},i._toback=function(t,e){e.bottom!==t&&(Re(t,e),t.next=e.bottom,t.prev=null,e.bottom.prev=t,e.bottom=t)},i._insertafter=function(t,e,i){Re(t,i),e==i.top&&(i.top=t),e.next&&(e.next.prev=t),t.next=e.next,t.prev=e,e.next=t},i._insertbefore=function(t,e,i){Re(t,i),e==i.bottom&&(i.bottom=t),e.prev&&(e.prev.next=t),t.prev=e.prev,e.prev=t,t.next=e},i.toMatrix=function(t,e){var i=ke(t),n={_:{transform:A},getBBox:function(){return i}};return je(n,e),n.matrix}),je=(i.transformPath=function(t,e){return me(t,Oe(t,e))},i._extractTransform=function(t,e){if(null==e)return t._.transform;e=B(e).replace(/\.{3}|\u2026/g,t._.transform||A);var n=i.parseTransformString(e),r=0,a=0,s=0,o=1,h=1,l=t._,u=new f;if(l.transform=n||[],n)for(var c=0,p=n.length;p>c;c++){var d,g,v,m,y,x=n[c],_=x.length,b=B(x[0]).toLowerCase(),w=x[0]!=b,C=w?u.invert():0;"t"==b&&3==_?w?(d=C.x(0,0),g=C.y(0,0),v=C.x(x[1],x[2]),m=C.y(x[1],x[2]),u.translate(v-d,m-g)):u.translate(x[1],x[2]):"r"==b?2==_?(y=y||t.getBBox(1),u.rotate(x[1],y.x+y.width/2,y.y+y.height/2),r+=x[1]):4==_&&(w?(v=C.x(x[2],x[3]),m=C.y(x[2],x[3]),u.rotate(x[1],v,m)):u.rotate(x[1],x[2],x[3]),r+=x[1]):"s"==b?2==_||3==_?(y=y||t.getBBox(1),u.scale(x[1],x[_-1],y.x+y.width/2,y.y+y.height/2),o*=x[1],h*=x[_-1]):5==_&&(w?(v=C.x(x[3],x[4]),m=C.y(x[3],x[4]),u.scale(x[1],x[2],v,m)):u.scale(x[1],x[2],x[3],x[4]),o*=x[1],h*=x[2]):"m"==b&&7==_&&u.add(x[1],x[2],x[3],x[4],x[5],x[6]),l.dirtyT=1,t.matrix=u}t.matrix=u,l.sx=o,l.sy=h,l.deg=r,l.dx=a=u.e,l.dy=s=u.f,1==o&&1==h&&!r&&l.bbox?(l.bbox.x+=+a,l.bbox.y+=+s):l.dirtyT=1}),$e=function(t){var e=t[0];switch(e.toLowerCase()){case"t":return[e,0,0];case"m":return[e,1,0,0,1,0,0];case"r":return 4==t.length?[e,0,t[2],t[3]]:[e,0];case"s":return 5==t.length?[e,1,1,t[3],t[4]]:3==t.length?[e,1,1]:[e,1]}},ze=i._equaliseTransform=function(t,e){e=B(e).replace(/\.{3}|\u2026/g,t),t=i.parseTransformString(t)||[],e=i.parseTransformString(e)||[]; -for(var n,r,a,s,o=$(t.length,e.length),h=[],l=[],u=0;o>u;u++){if(a=t[u]||$e(e[u]),s=e[u]||$e(a),a[0]!=s[0]||"r"==a[0].toLowerCase()&&(a[2]!=s[2]||a[3]!=s[3])||"s"==a[0].toLowerCase()&&(a[3]!=s[3]||a[4]!=s[4]))return;for(h[u]=[],l[u]=[],n=0,r=$(a.length,s.length);r>n;n++)n in a&&(h[u][n]=a[n]),n in s&&(l[u][n]=s[n])}return{from:h,to:l}};i._getContainer=function(t,e,n,r){var a;return a=null!=r||i.is(t,"object")?t:L.doc.getElementById(t),null!=a?a.tagName?null==e?{container:a,width:a.style.pixelWidth||a.offsetWidth,height:a.style.pixelHeight||a.offsetHeight}:{container:a,width:e,height:n}:{container:1,x:t,y:e,width:n,height:r}:void 0},i.pathToRelative=Ee,i._engine={},i.path2curve=Ge,i.matrix=function(t,e,i,n,r,a){return new f(t,e,i,n,r,a)},function(t){function e(t){return t[0]*t[0]+t[1]*t[1]}function n(t){var i=j.sqrt(e(t));t[0]&&(t[0]/=i),t[1]&&(t[1]/=i)}t.add=function(t,e,i,n,r,a){var s,o,h,l,u=[[],[],[]],c=[[this.a,this.c,this.e],[this.b,this.d,this.f],[0,0,1]],p=[[t,i,r],[e,n,a],[0,0,1]];for(t&&t instanceof f&&(p=[[t.a,t.c,t.e],[t.b,t.d,t.f],[0,0,1]]),s=0;3>s;s++)for(o=0;3>o;o++){for(l=0,h=0;3>h;h++)l+=c[s][h]*p[h][o];u[s][o]=l}this.a=u[0][0],this.b=u[1][0],this.c=u[0][1],this.d=u[1][1],this.e=u[0][2],this.f=u[1][2]},t.invert=function(){var t=this,e=t.a*t.d-t.b*t.c;return new f(t.d/e,-t.b/e,-t.c/e,t.a/e,(t.c*t.f-t.d*t.e)/e,(t.b*t.e-t.a*t.f)/e)},t.clone=function(){return new f(this.a,this.b,this.c,this.d,this.e,this.f)},t.translate=function(t,e){this.add(1,0,0,1,t,e)},t.scale=function(t,e,i,n){null==e&&(e=t),(i||n)&&this.add(1,0,0,1,i,n),this.add(t,0,0,e,0,0),(i||n)&&this.add(1,0,0,1,-i,-n)},t.rotate=function(t,e,n){t=i.rad(t),e=e||0,n=n||0;var r=+j.cos(t).toFixed(9),a=+j.sin(t).toFixed(9);this.add(r,a,-a,r,e,n),this.add(1,0,0,1,-e,-n)},t.x=function(t,e){return t*this.a+e*this.c+this.e},t.y=function(t,e){return t*this.b+e*this.d+this.f},t.get=function(t){return+this[B.fromCharCode(97+t)].toFixed(4)},t.toString=function(){return i.svg?"matrix("+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)].join()+")":[this.get(0),this.get(2),this.get(1),this.get(3),0,0].join()},t.toFilter=function(){return"progid:DXImageTransform.Microsoft.Matrix(M11="+this.get(0)+", M12="+this.get(2)+", M21="+this.get(1)+", M22="+this.get(3)+", Dx="+this.get(4)+", Dy="+this.get(5)+", sizingmethod='auto expand')"},t.offset=function(){return[this.e.toFixed(4),this.f.toFixed(4)]},t.split=function(){var t={};t.dx=this.e,t.dy=this.f;var r=[[this.a,this.c],[this.b,this.d]];t.scalex=j.sqrt(e(r[0])),n(r[0]),t.shear=r[0][0]*r[1][0]+r[0][1]*r[1][1],r[1]=[r[1][0]-r[0][0]*t.shear,r[1][1]-r[0][1]*t.shear],t.scaley=j.sqrt(e(r[1])),n(r[1]),t.shear/=t.scaley;var a=-r[0][1],s=r[1][1];return 0>s?(t.rotate=i.deg(j.acos(s)),0>a&&(t.rotate=360-t.rotate)):t.rotate=i.deg(j.asin(a)),t.isSimple=!(+t.shear.toFixed(9)||t.scalex.toFixed(9)!=t.scaley.toFixed(9)&&t.rotate),t.isSuperSimple=!+t.shear.toFixed(9)&&t.scalex.toFixed(9)==t.scaley.toFixed(9)&&!t.rotate,t.noRotation=!+t.shear.toFixed(9)&&!t.rotate,t},t.toTransformString=function(t){var e=t||this[F]();return e.isSimple?(e.scalex=+e.scalex.toFixed(4),e.scaley=+e.scaley.toFixed(4),e.rotate=+e.rotate.toFixed(4),(e.dx||e.dy?"t"+[e.dx,e.dy]:A)+(1!=e.scalex||1!=e.scaley?"s"+[e.scalex,e.scaley,0,0]:A)+(e.rotate?"r"+[e.rotate,0,0]:A)):"m"+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)]}}(f.prototype);var Ne=navigator.userAgent.match(/Version\/(.*?)\s/)||navigator.userAgent.match(/Chrome\/(\d+)/);b.safari="Apple Computer, Inc."==navigator.vendor&&(Ne&&4>Ne[1]||"iP"==navigator.platform.slice(0,2))||"Google Inc."==navigator.vendor&&Ne&&8>Ne[1]?function(){var t=this.rect(-99,-99,this.width+99,this.height+99).attr({stroke:"none"});setTimeout(function(){t.remove()})}:pe;for(var Ye=function(){this.returnValue=!1},Xe=function(){return this.originalEvent.preventDefault()},He=function(){this.cancelBubble=!0},We=function(){return this.originalEvent.stopPropagation()},qe=function(){return L.doc.addEventListener?function(t,e,i,n){var r=I&&R[e]?R[e]:e,a=function(r){var a=L.doc.documentElement.scrollTop||L.doc.body.scrollTop,s=L.doc.documentElement.scrollLeft||L.doc.body.scrollLeft,o=r.clientX+s,h=r.clientY+a;if(I&&R[T](e))for(var l=0,u=r.targetTouches&&r.targetTouches.length;u>l;l++)if(r.targetTouches[l].target==t){var c=r;r=r.targetTouches[l],r.originalEvent=c,r.preventDefault=Xe,r.stopPropagation=We;break}return i.call(n,r,o,h)};return t.addEventListener(r,a,!1),function(){return t.removeEventListener(r,a,!1),!0}}:L.doc.attachEvent?function(t,e,i,n){var r=function(t){t=t||L.win.event;var e=L.doc.documentElement.scrollTop||L.doc.body.scrollTop,r=L.doc.documentElement.scrollLeft||L.doc.body.scrollLeft,a=t.clientX+r,s=t.clientY+e;return t.preventDefault=t.preventDefault||Ye,t.stopPropagation=t.stopPropagation||He,i.call(n,t,a,s)};t.attachEvent("on"+e,r);var a=function(){return t.detachEvent("on"+e,r),!0};return a}:void 0}(),Ue=[],Ve=function(t){for(var i,n=t.clientX,r=t.clientY,a=L.doc.documentElement.scrollTop||L.doc.body.scrollTop,s=L.doc.documentElement.scrollLeft||L.doc.body.scrollLeft,o=Ue.length;o--;){if(i=Ue[o],I){for(var h,l=t.touches.length;l--;)if(h=t.touches[l],h.identifier==i.el._drag.id){n=h.clientX,r=h.clientY,(t.originalEvent?t.originalEvent:t).preventDefault();break}}else t.preventDefault();var u,c=i.el.node,p=c.nextSibling,d=c.parentNode,f=c.style.display;L.win.opera&&d.removeChild(c),c.style.display="none",u=i.el.paper.getElementByPoint(n,r),c.style.display=f,L.win.opera&&(p?d.insertBefore(c,p):d.appendChild(c)),u&&e("raphael.drag.over."+i.el.id,i.el,u),n+=s,r+=a,e("raphael.drag.move."+i.el.id,i.move_scope||i.el,n-i.el._drag.x,r-i.el._drag.y,n,r,t)}},Je=function(t){i.unmousemove(Ve).unmouseup(Je);for(var n,r=Ue.length;r--;)n=Ue[r],n.el._drag={},e("raphael.drag.end."+n.el.id,n.end_scope||n.start_scope||n.move_scope||n.el,t);Ue=[]},Qe=i.el={},Ke=G.length;Ke--;)(function(t){i[t]=Qe[t]=function(e,n){return i.is(e,"function")&&(this.events=this.events||[],this.events.push({name:t,f:e,unbind:qe(this.shape||this.node||L.doc,t,e,n||this)})),this},i["un"+t]=Qe["un"+t]=function(e){for(var n=this.events||[],r=n.length;r--;)n[r].name!=t||!i.is(e,"undefined")&&n[r].f!=e||(n[r].unbind(),n.splice(r,1),!n.length&&delete this.events);return this}})(G[Ke]);Qe.data=function(t,n){var r=ue[this.id]=ue[this.id]||{};if(0==arguments.length)return r;if(1==arguments.length){if(i.is(t,"object")){for(var a in t)t[T](a)&&this.data(a,t[a]);return this}return e("raphael.data.get."+this.id,this,r[t],t),r[t]}return r[t]=n,e("raphael.data.set."+this.id,this,n,t),this},Qe.removeData=function(t){return null==t?ue[this.id]={}:ue[this.id]&&delete ue[this.id][t],this},Qe.getData=function(){return n(ue[this.id]||{})},Qe.hover=function(t,e,i,n){return this.mouseover(t,i).mouseout(e,n||i)},Qe.unhover=function(t,e){return this.unmouseover(t).unmouseout(e)};var Ze=[];Qe.drag=function(t,n,r,a,s,o){function h(h){(h.originalEvent||h).preventDefault();var l=L.doc.documentElement.scrollTop||L.doc.body.scrollTop,u=L.doc.documentElement.scrollLeft||L.doc.body.scrollLeft;this._drag.x=h.clientX+u,this._drag.y=h.clientY+l,this._drag.id=h.identifier,!Ue.length&&i.mousemove(Ve).mouseup(Je),Ue.push({el:this,move_scope:a,start_scope:s,end_scope:o}),n&&e.on("raphael.drag.start."+this.id,n),t&&e.on("raphael.drag.move."+this.id,t),r&&e.on("raphael.drag.end."+this.id,r),e("raphael.drag.start."+this.id,s||a||this,h.clientX+u,h.clientY+l,h)}return this._drag={},Ze.push({el:this,start:h}),this.mousedown(h),this},Qe.onDragOver=function(t){t?e.on("raphael.drag.over."+this.id,t):e.unbind("raphael.drag.over."+this.id)},Qe.undrag=function(){for(var t=Ze.length;t--;)Ze[t].el==this&&(this.unmousedown(Ze[t].start),Ze.splice(t,1),e.unbind("raphael.drag.*."+this.id));!Ze.length&&i.unmousemove(Ve).unmouseup(Je),Ue=[]},b.circle=function(t,e,n){var r=i._engine.circle(this,t||0,e||0,n||0);return this.__set__&&this.__set__.push(r),r},b.rect=function(t,e,n,r,a){var s=i._engine.rect(this,t||0,e||0,n||0,r||0,a||0);return this.__set__&&this.__set__.push(s),s},b.ellipse=function(t,e,n,r){var a=i._engine.ellipse(this,t||0,e||0,n||0,r||0);return this.__set__&&this.__set__.push(a),a},b.path=function(t){t&&!i.is(t,W)&&!i.is(t[0],q)&&(t+=A);var e=i._engine.path(i.format[E](i,arguments),this);return this.__set__&&this.__set__.push(e),e},b.image=function(t,e,n,r,a){var s=i._engine.image(this,t||"about:blank",e||0,n||0,r||0,a||0);return this.__set__&&this.__set__.push(s),s},b.text=function(t,e,n){var r=i._engine.text(this,t||0,e||0,B(n));return this.__set__&&this.__set__.push(r),r},b.set=function(t){!i.is(t,"array")&&(t=Array.prototype.splice.call(arguments,0,arguments.length));var e=new ci(t);return this.__set__&&this.__set__.push(e),e.paper=this,e.type="set",e},b.setStart=function(t){this.__set__=t||this.set()},b.setFinish=function(){var t=this.__set__;return delete this.__set__,t},b.setSize=function(t,e){return i._engine.setSize.call(this,t,e)},b.setViewBox=function(t,e,n,r,a){return i._engine.setViewBox.call(this,t,e,n,r,a)},b.top=b.bottom=null,b.raphael=i;var ti=function(t){var e=t.getBoundingClientRect(),i=t.ownerDocument,n=i.body,r=i.documentElement,a=r.clientTop||n.clientTop||0,s=r.clientLeft||n.clientLeft||0,o=e.top+(L.win.pageYOffset||r.scrollTop||n.scrollTop)-a,h=e.left+(L.win.pageXOffset||r.scrollLeft||n.scrollLeft)-s;return{y:o,x:h}};b.getElementByPoint=function(t,e){var i=this,n=i.canvas,r=L.doc.elementFromPoint(t,e);if(L.win.opera&&"svg"==r.tagName){var a=ti(n),s=n.createSVGRect();s.x=t-a.x,s.y=e-a.y,s.width=s.height=1;var o=n.getIntersectionList(s,null);o.length&&(r=o[o.length-1])}if(!r)return null;for(;r.parentNode&&r!=n.parentNode&&!r.raphael;)r=r.parentNode;return r==i.canvas.parentNode&&(r=n),r=r&&r.raphael?i.getById(r.raphaelid):null},b.getElementsByBBox=function(t){var e=this.set();return this.forEach(function(n){i.isBBoxIntersect(n.getBBox(),t)&&e.push(n)}),e},b.getById=function(t){for(var e=this.bottom;e;){if(e.id==t)return e;e=e.next}return null},b.forEach=function(t,e){for(var i=this.bottom;i;){if(t.call(e,i)===!1)return this;i=i.next}return this},b.getElementsByPoint=function(t,e){var i=this.set();return this.forEach(function(n){n.isPointInside(t,e)&&i.push(n)}),i},Qe.isPointInside=function(t,e){var n=this.realPath=this.realPath||ve[this.type](this);return i.isPointInsidePath(n,t,e)},Qe.getBBox=function(t){if(this.removed)return{};var e=this._;return t?((e.dirty||!e.bboxwt)&&(this.realPath=ve[this.type](this),e.bboxwt=ke(this.realPath),e.bboxwt.toString=g,e.dirty=0),e.bboxwt):((e.dirty||e.dirtyT||!e.bbox)&&((e.dirty||!this.realPath)&&(e.bboxwt=0,this.realPath=ve[this.type](this)),e.bbox=ke(me(this.realPath,this.matrix)),e.bbox.toString=g,e.dirty=e.dirtyT=0),e.bbox)},Qe.clone=function(){if(this.removed)return null;var t=this.paper[this.type]().attr(this.attr());return this.__set__&&this.__set__.push(t),t},Qe.glow=function(t){if("text"==this.type)return null;t=t||{};var e={width:(t.width||10)+(+this.attr("stroke-width")||1),fill:t.fill||!1,opacity:t.opacity||.5,offsetx:t.offsetx||0,offsety:t.offsety||0,color:t.color||"#000"},i=e.width/2,n=this.paper,r=n.set(),a=this.realPath||ve[this.type](this);a=this.matrix?me(a,this.matrix):a;for(var s=1;i+1>s;s++)r.push(n.path(a).attr({stroke:e.color,fill:e.fill?e.color:"none","stroke-linejoin":"round","stroke-linecap":"round","stroke-width":+(e.width/i*s).toFixed(3),opacity:+(e.opacity/i).toFixed(3)}));return r.insertBefore(this).translate(e.offsetx,e.offsety)};var ei=function(t,e,n,r,a,s,o,h,c){return null==c?l(t,e,n,r,a,s,o,h):i.findDotsAtSegment(t,e,n,r,a,s,o,h,u(t,e,n,r,a,s,o,h,c))},ii=function(t,e){return function(n,r,a){n=Ge(n);for(var s,o,h,l,u,c="",p={},d=0,f=0,g=n.length;g>f;f++){if(h=n[f],"M"==h[0])s=+h[1],o=+h[2];else{if(l=ei(s,o,h[1],h[2],h[3],h[4],h[5],h[6]),d+l>r){if(e&&!p.start){if(u=ei(s,o,h[1],h[2],h[3],h[4],h[5],h[6],r-d),c+=["C"+u.start.x,u.start.y,u.m.x,u.m.y,u.x,u.y],a)return c;p.start=c,c=["M"+u.x,u.y+"C"+u.n.x,u.n.y,u.end.x,u.end.y,h[5],h[6]].join(),d+=l,s=+h[5],o=+h[6];continue}if(!t&&!e)return u=ei(s,o,h[1],h[2],h[3],h[4],h[5],h[6],r-d),{x:u.x,y:u.y,alpha:u.alpha}}d+=l,s=+h[5],o=+h[6]}c+=h.shift()+h}return p.end=c,u=t?d:e?p:i.findDotsAtSegment(s,o,h[0],h[1],h[2],h[3],h[4],h[5],1),u.alpha&&(u={x:u.x,y:u.y,alpha:u.alpha}),u}},ni=ii(1),ri=ii(),ai=ii(0,1);i.getTotalLength=ni,i.getPointAtLength=ri,i.getSubpath=function(t,e,i){if(1e-6>this.getTotalLength(t)-i)return ai(t,e).end;var n=ai(t,i,1);return e?ai(n,e).end:n},Qe.getTotalLength=function(){return"path"==this.type?this.node.getTotalLength?this.node.getTotalLength():ni(this.attrs.path):void 0},Qe.getPointAtLength=function(t){return"path"==this.type?ri(this.attrs.path,t):void 0},Qe.getSubpath=function(t,e){return"path"==this.type?i.getSubpath(this.attrs.path,t,e):void 0};var si=i.easing_formulas={linear:function(t){return t},"<":function(t){return Y(t,1.7)},">":function(t){return Y(t,.48)},"<>":function(t){var e=.48-t/1.04,i=j.sqrt(.1734+e*e),n=i-e,r=Y(N(n),1/3)*(0>n?-1:1),a=-i-e,s=Y(N(a),1/3)*(0>a?-1:1),o=r+s+.5;return 3*(1-o)*o*o+o*o*o},backIn:function(t){var e=1.70158;return t*t*((e+1)*t-e)},backOut:function(t){t-=1;var e=1.70158;return t*t*((e+1)*t+e)+1},elastic:function(t){return t==!!t?t:Y(2,-10*t)*j.sin(2*(t-.075)*X/.3)+1},bounce:function(t){var e,i=7.5625,n=2.75;return 1/n>t?e=i*t*t:2/n>t?(t-=1.5/n,e=i*t*t+.75):2.5/n>t?(t-=2.25/n,e=i*t*t+.9375):(t-=2.625/n,e=i*t*t+.984375),e}};si.easeIn=si["ease-in"]=si["<"],si.easeOut=si["ease-out"]=si[">"],si.easeInOut=si["ease-in-out"]=si["<>"],si["back-in"]=si.backIn,si["back-out"]=si.backOut;var oi=[],hi=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(t){setTimeout(t,16)},li=function(){for(var t=+new Date,n=0;oi.length>n;n++){var r=oi[n];if(!r.el.removed&&!r.paused){var a,s,o=t-r.start,h=r.ms,l=r.easing,u=r.from,c=r.diff,p=r.to,d=(r.t,r.el),f={},g={};if(r.initstatus?(o=(r.initstatus*r.anim.top-r.prev)/(r.percent-r.prev)*h,r.status=r.initstatus,delete r.initstatus,r.stop&&oi.splice(n--,1)):r.status=(r.prev+(r.percent-r.prev)*(o/h))/r.anim.top,!(0>o))if(h>o){var v=l(o/h);for(var m in u)if(u[T](m)){switch(ne[m]){case H:a=+u[m]+v*h*c[m];break;case"colour":a="rgb("+[ui(K(u[m].r+v*h*c[m].r)),ui(K(u[m].g+v*h*c[m].g)),ui(K(u[m].b+v*h*c[m].b))].join(",")+")";break;case"path":a=[];for(var x=0,_=u[m].length;_>x;x++){a[x]=[u[m][x][0]];for(var b=1,w=u[m][x].length;w>b;b++)a[x][b]=+u[m][x][b]+v*h*c[m][x][b];a[x]=a[x].join(P)}a=a.join(P);break;case"transform":if(c[m].real)for(a=[],x=0,_=u[m].length;_>x;x++)for(a[x]=[u[m][x][0]],b=1,w=u[m][x].length;w>b;b++)a[x][b]=u[m][x][b]+v*h*c[m][x][b];else{var C=function(t){return+u[m][t]+v*h*c[m][t]};a=[["m",C(0),C(1),C(2),C(3),C(4),C(5)]]}break;case"csv":if("clip-rect"==m)for(a=[],x=4;x--;)a[x]=+u[m][x]+v*h*c[m][x];break;default:var D=[][S](u[m]);for(a=[],x=d.paper.customAttributes[m].length;x--;)a[x]=+D[x]+v*h*c[m][x]}f[m]=a}d.attr(f),function(t,i,n){setTimeout(function(){e("raphael.anim.frame."+t,i,n)})}(d.id,d,r.anim)}else{if(function(t,n,r){setTimeout(function(){e("raphael.anim.frame."+n.id,n,r),e("raphael.anim.finish."+n.id,n,r),i.is(t,"function")&&t.call(n)})}(r.callback,d,r.anim),d.attr(p),oi.splice(n--,1),r.repeat>1&&!r.next){for(s in p)p[T](s)&&(g[s]=r.totalOrigin[s]);r.el.attr(g),y(r.anim,r.el,r.anim.percents[0],null,r.totalOrigin,r.repeat-1)}r.next&&!r.stop&&y(r.anim,r.el,r.next,null,r.totalOrigin,r.repeat)}}}i.svg&&d&&d.paper&&d.paper.safari(),oi.length&&hi(li)},ui=function(t){return t>255?255:0>t?0:t};Qe.animateWith=function(t,e,n,r,a,s){var o=this;if(o.removed)return s&&s.call(o),o;var h=n instanceof m?n:i.animation(n,r,a,s);y(h,o,h.percents[0],null,o.attr());for(var l=0,u=oi.length;u>l;l++)if(oi[l].anim==e&&oi[l].el==t){oi[u-1].start=oi[l].start;break}return o},Qe.onAnimation=function(t){return t?e.on("raphael.anim.frame."+this.id,t):e.unbind("raphael.anim.frame."+this.id),this},m.prototype.delay=function(t){var e=new m(this.anim,this.ms);return e.times=this.times,e.del=+t||0,e},m.prototype.repeat=function(t){var e=new m(this.anim,this.ms);return e.del=this.del,e.times=j.floor($(t,0))||1,e},i.animation=function(t,e,n,r){if(t instanceof m)return t;(i.is(n,"function")||!n)&&(r=r||n||null,n=null),t=Object(t),e=+e||0;var a,s,o={};for(s in t)t[T](s)&&Z(s)!=s&&Z(s)+"%"!=s&&(a=!0,o[s]=t[s]);return a?(n&&(o.easing=n),r&&(o.callback=r),new m({100:o},e)):new m(t,e)},Qe.animate=function(t,e,n,r){var a=this;if(a.removed)return r&&r.call(a),a;var s=t instanceof m?t:i.animation(t,e,n,r);return y(s,a,s.percents[0],null,a.attr()),a},Qe.setTime=function(t,e){return t&&null!=e&&this.status(t,z(e,t.ms)/t.ms),this},Qe.status=function(t,e){var i,n,r=[],a=0;if(null!=e)return y(t,this,-1,z(e,1)),this;for(i=oi.length;i>a;a++)if(n=oi[a],n.el.id==this.id&&(!t||n.anim==t)){if(t)return n.status;r.push({anim:n.anim,status:n.status})}return t?0:r},Qe.pause=function(t){for(var i=0;oi.length>i;i++)oi[i].el.id!=this.id||t&&oi[i].anim!=t||e("raphael.anim.pause."+this.id,this,oi[i].anim)!==!1&&(oi[i].paused=!0);return this},Qe.resume=function(t){for(var i=0;oi.length>i;i++)if(oi[i].el.id==this.id&&(!t||oi[i].anim==t)){var n=oi[i];e("raphael.anim.resume."+this.id,this,n.anim)!==!1&&(delete n.paused,this.status(n.anim,n.status))}return this},Qe.stop=function(t){for(var i=0;oi.length>i;i++)oi[i].el.id!=this.id||t&&oi[i].anim!=t||e("raphael.anim.stop."+this.id,this,oi[i].anim)!==!1&&oi.splice(i--,1);return this},e.on("raphael.remove",x),e.on("raphael.clear",x),Qe.toString=function(){return"Raphaël’s object"};var ci=function(t){if(this.items=[],this.length=0,this.type="set",t)for(var e=0,i=t.length;i>e;e++)!t[e]||t[e].constructor!=Qe.constructor&&t[e].constructor!=ci||(this[this.items.length]=this.items[this.items.length]=t[e],this.length++)},pi=ci.prototype;pi.push=function(){for(var t,e,i=0,n=arguments.length;n>i;i++)t=arguments[i],!t||t.constructor!=Qe.constructor&&t.constructor!=ci||(e=this.items.length,this[e]=this.items[e]=t,this.length++);return this},pi.pop=function(){return this.length&&delete this[this.length--],this.items.pop()},pi.forEach=function(t,e){for(var i=0,n=this.items.length;n>i;i++)if(t.call(e,this.items[i],i)===!1)return this;return this};for(var di in Qe)Qe[T](di)&&(pi[di]=function(t){return function(){var e=arguments;return this.forEach(function(i){i[t][E](i,e)})}}(di));return pi.attr=function(t,e){if(t&&i.is(t,q)&&i.is(t[0],"object"))for(var n=0,r=t.length;r>n;n++)this.items[n].attr(t[n]);else for(var a=0,s=this.items.length;s>a;a++)this.items[a].attr(t,e);return this},pi.clear=function(){for(;this.length;)this.pop()},pi.splice=function(t,e){t=0>t?$(this.length+t,0):t,e=$(0,z(this.length-t,e));var i,n=[],r=[],a=[];for(i=2;arguments.length>i;i++)a.push(arguments[i]);for(i=0;e>i;i++)r.push(this[t+i]);for(;this.length-t>i;i++)n.push(this[t+i]);var s=a.length;for(i=0;s+n.length>i;i++)this.items[t+i]=this[t+i]=s>i?a[i]:n[i-s];for(i=this.items.length=this.length-=e-s;this[i];)delete this[i++];return new ci(r)},pi.exclude=function(t){for(var e=0,i=this.length;i>e;e++)if(this[e]==t)return this.splice(e,1),!0},pi.animate=function(t,e,n,r){(i.is(n,"function")||!n)&&(r=n||null);var a,s,o=this.items.length,h=o,l=this;if(!o)return this;r&&(s=function(){!--o&&r.call(l)}),n=i.is(n,W)?n:s;var u=i.animation(t,e,n,s);for(a=this.items[--h].animate(u);h--;)this.items[h]&&!this.items[h].removed&&this.items[h].animateWith(a,u,u),this.items[h]&&!this.items[h].removed||o--;return this},pi.insertAfter=function(t){for(var e=this.items.length;e--;)this.items[e].insertAfter(t);return this},pi.getBBox=function(){for(var t=[],e=[],i=[],n=[],r=this.items.length;r--;)if(!this.items[r].removed){var a=this.items[r].getBBox();t.push(a.x),e.push(a.y),i.push(a.x+a.width),n.push(a.y+a.height)}return t=z[E](0,t),e=z[E](0,e),i=$[E](0,i),n=$[E](0,n),{x:t,y:e,x2:i,y2:n,width:i-t,height:n-e}},pi.clone=function(t){t=this.paper.set();for(var e=0,i=this.items.length;i>e;e++)t.push(this.items[e].clone());return t},pi.toString=function(){return"Raphaël‘s set"},pi.glow=function(t){var e=this.paper.set();return this.forEach(function(i){var n=i.glow(t);null!=n&&n.forEach(function(t){e.push(t)})}),e},pi.isPointInside=function(t,e){var i=!1;return this.forEach(function(n){return n.isPointInside(t,e)?(console.log("runned"),i=!0,!1):void 0}),i},i.registerFont=function(t){if(!t.face)return t;this.fonts=this.fonts||{};var e={w:t.w,face:{},glyphs:{}},i=t.face["font-family"];for(var n in t.face)t.face[T](n)&&(e.face[n]=t.face[n]);if(this.fonts[i]?this.fonts[i].push(e):this.fonts[i]=[e],!t.svg){e.face["units-per-em"]=te(t.face["units-per-em"],10);for(var r in t.glyphs)if(t.glyphs[T](r)){var a=t.glyphs[r];if(e.glyphs[r]={w:a.w,k:{},d:a.d&&"M"+a.d.replace(/[mlcxtrv]/g,function(t){return{l:"L",c:"C",x:"z",t:"m",r:"l",v:"c"}[t]||"M"})+"z"},a.k)for(var s in a.k)a[T](s)&&(e.glyphs[r].k[s]=a.k[s])}}return t},b.getFont=function(t,e,n,r){if(r=r||"normal",n=n||"normal",e=+e||{normal:400,bold:700,lighter:300,bolder:800}[e]||400,i.fonts){var a=i.fonts[t];if(!a){var s=RegExp("(^|\\s)"+t.replace(/[^\w\d\s+!~.:_-]/g,A)+"(\\s|$)","i");for(var o in i.fonts)if(i.fonts[T](o)&&s.test(o)){a=i.fonts[o];break}}var h;if(a)for(var l=0,u=a.length;u>l&&(h=a[l],h.face["font-weight"]!=e||h.face["font-style"]!=n&&h.face["font-style"]||h.face["font-stretch"]!=r);l++);return h}},b.print=function(t,e,n,r,a,s,o,h){s=s||"middle",o=$(z(o||0,1),-1),h=$(z(h||1,3),1);var l,u=B(n)[F](A),c=0,p=0,d=A;if(i.is(r,"string")&&(r=this.getFont(r)),r){l=(a||16)/r.face["units-per-em"];for(var f=r.face.bbox[F](w),g=+f[0],v=f[3]-f[1],m=0,y=+f[1]+("baseline"==s?v+ +r.face.descent:v/2),x=0,_=u.length;_>x;x++){if("\n"==u[x])c=0,C=0,p=0,m+=v*h;else{var b=p&&r.glyphs[u[x-1]]||{},C=r.glyphs[u[x]];c+=p?(b.w||r.w)+(b.k&&b.k[u[x]]||0)+r.w*o:0,p=1}C&&C.d&&(d+=i.transformPath(C.d,["t",c*l,m*l,"s",l,l,g,y,"t",(t-g)/l,(e-y)/l]))}}return this.path(d).attr({fill:"#000",stroke:"none"})},b.add=function(t){if(i.is(t,"array"))for(var e,n=this.set(),r=0,a=t.length;a>r;r++)e=t[r]||{},C[T](e.type)&&n.push(this[e.type]().attr(e));return n},i.format=function(t,e){var n=i.is(e,q)?[0][S](e):arguments;return t&&i.is(t,W)&&n.length-1&&(t=t.replace(D,function(t,e){return null==n[++e]?A:n[e]})),t||A},i.fullfill=function(){var t=/\{([^\}]+)\}/g,e=/(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g,i=function(t,i,n){var r=n;return i.replace(e,function(t,e,i,n,a){e=e||n,r&&(e in r&&(r=r[e]),"function"==typeof r&&a&&(r=r()))}),r=(null==r||r==n?t:r)+""};return function(e,n){return(e+"").replace(t,function(t,e){return i(t,e,n)})}}(),i.ninja=function(){return k.was?L.win.Raphael=k.is:delete Raphael,i},i.st=pi,function(t,e,n){function r(){/in/.test(t.readyState)?setTimeout(r,9):i.eve("raphael.DOMload")}null==t.readyState&&t.addEventListener&&(t.addEventListener(e,n=function(){t.removeEventListener(e,n,!1),t.readyState="complete"},!1),t.readyState="loading"),r()}(document,"DOMContentLoaded"),e.on("raphael.DOMload",function(){_=!0}),function(){if(i.svg){var t="hasOwnProperty",e=String,n=parseFloat,r=parseInt,a=Math,s=a.max,o=a.abs,h=a.pow,l=/[, ]+/,u=i.eve,c="",p=" ",d="http://www.w3.org/1999/xlink",f={block:"M5,0 0,2.5 5,5z",classic:"M5,0 0,2.5 5,5 3.5,3 3.5,2z",diamond:"M2.5,0 5,2.5 2.5,5 0,2.5z",open:"M6,1 1,3.5 6,6",oval:"M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"},g={};i.toString=function(){return"Your browser supports SVG.\nYou are running Raphaël "+this.version};var v=function(n,r){if(r){"string"==typeof n&&(n=v(n));for(var a in r)r[t](a)&&("xlink:"==a.substring(0,6)?n.setAttributeNS(d,a.substring(6),e(r[a])):n.setAttribute(a,e(r[a])))}else n=i._g.doc.createElementNS("http://www.w3.org/2000/svg",n),n.style&&(n.style.webkitTapHighlightColor="rgba(0,0,0,0)");return n},m=function(t,r){var l="linear",u=t.id+r,p=.5,d=.5,f=t.node,g=t.paper,m=f.style,y=i._g.doc.getElementById(u);if(!y){if(r=e(r).replace(i._radial_gradient,function(t,e,i){if(l="radial",e&&i){p=n(e),d=n(i);var r=2*(d>.5)-1;h(p-.5,2)+h(d-.5,2)>.25&&(d=a.sqrt(.25-h(p-.5,2))*r+.5)&&.5!=d&&(d=d.toFixed(5)-1e-5*r)}return c}),r=r.split(/\s*\-\s*/),"linear"==l){var x=r.shift();if(x=-n(x),isNaN(x))return null;var _=[0,0,a.cos(i.rad(x)),a.sin(i.rad(x))],b=1/(s(o(_[2]),o(_[3]))||1);_[2]*=b,_[3]*=b,0>_[2]&&(_[0]=-_[2],_[2]=0),0>_[3]&&(_[1]=-_[3],_[3]=0)}var w=i._parseDots(r);if(!w)return null;if(u=u.replace(/[\(\)\s,\xb0#]/g,"_"),t.gradient&&u!=t.gradient.id&&(g.defs.removeChild(t.gradient),delete t.gradient),!t.gradient){y=v(l+"Gradient",{id:u}),t.gradient=y,v(y,"radial"==l?{fx:p,fy:d}:{x1:_[0],y1:_[1],x2:_[2],y2:_[3],gradientTransform:t.matrix.invert()}),g.defs.appendChild(y);for(var C=0,D=w.length;D>C;C++)y.appendChild(v("stop",{offset:w[C].offset?w[C].offset:C?"100%":"0%","stop-color":w[C].color||"#fff"}))}}return v(f,{fill:"url(#"+u+")",opacity:1,"fill-opacity":1}),m.fill=c,m.opacity=1,m.fillOpacity=1,1},y=function(t){var e=t.getBBox(1);v(t.pattern,{patternTransform:t.matrix.invert()+" translate("+e.x+","+e.y+")"})},x=function(n,r,a){if("path"==n.type){for(var s,o,h,l,u,p=e(r).toLowerCase().split("-"),d=n.paper,m=a?"end":"start",y=n.node,x=n.attrs,_=x["stroke-width"],b=p.length,w="classic",C=3,D=3,T=5;b--;)switch(p[b]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":w=p[b];break;case"wide":D=5;break;case"narrow":D=2;break;case"long":C=5;break;case"short":C=2}if("open"==w?(C+=2,D+=2,T+=2,h=1,l=a?4:1,u={fill:"none",stroke:x.stroke}):(l=h=C/2,u={fill:x.stroke,stroke:"none"}),n._.arrows?a?(n._.arrows.endPath&&g[n._.arrows.endPath]--,n._.arrows.endMarker&&g[n._.arrows.endMarker]--):(n._.arrows.startPath&&g[n._.arrows.startPath]--,n._.arrows.startMarker&&g[n._.arrows.startMarker]--):n._.arrows={},"none"!=w){var L="raphael-marker-"+w,k="raphael-marker-"+m+w+C+D;i._g.doc.getElementById(L)?g[L]++:(d.defs.appendChild(v(v("path"),{"stroke-linecap":"round",d:f[w],id:L})),g[L]=1);var M,E=i._g.doc.getElementById(k);E?(g[k]++,M=E.getElementsByTagName("use")[0]):(E=v(v("marker"),{id:k,markerHeight:D,markerWidth:C,orient:"auto",refX:l,refY:D/2}),M=v(v("use"),{"xlink:href":"#"+L,transform:(a?"rotate(180 "+C/2+" "+D/2+") ":c)+"scale("+C/T+","+D/T+")","stroke-width":(1/((C/T+D/T)/2)).toFixed(4)}),E.appendChild(M),d.defs.appendChild(E),g[k]=1),v(M,u);var S=h*("diamond"!=w&&"oval"!=w);a?(s=n._.arrows.startdx*_||0,o=i.getTotalLength(x.path)-S*_):(s=S*_,o=i.getTotalLength(x.path)-(n._.arrows.enddx*_||0)),u={},u["marker-"+m]="url(#"+k+")",(o||s)&&(u.d=i.getSubpath(x.path,s,o)),v(y,u),n._.arrows[m+"Path"]=L,n._.arrows[m+"Marker"]=k,n._.arrows[m+"dx"]=S,n._.arrows[m+"Type"]=w,n._.arrows[m+"String"]=r}else a?(s=n._.arrows.startdx*_||0,o=i.getTotalLength(x.path)-s):(s=0,o=i.getTotalLength(x.path)-(n._.arrows.enddx*_||0)),n._.arrows[m+"Path"]&&v(y,{d:i.getSubpath(x.path,s,o)}),delete n._.arrows[m+"Path"],delete n._.arrows[m+"Marker"],delete n._.arrows[m+"dx"],delete n._.arrows[m+"Type"],delete n._.arrows[m+"String"];for(u in g)if(g[t](u)&&!g[u]){var I=i._g.doc.getElementById(u);I&&I.parentNode.removeChild(I)}}},_={"":[0],none:[0],"-":[3,1],".":[1,1],"-.":[3,1,1,1],"-..":[3,1,1,1,1,1],". ":[1,3],"- ":[4,3],"--":[8,3],"- .":[4,3,1,3],"--.":[8,3,1,3],"--..":[8,3,1,3,1,3]},b=function(t,i,n){if(i=_[e(i).toLowerCase()]){for(var r=t.attrs["stroke-width"]||"1",a={round:r,square:r,butt:0}[t.attrs["stroke-linecap"]||n["stroke-linecap"]]||0,s=[],o=i.length;o--;)s[o]=i[o]*r+(o%2?1:-1)*a;v(t.node,{"stroke-dasharray":s.join(",")})}},w=function(n,a){var h=n.node,u=n.attrs,p=h.style.visibility;h.style.visibility="hidden";for(var f in a)if(a[t](f)){if(!i._availableAttrs[t](f))continue;var g=a[f];switch(u[f]=g,f){case"blur":n.blur(g);break;case"href":case"title":case"target":var _=h.parentNode;if("a"!=_.tagName.toLowerCase()){var w=v("a");_.insertBefore(w,h),w.appendChild(h),_=w}"target"==f?_.setAttributeNS(d,"show","blank"==g?"new":g):_.setAttributeNS(d,f,g);break;case"cursor":h.style.cursor=g;break;case"transform":n.transform(g);break;case"arrow-start":x(n,g);break;case"arrow-end":x(n,g,1);break;case"clip-rect":var C=e(g).split(l);if(4==C.length){n.clip&&n.clip.parentNode.parentNode.removeChild(n.clip.parentNode);var T=v("clipPath"),L=v("rect");T.id=i.createUUID(),v(L,{x:C[0],y:C[1],width:C[2],height:C[3]}),T.appendChild(L),n.paper.defs.appendChild(T),v(h,{"clip-path":"url(#"+T.id+")"}),n.clip=L}if(!g){var k=h.getAttribute("clip-path");if(k){var M=i._g.doc.getElementById(k.replace(/(^url\(#|\)$)/g,c));M&&M.parentNode.removeChild(M),v(h,{"clip-path":c}),delete n.clip}}break;case"path":"path"==n.type&&(v(h,{d:g?u.path=i._pathToAbsolute(g):"M0,0"}),n._.dirty=1,n._.arrows&&("startString"in n._.arrows&&x(n,n._.arrows.startString),"endString"in n._.arrows&&x(n,n._.arrows.endString,1)));break;case"width":if(h.setAttribute(f,g),n._.dirty=1,!u.fx)break;f="x",g=u.x;case"x":u.fx&&(g=-u.x-(u.width||0));case"rx":if("rx"==f&&"rect"==n.type)break;case"cx":h.setAttribute(f,g),n.pattern&&y(n),n._.dirty=1;break;case"height":if(h.setAttribute(f,g),n._.dirty=1,!u.fy)break;f="y",g=u.y;case"y":u.fy&&(g=-u.y-(u.height||0));case"ry":if("ry"==f&&"rect"==n.type)break;case"cy":h.setAttribute(f,g),n.pattern&&y(n),n._.dirty=1;break;case"r":"rect"==n.type?v(h,{rx:g,ry:g}):h.setAttribute(f,g),n._.dirty=1;break;case"src":"image"==n.type&&h.setAttributeNS(d,"href",g);break;case"stroke-width":(1!=n._.sx||1!=n._.sy)&&(g/=s(o(n._.sx),o(n._.sy))||1),n.paper._vbSize&&(g*=n.paper._vbSize),h.setAttribute(f,g),u["stroke-dasharray"]&&b(n,u["stroke-dasharray"],a),n._.arrows&&("startString"in n._.arrows&&x(n,n._.arrows.startString),"endString"in n._.arrows&&x(n,n._.arrows.endString,1));break;case"stroke-dasharray":b(n,g,a);break;case"fill":var E=e(g).match(i._ISURL);if(E){T=v("pattern");var S=v("image");T.id=i.createUUID(),v(T,{x:0,y:0,patternUnits:"userSpaceOnUse",height:1,width:1}),v(S,{x:0,y:0,"xlink:href":E[1]}),T.appendChild(S),function(t){i._preload(E[1],function(){var e=this.offsetWidth,i=this.offsetHeight;v(t,{width:e,height:i}),v(S,{width:e,height:i}),n.paper.safari()})}(T),n.paper.defs.appendChild(T),v(h,{fill:"url(#"+T.id+")"}),n.pattern=T,n.pattern&&y(n);break}var I=i.getRGB(g);if(I.error){if(("circle"==n.type||"ellipse"==n.type||"r"!=e(g).charAt())&&m(n,g)){if("opacity"in u||"fill-opacity"in u){var A=i._g.doc.getElementById(h.getAttribute("fill").replace(/^url\(#|\)$/g,c));if(A){var P=A.getElementsByTagName("stop");v(P[P.length-1],{"stop-opacity":("opacity"in u?u.opacity:1)*("fill-opacity"in u?u["fill-opacity"]:1)})}}u.gradient=g,u.fill="none";break}}else delete a.gradient,delete u.gradient,!i.is(u.opacity,"undefined")&&i.is(a.opacity,"undefined")&&v(h,{opacity:u.opacity}),!i.is(u["fill-opacity"],"undefined")&&i.is(a["fill-opacity"],"undefined")&&v(h,{"fill-opacity":u["fill-opacity"]});I[t]("opacity")&&v(h,{"fill-opacity":I.opacity>1?I.opacity/100:I.opacity});case"stroke":I=i.getRGB(g),h.setAttribute(f,I.hex),"stroke"==f&&I[t]("opacity")&&v(h,{"stroke-opacity":I.opacity>1?I.opacity/100:I.opacity}),"stroke"==f&&n._.arrows&&("startString"in n._.arrows&&x(n,n._.arrows.startString),"endString"in n._.arrows&&x(n,n._.arrows.endString,1));break;case"gradient":("circle"==n.type||"ellipse"==n.type||"r"!=e(g).charAt())&&m(n,g);break;case"opacity":u.gradient&&!u[t]("stroke-opacity")&&v(h,{"stroke-opacity":g>1?g/100:g});case"fill-opacity":if(u.gradient){A=i._g.doc.getElementById(h.getAttribute("fill").replace(/^url\(#|\)$/g,c)),A&&(P=A.getElementsByTagName("stop"),v(P[P.length-1],{"stop-opacity":g}));break}default:"font-size"==f&&(g=r(g,10)+"px");var B=f.replace(/(\-.)/g,function(t){return t.substring(1).toUpperCase()});h.style[B]=g,n._.dirty=1,h.setAttribute(f,g)}}D(n,a),h.style.visibility=p},C=1.2,D=function(n,a){if("text"==n.type&&(a[t]("text")||a[t]("font")||a[t]("font-size")||a[t]("x")||a[t]("y"))){var s=n.attrs,o=n.node,h=o.firstChild?r(i._g.doc.defaultView.getComputedStyle(o.firstChild,c).getPropertyValue("font-size"),10):10;if(a[t]("text")){for(s.text=a.text;o.firstChild;)o.removeChild(o.firstChild);for(var l,u=e(a.text).split("\n"),p=[],d=0,f=u.length;f>d;d++)l=v("tspan"),d&&v(l,{dy:h*C,x:s.x}),l.appendChild(i._g.doc.createTextNode(u[d])),o.appendChild(l),p[d]=l -}else for(p=o.getElementsByTagName("tspan"),d=0,f=p.length;f>d;d++)d?v(p[d],{dy:h*C,x:s.x}):v(p[0],{dy:0});v(o,{x:s.x,y:s.y}),n._.dirty=1;var g=n._getBBox(),m=s.y-(g.y+g.height/2);m&&i.is(m,"finite")&&v(p[0],{dy:m})}},T=function(t,e){this[0]=this.node=t,t.raphael=!0,this.id=i._oid++,t.raphaelid=this.id,this.matrix=i.matrix(),this.realPath=null,this.paper=e,this.attrs=this.attrs||{},this._={transform:[],sx:1,sy:1,deg:0,dx:0,dy:0,dirty:1},!e.bottom&&(e.bottom=this),this.prev=e.top,e.top&&(e.top.next=this),e.top=this,this.next=null},L=i.el;T.prototype=L,L.constructor=T,i._engine.path=function(t,e){var i=v("path");e.canvas&&e.canvas.appendChild(i);var n=new T(i,e);return n.type="path",w(n,{fill:"none",stroke:"#000",path:t}),n},L.rotate=function(t,i,r){if(this.removed)return this;if(t=e(t).split(l),t.length-1&&(i=n(t[1]),r=n(t[2])),t=n(t[0]),null==r&&(i=r),null==i||null==r){var a=this.getBBox(1);i=a.x+a.width/2,r=a.y+a.height/2}return this.transform(this._.transform.concat([["r",t,i,r]])),this},L.scale=function(t,i,r,a){if(this.removed)return this;if(t=e(t).split(l),t.length-1&&(i=n(t[1]),r=n(t[2]),a=n(t[3])),t=n(t[0]),null==i&&(i=t),null==a&&(r=a),null==r||null==a)var s=this.getBBox(1);return r=null==r?s.x+s.width/2:r,a=null==a?s.y+s.height/2:a,this.transform(this._.transform.concat([["s",t,i,r,a]])),this},L.translate=function(t,i){return this.removed?this:(t=e(t).split(l),t.length-1&&(i=n(t[1])),t=n(t[0])||0,i=+i||0,this.transform(this._.transform.concat([["t",t,i]])),this)},L.transform=function(e){var n=this._;if(null==e)return n.transform;if(i._extractTransform(this,e),this.clip&&v(this.clip,{transform:this.matrix.invert()}),this.pattern&&y(this),this.node&&v(this.node,{transform:this.matrix}),1!=n.sx||1!=n.sy){var r=this.attrs[t]("stroke-width")?this.attrs["stroke-width"]:1;this.attr({"stroke-width":r})}return this},L.hide=function(){return!this.removed&&this.paper.safari(this.node.style.display="none"),this},L.show=function(){return!this.removed&&this.paper.safari(this.node.style.display=""),this},L.remove=function(){if(!this.removed&&this.node.parentNode){var t=this.paper;t.__set__&&t.__set__.exclude(this),u.unbind("raphael.*.*."+this.id),this.gradient&&t.defs.removeChild(this.gradient),i._tear(this,t),"a"==this.node.parentNode.tagName.toLowerCase()?this.node.parentNode.parentNode.removeChild(this.node.parentNode):this.node.parentNode.removeChild(this.node);for(var e in this)this[e]="function"==typeof this[e]?i._removedFactory(e):null;this.removed=!0}},L._getBBox=function(){if("none"==this.node.style.display){this.show();var t=!0}var e={};try{e=this.node.getBBox()}catch(i){}finally{e=e||{}}return t&&this.hide(),e},L.attr=function(e,n){if(this.removed)return this;if(null==e){var r={};for(var a in this.attrs)this.attrs[t](a)&&(r[a]=this.attrs[a]);return r.gradient&&"none"==r.fill&&(r.fill=r.gradient)&&delete r.gradient,r.transform=this._.transform,r}if(null==n&&i.is(e,"string")){if("fill"==e&&"none"==this.attrs.fill&&this.attrs.gradient)return this.attrs.gradient;if("transform"==e)return this._.transform;for(var s=e.split(l),o={},h=0,c=s.length;c>h;h++)e=s[h],o[e]=e in this.attrs?this.attrs[e]:i.is(this.paper.customAttributes[e],"function")?this.paper.customAttributes[e].def:i._availableAttrs[e];return c-1?o:o[s[0]]}if(null==n&&i.is(e,"array")){for(o={},h=0,c=e.length;c>h;h++)o[e[h]]=this.attr(e[h]);return o}if(null!=n){var p={};p[e]=n}else null!=e&&i.is(e,"object")&&(p=e);for(var d in p)u("raphael.attr."+d+"."+this.id,this,p[d]);for(d in this.paper.customAttributes)if(this.paper.customAttributes[t](d)&&p[t](d)&&i.is(this.paper.customAttributes[d],"function")){var f=this.paper.customAttributes[d].apply(this,[].concat(p[d]));this.attrs[d]=p[d];for(var g in f)f[t](g)&&(p[g]=f[g])}return w(this,p),this},L.toFront=function(){if(this.removed)return this;"a"==this.node.parentNode.tagName.toLowerCase()?this.node.parentNode.parentNode.appendChild(this.node.parentNode):this.node.parentNode.appendChild(this.node);var t=this.paper;return t.top!=this&&i._tofront(this,t),this},L.toBack=function(){if(this.removed)return this;var t=this.node.parentNode;return"a"==t.tagName.toLowerCase()?t.parentNode.insertBefore(this.node.parentNode,this.node.parentNode.parentNode.firstChild):t.firstChild!=this.node&&t.insertBefore(this.node,this.node.parentNode.firstChild),i._toback(this,this.paper),this.paper,this},L.insertAfter=function(t){if(this.removed)return this;var e=t.node||t[t.length-1].node;return e.nextSibling?e.parentNode.insertBefore(this.node,e.nextSibling):e.parentNode.appendChild(this.node),i._insertafter(this,t,this.paper),this},L.insertBefore=function(t){if(this.removed)return this;var e=t.node||t[0].node;return e.parentNode.insertBefore(this.node,e),i._insertbefore(this,t,this.paper),this},L.blur=function(t){var e=this;if(0!==+t){var n=v("filter"),r=v("feGaussianBlur");e.attrs.blur=t,n.id=i.createUUID(),v(r,{stdDeviation:+t||1.5}),n.appendChild(r),e.paper.defs.appendChild(n),e._blur=n,v(e.node,{filter:"url(#"+n.id+")"})}else e._blur&&(e._blur.parentNode.removeChild(e._blur),delete e._blur,delete e.attrs.blur),e.node.removeAttribute("filter");return e},i._engine.circle=function(t,e,i,n){var r=v("circle");t.canvas&&t.canvas.appendChild(r);var a=new T(r,t);return a.attrs={cx:e,cy:i,r:n,fill:"none",stroke:"#000"},a.type="circle",v(r,a.attrs),a},i._engine.rect=function(t,e,i,n,r,a){var s=v("rect");t.canvas&&t.canvas.appendChild(s);var o=new T(s,t);return o.attrs={x:e,y:i,width:n,height:r,r:a||0,rx:a||0,ry:a||0,fill:"none",stroke:"#000"},o.type="rect",v(s,o.attrs),o},i._engine.ellipse=function(t,e,i,n,r){var a=v("ellipse");t.canvas&&t.canvas.appendChild(a);var s=new T(a,t);return s.attrs={cx:e,cy:i,rx:n,ry:r,fill:"none",stroke:"#000"},s.type="ellipse",v(a,s.attrs),s},i._engine.image=function(t,e,i,n,r,a){var s=v("image");v(s,{x:i,y:n,width:r,height:a,preserveAspectRatio:"none"}),s.setAttributeNS(d,"href",e),t.canvas&&t.canvas.appendChild(s);var o=new T(s,t);return o.attrs={x:i,y:n,width:r,height:a,src:e},o.type="image",o},i._engine.text=function(t,e,n,r){var a=v("text");t.canvas&&t.canvas.appendChild(a);var s=new T(a,t);return s.attrs={x:e,y:n,"text-anchor":"middle",text:r,font:i._availableAttrs.font,stroke:"none",fill:"#000"},s.type="text",w(s,s.attrs),s},i._engine.setSize=function(t,e){return this.width=t||this.width,this.height=e||this.height,this.canvas.setAttribute("width",this.width),this.canvas.setAttribute("height",this.height),this._viewBox&&this.setViewBox.apply(this,this._viewBox),this},i._engine.create=function(){var t=i._getContainer.apply(0,arguments),e=t&&t.container,n=t.x,r=t.y,a=t.width,s=t.height;if(!e)throw Error("SVG container not found.");var o,h=v("svg"),l="overflow:hidden;";return n=n||0,r=r||0,a=a||512,s=s||342,v(h,{height:s,version:1.1,width:a,xmlns:"http://www.w3.org/2000/svg"}),1==e?(h.style.cssText=l+"position:absolute;left:"+n+"px;top:"+r+"px",i._g.doc.body.appendChild(h),o=1):(h.style.cssText=l+"position:relative",e.firstChild?e.insertBefore(h,e.firstChild):e.appendChild(h)),e=new i._Paper,e.width=a,e.height=s,e.canvas=h,e.clear(),e._left=e._top=0,o&&(e.renderfix=function(){}),e.renderfix(),e},i._engine.setViewBox=function(t,e,i,n,r){u("raphael.setViewBox",this,this._viewBox,[t,e,i,n,r]);var a,o,h=s(i/this.width,n/this.height),l=this.top,c=r?"meet":"xMinYMin";for(null==t?(this._vbSize&&(h=1),delete this._vbSize,a="0 0 "+this.width+p+this.height):(this._vbSize=h,a=t+p+e+p+i+p+n),v(this.canvas,{viewBox:a,preserveAspectRatio:c});h&&l;)o="stroke-width"in l.attrs?l.attrs["stroke-width"]:1,l.attr({"stroke-width":o}),l._.dirty=1,l._.dirtyT=1,l=l.prev;return this._viewBox=[t,e,i,n,!!r],this},i.prototype.renderfix=function(){var t,e=this.canvas,i=e.style;try{t=e.getScreenCTM()||e.createSVGMatrix()}catch(n){t=e.createSVGMatrix()}var r=-t.e%1,a=-t.f%1;(r||a)&&(r&&(this._left=(this._left+r)%1,i.left=this._left+"px"),a&&(this._top=(this._top+a)%1,i.top=this._top+"px"))},i.prototype.clear=function(){i.eve("raphael.clear",this);for(var t=this.canvas;t.firstChild;)t.removeChild(t.firstChild);this.bottom=this.top=null,(this.desc=v("desc")).appendChild(i._g.doc.createTextNode("Created with Raphaël "+i.version)),t.appendChild(this.desc),t.appendChild(this.defs=v("defs"))},i.prototype.remove=function(){u("raphael.remove",this),this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas);for(var t in this)this[t]="function"==typeof this[t]?i._removedFactory(t):null};var k=i.st;for(var M in L)L[t](M)&&!k[t](M)&&(k[M]=function(t){return function(){var e=arguments;return this.forEach(function(i){i[t].apply(i,e)})}}(M))}}(),function(){if(i.vml){var t="hasOwnProperty",e=String,n=parseFloat,r=Math,a=r.round,s=r.max,o=r.min,h=r.abs,l="fill",u=/[, ]+/,c=i.eve,p=" progid:DXImageTransform.Microsoft",d=" ",f="",g={M:"m",L:"l",C:"c",Z:"x",m:"t",l:"r",c:"v",z:"x"},v=/([clmz]),?([^clmz]*)/gi,m=/ progid:\S+Blur\([^\)]+\)/g,y=/-?[^,\s-]+/g,x="position:absolute;left:0;top:0;width:1px;height:1px",_=21600,b={path:1,rect:1,image:1},w={circle:1,ellipse:1},C=function(t){var n=/[ahqstv]/gi,r=i._pathToAbsolute;if(e(t).match(n)&&(r=i._path2curve),n=/[clmz]/g,r==i._pathToAbsolute&&!e(t).match(n)){var s=e(t).replace(v,function(t,e,i){var n=[],r="m"==e.toLowerCase(),s=g[e];return i.replace(y,function(t){r&&2==n.length&&(s+=n+g["m"==e?"l":"L"],n=[]),n.push(a(t*_))}),s+n});return s}var o,h,l=r(t);s=[];for(var u=0,c=l.length;c>u;u++){o=l[u],h=l[u][0].toLowerCase(),"z"==h&&(h="x");for(var p=1,m=o.length;m>p;p++)h+=a(o[p]*_)+(p!=m-1?",":f);s.push(h)}return s.join(d)},D=function(t,e,n){var r=i.matrix();return r.rotate(-t,.5,.5),{dx:r.x(e,n),dy:r.y(e,n)}},T=function(t,e,i,n,r,a){var s=t._,o=t.matrix,u=s.fillpos,c=t.node,p=c.style,f=1,g="",v=_/e,m=_/i;if(p.visibility="hidden",e&&i){if(c.coordsize=h(v)+d+h(m),p.rotation=a*(0>e*i?-1:1),a){var y=D(a,n,r);n=y.dx,r=y.dy}if(0>e&&(g+="x"),0>i&&(g+=" y")&&(f=-1),p.flip=g,c.coordorigin=n*-v+d+r*-m,u||s.fillsize){var x=c.getElementsByTagName(l);x=x&&x[0],c.removeChild(x),u&&(y=D(a,o.x(u[0],u[1]),o.y(u[0],u[1])),x.position=y.dx*f+d+y.dy*f),s.fillsize&&(x.size=s.fillsize[0]*h(e)+d+s.fillsize[1]*h(i)),c.appendChild(x)}p.visibility="visible"}};i.toString=function(){return"Your browser doesn’t support SVG. Falling down to VML.\nYou are running Raphaël "+this.version};var L=function(t,i,n){for(var r=e(i).toLowerCase().split("-"),a=n?"end":"start",s=r.length,o="classic",h="medium",l="medium";s--;)switch(r[s]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":o=r[s];break;case"wide":case"narrow":l=r[s];break;case"long":case"short":h=r[s]}var u=t.node.getElementsByTagName("stroke")[0];u[a+"arrow"]=o,u[a+"arrowlength"]=h,u[a+"arrowwidth"]=l},k=function(r,h){r.attrs=r.attrs||{};var c=r.node,p=r.attrs,g=c.style,v=b[r.type]&&(h.x!=p.x||h.y!=p.y||h.width!=p.width||h.height!=p.height||h.cx!=p.cx||h.cy!=p.cy||h.rx!=p.rx||h.ry!=p.ry||h.r!=p.r),m=w[r.type]&&(p.cx!=h.cx||p.cy!=h.cy||p.r!=h.r||p.rx!=h.rx||p.ry!=h.ry),y=r;for(var x in h)h[t](x)&&(p[x]=h[x]);if(v&&(p.path=i._getPath[r.type](r),r._.dirty=1),h.href&&(c.href=h.href),h.title&&(c.title=h.title),h.target&&(c.target=h.target),h.cursor&&(g.cursor=h.cursor),"blur"in h&&r.blur(h.blur),(h.path&&"path"==r.type||v)&&(c.path=C(~e(p.path).toLowerCase().indexOf("r")?i._pathToAbsolute(p.path):p.path),"image"==r.type&&(r._.fillpos=[p.x,p.y],r._.fillsize=[p.width,p.height],T(r,1,1,0,0,0))),"transform"in h&&r.transform(h.transform),m){var D=+p.cx,k=+p.cy,E=+p.rx||+p.r||0,S=+p.ry||+p.r||0;c.path=i.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x",a((D-E)*_),a((k-S)*_),a((D+E)*_),a((k+S)*_),a(D*_)),r._.dirty=1}if("clip-rect"in h){var A=e(h["clip-rect"]).split(u);if(4==A.length){A[2]=+A[2]+ +A[0],A[3]=+A[3]+ +A[1];var P=c.clipRect||i._g.doc.createElement("div"),B=P.style;B.clip=i.format("rect({1}px {2}px {3}px {0}px)",A),c.clipRect||(B.position="absolute",B.top=0,B.left=0,B.width=r.paper.width+"px",B.height=r.paper.height+"px",c.parentNode.insertBefore(P,c),P.appendChild(c),c.clipRect=P)}h["clip-rect"]||c.clipRect&&(c.clipRect.style.clip="auto")}if(r.textpath){var F=r.textpath.style;h.font&&(F.font=h.font),h["font-family"]&&(F.fontFamily='"'+h["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g,f)+'"'),h["font-size"]&&(F.fontSize=h["font-size"]),h["font-weight"]&&(F.fontWeight=h["font-weight"]),h["font-style"]&&(F.fontStyle=h["font-style"])}if("arrow-start"in h&&L(y,h["arrow-start"]),"arrow-end"in h&&L(y,h["arrow-end"],1),null!=h.opacity||null!=h["stroke-width"]||null!=h.fill||null!=h.src||null!=h.stroke||null!=h["stroke-width"]||null!=h["stroke-opacity"]||null!=h["fill-opacity"]||null!=h["stroke-dasharray"]||null!=h["stroke-miterlimit"]||null!=h["stroke-linejoin"]||null!=h["stroke-linecap"]){var G=c.getElementsByTagName(l),R=!1;if(G=G&&G[0],!G&&(R=G=I(l)),"image"==r.type&&h.src&&(G.src=h.src),h.fill&&(G.on=!0),(null==G.on||"none"==h.fill||null===h.fill)&&(G.on=!1),G.on&&h.fill){var O=e(h.fill).match(i._ISURL);if(O){G.parentNode==c&&c.removeChild(G),G.rotate=!0,G.src=O[1],G.type="tile";var j=r.getBBox(1);G.position=j.x+d+j.y,r._.fillpos=[j.x,j.y],i._preload(O[1],function(){r._.fillsize=[this.offsetWidth,this.offsetHeight]})}else G.color=i.getRGB(h.fill).hex,G.src=f,G.type="solid",i.getRGB(h.fill).error&&(y.type in{circle:1,ellipse:1}||"r"!=e(h.fill).charAt())&&M(y,h.fill,G)&&(p.fill="none",p.gradient=h.fill,G.rotate=!1)}if("fill-opacity"in h||"opacity"in h){var $=((+p["fill-opacity"]+1||2)-1)*((+p.opacity+1||2)-1)*((+i.getRGB(h.fill).o+1||2)-1);$=o(s($,0),1),G.opacity=$,G.src&&(G.color="none")}c.appendChild(G);var z=c.getElementsByTagName("stroke")&&c.getElementsByTagName("stroke")[0],N=!1;!z&&(N=z=I("stroke")),(h.stroke&&"none"!=h.stroke||h["stroke-width"]||null!=h["stroke-opacity"]||h["stroke-dasharray"]||h["stroke-miterlimit"]||h["stroke-linejoin"]||h["stroke-linecap"])&&(z.on=!0),("none"==h.stroke||null===h.stroke||null==z.on||0==h.stroke||0==h["stroke-width"])&&(z.on=!1);var Y=i.getRGB(h.stroke);z.on&&h.stroke&&(z.color=Y.hex),$=((+p["stroke-opacity"]+1||2)-1)*((+p.opacity+1||2)-1)*((+Y.o+1||2)-1);var X=.75*(n(h["stroke-width"])||1);if($=o(s($,0),1),null==h["stroke-width"]&&(X=p["stroke-width"]),h["stroke-width"]&&(z.weight=X),X&&1>X&&($*=X)&&(z.weight=1),z.opacity=$,h["stroke-linejoin"]&&(z.joinstyle=h["stroke-linejoin"]||"miter"),z.miterlimit=h["stroke-miterlimit"]||8,h["stroke-linecap"]&&(z.endcap="butt"==h["stroke-linecap"]?"flat":"square"==h["stroke-linecap"]?"square":"round"),h["stroke-dasharray"]){var H={"-":"shortdash",".":"shortdot","-.":"shortdashdot","-..":"shortdashdotdot",". ":"dot","- ":"dash","--":"longdash","- .":"dashdot","--.":"longdashdot","--..":"longdashdotdot"};z.dashstyle=H[t](h["stroke-dasharray"])?H[h["stroke-dasharray"]]:f}N&&c.appendChild(z)}if("text"==y.type){y.paper.canvas.style.display=f;var W=y.paper.span,q=100,U=p.font&&p.font.match(/\d+(?:\.\d*)?(?=px)/);g=W.style,p.font&&(g.font=p.font),p["font-family"]&&(g.fontFamily=p["font-family"]),p["font-weight"]&&(g.fontWeight=p["font-weight"]),p["font-style"]&&(g.fontStyle=p["font-style"]),U=n(p["font-size"]||U&&U[0])||10,g.fontSize=U*q+"px",y.textpath.string&&(W.innerHTML=e(y.textpath.string).replace(/"));var V=W.getBoundingClientRect();y.W=p.w=(V.right-V.left)/q,y.H=p.h=(V.bottom-V.top)/q,y.X=p.x,y.Y=p.y+y.H/2,("x"in h||"y"in h)&&(y.path.v=i.format("m{0},{1}l{2},{1}",a(p.x*_),a(p.y*_),a(p.x*_)+1));for(var J=["x","y","text","font","font-family","font-weight","font-style","font-size"],Q=0,K=J.length;K>Q;Q++)if(J[Q]in h){y._.dirty=1;break}switch(p["text-anchor"]){case"start":y.textpath.style["v-text-align"]="left",y.bbx=y.W/2;break;case"end":y.textpath.style["v-text-align"]="right",y.bbx=-y.W/2;break;default:y.textpath.style["v-text-align"]="center",y.bbx=0}y.textpath.style["v-text-kern"]=!0}},M=function(t,a,s){t.attrs=t.attrs||{};var o=(t.attrs,Math.pow),h="linear",l=".5 .5";if(t.attrs.gradient=a,a=e(a).replace(i._radial_gradient,function(t,e,i){return h="radial",e&&i&&(e=n(e),i=n(i),o(e-.5,2)+o(i-.5,2)>.25&&(i=r.sqrt(.25-o(e-.5,2))*(2*(i>.5)-1)+.5),l=e+d+i),f}),a=a.split(/\s*\-\s*/),"linear"==h){var u=a.shift();if(u=-n(u),isNaN(u))return null}var c=i._parseDots(a);if(!c)return null;if(t=t.shape||t.node,c.length){t.removeChild(s),s.on=!0,s.method="none",s.color=c[0].color,s.color2=c[c.length-1].color;for(var p=[],g=0,v=c.length;v>g;g++)c[g].offset&&p.push(c[g].offset+d+c[g].color);s.colors=p.length?p.join():"0% "+s.color,"radial"==h?(s.type="gradientTitle",s.focus="100%",s.focussize="0 0",s.focusposition=l,s.angle=0):(s.type="gradient",s.angle=(270-u)%360),t.appendChild(s)}return 1},E=function(t,e){this[0]=this.node=t,t.raphael=!0,this.id=i._oid++,t.raphaelid=this.id,this.X=0,this.Y=0,this.attrs={},this.paper=e,this.matrix=i.matrix(),this._={transform:[],sx:1,sy:1,dx:0,dy:0,deg:0,dirty:1,dirtyT:1},!e.bottom&&(e.bottom=this),this.prev=e.top,e.top&&(e.top.next=this),e.top=this,this.next=null},S=i.el;E.prototype=S,S.constructor=E,S.transform=function(t){if(null==t)return this._.transform;var n,r=this.paper._viewBoxShift,a=r?"s"+[r.scale,r.scale]+"-1-1t"+[r.dx,r.dy]:f;r&&(n=t=e(t).replace(/\.{3}|\u2026/g,this._.transform||f)),i._extractTransform(this,a+t);var s,o=this.matrix.clone(),h=this.skew,l=this.node,u=~e(this.attrs.fill).indexOf("-"),c=!e(this.attrs.fill).indexOf("url(");if(o.translate(-.5,-.5),c||u||"image"==this.type)if(h.matrix="1 0 0 1",h.offset="0 0",s=o.split(),u&&s.noRotation||!s.isSimple){l.style.filter=o.toFilter();var p=this.getBBox(),g=this.getBBox(1),v=p.x-g.x,m=p.y-g.y;l.coordorigin=v*-_+d+m*-_,T(this,1,1,v,m,0)}else l.style.filter=f,T(this,s.scalex,s.scaley,s.dx,s.dy,s.rotate);else l.style.filter=f,h.matrix=e(o),h.offset=o.offset();return n&&(this._.transform=n),this},S.rotate=function(t,i,r){if(this.removed)return this;if(null!=t){if(t=e(t).split(u),t.length-1&&(i=n(t[1]),r=n(t[2])),t=n(t[0]),null==r&&(i=r),null==i||null==r){var a=this.getBBox(1);i=a.x+a.width/2,r=a.y+a.height/2}return this._.dirtyT=1,this.transform(this._.transform.concat([["r",t,i,r]])),this}},S.translate=function(t,i){return this.removed?this:(t=e(t).split(u),t.length-1&&(i=n(t[1])),t=n(t[0])||0,i=+i||0,this._.bbox&&(this._.bbox.x+=t,this._.bbox.y+=i),this.transform(this._.transform.concat([["t",t,i]])),this)},S.scale=function(t,i,r,a){if(this.removed)return this;if(t=e(t).split(u),t.length-1&&(i=n(t[1]),r=n(t[2]),a=n(t[3]),isNaN(r)&&(r=null),isNaN(a)&&(a=null)),t=n(t[0]),null==i&&(i=t),null==a&&(r=a),null==r||null==a)var s=this.getBBox(1);return r=null==r?s.x+s.width/2:r,a=null==a?s.y+s.height/2:a,this.transform(this._.transform.concat([["s",t,i,r,a]])),this._.dirtyT=1,this},S.hide=function(){return!this.removed&&(this.node.style.display="none"),this},S.show=function(){return!this.removed&&(this.node.style.display=f),this},S._getBBox=function(){return this.removed?{}:{x:this.X+(this.bbx||0)-this.W/2,y:this.Y-this.H,width:this.W,height:this.H}},S.remove=function(){if(!this.removed&&this.node.parentNode){this.paper.__set__&&this.paper.__set__.exclude(this),i.eve.unbind("raphael.*.*."+this.id),i._tear(this,this.paper),this.node.parentNode.removeChild(this.node),this.shape&&this.shape.parentNode.removeChild(this.shape);for(var t in this)this[t]="function"==typeof this[t]?i._removedFactory(t):null;this.removed=!0}},S.attr=function(e,n){if(this.removed)return this;if(null==e){var r={};for(var a in this.attrs)this.attrs[t](a)&&(r[a]=this.attrs[a]);return r.gradient&&"none"==r.fill&&(r.fill=r.gradient)&&delete r.gradient,r.transform=this._.transform,r}if(null==n&&i.is(e,"string")){if(e==l&&"none"==this.attrs.fill&&this.attrs.gradient)return this.attrs.gradient;for(var s=e.split(u),o={},h=0,p=s.length;p>h;h++)e=s[h],o[e]=e in this.attrs?this.attrs[e]:i.is(this.paper.customAttributes[e],"function")?this.paper.customAttributes[e].def:i._availableAttrs[e];return p-1?o:o[s[0]]}if(this.attrs&&null==n&&i.is(e,"array")){for(o={},h=0,p=e.length;p>h;h++)o[e[h]]=this.attr(e[h]);return o}var d;null!=n&&(d={},d[e]=n),null==n&&i.is(e,"object")&&(d=e);for(var f in d)c("raphael.attr."+f+"."+this.id,this,d[f]);if(d){for(f in this.paper.customAttributes)if(this.paper.customAttributes[t](f)&&d[t](f)&&i.is(this.paper.customAttributes[f],"function")){var g=this.paper.customAttributes[f].apply(this,[].concat(d[f]));this.attrs[f]=d[f];for(var v in g)g[t](v)&&(d[v]=g[v])}d.text&&"text"==this.type&&(this.textpath.string=d.text),k(this,d)}return this},S.toFront=function(){return!this.removed&&this.node.parentNode.appendChild(this.node),this.paper&&this.paper.top!=this&&i._tofront(this,this.paper),this},S.toBack=function(){return this.removed?this:(this.node.parentNode.firstChild!=this.node&&(this.node.parentNode.insertBefore(this.node,this.node.parentNode.firstChild),i._toback(this,this.paper)),this)},S.insertAfter=function(t){return this.removed?this:(t.constructor==i.st.constructor&&(t=t[t.length-1]),t.node.nextSibling?t.node.parentNode.insertBefore(this.node,t.node.nextSibling):t.node.parentNode.appendChild(this.node),i._insertafter(this,t,this.paper),this)},S.insertBefore=function(t){return this.removed?this:(t.constructor==i.st.constructor&&(t=t[0]),t.node.parentNode.insertBefore(this.node,t.node),i._insertbefore(this,t,this.paper),this)},S.blur=function(t){var e=this.node.runtimeStyle,n=e.filter;return n=n.replace(m,f),0!==+t?(this.attrs.blur=t,e.filter=n+d+p+".Blur(pixelradius="+(+t||1.5)+")",e.margin=i.format("-{0}px 0 0 -{0}px",a(+t||1.5))):(e.filter=n,e.margin=0,delete this.attrs.blur),this},i._engine.path=function(t,e){var i=I("shape");i.style.cssText=x,i.coordsize=_+d+_,i.coordorigin=e.coordorigin;var n=new E(i,e),r={fill:"none",stroke:"#000"};t&&(r.path=t),n.type="path",n.path=[],n.Path=f,k(n,r),e.canvas.appendChild(i);var a=I("skew");return a.on=!0,i.appendChild(a),n.skew=a,n.transform(f),n},i._engine.rect=function(t,e,n,r,a,s){var o=i._rectPath(e,n,r,a,s),h=t.path(o),l=h.attrs;return h.X=l.x=e,h.Y=l.y=n,h.W=l.width=r,h.H=l.height=a,l.r=s,l.path=o,h.type="rect",h},i._engine.ellipse=function(t,e,i,n,r){var a=t.path();return a.attrs,a.X=e-n,a.Y=i-r,a.W=2*n,a.H=2*r,a.type="ellipse",k(a,{cx:e,cy:i,rx:n,ry:r}),a},i._engine.circle=function(t,e,i,n){var r=t.path();return r.attrs,r.X=e-n,r.Y=i-n,r.W=r.H=2*n,r.type="circle",k(r,{cx:e,cy:i,r:n}),r},i._engine.image=function(t,e,n,r,a,s){var o=i._rectPath(n,r,a,s),h=t.path(o).attr({stroke:"none"}),u=h.attrs,c=h.node,p=c.getElementsByTagName(l)[0];return u.src=e,h.X=u.x=n,h.Y=u.y=r,h.W=u.width=a,h.H=u.height=s,u.path=o,h.type="image",p.parentNode==c&&c.removeChild(p),p.rotate=!0,p.src=e,p.type="tile",h._.fillpos=[n,r],h._.fillsize=[a,s],c.appendChild(p),T(h,1,1,0,0,0),h},i._engine.text=function(t,n,r,s){var o=I("shape"),h=I("path"),l=I("textpath");n=n||0,r=r||0,s=s||"",h.v=i.format("m{0},{1}l{2},{1}",a(n*_),a(r*_),a(n*_)+1),h.textpathok=!0,l.string=e(s),l.on=!0,o.style.cssText=x,o.coordsize=_+d+_,o.coordorigin="0 0";var u=new E(o,t),c={fill:"#000",stroke:"none",font:i._availableAttrs.font,text:s};u.shape=o,u.path=h,u.textpath=l,u.type="text",u.attrs.text=e(s),u.attrs.x=n,u.attrs.y=r,u.attrs.w=1,u.attrs.h=1,k(u,c),o.appendChild(l),o.appendChild(h),t.canvas.appendChild(o);var p=I("skew");return p.on=!0,o.appendChild(p),u.skew=p,u.transform(f),u},i._engine.setSize=function(t,e){var n=this.canvas.style;return this.width=t,this.height=e,t==+t&&(t+="px"),e==+e&&(e+="px"),n.width=t,n.height=e,n.clip="rect(0 "+t+" "+e+" 0)",this._viewBox&&i._engine.setViewBox.apply(this,this._viewBox),this},i._engine.setViewBox=function(t,e,n,r,a){i.eve("raphael.setViewBox",this,this._viewBox,[t,e,n,r,a]);var o,h,l=this.width,u=this.height,c=1/s(n/l,r/u);return a&&(o=u/r,h=l/n,l>n*o&&(t-=(l-n*o)/2/o),u>r*h&&(e-=(u-r*h)/2/h)),this._viewBox=[t,e,n,r,!!a],this._viewBoxShift={dx:-t,dy:-e,scale:c},this.forEach(function(t){t.transform("...")}),this};var I;i._engine.initWin=function(t){var e=t.document;e.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{!e.namespaces.rvml&&e.namespaces.add("rvml","urn:schemas-microsoft-com:vml"),I=function(t){return e.createElement("')}}catch(i){I=function(t){return e.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}},i._engine.initWin(i._g.win),i._engine.create=function(){var t=i._getContainer.apply(0,arguments),e=t.container,n=t.height,r=t.width,a=t.x,s=t.y;if(!e)throw Error("VML container not found.");var o=new i._Paper,h=o.canvas=i._g.doc.createElement("div"),l=h.style;return a=a||0,s=s||0,r=r||512,n=n||342,o.width=r,o.height=n,r==+r&&(r+="px"),n==+n&&(n+="px"),o.coordsize=1e3*_+d+1e3*_,o.coordorigin="0 0",o.span=i._g.doc.createElement("span"),o.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",h.appendChild(o.span),l.cssText=i.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",r,n),1==e?(i._g.doc.body.appendChild(h),l.left=a+"px",l.top=s+"px",l.position="absolute"):e.firstChild?e.insertBefore(h,e.firstChild):e.appendChild(h),o.renderfix=function(){},o},i.prototype.clear=function(){i.eve("raphael.clear",this),this.canvas.innerHTML=f,this.span=i._g.doc.createElement("span"),this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;",this.canvas.appendChild(this.span),this.bottom=this.top=null},i.prototype.remove=function(){i.eve("raphael.remove",this),this.canvas.parentNode.removeChild(this.canvas);for(var t in this)this[t]="function"==typeof this[t]?i._removedFactory(t):null;return!0};var A=i.st;for(var P in S)S[t](P)&&!A[t](P)&&(A[P]=function(t){return function(){var e=arguments;return this.forEach(function(i){i[t].apply(i,e)})}}(P))}}(),k.was?L.win.Raphael=i:Raphael=i,i});(function(){var t,e,i,n,r=[].slice,a={}.hasOwnProperty,s=function(t,e){function i(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},o=function(t,e){return function(){return t.apply(e,arguments)}},h=[].indexOf||function(t){for(var e=0,i=this.length;i>e;e++)if(e in this&&this[e]===t)return e;return-1};e=window.Morris={},t=jQuery,e.EventEmitter=function(){function t(){}return t.prototype.on=function(t,e){return null==this.handlers&&(this.handlers={}),null==this.handlers[t]&&(this.handlers[t]=[]),this.handlers[t].push(e),this},t.prototype.fire=function(){var t,e,i,n,a,s,o;i=arguments[0],t=arguments.length>=2?r.call(arguments,1):[];if(null!=this.handlers&&null!=this.handlers[i]){s=this.handlers[i],o=[];for(n=0,a=s.length;a>n;n++)e=s[n],o.push(e.apply(null,t));return o}},t}(),e.commas=function(t){var e,i,n,r;return null!=t?(n=0>t?"-":"",e=Math.abs(t),i=Math.floor(e).toFixed(0),n+=i.replace(/(?=(?:\d{3})+$)(?!^)/g,","),r=""+e,r.length>i.length&&(n+=r.slice(i.length)),n):"-"},e.pad2=function(t){return(10>t?"0":"")+t},e.Grid=function(i){function n(e){var i=this;this.el="string"==typeof e.element?t(document.getElementById(e.element)):t(e.element);if(null==this.el||0===this.el.length)throw Error("Graph container element not found");"static"===this.el.css("position")&&this.el.css("position","relative"),this.options=t.extend({},this.gridDefaults,this.defaults||{},e),"string"==typeof this.options.units&&(this.options.postUnits=e.units),this.raphael=new Raphael(this.el[0]),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.init&&this.init(),this.setData(this.options.data),this.el.bind("mousemove",function(t){var e;return e=i.el.offset(),i.fire("hovermove",t.pageX-e.left,t.pageY-e.top)}),this.el.bind("mouseout",function(){return i.fire("hoverout")}),this.el.bind("touchstart touchmove touchend",function(t){var e,n;return n=t.originalEvent.touches[0]||t.originalEvent.changedTouches[0],e=i.el.offset(),i.fire("hover",n.pageX-e.left,n.pageY-e.top),n}),this.el.bind("click",function(t){var e;return e=i.el.offset(),i.fire("gridclick",t.pageX-e.left,t.pageY-e.top)}),this.postInit&&this.postInit()}return s(n,i),n.prototype.gridDefaults={dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,gridTextFamily:"sans-serif",gridTextWeight:"normal",hideHover:!1,yLabelFormat:null,xLabelAngle:0,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"]},n.prototype.setData=function(t,i){var n,r,a,s,o,h,l,u,c,p,d,f,g,v;null==i&&(i=!0),this.options.data=t;if(null!=t&&0!==t.length){f=this.cumulative?0:null,g=this.cumulative?0:null,this.options.goals.length>0&&(o=Math.min.apply(null,this.options.goals),s=Math.max.apply(null,this.options.goals),g=null!=g?Math.min(g,o):o,f=null!=f?Math.max(f,s):s),this.data=function(){var i,n,s;s=[];for(a=i=0,n=t.length;n>i;a=++i)l=t[a],h={},h.label=l[this.options.xkey],this.options.parseTime?(h.x=e.parseDate(h.label),this.options.dateFormat?h.label=this.options.dateFormat(h.x):"number"==typeof h.label&&(h.label=""+new Date(h.label))):(h.x=a,this.options.xLabelFormat&&(h.label=this.options.xLabelFormat(h))),c=0,h.y=function(){var t,e,i,n;i=this.options.ykeys,n=[];for(r=t=0,e=i.length;e>t;r=++t)d=i[r],v=l[d],"string"==typeof v&&(v=parseFloat(v)),null!=v&&"number"!=typeof v&&(v=null),null!=v&&(this.cumulative?c+=v:null!=f?(f=Math.max(v,f),g=Math.min(v,g)):f=g=v),this.cumulative&&null!=c&&(f=Math.max(c,f),g=Math.min(c,g)),n.push(v);return n}.call(this),s.push(h);return s}.call(this),this.options.parseTime&&(this.data=this.data.sort(function(t,e){return(t.x>e.x)-(e.x>t.x)})),this.xmin=this.data[0].x,this.xmax=this.data[this.data.length-1].x,this.events=[],this.options.parseTime&&this.options.events.length>0&&(this.events=function(){var t,i,r,a;r=this.options.events,a=[];for(t=0,i=r.length;i>t;t++)n=r[t],a.push(e.parseDate(n));return a}.call(this),this.xmax=Math.max(this.xmax,Math.max.apply(null,this.events)),this.xmin=Math.min(this.xmin,Math.min.apply(null,this.events))),this.xmin===this.xmax&&(this.xmin-=1,this.xmax+=1),this.ymin=this.yboundary("min",g),this.ymax=this.yboundary("max",f),this.ymin===this.ymax&&(g&&(this.ymin-=1),this.ymax+=1);(this.options.axes===!0||this.options.grid===!0)&&(this.options.ymax===this.gridDefaults.ymax&&this.options.ymin===this.gridDefaults.ymin?(this.grid=this.autoGridLines(this.ymin,this.ymax,this.options.numLines),this.ymin=Math.min(this.ymin,this.grid[0]),this.ymax=Math.max(this.ymax,this.grid[this.grid.length-1])):(u=(this.ymax-this.ymin)/(this.options.numLines-1),this.grid=function(){var t,e,i,n;n=[];for(p=t=e=this.ymin,i=this.ymax;i>=e?i>=t:t>=i;p=t+=u)n.push(p);return n}.call(this)));this.dirty=!0;return i?this.redraw():void 0}this.data=[],this.raphael.clear(),null!=this.hover&&this.hover.hide()},n.prototype.yboundary=function(t,e){var i,n;return i=this.options["y"+t],"string"==typeof i?"auto"===i.slice(0,4)?i.length>5?(n=parseInt(i.slice(5),10),null==e?n:Math[t](e,n)):null!=e?e:0:parseInt(i,10):i},n.prototype.autoGridLines=function(t,e,i){var n,r,a,s,o,h,l,u,c;return o=e-t,c=Math.floor(Math.log(o)/Math.log(10)),l=Math.pow(10,c),r=Math.floor(t/l)*l,n=Math.ceil(e/l)*l,h=(n-r)/(i-1),1===l&&h>1&&Math.ceil(h)!==h&&(h=Math.ceil(h),n=r+h*(i-1)),0>r&&n>0&&(r=Math.floor(t/h)*h,n=Math.ceil(e/h)*h),1>h?(s=Math.floor(Math.log(h)/Math.log(10)),a=function(){var t,e;e=[];for(u=t=r;n>=r?n>=t:t>=n;u=t+=h)e.push(parseFloat(u.toFixed(1-s)));return e}()):a=function(){var t,e;e=[];for(u=t=r;n>=r?n>=t:t>=n;u=t+=h)e.push(u);return e}(),a},n.prototype._calc=function(){var t,e,i,n,r,a;r=this.el.width(),i=this.el.height();if(this.elementWidth!==r||this.elementHeight!==i||this.dirty){this.elementWidth=r,this.elementHeight=i,this.dirty=!1,this.left=this.options.padding,this.right=this.elementWidth-this.options.padding,this.top=this.options.padding,this.bottom=this.elementHeight-this.options.padding,this.options.axes&&(a=function(){var t,i,n,r;n=this.grid,r=[];for(t=0,i=n.length;i>t;t++)e=n[t],r.push(this.measureText(this.yAxisFormat(e)).width); -return r}.call(this),this.left+=Math.max.apply(Math,a),t=function(){var t,e,i;i=[];for(n=t=0,e=this.data.length;e>=0?e>t:t>e;n=e>=0?++t:--t)i.push(this.measureText(this.data[n].text,-this.options.xLabelAngle).height);return i}.call(this),this.bottom-=Math.max.apply(Math,t)),this.width=Math.max(1,this.right-this.left),this.height=Math.max(1,this.bottom-this.top),this.dx=this.width/(this.xmax-this.xmin),this.dy=this.height/(this.ymax-this.ymin);if(this.calc)return this.calc()}},n.prototype.transY=function(t){return this.bottom-(t-this.ymin)*this.dy},n.prototype.transX=function(t){return 1===this.data.length?(this.left+this.right)/2:this.left+(t-this.xmin)*this.dx},n.prototype.redraw=function(){this.raphael.clear(),this._calc(),this.drawGrid(),this.drawGoals(),this.drawEvents();return this.draw?this.draw():void 0},n.prototype.measureText=function(t,e){var i,n;return null==e&&(e=0),n=this.raphael.text(100,100,t).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).rotate(e),i=n.getBBox(),n.remove(),i},n.prototype.yAxisFormat=function(t){return this.yLabelFormat(t)},n.prototype.yLabelFormat=function(t){return"function"==typeof this.options.yLabelFormat?this.options.yLabelFormat(t):""+this.options.preUnits+e.commas(t)+this.options.postUnits},n.prototype.updateHover=function(t,e){var i,n;i=this.hitTest(t,e);return null!=i?(n=this.hover).update.apply(n,i):void 0},n.prototype.drawGrid=function(){var t,e,i,n,r,a;if(this.options.grid!==!1||this.options.axes!==!1){r=this.grid,a=[];for(i=0,n=r.length;n>i;i++)t=r[i],e=this.transY(t),this.options.axes&&this.drawYAxisLabel(this.left-this.options.padding/2,e,this.yAxisFormat(t)),this.options.grid?a.push(this.drawGridLine("M"+this.left+","+e+"H"+(this.left+this.width))):a.push(void 0);return a}},n.prototype.drawGoals=function(){var t,e,i,n,r,a,s;a=this.options.goals,s=[];for(i=n=0,r=a.length;r>n;i=++n)e=a[i],t=this.options.goalLineColors[i%this.options.goalLineColors.length],s.push(this.drawGoal(e,t));return s},n.prototype.drawEvents=function(){var t,e,i,n,r,a,s;a=this.events,s=[];for(i=n=0,r=a.length;r>n;i=++n)e=a[i],t=this.options.eventLineColors[i%this.options.eventLineColors.length],s.push(this.drawEvent(e,t));return s},n.prototype.drawGoal=function(t,e){return this.raphael.path("M"+this.left+","+this.transY(t)+"H"+this.right).attr("stroke",e).attr("stroke-width",this.options.goalStrokeWidth)},n.prototype.drawEvent=function(t,e){return this.raphael.path("M"+this.transX(t)+","+this.bottom+"V"+this.top).attr("stroke",e).attr("stroke-width",this.options.eventStrokeWidth)},n.prototype.drawYAxisLabel=function(t,e,i){return this.raphael.text(t,e,i).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor).attr("text-anchor","end")},n.prototype.drawGridLine=function(t){return this.raphael.path(t).attr("stroke",this.options.gridLineColor).attr("stroke-width",this.options.gridStrokeWidth)},n}(e.EventEmitter),e.parseDate=function(t){var e,i,n,r,a,s,o,h,l,u,c;return"number"==typeof t?t:(i=t.match(/^(\d+) Q(\d)$/),r=t.match(/^(\d+)-(\d+)$/),a=t.match(/^(\d+)-(\d+)-(\d+)$/),o=t.match(/^(\d+) W(\d+)$/),h=t.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+)(Z|([+-])(\d\d):?(\d\d))?$/),l=t.match(/^(\d+)-(\d+)-(\d+)[ T](\d+):(\d+):(\d+(\.\d+)?)(Z|([+-])(\d\d):?(\d\d))?$/),i?new Date(parseInt(i[1],10),3*parseInt(i[2],10)-1,1).getTime():r?new Date(parseInt(r[1],10),parseInt(r[2],10)-1,1).getTime():a?new Date(parseInt(a[1],10),parseInt(a[2],10)-1,parseInt(a[3],10)).getTime():o?(u=new Date(parseInt(o[1],10),0,1),4!==u.getDay()&&u.setMonth(0,1+(4-u.getDay()+7)%7),u.getTime()+6048e5*parseInt(o[2],10)):h?h[6]?(s=0,"Z"!==h[6]&&(s=60*parseInt(h[8],10)+parseInt(h[9],10),"+"===h[7]&&(s=0-s)),Date.UTC(parseInt(h[1],10),parseInt(h[2],10)-1,parseInt(h[3],10),parseInt(h[4],10),parseInt(h[5],10)+s)):new Date(parseInt(h[1],10),parseInt(h[2],10)-1,parseInt(h[3],10),parseInt(h[4],10),parseInt(h[5],10)).getTime():l?(c=parseFloat(l[6]),e=Math.floor(c),n=Math.round(1e3*(c-e)),l[8]?(s=0,"Z"!==l[8]&&(s=60*parseInt(l[10],10)+parseInt(l[11],10),"+"===l[9]&&(s=0-s)),Date.UTC(parseInt(l[1],10),parseInt(l[2],10)-1,parseInt(l[3],10),parseInt(l[4],10),parseInt(l[5],10)+s,e,n)):new Date(parseInt(l[1],10),parseInt(l[2],10)-1,parseInt(l[3],10),parseInt(l[4],10),parseInt(l[5],10),e,n).getTime()):new Date(parseInt(t,10),0,1).getTime())},e.Hover=function(){function i(i){null==i&&(i={}),this.options=t.extend({},e.Hover.defaults,i),this.el=t("
"),this.el.hide(),this.options.parent.append(this.el)}return i.defaults={"class":"morris-hover morris-default-style"},i.prototype.update=function(t,e,i){return this.html(t),this.show(),this.moveTo(e,i)},i.prototype.html=function(t){return this.el.html(t)},i.prototype.moveTo=function(t,e){var i,n,r,a,s,o;return s=this.options.parent.innerWidth(),a=this.options.parent.innerHeight(),n=this.el.outerWidth(),i=this.el.outerHeight(),r=Math.min(Math.max(0,t-n/2),s-n),null!=e?(o=e-i-10,0>o&&(o=e+10,o+i>a&&(o=a/2-i/2))):o=a/2-i/2,this.el.css({left:r+"px",top:parseInt(o)+"px"})},i.prototype.show=function(){return this.el.show()},i.prototype.hide=function(){return this.el.hide()},i}(),e.Line=function(t){function i(t){this.hilight=o(this.hilight,this),this.onHoverOut=o(this.onHoverOut,this),this.onHoverMove=o(this.onHoverMove,this),this.onGridClick=o(this.onGridClick,this);if(!(this instanceof e.Line))return new e.Line(t);i.__super__.constructor.call(this,t);return void 0}return s(i,t),i.prototype.init=function(){this.pointGrow=Raphael.animation({r:this.options.pointSize+3},25,"linear"),this.pointShrink=Raphael.animation({r:this.options.pointSize},25,"linear");return"always"!==this.options.hideHover?(this.hover=new e.Hover({parent:this.el}),this.on("hovermove",this.onHoverMove),this.on("hoverout",this.onHoverOut),this.on("gridclick",this.onGridClick)):void 0},i.prototype.defaults={lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:24,continuousLine:!0,hideHover:!1},i.prototype.calc=function(){return this.calcPoints(),this.generatePaths()},i.prototype.calcPoints=function(){var t,e,i,n,r,a;r=this.data,a=[];for(i=0,n=r.length;n>i;i++)t=r[i],t._x=this.transX(t.x),t._y=function(){var i,n,r,a;r=t.y,a=[];for(i=0,n=r.length;n>i;i++)e=r[i],null!=e?a.push(this.transY(e)):a.push(e);return a}.call(this),a.push(t._ymax=Math.min.apply(null,[this.bottom].concat(function(){var i,n,r,a;r=t._y,a=[];for(i=0,n=r.length;n>i;i++)e=r[i],null!=e&&a.push(e);return a}())));return a},i.prototype.hitTest=function(t){var e,i,n,r,a;if(0===this.data.length)return null;a=this.data.slice(1);for(e=n=0,r=a.length;r>n;e=++n){i=a[e];if((i._x+this.data[e]._x)/2>t)break}return e},i.prototype.onGridClick=function(t,e){var i;return i=this.hitTest(t,e),this.fire("click",i,this.options.data[i],t,e)},i.prototype.onHoverMove=function(t,e){var i;return i=this.hitTest(t,e),this.displayHoverForRow(i)},i.prototype.onHoverOut=function(){return this.options.hideHover!==!1?this.displayHoverForRow(null):void 0},i.prototype.displayHoverForRow=function(t){var e;return null!=t?((e=this.hover).update.apply(e,this.hoverContentForRow(t)),this.hilight(t)):(this.hover.hide(),this.hilight())},i.prototype.hoverContentForRow=function(t){var e,i,n,r,a,s,o;n=this.data[t],e="
"+n.label+"
",o=n.y;for(i=a=0,s=o.length;s>a;i=++a)r=o[i],e+="
\n "+this.options.labels[i]+":\n "+this.yLabelFormat(r)+"\n
";return"function"==typeof this.options.hoverCallback&&(e=this.options.hoverCallback(t,this.options,e)),[e,n._x,n._ymax]},i.prototype.generatePaths=function(){var t,i,n,r,a;return this.paths=function(){var s,o,l,u;u=[];for(n=s=0,o=this.options.ykeys.length;o>=0?o>s:s>o;n=o>=0?++s:--s)a=this.options.smooth===!0||(l=this.options.ykeys[n],h.call(this.options.smooth,l)>=0),i=function(){var t,e,i,a;i=this.data,a=[];for(t=0,e=i.length;e>t;t++)r=i[t],void 0!==r._y[n]&&a.push({x:r._x,y:r._y[n]});return a}.call(this),this.options.continuousLine&&(i=function(){var e,n,r;r=[];for(e=0,n=i.length;n>e;e++)t=i[e],null!==t.y&&r.push(t);return r}()),i.length>1?u.push(e.Line.createPath(i,a,this.bottom)):u.push(null);return u}.call(this)},i.prototype.draw=function(){this.options.axes&&this.drawXAxis(),this.drawSeries();return this.options.hideHover===!1?this.displayHoverForRow(this.data.length-1):void 0},i.prototype.drawXAxis=function(){var t,i,n,r,a,s,o,h,l,u,c=this;o=this.bottom+this.options.padding/2,a=null,r=null,t=function(t,e){var i,n,s,h,l;return i=c.drawXAxisLabel(c.transX(e),o,t),l=i.getBBox(),i.transform("r"+-c.options.xLabelAngle),n=i.getBBox(),i.transform("t0,"+n.height/2+"..."),0!==c.options.xLabelAngle&&(h=-.5*l.width*Math.cos(c.options.xLabelAngle*Math.PI/180),i.transform("t"+h+",0...")),n=i.getBBox(),(null==a||a>=n.x+n.width||null!=r&&r>=n.x)&&n.x>=0&&n.x+n.widtht;t++)s=i[t],n.push([s.label,s.x]);return n}.call(this),n.reverse(),u=[];for(h=0,l=n.length;l>h;h++)i=n[h],u.push(t(i[0],i[1]));return u},i.prototype.drawSeries=function(){var t,e,i,n,r,a;this.seriesPoints=[];for(t=e=n=this.options.ykeys.length-1;0>=n?0>=e:e>=0;t=0>=n?++e:--e)this._drawLineFor(t);a=[];for(t=i=r=this.options.ykeys.length-1;0>=r?0>=i:i>=0;t=0>=r?++i:--i)a.push(this._drawPointFor(t));return a},i.prototype._drawPointFor=function(t){var e,i,n,r,a,s;this.seriesPoints[t]=[],a=this.data,s=[];for(n=0,r=a.length;r>n;n++)i=a[n],e=null,null!=i._y[t]&&(e=this.drawLinePoint(i._x,i._y[t],this.options.pointSize,this.colorFor(i,t,"point"),t)),s.push(this.seriesPoints[t].push(e));return s},i.prototype._drawLineFor=function(t){var e;e=this.paths[t];return null!==e?this.drawLinePath(e,this.colorFor(null,t,"line")):void 0},i.createPath=function(t,i,n){var r,a,s,o,h,l,u,c,p,d,f,g,v,m;u="",i&&(s=e.Line.gradients(t)),c={y:null};for(o=v=0,m=t.length;m>v;o=++v){r=t[o];null!=r.y&&(null!=c.y?i?(a=s[o],l=s[o-1],h=(r.x-c.x)/4,p=c.x+h,f=Math.min(n,c.y+h*l),d=r.x-h,g=Math.min(n,r.y-h*a),u+="C"+p+","+f+","+d+","+g+","+r.x+","+r.y):u+="L"+r.x+","+r.y:i&&null==s[o]||(u+="M"+r.x+","+r.y));c=r}return u},i.gradients=function(t){var e,i,n,r,a,s,o,h;i=function(t,e){return(t.y-e.y)/(t.x-e.x)},h=[];for(n=s=0,o=t.length;o>s;n=++s)e=t[n],null!=e.y?(r=t[n+1]||{y:null},a=t[n-1]||{y:null},null!=a.y&&null!=r.y?h.push(i(a,r)):null!=a.y?h.push(i(a,e)):null!=r.y?h.push(i(e,r)):h.push(null)):h.push(null);return h},i.prototype.hilight=function(t){var e,i,n,r,a;if(null!==this.prevHilight&&this.prevHilight!==t)for(e=i=0,r=this.seriesPoints.length-1;r>=0?r>=i:i>=r;e=r>=0?++i:--i)this.seriesPoints[e][this.prevHilight]&&this.seriesPoints[e][this.prevHilight].animate(this.pointShrink);if(null!==t&&this.prevHilight!==t)for(e=n=0,a=this.seriesPoints.length-1;a>=0?a>=n:n>=a;e=a>=0?++n:--n)this.seriesPoints[e][t]&&this.seriesPoints[e][t].animate(this.pointGrow);return this.prevHilight=t},i.prototype.colorFor=function(t,e,i){return"function"==typeof this.options.lineColors?this.options.lineColors.call(this,t,e,i):"point"===i?this.options.pointFillColors[e%this.options.pointFillColors.length]||this.options.lineColors[e%this.options.lineColors.length]:this.options.lineColors[e%this.options.lineColors.length]},i.prototype.drawXAxisLabel=function(t,e,i){return this.raphael.text(t,e,i).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor)},i.prototype.drawLinePath=function(t,e){return this.raphael.path(t).attr("stroke",e).attr("stroke-width",this.options.lineWidth)},i.prototype.drawLinePoint=function(t,e,i,n,r){return this.raphael.circle(t,e,i).attr("fill",n).attr("stroke-width",this.strokeWidthForSeries(r)).attr("stroke",this.strokeForSeries(r))},i.prototype.strokeWidthForSeries=function(t){return this.options.pointWidths[t%this.options.pointWidths.length]},i.prototype.strokeForSeries=function(t){return this.options.pointStrokeColors[t%this.options.pointStrokeColors.length]},i}(e.Grid),e.labelSeries=function(i,n,r,a,s){var o,h,l,u,c,p,d,f,g,v,m;l=200*(n-i)/r,h=new Date(i),d=e.LABEL_SPECS[a];if(void 0===d){m=e.AUTO_LABEL_ORDER;for(g=0,v=m.length;v>g;g++){u=m[g],p=e.LABEL_SPECS[u];if(l>=p.span){d=p;break}}}void 0===d&&(d=e.LABEL_SPECS.second),s&&(d=t.extend({},d,{fmt:s})),o=d.start(h),c=[];for(;n>=(f=o.getTime());)f>=i&&c.push([d.fmt(o),f]),d.incr(o);return c},i=function(t){return{span:1e3*60*t,start:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours())},fmt:function(t){return""+e.pad2(t.getHours())+":"+e.pad2(t.getMinutes())},incr:function(e){return e.setUTCMinutes(e.getUTCMinutes()+t)}}},n=function(t){return{span:1e3*t,start:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes())},fmt:function(t){return""+e.pad2(t.getHours())+":"+e.pad2(t.getMinutes())+":"+e.pad2(t.getSeconds())},incr:function(e){return e.setUTCSeconds(e.getUTCSeconds()+t)}}},e.LABEL_SPECS={decade:{span:1728e8,start:function(t){return new Date(t.getFullYear()-t.getFullYear()%10,0,1)},fmt:function(t){return""+t.getFullYear()},incr:function(t){return t.setFullYear(t.getFullYear()+10)}},year:{span:1728e7,start:function(t){return new Date(t.getFullYear(),0,1)},fmt:function(t){return""+t.getFullYear()},incr:function(t){return t.setFullYear(t.getFullYear()+1)}},month:{span:24192e5,start:function(t){return new Date(t.getFullYear(),t.getMonth(),1)},fmt:function(t){return""+t.getFullYear()+"-"+e.pad2(t.getMonth()+1)},incr:function(t){return t.setMonth(t.getMonth()+1)}},day:{span:864e5,start:function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate())},fmt:function(t){return""+t.getFullYear()+"-"+e.pad2(t.getMonth()+1)+"-"+e.pad2(t.getDate())},incr:function(t){return t.setDate(t.getDate()+1)}},hour:i(60),"30min":i(30),"15min":i(15),"10min":i(10),"5min":i(5),minute:i(1),"30sec":n(30),"15sec":n(15),"10sec":n(10),"5sec":n(5),second:n(1)},e.AUTO_LABEL_ORDER=["decade","year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"],e.Area=function(i){function n(i){var a;if(!(this instanceof e.Area))return new e.Area(i);a=t.extend({},r,i),this.cumulative=!a.behaveLikeLine,"auto"===a.fillOpacity&&(a.fillOpacity=a.behaveLikeLine?.8:1),n.__super__.constructor.call(this,a);return void 0}var r;return s(n,i),r={fillOpacity:"auto",behaveLikeLine:!1},n.prototype.calcPoints=function(){var t,e,i,n,r,a,s;a=this.data,s=[];for(n=0,r=a.length;r>n;n++)t=a[n],t._x=this.transX(t.x),e=0,t._y=function(){var n,r,a,s;a=t.y,s=[];for(n=0,r=a.length;r>n;n++)i=a[n],this.options.behaveLikeLine?s.push(this.transY(i)):(e+=i||0,s.push(this.transY(e)));return s}.call(this),s.push(t._ymax=Math.max.apply(Math,t._y));return s},n.prototype.drawSeries=function(){var t,e,i,n,r,a,s,o;this.seriesPoints=[],e=this.options.behaveLikeLine?function(){a=[];for(var t=0,e=this.options.ykeys.length-1;e>=0?e>=t:t>=e;e>=0?t++:t--)a.push(t);return a}.apply(this):function(){s=[];for(var t=r=this.options.ykeys.length-1;0>=r?0>=t:t>=0;0>=r?t++:t--)s.push(t);return s}.apply(this),o=[];for(i=0,n=e.length;n>i;i++)t=e[i],this._drawFillFor(t),this._drawLineFor(t),o.push(this._drawPointFor(t));return o},n.prototype._drawFillFor=function(t){var e;e=this.paths[t];return null!==e?(e+="L"+this.transX(this.xmax)+","+this.bottom+"L"+this.transX(this.xmin)+","+this.bottom+"Z",this.drawFilledPath(e,this.fillForSeries(t))):void 0},n.prototype.fillForSeries=function(t){var e;return e=Raphael.rgb2hsl(this.colorFor(this.data[t],t,"line")),Raphael.hsl(e.h,this.options.behaveLikeLine?.9*e.s:.75*e.s,Math.min(.98,this.options.behaveLikeLine?1.2*e.l:1.25*e.l))},n.prototype.drawFilledPath=function(t,e){return this.raphael.path(t).attr("fill",e).attr("fill-opacity",this.options.fillOpacity).attr("stroke-width",0)},n}(e.Line),e.Bar=function(i){function n(i){this.onHoverOut=o(this.onHoverOut,this),this.onHoverMove=o(this.onHoverMove,this),this.onGridClick=o(this.onGridClick,this);if(!(this instanceof e.Bar))return new e.Bar(i);n.__super__.constructor.call(this,t.extend({},i,{parseTime:!1}));return void 0}return s(n,i),n.prototype.init=function(){this.cumulative=this.options.stacked;return"always"!==this.options.hideHover?(this.hover=new e.Hover({parent:this.el}),this.on("hovermove",this.onHoverMove),this.on("hoverout",this.onHoverOut),this.on("gridclick",this.onGridClick)):void 0},n.prototype.defaults={barSizeRatio:.75,barGap:3,barColors:["#0b62a4","#7a92a3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],xLabelMargin:50},n.prototype.calc=function(){var t;this.calcBars();return this.options.hideHover===!1?(t=this.hover).update.apply(t,this.hoverContentForRow(this.data.length-1)):void 0},n.prototype.calcBars=function(){var t,e,i,n,r,a,s;a=this.data,s=[];for(t=n=0,r=a.length;r>n;t=++n)e=a[t],e._x=this.left+this.width*(t+.5)/this.data.length,s.push(e._y=function(){var t,n,r,a;r=e.y,a=[];for(t=0,n=r.length;n>t;t++)i=r[t],null!=i?a.push(this.transY(i)):a.push(null);return a}.call(this));return s},n.prototype.draw=function(){return this.options.axes&&this.drawXAxis(),this.drawSeries()},n.prototype.drawXAxis=function(){var t,e,i,n,r,a,s,o,h,l,u,c,p;l=this.bottom+this.options.padding/2,s=null,a=null,p=[];for(t=u=0,c=this.data.length;c>=0?c>u:u>c;t=c>=0?++u:--u)o=this.data[this.data.length-1-t],e=this.drawXAxisLabel(o._x,l,o.label),h=e.getBBox(),e.transform("r"+-this.options.xLabelAngle),i=e.getBBox(),e.transform("t0,"+i.height/2+"..."),0!==this.options.xLabelAngle&&(r=-.5*h.width*Math.cos(this.options.xLabelAngle*Math.PI/180),e.transform("t"+r+",0...")),(null==s||s>=i.x+i.width||null!=a&&a>=i.x)&&i.x>=0&&i.x+i.width=this.ymin&&this.ymax>=0?this.transY(0):null,this.bars=function(){var o,f,g,v;g=this.data,v=[];for(n=o=0,f=g.length;f>o;n=++o)h=g[n],r=0,v.push(function(){var o,f,g,v;g=h._y,v=[];for(l=o=0,f=g.length;f>o;l=++o)p=g[l],null!==p?(d?(c=Math.min(p,d),e=Math.max(p,d)):(c=p,e=this.bottom),a=this.left+n*i+s,this.options.stacked||(a+=l*(t+this.options.barGap)),u=e-c,this.options.stacked&&(c-=r),this.drawBar(a,c,t,u,this.colorFor(h,l,"bar")),v.push(r+=u)):v.push(null);return v}.call(this));return v}.call(this)},n.prototype.colorFor=function(t,e,i){var n,r;return"function"==typeof this.options.barColors?(n={x:t.x,y:t.y[e],label:t.label},r={index:e,key:this.options.ykeys[e],label:this.options.labels[e]},this.options.barColors.call(this,n,r,i)):this.options.barColors[e%this.options.barColors.length]},n.prototype.hitTest=function(t){return 0===this.data.length?null:(t=Math.max(Math.min(t,this.right),this.left),Math.min(this.data.length-1,Math.floor((t-this.left)/(this.width/this.data.length))))},n.prototype.onGridClick=function(t,e){var i;return i=this.hitTest(t,e),this.fire("click",i,this.options.data[i],t,e)},n.prototype.onHoverMove=function(t,e){var i,n;return i=this.hitTest(t,e),(n=this.hover).update.apply(n,this.hoverContentForRow(i))},n.prototype.onHoverOut=function(){return this.options.hideHover!==!1?this.hover.hide():void 0},n.prototype.hoverContentForRow=function(t){var e,i,n,r,a,s,o,h;n=this.data[t],e="
"+n.label+"
",h=n.y;for(i=s=0,o=h.length;o>s;i=++s)a=h[i],e+="
\n "+this.options.labels[i]+":\n "+this.yLabelFormat(a)+"\n
";return"function"==typeof this.options.hoverCallback&&(e=this.options.hoverCallback(t,this.options,e)),r=this.left+(t+.5)*this.width/this.data.length,[e,r]},n.prototype.drawXAxisLabel=function(t,e,i){var n;return n=this.raphael.text(t,e,i).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor)},n.prototype.drawBar=function(t,e,i,n,r){return this.raphael.rect(t,e,i,n).attr("fill",r).attr("stroke-width",0)},n}(e.Grid),e.Donut=function(i){function n(i){this.select=o(this.select,this),this.click=o(this.click,this);var n;if(!(this instanceof e.Donut))return new e.Donut(i);this.el="string"==typeof i.element?t(document.getElementById(i.element)):t(i.element),this.options=t.extend({},this.defaults,i);if(null===this.el||0===this.el.length)throw Error("Graph placeholder not found.");void 0!==i.data&&0!==i.data.length&&(this.data=i.data,this.values=function(){var t,e,i,r;i=this.data,r=[];for(t=0,e=i.length;e>t;t++)n=i[t],r.push(parseFloat(n.value));return r}.call(this),this.redraw())}return s(n,i),n.prototype.defaults={colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],backgroundColor:"#FFFFFF",labelColor:"#000000",formatter:e.commas},n.prototype.redraw=function(){var t,i,n,r,a,s,o,h,l,u,c,p,d,f,g,v,m,y,x,_,b,w,C;this.el.empty(),this.raphael=new Raphael(this.el[0]),i=this.el.width()/2,n=this.el.height()/2,d=(Math.min(i,n)-10)/3,c=0,_=this.values;for(f=0,m=_.length;m>f;f++)p=_[f],c+=p;h=5/(2*d),t=1.9999*Math.PI-h*this.data.length,s=0,a=0,this.segments=[],b=this.values;for(r=g=0,y=b.length;y>g;r=++g)p=b[r],l=s+h+t*(p/c),u=new e.DonutSegment(i,n,2*d,d,s,l,this.options.colors[a%this.options.colors.length],this.options.backgroundColor,a,this.raphael),u.render(),this.segments.push(u),u.on("hover",this.select),u.on("click",this.click),s=l,a+=1;this.text1=this.drawEmptyDonutLabel(i,n-10,this.options.labelColor,15,800),this.text2=this.drawEmptyDonutLabel(i,n+10,this.options.labelColor,14),o=Math.max.apply(null,function(){var t,e,i,n;i=this.values,n=[];for(t=0,e=i.length;e>t;t++)p=i[t],n.push(p);return n}.call(this)),a=0,w=this.values,C=[];for(v=0,x=w.length;x>v;v++){p=w[v];if(p===o){this.select(a);break}C.push(a+=1)}return C},n.prototype.click=function(t){return this.fire("click",t,this.data[t])},n.prototype.select=function(t){var e,i,n,r,a,s;s=this.segments;for(r=0,a=s.length;a>r;r++)i=s[r],i.deselect();return n=this.segments[t],n.select(),e=this.data[t],this.setLabels(e.label,this.options.formatter(e.value,e))},n.prototype.setLabels=function(t,e){var i,n,r,a,s,o,h,l;return i=2*(Math.min(this.el.width()/2,this.el.height()/2)-10)/3,a=1.8*i,r=i/2,n=i/3,this.text1.attr({text:t,transform:""}),s=this.text1.getBBox(),o=Math.min(a/s.width,r/s.height),this.text1.attr({transform:"S"+o+","+o+","+(s.x+s.width/2)+","+(s.y+s.height)}),this.text2.attr({text:e,transform:""}),h=this.text2.getBBox(),l=Math.min(a/h.width,n/h.height),this.text2.attr({transform:"S"+l+","+l+","+(h.x+h.width/2)+","+h.y})},n.prototype.drawEmptyDonutLabel=function(t,e,i,n,r){var a;return a=this.raphael.text(t,e,"").attr("font-size",n).attr("fill",i),null!=r&&a.attr("font-weight",r),a},n}(e.EventEmitter),e.DonutSegment=function(t){function e(t,e,i,n,r,a,s,h,l,u){this.cx=t,this.cy=e,this.inner=i,this.outer=n,this.color=s,this.backgroundColor=h,this.index=l,this.raphael=u,this.deselect=o(this.deselect,this),this.select=o(this.select,this),this.sin_p0=Math.sin(r),this.cos_p0=Math.cos(r),this.sin_p1=Math.sin(a),this.cos_p1=Math.cos(a),this.is_long=a-r>Math.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return s(e,t),e.prototype.calcArcPoints=function(t){return[this.cx+t*this.sin_p0,this.cy+t*this.cos_p0,this.cx+t*this.sin_p1,this.cy+t*this.cos_p1]},e.prototype.calcSegment=function(t,e){var i,n,r,a,s,o,h,l,u,c;return u=this.calcArcPoints(t),i=u[0],r=u[1],n=u[2],a=u[3],c=this.calcArcPoints(e),s=c[0],h=c[1],o=c[2],l=c[3],"M"+i+","+r+("A"+t+","+t+",0,"+this.is_long+",0,"+n+","+a)+("L"+o+","+l)+("A"+e+","+e+",0,"+this.is_long+",1,"+s+","+h)+"Z"},e.prototype.calcArc=function(t){var e,i,n,r,a;return a=this.calcArcPoints(t),e=a[0],n=a[1],i=a[2],r=a[3],"M"+e+","+n+("A"+t+","+t+",0,"+this.is_long+",0,"+i+","+r)},e.prototype.render=function(){var t=this;return this.arc=this.drawDonutArc(this.hilight,this.color),this.seg=this.drawDonutSegment(this.path,this.color,this.backgroundColor,function(){return t.fire("hover",t.index)},function(){return t.fire("click",t.index)})},e.prototype.drawDonutArc=function(t,e){return this.raphael.path(t).attr({stroke:e,"stroke-width":2,opacity:0})},e.prototype.drawDonutSegment=function(t,e,i,n,r){return this.raphael.path(t).attr({fill:e,stroke:i,"stroke-width":3}).hover(n).click(r)},e.prototype.select=function(){return this.selected?void 0:(this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0)},e.prototype.deselect=function(){return this.selected?(this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1):void 0},e}(e.EventEmitter)}).call(this);(function(){var t=document.createElement("canvas");if(t.getContext&&t.getContext("2d")){this.createjs=this.createjs||{};(function(){var t=function(){throw"UID cannot be instantiated"};t._nextID=0;t.get=function(){return t._nextID++};createjs.UID=t})();this.createjs=this.createjs||{};(function(){var t=function(){this.initialize()},e=t.prototype;t.initialize=function(t){t.addEventListener=e.addEventListener;t.removeEventListener=e.removeEventListener;t.removeAllEventListeners=e.removeAllEventListeners;t.hasEventListener=e.hasEventListener;t.dispatchEvent=e.dispatchEvent};e._listeners=null;e.initialize=function(){};e.addEventListener=function(t,e){var i=this._listeners;i?this.removeEventListener(t,e):i=this._listeners={};var n=i[t];n||(n=i[t]=[]);n.push(e);return e};e.removeEventListener=function(t,e){var i=this._listeners;if(i){var n=i[t];if(n)for(var r=0,a=n.length;a>r;r++)if(n[r]==e){1==a?delete i[t]:n.splice(r,1);break}}};e.removeAllEventListeners=function(t){t?this._listeners&&delete this._listeners[t]:this._listeners=null};e.dispatchEvent=function(t,e){var i=!1,n=this._listeners;if(t&&n){"string"==typeof t&&(t={type:t});n=n[t.type];if(!n)return i;t.target=e||this;for(var n=n.slice(),r=0,a=n.length;a>r;r++)var s=n[r],i=s.handleEvent?i||s.handleEvent(t):i||s(t)}return!!i};e.hasEventListener=function(t){var e=this._listeners;return!(!e||!e[t])};e.toString=function(){return"[EventDispatcher]"};createjs.EventDispatcher=t})();this.createjs=this.createjs||{};(function(){var t=function(){throw"Ticker cannot be instantiated."};t.useRAF=!1;t.addEventListener=null;t.removeEventListener=null;t.removeAllEventListeners=null;t.dispatchEvent=null;t.hasEventListener=null;t._listeners=null;createjs.EventDispatcher.initialize(t);t._listeners=null;t._pauseable=null;t._paused=!1;t._inited=!1;t._startTime=0;t._pausedTime=0;t._ticks=0;t._pausedTicks=0;t._interval=50;t._lastTime=0;t._times=null;t._tickTimes=null;t._rafActive=!1;t._timeoutID=null;t.addListener=function(e,i){null!=e&&(t.removeListener(e),t._pauseable[t._listeners.length]=null==i?!0:i,t._listeners.push(e))};t.init=function(){t._inited=!0;t._times=[];t._tickTimes=[];t._pauseable=[];t._listeners=[];t._times.push(t._lastTime=t._startTime=t._getTime());t.setInterval(t._interval)};t.removeListener=function(e){var i=t._listeners;i&&(e=i.indexOf(e),-1!=e&&(i.splice(e,1),t._pauseable.splice(e,1)))};t.removeAllListeners=function(){t._listeners=[];t._pauseable=[]};t.setInterval=function(e){t._interval=e;t._inited&&t._setupTick()};t.getInterval=function(){return t._interval};t.setFPS=function(e){t.setInterval(1e3/e)};t.getFPS=function(){return 1e3/t._interval};t.getMeasuredFPS=function(e){if(2>t._times.length)return-1;null==e&&(e=0|t.getFPS());e=Math.min(t._times.length-1,e);return 1e3/((t._times[0]-t._times[e])/e)};t.setPaused=function(e){t._paused=e};t.getPaused=function(){return t._paused};t.getTime=function(e){return t._getTime()-t._startTime-(e?t._pausedTime:0)};t.getTicks=function(e){return t._ticks-(e?t._pausedTicks:0)};t._handleAF=function(){t._rafActive=!1;t._setupTick();t._getTime()-t._lastTime>=.97*(t._interval-1)&&t._tick()};t._handleTimeout=function(){t.timeoutID=null;t._setupTick();t._tick()};t._setupTick=function(){if(!t._rafActive&&null==t.timeoutID){if(t.useRAF){var e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(e){e(t._handleAF);t._rafActive=!0;return}}t.timeoutID=setTimeout(t._handleTimeout,t._interval)}};t._tick=function(){var e=t._getTime();t._ticks++;var i=e-t._lastTime,n=t._paused;n&&(t._pausedTicks++,t._pausedTime+=i);t._lastTime=e;for(var r=t._pauseable,a=t._listeners.slice(),s=a?a.length:0,o=0;s>o;o++){var h=a[o];null==h||n&&r[o]||(h.tick?h.tick(i,n):h instanceof Function&&h(i,n))}t.dispatchEvent({type:"tick",paused:n,delta:i,time:e,runTime:e-t._pausedTime});for(t._tickTimes.unshift(t._getTime()-e);t._tickTimes.length>100;)t._tickTimes.pop();for(t._times.unshift(e);t._times.length>100;)t._times.pop()};var e=window.performance&&(performance.now||performance.mozNow||performance.msNow||performance.oNow||performance.webkitNow);t._getTime=function(){return e&&e.call(performance)||(new Date).getTime()};t.init();createjs.Ticker=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i,n,r,a,s,o,h){this.initialize(t,e,i,n,r,a,s,o,h)},e=t.prototype;e.stageX=0;e.stageY=0;e.rawX=0;e.rawY=0;e.type=null;e.nativeEvent=null;e.onMouseMove=null;e.onMouseUp=null;e.target=null;e.pointerID=0;e.primary=!1;e.addEventListener=null;e.removeEventListener=null;e.removeAllEventListeners=null;e.dispatchEvent=null;e.hasEventListener=null;e._listeners=null;createjs.EventDispatcher.initialize(e);e.initialize=function(t,e,i,n,r,a,s,o,h){this.type=t;this.stageX=e;this.stageY=i;this.target=n;this.nativeEvent=r;this.pointerID=a;this.primary=s;this.rawX=null==o?e:o;this.rawY=null==h?i:h};e.clone=function(){return new t(this.type,this.stageX,this.stageY,this.target,this.nativeEvent,this.pointerID,this.primary,this.rawX,this.rawY)};e.toString=function(){return"[MouseEvent (type="+this.type+" stageX="+this.stageX+" stageY="+this.stageY+")]"};createjs.MouseEvent=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i,n,r,a){this.initialize(t,e,i,n,r,a)},e=t.prototype;t.identity=null;t.DEG_TO_RAD=Math.PI/180;e.a=1;e.b=0;e.c=0;e.d=1;e.tx=0;e.ty=0;e.alpha=1;e.shadow=null;e.compositeOperation=null;e.initialize=function(t,e,i,n,r,a){null!=t&&(this.a=t);this.b=e||0;this.c=i||0;null!=n&&(this.d=n);this.tx=r||0;this.ty=a||0;return this};e.prepend=function(t,e,i,n,r,a){var s=this.tx;if(1!=t||0!=e||0!=i||1!=n){var o=this.a,h=this.c;this.a=o*t+this.b*i;this.b=o*e+this.b*n;this.c=h*t+this.d*i;this.d=h*e+this.d*n}this.tx=s*t+this.ty*i+r;this.ty=s*e+this.ty*n+a;return this};e.append=function(t,e,i,n,r,a){var s=this.a,o=this.b,h=this.c,l=this.d;this.a=t*s+e*h;this.b=t*o+e*l;this.c=i*s+n*h;this.d=i*o+n*l;this.tx=r*s+a*h+this.tx;this.ty=r*o+a*l+this.ty;return this};e.prependMatrix=function(t){this.prepend(t.a,t.b,t.c,t.d,t.tx,t.ty);this.prependProperties(t.alpha,t.shadow,t.compositeOperation);return this -};e.appendMatrix=function(t){this.append(t.a,t.b,t.c,t.d,t.tx,t.ty);this.appendProperties(t.alpha,t.shadow,t.compositeOperation);return this};e.prependTransform=function(e,i,n,r,a,s,o,h,l){if(a%360){var u=a*t.DEG_TO_RAD;a=Math.cos(u);u=Math.sin(u)}else a=1,u=0;(h||l)&&(this.tx-=h,this.ty-=l);s||o?(s*=t.DEG_TO_RAD,o*=t.DEG_TO_RAD,this.prepend(a*n,u*n,-u*r,a*r,0,0),this.prepend(Math.cos(o),Math.sin(o),-Math.sin(s),Math.cos(s),e,i)):this.prepend(a*n,u*n,-u*r,a*r,e,i);return this};e.appendTransform=function(e,i,n,r,a,s,o,h,l){if(a%360){var u=a*t.DEG_TO_RAD;a=Math.cos(u);u=Math.sin(u)}else a=1,u=0;s||o?(s*=t.DEG_TO_RAD,o*=t.DEG_TO_RAD,this.append(Math.cos(o),Math.sin(o),-Math.sin(s),Math.cos(s),e,i),this.append(a*n,u*n,-u*r,a*r,0,0)):this.append(a*n,u*n,-u*r,a*r,e,i);(h||l)&&(this.tx-=h*this.a+l*this.c,this.ty-=h*this.b+l*this.d);return this};e.rotate=function(t){var e=Math.cos(t);t=Math.sin(t);var i=this.a,n=this.c,r=this.tx;this.a=i*e-this.b*t;this.b=i*t+this.b*e;this.c=n*e-this.d*t;this.d=n*t+this.d*e;this.tx=r*e-this.ty*t;this.ty=r*t+this.ty*e;return this};e.skew=function(e,i){e*=t.DEG_TO_RAD;i*=t.DEG_TO_RAD;this.append(Math.cos(i),Math.sin(i),-Math.sin(e),Math.cos(e),0,0);return this};e.scale=function(t,e){this.a*=t;this.d*=e;this.c*=t;this.b*=e;return this};e.translate=function(t,e){this.tx+=t;this.ty+=e;return this};e.identity=function(){this.alpha=this.a=this.d=1;this.b=this.c=this.tx=this.ty=0;this.shadow=this.compositeOperation=null;return this};e.invert=function(){var t=this.a,e=this.b,i=this.c,n=this.d,r=this.tx,a=t*n-e*i;this.a=n/a;this.b=-e/a;this.c=-i/a;this.d=t/a;this.tx=(i*this.ty-n*r)/a;this.ty=-(t*this.ty-e*r)/a;return this};e.isIdentity=function(){return 0==this.tx&&0==this.ty&&1==this.a&&0==this.b&&0==this.c&&1==this.d};e.decompose=function(e){null==e&&(e={});e.x=this.tx;e.y=this.ty;e.scaleX=Math.sqrt(this.a*this.a+this.b*this.b);e.scaleY=Math.sqrt(this.c*this.c+this.d*this.d);var i=Math.atan2(-this.c,this.d),n=Math.atan2(this.b,this.a);i==n?(e.rotation=n/t.DEG_TO_RAD,0>this.a&&this.d>=0&&(e.rotation+=0>=e.rotation?180:-180),e.skewX=e.skewY=0):(e.skewX=i/t.DEG_TO_RAD,e.skewY=n/t.DEG_TO_RAD);return e};e.reinitialize=function(t,e,i,n,r,a,s,o,h){this.initialize(t,e,i,n,r,a);this.alpha=s||1;this.shadow=o;this.compositeOperation=h;return this};e.appendProperties=function(t,e,i){this.alpha*=t;this.shadow=e||this.shadow;this.compositeOperation=i||this.compositeOperation;return this};e.prependProperties=function(t,e,i){this.alpha*=t;this.shadow=this.shadow||e;this.compositeOperation=this.compositeOperation||i;return this};e.clone=function(){var e=new t(this.a,this.b,this.c,this.d,this.tx,this.ty);e.shadow=this.shadow;e.alpha=this.alpha;e.compositeOperation=this.compositeOperation;return e};e.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};t.identity=new t(1,0,0,1,0,0);createjs.Matrix2D=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e){this.initialize(t,e)},e=t.prototype;e.x=0;e.y=0;e.initialize=function(t,e){this.x=null==t?0:t;this.y=null==e?0:e};e.clone=function(){return new t(this.x,this.y)};e.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};createjs.Point=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i,n){this.initialize(t,e,i,n)},e=t.prototype;e.x=0;e.y=0;e.width=0;e.height=0;e.initialize=function(t,e,i,n){this.x=null==t?0:t;this.y=null==e?0:e;this.width=null==i?0:i;this.height=null==n?0:n};e.clone=function(){return new t(this.x,this.y,this.width,this.height)};e.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};createjs.Rectangle=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i,n,r,a,s){this.initialize(t,e,i,n,r,a,s)},e=t.prototype;e.target=null;e.overLabel=null;e.outLabel=null;e.downLabel=null;e.play=!1;e._isPressed=!1;e._isOver=!1;e.initialize=function(t,e,i,n,r,a,s){t.addEventListener&&(this.target=t,t.cursor="pointer",this.overLabel=null==i?"over":i,this.outLabel=null==e?"out":e,this.downLabel=null==n?"down":n,this.play=r,this.setEnabled(!0),this.handleEvent({}),a&&(s&&(a.actionsEnabled=!1,a.gotoAndStop&&a.gotoAndStop(s)),t.hitArea=a))};e.setEnabled=function(t){var e=this.target;t?(e.addEventListener("mouseover",this),e.addEventListener("mouseout",this),e.addEventListener("mousedown",this)):(e.removeEventListener("mouseover",this),e.removeEventListener("mouseout",this),e.removeEventListener("mousedown",this))};e.toString=function(){return"[ButtonHelper]"};e.handleEvent=function(t){var e=this.target,i=t.type;"mousedown"==i?(t.addEventListener("mouseup",this),this._isPressed=!0,t=this.downLabel):"mouseup"==i?(this._isPressed=!1,t=this._isOver?this.overLabel:this.outLabel):"mouseover"==i?(this._isOver=!0,t=this._isPressed?this.downLabel:this.overLabel):(this._isOver=!1,t=this._isPressed?this.overLabel:this.outLabel);this.play?e.gotoAndPlay&&e.gotoAndPlay(t):e.gotoAndStop&&e.gotoAndStop(t)};createjs.ButtonHelper=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i,n){this.initialize(t,e,i,n)},e=t.prototype;t.identity=null;e.color=null;e.offsetX=0;e.offsetY=0;e.blur=0;e.initialize=function(t,e,i,n){this.color=t;this.offsetX=e;this.offsetY=i;this.blur=n};e.toString=function(){return"[Shadow]"};e.clone=function(){return new t(this.color,this.offsetX,this.offsetY,this.blur)};t.identity=new t("transparent",0,0,0);createjs.Shadow=t})();this.createjs=this.createjs||{};(function(){var t=function(t){this.initialize(t)},e=t.prototype;e.complete=!0;e.onComplete=null;e.addEventListener=null;e.removeEventListener=null;e.removeAllEventListeners=null;e.dispatchEvent=null;e.hasEventListener=null;e._listeners=null;createjs.EventDispatcher.initialize(e);e._animations=null;e._frames=null;e._images=null;e._data=null;e._loadCount=0;e._frameHeight=0;e._frameWidth=0;e._numFrames=0;e._regX=0;e._regY=0;e.initialize=function(t){var e,i,n;if(null!=t){if(t.images&&(i=t.images.length)>0){n=this._images=[];for(e=0;i>e;e++){var r=t.images[e];if("string"==typeof r){var a=r,r=new Image;r.src=a}n.push(r);!r.getContext&&!r.complete&&(this._loadCount++,this.complete=!1,function(t){r.onload=function(){t._handleImageLoad()}}(this))}}if(null!=t.frames)if(t.frames instanceof Array){this._frames=[];n=t.frames;e=0;for(i=n.length;i>e;e++)a=n[e],this._frames.push({image:this._images[a[4]?a[4]:0],rect:new createjs.Rectangle(a[0],a[1],a[2],a[3]),regX:a[5]||0,regY:a[6]||0})}else i=t.frames,this._frameWidth=i.width,this._frameHeight=i.height,this._regX=i.regX||0,this._regY=i.regY||0,this._numFrames=i.count,0==this._loadCount&&this._calculateFrames();if(null!=(i=t.animations)){this._animations=[];this._data={};for(var s in i){t={name:s};a=i[s];if("number"==typeof a)n=t.frames=[a];else if(a instanceof Array)if(1==a.length)t.frames=[a[0]];else{t.frequency=a[3];t.next=a[2];n=t.frames=[];for(e=a[0];a[1]>=e;e++)n.push(e)}else t.frequency=a.frequency,t.next=a.next,e=a.frames,n=t.frames="number"==typeof e?[e]:e.slice(0);t.next=2>n.length||!1==t.next?null:null==t.next||!0==t.next?s:t.next;t.frequency||(t.frequency=1);this._animations.push(s);this._data[s]=t}}}};e.getNumFrames=function(t){if(null==t)return this._frames?this._frames.length:this._numFrames;t=this._data[t];return null==t?0:t.frames.length};e.getAnimations=function(){return this._animations.slice(0)};e.getAnimation=function(t){return this._data[t]};e.getFrame=function(t){var e;return this.complete&&this._frames&&(e=this._frames[t])?e:null};e.getFrameBounds=function(t){return(t=this.getFrame(t))?new createjs.Rectangle(-t.regX,-t.regY,t.rect.width,t.rect.height):null};e.toString=function(){return"[SpriteSheet]"};e.clone=function(){var e=new t;e.complete=this.complete;e._animations=this._animations;e._frames=this._frames;e._images=this._images;e._data=this._data;e._frameHeight=this._frameHeight;e._frameWidth=this._frameWidth;e._numFrames=this._numFrames;e._loadCount=this._loadCount;return e};e._handleImageLoad=function(){0==--this._loadCount&&(this._calculateFrames(),this.complete=!0,this.onComplete&&this.onComplete(),this.dispatchEvent("complete"))};e._calculateFrames=function(){if(!this._frames&&0!=this._frameWidth){this._frames=[];for(var t=0,e=this._frameWidth,i=this._frameHeight,n=0,r=this._images;r.length>n;n++){for(var a=r[n],s=0|(a.width+1)/e,o=0|(a.height+1)/i,o=this._numFrames>0?Math.min(this._numFrames-t,s*o):s*o,h=0;o>h;h++)this._frames.push({image:a,rect:new createjs.Rectangle(h%s*e,(0|h/s)*i,e,i),regX:this._regX,regY:this._regY});t+=o}this._numFrames=t}};createjs.SpriteSheet=t})();this.createjs=this.createjs||{};(function(){function t(t,e,i){this.f=t;this.params=e;this.path=null==i?!0:i}t.prototype.exec=function(t){this.f.apply(t,this.params)};var e=function(){this.initialize()},i=e.prototype;e.getRGB=function(t,e,i,n){null!=t&&null==i&&(n=e,i=255&t,e=255&t>>8,t=255&t>>16);return null==n?"rgb("+t+","+e+","+i+")":"rgba("+t+","+e+","+i+","+n+")"};e.getHSL=function(t,e,i,n){return null==n?"hsl("+t%360+","+e+"%,"+i+"%)":"hsla("+t%360+","+e+"%,"+i+"%,"+n+")"};e.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,0:52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63};e.STROKE_CAPS_MAP=["butt","round","square"];e.STROKE_JOINTS_MAP=["miter","round","bevel"];e._ctx=(createjs.createCanvas?createjs.createCanvas():document.createElement("canvas")).getContext("2d");e.beginCmd=new t(e._ctx.beginPath,[],!1);e.fillCmd=new t(e._ctx.fill,[],!1);e.strokeCmd=new t(e._ctx.stroke,[],!1);i._strokeInstructions=null;i._strokeStyleInstructions=null;i._ignoreScaleStroke=!1;i._fillInstructions=null;i._instructions=null;i._oldInstructions=null;i._activeInstructions=null;i._active=!1;i._dirty=!1;i.initialize=function(){this.clear();this._ctx=e._ctx};i.isEmpty=function(){return!(this._instructions.length||this._oldInstructions.length||this._activeInstructions.length)};i.draw=function(t){this._dirty&&this._updateInstructions();for(var e=this._instructions,i=0,n=e.length;n>i;i++)e[i].exec(t)};i.drawAsPath=function(t){this._dirty&&this._updateInstructions();for(var e,i=this._instructions,n=0,r=i.length;r>n;n++)((e=i[n]).path||0==n)&&e.exec(t)};i.moveTo=function(e,i){this._activeInstructions.push(new t(this._ctx.moveTo,[e,i]));return this};i.lineTo=function(e,i){this._dirty=this._active=!0;this._activeInstructions.push(new t(this._ctx.lineTo,[e,i]));return this};i.arcTo=function(e,i,n,r,a){this._dirty=this._active=!0;this._activeInstructions.push(new t(this._ctx.arcTo,[e,i,n,r,a]));return this};i.arc=function(e,i,n,r,a,s){this._dirty=this._active=!0;null==s&&(s=!1);this._activeInstructions.push(new t(this._ctx.arc,[e,i,n,r,a,s]));return this};i.quadraticCurveTo=function(e,i,n,r){this._dirty=this._active=!0;this._activeInstructions.push(new t(this._ctx.quadraticCurveTo,[e,i,n,r]));return this};i.bezierCurveTo=function(e,i,n,r,a,s){this._dirty=this._active=!0;this._activeInstructions.push(new t(this._ctx.bezierCurveTo,[e,i,n,r,a,s]));return this};i.rect=function(e,i,n,r){this._dirty=this._active=!0;this._activeInstructions.push(new t(this._ctx.rect,[e,i,n,r]));return this};i.closePath=function(){this._active&&(this._dirty=!0,this._activeInstructions.push(new t(this._ctx.closePath,[])));return this};i.clear=function(){this._instructions=[];this._oldInstructions=[];this._activeInstructions=[];this._strokeStyleInstructions=this._strokeInstructions=this._fillInstructions=null;this._active=this._dirty=!1;return this};i.beginFill=function(i){this._active&&this._newPath();this._fillInstructions=i?[new t(this._setProp,["fillStyle",i],!1),e.fillCmd]:null;return this};i.beginLinearGradientFill=function(i,n,r,a,s,o){this._active&&this._newPath();r=this._ctx.createLinearGradient(r,a,s,o);a=0;for(s=i.length;s>a;a++)r.addColorStop(n[a],i[a]);this._fillInstructions=[new t(this._setProp,["fillStyle",r],!1),e.fillCmd];return this};i.beginRadialGradientFill=function(i,n,r,a,s,o,h,l){this._active&&this._newPath();r=this._ctx.createRadialGradient(r,a,s,o,h,l);a=0;for(s=i.length;s>a;a++)r.addColorStop(n[a],i[a]);this._fillInstructions=[new t(this._setProp,["fillStyle",r],!1),e.fillCmd];return this};i.beginBitmapFill=function(i,n,r){this._active&&this._newPath();i=this._ctx.createPattern(i,n||"");i=new t(this._setProp,["fillStyle",i],!1);this._fillInstructions=r?[i,new t(this._ctx.save,[],!1),new t(this._ctx.transform,[r.a,r.b,r.c,r.d,r.tx,r.ty],!1),e.fillCmd,new t(this._ctx.restore,[],!1)]:[i,e.fillCmd];return this};i.endFill=function(){return this.beginFill()};i.setStrokeStyle=function(i,n,r,a,s){this._active&&this._newPath();this._strokeStyleInstructions=[new t(this._setProp,["lineWidth",null==i?"1":i],!1),new t(this._setProp,["lineCap",null==n?"butt":isNaN(n)?n:e.STROKE_CAPS_MAP[n]],!1),new t(this._setProp,["lineJoin",null==r?"miter":isNaN(r)?r:e.STROKE_JOINTS_MAP[r]],!1),new t(this._setProp,["miterLimit",null==a?"10":a],!1)];this._ignoreScaleStroke=s;return this};i.beginStroke=function(e){this._active&&this._newPath();this._strokeInstructions=e?[new t(this._setProp,["strokeStyle",e],!1)]:null;return this};i.beginLinearGradientStroke=function(e,i,n,r,a,s){this._active&&this._newPath();n=this._ctx.createLinearGradient(n,r,a,s);r=0;for(a=e.length;a>r;r++)n.addColorStop(i[r],e[r]);this._strokeInstructions=[new t(this._setProp,["strokeStyle",n],!1)];return this};i.beginRadialGradientStroke=function(e,i,n,r,a,s,o,h){this._active&&this._newPath();n=this._ctx.createRadialGradient(n,r,a,s,o,h);r=0;for(a=e.length;a>r;r++)n.addColorStop(i[r],e[r]);this._strokeInstructions=[new t(this._setProp,["strokeStyle",n],!1)];return this};i.beginBitmapStroke=function(e,i){this._active&&this._newPath();var n=this._ctx.createPattern(e,i||"");this._strokeInstructions=[new t(this._setProp,["strokeStyle",n],!1)];return this};i.endStroke=function(){this.beginStroke();return this};i.curveTo=i.quadraticCurveTo;i.drawRect=i.rect;i.drawRoundRect=function(t,e,i,n,r){this.drawRoundRectComplex(t,e,i,n,r,r,r,r);return this};i.drawRoundRectComplex=function(e,i,n,r,a,s,o,h){var l=(r>n?n:r)/2,u=0,c=0,p=0,d=0;0>a&&(a*=u=-1);a>l&&(a=l);0>s&&(s*=c=-1);s>l&&(s=l);0>o&&(o*=p=-1);o>l&&(o=l);0>h&&(h*=d=-1);h>l&&(h=l);this._dirty=this._active=!0;var l=this._ctx.arcTo,f=this._ctx.lineTo;this._activeInstructions.push(new t(this._ctx.moveTo,[e+n-s,i]),new t(l,[e+n+s*c,i-s*c,e+n,i+s,s]),new t(f,[e+n,i+r-o]),new t(l,[e+n+o*p,i+r+o*p,e+n-o,i+r,o]),new t(f,[e+h,i+r]),new t(l,[e-h*d,i+r+h*d,e,i+r-h,h]),new t(f,[e,i+a]),new t(l,[e-a*u,i-a*u,e+a,i,a]),new t(this._ctx.closePath));return this};i.drawCircle=function(t,e,i){this.arc(t,e,i,0,2*Math.PI);return this};i.drawEllipse=function(e,i,n,r){this._dirty=this._active=!0;var a=.5522848*(n/2),s=.5522848*(r/2),o=e+n,h=i+r;n=e+n/2;r=i+r/2;this._activeInstructions.push(new t(this._ctx.moveTo,[e,r]),new t(this._ctx.bezierCurveTo,[e,r-s,n-a,i,n,i]),new t(this._ctx.bezierCurveTo,[n+a,i,o,r-s,o,r]),new t(this._ctx.bezierCurveTo,[o,r+s,n+a,h,n,h]),new t(this._ctx.bezierCurveTo,[n-a,h,e,r+s,e,r]));return this};i.drawPolyStar=function(e,i,n,r,a,s){this._dirty=this._active=!0;null==a&&(a=0);a=1-a;s=null==s?0:s/(180/Math.PI);var o=Math.PI/r;this._activeInstructions.push(new t(this._ctx.moveTo,[e+Math.cos(s)*n,i+Math.sin(s)*n]));for(var h=0;r>h;h++)s+=o,1!=a&&this._activeInstructions.push(new t(this._ctx.lineTo,[e+Math.cos(s)*n*a,i+Math.sin(s)*n*a])),s+=o,this._activeInstructions.push(new t(this._ctx.lineTo,[e+Math.cos(s)*n,i+Math.sin(s)*n]));return this};i.decodePath=function(t){for(var i=[this.moveTo,this.lineTo,this.quadraticCurveTo,this.bezierCurveTo,this.closePath],n=[2,2,4,6,0],r=0,a=t.length,s=[],o=0,h=0,l=e.BASE_64;a>r;){var u=t.charAt(r),c=l[u],p=c>>3,d=i[p];if(!d||3&c)throw"bad path data (@"+r+"): "+u;u=n[p];p||(o=h=0);s.length=0;r++;c=(1&c>>2)+2;for(p=0;u>p;p++){var f=l[t.charAt(r)],g=f>>5?-1:1,f=(31&f)<<6|l[t.charAt(r+1)];3==c&&(f=f<<6|l[t.charAt(r+2)]);f=g*f/10;p%2?o=f+=o:h=f+=h;s[p]=f;r+=c}d.apply(this,s)}return this};i.clone=function(){var t=new e;t._instructions=this._instructions.slice();t._activeInstructions=this._activeInstructions.slice();t._oldInstructions=this._oldInstructions.slice();this._fillInstructions&&(t._fillInstructions=this._fillInstructions.slice());this._strokeInstructions&&(t._strokeInstructions=this._strokeInstructions.slice());this._strokeStyleInstructions&&(t._strokeStyleInstructions=this._strokeStyleInstructions.slice());t._active=this._active;t._dirty=this._dirty;return t};i.toString=function(){return"[Graphics]"};i.mt=i.moveTo;i.lt=i.lineTo;i.at=i.arcTo;i.bt=i.bezierCurveTo;i.qt=i.quadraticCurveTo;i.a=i.arc;i.r=i.rect;i.cp=i.closePath;i.c=i.clear;i.f=i.beginFill;i.lf=i.beginLinearGradientFill;i.rf=i.beginRadialGradientFill;i.bf=i.beginBitmapFill;i.ef=i.endFill;i.ss=i.setStrokeStyle;i.s=i.beginStroke;i.ls=i.beginLinearGradientStroke;i.rs=i.beginRadialGradientStroke;i.bs=i.beginBitmapStroke;i.es=i.endStroke;i.dr=i.drawRect;i.rr=i.drawRoundRect;i.rc=i.drawRoundRectComplex;i.dc=i.drawCircle;i.de=i.drawEllipse;i.dp=i.drawPolyStar;i.p=i.decodePath;i._updateInstructions=function(){this._instructions=this._oldInstructions.slice();this._instructions.push(e.beginCmd);this._instructions.push.apply(this._instructions,this._activeInstructions);this._fillInstructions&&this._instructions.push.apply(this._instructions,this._fillInstructions);this._strokeInstructions&&(this._strokeStyleInstructions&&this._instructions.push.apply(this._instructions,this._strokeStyleInstructions),this._instructions.push.apply(this._instructions,this._strokeInstructions),this._ignoreScaleStroke?this._instructions.push(new t(this._ctx.save,[],!1),new t(this._ctx.setTransform,[1,0,0,1,0,0],!1),e.strokeCmd,new t(this._ctx.restore,[],!1)):this._instructions.push(e.strokeCmd))};i._newPath=function(){this._dirty&&this._updateInstructions();this._oldInstructions=this._instructions;this._activeInstructions=[];this._active=this._dirty=!1};i._setProp=function(t,e){this[t]=e};createjs.Graphics=e})();this.createjs=this.createjs||{};(function(){var t=function(){this.initialize()},e=t.prototype;t.suppressCrossDomainErrors=!1;t._hitTestCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");t._hitTestCanvas.width=t._hitTestCanvas.height=1;t._hitTestContext=t._hitTestCanvas.getContext("2d");t._nextCacheID=1;e.alpha=1;e.cacheCanvas=null;e.id=-1;e.mouseEnabled=!0;e.name=null;e.parent=null;e.regX=0;e.regY=0;e.rotation=0;e.scaleX=1;e.scaleY=1;e.skewX=0;e.skewY=0;e.shadow=null;e.visible=!0;e.x=0;e.y=0;e.compositeOperation=null;e.snapToPixel=!1;e.onPress=null;e.onClick=null;e.onDoubleClick=null;e.onMouseOver=null;e.onMouseOut=null;e.onTick=null;e.filters=null;e.cacheID=0;e.mask=null;e.hitArea=null;e.cursor=null;e.addEventListener=null;e.removeEventListener=null;e.removeAllEventListeners=null;e.dispatchEvent=null;e.hasEventListener=null;e._listeners=null;createjs.EventDispatcher.initialize(e);e._cacheOffsetX=0;e._cacheOffsetY=0;e._cacheScale=1;e._cacheDataURLID=0;e._cacheDataURL=null;e._matrix=null;e.initialize=function(){this.id=createjs.UID.get();this._matrix=new createjs.Matrix2D};e.isVisible=function(){return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY)};e.draw=function(t,e){var i=this.cacheCanvas;if(e||!i)return!1;var n=this._cacheScale;t.drawImage(i,this._cacheOffsetX,this._cacheOffsetY,i.width/n,i.height/n);return!0};e.updateContext=function(t){var e,i=this.mask;i&&i.graphics&&!i.graphics.isEmpty()&&(e=i.getMatrix(i._matrix),t.transform(e.a,e.b,e.c,e.d,e.tx,e.ty),i.graphics.drawAsPath(t),t.clip(),e.invert(),t.transform(e.a,e.b,e.c,e.d,e.tx,e.ty));e=this._matrix.identity().appendTransform(this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.skewX,this.skewY,this.regX,this.regY);createjs.Stage._snapToPixelEnabled&&this.snapToPixel?t.transform(e.a,e.b,e.c,e.d,0|e.tx+.5,0|e.ty+.5):t.transform(e.a,e.b,e.c,e.d,e.tx,e.ty);t.globalAlpha*=this.alpha;this.compositeOperation&&(t.globalCompositeOperation=this.compositeOperation);this.shadow&&this._applyShadow(t,this.shadow)};e.cache=function(t,e,i,n,r){r=r||1;this.cacheCanvas||(this.cacheCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));this.cacheCanvas.width=Math.ceil(i*r);this.cacheCanvas.height=Math.ceil(n*r);this._cacheOffsetX=t;this._cacheOffsetY=e;this._cacheScale=r||1;this.updateCache()};e.updateCache=function(e){var i=this.cacheCanvas,n=this._cacheScale,r=this._cacheOffsetX*n,a=this._cacheOffsetY*n;if(!i)throw"cache() must be called before updateCache()";var s=i.getContext("2d");s.save();e||s.clearRect(0,0,i.width+1,i.height+1);s.globalCompositeOperation=e;s.setTransform(n,0,0,n,-r,-a);this.draw(s,!0);this._applyFilters();s.restore();this.cacheID=t._nextCacheID++};e.uncache=function(){this._cacheDataURL=this.cacheCanvas=null;this.cacheID=this._cacheOffsetX=this._cacheOffsetY=0;this._cacheScale=1};e.getCacheDataURL=function(){if(!this.cacheCanvas)return null;this.cacheID!=this._cacheDataURLID&&(this._cacheDataURL=this.cacheCanvas.toDataURL());return this._cacheDataURL};e.getStage=function(){for(var t=this;t.parent;)t=t.parent;return t instanceof createjs.Stage?t:null};e.localToGlobal=function(t,e){var i=this.getConcatenatedMatrix(this._matrix);if(null==i)return null;i.append(1,0,0,1,t,e);return new createjs.Point(i.tx,i.ty)};e.globalToLocal=function(t,e){var i=this.getConcatenatedMatrix(this._matrix);if(null==i)return null;i.invert();i.append(1,0,0,1,t,e);return new createjs.Point(i.tx,i.ty)};e.localToLocal=function(t,e,i){t=this.localToGlobal(t,e);return i.globalToLocal(t.x,t.y)};e.setTransform=function(t,e,i,n,r,a,s,o,h){this.x=t||0;this.y=e||0;this.scaleX=null==i?1:i;this.scaleY=null==n?1:n;this.rotation=r||0;this.skewX=a||0;this.skewY=s||0;this.regX=o||0;this.regY=h||0;return this};e.getMatrix=function(t){return(t?t.identity():new createjs.Matrix2D).appendTransform(this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.skewX,this.skewY,this.regX,this.regY).appendProperties(this.alpha,this.shadow,this.compositeOperation)};e.getConcatenatedMatrix=function(t){t?t.identity():t=new createjs.Matrix2D;for(var e=this;null!=e;)t.prependTransform(e.x,e.y,e.scaleX,e.scaleY,e.rotation,e.skewX,e.skewY,e.regX,e.regY).prependProperties(e.alpha,e.shadow,e.compositeOperation),e=e.parent;return t};e.hitTest=function(e,i){var n=t._hitTestContext;n.setTransform(1,0,0,1,-e,-i);this.draw(n);var r=this._testHit(n);n.setTransform(1,0,0,1,0,0);n.clearRect(0,0,2,2);return r};e.set=function(t){for(var e in t)this[e]=t[e];return this};e.clone=function(){var e=new t;this.cloneProps(e);return e};e.toString=function(){return"[DisplayObject (name="+this.name+")]"};e.cloneProps=function(t){t.alpha=this.alpha;t.name=this.name;t.regX=this.regX;t.regY=this.regY;t.rotation=this.rotation;t.scaleX=this.scaleX;t.scaleY=this.scaleY;t.shadow=this.shadow;t.skewX=this.skewX;t.skewY=this.skewY;t.visible=this.visible;t.x=this.x;t.y=this.y;t.mouseEnabled=this.mouseEnabled;t.compositeOperation=this.compositeOperation;this.cacheCanvas&&(t.cacheCanvas=this.cacheCanvas.cloneNode(!0),t.cacheCanvas.getContext("2d").putImageData(this.cacheCanvas.getContext("2d").getImageData(0,0,this.cacheCanvas.width,this.cacheCanvas.height),0,0))};e._applyShadow=function(t,e){e=e||Shadow.identity;t.shadowColor=e.color;t.shadowOffsetX=e.offsetX;t.shadowOffsetY=e.offsetY;t.shadowBlur=e.blur};e._tick=function(t){this.onTick&&this.onTick.apply(this,t);var e=this._listeners;e&&e.tick&&this.dispatchEvent({type:"tick",params:t})};e._testHit=function(e){try{var i=e.getImageData(0,0,1,1).data[3]>1}catch(n){if(!t.suppressCrossDomainErrors)throw"An error has occurred. This is most likely due to security restrictions on reading canvas pixel data with local or cross-domain images."}return i};e._applyFilters=function(){if(this.filters&&0!=this.filters.length&&this.cacheCanvas)for(var t=this.filters.length,e=this.cacheCanvas.getContext("2d"),i=this.cacheCanvas.width,n=this.cacheCanvas.height,r=0;t>r;r++)this.filters[r].applyFilter(e,0,0,i,n)};e._hasMouseHandler=function(t){var e=this._listeners;return!!(1&t&&(this.onPress||this.onClick||this.onDoubleClick||e&&(this.hasEventListener("mousedown")||this.hasEventListener("click")||this.hasEventListener("dblclick")))||2&t&&(this.onMouseOver||this.onMouseOut||this.cursor||e&&(this.hasEventListener("mouseover")||this.hasEventListener("mouseout"))))};createjs.DisplayObject=t})();this.createjs=this.createjs||{};(function(){var t=function(){this.initialize()},e=t.prototype=new createjs.DisplayObject;e.children=null;e.DisplayObject_initialize=e.initialize;e.initialize=function(){this.DisplayObject_initialize();this.children=[]};e.isVisible=function(){var t=this.cacheCanvas||this.children.length;return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY&&t)};e.DisplayObject_draw=e.draw;e.draw=function(t,e){if(this.DisplayObject_draw(t,e))return!0;for(var i=this.children.slice(0),n=0,r=i.length;r>n;n++){var a=i[n];a.isVisible()&&(t.save(),a.updateContext(t),a.draw(t),t.restore())}return!0};e.addChild=function(t){if(null==t)return t;var e=arguments.length;if(e>1){for(var i=0;e>i;i++)this.addChild(arguments[i]);return arguments[e-1]}t.parent&&t.parent.removeChild(t);t.parent=this;this.children.push(t);return t};e.addChildAt=function(t,e){var i=arguments.length,n=arguments[i-1];if(0>n||n>this.children.length)return arguments[i-2];if(i>2){for(var r=0;i-1>r;r++)this.addChildAt(arguments[r],n+r);return arguments[i-2]}t.parent&&t.parent.removeChild(t);t.parent=this;this.children.splice(e,0,t);return t};e.removeChild=function(t){var e=arguments.length;if(e>1){for(var i=!0,n=0;e>n;n++)i=i&&this.removeChild(arguments[n]);return i}return this.removeChildAt(this.children.indexOf(t))};e.removeChildAt=function(t){var e=arguments.length;if(e>1){for(var i=[],n=0;e>n;n++)i[n]=arguments[n];i.sort(function(t,e){return e-t});for(var r=!0,n=0;e>n;n++)r=r&&this.removeChildAt(i[n]);return r}if(0>t||t>this.children.length-1)return!1;(e=this.children[t])&&(e.parent=null);this.children.splice(t,1);return!0};e.removeAllChildren=function(){for(var t=this.children;t.length;)t.pop().parent=null};e.getChildAt=function(t){return this.children[t]};e.getChildByName=function(t){for(var e=this.children,i=0,n=e.length;n>i;i++)if(e[i].name==t)return e[i];return null};e.sortChildren=function(t){this.children.sort(t)};e.getChildIndex=function(t){return this.children.indexOf(t)};e.getNumChildren=function(){return this.children.length};e.swapChildrenAt=function(t,e){var i=this.children,n=i[t],r=i[e];n&&r&&(i[t]=r,i[e]=n)};e.swapChildren=function(t,e){for(var i,n,r=this.children,a=0,s=r.length;s>a&&!(r[a]==t&&(i=a),r[a]==e&&(n=a),null!=i&&null!=n);a++);a!=s&&(r[i]=e,r[n]=t)};e.setChildIndex=function(t,e){var i=this.children,n=i.length;if(!(t.parent!=this||0>e||e>=n)){for(var r=0;n>r&&i[r]!=t;r++);r==n||r==e||(i.splice(r,1),r>e&&e--,i.splice(e,0,t))}};e.contains=function(t){for(;t;){if(t==this)return!0;t=t.parent}return!1};e.hitTest=function(t,e){return null!=this.getObjectUnderPoint(t,e)};e.getObjectsUnderPoint=function(t,e){var i=[],n=this.localToGlobal(t,e);this._getObjectsUnderPoint(n.x,n.y,i);return i};e.getObjectUnderPoint=function(t,e){var i=this.localToGlobal(t,e);return this._getObjectsUnderPoint(i.x,i.y)};e.clone=function(e){var i=new t;this.cloneProps(i);if(e)for(var n=i.children=[],r=0,a=this.children.length;a>r;r++){var s=this.children[r].clone(e);s.parent=i;n.push(s)}return i};e.toString=function(){return"[Container (name="+this.name+")]"};e.DisplayObject__tick=e._tick;e._tick=function(t){for(var e=this.children.length-1;e>=0;e--){var i=this.children[e];i._tick&&i._tick(t)}this.DisplayObject__tick(t)};e._getObjectsUnderPoint=function(e,i,n,r){var a=createjs.DisplayObject._hitTestContext,s=this._matrix,o=this._hasMouseHandler(r);if(!this.hitArea&&this.cacheCanvas&&o&&(this.getConcatenatedMatrix(s),a.setTransform(s.a,s.b,s.c,s.d,s.tx-e,s.ty-i),a.globalAlpha=s.alpha,this.draw(a),this._testHit(a)))return a.setTransform(1,0,0,1,0,0),a.clearRect(0,0,2,2),this;for(var h=this.children.length-1;h>=0;h--){var l=this.children[h],u=l.hitArea;if(l.visible&&(u||l.isVisible())&&(!r||l.mouseEnabled)){var c=r&&l._hasMouseHandler(r);if(!(l instanceof t)||u&&c){if((!r||o||c)&&(l.getConcatenatedMatrix(s),u&&(s.appendTransform(u.x,u.y,u.scaleX,u.scaleY,u.rotation,u.skewX,u.skewY,u.regX,u.regY),s.alpha=u.alpha),a.globalAlpha=s.alpha,a.setTransform(s.a,s.b,s.c,s.d,s.tx-e,s.ty-i),(u||l).draw(a),this._testHit(a))){a.setTransform(1,0,0,1,0,0);a.clearRect(0,0,2,2);if(o)return this;if(!n)return l;n.push(l)}}else if(o){if(l=l._getObjectsUnderPoint(e,i))return this}else if(l=l._getObjectsUnderPoint(e,i,n,r),!n&&l)return l}}return null};createjs.Container=t})();this.createjs=this.createjs||{};(function(){var t=function(t){this.initialize(t)},e=t.prototype=new createjs.Container;t._snapToPixelEnabled=!1;e.autoClear=!0;e.canvas=null;e.mouseX=0;e.mouseY=0;e.onMouseMove=null;e.onMouseUp=null;e.onMouseDown=null;e.snapToPixelEnabled=!1;e.mouseInBounds=!1;e.tickOnUpdate=!0;e.mouseMoveOutside=!1;e._pointerData=null;e._pointerCount=0;e._primaryPointerID=null;e._mouseOverIntervalID=null;e.Container_initialize=e.initialize;e.initialize=function(t){this.Container_initialize();this.canvas="string"==typeof t?document.getElementById(t):t;this._pointerData={};this.enableDOMEvents(!0)};e.update=function(){if(this.canvas){this.autoClear&&this.clear();t._snapToPixelEnabled=this.snapToPixelEnabled;this.tickOnUpdate&&this._tick(arguments.length?arguments:null);var e=this.canvas.getContext("2d");e.save();this.updateContext(e);this.draw(e,!1);e.restore()}};e.tick=e.update;e.handleEvent=function(t){"tick"==t.type&&this.update(t)};e.clear=function(){if(this.canvas){var t=this.canvas.getContext("2d");t.setTransform(1,0,0,1,0,0);t.clearRect(0,0,this.canvas.width+1,this.canvas.height+1)}};e.toDataURL=function(t,e){e||(e="image/png");var i,n=this.canvas.getContext("2d"),r=this.canvas.width,a=this.canvas.height;if(t){i=n.getImageData(0,0,r,a);var s=n.globalCompositeOperation;n.globalCompositeOperation="destination-over";n.fillStyle=t;n.fillRect(0,0,r,a)}var o=this.canvas.toDataURL(e);t&&(n.clearRect(0,0,r+1,a+1),n.putImageData(i,0,0),n.globalCompositeOperation=s);return o};e.enableMouseOver=function(t){this._mouseOverIntervalID&&(clearInterval(this._mouseOverIntervalID),this._mouseOverIntervalID=null);if(null==t)t=20;else if(0>=t)return;var e=this;this._mouseOverIntervalID=setInterval(function(){e._testMouseOver()},1e3/Math.min(50,t))};e.enableDOMEvents=function(t){null==t&&(t=!0);var e,i=this._eventListeners;if(!t&&i){for(e in i)t=i[e],t.t.removeEventListener(e,t.f);this._eventListeners=null}else if(t&&!i&&this.canvas){t=window.addEventListener?window:document;var n=this,i=this._eventListeners={};i.mouseup={t:t,f:function(t){n._handleMouseUp(t)}};i.mousemove={t:t,f:function(t){n._handleMouseMove(t)}};i.dblclick={t:t,f:function(t){n._handleDoubleClick(t)}};i.mousedown={t:this.canvas,f:function(t){n._handleMouseDown(t)}};for(e in i)t=i[e],t.t.addEventListener(e,t.f)}};e.clone=function(){var e=new t(null);this.cloneProps(e);return e};e.toString=function(){return"[Stage (name="+this.name+")]"};e._getPointerData=function(t){var e=this._pointerData[t];e||(e=this._pointerData[t]={x:0,y:0},null!=this._primaryPointerID&&-1!=this._primaryPointerID)||(this._primaryPointerID=t);return e};e._handleMouseMove=function(t){t||(t=window.event);this._handlePointerMove(-1,t,t.pageX,t.pageY)};e._handlePointerMove=function(t,e,i,n){if(this.canvas){var r=this._getPointerData(t),a=r.inBounds;this._updatePointerPosition(t,i,n);if(a||r.inBounds||this.mouseMoveOutside){(this.onMouseMove||this.hasEventListener("stagemousemove"))&&(i=new createjs.MouseEvent("stagemousemove",r.x,r.y,this,e,t,t==this._primaryPointerID,r.rawX,r.rawY),this.onMouseMove&&this.onMouseMove(i),this.dispatchEvent(i));(n=r.event)&&(n.onMouseMove||n.hasEventListener("mousemove"))&&(i=new createjs.MouseEvent("mousemove",r.x,r.y,n.target,e,t,t==this._primaryPointerID,r.rawX,r.rawY),n.onMouseMove&&n.onMouseMove(i),n.dispatchEvent(i,n.target)) -}}};e._updatePointerPosition=function(t,e,i){var n=this._getElementRect(this.canvas);e-=n.left;i-=n.top;var r=this.canvas.width,a=this.canvas.height;e/=(n.right-n.left)/r;i/=(n.bottom-n.top)/a;n=this._getPointerData(t);(n.inBounds=e>=0&&i>=0&&r-1>=e&&a-1>=i)?(n.x=e,n.y=i):this.mouseMoveOutside&&(n.x=0>e?0:e>r-1?r-1:e,n.y=0>i?0:i>a-1?a-1:i);n.rawX=e;n.rawY=i;t==this._primaryPointerID&&(this.mouseX=n.x,this.mouseY=n.y,this.mouseInBounds=n.inBounds)};e._getElementRect=function(t){var e;try{e=t.getBoundingClientRect()}catch(i){e={top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth,height:t.offsetHeight}}var n=(window.pageXOffset||document.scrollLeft||0)-(document.clientLeft||document.body.clientLeft||0),r=(window.pageYOffset||document.scrollTop||0)-(document.clientTop||document.body.clientTop||0),a=window.getComputedStyle?getComputedStyle(t):t.currentStyle;t=parseInt(a.paddingLeft)+parseInt(a.borderLeftWidth);var s=parseInt(a.paddingTop)+parseInt(a.borderTopWidth),o=parseInt(a.paddingRight)+parseInt(a.borderRightWidth),a=parseInt(a.paddingBottom)+parseInt(a.borderBottomWidth);return{left:e.left+n+t,right:e.right+n-o,top:e.top+r+s,bottom:e.bottom+r-a}};e._handleMouseUp=function(t){this._handlePointerUp(-1,t,!1)};e._handlePointerUp=function(t,e,i){var n,r=this._getPointerData(t);(this.onMouseMove||this.hasEventListener("stagemouseup"))&&(n=new createjs.MouseEvent("stagemouseup",r.x,r.y,this,e,t,t==this._primaryPointerID,r.rawX,r.rawY),this.onMouseUp&&this.onMouseUp(n),this.dispatchEvent(n));var a=r.event;a&&(a.onMouseUp||a.hasEventListener("mouseup"))&&(n=new createjs.MouseEvent("mouseup",r.x,r.y,a.target,e,t,t==this._primaryPointerID,r.rawX,r.rawY),a.onMouseUp&&a.onMouseUp(n),a.dispatchEvent(n,a.target));(a=r.target)&&(a.onClick||a.hasEventListener("click"))&&this._getObjectsUnderPoint(r.x,r.y,null,!0,this._mouseOverIntervalID?3:1)==a&&(n=new createjs.MouseEvent("click",r.x,r.y,a,e,t,t==this._primaryPointerID,r.rawX,r.rawY),a.onClick&&a.onClick(n),a.dispatchEvent(n));i?(t==this._primaryPointerID&&(this._primaryPointerID=null),delete this._pointerData[t]):r.event=r.target=null};e._handleMouseDown=function(t){this._handlePointerDown(-1,t,!1)};e._handlePointerDown=function(t,e,i,n){var r=this._getPointerData(t);null!=n&&this._updatePointerPosition(t,i,n);(this.onMouseDown||this.hasEventListener("stagemousedown"))&&(i=new createjs.MouseEvent("stagemousedown",r.x,r.y,this,e,t,t==this._primaryPointerID,r.rawX,r.rawY),this.onMouseDown&&this.onMouseDown(i),this.dispatchEvent(i));(n=this._getObjectsUnderPoint(r.x,r.y,null,this._mouseOverIntervalID?3:1))&&(r.target=n,n.onPress||n.hasEventListener("mousedown"))&&(i=new createjs.MouseEvent("mousedown",r.x,r.y,n,e,t,t==this._primaryPointerID,r.rawX,r.rawY),n.onPress&&n.onPress(i),n.dispatchEvent(i),i.onMouseMove||i.onMouseUp||i.hasEventListener("mousemove")||i.hasEventListener("mouseup"))&&(r.event=i)};e._testMouseOver=function(){if(-1==this._primaryPointerID&&(this.mouseX!=this._mouseOverX||this.mouseY!=this._mouseOverY||!this.mouseInBounds)){var t=null;this.mouseInBounds&&(t=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY);var e=this._mouseOverTarget;if(e!=t){var i=this._getPointerData(-1);if(e&&(e.onMouseOut||e.hasEventListener("mouseout"))){var n=new createjs.MouseEvent("mouseout",i.x,i.y,e,null,-1,i.rawX,i.rawY);e.onMouseOut&&e.onMouseOut(n);e.dispatchEvent(n)}e&&(this.canvas.style.cursor="");t&&(t.onMouseOver||t.hasEventListener("mouseover"))&&(n=new createjs.MouseEvent("mouseover",i.x,i.y,t,null,-1,i.rawX,i.rawY),t.onMouseOver&&t.onMouseOver(n),t.dispatchEvent(n));t&&(this.canvas.style.cursor=t.cursor||"");this._mouseOverTarget=t}}};e._handleDoubleClick=function(t){var e=this._getPointerData(-1),i=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1);i&&(i.onDoubleClick||i.hasEventListener("dblclick"))&&(evt=new createjs.MouseEvent("dblclick",e.x,e.y,i,t,-1,!0,e.rawX,e.rawY),i.onDoubleClick&&i.onDoubleClick(evt),i.dispatchEvent(evt))};createjs.Stage=t})();this.createjs=this.createjs||{};(function(){var t=function(t){this.initialize(t)},e=t.prototype=new createjs.DisplayObject;e.image=null;e.snapToPixel=!0;e.sourceRect=null;e.DisplayObject_initialize=e.initialize;e.initialize=function(t){this.DisplayObject_initialize();"string"==typeof t?(this.image=new Image,this.image.src=t):this.image=t};e.isVisible=function(){var t=this.cacheCanvas||this.image&&(this.image.complete||this.image.getContext||this.image.readyState>=2);return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY&&t)};e.DisplayObject_draw=e.draw;e.draw=function(t,e){if(this.DisplayObject_draw(t,e))return!0;var i=this.sourceRect;i?t.drawImage(this.image,i.x,i.y,i.width,i.height,0,0,i.width,i.height):t.drawImage(this.image,0,0);return!0};e.clone=function(){var e=new t(this.image);this.sourceRect&&(e.sourceRect=this.sourceRect.clone());this.cloneProps(e);return e};e.toString=function(){return"[Bitmap (name="+this.name+")]"};createjs.Bitmap=t})();this.createjs=this.createjs||{};(function(){var t=function(t){this.initialize(t)},e=t.prototype=new createjs.DisplayObject;e.onAnimationEnd=null;e.currentFrame=-1;e.currentAnimation=null;e.paused=!0;e.spriteSheet=null;e.snapToPixel=!0;e.offset=0;e.currentAnimationFrame=0;e.addEventListener=null;e.removeEventListener=null;e.removeAllEventListeners=null;e.dispatchEvent=null;e.hasEventListener=null;e._listeners=null;createjs.EventDispatcher.initialize(e);e._advanceCount=0;e._animation=null;e.DisplayObject_initialize=e.initialize;e.initialize=function(t){this.DisplayObject_initialize();this.spriteSheet=t};e.isVisible=function(){var t=this.cacheCanvas||this.spriteSheet.complete&&this.currentFrame>=0;return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY&&t)};e.DisplayObject_draw=e.draw;e.draw=function(t,e){if(this.DisplayObject_draw(t,e))return!0;this._normalizeFrame();var i=this.spriteSheet.getFrame(this.currentFrame);if(i){var n=i.rect;t.drawImage(i.image,n.x,n.y,n.width,n.height,-i.regX,-i.regY,n.width,n.height);return!0}};e.play=function(){this.paused=!1};e.stop=function(){this.paused=!0};e.gotoAndPlay=function(t){this.paused=!1;this._goto(t)};e.gotoAndStop=function(t){this.paused=!0;this._goto(t)};e.advance=function(){this._animation?this.currentAnimationFrame++:this.currentFrame++;this._normalizeFrame()};e.getBounds=function(){return this.spriteSheet.getFrameBounds(this.currentFrame)};e.clone=function(){var e=new t(this.spriteSheet);this.cloneProps(e);return e};e.toString=function(){return"[BitmapAnimation (name="+this.name+")]"};e.DisplayObject__tick=e._tick;e._tick=function(t){var e=this._animation?this._animation.frequency:1;!this.paused&&0==(++this._advanceCount+this.offset)%e&&this.advance();this.DisplayObject__tick(t)};e._normalizeFrame=function(){var t,e=this._animation,i=this.currentFrame,n=this.paused;if(e)if(t=e.frames.length,this.currentAnimationFrame>=t){var r=e.next;this._dispatchAnimationEnd(e,i,n,r,t-1)||(r?this._goto(r):(this.paused=!0,this.currentAnimationFrame=e.frames.length-1,this.currentFrame=e.frames[this.currentAnimationFrame]))}else this.currentFrame=e.frames[this.currentAnimationFrame];else t=this.spriteSheet.getNumFrames(),i>=t&&!this._dispatchAnimationEnd(e,i,n,t-1)&&(this.currentFrame=0)};e._dispatchAnimationEnd=function(t,e,i,n,r){var a=t?t.name:null;this.onAnimationEnd&&this.onAnimationEnd(this,a,n);this.dispatchEvent({type:"animationend",name:a,next:n});!i&&this.paused&&(this.currentAnimationFrame=r);return this.paused!=i||this._animation!=t||this.currentFrame!=e};e.DisplayObject_cloneProps=e.cloneProps;e.cloneProps=function(t){this.DisplayObject_cloneProps(t);t.onAnimationEnd=this.onAnimationEnd;t.currentFrame=this.currentFrame;t.currentAnimation=this.currentAnimation;t.paused=this.paused;t.offset=this.offset;t._animation=this._animation;t.currentAnimationFrame=this.currentAnimationFrame};e._goto=function(t){if(isNaN(t)){var e=this.spriteSheet.getAnimation(t);e&&(this.currentAnimationFrame=0,this._animation=e,this.currentAnimation=t,this._normalizeFrame())}else this.currentAnimation=this._animation=null,this.currentFrame=t};createjs.BitmapAnimation=t})();this.createjs=this.createjs||{};(function(){var t=function(t){this.initialize(t)},e=t.prototype=new createjs.DisplayObject;e.graphics=null;e.DisplayObject_initialize=e.initialize;e.initialize=function(t){this.DisplayObject_initialize();this.graphics=t?t:new createjs.Graphics};e.isVisible=function(){var t=this.cacheCanvas||this.graphics&&!this.graphics.isEmpty();return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY&&t)};e.DisplayObject_draw=e.draw;e.draw=function(t,e){if(this.DisplayObject_draw(t,e))return!0;this.graphics.draw(t);return!0};e.clone=function(e){e=new t(e&&this.graphics?this.graphics.clone():this.graphics);this.cloneProps(e);return e};e.toString=function(){return"[Shape (name="+this.name+")]"};createjs.Shape=t})();this.createjs=this.createjs||{};(function(){var t=function(t,e,i){this.initialize(t,e,i)},e=t.prototype=new createjs.DisplayObject;t._workingContext=(createjs.createCanvas?createjs.createCanvas():document.createElement("canvas")).getContext("2d");e.text="";e.font=null;e.color="#000";e.textAlign="left";e.textBaseline="top";e.maxWidth=null;e.outline=!1;e.lineHeight=0;e.lineWidth=null;e.DisplayObject_initialize=e.initialize;e.initialize=function(t,e,i){this.DisplayObject_initialize();this.text=t;this.font=e;this.color=i?i:"#000"};e.isVisible=function(){var t=this.cacheCanvas||null!=this.text&&""!==this.text;return!!(this.visible&&this.alpha>0&&0!=this.scaleX&&0!=this.scaleY&&t)};e.DisplayObject_draw=e.draw;e.draw=function(t,e){if(this.DisplayObject_draw(t,e))return!0;this.outline?t.strokeStyle=this.color:t.fillStyle=this.color;t.font=this.font;t.textAlign=this.textAlign||"start";t.textBaseline=this.textBaseline||"alphabetic";this._drawText(t);return!0};e.getMeasuredWidth=function(){return this._getWorkingContext().measureText(this.text).width};e.getMeasuredLineHeight=function(){return 1.2*this._getWorkingContext().measureText("M").width};e.getMeasuredHeight=function(){return this._drawText()*(this.lineHeight||this.getMeasuredLineHeight())};e.clone=function(){var e=new t(this.text,this.font,this.color);this.cloneProps(e);return e};e.toString=function(){return"[Text (text="+(this.text.length>20?this.text.substr(0,17)+"...":this.text)+")]"};e.DisplayObject_cloneProps=e.cloneProps;e.cloneProps=function(t){this.DisplayObject_cloneProps(t);t.textAlign=this.textAlign;t.textBaseline=this.textBaseline;t.maxWidth=this.maxWidth;t.outline=this.outline;t.lineHeight=this.lineHeight;t.lineWidth=this.lineWidth};e._getWorkingContext=function(){var e=t._workingContext;e.font=this.font;e.textAlign=this.textAlign||"start";e.textBaseline=this.textBaseline||"alphabetic";return e};e._drawText=function(t){var e=!!t;e||(t=this._getWorkingContext());for(var i=(this.text+"").split(/(?:\r\n|\r|\n)/),n=this.lineHeight||this.getMeasuredLineHeight(),r=0,a=0,s=i.length;s>a;a++){var o=t.measureText(i[a]).width;if(null==this.lineWidth||this.lineWidth>o)e&&this._drawTextLine(t,i[a],r*n);else{for(var o=i[a].split(/(\s)/),h=o[0],l=1,u=o.length;u>l;l+=2)t.measureText(h+o[l]+o[l+1]).width>this.lineWidth?(e&&this._drawTextLine(t,h,r*n),r++,h=o[l+1]):h+=o[l]+o[l+1];e&&this._drawTextLine(t,h,r*n)}r++}return r};e._drawTextLine=function(t,e,i){this.outline?t.strokeText(e,0,i,this.maxWidth||65535):t.fillText(e,0,i,this.maxWidth||65535)};createjs.Text=t})();this.createjs=this.createjs||{};(function(){var t=function(){throw"SpriteSheetUtils cannot be instantiated"};t._workingCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");t._workingContext=t._workingCanvas.getContext("2d");t.addFlippedFrames=function(e,i,n,r){if(i||n||r){var a=0;i&&t._flip(e,++a,!0,!1);n&&t._flip(e,++a,!1,!0);r&&t._flip(e,++a,!0,!0)}};t.extractFrame=function(e,i){isNaN(i)&&(i=e.getAnimation(i).frames[0]);var n=e.getFrame(i);if(!n)return null;var r=n.rect,a=t._workingCanvas;a.width=r.width;a.height=r.height;t._workingContext.drawImage(n.image,r.x,r.y,r.width,r.height,0,0,r.width,r.height);n=new Image;n.src=a.toDataURL("image/png");return n};t.mergeAlpha=function(t,e,i){i||(i=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));i.width=Math.max(e.width,t.width);i.height=Math.max(e.height,t.height);var n=i.getContext("2d");n.save();n.drawImage(t,0,0);n.globalCompositeOperation="destination-in";n.drawImage(e,0,0);n.restore();return i};t._flip=function(e,i,n,r){for(var a=e._images,s=t._workingCanvas,o=t._workingContext,h=a.length/i,l=0;h>l;l++){var u=a[l];u.__tmp=l;o.setTransform(1,0,0,1,0,0);o.clearRect(0,0,s.width+1,s.height+1);s.width=u.width;s.height=u.height;o.setTransform(n?-1:1,0,0,r?-1:1,n?u.width:0,r?u.height:0);o.drawImage(u,0,0);var c=new Image;c.src=s.toDataURL("image/png");c.width=u.width;c.height=u.height;a.push(c)}o=e._frames;s=o.length/i;for(l=0;s>l;l++){var u=o[l],p=u.rect.clone(),c=a[u.image.__tmp+h*i],d={image:c,rect:p,regX:u.regX,regY:u.regY};n&&(p.x=c.width-p.x-p.width,d.regX=p.width-u.regX);r&&(p.y=c.height-p.y-p.height,d.regY=p.height-u.regY);o.push(d)}n="_"+(n?"h":"")+(r?"v":"");r=e._animations;e=e._data;a=r.length/i;for(l=0;a>l;l++){o=r[l];u=e[o];h={name:o+n,frequency:u.frequency,next:u.next,frames:[]};u.next&&(h.next+=n);o=u.frames;u=0;for(c=o.length;c>u;u++)h.frames.push(o[u]+s*i);e[h.name]=h;r.push(h.name)}};createjs.SpriteSheetUtils=t})();this.createjs=this.createjs||{};(function(){var t=function(){this.initialize()},e=t.prototype;t.ERR_DIMENSIONS="frame dimensions exceed max spritesheet dimensions";t.ERR_RUNNING="a build is already running";e.maxWidth=2048;e.maxHeight=2048;e.spriteSheet=null;e.scale=1;e.padding=1;e.timeSlice=.3;e.progress=-1;e.onComplete=null;e.onProgress=null;e.addEventListener=null;e.removeEventListener=null;e.removeAllEventListeners=null;e.dispatchEvent=null;e.hasEventListener=null;e._listeners=null;createjs.EventDispatcher.initialize(e);e._frames=null;e._animations=null;e._data=null;e._nextFrameIndex=0;e._index=0;e._timerID=null;e._scale=1;e.initialize=function(){this._frames=[];this._animations={}};e.addFrame=function(e,i,n,r,a,s){if(this._data)throw t.ERR_RUNNING;i=i||e.bounds||e.nominalBounds;!i&&e.getBounds&&(i=e.getBounds());if(!i)return null;n=n||1;return this._frames.push({source:e,sourceRect:i,scale:n,funct:r,params:a,scope:s,index:this._frames.length,height:i.height*n})-1};e.addAnimation=function(e,i,n,r){if(this._data)throw t.ERR_RUNNING;this._animations[e]={frames:i,next:n,frequency:r}};e.addMovieClip=function(e,i,n){if(this._data)throw t.ERR_RUNNING;var r=e.frameBounds,a=i||e.bounds||e.nominalBounds;!a&&e.getBounds&&(a=e.getBounds());if(!a&&!r)return null;i=this._frames.length;for(var s=e.timeline.duration,o=0;s>o;o++)this.addFrame(e,r&&r[o]?r[o]:a,n,function(t){var e=this.actionsEnabled;this.actionsEnabled=!1;this.gotoAndStop(t);this.actionsEnabled=e},[o],e);o=e.timeline._labels;e=[];for(var h in o)e.push({index:o[h],label:h});if(e.length){e.sort(function(t,e){return t.index-e.index});o=0;for(h=e.length;h>o;o++){n=e[o].label;for(var r=i+(o==h-1?s:e[o+1].index),a=[],l=i+e[o].index;r>l;l++)a.push(l);this.addAnimation(n,a,!0)}}};e.build=function(){if(this._data)throw t.ERR_RUNNING;for(this._startBuild();this._drawNext(););this._endBuild();return this.spriteSheet};e.buildAsync=function(e){if(this._data)throw t.ERR_RUNNING;this.timeSlice=e;this._startBuild();var i=this;this._timerID=setTimeout(function(){i._run()},50-50*Math.max(.01,Math.min(.99,this.timeSlice||.3)))};e.stopAsync=function(){clearTimeout(this._timerID);this._data=null};e.clone=function(){throw"SpriteSheetBuilder cannot be cloned."};e.toString=function(){return"[SpriteSheetBuilder]"};e._startBuild=function(){var e=this.padding||0;this.progress=0;this.spriteSheet=null;this._index=0;this._scale=this.scale;var i=[];this._data={images:[],frames:i,animations:this._animations};var n=this._frames.slice();n.sort(function(t,e){return t.height<=e.height?-1:1});if(n[n.length-1].height+2*e>this.maxHeight)throw t.ERR_DIMENSIONS;for(var r=0,a=0,s=0;n.length;){var o=this._fillRow(n,r,s,i,e);o.w>a&&(a=o.w);r+=o.h;if(!o.h||!n.length){var h=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");h.width=this._getSize(a,this.maxWidth);h.height=this._getSize(r,this.maxHeight);this._data.images[s]=h;o.h||(a=r=0,s++)}}};e._getSize=function(t,e){for(var i=4;t>Math.pow(2,++i););return Math.min(e,Math.pow(2,i))};e._fillRow=function(e,i,n,r,a){var s=this.maxWidth,o=this.maxHeight;i+=a;for(var o=o-i,h=a,l=0,u=e.length-1;u>=0;u--){var c=e[u],p=this._scale*c.scale,d=c.sourceRect,f=c.source,g=Math.floor(p*d.x-a),v=Math.floor(p*d.y-a),m=Math.ceil(p*d.height+2*a),d=Math.ceil(p*d.width+2*a);if(d>s)throw t.ERR_DIMENSIONS;m>o||h+d>s||(c.img=n,c.rect=new createjs.Rectangle(h,i,d,m),l=l||m,e.splice(u,1),r[c.index]=[h,i,d,m,n,Math.round(-g+p*f.regX-a),Math.round(-v+p*f.regY-a)],h+=d)}return{w:h,h:l}};e._endBuild=function(){this.spriteSheet=new createjs.SpriteSheet(this._data);this._data=null;this.progress=1;this.onComplete&&this.onComplete(this);this.dispatchEvent("complete")};e._run=function(){for(var t=50*Math.max(.01,Math.min(.99,this.timeSlice||.3)),e=(new Date).getTime()+t,i=!1;e>(new Date).getTime();)if(!this._drawNext()){i=!0;break}if(i)this._endBuild();else{var n=this;this._timerID=setTimeout(function(){n._run()},50-t)}t=this.progress=this._index/this._frames.length;this.onProgress&&this.onProgress(this,t);this.dispatchEvent({type:"progress",progress:t})};e._drawNext=function(){var t=this._frames[this._index],e=t.scale*this._scale,i=t.rect,n=t.sourceRect,r=this._data.images[t.img].getContext("2d");t.funct&&t.funct.apply(t.scope,t.params);r.save();r.beginPath();r.rect(i.x,i.y,i.width,i.height);r.clip();r.translate(Math.ceil(i.x-n.x*e),Math.ceil(i.y-n.y*e));r.scale(e,e);t.source.draw(r);r.restore();return++this._indexr;r++){var s=i[r],o=s.identifier;s.target==t.canvas&&("touchstart"==n?this._handleStart(t,o,e,s.pageX,s.pageY):"touchmove"==n?this._handleMove(t,o,e,s.pageX,s.pageY):("touchend"==n||"touchcancel"==n)&&this._handleEnd(t,o,e))}}};t._IE_enable=function(e){var i=e.canvas,n=e.__touch.f=function(i){t._IE_handleEvent(e,i)};i.addEventListener("MSPointerDown",n,!1);window.addEventListener("MSPointerMove",n,!1);window.addEventListener("MSPointerUp",n,!1);window.addEventListener("MSPointerCancel",n,!1);e.__touch.preventDefault&&(i.style.msTouchAction="none");e.__touch.activeIDs={}};t._IE_disable=function(t){var e=t.__touch.f;window.removeEventListener("MSPointerMove",e,!1);window.removeEventListener("MSPointerUp",e,!1);window.removeEventListener("MSPointerCancel",e,!1);t.canvas&&t.canvas.removeEventListener("MSPointerDown",e,!1)};t._IE_handleEvent=function(t,e){if(t){t.__touch.preventDefault&&e.preventDefault&&e.preventDefault();var i=e.type,n=e.pointerId,r=t.__touch.activeIDs;"MSPointerDown"==i?e.srcElement==t.canvas&&(r[n]=!0,this._handleStart(t,n,e,e.pageX,e.pageY)):r[n]&&("MSPointerMove"==i?this._handleMove(t,n,e,e.pageX,e.pageY):("MSPointerUp"==i||"MSPointerCancel"==i)&&(delete r[n],this._handleEnd(t,n,e)))}};t._handleStart=function(t,e,i,n,r){var a=t.__touch;if(a.multitouch||!a.count){var s=a.pointers;s[e]||(s[e]=!0,a.count++,t._handlePointerDown(e,i,n,r))}};t._handleMove=function(t,e,i,n,r){t.__touch.pointers[e]&&t._handlePointerMove(e,i,n,r)};t._handleEnd=function(t,e,i){var n=t.__touch,r=n.pointers;r[e]&&(n.count--,t._handlePointerUp(e,i,!0),delete r[e])};createjs.Touch=t})();(function(){var t=this.createjs=this.createjs||{},t=t.EaselJS=t.EaselJS||{};t.version="NEXT";t.buildDate="Thu, 09 May 2013 18:21:47 GMT"})();return this.createjs}})();var ChartAPI=function(t,e){"use strict";var i=e,n={},r=t.MT=t.MT||{};r.ChartAPI=n;n.Data={};n.Data.getData=function(t,e,n,r){var a,s,o,h;t&&t.done(function(t){a||(a="string"==typeof t?""+t:i.isArray(t)?i.map(t,function(t){return i.extend({},t)}):i.extend({},t));n(a)}).fail(function(t){s={404:"Data is not found",403:"Data is forbidden to access"};o="Some error occured in the data fetching process";h=t.status?"error-"+t.status:"error-unknown";r&&(r.$errormsg=i('
'+(s[t.status]||o)+"
").appendTo(e))}).always(function(){r&&r.$progress&&r.$progress.parent().length>0&&r.$progress.remove()}).progress(function(){!r||r.$progress&&0!==r.$progress.parent().length||(r.$progress=i('
fetching data...
').appendTo(e))})};n.Data.filterData=function(t,e,r,a,s,o){var h,l={};s=s||1;i.each(t,function(t,u){var c,p;c=n.Date.parse(u.x);if(c&&c>=r&&e>=c)if(o){p=n.Date.createId(c,"daily");l[p]=u}else{"weekly"===a&&(c=n.Date.getWeekStartday(c));p=n.Date.createId(c,a);if(l[p])for(t=0;s>t;t++){h=t?"y"+t:"y";l[p][h]=parseInt(l[p][h],10)+parseInt(u[h],10)}else l[p]=i.extend({},u)}});return l};n.Date={};n.Date.getWeekStartday=function(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()-t.getDay())};n.Date.zeroPadArray=function(t,e){var n;({yearly:function(){n=[t.getFullYear()]},monthly:function(){n=[t.getFullYear(),t.getMonth()+1]},quarter:function(){n=[t.getFullYear(),t.getMonth()+1]},weekly:function(){n=[t.getFullYear(),t.getMonth()+1,t.getDate()-t.getDay()]},daily:function(){n=[t.getFullYear(),t.getMonth()+1,t.getDate()]},hourly:function(){n=[t.getFullYear(),t.getMonth()+1,t.getDate(),t.getHours()]}})[e]();return i.map(n,function(t){t=""+t;return 1===t.length?"0"+t:t})};n.Date.createId=function(t,e){return n.Date.zeroPadArray(t,e).join("")};n.Date.createXLabel=function(t,e){var i,r,a=n.Date.zeroPadArray(t,e);if("hourly"===e){i=a.pop();r=a.join("-")+" "+i+":00"}else r=a.join("-");return r};n.Date.parse=function(t){var e;e=!t||t instanceof Date?t||null:"number"==typeof t?new Date(t):new Date(Date.parse(""+t));if(e&&/NaN|Invalid Date/.test(""+e)){e=t.replace(/-/g,"/").split("+")[0];if(1===e.split("/").length){e=t.match(/([0-9]{4})([0-9]{1,2})([0-9]{1,2})/);e=[e[1],e[2],e[3]].join("/")}2===e.split("/").length&&(e+="/01");e=i.each(e.split("/"),function(t,e){return 1===e.length?"0"+e:e}).join("/");e=new Date(Date.parse(e))}return e};n.Date.calcDate=function(t,e,i,n){var r,a,s,o;r=t.getFullYear();a=t.getMonth();s=t.getDate();o=0;e-=1;n=n?-1:1;({yearly:function(){r+=n*e},monthly:function(){a+=n*e},quarter:function(){a+=4*n*e},weekly:function(){s=s+7*n*e-t.getDay()},daily:function(){s+=n*e},hourly:function(){o=t.getHours()+n*e}})[i]();return new Date(r,a,s,o)};n.Range={};n.Range.factory=function(t){var e;t=t||{};t.maxLength=t.maxLength||90;t.dataType=t.dataType||"timeline";t.isTimeline=n.Range.isTimeline(t.dataType);e=t.isTimeline?n.Range.calcDate:n.Range.calcNum;return e(t.start,t.end,t.length,t.maxLength,t.unit,t.dataType,t.autoSized)};n.Range.generate=n.Range.factory;n.Range.isTimeline=function(t){return!t||"timeline"===t};n.Range.calcDate=function(t,e,r,a,s,o,h){s=s||"monthly";r=r||("hourly"===s?24:10);if(h){var l=i(window).width();a=Math.min(Math.ceil(.021875*l),a);r=a}t=n.Date.parse(t);e=n.Date.parse(e);t||e||(e=n.Range.getEndDate(new Date,s));t||(t=n.Range.getStartDate(n.Date.calcDate(e,r,s,!0),s));e||(e=n.Range.getEndDate(n.Date.calcDate(t,r,s,!1),s));e>new Date&&(e=new Date);t>e&&(t=e);r=n.Range.getLength(t,e,s);if(r>a){r=a;t=n.Date.calcDate(e,r,s,!0)}return{start:t,end:e,length:r,maxLength:a,unit:s,dataType:o,max:n.Range.getEndDate(e,s),min:n.Range.getStartDate(t,s),isTimeline:!0}};n.Range.calcNum=function(t,e,n,r,a,s,o){n=n||10;if(o){var h=i(window).width();r=Math.min(Math.ceil(.021875*h),r);n=Math.min(n,r)}if(!t&&!e){t=0;e=n-1}t=parseInt(t,10)||(0===t?0:null);e=parseInt(e,10)||(0===e?0:null);if(null===t){t=e-n;0>t&&(t=0)}null===e&&(e=t+n);t>e&&(t=e);n=e-t+1;if(n>r){n=r;t=e-r}return{start:t,end:e,length:n,maxLength:r,dataType:s,unit:null,max:e,min:t,isTimeline:!1}};n.Range.getStartDate=function(t,e){var i,n=t.getFullYear(),r=t.getMonth(),a=t.getDate();({yearly:function(){i=new Date(n,0,1,0,0,0)},monthly:function(){i=new Date(n,r,1,0,0,0)},quarter:function(){i=new Date(n,r,1,0,0,0)},weekly:function(){i=new Date(n,r,a-t.getDay(),0,0,0)},daily:function(){i=new Date(n,r,a,0,0,0)},hourly:function(){i=new Date(n,r,a,t.getHours(),0,0)}})[e]();return i};n.Range.getEndDate=function(t,e){var i,n=t.getFullYear(),r=t.getMonth(),a=t.getDate();({yearly:function(){i=new Date(n,11,31,23,59,59)},monthly:function(){i=new Date(new Date(n,r+1,1,0,0,0).valueOf()-1)},quarter:function(){i=new Date(new Date(n,r+1,1,0,0,0).valueOf()-1)},weekly:function(){i=new Date(n,r,a-t.getDay()+6,23,59,59)},daily:function(){i=new Date(n,r,a,23,59,59)},hourly:function(){i=new Date(n,r,a,t.getHours(),0,0)}})[e]();return new Date>i?i:new Date};n.Range.getNextDate=function(t,e,i,n){var r,a=t.getFullYear(),s=t.getMonth(),o=t.getDate();({yearly:function(t){r=new Date(a+t,0,1)},monthly:function(t){r=new Date(a,s+t,1)},quarter:function(t){r=new Date(a,s+4*t,1)},weekly:function(e){r=new Date(a,s,o+7*e-t.getDay())},daily:function(t){r=new Date(a,s,o+t)},hourly:function(e){r=new Date(a,s,o,t.getHours()+e)}})[n](i);return e>r?r:null};n.Range.getDataRange=function(t,e){var r,a,s;if(e){r=i.map(t,function(t){return n.Date.parse(t.x).valueOf()});a=Math.max.apply(null,r);s=Math.min.apply(null,r)}else{s=0;a=t.length-1}return{max:a,min:s}};n.Range.getLength=function(t,e,i){var r;({yearly:function(){r=Math.ceil(e.getFullYear()-t.getFullYear())},monthly:function(){r=Math.ceil(12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))},quarter:function(){r=Math.ceil((12*e.getFullYear()+e.getMonth()-(12*t.getFullYear()+t.getMonth()))/4)},weekly:function(){r=Math.ceil((n.Date.getWeekStartday(e)-n.Date.getWeekStartday(t))/6048e5)},daily:function(){r=Math.ceil((e-t)/864e5)},hourly:function(){r=Math.ceil((e-t)/36e5)}})[i]();return r>0?r+1:1};n.Graph=function(t,i){this.config=e.extend({type:"morris.bar",staticPath:"",data:"graph.json"},t);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=n.Range.generate(i);if("string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=e.Deferred();this.getData(e.proxy(function(t){this.graphData[this.range.unit].resolve(this.generateGraphData(t))},this));this.$graphContainer=e('
');this.$graphContainer.on("UPDATE",e.proxy(function(t,i,n){this.update_(i,n);return e(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",e.proxy(function(){this.remove_()},this));var r=e(window).width();this.updateFunc=e.proxy(function(){if(r&&r!==e(window).width()){r=e(window).width();this.update_()}},this);t.autoResize&&e(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",e.proxy(function(t,i){e.proxy(this.getData(e.proxy(function(t){i(n.Range.getDataRange(t,this.range.isTimeline))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",e.proxy(function(t,i,n){e.proxy(this.getData(e.proxy(function(t){n(this.getDataLabelByIndex(i,t))},this),this));return e(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",e.proxy(function(t,i){this.$graphContainer.appendTo(i);this.graphData[this.range.unit].done(e.proxy(function(t){var i;i=this.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.start<=t.timestamp&&t.timestamp<=this.range.end},this)):t.slice(this.range.min,this.range.max+1);this.draw_(i)},this));return e(this.$graphContainer)},this));return this.$graphContainer};n.Graph.prototype.getData=function(t){n.Data.getData(this.origData_,this.$graphContainer,t,this)};n.Graph.prototype.getDataLabelByIndex=function(t,i){var n=this.config.dataLabel||"x";return e.map(t,function(t){return i[t][n]})};n.Graph.prototype.getTotalCount_=function(t,i){var n=0,r="y"+(i||"");e.each(t,function(t,e){n+=parseInt(e[r]||e.value||0,10)});return n};n.Graph.prototype.getDelta_=function(t,e){var i,n,r,a,s=t.length;a="y"+(e||"");i=t[s-1];n=t[s-2];r=n&&i&&n[a]?i[a]-n[a]:i[a];return void 0===r?"":r};n.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};n.Graph.getChartColors=function(t,e){var i={reverse:function(t){return t.reverse()},shuffle:function(t){var e,i,n,r;n=t.length;for(e=0;n>e;e++){i=Math.floor(Math.random()*n);r=t[e];t[e]=t[i];t[i]=r}return t},def:function(t){return t}};return i[e||"def"](t||n.Graph.presetColors())};n.Graph.cachedChartColors={};n.Graph.getCachedChartColors=function(t,e,i){return n.Graph.cachedChartColors[t]=n.Graph.cachedChartColors[t]||n.Graph.getChartColors(e,i)};n.Graph.prototype.draw_=function(t){var i=this.config.type.split("."),r=i[0],a=i[1],s=this.config;if(s.label)if(this.labelTemplate)this.generateLabel(this.labelTemplate); -else if(s.label.template){var o=s.label.template;if(window.require&&"function"==typeof require){var h=s.label.type;require([h+"!"+s.staticPath+o],e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}else{var l=e.get(s.staticPath+o,"text");n.Data.getData(l,this.$graphContainer,e.proxy(function(t){this.labelTemplate=t;this.generateLabel(t)},this))}}else{this.labelTemplate='';this.generateLabel(this.labelTemplate)}if(s.fallback&&s.fallback.test&&!n.Graph.test[s.fallback.test]()){i=s.fallback.type.split(".");r=i[0];a=i[1];s=e.extend(s,s.fallback)}s.chartColors&&"string"==typeof s.chartColors&&(s.chartColors=s.chartColors.split(","));this.graphObject=n.Graph[r][a](t,s,this.range,this.$graphContainer)};n.Graph.test={};n.Graph.test.canvas=function(){var t=document.createElement("canvas");return t.getContext&&t.getContext("2d")};n.Graph.test.svg=function(){var t={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(t.svg,"svg").createSVGRect};n.Graph.test.vml=function(){var t,e=n.Graph.test.svg();if(!e){var i=document.body.appendChild(document.createElement("div"));i.innerHTML='';var r=i.firstChild;r.style.behavior="url(#default#VML)";t=r?"object"==typeof r.adj:!0;i.parentNode.removeChild(i)}return e||t};n.Graph.prototype.generateLabel=function(t){var i,r=this.config.label.template&&this.config.label.data?this.config.label.data:{},a=this.config.label.yLength||this.config.yLength,s=e.proxy(function(){this.labels=new n.Graph.Labels(this.$graphContainer,a,t);this.getData(e.proxy(function(t){for(var e=0;a>e;e++){this.config.label.hideTotalCount||this.labels.getTotalObject(e).createTotalCount(this.getTotalCount_(t,e));!this.config.label.hideDeltaCount&&this.range.isTimeline&&this.labels.getTotalObject(e).createDeltaCount(this.getDelta_(t,e))}},this))},this);if(r&&"string"==typeof r)i=e.getJSON(this.config.staticPath+r);else{i=e.Deferred();i.resolve(r)}i.done(function(e){if(t&&"function"==typeof t){t=t(e);s()}else if(window._){t=_.template(t,e);s()}else{t=t;s()}})};n.Graph.prototype.update_=function(t,i){var r=this;t=t||[];this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.range=n.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:i||this.range.unit,dataType:this.range.dataType,autoSized:this.range.autoSized});this.graphData[this.range.unit].done(e.proxy(function(t){var i;i=r.range.isTimeline?e.grep(t,e.proxy(function(t){return this.range.min<=t.timestamp&&t.timestamp<=this.range.max},this)):t.slice(this.range.min,this.range.max+1);this.draw_(i)},this))};n.Graph.prototype.remove_=function(){this.config.autoResize&&e(window).off("orientationchange debouncedresize",this.updateFunc);this.graphObject&&this.graphObject.remove&&this.graphObject.remove();this.labels&&this.labels.remove();this.$graphContainer.remove()};n.Graph.prototype.generateGraphData=function(t){var i,r,a,s,o,h,l,u=this.range,c=u.start,p=u.end,d=u.unit,f=u.length,g=[],v=this.config.yLength||1;if(this.range.isTimeline){var m=n.Range.getDataRange(t,this.range.isTimeline);c=new Date(Math.min(this.range.min,m.min));p=new Date(Math.max(this.range.max,m.max));f=n.Range.getLength(c,p,d);o=n.Data.filterData(t,m.max,m.min,d,v);for(i=0;f>i;i++){a=n.Range.getNextDate(c,p,i,d);if(!a)break;s=n.Date.createId(a,d);h={timestamp:a.valueOf(),x:n.Date.createXLabel(a,d)};for(r=0;v>r;r++){l="y"+(r||"");h[l]=o[s]?o[s][l]||0:0}g.push(h)}}else g=t;"morris.donut"===this.config.type&&e.each(g,function(t,i){e.extend(i,{label:i.xLabel||i.x,value:i.y})});return g};n.Graph.Labels=function(t,i,r){var a,s;this.$labelContainer=e('
');r&&e('
').html(r).prependTo(this.$labelContainer);this.totals={};for(a=0;i>a;a++){s="y"+(a||"");this.totals[s]=new n.Graph.Labels.Total(this.$labelContainer,a)}this.$labelContainer.appendTo(t)};n.Graph.Labels.prototype.remove=function(){this.$labelContainer.remove()};n.Graph.Labels.prototype.getTotalObject=function(t){return this.totals["y"+(t||"")]};n.Graph.Labels.Total=function(t,e){this.index=e;this.$totalContainer=i('
').appendTo(t)};n.Graph.Labels.Total.prototype.createTotalCount=function(t){i('"+t+" ").appendTo(this.$totalContainer)};n.Graph.Labels.Total.prototype.createDeltaCount=function(t){var e=t?0>t?"minus ":"plus ":"zero ";i('('+t+")").appendTo(this.$totalContainer)};n.Graph.css={};n.Graph.css.Base=function(t,i){this.len=t.length;this.$graphEl=e('
')};n.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};n.Graph.css.Base.prototype.horizontalBar=function(t,i,r,a){i.width&&this.$graphEl.css({width:i.width,"max-width":"100%",margin:"0 auto"});for(var s,o,h,l,u,c,p=i.barColor||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod)[1],d=i.barBackgroundColor||"#f0f0f0",f=i.dateColor||"#999999",g=i.dateColorSaturday||f,v=i.dateColorSunday||f,m=i.labelColor||"#999999",y=parseInt(i.barWidth,10)||30,x=parseInt(i.barMarginLeft,10)||30,_=parseInt(i.barInterval,10)||5,b=parseInt(i.labelSize,10)||.45*y,w=parseInt(i.dateLabelSize,10)||b,C=function(){return e('
')},D=e.map(t,function(t){return parseInt(t.y,10)}),T=e.map(t,function(t){return{value:""+parseInt(t.x.substr(t.x.lastIndexOf("-")+1),10),weekday:n.Date.parse(t.x)?n.Date.parse(t.x).getDay():null}}),L=Math.max.apply(null,D)||1,k=i.yLabel||D,M=this.len;M>0;){M-=1;s=Math.floor(100*(D[M]/L))-15;o=C();h=o.find(".css-graph-bar-background");h.css({"background-color":d});if(i.showDate){c=o.find(".css-graph-date");c.text(T[M].value).css({color:f,"font-size":w+"px","line-height":y+"px"});6===T[M].weekday?c.addClass("saturday").css({color:g}):0===T[M].weekday&&c.addClass("sunday").css({color:v});o.find(".css-graph-bar-container").css({"margin-left":x+"px"})}l=o.find(".css-graph-bar");l.css({width:s+"%","background-color":p});u=o.find(".css-graph-bar-count");u.text(k[M]).css({color:m,"font-size":b+"px","line-height":y+"px"});o.appendTo(this.$graphEl)}this.$graphEl.appendTo(a)};n.Graph.css.Base.prototype.ratioHorizontalBar=function(t,i,r,a){var s,o,h,l,u,c,p,d,f,g,v,m,y=i.yLength,x=parseInt(i.barWidth,10)||30,_=parseInt(i.barMarginLeft,10)||30,b=parseInt(i.barInterval,10)||5,w=parseInt(i.labelSize,10)||.45*x,C=i.dateColor||"#999999",D=i.barColors||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod),T=i.labelColors,L=i.labelClasses;for(s=0;this.len>s;s++){h=t[s];l=[];u=0;m=0;for(o=0;y>o;o++){l.push(h["y"+(o||"")]);u+=parseInt(h["y"+(o||"")],10)}c=e('
').appendTo(this.$graphEl);if(i.showDate&&h.x){f=""+parseInt(h.x.substr(h.x.lastIndexOf("-")+1),10);g=e('
'+f+"
").appendTo(c)}p=e('
').appendTo(c);i.showDate&&p.css({"margin-left":_+"px"});for(o=0;y>o;o++){v=Math.floor(1e3*(l[o]/u))/10;if(v){y===o&&(v=100-m);m+=v;d=e('
');d.css({width:v+"%","background-color":D[o]});i.showCount&&d.text(l[o]);L&&L[o]&&d.addClass(L[o]);T&&T[o]&&d.css({color:T[o]});d.appendTo(p)}}p.appendTo(c)}this.$graphEl.appendTo(a)};n.Graph.css.horizontalBar=n.Graph.css.ratioHorizontalBar=function(t,e,i,r){var a=new n.Graph.css.Base(t,e,i,r),s=e.type.slice(e.type.lastIndexOf(".")+1);a[s](t,e,i,r);return a};n.Graph.easel={};n.Graph.easel.Base=function(t,i,n,r){this.data=t;this.config=i;this.range=n;this.$container=r;if(window.createjs||"function"!=typeof window.require){var a=parseInt(i.width||r.width(),10);a?this.buildCanvas(createjs):setTimeout(e.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],e.proxy(function(){this.buildCanvas(createjs)},this))};n.Graph.easel.Base.prototype.buildCanvas=function(t){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=e('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new t.Stage(this.canvas);this.stage.update();var i=this.config.type.split(".")[1];this[i](this.data,this.config)};n.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};n.Graph.easel.Base.prototype.bar=function(t,i){for(var r,a,s,o,h,l=t.length,u=i.chartColorsAlpha?i.chartColorsAlpha[0]:1,c=i.chartColors||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod),p=this.convertColor(c[0],u),d=parseInt(i.barMargin,10)||10,f=Math.floor(this.width/l),g=f-d,v=Math.floor((this.width-f*l)/2)+d/2,m=e.map(t,function(t){return parseInt(t.y,10)}),y=Math.max.apply(null,m)||1,x=0;l>x;x++){r=new createjs.Shape;a=r.graphics;s=x*f+v;h=Math.floor(m[x]/y*this.height);o=this.height-h;a.beginFill(p).drawRect(s,o,g,h);this.stage.addChild(r)}this.stage.update()};n.Graph.easel.Base.prototype.motionLine=function(t,i){var r,a,s=t.length,o=parseInt(i.lineWidth,10)||8,h=i.yLength||1,l=i.lineColors||i.chartColors||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod),u=i.chartColorsAlpha||[null],c=i.pointerColors||i.chartColors||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod),p=i.pointerColorsAlpha||[null],d=i.pointerRadius||10,f=o/2,g=o/2,v=2*(s-1),m=Math.floor(this.width/s)/2,y=(this.width-m*v)/2,x=this.height,_=[],b=function(t){return parseInt(t["y"+(w||"")],10)};i.drawPointer&&(g+=d);r=this.height-(f+g);for(var w=0;h>w;w++){a=e.map(t,b);_.push(a)}var C=[];e.each(_,function(t,e){C=C.concat(e)});var D=Math.max.apply(null,C)||1,T=[],L=function(t){var i=[];e.each(t,function(e,n){if(e>0){var a=t[e-1],s=a+Math.floor((n-a)/2);s=Math.floor(s/D*r)+g;n=Math.floor(n/D*r)+g;i=i.concat([s,n])}else{n=Math.floor(n/D*r)+g;i.push(n)}});return i};e.each(_,function(t,e){T.push(L(e))});var k,M,E,S=[],I=[],A=y,P=[];for(w=0;h>w;w++){k=this.convertColor(l[w],u[w]);S[w]=new createjs.Shape;I[w]=S[w].graphics;M=x-T[w][0];I[w].setStrokeStyle(o).beginStroke(k).moveTo(A,M);this.stage.addChild(S[w]);if(i.drawPointer){E=this.convertColor(c[w],p[w]);P[w]=new createjs.Shape;P[w].graphics.beginFill(E).drawCircle(0,0,d);this.stage.addChild(P[w])}}var B=this.stage,F=function(t){v-=1;0===v&&createjs.Ticker.removeEventListener("tick",F);A+=m;for(var e,n=0;h>n;n++){e=T[n];M=x-e[e.length-v-1];I[n].lineTo(A,M);if(i.drawPointer){P[n].x=A;P[n].y=Math.max(M,d)}}B.update(t)};createjs.Ticker.useRAF=!0;createjs.Ticker.setFPS(30);createjs.Ticker.addEventListener("tick",F)};n.Graph.easel.Base.prototype.convertColor=function(t,e){if(-1!==t.indexOf("#")){var i=parseInt(t.substr(1,2),16),n=parseInt(t.substr(3,2),16),r=parseInt(t.substr(5,2),16);t=e?"rgba("+[i,n,r,e].join(",")+")":"rgb("+[i,n,r].join(",")+")"}else-1!==t.indexOf("rgb")&&(t=4>t.split(",").length?"rgb("+t+")":"rgba("+t+")");return t};n.Graph.easel.Base.prototype.mix=function(t,i){var r=0,a=function(t,i){t=t||1;var n=e.map(i,function(e){for(var i,n,a={x:e.x},s=0;t>s;s++){i="y"+(s||"");n="y"+(r+s||"");a[i]=e[n]}return a});r+=t;return n},s=i.chartColors||n.Graph.getCachedChartColors(i.id,null,i.chartColorsMethod);e.each(i.mix,e.proxy(function(n,o){var h={chartColors:s.slice(r,r+o.yLength)},l=a(o.yLength,t);o=e.extend({},i,h,o);this[o.type](l,o)},this))};n.Graph.easel.bar=n.Graph.easel.motionLine=n.Graph.easel.mix=function(t,e,i,r){if(n.Graph.test.canvas()){var a=new n.Graph.easel.Base(t,e,i,r);return a}console.warn("EaselJS graph requires for HTML5 Canvas capability");r.trigger("REMOVE")};n.Graph.morris={};n.Graph.morris.Base=function(t,i,n,r){if(window.Morris||"function"!=typeof window.require){var a=i.width||r.width();a?this.build_(Morris,t,i,n,r):setTimeout(e.proxy(function(){this.build_(Morris,t,i,n,r)},this),100)}else require(["raphael","morris"],e.proxy(function(){this.build_(Morris,t,i,n,r)},this))};n.Graph.morris.Base.prototype.build_=function(t,i,r,a,s){var o,h,l,u=r.type.split(".")[1],c=r.yLength,p=r.width||s.width()||300,d=r.height||s.height()||300;this.$graphEl=e('
').css({height:d+"px",width:p+"px"}).prependTo(s);r=e.extend({},r,{element:r.id,data:i,xkey:"x",labels:this.getYLabels_(c,r.labels),ykeys:this.getYKeys_(c),ymax:this.getYMax_(i,u,c),ymin:r.ymin||0,lineWidth:parseInt(r.lineWidth,10)||6,pointSize:parseInt(r.pointSize,10)||6,smooth:r.smooth||!1});r.barColors=r.barColors||this.getChartColors(r);r.colors=r.colors||this.getChartColors(r);r.lineColors=r.lineColors||this.getChartColors(r);r.numLines=parseInt(r.numLines,10)||this.getNumLines_(r.ymax,d);r.pointStrokeColors=r.pointStrokeColors?r.pointStrokeColors.split(/,/):[];if(!r.pointStrokeColors.length)for(o=0;c>o;o++)r.pointStrokeColors.push("none");h={element:null,data:null,xkey:"x",labels:[],ykeys:[],dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,hideHover:!1,hoverCallback:null,yLabelFormat:null,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"],lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:50,continuousLine:!0,barSizeRatio:.75,barGap:3,barColors:["#0b62a4","#7a92a3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],colors:["#0B62A4","#3980B5","#679DC6","#95BBD7","#B0CCE1","#095791","#095085","#083E67","#052C48","#042135"],backgroundColor:"#FFFFFF",labelColor:"#000000",formatter:t.commas};l={};e.each(r,function(t,e){void 0!==h[t]&&(l[t]=e)});n.Graph.test.svg||(l.smooth=!0);if("donut"===u){var f=this.getTotalCount_(i,o);l.formatter=function(t){var e=t=(t+"").replace(/,/g,"");if(!r.noCommaOnYLabel)for(;e!=(e=e.replace(/^(-?\d+)(\d{3})/,"$1,$2")););var i,n=Math.ceil(1e4*(t/f))/100;i=r.donutsFormatter&&"function"==typeof r.donutsFormatter?r.donutsFormatter(e,n+"%",t):e+"("+n+"%)";return i}}var g={bar:t.Bar,line:t.Line,donut:t.Donut,area:t.Area}[u];this.graph=new g(l)};n.Graph.morris.Base.prototype.getYMax_=function(t,i,n){var r,a,s,o,h;if("area"!==i){s=[];e.each(t,function(t,e){for(r=0;n>r;r++){h="y"+(r||"");s.push(parseInt(e[h],10))}});a=Math.max.apply(null,s)}else a=Math.max.apply(null,e.map(t,function(t){o=0;for(r=0;n>r;r++){h="y"+(r||"");o+=parseInt(t[h],10)}return o}));a||(a=1);0!==a%2&&(a+=1);return a};n.Graph.morris.Base.prototype.getChartColors=function(t){this.chartColors||(this.chartColors=t.chartColors||n.Graph.getCachedChartColors(t.id,null,t.chartColorsMethod));return this.chartColors};n.Graph.morris.Base.prototype.getYKeys_=function(t){var e,i=[];for(e=0;t>e;e++)i.push("y"+(e||""));return i};n.Graph.morris.Base.prototype.getYLabels_=function(t,e){var i,n=[];e=e?e.split(/,/):[];for(i=0;t>i;i++)n.push(e[i]||"Count");return n};n.Graph.morris.Base.prototype.getNumLines_=function(t,e){var i;i=t>=18?9:2===t?3:t/2+1;i=Math.min(i||1,Math.floor(e/56));return i};n.Graph.morris.Base.prototype.getTotalCount_=function(t,i){var n,r=0,a="y"+(i||"");e.each(t,function(t,e){n=e[a]||e.value||0;"string"==typeof n&&(n=parseFloat(n.replace(/,/g,""),10));r+=n});return r};n.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};n.Graph.morris.bar=n.Graph.morris.line=n.Graph.morris.donut=n.Graph.morris.area=function(t,e,i,r){if(n.Graph.test.vml()){var a=new n.Graph.morris.Base(t,e,i,r);return a}console.warn("Morris graph requires for SVG/VML capability");r.trigger("REMOVE")};n.Slider=function(t,i,r,a,s){if(!e.ui||!e.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var o=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.range=n.Range.generate(i);this.$dataRangeTarget=r;this.$sliderContainer=e('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};e.each(a,function(t,e){o.eventTargetList.update.add(e)});e.each(s,function(t,e){o.eventTargetList.amount.add(e)});this.$sliderContainer.on("APPEND_TO",function(t,i){o.$container=i;o.draw_(i);return e(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){o.$dataRangeTarget.trigger("GET_DATA_RANGE",function(t){o.buildSlider(t.min,t.max)});return e(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(t,i){o.$dataRangeTarget=i;return e(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(t,i,n){n=e.isArray(n)?n:[n];e.each(n,function(t,e){o.eventTargetList[i].add(e)});return e(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(t,i,n){n=e.isArray(n)?n:[n];e.each(n,function(t,e){o.eventTargetList[i].remove(e)});return e(this)});this.$sliderContainer.on("ERASE",function(){o.erase_();return e(this)});this.$sliderContainer.on("REDRAW",function(){var t=e(this);t.trigger("BUILD_SLIDER").trigger("APPEND_TO",[o.$container]);return e(this)});this.$sliderContainer.on("UPDATE",function(t,i){o.$slider("values",i);o.updateSliderAmount(i);return e(this)});return this.$sliderContainer};n.Slider.prototype.initEventTarget=function(){var t=[];return{add:function(e){t.push(e)},remove:function(i){t=e.grep(t,function(t){return t!==i})},get:function(){return t}}};n.Slider.prototype.buildSlider=function(t,i,n){var r=this;n=n||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}this.$slider=e('
').slider({range:!0,min:t,max:i,values:n,slide:function(t,e){r.updateSliderAmount(e.values,e)},stop:function(t,e){r.updateGraphAndList(e.values)}}).appendTo(r.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=e('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(n)}};n.Slider.prototype.draw_=function(t){this.$sliderContainer.appendTo(t)};n.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};n.Slider.prototype.updateSliderAmount=function(t,i){var r,a,s,o,h=this.range.maxLength,l=this.$amount;if(this.range.isTimeline){r=n.Date.parse(t[0]);a=n.Date.parse(t[1]);s=this.range.unit;o=n.Range.getLength(r,a,s);if(i&&o>h)if(i.value===i.values[0]){a=n.Date.calcDate(r,h,s,!1);this.$slider.slider("values",1,a.valueOf())}else{r=n.Date.calcDate(a,h,s,!0);this.$slider.slider("values",0,r.valueOf())}l&&l.text([n.Date.createXLabel(r,s),n.Date.createXLabel(a,s)].join(" - "))}else{r=t[0];a=t[1];if(a-r>h)if(i.value===i.values[0]){a=h-r;this.$slider.slider("values",1,a)}else{r=a-h;this.$slider.slider("values",0,r)}l&&e.each(this.eventTargetList.amount.get(),function(t,e){e.trigger("GET_LABEL",[[r,a],function(t){l.text([t[0],t[1]].join(" - "))}])})}};n.Slider.prototype.updateGraphAndList=function(t,i){e.each(this.eventTargetList.update.get(),function(e,n){n.trigger("UPDATE",[t,i])})};n.Slider.prototype.update_=function(t,e){this.$slider.slider("values",t,e)};n.List=function(t,i){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=t;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=e.getJSON(this.config.staticPath+this.config.data);else{this.origData_=e.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var r=this.config.type||"text";this.template_=e.Deferred();require([r+"!"+this.config.staticPath+this.config.template],e.proxy(function(t){this.template_.resolve(t)},this))}else this.template_=e.get(this.config.staticPath+this.config.template,"text");this.range=n.Range.generate(i);this.$listContainer=e('
');this.$listContainer.on("UPDATE",e.proxy(function(t,e){this.update_(e)},this));this.$listContainer.on("GET_DATA_RANGE",e.proxy(function(t,i){this.getData(e.proxy(function(t){i(n.Range.getDataRange(t,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",e.proxy(function(t,i,n){this.getData(e.proxy(function(t){n(this.getDataLabelByIndex(i,t))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",e.proxy(function(t,i){this.$listContainer.appendTo(i);this.getData(e.proxy(function(t){this.draw_(t)},this));return this.$listContainer},this));return this.$listContainer}};n.List.prototype.getData=function(t){this.config.data?n.Data.getData(this.origData_,this.$listContainer,t,this):t()};n.List.prototype.getTemplate=function(t){n.Data.getData(this.template_,this.$listContainer,t,this)};n.List.prototype.draw_=function(t){var e=this;this.getTemplate(function(i){t=e.createListData(t);e.$listContainer.html(_.template(i,t))})};n.List.prototype.getDataLabelByIndex=function(t,i){var n=this.config.dataLabel||"x";return e.map(t,function(t){return i[t][n]})};n.List.prototype.createListData=function(t){var e="";t&&(e=this.range.isTimeline?n.Data.filterData(t,this.range.max,this.range.min,this.range.unit,1,!0):t.slice(this.range.min,this.range.max+1));return{data:e}};n.List.prototype.update_=function(t,e){var i=this;t=t||[];e=e||this.range.unit;this.range=n.Range.generate({start:t[0]||this.range.start,end:t[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:e,dataType:this.range.dataType});this.getData(function(t){i.draw_(t)})};n.Build=function(t){var i;if("string"==typeof t&&/\.json$/.test(t)){i=e('
');n.Data.getData(e.getJSON(t),null,function(t){t.$container=i;n.Build_(t).trigger("APPEND")})}else i=n.Build_(t).trigger("APPEND");return i};n.Build_=function(t){var i,r,a,s,o,h,l;i=t.$container||e('
');h=[];if(t.graph){r=new n.Graph(t.graph,t.range);h.push(r)}if(t.list){s=new n.List(t.list,t.range);t.list.data&&h.push(s)}if(t.graph&&"donut"!==t.graph.type){o=r;l=[r]}else{o=s;l=[s]}var u=function(){var t=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(t)};!t.slider||!t.slider.force&&u()||(a=new n.Slider(t.slider,t.range,o,h,l));i.on("APPEND",function(){r&&r.trigger("APPEND_TO",[i]);a&&a.trigger("BUILD_SLIDER").trigger("APPEND_TO",[i]);s&&s.trigger("APPEND_TO",[i])});i.on("GET_CONTAINER",function(t,e,i){i({graph:r,slider:a,list:s}[e])});return i};return n}(this,jQuery); \ No newline at end of file +!function(a){var b,c,d=a.event;b=d.special.debouncedresize={setup:function(){a(this).on("resize",b.handler)},teardown:function(){a(this).off("resize",b.handler)},handler:function(a,e){var f=this,g=arguments,h=function(){a.type="debouncedresize";d.dispatch.apply(f,g)};c&&clearTimeout(c);e?h():c=setTimeout(h,b.threshold)},threshold:150}}(jQuery);(function(a){var b,c,d="0.4.2",e="hasOwnProperty",f=/[\.\/]/,g=function(){},h=function(a,b){return a-b},i={n:{}},j=function(a,d){a+="";var e,f=c,g=Array.prototype.slice.call(arguments,2),i=j.listeners(a),k=0,l=[],m={},n=[],o=b;b=a,c=0;for(var p=0,q=i.length;q>p;p++)"zIndex"in i[p]&&(l.push(i[p].zIndex),0>i[p].zIndex&&(m[i[p].zIndex]=i[p]));for(l.sort(h);0>l[k];)if(e=m[l[k++]],n.push(e.apply(d,g)),c)return c=f,n;for(p=0;q>p;p++)if(e=i[p],"zIndex"in e)if(e.zIndex==l[k]){if(n.push(e.apply(d,g)),c)break;do if(k++,e=m[l[k]],e&&n.push(e.apply(d,g)),c)break;while(e)}else m[e.zIndex]=e;else if(n.push(e.apply(d,g)),c)break;return c=f,b=o,n.length?n:null};j._events=i,j.listeners=function(a){var b,c,d,e,g,h,j,k,l=a.split(f),m=i,n=[m],o=[];for(e=0,g=l.length;g>e;e++){for(k=[],h=0,j=n.length;j>h;h++)for(m=n[h].n,c=[m[l[e]],m["*"]],d=2;d--;)b=c[d],b&&(k.push(b),o=o.concat(b.f||[]));n=k}return o},j.on=function(a,b){if(a+="","function"!=typeof b)return function(){};for(var c=a.split(f),d=i,e=0,h=c.length;h>e;e++)d=d.n,d=d.hasOwnProperty(c[e])&&d[c[e]]||(d[c[e]]={n:{}});for(d.f=d.f||[],e=0,h=d.f.length;h>e;e++)if(d.f[e]==b)return g;return d.f.push(b),function(a){+a==+a&&(b.zIndex=+a)}},j.f=function(a){var b=[].slice.call(arguments,1);return function(){j.apply(null,[a,null].concat(b).concat([].slice.call(arguments,0)))}},j.stop=function(){c=1},j.nt=function(a){return a?RegExp("(?:\\.|\\/|^)"+a+"(?:\\.|\\/|$)").test(b):b},j.nts=function(){return b.split(f)},j.off=j.unbind=function(a,b){if(!a)return void(j._events=i={n:{}});var c,d,g,h,k,l,m,n=a.split(f),o=[i];for(h=0,k=n.length;k>h;h++)for(l=0;o.length>l;l+=g.length-2){if(g=[l,1],c=o[l].n,"*"!=n[h])c[n[h]]&&g.push(c[n[h]]);else for(d in c)c[e](d)&&g.push(c[d]);o.splice.apply(o,g)}for(h=0,k=o.length;k>h;h++)for(c=o[h];c.n;){if(b){if(c.f){for(l=0,m=c.f.length;m>l;l++)if(c.f[l]==b){c.f.splice(l,1);break}!c.f.length&&delete c.f}for(d in c.n)if(c.n[e](d)&&c.n[d].f){var p=c.n[d].f;for(l=0,m=p.length;m>l;l++)if(p[l]==b){p.splice(l,1);break}!p.length&&delete c.n[d].f}}else{delete c.f;for(d in c.n)c.n[e](d)&&c.n[d].f&&delete c.n[d].f}c=c.n}},j.once=function(a,b){var c=function(){return j.unbind(a,c),b.apply(this,arguments)};return j.on(a,c)},j.version=d,j.toString=function(){return"You are running Eve "+d},"undefined"!=typeof module&&module.exports?module.exports=j:"undefined"!=typeof define?define("eve",[],function(){return j}):a.eve=j})(this),function(a,b){"function"==typeof define&&define.amd?define(["eve"],function(c){return b(a,c)}):b(a,a.eve)}(this,function(a,b){function c(a){if(c.is(a,"function"))return u?a():b.on("raphael.DOMload",a);if(c.is(a,U))return c._engine.create[C](c,a.splice(0,3+c.is(a[0],S))).add(a);var d=Array.prototype.slice.call(arguments,0);if(c.is(d[d.length-1],"function")){var e=d.pop();return u?e.call(c._engine.create[C](c,d)):b.on("raphael.DOMload",function(){e.call(c._engine.create[C](c,d))})}return c._engine.create[C](c,arguments)}function d(a){if(Object(a)!==a)return a;var b=new a.constructor;for(var c in a)a[y](c)&&(b[c]=d(a[c]));return b}function e(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return a.push(a.splice(c,1)[0])}function f(a,b,c){function d(){var f=Array.prototype.slice.call(arguments,0),g=f.join("␀"),h=d.cache=d.cache||{},i=d.count=d.count||[];return h[y](g)?(e(i,g),c?c(h[g]):h[g]):(i.length>=1e3&&delete h[i.shift()],i.push(g),h[g]=a[C](b,f),c?c(h[g]):h[g])}return d}function g(){return this.hex}function h(a,b){for(var c=[],d=0,e=a.length;e-2*!b>d;d+=2){var f=[{x:+a[d-2],y:+a[d-1]},{x:+a[d],y:+a[d+1]},{x:+a[d+2],y:+a[d+3]},{x:+a[d+4],y:+a[d+5]}];b?d?e-4==d?f[3]={x:+a[0],y:+a[1]}:e-2==d&&(f[2]={x:+a[0],y:+a[1]},f[3]={x:+a[2],y:+a[3]}):f[0]={x:+a[e-2],y:+a[e-1]}:e-4==d?f[3]=f[2]:d||(f[0]={x:+a[d],y:+a[d+1]}),c.push(["C",(-f[0].x+6*f[1].x+f[2].x)/6,(-f[0].y+6*f[1].y+f[2].y)/6,(f[1].x+6*f[2].x-f[3].x)/6,(f[1].y+6*f[2].y-f[3].y)/6,f[2].x,f[2].y])}return c}function i(a,b,c,d,e){return a*(a*(-3*b+9*c-9*d+3*e)+6*b-12*c+6*d)-3*b+3*c}function j(a,b,c,d,e,f,g,h,j){null==j&&(j=1),j=j>1?1:0>j?0:j;for(var k=j/2,l=[-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816],m=[.2491,.2491,.2335,.2335,.2032,.2032,.1601,.1601,.1069,.1069,.0472,.0472],n=0,o=0;12>o;o++){var p=k*l[o]+k,q=i(p,a,c,e,g),r=i(p,b,d,f,h),s=q*q+r*r;n+=m[o]*M.sqrt(s)}return k*n}function k(a,b,c,d,e,f,g,h,i){if(!(0>i||i>j(a,b,c,d,e,f,g,h))){var k,l=.5,m=1-l;for(k=j(a,b,c,d,e,f,g,h,m);P(k-i)>.01;)l/=2,m+=(i>k?1:-1)*l,k=j(a,b,c,d,e,f,g,h,m);return m}}function l(a,b,c,d,e,f,g,h){if(!(N(a,c)N(e,g)||N(b,d)N(f,h))){var i=(a*d-b*c)*(e-g)-(a-c)*(e*h-f*g),j=(a*d-b*c)*(f-h)-(b-d)*(e*h-f*g),k=(a-c)*(f-h)-(b-d)*(e-g);if(k){var l=i/k,m=j/k,n=+l.toFixed(2),o=+m.toFixed(2);if(!(+O(a,c).toFixed(2)>n||n>+N(a,c).toFixed(2)||+O(e,g).toFixed(2)>n||n>+N(e,g).toFixed(2)||+O(b,d).toFixed(2)>o||o>+N(b,d).toFixed(2)||+O(f,h).toFixed(2)>o||o>+N(f,h).toFixed(2)))return{x:l,y:m}}}}function m(a,b,d){var e=c.bezierBBox(a),f=c.bezierBBox(b);if(!c.isBBoxIntersect(e,f))return d?0:[];for(var g=j.apply(0,a),h=j.apply(0,b),i=~~(g/5),k=~~(h/5),m=[],n=[],o={},p=d?0:[],q=0;i+1>q;q++){var r=c.findDotsAtSegment.apply(c,a.concat(q/i));m.push({x:r.x,y:r.y,t:q/i})}for(q=0;k+1>q;q++)r=c.findDotsAtSegment.apply(c,b.concat(q/k)),n.push({x:r.x,y:r.y,t:q/k});for(q=0;i>q;q++)for(var s=0;k>s;s++){var t=m[q],u=m[q+1],v=n[s],w=n[s+1],x=.001>P(u.x-t.x)?"y":"x",y=.001>P(w.x-v.x)?"y":"x",z=l(t.x,t.y,u.x,u.y,v.x,v.y,w.x,w.y);if(z){if(o[z.x.toFixed(4)]==z.y.toFixed(4))continue;o[z.x.toFixed(4)]=z.y.toFixed(4);var A=t.t+P((z[x]-t[x])/(u[x]-t[x]))*(u.t-t.t),B=v.t+P((z[y]-v[y])/(w[y]-v[y]))*(w.t-v.t);A>=0&&1>=A&&B>=0&&1>=B&&(d?p++:p.push({x:z.x,y:z.y,t1:A,t2:B}))}}return p}function n(a,b,d){a=c._path2curve(a),b=c._path2curve(b);for(var e,f,g,h,i,j,k,l,n,o,p=d?0:[],q=0,r=a.length;r>q;q++){var s=a[q];if("M"==s[0])e=i=s[1],f=j=s[2];else{"C"==s[0]?(n=[e,f].concat(s.slice(1)),e=n[6],f=n[7]):(n=[e,f,e,f,i,j,i,j],e=i,f=j);for(var t=0,u=b.length;u>t;t++){var v=b[t];if("M"==v[0])g=k=v[1],h=l=v[2];else{"C"==v[0]?(o=[g,h].concat(v.slice(1)),g=o[6],h=o[7]):(o=[g,h,g,h,k,l,k,l],g=k,h=l);var w=m(n,o,d);if(d)p+=w;else{for(var x=0,y=w.length;y>x;x++)w[x].segment1=q,w[x].segment2=t,w[x].bez1=n,w[x].bez2=o;p=p.concat(w)}}}}}return p}function o(a,b,c,d,e,f){null!=a?(this.a=+a,this.b=+b,this.c=+c,this.d=+d,this.e=+e,this.f=+f):(this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0)}function p(){return this.x+G+this.y+G+this.width+" × "+this.height}function q(a,b,c,d,e,f){function g(a){return((l*a+k)*a+j)*a}function h(a,b){var c=i(a,b);return((o*c+n)*c+m)*c}function i(a,b){var c,d,e,f,h,i;for(e=a,i=0;8>i;i++){if(f=g(e)-a,b>P(f))return e;if(h=(3*l*e+2*k)*e+j,1e-6>P(h))break;e-=f/h}if(c=0,d=1,e=a,c>e)return c;if(e>d)return d;for(;d>c;){if(f=g(e),b>P(f-a))return e;a>f?c=e:d=e,e=(d-c)/2+c}return e}var j=3*b,k=3*(d-b)-j,l=1-j-k,m=3*c,n=3*(e-c)-m,o=1-m-n;return h(a,1/(200*f))}function r(a,b){var c=[],d={};if(this.ms=b,this.times=1,a){for(var e in a)a[y](e)&&(d[$(e)]=a[e],c.push($(e)));c.sort(ha)}this.anim=d,this.top=c[c.length-1],this.percents=c}function s(a,d,e,f,g,h){e=$(e);var i,j,k,l,m,n,p=a.ms,r={},s={},t={};if(f)for(v=0,x=db.length;x>v;v++){var u=db[v];if(u.el.id==d.id&&u.anim==a){u.percent!=e?(db.splice(v,1),k=1):j=u,d.attr(u.totalOrigin);break}}else f=+s;for(var v=0,x=a.percents.length;x>v;v++){if(a.percents[v]==e||a.percents[v]>f*a.top){e=a.percents[v],m=a.percents[v-1]||0,p=p/a.top*(e-m),l=a.percents[v+1],i=a.anim[e];break}f&&d.attr(a.anim[a.percents[v]])}if(i){if(j)j.initstatus=f,j.start=new Date-j.ms*f;else{for(var z in i)if(i[y](z)&&(ca[y](z)||d.paper.customAttributes[y](z)))switch(r[z]=d.attr(z),null==r[z]&&(r[z]=ba[z]),s[z]=i[z],ca[z]){case S:t[z]=(s[z]-r[z])/p;break;case"colour":r[z]=c.getRGB(r[z]);var A=c.getRGB(s[z]);t[z]={r:(A.r-r[z].r)/p,g:(A.g-r[z].g)/p,b:(A.b-r[z].b)/p};break;case"path":var B=Ga(r[z],s[z]),C=B[1];for(r[z]=B[0],t[z]=[],v=0,x=r[z].length;x>v;v++){t[z][v]=[0];for(var E=1,F=r[z][v].length;F>E;E++)t[z][v][E]=(C[v][E]-r[z][v][E])/p}break;case"transform":var G=d._,J=La(G[z],s[z]);if(J)for(r[z]=J.from,s[z]=J.to,t[z]=[],t[z].real=!0,v=0,x=r[z].length;x>v;v++)for(t[z][v]=[r[z][v][0]],E=1,F=r[z][v].length;F>E;E++)t[z][v][E]=(s[z][v][E]-r[z][v][E])/p;else{var K=d.matrix||new o,L={_:{transform:G.transform},getBBox:function(){return d.getBBox(1)}};r[z]=[K.a,K.b,K.c,K.d,K.e,K.f],Ja(L,s[z]),s[z]=L._.transform,t[z]=[(L.matrix.a-K.a)/p,(L.matrix.b-K.b)/p,(L.matrix.c-K.c)/p,(L.matrix.d-K.d)/p,(L.matrix.e-K.e)/p,(L.matrix.f-K.f)/p]}break;case"csv":var M=H(i[z])[I](w),N=H(r[z])[I](w);if("clip-rect"==z)for(r[z]=N,t[z]=[],v=N.length;v--;)t[z][v]=(M[v]-r[z][v])/p;s[z]=M;break;default:for(M=[][D](i[z]),N=[][D](r[z]),t[z]=[],v=d.paper.customAttributes[z].length;v--;)t[z][v]=((M[v]||0)-(N[v]||0))/p}var O=i.easing,P=c.easing_formulas[O];if(!P)if(P=H(O).match(Y),P&&5==P.length){var Q=P;P=function(a){return q(a,+Q[1],+Q[2],+Q[3],+Q[4],p)}}else P=ja;if(n=i.start||a.start||+new Date,u={anim:a,percent:e,timestamp:n,start:n+(a.del||0),status:0,initstatus:f||0,stop:!1,ms:p,easing:P,from:r,diff:t,to:s,el:d,callback:i.callback,prev:m,next:l,repeat:h||a.times,origin:d.attr(),totalOrigin:g},db.push(u),f&&!j&&!k&&(u.stop=!0,u.start=new Date-p*f,1==db.length))return fb();k&&(u.start=new Date-u.ms*f),1==db.length&&eb(fb)}b("raphael.anim.start."+d.id,d,a)}}function t(a){for(var b=0;db.length>b;b++)db[b].el.paper==a&&db.splice(b--,1)}c.version="2.1.0",c.eve=b;var u,v,w=/[, ]+/,x={circle:1,rect:1,path:1,ellipse:1,text:1,image:1},y="hasOwnProperty",z={doc:document,win:a},A={was:Object.prototype[y].call(z.win,"Raphael"),is:z.win.Raphael},B=function(){this.ca=this.customAttributes={}},C="apply",D="concat",E="ontouchstart"in z.win||z.win.DocumentTouch&&z.doc instanceof DocumentTouch,F="",G=" ",H=String,I="split",J="click dblclick mousedown mousemove mouseout mouseover mouseup touchstart touchmove touchend touchcancel"[I](G),K={mousedown:"touchstart",mousemove:"touchmove",mouseup:"touchend"},L=H.prototype.toLowerCase,M=Math,N=M.max,O=M.min,P=M.abs,Q=M.pow,R=M.PI,S="number",T="string",U="array",V=Object.prototype.toString,W=(c._ISURL=/^url\(['"]?([^\)]+?)['"]?\)$/i,/^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?)%?\s*\))\s*$/i),X={NaN:1,Infinity:1,"-Infinity":1},Y=/^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,Z=M.round,$=parseFloat,_=parseInt,aa=H.prototype.toUpperCase,ba=c._availableAttrs={"arrow-end":"none","arrow-start":"none",blur:0,"clip-rect":"0 0 1e9 1e9",cursor:"default",cx:0,cy:0,fill:"#fff","fill-opacity":1,font:'10px "Arial"',"font-family":'"Arial"',"font-size":"10","font-style":"normal","font-weight":400,gradient:0,height:0,href:"http://raphaeljs.com/","letter-spacing":0,opacity:1,path:"M0,0",r:0,rx:0,ry:0,src:"",stroke:"#000","stroke-dasharray":"","stroke-linecap":"butt","stroke-linejoin":"butt","stroke-miterlimit":0,"stroke-opacity":1,"stroke-width":1,target:"_blank","text-anchor":"middle",title:"Raphael",transform:"",width:0,x:0,y:0},ca=c._availableAnimAttrs={blur:S,"clip-rect":"csv",cx:S,cy:S,fill:"colour","fill-opacity":S,"font-size":S,height:S,opacity:S,path:"path",r:S,rx:S,ry:S,stroke:"colour","stroke-opacity":S,"stroke-width":S,transform:"transform",width:S,x:S,y:S},da=/[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/,ea={hs:1,rg:1},fa=/(-?\d*\.?\d*(?:e[\-+]?\d+)?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*/gi,ga=(c._radial_gradient=/^r(?:\(([^,]+?)[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*([^\)]+?)\))?/,{}),ha=function(a,b){return $(a)-$(b)},ia=function(){},ja=function(a){return a},ka=c._rectPath=function(a,b,c,d,e){return e?[["M",a+e,b],["l",c-2*e,0],["a",e,e,0,0,1,e,e],["l",0,d-2*e],["a",e,e,0,0,1,-e,e],["l",2*e-c,0],["a",e,e,0,0,1,-e,-e],["l",0,2*e-d],["a",e,e,0,0,1,e,-e],["z"]]:[["M",a,b],["l",c,0],["l",0,d],["l",-c,0],["z"]]},la=function(a,b,c,d){return null==d&&(d=c),[["M",a,b],["m",0,-d],["a",c,d,0,1,1,0,2*d],["a",c,d,0,1,1,0,-2*d],["z"]]},ma=c._getPath={path:function(a){return a.attr("path")},circle:function(a){var b=a.attrs;return la(b.cx,b.cy,b.r)},ellipse:function(a){var b=a.attrs;return la(b.cx,b.cy,b.rx,b.ry)},rect:function(a){var b=a.attrs;return ka(b.x,b.y,b.width,b.height,b.r)},image:function(a){var b=a.attrs;return ka(b.x,b.y,b.width,b.height)},text:function(a){var b=a._getBBox();return ka(b.x,b.y,b.width,b.height)},set:function(a){var b=a._getBBox();return ka(b.x,b.y,b.width,b.height)}},na=c.mapPath=function(a,b){if(!b)return a;var c,d,e,f,g,h,i;for(a=Ga(a),e=0,g=a.length;g>e;e++)for(i=a[e],f=1,h=i.length;h>f;f+=2)c=b.x(i[f],i[f+1]),d=b.y(i[f],i[f+1]),i[f]=c,i[f+1]=d;return a};if(c._g=z,c.type=z.win.SVGAngle||z.doc.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1")?"SVG":"VML","VML"==c.type){var oa,pa=z.doc.createElement("div");if(pa.innerHTML='',oa=pa.firstChild,oa.style.behavior="url(#default#VML)",!oa||"object"!=typeof oa.adj)return c.type=F;pa=null}c.svg=!(c.vml="VML"==c.type),c._Paper=B,c.fn=v=B.prototype=c.prototype,c._id=0,c._oid=0,c.is=function(a,b){return b=L.call(b),"finite"==b?!X[y](+a):"array"==b?a instanceof Array:"null"==b&&null===a||b==typeof a&&null!==a||"object"==b&&a===Object(a)||"array"==b&&Array.isArray&&Array.isArray(a)||V.call(a).slice(8,-1).toLowerCase()==b},c.angle=function(a,b,d,e,f,g){if(null==f){var h=a-d,i=b-e;return h||i?(180+180*M.atan2(-i,-h)/R+360)%360:0}return c.angle(a,b,f,g)-c.angle(d,e,f,g)},c.rad=function(a){return a%360*R/180},c.deg=function(a){return 180*a/R%360},c.snapTo=function(a,b,d){if(d=c.is(d,"finite")?d:10,c.is(a,U)){for(var e=a.length;e--;)if(d>=P(a[e]-b))return a[e]}else{a=+a;var f=b%a;if(d>f)return b-f;if(f>a-d)return b-f+a}return b},c.createUUID=function(a,b){return function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,b).toUpperCase()}}(/[xy]/g,function(a){var b=0|16*M.random();return("x"==a?b:8|3&b).toString(16)}),c.setWindow=function(a){b("raphael.setWindow",c,z.win,a),z.win=a,z.doc=z.win.document,c._engine.initWin&&c._engine.initWin(z.win)};var qa=function(a){if(c.vml){var b;try{var d=new ActiveXObject("htmlfile");d.write(""),d.close(),b=d.body}catch(a){b=createPopup().document.body}var e=b.createTextRange();qa=f(function(a){try{b.style.color=H(a).replace(/^\s+|\s+$/g,F);var c=e.queryCommandValue("ForeColor");return c=(255&c)<<16|65280&c|(16711680&c)>>>16,"#"+("000000"+c.toString(16)).slice(-6)}catch(a){return"none"}})}else{var g=z.doc.createElement("i");g.title="Raphaël Colour Picker",g.style.display="none",z.doc.body.appendChild(g),qa=f(function(a){return g.style.color=a,z.doc.defaultView.getComputedStyle(g,F).getPropertyValue("color")})}return qa(a)},ra=function(){return"hsb("+[this.h,this.s,this.b]+")"},sa=function(){return"hsl("+[this.h,this.s,this.l]+")"},ta=function(){return this.hex},ua=function(a,b,d){if(null==b&&c.is(a,"object")&&"r"in a&&"g"in a&&"b"in a&&(d=a.b,b=a.g,a=a.r),null==b&&c.is(a,T)){var e=c.getRGB(a);a=e.r,b=e.g,d=e.b}return(a>1||b>1||d>1)&&(a/=255,b/=255,d/=255),[a,b,d]},va=function(a,b,d,e){a*=255,b*=255,d*=255;var f={r:a,g:b,b:d,hex:c.rgb(a,b,d),toString:ta};return c.is(e,"finite")&&(f.opacity=e),f};c.color=function(a){var b;return c.is(a,"object")&&"h"in a&&"s"in a&&"b"in a?(b=c.hsb2rgb(a),a.r=b.r,a.g=b.g,a.b=b.b,a.hex=b.hex):c.is(a,"object")&&"h"in a&&"s"in a&&"l"in a?(b=c.hsl2rgb(a),a.r=b.r,a.g=b.g,a.b=b.b,a.hex=b.hex):(c.is(a,"string")&&(a=c.getRGB(a)),c.is(a,"object")&&"r"in a&&"g"in a&&"b"in a?(b=c.rgb2hsl(a),a.h=b.h,a.s=b.s,a.l=b.l,b=c.rgb2hsb(a),a.v=b.b):(a={hex:"none"},a.r=a.g=a.b=a.h=a.s=a.v=a.l=-1)),a.toString=ta,a},c.hsb2rgb=function(a,b,c,d){this.is(a,"object")&&"h"in a&&"s"in a&&"b"in a&&(c=a.b,b=a.s,a=a.h,d=a.o),a*=360;var e,f,g,h,i;return a=a%360/60,i=c*b,h=i*(1-P(a%2-1)),e=f=g=c-i,a=~~a,e+=[i,h,0,0,h,i][a],f+=[h,i,i,h,0,0][a],g+=[0,0,h,i,i,h][a],va(e,f,g,d)},c.hsl2rgb=function(a,b,c,d){this.is(a,"object")&&"h"in a&&"s"in a&&"l"in a&&(c=a.l,b=a.s,a=a.h),(a>1||b>1||c>1)&&(a/=360,b/=100,c/=100),a*=360;var e,f,g,h,i;return a=a%360/60,i=2*b*(.5>c?c:1-c),h=i*(1-P(a%2-1)),e=f=g=c-i/2,a=~~a,e+=[i,h,0,0,h,i][a],f+=[h,i,i,h,0,0][a],g+=[0,0,h,i,i,h][a],va(e,f,g,d)},c.rgb2hsb=function(a,b,c){c=ua(a,b,c),a=c[0],b=c[1],c=c[2];var d,e,f,g;return f=N(a,b,c),g=f-O(a,b,c),d=0==g?null:f==a?(b-c)/g:f==b?(c-a)/g+2:(a-b)/g+4,d=60*((d+360)%6)/360,e=0==g?0:g/f,{h:d,s:e,b:f,toString:ra}},c.rgb2hsl=function(a,b,c){c=ua(a,b,c),a=c[0],b=c[1],c=c[2];var d,e,f,g,h,i;return g=N(a,b,c),h=O(a,b,c),i=g-h,d=0==i?null:g==a?(b-c)/i:g==b?(c-a)/i+2:(a-b)/i+4,d=60*((d+360)%6)/360,f=(g+h)/2,e=0==i?0:.5>f?i/(2*f):i/(2-2*f),{h:d,s:e,l:f,toString:sa}},c._path2string=function(){return this.join(",").replace(/,?([achlmqrstvxz]),?/gi,"$1")},c._preload=function(a,b){var c=z.doc.createElement("img");c.style.cssText="position:absolute;left:-9999em;top:-9999em",c.onload=function(){b.call(this),this.onload=null,z.doc.body.removeChild(this)},c.onerror=function(){z.doc.body.removeChild(this)},z.doc.body.appendChild(c),c.src=a},c.getRGB=f(function(a){if(!a||(a=H(a)).indexOf("-")+1)return{r:-1,g:-1,b:-1,hex:"none",error:1,toString:g};if("none"==a)return{r:-1,g:-1,b:-1,hex:"none",toString:g};!(ea[y](a.toLowerCase().substring(0,2))||"#"==a.charAt())&&(a=qa(a));var b,d,e,f,h,i,j=a.match(W);return j?(j[2]&&(e=_(j[2].substring(5),16),d=_(j[2].substring(3,5),16),b=_(j[2].substring(1,3),16)),j[3]&&(e=_((h=j[3].charAt(3))+h,16),d=_((h=j[3].charAt(2))+h,16),b=_((h=j[3].charAt(1))+h,16)),j[4]&&(i=j[4][I](da),b=$(i[0]),"%"==i[0].slice(-1)&&(b*=2.55),d=$(i[1]),"%"==i[1].slice(-1)&&(d*=2.55),e=$(i[2]),"%"==i[2].slice(-1)&&(e*=2.55),"rgba"==j[1].toLowerCase().slice(0,4)&&(f=$(i[3])),i[3]&&"%"==i[3].slice(-1)&&(f/=100)),j[5]?(i=j[5][I](da),b=$(i[0]),"%"==i[0].slice(-1)&&(b*=2.55),d=$(i[1]),"%"==i[1].slice(-1)&&(d*=2.55),e=$(i[2]),"%"==i[2].slice(-1)&&(e*=2.55),("deg"==i[0].slice(-3)||"°"==i[0].slice(-1))&&(b/=360),"hsba"==j[1].toLowerCase().slice(0,4)&&(f=$(i[3])),i[3]&&"%"==i[3].slice(-1)&&(f/=100),c.hsb2rgb(b,d,e,f)):j[6]?(i=j[6][I](da),b=$(i[0]),"%"==i[0].slice(-1)&&(b*=2.55),d=$(i[1]),"%"==i[1].slice(-1)&&(d*=2.55),e=$(i[2]),"%"==i[2].slice(-1)&&(e*=2.55),("deg"==i[0].slice(-3)||"°"==i[0].slice(-1))&&(b/=360),"hsla"==j[1].toLowerCase().slice(0,4)&&(f=$(i[3])),i[3]&&"%"==i[3].slice(-1)&&(f/=100),c.hsl2rgb(b,d,e,f)):(j={r:b,g:d,b:e,toString:g},j.hex="#"+(16777216|e|d<<8|b<<16).toString(16).slice(1),c.is(f,"finite")&&(j.opacity=f),j)):{r:-1,g:-1,b:-1,hex:"none",error:1,toString:g}},c),c.hsb=f(function(a,b,d){return c.hsb2rgb(a,b,d).hex}),c.hsl=f(function(a,b,d){return c.hsl2rgb(a,b,d).hex}),c.rgb=f(function(a,b,c){return"#"+(16777216|c|b<<8|a<<16).toString(16).slice(1)}),c.getColor=function(a){var b=this.getColor.start=this.getColor.start||{h:0,s:1,b:a||.75},c=this.hsb2rgb(b.h,b.s,b.b);return b.h+=.075,b.h>1&&(b.h=0,b.s-=.2,0>=b.s&&(this.getColor.start={h:0,s:1,b:b.b})),c.hex},c.getColor.reset=function(){delete this.start},c.parsePathString=function(a){if(!a)return null;var b=wa(a);if(b.arr)return ya(b.arr);var d={a:7,c:6,h:1,l:2,m:2,r:4,q:4,s:4,t:2,v:1,z:0},e=[];return c.is(a,U)&&c.is(a[0],U)&&(e=ya(a)),e.length||H(a).replace(/([achlmrqstvz])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,function(a,b,c){var f=[],g=b.toLowerCase();if(c.replace(fa,function(a,b){b&&f.push(+b)}),"m"==g&&f.length>2&&(e.push([b][D](f.splice(0,2))),g="l",b="m"==b?"l":"L"),"r"==g)e.push([b][D](f));else for(;f.length>=d[g]&&(e.push([b][D](f.splice(0,d[g]))),d[g]););}),e.toString=c._path2string,b.arr=ya(e),e},c.parseTransformString=f(function(a){if(!a)return null;var b=[];return c.is(a,U)&&c.is(a[0],U)&&(b=ya(a)),b.length||H(a).replace(/([rstm])[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*,?[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029]*)+)/gi,function(a,c,d){var e=[];L.call(c),d.replace(fa,function(a,b){b&&e.push(+b)}),b.push([c][D](e))}),b.toString=c._path2string,b});var wa=function(a){var b=wa.ps=wa.ps||{};return b[a]?b[a].sleep=100:b[a]={sleep:100},setTimeout(function(){for(var c in b)b[y](c)&&c!=a&&(b[c].sleep--,!b[c].sleep&&delete b[c])}),b[a]};c.findDotsAtSegment=function(a,b,c,d,e,f,g,h,i){var j=1-i,k=Q(j,3),l=Q(j,2),m=i*i,n=m*i,o=k*a+3*l*i*c+3*j*i*i*e+n*g,p=k*b+3*l*i*d+3*j*i*i*f+n*h,q=a+2*i*(c-a)+m*(e-2*c+a),r=b+2*i*(d-b)+m*(f-2*d+b),s=c+2*i*(e-c)+m*(g-2*e+c),t=d+2*i*(f-d)+m*(h-2*f+d),u=j*a+i*c,v=j*b+i*d,w=j*e+i*g,x=j*f+i*h,y=90-180*M.atan2(q-s,r-t)/R;return(q>s||t>r)&&(y+=180),{x:o,y:p,m:{x:q,y:r},n:{x:s,y:t},start:{x:u,y:v},end:{x:w,y:x},alpha:y}},c.bezierBBox=function(a,b,d,e,f,g,h,i){c.is(a,"array")||(a=[a,b,d,e,f,g,h,i]);var j=Fa.apply(null,a);return{x:j.min.x,y:j.min.y,x2:j.max.x,y2:j.max.y,width:j.max.x-j.min.x,height:j.max.y-j.min.y}},c.isPointInsideBBox=function(a,b,c){return b>=a.x&&a.x2>=b&&c>=a.y&&a.y2>=c},c.isBBoxIntersect=function(a,b){var d=c.isPointInsideBBox;return d(b,a.x,a.y)||d(b,a.x2,a.y)||d(b,a.x,a.y2)||d(b,a.x2,a.y2)||d(a,b.x,b.y)||d(a,b.x2,b.y)||d(a,b.x,b.y2)||d(a,b.x2,b.y2)||(a.xb.x||b.xa.x)&&(a.yb.y||b.ya.y)},c.pathIntersection=function(a,b){return n(a,b)},c.pathIntersectionNumber=function(a,b){return n(a,b,1)},c.isPointInsidePath=function(a,b,d){var e=c.pathBBox(a);return c.isPointInsideBBox(e,b,d)&&1==n(a,[["M",b,d],["H",e.x2+10]],1)%2},c._removedFactory=function(a){return function(){b("raphael.log",null,"Raphaël: you are calling to method “"+a+"” of removed object",a)}};var xa=c.pathBBox=function(a){var b=wa(a);if(b.bbox)return d(b.bbox);if(!a)return{x:0,y:0,width:0,height:0,x2:0,y2:0};a=Ga(a);for(var c,e=0,f=0,g=[],h=[],i=0,j=a.length;j>i;i++)if(c=a[i],"M"==c[0])e=c[1],f=c[2],g.push(e),h.push(f);else{var k=Fa(e,f,c[1],c[2],c[3],c[4],c[5],c[6]);g=g[D](k.min.x,k.max.x),h=h[D](k.min.y,k.max.y),e=c[5],f=c[6]}var l=O[C](0,g),m=O[C](0,h),n=N[C](0,g),o=N[C](0,h),p=n-l,q=o-m,r={x:l,y:m,x2:n,y2:o,width:p,height:q,cx:l+p/2,cy:m+q/2};return b.bbox=d(r),r},ya=function(a){var b=d(a);return b.toString=c._path2string,b},za=c._pathToRelative=function(a){var b=wa(a);if(b.rel)return ya(b.rel);c.is(a,U)&&c.is(a&&a[0],U)||(a=c.parsePathString(a));var d=[],e=0,f=0,g=0,h=0,i=0;"M"==a[0][0]&&(e=a[0][1],f=a[0][2],g=e,h=f,i++,d.push(["M",e,f]));for(var j=i,k=a.length;k>j;j++){var l=d[j]=[],m=a[j];if(m[0]!=L.call(m[0]))switch(l[0]=L.call(m[0]),l[0]){case"a":l[1]=m[1],l[2]=m[2],l[3]=m[3],l[4]=m[4],l[5]=m[5],l[6]=+(m[6]-e).toFixed(3),l[7]=+(m[7]-f).toFixed(3);break;case"v":l[1]=+(m[1]-f).toFixed(3);break;case"m":g=m[1],h=m[2];default:for(var n=1,o=m.length;o>n;n++)l[n]=+(m[n]-(n%2?e:f)).toFixed(3)}else{l=d[j]=[],"m"==m[0]&&(g=m[1]+e,h=m[2]+f);for(var p=0,q=m.length;q>p;p++)d[j][p]=m[p]}var r=d[j].length;switch(d[j][0]){case"z":e=g,f=h;break;case"h":e+=+d[j][r-1];break;case"v":f+=+d[j][r-1];break;default:e+=+d[j][r-2],f+=+d[j][r-1]}}return d.toString=c._path2string,b.rel=ya(d),d},Aa=c._pathToAbsolute=function(a){var b=wa(a);if(b.abs)return ya(b.abs);if(c.is(a,U)&&c.is(a&&a[0],U)||(a=c.parsePathString(a)),!a||!a.length)return[["M",0,0]];var d=[],e=0,f=0,g=0,i=0,j=0;"M"==a[0][0]&&(e=+a[0][1],f=+a[0][2],g=e,i=f,j++,d[0]=["M",e,f]);for(var k,l,m=3==a.length&&"M"==a[0][0]&&"R"==a[1][0].toUpperCase()&&"Z"==a[2][0].toUpperCase(),n=j,o=a.length;o>n;n++){if(d.push(k=[]),l=a[n],l[0]!=aa.call(l[0]))switch(k[0]=aa.call(l[0]),k[0]){case"A":k[1]=l[1],k[2]=l[2],k[3]=l[3],k[4]=l[4],k[5]=l[5],k[6]=+(l[6]+e),k[7]=+(l[7]+f);break;case"V":k[1]=+l[1]+f;break;case"H":k[1]=+l[1]+e;break;case"R":for(var p=[e,f][D](l.slice(1)),q=2,r=p.length;r>q;q++)p[q]=+p[q]+e,p[++q]=+p[q]+f;d.pop(),d=d[D](h(p,m));break;case"M":g=+l[1]+e,i=+l[2]+f;default:for(q=1,r=l.length;r>q;q++)k[q]=+l[q]+(q%2?e:f)}else if("R"==l[0])p=[e,f][D](l.slice(1)),d.pop(),d=d[D](h(p,m)),k=["R"][D](l.slice(-2));else for(var s=0,t=l.length;t>s;s++)k[s]=l[s];switch(k[0]){case"Z":e=g,f=i;break;case"H":e=k[1];break;case"V":f=k[1];break;case"M":g=k[k.length-2],i=k[k.length-1];default:e=k[k.length-2],f=k[k.length-1]}}return d.toString=c._path2string,b.abs=ya(d),d},Ba=function(a,b,c,d){return[a,b,c,d,c,d]},Ca=function(a,b,c,d,e,f){var g=1/3,h=2/3;return[g*a+h*c,g*b+h*d,g*e+h*c,g*f+h*d,e,f]},Da=function(a,b,c,d,e,g,h,i,j,k){var l,m=120*R/180,n=R/180*(+e||0),o=[],p=f(function(a,b,c){return{x:a*M.cos(c)-b*M.sin(c),y:a*M.sin(c)+b*M.cos(c)}});if(k)y=k[0],z=k[1],w=k[2],x=k[3];else{l=p(a,b,-n),a=l.x,b=l.y,l=p(i,j,-n),i=l.x,j=l.y;var q=(M.cos(R/180*e),M.sin(R/180*e),(a-i)/2),r=(b-j)/2,s=q*q/(c*c)+r*r/(d*d);s>1&&(s=M.sqrt(s),c*=s,d*=s);var t=c*c,u=d*d,v=(g==h?-1:1)*M.sqrt(P((t*u-t*r*r-u*q*q)/(t*r*r+u*q*q))),w=v*c*r/d+(a+i)/2,x=v*-d*q/c+(b+j)/2,y=M.asin(((b-x)/d).toFixed(9)),z=M.asin(((j-x)/d).toFixed(9));y=w>a?R-y:y,z=w>i?R-z:z,0>y&&(y=2*R+y),0>z&&(z=2*R+z),h&&y>z&&(y-=2*R),!h&&z>y&&(z-=2*R)}var A=z-y;if(P(A)>m){var B=z,C=i,E=j;z=y+m*(h&&z>y?1:-1),i=w+c*M.cos(z),j=x+d*M.sin(z),o=Da(i,j,c,d,e,0,h,C,E,[z,B,w,x])}A=z-y;var F=M.cos(y),G=M.sin(y),H=M.cos(z),J=M.sin(z),K=M.tan(A/4),L=4/3*c*K,N=4/3*d*K,O=[a,b],Q=[a+L*G,b-N*F],S=[i+L*J,j-N*H],T=[i,j];if(Q[0]=2*O[0]-Q[0],Q[1]=2*O[1]-Q[1],k)return[Q,S,T][D](o);o=[Q,S,T][D](o).join()[I](",");for(var U=[],V=0,W=o.length;W>V;V++)U[V]=V%2?p(o[V-1],o[V],n).y:p(o[V],o[V+1],n).x;return U},Ea=function(a,b,c,d,e,f,g,h,i){var j=1-i;return{x:Q(j,3)*a+3*Q(j,2)*i*c+3*j*i*i*e+Q(i,3)*g,y:Q(j,3)*b+3*Q(j,2)*i*d+3*j*i*i*f+Q(i,3)*h}},Fa=f(function(a,b,c,d,e,f,g,h){var i,j=e-2*c+a-(g-2*e+c),k=2*(c-a)-2*(e-c),l=a-c,m=(-k+M.sqrt(k*k-4*j*l))/2/j,n=(-k-M.sqrt(k*k-4*j*l))/2/j,o=[b,h],p=[a,g];return P(m)>"1e12"&&(m=.5),P(n)>"1e12"&&(n=.5),m>0&&1>m&&(i=Ea(a,b,c,d,e,f,g,h,m),p.push(i.x),o.push(i.y)),n>0&&1>n&&(i=Ea(a,b,c,d,e,f,g,h,n),p.push(i.x),o.push(i.y)),j=f-2*d+b-(h-2*f+d),k=2*(d-b)-2*(f-d),l=b-d,m=(-k+M.sqrt(k*k-4*j*l))/2/j,n=(-k-M.sqrt(k*k-4*j*l))/2/j,P(m)>"1e12"&&(m=.5),P(n)>"1e12"&&(n=.5),m>0&&1>m&&(i=Ea(a,b,c,d,e,f,g,h,m),p.push(i.x),o.push(i.y)),n>0&&1>n&&(i=Ea(a,b,c,d,e,f,g,h,n),p.push(i.x),o.push(i.y)),{min:{x:O[C](0,p),y:O[C](0,o)},max:{x:N[C](0,p),y:N[C](0,o)}}}),Ga=c._path2curve=f(function(a,b){var c=!b&&wa(a);if(!b&&c.curve)return ya(c.curve);for(var d=Aa(a),e=b&&Aa(b),f={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},g={x:0,y:0,bx:0,by:0,X:0,Y:0,qx:null,qy:null},h=(function(a,b){var c,d;if(!a)return["C",b.x,b.y,b.x,b.y,b.x,b.y];switch(!(a[0]in{T:1,Q:1})&&(b.qx=b.qy=null),a[0]){case"M":b.X=a[1],b.Y=a[2];break;case"A":a=["C"][D](Da[C](0,[b.x,b.y][D](a.slice(1))));break;case"S":c=b.x+(b.x-(b.bx||b.x)),d=b.y+(b.y-(b.by||b.y)),a=["C",c,d][D](a.slice(1));break;case"T":b.qx=b.x+(b.x-(b.qx||b.x)),b.qy=b.y+(b.y-(b.qy||b.y)),a=["C"][D](Ca(b.x,b.y,b.qx,b.qy,a[1],a[2]));break;case"Q":b.qx=a[1],b.qy=a[2],a=["C"][D](Ca(b.x,b.y,a[1],a[2],a[3],a[4]));break;case"L":a=["C"][D](Ba(b.x,b.y,a[1],a[2]));break;case"H":a=["C"][D](Ba(b.x,b.y,a[1],b.y));break;case"V":a=["C"][D](Ba(b.x,b.y,b.x,a[1]));break;case"Z":a=["C"][D](Ba(b.x,b.y,b.X,b.Y))}return a}),i=function(a,b){if(a[b].length>7){a[b].shift();for(var c=a[b];c.length;)a.splice(b++,0,["C"][D](c.splice(0,6)));a.splice(b,1),l=N(d.length,e&&e.length||0)}},j=function(a,b,c,f,g){a&&b&&"M"==a[g][0]&&"M"!=b[g][0]&&(b.splice(g,0,["M",f.x,f.y]),c.bx=0,c.by=0,c.x=a[g][1],c.y=a[g][2],l=N(d.length,e&&e.length||0))},k=0,l=N(d.length,e&&e.length||0);l>k;k++){d[k]=h(d[k],f),i(d,k),e&&(e[k]=h(e[k],g)),e&&i(e,k),j(d,e,f,g,k),j(e,d,g,f,k);var m=d[k],n=e&&e[k],o=m.length,p=e&&n.length;f.x=m[o-2],f.y=m[o-1],f.bx=$(m[o-4])||f.x,f.by=$(m[o-3])||f.y,g.bx=e&&($(n[p-4])||g.x),g.by=e&&($(n[p-3])||g.y),g.x=e&&n[p-2],g.y=e&&n[p-1]}return e||(c.curve=ya(d)),e?[d,e]:d},null,ya),Ha=(c._parseDots=f(function(a){for(var b=[],d=0,e=a.length;e>d;d++){var f={},g=a[d].match(/^([^:]*):?([\d\.]*)/);if(f.color=c.getRGB(g[1]),f.color.error)return null;f.color=f.color.hex,g[2]&&(f.offset=g[2]+"%"),b.push(f)}for(d=1,e=b.length-1;e>d;d++)if(!b[d].offset){for(var h=$(b[d-1].offset||0),i=0,j=d+1;e>j;j++)if(b[j].offset){i=b[j].offset;break}i||(i=100,j=e),i=$(i);for(var k=(i-h)/(j-d+1);j>d;d++)h+=k,b[d].offset=h+"%"}return b}),c._tear=function(a,b){a==b.top&&(b.top=a.prev),a==b.bottom&&(b.bottom=a.next),a.next&&(a.next.prev=a.prev),a.prev&&(a.prev.next=a.next)}),Ia=(c._tofront=function(a,b){b.top!==a&&(Ha(a,b),a.next=null,a.prev=b.top,b.top.next=a,b.top=a)},c._toback=function(a,b){b.bottom!==a&&(Ha(a,b),a.next=b.bottom,a.prev=null,b.bottom.prev=a,b.bottom=a)},c._insertafter=function(a,b,c){Ha(a,c),b==c.top&&(c.top=a),b.next&&(b.next.prev=a),a.next=b.next,a.prev=b,b.next=a},c._insertbefore=function(a,b,c){Ha(a,c),b==c.bottom&&(c.bottom=a),b.prev&&(b.prev.next=a),a.prev=b.prev,b.prev=a,a.next=b},c.toMatrix=function(a,b){var c=xa(a),d={_:{transform:F},getBBox:function(){return c}};return Ja(d,b),d.matrix}),Ja=(c.transformPath=function(a,b){return na(a,Ia(a,b))},c._extractTransform=function(a,b){if(null==b)return a._.transform;b=H(b).replace(/\.{3}|\u2026/g,a._.transform||F);var d=c.parseTransformString(b),e=0,f=0,g=0,h=1,i=1,j=a._,k=new o;if(j.transform=d||[],d)for(var l=0,m=d.length;m>l;l++){var n,p,q,r,s,t=d[l],u=t.length,v=H(t[0]).toLowerCase(),w=t[0]!=v,x=w?k.invert():0;"t"==v&&3==u?w?(n=x.x(0,0),p=x.y(0,0),q=x.x(t[1],t[2]),r=x.y(t[1],t[2]),k.translate(q-n,r-p)):k.translate(t[1],t[2]):"r"==v?2==u?(s=s||a.getBBox(1),k.rotate(t[1],s.x+s.width/2,s.y+s.height/2),e+=t[1]):4==u&&(w?(q=x.x(t[2],t[3]),r=x.y(t[2],t[3]),k.rotate(t[1],q,r)):k.rotate(t[1],t[2],t[3]),e+=t[1]):"s"==v?2==u||3==u?(s=s||a.getBBox(1),k.scale(t[1],t[u-1],s.x+s.width/2,s.y+s.height/2),h*=t[1],i*=t[u-1]):5==u&&(w?(q=x.x(t[3],t[4]),r=x.y(t[3],t[4]),k.scale(t[1],t[2],q,r)):k.scale(t[1],t[2],t[3],t[4]),h*=t[1],i*=t[2]):"m"==v&&7==u&&k.add(t[1],t[2],t[3],t[4],t[5],t[6]),j.dirtyT=1,a.matrix=k}a.matrix=k,j.sx=h,j.sy=i,j.deg=e,j.dx=f=k.e,j.dy=g=k.f,1==h&&1==i&&!e&&j.bbox?(j.bbox.x+=+f,j.bbox.y+=+g):j.dirtyT=1}),Ka=function(a){var b=a[0];switch(b.toLowerCase()){case"t":return[b,0,0];case"m":return[b,1,0,0,1,0,0];case"r":return 4==a.length?[b,0,a[2],a[3]]:[b,0];case"s":return 5==a.length?[b,1,1,a[3],a[4]]:3==a.length?[b,1,1]:[b,1]}},La=c._equaliseTransform=function(a,b){b=H(b).replace(/\.{3}|\u2026/g,a),a=c.parseTransformString(a)||[],b=c.parseTransformString(b)||[] +;for(var d,e,f,g,h=N(a.length,b.length),i=[],j=[],k=0;h>k;k++){if(f=a[k]||Ka(b[k]),g=b[k]||Ka(f),f[0]!=g[0]||"r"==f[0].toLowerCase()&&(f[2]!=g[2]||f[3]!=g[3])||"s"==f[0].toLowerCase()&&(f[3]!=g[3]||f[4]!=g[4]))return;for(i[k]=[],j[k]=[],d=0,e=N(f.length,g.length);e>d;d++)d in f&&(i[k][d]=f[d]),d in g&&(j[k][d]=g[d])}return{from:i,to:j}};c._getContainer=function(a,b,d,e){var f;return f=null!=e||c.is(a,"object")?a:z.doc.getElementById(a),null!=f?f.tagName?null==b?{container:f,width:f.style.pixelWidth||f.offsetWidth,height:f.style.pixelHeight||f.offsetHeight}:{container:f,width:b,height:d}:{container:1,x:a,y:b,width:d,height:e}:void 0},c.pathToRelative=za,c._engine={},c.path2curve=Ga,c.matrix=function(a,b,c,d,e,f){return new o(a,b,c,d,e,f)},function(a){function b(a){return a[0]*a[0]+a[1]*a[1]}function d(a){var c=M.sqrt(b(a));a[0]&&(a[0]/=c),a[1]&&(a[1]/=c)}a.add=function(a,b,c,d,e,f){var g,h,i,j,k=[[],[],[]],l=[[this.a,this.c,this.e],[this.b,this.d,this.f],[0,0,1]],m=[[a,c,e],[b,d,f],[0,0,1]];for(a&&a instanceof o&&(m=[[a.a,a.c,a.e],[a.b,a.d,a.f],[0,0,1]]),g=0;3>g;g++)for(h=0;3>h;h++){for(j=0,i=0;3>i;i++)j+=l[g][i]*m[i][h];k[g][h]=j}this.a=k[0][0],this.b=k[1][0],this.c=k[0][1],this.d=k[1][1],this.e=k[0][2],this.f=k[1][2]},a.invert=function(){var a=this,b=a.a*a.d-a.b*a.c;return new o(a.d/b,-a.b/b,-a.c/b,a.a/b,(a.c*a.f-a.d*a.e)/b,(a.b*a.e-a.a*a.f)/b)},a.clone=function(){return new o(this.a,this.b,this.c,this.d,this.e,this.f)},a.translate=function(a,b){this.add(1,0,0,1,a,b)},a.scale=function(a,b,c,d){null==b&&(b=a),(c||d)&&this.add(1,0,0,1,c,d),this.add(a,0,0,b,0,0),(c||d)&&this.add(1,0,0,1,-c,-d)},a.rotate=function(a,b,d){a=c.rad(a),b=b||0,d=d||0;var e=+M.cos(a).toFixed(9),f=+M.sin(a).toFixed(9);this.add(e,f,-f,e,b,d),this.add(1,0,0,1,-b,-d)},a.x=function(a,b){return a*this.a+b*this.c+this.e},a.y=function(a,b){return a*this.b+b*this.d+this.f},a.get=function(a){return+this[H.fromCharCode(97+a)].toFixed(4)},a.toString=function(){return c.svg?"matrix("+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)].join()+")":[this.get(0),this.get(2),this.get(1),this.get(3),0,0].join()},a.toFilter=function(){return"progid:DXImageTransform.Microsoft.Matrix(M11="+this.get(0)+", M12="+this.get(2)+", M21="+this.get(1)+", M22="+this.get(3)+", Dx="+this.get(4)+", Dy="+this.get(5)+", sizingmethod='auto expand')"},a.offset=function(){return[this.e.toFixed(4),this.f.toFixed(4)]},a.split=function(){var a={};a.dx=this.e,a.dy=this.f;var e=[[this.a,this.c],[this.b,this.d]];a.scalex=M.sqrt(b(e[0])),d(e[0]),a.shear=e[0][0]*e[1][0]+e[0][1]*e[1][1],e[1]=[e[1][0]-e[0][0]*a.shear,e[1][1]-e[0][1]*a.shear],a.scaley=M.sqrt(b(e[1])),d(e[1]),a.shear/=a.scaley;var f=-e[0][1],g=e[1][1];return 0>g?(a.rotate=c.deg(M.acos(g)),0>f&&(a.rotate=360-a.rotate)):a.rotate=c.deg(M.asin(f)),a.isSimple=!(+a.shear.toFixed(9)||a.scalex.toFixed(9)!=a.scaley.toFixed(9)&&a.rotate),a.isSuperSimple=!+a.shear.toFixed(9)&&a.scalex.toFixed(9)==a.scaley.toFixed(9)&&!a.rotate,a.noRotation=!+a.shear.toFixed(9)&&!a.rotate,a},a.toTransformString=function(a){var b=a||this[I]();return b.isSimple?(b.scalex=+b.scalex.toFixed(4),b.scaley=+b.scaley.toFixed(4),b.rotate=+b.rotate.toFixed(4),(b.dx||b.dy?"t"+[b.dx,b.dy]:F)+(1!=b.scalex||1!=b.scaley?"s"+[b.scalex,b.scaley,0,0]:F)+(b.rotate?"r"+[b.rotate,0,0]:F)):"m"+[this.get(0),this.get(1),this.get(2),this.get(3),this.get(4),this.get(5)]}}(o.prototype);var Ma=navigator.userAgent.match(/Version\/(.*?)\s/)||navigator.userAgent.match(/Chrome\/(\d+)/);v.safari="Apple Computer, Inc."==navigator.vendor&&(Ma&&4>Ma[1]||"iP"==navigator.platform.slice(0,2))||"Google Inc."==navigator.vendor&&Ma&&8>Ma[1]?function(){var a=this.rect(-99,-99,this.width+99,this.height+99).attr({stroke:"none"});setTimeout(function(){a.remove()})}:ia;for(var Na=function(){this.returnValue=!1},Oa=function(){return this.originalEvent.preventDefault()},Pa=function(){this.cancelBubble=!0},Qa=function(){return this.originalEvent.stopPropagation()},Ra=function(){return z.doc.addEventListener?function(a,b,c,d){var e=E&&K[b]?K[b]:b,f=function(e){var f=z.doc.documentElement.scrollTop||z.doc.body.scrollTop,g=z.doc.documentElement.scrollLeft||z.doc.body.scrollLeft,h=e.clientX+g,i=e.clientY+f;if(E&&K[y](b))for(var j=0,k=e.targetTouches&&e.targetTouches.length;k>j;j++)if(e.targetTouches[j].target==a){var l=e;e=e.targetTouches[j],e.originalEvent=l,e.preventDefault=Oa,e.stopPropagation=Qa;break}return c.call(d,e,h,i)};return a.addEventListener(e,f,!1),function(){return a.removeEventListener(e,f,!1),!0}}:z.doc.attachEvent?function(a,b,c,d){var e=function(a){a=a||z.win.event;var b=z.doc.documentElement.scrollTop||z.doc.body.scrollTop,e=z.doc.documentElement.scrollLeft||z.doc.body.scrollLeft,f=a.clientX+e,g=a.clientY+b;return a.preventDefault=a.preventDefault||Na,a.stopPropagation=a.stopPropagation||Pa,c.call(d,a,f,g)};a.attachEvent("on"+b,e);return function(){return a.detachEvent("on"+b,e),!0}}:void 0}(),Sa=[],Ta=function(a){for(var c,d=a.clientX,e=a.clientY,f=z.doc.documentElement.scrollTop||z.doc.body.scrollTop,g=z.doc.documentElement.scrollLeft||z.doc.body.scrollLeft,h=Sa.length;h--;){if(c=Sa[h],E){for(var i,j=a.touches.length;j--;)if(i=a.touches[j],i.identifier==c.el._drag.id){d=i.clientX,e=i.clientY,(a.originalEvent?a.originalEvent:a).preventDefault();break}}else a.preventDefault();var k,l=c.el.node,m=l.nextSibling,n=l.parentNode,o=l.style.display;z.win.opera&&n.removeChild(l),l.style.display="none",k=c.el.paper.getElementByPoint(d,e),l.style.display=o,z.win.opera&&(m?n.insertBefore(l,m):n.appendChild(l)),k&&b("raphael.drag.over."+c.el.id,c.el,k),d+=g,e+=f,b("raphael.drag.move."+c.el.id,c.move_scope||c.el,d-c.el._drag.x,e-c.el._drag.y,d,e,a)}},Ua=function(a){c.unmousemove(Ta).unmouseup(Ua);for(var d,e=Sa.length;e--;)d=Sa[e],d.el._drag={},b("raphael.drag.end."+d.el.id,d.end_scope||d.start_scope||d.move_scope||d.el,a);Sa=[]},Va=c.el={},Wa=J.length;Wa--;)!function(a){c[a]=Va[a]=function(b,d){return c.is(b,"function")&&(this.events=this.events||[],this.events.push({name:a,f:b,unbind:Ra(this.shape||this.node||z.doc,a,b,d||this)})),this},c["un"+a]=Va["un"+a]=function(b){for(var d=this.events||[],e=d.length;e--;)d[e].name!=a||!c.is(b,"undefined")&&d[e].f!=b||(d[e].unbind(),d.splice(e,1),!d.length&&delete this.events);return this}}(J[Wa]);Va.data=function(a,d){var e=ga[this.id]=ga[this.id]||{};if(0==arguments.length)return e;if(1==arguments.length){if(c.is(a,"object")){for(var f in a)a[y](f)&&this.data(f,a[f]);return this}return b("raphael.data.get."+this.id,this,e[a],a),e[a]}return e[a]=d,b("raphael.data.set."+this.id,this,d,a),this},Va.removeData=function(a){return null==a?ga[this.id]={}:ga[this.id]&&delete ga[this.id][a],this},Va.getData=function(){return d(ga[this.id]||{})},Va.hover=function(a,b,c,d){return this.mouseover(a,c).mouseout(b,d||c)},Va.unhover=function(a,b){return this.unmouseover(a).unmouseout(b)};var Xa=[];Va.drag=function(a,d,e,f,g,h){function i(i){(i.originalEvent||i).preventDefault();var j=z.doc.documentElement.scrollTop||z.doc.body.scrollTop,k=z.doc.documentElement.scrollLeft||z.doc.body.scrollLeft;this._drag.x=i.clientX+k,this._drag.y=i.clientY+j,this._drag.id=i.identifier,!Sa.length&&c.mousemove(Ta).mouseup(Ua),Sa.push({el:this,move_scope:f,start_scope:g,end_scope:h}),d&&b.on("raphael.drag.start."+this.id,d),a&&b.on("raphael.drag.move."+this.id,a),e&&b.on("raphael.drag.end."+this.id,e),b("raphael.drag.start."+this.id,g||f||this,i.clientX+k,i.clientY+j,i)}return this._drag={},Xa.push({el:this,start:i}),this.mousedown(i),this},Va.onDragOver=function(a){a?b.on("raphael.drag.over."+this.id,a):b.unbind("raphael.drag.over."+this.id)},Va.undrag=function(){for(var a=Xa.length;a--;)Xa[a].el==this&&(this.unmousedown(Xa[a].start),Xa.splice(a,1),b.unbind("raphael.drag.*."+this.id));!Xa.length&&c.unmousemove(Ta).unmouseup(Ua),Sa=[]},v.circle=function(a,b,d){var e=c._engine.circle(this,a||0,b||0,d||0);return this.__set__&&this.__set__.push(e),e},v.rect=function(a,b,d,e,f){var g=c._engine.rect(this,a||0,b||0,d||0,e||0,f||0);return this.__set__&&this.__set__.push(g),g},v.ellipse=function(a,b,d,e){var f=c._engine.ellipse(this,a||0,b||0,d||0,e||0);return this.__set__&&this.__set__.push(f),f},v.path=function(a){a&&!c.is(a,T)&&!c.is(a[0],U)&&(a+=F);var b=c._engine.path(c.format[C](c,arguments),this);return this.__set__&&this.__set__.push(b),b},v.image=function(a,b,d,e,f){var g=c._engine.image(this,a||"about:blank",b||0,d||0,e||0,f||0);return this.__set__&&this.__set__.push(g),g},v.text=function(a,b,d){var e=c._engine.text(this,a||0,b||0,H(d));return this.__set__&&this.__set__.push(e),e},v.set=function(a){!c.is(a,"array")&&(a=Array.prototype.splice.call(arguments,0,arguments.length));var b=new hb(a);return this.__set__&&this.__set__.push(b),b.paper=this,b.type="set",b},v.setStart=function(a){this.__set__=a||this.set()},v.setFinish=function(){var a=this.__set__;return delete this.__set__,a},v.setSize=function(a,b){return c._engine.setSize.call(this,a,b)},v.setViewBox=function(a,b,d,e,f){return c._engine.setViewBox.call(this,a,b,d,e,f)},v.top=v.bottom=null,v.raphael=c;var Ya=function(a){var b=a.getBoundingClientRect(),c=a.ownerDocument,d=c.body,e=c.documentElement,f=e.clientTop||d.clientTop||0,g=e.clientLeft||d.clientLeft||0;return{y:b.top+(z.win.pageYOffset||e.scrollTop||d.scrollTop)-f,x:b.left+(z.win.pageXOffset||e.scrollLeft||d.scrollLeft)-g}};v.getElementByPoint=function(a,b){var c=this,d=c.canvas,e=z.doc.elementFromPoint(a,b);if(z.win.opera&&"svg"==e.tagName){var f=Ya(d),g=d.createSVGRect();g.x=a-f.x,g.y=b-f.y,g.width=g.height=1;var h=d.getIntersectionList(g,null);h.length&&(e=h[h.length-1])}if(!e)return null;for(;e.parentNode&&e!=d.parentNode&&!e.raphael;)e=e.parentNode;return e==c.canvas.parentNode&&(e=d),e=e&&e.raphael?c.getById(e.raphaelid):null},v.getElementsByBBox=function(a){var b=this.set();return this.forEach(function(d){c.isBBoxIntersect(d.getBBox(),a)&&b.push(d)}),b},v.getById=function(a){for(var b=this.bottom;b;){if(b.id==a)return b;b=b.next}return null},v.forEach=function(a,b){for(var c=this.bottom;c;){if(a.call(b,c)===!1)return this;c=c.next}return this},v.getElementsByPoint=function(a,b){var c=this.set();return this.forEach(function(d){d.isPointInside(a,b)&&c.push(d)}),c},Va.isPointInside=function(a,b){var d=this.realPath=this.realPath||ma[this.type](this);return c.isPointInsidePath(d,a,b)},Va.getBBox=function(a){if(this.removed)return{};var b=this._;return a?((b.dirty||!b.bboxwt)&&(this.realPath=ma[this.type](this),b.bboxwt=xa(this.realPath),b.bboxwt.toString=p,b.dirty=0),b.bboxwt):((b.dirty||b.dirtyT||!b.bbox)&&((b.dirty||!this.realPath)&&(b.bboxwt=0,this.realPath=ma[this.type](this)),b.bbox=xa(na(this.realPath,this.matrix)),b.bbox.toString=p,b.dirty=b.dirtyT=0),b.bbox)},Va.clone=function(){if(this.removed)return null;var a=this.paper[this.type]().attr(this.attr());return this.__set__&&this.__set__.push(a),a},Va.glow=function(a){if("text"==this.type)return null;a=a||{};var b={width:(a.width||10)+(+this.attr("stroke-width")||1),fill:a.fill||!1,opacity:a.opacity||.5,offsetx:a.offsetx||0,offsety:a.offsety||0,color:a.color||"#000"},c=b.width/2,d=this.paper,e=d.set(),f=this.realPath||ma[this.type](this);f=this.matrix?na(f,this.matrix):f;for(var g=1;c+1>g;g++)e.push(d.path(f).attr({stroke:b.color,fill:b.fill?b.color:"none","stroke-linejoin":"round","stroke-linecap":"round","stroke-width":+(b.width/c*g).toFixed(3),opacity:+(b.opacity/c).toFixed(3)}));return e.insertBefore(this).translate(b.offsetx,b.offsety)};var Za=function(a,b,d,e,f,g,h,i,l){return null==l?j(a,b,d,e,f,g,h,i):c.findDotsAtSegment(a,b,d,e,f,g,h,i,k(a,b,d,e,f,g,h,i,l))},$a=function(a,b){return function(d,e,f){d=Ga(d);for(var g,h,i,j,k,l="",m={},n=0,o=0,p=d.length;p>o;o++){if(i=d[o],"M"==i[0])g=+i[1],h=+i[2];else{if(j=Za(g,h,i[1],i[2],i[3],i[4],i[5],i[6]),n+j>e){if(b&&!m.start){if(k=Za(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n),l+=["C"+k.start.x,k.start.y,k.m.x,k.m.y,k.x,k.y],f)return l;m.start=l,l=["M"+k.x,k.y+"C"+k.n.x,k.n.y,k.end.x,k.end.y,i[5],i[6]].join(),n+=j,g=+i[5],h=+i[6];continue}if(!a&&!b)return k=Za(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n),{x:k.x,y:k.y,alpha:k.alpha}}n+=j,g=+i[5],h=+i[6]}l+=i.shift()+i}return m.end=l,k=a?n:b?m:c.findDotsAtSegment(g,h,i[0],i[1],i[2],i[3],i[4],i[5],1),k.alpha&&(k={x:k.x,y:k.y,alpha:k.alpha}),k}},_a=$a(1),ab=$a(),bb=$a(0,1);c.getTotalLength=_a,c.getPointAtLength=ab,c.getSubpath=function(a,b,c){if(1e-6>this.getTotalLength(a)-c)return bb(a,b).end;var d=bb(a,c,1);return b?bb(d,b).end:d},Va.getTotalLength=function(){return"path"==this.type?this.node.getTotalLength?this.node.getTotalLength():_a(this.attrs.path):void 0},Va.getPointAtLength=function(a){return"path"==this.type?ab(this.attrs.path,a):void 0},Va.getSubpath=function(a,b){return"path"==this.type?c.getSubpath(this.attrs.path,a,b):void 0};var cb=c.easing_formulas={linear:function(a){return a},"<":function(a){return Q(a,1.7)},">":function(a){return Q(a,.48)},"<>":function(a){var b=.48-a/1.04,c=M.sqrt(.1734+b*b),d=c-b,e=Q(P(d),1/3)*(0>d?-1:1),f=-c-b,g=Q(P(f),1/3)*(0>f?-1:1),h=e+g+.5;return 3*(1-h)*h*h+h*h*h},backIn:function(a){var b=1.70158;return a*a*((b+1)*a-b)},backOut:function(a){a-=1;var b=1.70158;return a*a*((b+1)*a+b)+1},elastic:function(a){return a==!!a?a:Q(2,-10*a)*M.sin(2*(a-.075)*R/.3)+1},bounce:function(a){var b,c=7.5625,d=2.75;return 1/d>a?b=c*a*a:2/d>a?(a-=1.5/d,b=c*a*a+.75):2.5/d>a?(a-=2.25/d,b=c*a*a+.9375):(a-=2.625/d,b=c*a*a+.984375),b}};cb.easeIn=cb["ease-in"]=cb["<"],cb.easeOut=cb["ease-out"]=cb[">"],cb.easeInOut=cb["ease-in-out"]=cb["<>"],cb["back-in"]=cb.backIn,cb["back-out"]=cb.backOut;var db=[],eb=a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame||a.oRequestAnimationFrame||a.msRequestAnimationFrame||function(a){setTimeout(a,16)},fb=function(){for(var a=+new Date,d=0;db.length>d;d++){var e=db[d];if(!e.el.removed&&!e.paused){var f,g,h=a-e.start,i=e.ms,j=e.easing,k=e.from,l=e.diff,m=e.to,n=(e.t,e.el),o={},p={};if(e.initstatus?(h=(e.initstatus*e.anim.top-e.prev)/(e.percent-e.prev)*i,e.status=e.initstatus,delete e.initstatus,e.stop&&db.splice(d--,1)):e.status=(e.prev+(e.percent-e.prev)*(h/i))/e.anim.top,!(0>h))if(i>h){var q=j(h/i);for(var r in k)if(k[y](r)){switch(ca[r]){case S:f=+k[r]+q*i*l[r];break;case"colour":f="rgb("+[gb(Z(k[r].r+q*i*l[r].r)),gb(Z(k[r].g+q*i*l[r].g)),gb(Z(k[r].b+q*i*l[r].b))].join(",")+")";break;case"path":f=[];for(var t=0,u=k[r].length;u>t;t++){f[t]=[k[r][t][0]];for(var v=1,w=k[r][t].length;w>v;v++)f[t][v]=+k[r][t][v]+q*i*l[r][t][v];f[t]=f[t].join(G)}f=f.join(G);break;case"transform":if(l[r].real)for(f=[],t=0,u=k[r].length;u>t;t++)for(f[t]=[k[r][t][0]],v=1,w=k[r][t].length;w>v;v++)f[t][v]=k[r][t][v]+q*i*l[r][t][v];else{var x=function(a){return+k[r][a]+q*i*l[r][a]};f=[["m",x(0),x(1),x(2),x(3),x(4),x(5)]]}break;case"csv":if("clip-rect"==r)for(f=[],t=4;t--;)f[t]=+k[r][t]+q*i*l[r][t];break;default:var z=[][D](k[r]);for(f=[],t=n.paper.customAttributes[r].length;t--;)f[t]=+z[t]+q*i*l[r][t]}o[r]=f}n.attr(o),function(a,c,d){setTimeout(function(){b("raphael.anim.frame."+a,c,d)})}(n.id,n,e.anim)}else{if(function(a,d,e){setTimeout(function(){b("raphael.anim.frame."+d.id,d,e),b("raphael.anim.finish."+d.id,d,e),c.is(a,"function")&&a.call(d)})}(e.callback,n,e.anim),n.attr(m),db.splice(d--,1),e.repeat>1&&!e.next){for(g in m)m[y](g)&&(p[g]=e.totalOrigin[g]);e.el.attr(p),s(e.anim,e.el,e.anim.percents[0],null,e.totalOrigin,e.repeat-1)}e.next&&!e.stop&&s(e.anim,e.el,e.next,null,e.totalOrigin,e.repeat)}}}c.svg&&n&&n.paper&&n.paper.safari(),db.length&&eb(fb)},gb=function(a){return a>255?255:0>a?0:a};Va.animateWith=function(a,b,d,e,f,g){var h=this;if(h.removed)return g&&g.call(h),h;var i=d instanceof r?d:c.animation(d,e,f,g);s(i,h,i.percents[0],null,h.attr());for(var j=0,k=db.length;k>j;j++)if(db[j].anim==b&&db[j].el==a){db[k-1].start=db[j].start;break}return h},Va.onAnimation=function(a){return a?b.on("raphael.anim.frame."+this.id,a):b.unbind("raphael.anim.frame."+this.id),this},r.prototype.delay=function(a){var b=new r(this.anim,this.ms);return b.times=this.times,b.del=+a||0,b},r.prototype.repeat=function(a){var b=new r(this.anim,this.ms);return b.del=this.del,b.times=M.floor(N(a,0))||1,b},c.animation=function(a,b,d,e){if(a instanceof r)return a;(c.is(d,"function")||!d)&&(e=e||d||null,d=null),a=Object(a),b=+b||0;var f,g,h={};for(g in a)a[y](g)&&$(g)!=g&&$(g)+"%"!=g&&(f=!0,h[g]=a[g]);return f?(d&&(h.easing=d),e&&(h.callback=e),new r({100:h},b)):new r(a,b)},Va.animate=function(a,b,d,e){var f=this;if(f.removed)return e&&e.call(f),f;var g=a instanceof r?a:c.animation(a,b,d,e);return s(g,f,g.percents[0],null,f.attr()),f},Va.setTime=function(a,b){return a&&null!=b&&this.status(a,O(b,a.ms)/a.ms),this},Va.status=function(a,b){var c,d,e=[],f=0;if(null!=b)return s(a,this,-1,O(b,1)),this;for(c=db.length;c>f;f++)if(d=db[f],d.el.id==this.id&&(!a||d.anim==a)){if(a)return d.status;e.push({anim:d.anim,status:d.status})}return a?0:e},Va.pause=function(a){for(var c=0;db.length>c;c++)db[c].el.id!=this.id||a&&db[c].anim!=a||b("raphael.anim.pause."+this.id,this,db[c].anim)!==!1&&(db[c].paused=!0);return this},Va.resume=function(a){for(var c=0;db.length>c;c++)if(db[c].el.id==this.id&&(!a||db[c].anim==a)){var d=db[c];b("raphael.anim.resume."+this.id,this,d.anim)!==!1&&(delete d.paused,this.status(d.anim,d.status))}return this},Va.stop=function(a){for(var c=0;db.length>c;c++)db[c].el.id!=this.id||a&&db[c].anim!=a||b("raphael.anim.stop."+this.id,this,db[c].anim)!==!1&&db.splice(c--,1);return this},b.on("raphael.remove",t),b.on("raphael.clear",t),Va.toString=function(){return"Raphaël’s object"};var hb=function(a){if(this.items=[],this.length=0,this.type="set",a)for(var b=0,c=a.length;c>b;b++)!a[b]||a[b].constructor!=Va.constructor&&a[b].constructor!=hb||(this[this.items.length]=this.items[this.items.length]=a[b],this.length++)},ib=hb.prototype;ib.push=function(){for(var a,b,c=0,d=arguments.length;d>c;c++)a=arguments[c],!a||a.constructor!=Va.constructor&&a.constructor!=hb||(b=this.items.length,this[b]=this.items[b]=a,this.length++);return this},ib.pop=function(){return this.length&&delete this[this.length--],this.items.pop()},ib.forEach=function(a,b){for(var c=0,d=this.items.length;d>c;c++)if(a.call(b,this.items[c],c)===!1)return this;return this};for(var jb in Va)Va[y](jb)&&(ib[jb]=function(a){return function(){var b=arguments;return this.forEach(function(c){c[a][C](c,b)})}}(jb));return ib.attr=function(a,b){if(a&&c.is(a,U)&&c.is(a[0],"object"))for(var d=0,e=a.length;e>d;d++)this.items[d].attr(a[d]);else for(var f=0,g=this.items.length;g>f;f++)this.items[f].attr(a,b);return this},ib.clear=function(){for(;this.length;)this.pop()},ib.splice=function(a,b){a=0>a?N(this.length+a,0):a,b=N(0,O(this.length-a,b));var c,d=[],e=[],f=[];for(c=2;arguments.length>c;c++)f.push(arguments[c]);for(c=0;b>c;c++)e.push(this[a+c]);for(;this.length-a>c;c++)d.push(this[a+c]);var g=f.length;for(c=0;g+d.length>c;c++)this.items[a+c]=this[a+c]=g>c?f[c]:d[c-g];for(c=this.items.length=this.length-=b-g;this[c];)delete this[c++];return new hb(e)},ib.exclude=function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]==a)return this.splice(b,1),!0},ib.animate=function(a,b,d,e){(c.is(d,"function")||!d)&&(e=d||null);var f,g,h=this.items.length,i=h,j=this;if(!h)return this;e&&(g=function(){!--h&&e.call(j)}),d=c.is(d,T)?d:g;var k=c.animation(a,b,d,g);for(f=this.items[--i].animate(k);i--;)this.items[i]&&!this.items[i].removed&&this.items[i].animateWith(f,k,k),this.items[i]&&!this.items[i].removed||h--;return this},ib.insertAfter=function(a){for(var b=this.items.length;b--;)this.items[b].insertAfter(a);return this},ib.getBBox=function(){for(var a=[],b=[],c=[],d=[],e=this.items.length;e--;)if(!this.items[e].removed){var f=this.items[e].getBBox();a.push(f.x),b.push(f.y),c.push(f.x+f.width),d.push(f.y+f.height)}return a=O[C](0,a),b=O[C](0,b),c=N[C](0,c),d=N[C](0,d),{x:a,y:b,x2:c,y2:d,width:c-a,height:d-b}},ib.clone=function(a){a=this.paper.set();for(var b=0,c=this.items.length;c>b;b++)a.push(this.items[b].clone());return a},ib.toString=function(){return"Raphaël‘s set"},ib.glow=function(a){var b=this.paper.set();return this.forEach(function(c){var d=c.glow(a);null!=d&&d.forEach(function(a){b.push(a)})}),b},ib.isPointInside=function(a,b){var c=!1;return this.forEach(function(d){return d.isPointInside(a,b)?(console.log("runned"),c=!0,!1):void 0}),c},c.registerFont=function(a){if(!a.face)return a;this.fonts=this.fonts||{};var b={w:a.w,face:{},glyphs:{}},c=a.face["font-family"];for(var d in a.face)a.face[y](d)&&(b.face[d]=a.face[d]);if(this.fonts[c]?this.fonts[c].push(b):this.fonts[c]=[b],!a.svg){b.face["units-per-em"]=_(a.face["units-per-em"],10);for(var e in a.glyphs)if(a.glyphs[y](e)){var f=a.glyphs[e];if(b.glyphs[e]={w:f.w,k:{},d:f.d&&"M"+f.d.replace(/[mlcxtrv]/g,function(a){return{l:"L",c:"C",x:"z",t:"m",r:"l",v:"c"}[a]||"M"})+"z"},f.k)for(var g in f.k)f[y](g)&&(b.glyphs[e].k[g]=f.k[g])}}return a},v.getFont=function(a,b,d,e){if(e=e||"normal",d=d||"normal",b=+b||{normal:400,bold:700,lighter:300,bolder:800}[b]||400,c.fonts){var f=c.fonts[a];if(!f){var g=RegExp("(^|\\s)"+a.replace(/[^\w\d\s+!~.:_-]/g,F)+"(\\s|$)","i");for(var h in c.fonts)if(c.fonts[y](h)&&g.test(h)){f=c.fonts[h];break}}var i;if(f)for(var j=0,k=f.length;k>j&&(i=f[j],i.face["font-weight"]!=b||i.face["font-style"]!=d&&i.face["font-style"]||i.face["font-stretch"]!=e);j++);return i}},v.print=function(a,b,d,e,f,g,h,i){g=g||"middle",h=N(O(h||0,1),-1),i=N(O(i||1,3),1);var j,k=H(d)[I](F),l=0,m=0,n=F;if(c.is(e,"string")&&(e=this.getFont(e)),e){j=(f||16)/e.face["units-per-em"];for(var o=e.face.bbox[I](w),p=+o[0],q=o[3]-o[1],r=0,s=+o[1]+("baseline"==g?q+ +e.face.descent:q/2),t=0,u=k.length;u>t;t++){if("\n"==k[t])l=0,x=0,m=0,r+=q*i;else{var v=m&&e.glyphs[k[t-1]]||{},x=e.glyphs[k[t]];l+=m?(v.w||e.w)+(v.k&&v.k[k[t]]||0)+e.w*h:0,m=1}x&&x.d&&(n+=c.transformPath(x.d,["t",l*j,r*j,"s",j,j,p,s,"t",(a-p)/j,(b-s)/j]))}}return this.path(n).attr({fill:"#000",stroke:"none"})},v.add=function(a){if(c.is(a,"array"))for(var b,d=this.set(),e=0,f=a.length;f>e;e++)b=a[e]||{},x[y](b.type)&&d.push(this[b.type]().attr(b));return d},c.format=function(a,b){var d=c.is(b,U)?[0][D](b):arguments;return a&&c.is(a,T)&&d.length-1&&(a=a.replace(/\{(\d+)\}/g,function(a,b){return null==d[++b]?F:d[b]})),a||F},c.fullfill=function(){var a=function(a,b,c){var d=c;return b.replace(/(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g,function(a,b,c,e,f){b=b||e,d&&(b in d&&(d=d[b]),"function"==typeof d&&f&&(d=d()))}),d=(null==d||d==c?a:d)+""};return function(b,c){return(b+"").replace(/\{([^\}]+)\}/g,function(b,d){return a(b,d,c)})}}(),c.ninja=function(){return A.was?z.win.Raphael=A.is:delete Raphael,c},c.st=ib,function(a,b,d){function e(){/in/.test(a.readyState)?setTimeout(e,9):c.eve("raphael.DOMload")}null==a.readyState&&a.addEventListener&&(a.addEventListener(b,d=function(){a.removeEventListener(b,d,!1),a.readyState="complete"},!1),a.readyState="loading"),e()}(document,"DOMContentLoaded"),b.on("raphael.DOMload",function(){u=!0}),function(){if(c.svg){var a="hasOwnProperty",b=String,d=parseFloat,e=parseInt,f=Math,g=f.max,h=f.abs,i=f.pow,j=/[, ]+/,k=c.eve,l="",m=" ",n="http://www.w3.org/1999/xlink",o={block:"M5,0 0,2.5 5,5z",classic:"M5,0 0,2.5 5,5 3.5,3 3.5,2z",diamond:"M2.5,0 5,2.5 2.5,5 0,2.5z",open:"M6,1 1,3.5 6,6",oval:"M2.5,0A2.5,2.5,0,0,1,2.5,5 2.5,2.5,0,0,1,2.5,0z"},p={};c.toString=function(){return"Your browser supports SVG.\nYou are running Raphaël "+this.version};var q=function(d,e){if(e){"string"==typeof d&&(d=q(d));for(var f in e)e[a](f)&&("xlink:"==f.substring(0,6)?d.setAttributeNS(n,f.substring(6),b(e[f])):d.setAttribute(f,b(e[f])))}else d=c._g.doc.createElementNS("http://www.w3.org/2000/svg",d),d.style&&(d.style.webkitTapHighlightColor="rgba(0,0,0,0)");return d},r=function(a,e){var j="linear",k=a.id+e,m=.5,n=.5,o=a.node,p=a.paper,r=o.style,s=c._g.doc.getElementById(k);if(!s){if(e=b(e).replace(c._radial_gradient,function(a,b,c){if(j="radial",b&&c){m=d(b),n=d(c);var e=2*(n>.5)-1;i(m-.5,2)+i(n-.5,2)>.25&&(n=f.sqrt(.25-i(m-.5,2))*e+.5)&&.5!=n&&(n=n.toFixed(5)-1e-5*e)}return l}),e=e.split(/\s*\-\s*/),"linear"==j){var t=e.shift();if(t=-d(t),isNaN(t))return null;var u=[0,0,f.cos(c.rad(t)),f.sin(c.rad(t))],v=1/(g(h(u[2]),h(u[3]))||1);u[2]*=v,u[3]*=v,0>u[2]&&(u[0]=-u[2],u[2]=0),0>u[3]&&(u[1]=-u[3],u[3]=0)}var w=c._parseDots(e);if(!w)return null;if(k=k.replace(/[\(\)\s,\xb0#]/g,"_"),a.gradient&&k!=a.gradient.id&&(p.defs.removeChild(a.gradient),delete a.gradient),!a.gradient){s=q(j+"Gradient",{id:k}),a.gradient=s,q(s,"radial"==j?{fx:m,fy:n}:{x1:u[0],y1:u[1],x2:u[2],y2:u[3],gradientTransform:a.matrix.invert()}),p.defs.appendChild(s);for(var x=0,y=w.length;y>x;x++)s.appendChild(q("stop",{offset:w[x].offset?w[x].offset:x?"100%":"0%","stop-color":w[x].color||"#fff"}))}}return q(o,{fill:"url(#"+k+")",opacity:1,"fill-opacity":1}),r.fill=l,r.opacity=1,r.fillOpacity=1,1},s=function(a){var b=a.getBBox(1);q(a.pattern,{patternTransform:a.matrix.invert()+" translate("+b.x+","+b.y+")"})},t=function(d,e,f){if("path"==d.type){for(var g,h,i,j,k,m=b(e).toLowerCase().split("-"),n=d.paper,r=f?"end":"start",s=d.node,t=d.attrs,u=t["stroke-width"],v=m.length,w="classic",x=3,y=3,z=5;v--;)switch(m[v]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":w=m[v];break;case"wide":y=5;break;case"narrow":y=2;break;case"long":x=5;break;case"short":x=2}if("open"==w?(x+=2,y+=2,z+=2,i=1,j=f?4:1,k={fill:"none",stroke:t.stroke}):(j=i=x/2,k={fill:t.stroke,stroke:"none"}),d._.arrows?f?(d._.arrows.endPath&&p[d._.arrows.endPath]--,d._.arrows.endMarker&&p[d._.arrows.endMarker]--):(d._.arrows.startPath&&p[d._.arrows.startPath]--,d._.arrows.startMarker&&p[d._.arrows.startMarker]--):d._.arrows={},"none"!=w){var A="raphael-marker-"+w,B="raphael-marker-"+r+w+x+y;c._g.doc.getElementById(A)?p[A]++:(n.defs.appendChild(q(q("path"),{"stroke-linecap":"round",d:o[w],id:A})),p[A]=1);var C,D=c._g.doc.getElementById(B);D?(p[B]++,C=D.getElementsByTagName("use")[0]):(D=q(q("marker"),{id:B,markerHeight:y,markerWidth:x,orient:"auto",refX:j,refY:y/2}),C=q(q("use"),{"xlink:href":"#"+A,transform:(f?"rotate(180 "+x/2+" "+y/2+") ":l)+"scale("+x/z+","+y/z+")","stroke-width":(1/((x/z+y/z)/2)).toFixed(4)}),D.appendChild(C),n.defs.appendChild(D),p[B]=1),q(C,k);var E=i*("diamond"!=w&&"oval"!=w);f?(g=d._.arrows.startdx*u||0,h=c.getTotalLength(t.path)-E*u):(g=E*u,h=c.getTotalLength(t.path)-(d._.arrows.enddx*u||0)),k={},k["marker-"+r]="url(#"+B+")",(h||g)&&(k.d=c.getSubpath(t.path,g,h)),q(s,k),d._.arrows[r+"Path"]=A,d._.arrows[r+"Marker"]=B,d._.arrows[r+"dx"]=E,d._.arrows[r+"Type"]=w,d._.arrows[r+"String"]=e}else f?(g=d._.arrows.startdx*u||0,h=c.getTotalLength(t.path)-g):(g=0,h=c.getTotalLength(t.path)-(d._.arrows.enddx*u||0)),d._.arrows[r+"Path"]&&q(s,{d:c.getSubpath(t.path,g,h)}),delete d._.arrows[r+"Path"],delete d._.arrows[r+"Marker"],delete d._.arrows[r+"dx"],delete d._.arrows[r+"Type"],delete d._.arrows[r+"String"];for(k in p)if(p[a](k)&&!p[k]){var F=c._g.doc.getElementById(k);F&&F.parentNode.removeChild(F)}}},u={"":[0],none:[0],"-":[3,1],".":[1,1],"-.":[3,1,1,1],"-..":[3,1,1,1,1,1],". ":[1,3],"- ":[4,3],"--":[8,3],"- .":[4,3,1,3],"--.":[8,3,1,3],"--..":[8,3,1,3,1,3]},v=function(a,c,d){if(c=u[b(c).toLowerCase()]){for(var e=a.attrs["stroke-width"]||"1",f={round:e,square:e,butt:0}[a.attrs["stroke-linecap"]||d["stroke-linecap"]]||0,g=[],h=c.length;h--;)g[h]=c[h]*e+(h%2?1:-1)*f;q(a.node,{"stroke-dasharray":g.join(",")})}},w=function(d,f){var i=d.node,k=d.attrs,m=i.style.visibility;i.style.visibility="hidden";for(var o in f)if(f[a](o)){if(!c._availableAttrs[a](o))continue;var p=f[o];switch(k[o]=p,o){case"blur":d.blur(p);break;case"href":case"title":case"target":var u=i.parentNode;if("a"!=u.tagName.toLowerCase()){var w=q("a");u.insertBefore(w,i),w.appendChild(i),u=w}"target"==o?u.setAttributeNS(n,"show","blank"==p?"new":p):u.setAttributeNS(n,o,p);break;case"cursor":i.style.cursor=p;break;case"transform":d.transform(p);break;case"arrow-start":t(d,p);break;case"arrow-end":t(d,p,1);break;case"clip-rect":var y=b(p).split(j);if(4==y.length){d.clip&&d.clip.parentNode.parentNode.removeChild(d.clip.parentNode);var z=q("clipPath"),A=q("rect");z.id=c.createUUID(),q(A,{x:y[0],y:y[1],width:y[2],height:y[3]}),z.appendChild(A),d.paper.defs.appendChild(z),q(i,{"clip-path":"url(#"+z.id+")"}),d.clip=A}if(!p){var B=i.getAttribute("clip-path");if(B){var C=c._g.doc.getElementById(B.replace(/(^url\(#|\)$)/g,l));C&&C.parentNode.removeChild(C),q(i,{"clip-path":l}),delete d.clip}}break;case"path":"path"==d.type&&(q(i,{d:p?k.path=c._pathToAbsolute(p):"M0,0"}),d._.dirty=1,d._.arrows&&("startString"in d._.arrows&&t(d,d._.arrows.startString),"endString"in d._.arrows&&t(d,d._.arrows.endString,1)));break;case"width":if(i.setAttribute(o,p),d._.dirty=1,!k.fx)break;o="x",p=k.x;case"x":k.fx&&(p=-k.x-(k.width||0));case"rx":if("rx"==o&&"rect"==d.type)break;case"cx":i.setAttribute(o,p),d.pattern&&s(d),d._.dirty=1;break;case"height":if(i.setAttribute(o,p),d._.dirty=1,!k.fy)break;o="y",p=k.y;case"y":k.fy&&(p=-k.y-(k.height||0));case"ry":if("ry"==o&&"rect"==d.type)break;case"cy":i.setAttribute(o,p),d.pattern&&s(d),d._.dirty=1;break;case"r":"rect"==d.type?q(i,{rx:p,ry:p}):i.setAttribute(o,p),d._.dirty=1;break;case"src":"image"==d.type&&i.setAttributeNS(n,"href",p);break;case"stroke-width":(1!=d._.sx||1!=d._.sy)&&(p/=g(h(d._.sx),h(d._.sy))||1),d.paper._vbSize&&(p*=d.paper._vbSize),i.setAttribute(o,p),k["stroke-dasharray"]&&v(d,k["stroke-dasharray"],f),d._.arrows&&("startString"in d._.arrows&&t(d,d._.arrows.startString),"endString"in d._.arrows&&t(d,d._.arrows.endString,1));break;case"stroke-dasharray":v(d,p,f);break;case"fill":var D=b(p).match(c._ISURL);if(D){z=q("pattern");var E=q("image");z.id=c.createUUID(),q(z,{x:0,y:0,patternUnits:"userSpaceOnUse",height:1,width:1}),q(E,{x:0,y:0,"xlink:href":D[1]}),z.appendChild(E),function(a){c._preload(D[1],function(){var b=this.offsetWidth,c=this.offsetHeight;q(a,{width:b,height:c}),q(E,{width:b,height:c}),d.paper.safari()})}(z),d.paper.defs.appendChild(z),q(i,{fill:"url(#"+z.id+")"}),d.pattern=z,d.pattern&&s(d);break}var F=c.getRGB(p);if(F.error){if(("circle"==d.type||"ellipse"==d.type||"r"!=b(p).charAt())&&r(d,p)){if("opacity"in k||"fill-opacity"in k){var G=c._g.doc.getElementById(i.getAttribute("fill").replace(/^url\(#|\)$/g,l));if(G){var H=G.getElementsByTagName("stop");q(H[H.length-1],{"stop-opacity":("opacity"in k?k.opacity:1)*("fill-opacity"in k?k["fill-opacity"]:1)})}}k.gradient=p,k.fill="none";break}}else delete f.gradient,delete k.gradient,!c.is(k.opacity,"undefined")&&c.is(f.opacity,"undefined")&&q(i,{opacity:k.opacity}),!c.is(k["fill-opacity"],"undefined")&&c.is(f["fill-opacity"],"undefined")&&q(i,{"fill-opacity":k["fill-opacity"]});F[a]("opacity")&&q(i,{"fill-opacity":F.opacity>1?F.opacity/100:F.opacity});case"stroke":F=c.getRGB(p),i.setAttribute(o,F.hex),"stroke"==o&&F[a]("opacity")&&q(i,{"stroke-opacity":F.opacity>1?F.opacity/100:F.opacity}),"stroke"==o&&d._.arrows&&("startString"in d._.arrows&&t(d,d._.arrows.startString),"endString"in d._.arrows&&t(d,d._.arrows.endString,1));break;case"gradient":("circle"==d.type||"ellipse"==d.type||"r"!=b(p).charAt())&&r(d,p);break;case"opacity":k.gradient&&!k[a]("stroke-opacity")&&q(i,{"stroke-opacity":p>1?p/100:p});case"fill-opacity":if(k.gradient){G=c._g.doc.getElementById(i.getAttribute("fill").replace(/^url\(#|\)$/g,l)),G&&(H=G.getElementsByTagName("stop"),q(H[H.length-1],{"stop-opacity":p}));break}default:"font-size"==o&&(p=e(p,10)+"px");var I=o.replace(/(\-.)/g,function(a){return a.substring(1).toUpperCase()});i.style[I]=p,d._.dirty=1,i.setAttribute(o,p)}}x(d,f),i.style.visibility=m},x=function(d,f){if("text"==d.type&&(f[a]("text")||f[a]("font")||f[a]("font-size")||f[a]("x")||f[a]("y"))){var g=d.attrs,h=d.node,i=h.firstChild?e(c._g.doc.defaultView.getComputedStyle(h.firstChild,l).getPropertyValue("font-size"),10):10;if(f[a]("text")){for(g.text=f.text;h.firstChild;)h.removeChild(h.firstChild) +;for(var j,k=b(f.text).split("\n"),m=[],n=0,o=k.length;o>n;n++)j=q("tspan"),n&&q(j,{dy:1.2*i,x:g.x}),j.appendChild(c._g.doc.createTextNode(k[n])),h.appendChild(j),m[n]=j}else for(m=h.getElementsByTagName("tspan"),n=0,o=m.length;o>n;n++)n?q(m[n],{dy:1.2*i,x:g.x}):q(m[0],{dy:0});q(h,{x:g.x,y:g.y}),d._.dirty=1;var p=d._getBBox(),r=g.y-(p.y+p.height/2);r&&c.is(r,"finite")&&q(m[0],{dy:r})}},y=function(a,b){this[0]=this.node=a,a.raphael=!0,this.id=c._oid++,a.raphaelid=this.id,this.matrix=c.matrix(),this.realPath=null,this.paper=b,this.attrs=this.attrs||{},this._={transform:[],sx:1,sy:1,deg:0,dx:0,dy:0,dirty:1},!b.bottom&&(b.bottom=this),this.prev=b.top,b.top&&(b.top.next=this),b.top=this,this.next=null},z=c.el;y.prototype=z,z.constructor=y,c._engine.path=function(a,b){var c=q("path");b.canvas&&b.canvas.appendChild(c);var d=new y(c,b);return d.type="path",w(d,{fill:"none",stroke:"#000",path:a}),d},z.rotate=function(a,c,e){if(this.removed)return this;if(a=b(a).split(j),a.length-1&&(c=d(a[1]),e=d(a[2])),a=d(a[0]),null==e&&(c=e),null==c||null==e){var f=this.getBBox(1);c=f.x+f.width/2,e=f.y+f.height/2}return this.transform(this._.transform.concat([["r",a,c,e]])),this},z.scale=function(a,c,e,f){if(this.removed)return this;if(a=b(a).split(j),a.length-1&&(c=d(a[1]),e=d(a[2]),f=d(a[3])),a=d(a[0]),null==c&&(c=a),null==f&&(e=f),null==e||null==f)var g=this.getBBox(1);return e=null==e?g.x+g.width/2:e,f=null==f?g.y+g.height/2:f,this.transform(this._.transform.concat([["s",a,c,e,f]])),this},z.translate=function(a,c){return this.removed?this:(a=b(a).split(j),a.length-1&&(c=d(a[1])),a=d(a[0])||0,c=+c||0,this.transform(this._.transform.concat([["t",a,c]])),this)},z.transform=function(b){var d=this._;if(null==b)return d.transform;if(c._extractTransform(this,b),this.clip&&q(this.clip,{transform:this.matrix.invert()}),this.pattern&&s(this),this.node&&q(this.node,{transform:this.matrix}),1!=d.sx||1!=d.sy){var e=this.attrs[a]("stroke-width")?this.attrs["stroke-width"]:1;this.attr({"stroke-width":e})}return this},z.hide=function(){return!this.removed&&this.paper.safari(this.node.style.display="none"),this},z.show=function(){return!this.removed&&this.paper.safari(this.node.style.display=""),this},z.remove=function(){if(!this.removed&&this.node.parentNode){var a=this.paper;a.__set__&&a.__set__.exclude(this),k.unbind("raphael.*.*."+this.id),this.gradient&&a.defs.removeChild(this.gradient),c._tear(this,a),"a"==this.node.parentNode.tagName.toLowerCase()?this.node.parentNode.parentNode.removeChild(this.node.parentNode):this.node.parentNode.removeChild(this.node);for(var b in this)this[b]="function"==typeof this[b]?c._removedFactory(b):null;this.removed=!0}},z._getBBox=function(){if("none"==this.node.style.display){this.show();var a=!0}var b={};try{b=this.node.getBBox()}catch(a){}finally{b=b||{}}return a&&this.hide(),b},z.attr=function(b,d){if(this.removed)return this;if(null==b){var e={};for(var f in this.attrs)this.attrs[a](f)&&(e[f]=this.attrs[f]);return e.gradient&&"none"==e.fill&&(e.fill=e.gradient)&&delete e.gradient,e.transform=this._.transform,e}if(null==d&&c.is(b,"string")){if("fill"==b&&"none"==this.attrs.fill&&this.attrs.gradient)return this.attrs.gradient;if("transform"==b)return this._.transform;for(var g=b.split(j),h={},i=0,l=g.length;l>i;i++)b=g[i],h[b]=b in this.attrs?this.attrs[b]:c.is(this.paper.customAttributes[b],"function")?this.paper.customAttributes[b].def:c._availableAttrs[b];return l-1?h:h[g[0]]}if(null==d&&c.is(b,"array")){for(h={},i=0,l=b.length;l>i;i++)h[b[i]]=this.attr(b[i]);return h}if(null!=d){var m={};m[b]=d}else null!=b&&c.is(b,"object")&&(m=b);for(var n in m)k("raphael.attr."+n+"."+this.id,this,m[n]);for(n in this.paper.customAttributes)if(this.paper.customAttributes[a](n)&&m[a](n)&&c.is(this.paper.customAttributes[n],"function")){var o=this.paper.customAttributes[n].apply(this,[].concat(m[n]));this.attrs[n]=m[n];for(var p in o)o[a](p)&&(m[p]=o[p])}return w(this,m),this},z.toFront=function(){if(this.removed)return this;"a"==this.node.parentNode.tagName.toLowerCase()?this.node.parentNode.parentNode.appendChild(this.node.parentNode):this.node.parentNode.appendChild(this.node);var a=this.paper;return a.top!=this&&c._tofront(this,a),this},z.toBack=function(){if(this.removed)return this;var a=this.node.parentNode;return"a"==a.tagName.toLowerCase()?a.parentNode.insertBefore(this.node.parentNode,this.node.parentNode.parentNode.firstChild):a.firstChild!=this.node&&a.insertBefore(this.node,this.node.parentNode.firstChild),c._toback(this,this.paper),this.paper,this},z.insertAfter=function(a){if(this.removed)return this;var b=a.node||a[a.length-1].node;return b.nextSibling?b.parentNode.insertBefore(this.node,b.nextSibling):b.parentNode.appendChild(this.node),c._insertafter(this,a,this.paper),this},z.insertBefore=function(a){if(this.removed)return this;var b=a.node||a[0].node;return b.parentNode.insertBefore(this.node,b),c._insertbefore(this,a,this.paper),this},z.blur=function(a){var b=this;if(0!==+a){var d=q("filter"),e=q("feGaussianBlur");b.attrs.blur=a,d.id=c.createUUID(),q(e,{stdDeviation:+a||1.5}),d.appendChild(e),b.paper.defs.appendChild(d),b._blur=d,q(b.node,{filter:"url(#"+d.id+")"})}else b._blur&&(b._blur.parentNode.removeChild(b._blur),delete b._blur,delete b.attrs.blur),b.node.removeAttribute("filter");return b},c._engine.circle=function(a,b,c,d){var e=q("circle");a.canvas&&a.canvas.appendChild(e);var f=new y(e,a);return f.attrs={cx:b,cy:c,r:d,fill:"none",stroke:"#000"},f.type="circle",q(e,f.attrs),f},c._engine.rect=function(a,b,c,d,e,f){var g=q("rect");a.canvas&&a.canvas.appendChild(g);var h=new y(g,a);return h.attrs={x:b,y:c,width:d,height:e,r:f||0,rx:f||0,ry:f||0,fill:"none",stroke:"#000"},h.type="rect",q(g,h.attrs),h},c._engine.ellipse=function(a,b,c,d,e){var f=q("ellipse");a.canvas&&a.canvas.appendChild(f);var g=new y(f,a);return g.attrs={cx:b,cy:c,rx:d,ry:e,fill:"none",stroke:"#000"},g.type="ellipse",q(f,g.attrs),g},c._engine.image=function(a,b,c,d,e,f){var g=q("image");q(g,{x:c,y:d,width:e,height:f,preserveAspectRatio:"none"}),g.setAttributeNS(n,"href",b),a.canvas&&a.canvas.appendChild(g);var h=new y(g,a);return h.attrs={x:c,y:d,width:e,height:f,src:b},h.type="image",h},c._engine.text=function(a,b,d,e){var f=q("text");a.canvas&&a.canvas.appendChild(f);var g=new y(f,a);return g.attrs={x:b,y:d,"text-anchor":"middle",text:e,font:c._availableAttrs.font,stroke:"none",fill:"#000"},g.type="text",w(g,g.attrs),g},c._engine.setSize=function(a,b){return this.width=a||this.width,this.height=b||this.height,this.canvas.setAttribute("width",this.width),this.canvas.setAttribute("height",this.height),this._viewBox&&this.setViewBox.apply(this,this._viewBox),this},c._engine.create=function(){var a=c._getContainer.apply(0,arguments),b=a&&a.container,d=a.x,e=a.y,f=a.width,g=a.height;if(!b)throw Error("SVG container not found.");var h,i=q("svg"),j="overflow:hidden;";return d=d||0,e=e||0,f=f||512,g=g||342,q(i,{height:g,version:1.1,width:f,xmlns:"http://www.w3.org/2000/svg"}),1==b?(i.style.cssText=j+"position:absolute;left:"+d+"px;top:"+e+"px",c._g.doc.body.appendChild(i),h=1):(i.style.cssText=j+"position:relative",b.firstChild?b.insertBefore(i,b.firstChild):b.appendChild(i)),b=new c._Paper,b.width=f,b.height=g,b.canvas=i,b.clear(),b._left=b._top=0,h&&(b.renderfix=function(){}),b.renderfix(),b},c._engine.setViewBox=function(a,b,c,d,e){k("raphael.setViewBox",this,this._viewBox,[a,b,c,d,e]);var f,h,i=g(c/this.width,d/this.height),j=this.top,l=e?"meet":"xMinYMin";for(null==a?(this._vbSize&&(i=1),delete this._vbSize,f="0 0 "+this.width+m+this.height):(this._vbSize=i,f=a+m+b+m+c+m+d),q(this.canvas,{viewBox:f,preserveAspectRatio:l});i&&j;)h="stroke-width"in j.attrs?j.attrs["stroke-width"]:1,j.attr({"stroke-width":h}),j._.dirty=1,j._.dirtyT=1,j=j.prev;return this._viewBox=[a,b,c,d,!!e],this},c.prototype.renderfix=function(){var a,b=this.canvas,c=b.style;try{a=b.getScreenCTM()||b.createSVGMatrix()}catch(c){a=b.createSVGMatrix()}var d=-a.e%1,e=-a.f%1;(d||e)&&(d&&(this._left=(this._left+d)%1,c.left=this._left+"px"),e&&(this._top=(this._top+e)%1,c.top=this._top+"px"))},c.prototype.clear=function(){c.eve("raphael.clear",this);for(var a=this.canvas;a.firstChild;)a.removeChild(a.firstChild);this.bottom=this.top=null,(this.desc=q("desc")).appendChild(c._g.doc.createTextNode("Created with Raphaël "+c.version)),a.appendChild(this.desc),a.appendChild(this.defs=q("defs"))},c.prototype.remove=function(){k("raphael.remove",this),this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas);for(var a in this)this[a]="function"==typeof this[a]?c._removedFactory(a):null};var A=c.st;for(var B in z)z[a](B)&&!A[a](B)&&(A[B]=function(a){return function(){var b=arguments;return this.forEach(function(c){c[a].apply(c,b)})}}(B))}}(),function(){if(c.vml){var a="hasOwnProperty",b=String,d=parseFloat,e=Math,f=e.round,g=e.max,h=e.min,i=e.abs,j="fill",k=/[, ]+/,l=c.eve,m=" ",n="",o={M:"m",L:"l",C:"c",Z:"x",m:"t",l:"r",c:"v",z:"x"},p="position:absolute;left:0;top:0;width:1px;height:1px",q=21600,r={path:1,rect:1,image:1},s={circle:1,ellipse:1},t=function(a){var d=/[ahqstv]/gi,e=c._pathToAbsolute;if(b(a).match(d)&&(e=c._path2curve),d=/[clmz]/g,e==c._pathToAbsolute&&!b(a).match(d)){var g=b(a).replace(/([clmz]),?([^clmz]*)/gi,function(a,b,c){var d=[],e="m"==b.toLowerCase(),g=o[b];return c.replace(/-?[^,\s-]+/g,function(a){e&&2==d.length&&(g+=d+o["m"==b?"l":"L"],d=[]),d.push(f(a*q))}),g+d});return g}var h,i,j=e(a);g=[];for(var k=0,l=j.length;l>k;k++){h=j[k],i=j[k][0].toLowerCase(),"z"==i&&(i="x");for(var p=1,r=h.length;r>p;p++)i+=f(h[p]*q)+(p!=r-1?",":n);g.push(i)}return g.join(m)},u=function(a,b,d){var e=c.matrix();return e.rotate(-a,.5,.5),{dx:e.x(b,d),dy:e.y(b,d)}},v=function(a,b,c,d,e,f){var g=a._,h=a.matrix,k=g.fillpos,l=a.node,n=l.style,o=1,p="",r=q/b,s=q/c;if(n.visibility="hidden",b&&c){if(l.coordsize=i(r)+m+i(s),n.rotation=f*(0>b*c?-1:1),f){var t=u(f,d,e);d=t.dx,e=t.dy}if(0>b&&(p+="x"),0>c&&(p+=" y")&&(o=-1),n.flip=p,l.coordorigin=d*-r+m+e*-s,k||g.fillsize){var v=l.getElementsByTagName(j);v=v&&v[0],l.removeChild(v),k&&(t=u(f,h.x(k[0],k[1]),h.y(k[0],k[1])),v.position=t.dx*o+m+t.dy*o),g.fillsize&&(v.size=g.fillsize[0]*i(b)+m+g.fillsize[1]*i(c)),l.appendChild(v)}n.visibility="visible"}};c.toString=function(){return"Your browser doesn’t support SVG. Falling down to VML.\nYou are running Raphaël "+this.version};var w=function(a,c,d){for(var e=b(c).toLowerCase().split("-"),f=d?"end":"start",g=e.length,h="classic",i="medium",j="medium";g--;)switch(e[g]){case"block":case"classic":case"oval":case"diamond":case"open":case"none":h=e[g];break;case"wide":case"narrow":j=e[g];break;case"long":case"short":i=e[g]}var k=a.node.getElementsByTagName("stroke")[0];k[f+"arrow"]=h,k[f+"arrowlength"]=i,k[f+"arrowwidth"]=j},x=function(e,i){e.attrs=e.attrs||{};var l=e.node,o=e.attrs,p=l.style,u=r[e.type]&&(i.x!=o.x||i.y!=o.y||i.width!=o.width||i.height!=o.height||i.cx!=o.cx||i.cy!=o.cy||i.rx!=o.rx||i.ry!=o.ry||i.r!=o.r),x=s[e.type]&&(o.cx!=i.cx||o.cy!=i.cy||o.r!=i.r||o.rx!=i.rx||o.ry!=i.ry),z=e;for(var A in i)i[a](A)&&(o[A]=i[A]);if(u&&(o.path=c._getPath[e.type](e),e._.dirty=1),i.href&&(l.href=i.href),i.title&&(l.title=i.title),i.target&&(l.target=i.target),i.cursor&&(p.cursor=i.cursor),"blur"in i&&e.blur(i.blur),(i.path&&"path"==e.type||u)&&(l.path=t(~b(o.path).toLowerCase().indexOf("r")?c._pathToAbsolute(o.path):o.path),"image"==e.type&&(e._.fillpos=[o.x,o.y],e._.fillsize=[o.width,o.height],v(e,1,1,0,0,0))),"transform"in i&&e.transform(i.transform),x){var C=+o.cx,D=+o.cy,E=+o.rx||+o.r||0,F=+o.ry||+o.r||0;l.path=c.format("ar{0},{1},{2},{3},{4},{1},{4},{1}x",f((C-E)*q),f((D-F)*q),f((C+E)*q),f((D+F)*q),f(C*q)),e._.dirty=1}if("clip-rect"in i){var G=b(i["clip-rect"]).split(k);if(4==G.length){G[2]=+G[2]+ +G[0],G[3]=+G[3]+ +G[1];var H=l.clipRect||c._g.doc.createElement("div"),I=H.style;I.clip=c.format("rect({1}px {2}px {3}px {0}px)",G),l.clipRect||(I.position="absolute",I.top=0,I.left=0,I.width=e.paper.width+"px",I.height=e.paper.height+"px",l.parentNode.insertBefore(H,l),H.appendChild(l),l.clipRect=H)}i["clip-rect"]||l.clipRect&&(l.clipRect.style.clip="auto")}if(e.textpath){var J=e.textpath.style;i.font&&(J.font=i.font),i["font-family"]&&(J.fontFamily='"'+i["font-family"].split(",")[0].replace(/^['"]+|['"]+$/g,n)+'"'),i["font-size"]&&(J.fontSize=i["font-size"]),i["font-weight"]&&(J.fontWeight=i["font-weight"]),i["font-style"]&&(J.fontStyle=i["font-style"])}if("arrow-start"in i&&w(z,i["arrow-start"]),"arrow-end"in i&&w(z,i["arrow-end"],1),null!=i.opacity||null!=i["stroke-width"]||null!=i.fill||null!=i.src||null!=i.stroke||null!=i["stroke-width"]||null!=i["stroke-opacity"]||null!=i["fill-opacity"]||null!=i["stroke-dasharray"]||null!=i["stroke-miterlimit"]||null!=i["stroke-linejoin"]||null!=i["stroke-linecap"]){var K=l.getElementsByTagName(j);if(K=K&&K[0],!K&&(K=B(j)),"image"==e.type&&i.src&&(K.src=i.src),i.fill&&(K.on=!0),(null==K.on||"none"==i.fill||null===i.fill)&&(K.on=!1),K.on&&i.fill){var L=b(i.fill).match(c._ISURL);if(L){K.parentNode==l&&l.removeChild(K),K.rotate=!0,K.src=L[1],K.type="tile";var M=e.getBBox(1);K.position=M.x+m+M.y,e._.fillpos=[M.x,M.y],c._preload(L[1],function(){e._.fillsize=[this.offsetWidth,this.offsetHeight]})}else K.color=c.getRGB(i.fill).hex,K.src=n,K.type="solid",c.getRGB(i.fill).error&&(z.type in{circle:1,ellipse:1}||"r"!=b(i.fill).charAt())&&y(z,i.fill,K)&&(o.fill="none",o.gradient=i.fill,K.rotate=!1)}if("fill-opacity"in i||"opacity"in i){var N=((+o["fill-opacity"]+1||2)-1)*((+o.opacity+1||2)-1)*((+c.getRGB(i.fill).o+1||2)-1);N=h(g(N,0),1),K.opacity=N,K.src&&(K.color="none")}l.appendChild(K);var O=l.getElementsByTagName("stroke")&&l.getElementsByTagName("stroke")[0],P=!1;!O&&(P=O=B("stroke")),(i.stroke&&"none"!=i.stroke||i["stroke-width"]||null!=i["stroke-opacity"]||i["stroke-dasharray"]||i["stroke-miterlimit"]||i["stroke-linejoin"]||i["stroke-linecap"])&&(O.on=!0),("none"==i.stroke||null===i.stroke||null==O.on||0==i.stroke||0==i["stroke-width"])&&(O.on=!1);var Q=c.getRGB(i.stroke);O.on&&i.stroke&&(O.color=Q.hex),N=((+o["stroke-opacity"]+1||2)-1)*((+o.opacity+1||2)-1)*((+Q.o+1||2)-1);var R=.75*(d(i["stroke-width"])||1);if(N=h(g(N,0),1),null==i["stroke-width"]&&(R=o["stroke-width"]),i["stroke-width"]&&(O.weight=R),R&&1>R&&(N*=R)&&(O.weight=1),O.opacity=N,i["stroke-linejoin"]&&(O.joinstyle=i["stroke-linejoin"]||"miter"),O.miterlimit=i["stroke-miterlimit"]||8,i["stroke-linecap"]&&(O.endcap="butt"==i["stroke-linecap"]?"flat":"square"==i["stroke-linecap"]?"square":"round"),i["stroke-dasharray"]){var S={"-":"shortdash",".":"shortdot","-.":"shortdashdot","-..":"shortdashdotdot",". ":"dot","- ":"dash","--":"longdash","- .":"dashdot","--.":"longdashdot","--..":"longdashdotdot"};O.dashstyle=S[a](i["stroke-dasharray"])?S[i["stroke-dasharray"]]:n}P&&l.appendChild(O)}if("text"==z.type){z.paper.canvas.style.display=n;var T=z.paper.span,U=o.font&&o.font.match(/\d+(?:\.\d*)?(?=px)/);p=T.style,o.font&&(p.font=o.font),o["font-family"]&&(p.fontFamily=o["font-family"]),o["font-weight"]&&(p.fontWeight=o["font-weight"]),o["font-style"]&&(p.fontStyle=o["font-style"]),U=d(o["font-size"]||U&&U[0])||10,p.fontSize=100*U+"px",z.textpath.string&&(T.innerHTML=b(z.textpath.string).replace(/"));var V=T.getBoundingClientRect();z.W=o.w=(V.right-V.left)/100,z.H=o.h=(V.bottom-V.top)/100,z.X=o.x,z.Y=o.y+z.H/2,("x"in i||"y"in i)&&(z.path.v=c.format("m{0},{1}l{2},{1}",f(o.x*q),f(o.y*q),f(o.x*q)+1));for(var W=["x","y","text","font","font-family","font-weight","font-style","font-size"],X=0;8>X;X++)if(W[X]in i){z._.dirty=1;break}switch(o["text-anchor"]){case"start":z.textpath.style["v-text-align"]="left",z.bbx=z.W/2;break;case"end":z.textpath.style["v-text-align"]="right",z.bbx=-z.W/2;break;default:z.textpath.style["v-text-align"]="center",z.bbx=0}z.textpath.style["v-text-kern"]=!0}},y=function(a,f,g){a.attrs=a.attrs||{};var h=(a.attrs,Math.pow),i="linear",j=".5 .5";if(a.attrs.gradient=f,f=b(f).replace(c._radial_gradient,function(a,b,c){return i="radial",b&&c&&(b=d(b),c=d(c),h(b-.5,2)+h(c-.5,2)>.25&&(c=e.sqrt(.25-h(b-.5,2))*(2*(c>.5)-1)+.5),j=b+m+c),n}),f=f.split(/\s*\-\s*/),"linear"==i){var k=f.shift();if(k=-d(k),isNaN(k))return null}var l=c._parseDots(f);if(!l)return null;if(a=a.shape||a.node,l.length){a.removeChild(g),g.on=!0,g.method="none",g.color=l[0].color,g.color2=l[l.length-1].color;for(var o=[],p=0,q=l.length;q>p;p++)l[p].offset&&o.push(l[p].offset+m+l[p].color);g.colors=o.length?o.join():"0% "+g.color,"radial"==i?(g.type="gradientTitle",g.focus="100%",g.focussize="0 0",g.focusposition=j,g.angle=0):(g.type="gradient",g.angle=(270-k)%360),a.appendChild(g)}return 1},z=function(a,b){this[0]=this.node=a,a.raphael=!0,this.id=c._oid++,a.raphaelid=this.id,this.X=0,this.Y=0,this.attrs={},this.paper=b,this.matrix=c.matrix(),this._={transform:[],sx:1,sy:1,dx:0,dy:0,deg:0,dirty:1,dirtyT:1},!b.bottom&&(b.bottom=this),this.prev=b.top,b.top&&(b.top.next=this),b.top=this,this.next=null},A=c.el;z.prototype=A,A.constructor=z,A.transform=function(a){if(null==a)return this._.transform;var d,e=this.paper._viewBoxShift,f=e?"s"+[e.scale,e.scale]+"-1-1t"+[e.dx,e.dy]:n;e&&(d=a=b(a).replace(/\.{3}|\u2026/g,this._.transform||n)),c._extractTransform(this,f+a);var g,h=this.matrix.clone(),i=this.skew,j=this.node,k=~b(this.attrs.fill).indexOf("-"),l=!b(this.attrs.fill).indexOf("url(");if(h.translate(-.5,-.5),l||k||"image"==this.type)if(i.matrix="1 0 0 1",i.offset="0 0",g=h.split(),k&&g.noRotation||!g.isSimple){j.style.filter=h.toFilter();var o=this.getBBox(),p=this.getBBox(1),r=o.x-p.x,s=o.y-p.y;j.coordorigin=r*-q+m+s*-q,v(this,1,1,r,s,0)}else j.style.filter=n,v(this,g.scalex,g.scaley,g.dx,g.dy,g.rotate);else j.style.filter=n,i.matrix=b(h),i.offset=h.offset();return d&&(this._.transform=d),this},A.rotate=function(a,c,e){if(this.removed)return this;if(null!=a){if(a=b(a).split(k),a.length-1&&(c=d(a[1]),e=d(a[2])),a=d(a[0]),null==e&&(c=e),null==c||null==e){var f=this.getBBox(1);c=f.x+f.width/2,e=f.y+f.height/2}return this._.dirtyT=1,this.transform(this._.transform.concat([["r",a,c,e]])),this}},A.translate=function(a,c){return this.removed?this:(a=b(a).split(k),a.length-1&&(c=d(a[1])),a=d(a[0])||0,c=+c||0,this._.bbox&&(this._.bbox.x+=a,this._.bbox.y+=c),this.transform(this._.transform.concat([["t",a,c]])),this)},A.scale=function(a,c,e,f){if(this.removed)return this;if(a=b(a).split(k),a.length-1&&(c=d(a[1]),e=d(a[2]),f=d(a[3]),isNaN(e)&&(e=null),isNaN(f)&&(f=null)),a=d(a[0]),null==c&&(c=a),null==f&&(e=f),null==e||null==f)var g=this.getBBox(1);return e=null==e?g.x+g.width/2:e,f=null==f?g.y+g.height/2:f,this.transform(this._.transform.concat([["s",a,c,e,f]])),this._.dirtyT=1,this},A.hide=function(){return!this.removed&&(this.node.style.display="none"),this},A.show=function(){return!this.removed&&(this.node.style.display=n),this},A._getBBox=function(){return this.removed?{}:{x:this.X+(this.bbx||0)-this.W/2,y:this.Y-this.H,width:this.W,height:this.H}},A.remove=function(){if(!this.removed&&this.node.parentNode){this.paper.__set__&&this.paper.__set__.exclude(this),c.eve.unbind("raphael.*.*."+this.id),c._tear(this,this.paper),this.node.parentNode.removeChild(this.node),this.shape&&this.shape.parentNode.removeChild(this.shape);for(var a in this)this[a]="function"==typeof this[a]?c._removedFactory(a):null;this.removed=!0}},A.attr=function(b,d){if(this.removed)return this;if(null==b){var e={};for(var f in this.attrs)this.attrs[a](f)&&(e[f]=this.attrs[f]);return e.gradient&&"none"==e.fill&&(e.fill=e.gradient)&&delete e.gradient,e.transform=this._.transform,e}if(null==d&&c.is(b,"string")){if(b==j&&"none"==this.attrs.fill&&this.attrs.gradient)return this.attrs.gradient;for(var g=b.split(k),h={},i=0,m=g.length;m>i;i++)b=g[i],h[b]=b in this.attrs?this.attrs[b]:c.is(this.paper.customAttributes[b],"function")?this.paper.customAttributes[b].def:c._availableAttrs[b];return m-1?h:h[g[0]]}if(this.attrs&&null==d&&c.is(b,"array")){for(h={},i=0,m=b.length;m>i;i++)h[b[i]]=this.attr(b[i]);return h}var n;null!=d&&(n={},n[b]=d),null==d&&c.is(b,"object")&&(n=b);for(var o in n)l("raphael.attr."+o+"."+this.id,this,n[o]);if(n){for(o in this.paper.customAttributes)if(this.paper.customAttributes[a](o)&&n[a](o)&&c.is(this.paper.customAttributes[o],"function")){var p=this.paper.customAttributes[o].apply(this,[].concat(n[o]));this.attrs[o]=n[o];for(var q in p)p[a](q)&&(n[q]=p[q])}n.text&&"text"==this.type&&(this.textpath.string=n.text),x(this,n)}return this},A.toFront=function(){return!this.removed&&this.node.parentNode.appendChild(this.node),this.paper&&this.paper.top!=this&&c._tofront(this,this.paper),this},A.toBack=function(){return this.removed?this:(this.node.parentNode.firstChild!=this.node&&(this.node.parentNode.insertBefore(this.node,this.node.parentNode.firstChild),c._toback(this,this.paper)),this)},A.insertAfter=function(a){return this.removed?this:(a.constructor==c.st.constructor&&(a=a[a.length-1]),a.node.nextSibling?a.node.parentNode.insertBefore(this.node,a.node.nextSibling):a.node.parentNode.appendChild(this.node),c._insertafter(this,a,this.paper),this)},A.insertBefore=function(a){return this.removed?this:(a.constructor==c.st.constructor&&(a=a[0]),a.node.parentNode.insertBefore(this.node,a.node),c._insertbefore(this,a,this.paper),this)},A.blur=function(a){var b=this.node.runtimeStyle,d=b.filter;return d=d.replace(/ progid:\S+Blur\([^\)]+\)/g,n),0!==+a?(this.attrs.blur=a,b.filter=d+m+" progid:DXImageTransform.Microsoft.Blur(pixelradius="+(+a||1.5)+")",b.margin=c.format("-{0}px 0 0 -{0}px",f(+a||1.5))):(b.filter=d,b.margin=0,delete this.attrs.blur),this},c._engine.path=function(a,b){var c=B("shape");c.style.cssText=p,c.coordsize=q+m+q,c.coordorigin=b.coordorigin;var d=new z(c,b),e={fill:"none",stroke:"#000"};a&&(e.path=a),d.type="path",d.path=[],d.Path=n,x(d,e),b.canvas.appendChild(c);var f=B("skew");return f.on=!0,c.appendChild(f),d.skew=f,d.transform(n),d},c._engine.rect=function(a,b,d,e,f,g){var h=c._rectPath(b,d,e,f,g),i=a.path(h),j=i.attrs;return i.X=j.x=b,i.Y=j.y=d,i.W=j.width=e,i.H=j.height=f,j.r=g,j.path=h,i.type="rect",i},c._engine.ellipse=function(a,b,c,d,e){var f=a.path();return f.attrs,f.X=b-d,f.Y=c-e,f.W=2*d,f.H=2*e,f.type="ellipse",x(f,{cx:b,cy:c,rx:d,ry:e}),f},c._engine.circle=function(a,b,c,d){var e=a.path();return e.attrs,e.X=b-d,e.Y=c-d,e.W=e.H=2*d,e.type="circle",x(e,{cx:b,cy:c,r:d}),e},c._engine.image=function(a,b,d,e,f,g){var h=c._rectPath(d,e,f,g),i=a.path(h).attr({stroke:"none"}),k=i.attrs,l=i.node,m=l.getElementsByTagName(j)[0];return k.src=b,i.X=k.x=d,i.Y=k.y=e,i.W=k.width=f,i.H=k.height=g,k.path=h,i.type="image",m.parentNode==l&&l.removeChild(m),m.rotate=!0,m.src=b,m.type="tile",i._.fillpos=[d,e],i._.fillsize=[f,g],l.appendChild(m),v(i,1,1,0,0,0),i},c._engine.text=function(a,d,e,g){var h=B("shape"),i=B("path"),j=B("textpath");d=d||0,e=e||0,g=g||"",i.v=c.format("m{0},{1}l{2},{1}",f(d*q),f(e*q),f(d*q)+1),i.textpathok=!0,j.string=b(g),j.on=!0,h.style.cssText=p,h.coordsize=q+m+q,h.coordorigin="0 0";var k=new z(h,a),l={fill:"#000",stroke:"none",font:c._availableAttrs.font,text:g};k.shape=h,k.path=i,k.textpath=j,k.type="text",k.attrs.text=b(g),k.attrs.x=d,k.attrs.y=e,k.attrs.w=1,k.attrs.h=1,x(k,l),h.appendChild(j),h.appendChild(i),a.canvas.appendChild(h);var o=B("skew");return o.on=!0,h.appendChild(o),k.skew=o,k.transform(n),k},c._engine.setSize=function(a,b){var d=this.canvas.style;return this.width=a,this.height=b,a==+a&&(a+="px"),b==+b&&(b+="px"),d.width=a,d.height=b,d.clip="rect(0 "+a+" "+b+" 0)",this._viewBox&&c._engine.setViewBox.apply(this,this._viewBox),this},c._engine.setViewBox=function(a,b,d,e,f){c.eve("raphael.setViewBox",this,this._viewBox,[a,b,d,e,f]);var h,i,j=this.width,k=this.height,l=1/g(d/j,e/k);return f&&(h=k/e,i=j/d,j>d*h&&(a-=(j-d*h)/2/h),k>e*i&&(b-=(k-e*i)/2/i)),this._viewBox=[a,b,d,e,!!f],this._viewBoxShift={dx:-a,dy:-b,scale:l},this.forEach(function(a){a.transform("...")}),this};var B;c._engine.initWin=function(a){var b=a.document;b.createStyleSheet().addRule(".rvml","behavior:url(#default#VML)");try{!b.namespaces.rvml&&b.namespaces.add("rvml","urn:schemas-microsoft-com:vml"),B=function(a){return b.createElement("')}}catch(a){B=function(a){return b.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}},c._engine.initWin(c._g.win),c._engine.create=function(){var a=c._getContainer.apply(0,arguments),b=a.container,d=a.height,e=a.width,f=a.x,g=a.y;if(!b)throw Error("VML container not found.");var h=new c._Paper,i=h.canvas=c._g.doc.createElement("div"),j=i.style;return f=f||0,g=g||0,e=e||512,d=d||342,h.width=e,h.height=d,e==+e&&(e+="px"),d==+d&&(d+="px"),h.coordsize=216e5+m+216e5,h.coordorigin="0 0",h.span=c._g.doc.createElement("span"),h.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",i.appendChild(h.span),j.cssText=c.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",e,d),1==b?(c._g.doc.body.appendChild(i),j.left=f+"px",j.top=g+"px",j.position="absolute"):b.firstChild?b.insertBefore(i,b.firstChild):b.appendChild(i),h.renderfix=function(){},h},c.prototype.clear=function(){c.eve("raphael.clear",this),this.canvas.innerHTML=n,this.span=c._g.doc.createElement("span"),this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;",this.canvas.appendChild(this.span),this.bottom=this.top=null},c.prototype.remove=function(){c.eve("raphael.remove",this),this.canvas.parentNode.removeChild(this.canvas);for(var a in this)this[a]="function"==typeof this[a]?c._removedFactory(a):null;return!0};var C=c.st;for(var D in A)A[a](D)&&!C[a](D)&&(C[D]=function(a){return function(){var b=arguments;return this.forEach(function(c){c[a].apply(c,b)})}}(D))}}(),A.was?z.win.Raphael=c:Raphael=c,c});(function(){var a,b,c,d,e=[].slice,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},h=function(a,b){return function(){return a.apply(b,arguments)}},i=[].indexOf||function(a){for(var b=0,c=this.length;bc.length&&(d+=e.slice(c.length)),d):"-"},b.pad2=function(a){return(a<10?"0":"")+a},b.Grid=function(c){function d(b){var c=this;"string"==typeof b.element?this.el=a(document.getElementById(b.element)):this.el=a(b.element);if(null==this.el||0===this.el.length)throw Error("Graph container element not found");"static"===this.el.css("position")&&this.el.css("position","relative"),this.options=a.extend({},this.gridDefaults,this.defaults||{},b),"string"==typeof this.options.units&&(this.options.postUnits=b.units),this.raphael=new Raphael(this.el[0]),this.elementWidth=null,this.elementHeight=null,this.dirty=!1,this.init&&this.init(),this.setData(this.options.data),this.el.bind("mousemove",function(a){var b;return b=c.el.offset(),c.fire("hovermove",a.pageX-b.left,a.pageY-b.top)}),this.el.bind("mouseout",function(a){return c.fire("hoverout")}),this.el.bind("touchstart touchmove touchend",function(a){var b,d;return d=a.originalEvent.touches[0]||a.originalEvent.changedTouches[0],b=c.el.offset(),c.fire("hover",d.pageX-b.left,d.pageY-b.top),d}),this.el.bind("click",function(a){var b;return b=c.el.offset(),c.fire("gridclick",a.pageX-b.left,a.pageY-b.top)}),this.postInit&&this.postInit()}return g(d,c),d.prototype.gridDefaults={dateFormat:null,axes:!0,grid:!0,gridLineColor:"#aaa",gridStrokeWidth:.5,gridTextColor:"#888",gridTextSize:12,gridTextFamily:"sans-serif",gridTextWeight:"normal",hideHover:!1,yLabelFormat:null,xLabelAngle:0,numLines:5,padding:25,parseTime:!0,postUnits:"",preUnits:"",ymax:"auto",ymin:"auto 0",goals:[],goalStrokeWidth:1,goalLineColors:["#666633","#999966","#cc6666","#663333"],events:[],eventStrokeWidth:1,eventLineColors:["#005a04","#ccffbb","#3a5f0b","#005502"]},d.prototype.setData=function(a,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q;null==c&&(c=!0),this.options.data=a;if(null!=a&&0!==a.length){o=this.cumulative?0:null,p=this.cumulative?0:null,this.options.goals.length>0&&(h=Math.min.apply(null,this.options.goals),g=Math.max.apply(null,this.options.goals),p=null!=p?Math.min(p,h):h,o=null!=o?Math.max(o,g):g),this.data=function(){var c,d,g;g=[];for(f=c=0,d=a.length;cb.x)-(b.x>a.x)})),this.xmin=this.data[0].x,this.xmax=this.data[this.data.length-1].x,this.events=[],this.options.parseTime&&this.options.events.length>0&&(this.events=function(){var a,c,e,f;e=this.options.events,f=[];for(a=0,c=e.length;a=c;m=a+=k)d.push(m);return d}.call(this)));this.dirty=!0;if(c)return this.redraw()}else this.data=[],this.raphael.clear(),null!=this.hover&&this.hover.hide()},d.prototype.yboundary=function(a,b){var c,d;return c=this.options["y"+a],"string"==typeof c?"auto"===c.slice(0,4)?c.length>5?(d=parseInt(c.slice(5),10),null==b?d:Math[a](b,d)):null!=b?b:0:parseInt(c,10):c},d.prototype.autoGridLines=function(a,b,c){var d,e,f,g,h,i,j,k,l;return h=b-a,l=Math.floor(Math.log(h)/Math.log(10)),j=Math.pow(10,l),e=Math.floor(a/j)*j,d=Math.ceil(b/j)*j,i=(d-e)/(c-1),1===j&&i>1&&Math.ceil(i)!==i&&(i=Math.ceil(i),d=e+i*(c-1)),e<0&&d>0&&(e=Math.floor(a/i)*i,d=Math.ceil(b/i)*i),i<1?(g=Math.floor(Math.log(i)/Math.log(10)),f=function(){var a,b;b=[];for(k=a=e;e<=d?a<=d:a>=d;k=a+=i)b.push(parseFloat(k.toFixed(1-g)));return b}()):f=function(){var a,b;b=[];for(k=a=e;e<=d?a<=d:a>=d;k=a+=i)b.push(k);return b}(),f},d.prototype._calc=function(){var a,b,c,d,e,f;e=this.el.width(),c=this.el.height();if(this.elementWidth!==e||this.elementHeight!==c||this.dirty){ +this.elementWidth=e,this.elementHeight=c,this.dirty=!1,this.left=this.options.padding,this.right=this.elementWidth-this.options.padding,this.top=this.options.padding,this.bottom=this.elementHeight-this.options.padding,this.options.axes&&(f=function(){var a,c,d,e;d=this.grid,e=[];for(a=0,c=d.length;ab;d=0<=b?++a:--a)c.push(this.measureText(this.data[d].text,-this.options.xLabelAngle).height);return c}.call(this),this.bottom-=Math.max.apply(Math,a)),this.width=Math.max(1,this.right-this.left),this.height=Math.max(1,this.bottom-this.top),this.dx=this.width/(this.xmax-this.xmin),this.dy=this.height/(this.ymax-this.ymin);if(this.calc)return this.calc()}},d.prototype.transY=function(a){return this.bottom-(a-this.ymin)*this.dy},d.prototype.transX=function(a){return 1===this.data.length?(this.left+this.right)/2:this.left+(a-this.xmin)*this.dx},d.prototype.redraw=function(){this.raphael.clear(),this._calc(),this.drawGrid(),this.drawGoals(),this.drawEvents();if(this.draw)return this.draw()},d.prototype.measureText=function(a,b){var c,d;return null==b&&(b=0),d=this.raphael.text(100,100,a).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).rotate(b),c=d.getBBox(),d.remove(),c},d.prototype.yAxisFormat=function(a){return this.yLabelFormat(a)},d.prototype.yLabelFormat=function(a){return"function"==typeof this.options.yLabelFormat?this.options.yLabelFormat(a):""+this.options.preUnits+b.commas(a)+this.options.postUnits},d.prototype.updateHover=function(a,b){var c,d;c=this.hitTest(a,b);if(null!=c)return(d=this.hover).update.apply(d,c)},d.prototype.drawGrid=function(){var a,b,c,d,e,f;if(this.options.grid!==!1||this.options.axes!==!1){e=this.grid,f=[];for(c=0,d=e.length;c
"),this.el.hide(),this.options.parent.append(this.el)}return c.defaults={class:"morris-hover morris-default-style"},c.prototype.update=function(a,b,c){return this.html(a),this.show(),this.moveTo(b,c)},c.prototype.html=function(a){return this.el.html(a)},c.prototype.moveTo=function(a,b){var c,d,e,f,g,h;return g=this.options.parent.innerWidth(),f=this.options.parent.innerHeight(),d=this.el.outerWidth(),c=this.el.outerHeight(),e=Math.min(Math.max(0,a-d/2),g-d),null!=b?(h=b-c-10,h<0&&(h=b+10,h+c>f&&(h=f/2-c/2))):h=f/2-c/2,this.el.css({left:e+"px",top:parseInt(h)+"px"})},c.prototype.show=function(){return this.el.show()},c.prototype.hide=function(){return this.el.hide()},c}(),b.Line=function(a){function c(a){this.hilight=h(this.hilight,this),this.onHoverOut=h(this.onHoverOut,this),this.onHoverMove=h(this.onHoverMove,this),this.onGridClick=h(this.onGridClick,this);if(!(this instanceof b.Line))return new b.Line(a);c.__super__.constructor.call(this,a)}return g(c,a),c.prototype.init=function(){this.pointGrow=Raphael.animation({r:this.options.pointSize+3},25,"linear"),this.pointShrink=Raphael.animation({r:this.options.pointSize},25,"linear");if("always"!==this.options.hideHover)return this.hover=new b.Hover({parent:this.el}),this.on("hovermove",this.onHoverMove),this.on("hoverout",this.onHoverOut),this.on("gridclick",this.onGridClick)},c.prototype.defaults={lineWidth:3,pointSize:4,lineColors:["#0b62a4","#7A92A3","#4da74d","#afd8f8","#edc240","#cb4b4b","#9440ed"],pointWidths:[1],pointStrokeColors:["#ffffff"],pointFillColors:[],smooth:!0,xLabels:"auto",xLabelFormat:null,xLabelMargin:24,continuousLine:!0,hideHover:!1},c.prototype.calc=function(){return this.calcPoints(),this.generatePaths()},c.prototype.calcPoints=function(){var a,b,c,d,e,f;e=this.data,f=[];for(c=0,d=e.length;c"+d.label+"
",h=d.y;for(c=f=0,g=h.length;f\n "+this.options.labels[c]+":\n "+this.yLabelFormat(e)+"\n
";return"function"==typeof this.options.hoverCallback&&(b=this.options.hoverCallback(a,this.options,b)),[b,d._x,d._ymax]},c.prototype.generatePaths=function(){var a,c,d,e,f;return this.paths=function(){var g,h,j,k;k=[];for(d=g=0,h=this.options.ykeys.length;0<=h?gh;d=0<=h?++g:--g)f=this.options.smooth===!0||(j=this.options.ykeys[d],i.call(this.options.smooth,j)>=0),c=function(){var a,b,c,f;c=this.data,f=[];for(a=0,b=c.length;a1?k.push(b.Line.createPath(c,f,this.bottom)):k.push(null);return k}.call(this)},c.prototype.draw=function(){this.options.axes&&this.drawXAxis(),this.drawSeries();if(this.options.hideHover===!1)return this.displayHoverForRow(this.data.length-1)},c.prototype.drawXAxis=function(){var a,c,d,e,f,g,h,i,j,k,l=this;h=this.bottom+this.options.padding/2,f=null,e=null,a=function(a,b){var c,d,g,i,j;return c=l.drawXAxisLabel(l.transX(b),h,a),j=c.getBBox(),c.transform("r"+-l.options.xLabelAngle),d=c.getBBox(),c.transform("t0,"+d.height/2+"..."),0!==l.options.xLabelAngle&&(i=-.5*j.width*Math.cos(l.options.xLabelAngle*Math.PI/180),c.transform("t"+i+",0...")),d=c.getBBox(),(null==f||f>=d.x+d.width||null!=e&&e>=d.x)&&d.x>=0&&d.x+d.width=0;a=d<=0?++b:--b)this._drawLineFor(a);f=[];for(a=c=e=this.options.ykeys.length-1;e<=0?c<=0:c>=0;a=e<=0?++c:--c)f.push(this._drawPointFor(a));return f},c.prototype._drawPointFor=function(a){var b,c,d,e,f,g;this.seriesPoints[a]=[],f=this.data,g=[];for(d=0,e=f.length;d=e;b=0<=e?++c:--c)this.seriesPoints[b][this.prevHilight]&&this.seriesPoints[b][this.prevHilight].animate(this.pointShrink);if(null!==a&&this.prevHilight!==a)for(b=d=0,f=this.seriesPoints.length-1;0<=f?d<=f:d>=f;b=0<=f?++d:--d)this.seriesPoints[b][a]&&this.seriesPoints[b][a].animate(this.pointGrow);return this.prevHilight=a},c.prototype.colorFor=function(a,b,c){return"function"==typeof this.options.lineColors?this.options.lineColors.call(this,a,b,c):"point"===c?this.options.pointFillColors[b%this.options.pointFillColors.length]||this.options.lineColors[b%this.options.lineColors.length]:this.options.lineColors[b%this.options.lineColors.length]},c.prototype.drawXAxisLabel=function(a,b,c){return this.raphael.text(a,b,c).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor)},c.prototype.drawLinePath=function(a,b){return this.raphael.path(a).attr("stroke",b).attr("stroke-width",this.options.lineWidth)},c.prototype.drawLinePoint=function(a,b,c,d,e){return this.raphael.circle(a,b,c).attr("fill",d).attr("stroke-width",this.strokeWidthForSeries(e)).attr("stroke",this.strokeForSeries(e))},c.prototype.strokeWidthForSeries=function(a){return this.options.pointWidths[a%this.options.pointWidths.length]},c.prototype.strokeForSeries=function(a){return this.options.pointStrokeColors[a%this.options.pointStrokeColors.length]},c}(b.Grid),b.labelSeries=function(c,d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r;j=200*(d-c)/e,i=new Date(c),n=b.LABEL_SPECS[f];if(void 0===n){r=b.AUTO_LABEL_ORDER;for(p=0,q=r.length;p=m.span){n=m;break}}}void 0===n&&(n=b.LABEL_SPECS.second),g&&(n=a.extend({},n,{fmt:g})),h=n.start(i),l=[];for(;(o=h.getTime())<=d;)o>=c&&l.push([n.fmt(h),o]),n.incr(h);return l},c=function(a){return{span:60*a*1e3,start:function(a){return new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours())},fmt:function(a){return""+b.pad2(a.getHours())+":"+b.pad2(a.getMinutes())},incr:function(b){return b.setUTCMinutes(b.getUTCMinutes()+a)}}},d=function(a){return{span:1e3*a,start:function(a){return new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),a.getMinutes())},fmt:function(a){return""+b.pad2(a.getHours())+":"+b.pad2(a.getMinutes())+":"+b.pad2(a.getSeconds())},incr:function(b){return b.setUTCSeconds(b.getUTCSeconds()+a)}}},b.LABEL_SPECS={decade:{span:1728e8,start:function(a){return new Date(a.getFullYear()-a.getFullYear()%10,0,1)},fmt:function(a){return""+a.getFullYear()},incr:function(a){return a.setFullYear(a.getFullYear()+10)}},year:{span:1728e7,start:function(a){return new Date(a.getFullYear(),0,1)},fmt:function(a){return""+a.getFullYear()},incr:function(a){return a.setFullYear(a.getFullYear()+1)}},month:{span:24192e5,start:function(a){return new Date(a.getFullYear(),a.getMonth(),1)},fmt:function(a){return""+a.getFullYear()+"-"+b.pad2(a.getMonth()+1)},incr:function(a){return a.setMonth(a.getMonth()+1)}},day:{span:864e5,start:function(a){return new Date(a.getFullYear(),a.getMonth(),a.getDate())},fmt:function(a){return""+a.getFullYear()+"-"+b.pad2(a.getMonth()+1)+"-"+b.pad2(a.getDate())},incr:function(a){return a.setDate(a.getDate()+1)}},hour:c(60),"30min":c(30),"15min":c(15),"10min":c(10),"5min":c(5),minute:c(1),"30sec":d(30),"15sec":d(15),"10sec":d(10),"5sec":d(5),second:d(1)},b.AUTO_LABEL_ORDER=["decade","year","month","day","hour","30min","15min","10min","5min","minute","30sec","15sec","10sec","5sec","second"],b.Area=function(c){function d(c){var f;if(!(this instanceof b.Area))return new b.Area(c);f=a.extend({},e,c),this.cumulative=!f.behaveLikeLine,"auto"===f.fillOpacity&&(f.fillOpacity=f.behaveLikeLine?.8:1),d.__super__.constructor.call(this,f)}var e;return g(d,c),e={fillOpacity:"auto",behaveLikeLine:!1},d.prototype.calcPoints=function(){var a,b,c,d,e,f,g;f=this.data,g=[];for(d=0,e=f.length;d=b;0<=b?a++:a--)f.push(a);return f}.apply(this):function(){g=[];for(var a=e=this.options.ykeys.length-1;e<=0?a<=0:a>=0;e<=0?a++:a--)g.push(a);return g}.apply(this),h=[];for(c=0,d=b.length;cl;a=0<=l?++k:--k)h=this.data[this.data.length-1-a],b=this.drawXAxisLabel(h._x,j,h.label),i=b.getBBox(),b.transform("r"+-this.options.xLabelAngle),c=b.getBBox(),b.transform("t0,"+c.height/2+"..."),0!==this.options.xLabelAngle&&(e=-.5*i.width*Math.cos(this.options.xLabelAngle*Math.PI/180),b.transform("t"+e+",0...")),(null==g||g>=c.x+c.width||null!=f&&f>=c.x)&&c.x>=0&&c.x+c.width=0?this.transY(0):null,this.bars=function(){var h,o,p,q;p=this.data,q=[];for(d=h=0,o=p.length;h"+d.label+"
",i=d.y;for(c=g=0,h=i.length;g\n "+this.options.labels[c]+":\n "+this.yLabelFormat(f)+"\n
";return"function"==typeof this.options.hoverCallback&&(b=this.options.hoverCallback(a,this.options,b)),e=this.left+(a+.5)*this.width/this.data.length,[b,e]},d.prototype.drawXAxisLabel=function(a,b,c){return this.raphael.text(a,b,c).attr("font-size",this.options.gridTextSize).attr("font-family",this.options.gridTextFamily).attr("font-weight",this.options.gridTextWeight).attr("fill",this.options.gridTextColor)},d.prototype.drawBar=function(a,b,c,d,e){return this.raphael.rect(a,b,c,d).attr("fill",e).attr("stroke-width",0)},d}(b.Grid),b.Donut=function(c){function d(c){this.select=h(this.select,this),this.click=h(this.click,this);var d;if(!(this instanceof b.Donut))return new b.Donut(c);"string"==typeof c.element?this.el=a(document.getElementById(c.element)):this.el=a(c.element),this.options=a.extend({},this.defaults,c);if(null===this.el||0===this.el.length)throw Error("Graph placeholder not found.");void 0!==c.data&&0!==c.data.length&&(this.data=c.data,this.values=function(){var a,b,c,e;c=this.data,e=[];for(a=0,b=c.length;aMath.PI?1:0,this.path=this.calcSegment(this.inner+3,this.inner+this.outer-5),this.selectedPath=this.calcSegment(this.inner+3,this.inner+this.outer),this.hilight=this.calcArc(this.inner)}return g(b,a),b.prototype.calcArcPoints=function(a){return[this.cx+a*this.sin_p0,this.cy+a*this.cos_p0,this.cx+a*this.sin_p1,this.cy+a*this.cos_p1]},b.prototype.calcSegment=function(a,b){var c,d,e,f,g,h,i,j,k,l;return k=this.calcArcPoints(a),c=k[0],e=k[1],d=k[2],f=k[3],l=this.calcArcPoints(b),g=l[0],i=l[1],h=l[2],j=l[3],"M"+c+","+e+"A"+a+","+a+",0,"+this.is_long+",0,"+d+","+f+"L"+h+","+j+"A"+b+","+b+",0,"+this.is_long+",1,"+g+","+i+"Z"},b.prototype.calcArc=function(a){var b,c,d,e,f;return f=this.calcArcPoints(a),b=f[0],d=f[1],c=f[2],e=f[3],"M"+b+","+d+"A"+a+","+a+",0,"+this.is_long+",0,"+c+","+e},b.prototype.render=function(){var a=this;return this.arc=this.drawDonutArc(this.hilight,this.color),this.seg=this.drawDonutSegment(this.path,this.color,this.backgroundColor,function(){return a.fire("hover",a.index)},function(){return a.fire("click",a.index)})},b.prototype.drawDonutArc=function(a,b){return this.raphael.path(a).attr({stroke:b,"stroke-width":2,opacity:0})},b.prototype.drawDonutSegment=function(a,b,c,d,e){return this.raphael.path(a).attr({fill:b,stroke:c,"stroke-width":3}).hover(d).click(e)},b.prototype.select=function(){if(!this.selected)return this.seg.animate({path:this.selectedPath},150,"<>"),this.arc.animate({opacity:1},150,"<>"),this.selected=!0},b.prototype.deselect=function(){if(this.selected)return this.seg.animate({path:this.path},150,"<>"),this.arc.animate({opacity:0},150,"<>"),this.selected=!1},b}(b.EventEmitter)}).call(this);!function(){var a=document.createElement("canvas");if(a.getContext&&a.getContext("2d")){this.createjs=this.createjs||{};!function(){var a=function(){throw"UID cannot be instantiated"};a._nextID=0;a.get=function(){return a._nextID++};createjs.UID=a}();this.createjs=this.createjs||{};!function(){var a=function(){this.initialize()},b=a.prototype;a.initialize=function(a){a.addEventListener=b.addEventListener;a.removeEventListener=b.removeEventListener;a.removeAllEventListeners=b.removeAllEventListeners;a.hasEventListener=b.hasEventListener;a.dispatchEvent=b.dispatchEvent};b._listeners=null;b.initialize=function(){};b.addEventListener=function(a,b){var c=this._listeners;c?this.removeEventListener(a,b):c=this._listeners={};var d=c[a];d||(d=c[a]=[]);d.push(b);return b};b.removeEventListener=function(a,b){var c=this._listeners;if(c){var d=c[a];if(d)for(var e=0,f=d.length;ea._times.length)return-1;null==b&&(b=0|a.getFPS());b=Math.min(a._times.length-1,b);return 1e3/((a._times[0]-a._times[b])/b)};a.setPaused=function(b){a._paused=b};a.getPaused=function(){return a._paused};a.getTime=function(b){return a._getTime()-a._startTime-(b?a._pausedTime:0)};a.getTicks=function(b){return a._ticks-(b?a._pausedTicks:0)};a._handleAF=function(){a._rafActive=!1;a._setupTick();a._getTime()-a._lastTime>=.97*(a._interval-1)&&a._tick()};a._handleTimeout=function(){a.timeoutID=null;a._setupTick();a._tick()};a._setupTick=function(){if(!a._rafActive&&null==a.timeoutID){if(a.useRAF){var b=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(b){b(a._handleAF);a._rafActive=!0;return}}a.timeoutID=setTimeout(a._handleTimeout,a._interval)}};a._tick=function(){var b=a._getTime();a._ticks++;var c=b-a._lastTime,d=a._paused;d&&(a._pausedTicks++,a._pausedTime+=c);a._lastTime=b;for(var e=a._pauseable,f=a._listeners.slice(),g=f?f.length:0,h=0;hthis.a&&0<=this.d&&(b.rotation+=0>=b.rotation?180:-180),b.skewX=b.skewY=0):(b.skewX=c/a.DEG_TO_RAD,b.skewY=d/a.DEG_TO_RAD);return b};b.reinitialize=function(a,b,c,d,e,f,g,h,i){this.initialize(a,b,c,d,e,f);this.alpha=g||1;this.shadow=h;this.compositeOperation=i;return this};b.appendProperties=function(a,b,c){this.alpha*=a;this.shadow=b||this.shadow;this.compositeOperation=c||this.compositeOperation;return this};b.prependProperties=function(a,b,c){this.alpha*=a;this.shadow=this.shadow||b;this.compositeOperation=this.compositeOperation||c;return this};b.clone=function(){var b=new a(this.a,this.b,this.c,this.d,this.tx,this.ty);b.shadow=this.shadow;b.alpha=this.alpha;b.compositeOperation=this.compositeOperation;return b};b.toString=function(){return"[Matrix2D (a="+this.a+" b="+this.b+" c="+this.c+" d="+this.d+" tx="+this.tx+" ty="+this.ty+")]"};a.identity=new a(1,0,0,1,0,0);createjs.Matrix2D=a}();this.createjs=this.createjs||{};!function(){var a=function(a,b){this.initialize(a,b)},b=a.prototype;b.x=0;b.y=0;b.initialize=function(a,b){this.x=null==a?0:a;this.y=null==b?0:b};b.clone=function(){return new a(this.x,this.y)};b.toString=function(){return"[Point (x="+this.x+" y="+this.y+")]"};createjs.Point=a}();this.createjs=this.createjs||{};!function(){var a=function(a,b,c,d){this.initialize(a,b,c,d)},b=a.prototype;b.x=0;b.y=0;b.width=0;b.height=0;b.initialize=function(a,b,c,d){this.x=null==a?0:a;this.y=null==b?0:b;this.width=null==c?0:c;this.height=null==d?0:d};b.clone=function(){return new a(this.x,this.y,this.width,this.height)};b.toString=function(){return"[Rectangle (x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+")]"};createjs.Rectangle=a}();this.createjs=this.createjs||{};!function(){var a=function(a,b,c,d,e,f,g){this.initialize(a,b,c,d,e,f,g)},b=a.prototype;b.target=null;b.overLabel=null;b.outLabel=null;b.downLabel=null;b.play=!1;b._isPressed=!1;b._isOver=!1;b.initialize=function(a,b,c,d,e,f,g){a.addEventListener&&(this.target=a,a.cursor="pointer",this.overLabel=null==c?"over":c,this.outLabel=null==b?"out":b,this.downLabel=null==d?"down":d,this.play=e,this.setEnabled(!0),this.handleEvent({}),f&&(g&&(f.actionsEnabled=!1,f.gotoAndStop&&f.gotoAndStop(g)),a.hitArea=f))};b.setEnabled=function(a){var b=this.target;a?(b.addEventListener("mouseover",this),b.addEventListener("mouseout",this),b.addEventListener("mousedown",this)):(b.removeEventListener("mouseover",this),b.removeEventListener("mouseout",this),b.removeEventListener("mousedown",this))};b.toString=function(){return"[ButtonHelper]"};b.handleEvent=function(a){var b=this.target,c=a.type;"mousedown"==c?(a.addEventListener("mouseup",this),this._isPressed=!0,a=this.downLabel):"mouseup"==c?(this._isPressed=!1,a=this._isOver?this.overLabel:this.outLabel):"mouseover"==c?(this._isOver=!0,a=this._isPressed?this.downLabel:this.overLabel):(this._isOver=!1,a=this._isPressed?this.overLabel:this.outLabel);this.play?b.gotoAndPlay&&b.gotoAndPlay(a):b.gotoAndStop&&b.gotoAndStop(a)};createjs.ButtonHelper=a}();this.createjs=this.createjs||{};!function(){var a=function(a,b,c,d){this.initialize(a,b,c,d)},b=a.prototype;a.identity=null;b.color=null;b.offsetX=0;b.offsetY=0;b.blur=0;b.initialize=function(a,b,c,d){this.color=a;this.offsetX=b;this.offsetY=c;this.blur=d};b.toString=function(){return"[Shadow]"};b.clone=function(){return new a(this.color,this.offsetX,this.offsetY,this.blur)};a.identity=new a("transparent",0,0,0);createjs.Shadow=a}();this.createjs=this.createjs||{};!function(){var a=function(a){this.initialize(a)},b=a.prototype;b.complete=!0;b.onComplete=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._animations=null;b._frames=null;b._images=null;b._data=null;b._loadCount=0;b._frameHeight=0;b._frameWidth=0;b._numFrames=0;b._regX=0;b._regY=0;b.initialize=function(a){var b,c,d;if(null!=a){if(a.images&&0<(c=a.images.length)){d=this._images=[];for(b=0;bd.length||!1==a.next?null:null==a.next||!0==a.next?g:a.next;a.frequency||(a.frequency=1);this._animations.push(g);this._data[g]=a}}}};b.getNumFrames=function(a){if(null==a)return this._frames?this._frames.length:this._numFrames;a=this._data[a];return null==a?0:a.frames.length};b.getAnimations=function(){return this._animations.slice(0)};b.getAnimation=function(a){return this._data[a]};b.getFrame=function(a){var b;return this.complete&&this._frames&&(b=this._frames[a])?b:null};b.getFrameBounds=function(a){return(a=this.getFrame(a))?new createjs.Rectangle(-a.regX,-a.regY,a.rect.width,a.rect.height):null};b.toString=function(){return"[SpriteSheet]"};b.clone=function(){var b=new a;b.complete=this.complete;b._animations=this._animations;b._frames=this._frames;b._images=this._images;b._data=this._data;b._frameHeight=this._frameHeight;b._frameWidth=this._frameWidth;b._numFrames=this._numFrames;b._loadCount=this._loadCount;return b};b._handleImageLoad=function(){0==--this._loadCount&&(this._calculateFrames(),this.complete=!0,this.onComplete&&this.onComplete(),this.dispatchEvent("complete"))};b._calculateFrames=function(){if(!this._frames&&0!=this._frameWidth){this._frames=[];for(var a=0,b=this._frameWidth,c=this._frameHeight,d=0,e=this._images;d>8&255,a=a>>16&255);return null==d?"rgb("+a+","+b+","+c+")":"rgba("+a+","+b+","+c+","+d+")"};b.getHSL=function(a,b,c,d){return null==d?"hsl("+a%360+","+b+"%,"+c+"%)":"hsla("+a%360+","+b+"%,"+c+"%,"+d+")"};b.BASE_64={A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,0:52,1:53,2:54,3:55,4:56,5:57,6:58,7:59,8:60,9:61,"+":62,"/":63};b.STROKE_CAPS_MAP=["butt","round","square"];b.STROKE_JOINTS_MAP=["miter","round","bevel"];b._ctx=(createjs.createCanvas?createjs.createCanvas():document.createElement("canvas")).getContext("2d");b.beginCmd=new a(b._ctx.beginPath,[],!1);b.fillCmd=new a(b._ctx.fill,[],!1);b.strokeCmd=new a(b._ctx.stroke,[],!1);c._strokeInstructions=null;c._strokeStyleInstructions=null;c._ignoreScaleStroke=!1;c._fillInstructions=null;c._instructions=null;c._oldInstructions=null;c._activeInstructions=null;c._active=!1;c._dirty=!1;c.initialize=function(){this.clear();this._ctx=b._ctx};c.isEmpty=function(){return!(this._instructions.length||this._oldInstructions.length||this._activeInstructions.length)};c.draw=function(a){this._dirty&&this._updateInstructions();for(var b=this._instructions,c=0,d=b.length;cf&&(f*=k=-1);f>j&&(f=j);0>g&&(g*=l=-1);g>j&&(g=j);0>h&&(h*=m=-1);h>j&&(h=j);0>i&&(i*=n=-1);i>j&&(i=j);this._dirty=this._active=!0;var j=this._ctx.arcTo,o=this._ctx.lineTo;this._activeInstructions.push(new a(this._ctx.moveTo,[b+d-g,c]),new a(j,[b+d+g*l,c-g*l,b+d,c+g,g]),new a(o,[b+d,c+e-h]),new a(j,[b+d+h*m,c+e+h*m,b+d-h,c+e,h]),new a(o,[b+i,c+e]),new a(j,[b-i*n,c+e+i*n,b,c+e-i,i]),new a(o,[b,c+f]),new a(j,[b-f*k,c-f*k,b+f,c,f]),new a(this._ctx.closePath));return this};c.drawCircle=function(a,b,c){this.arc(a,b,c,0,2*Math.PI);return this};c.drawEllipse=function(b,c,d,e){this._dirty=this._active=!0;var f=.5522848*(d/2),g=.5522848*(e/2),h=b+d,i=c+e;d=b+d/2;e=c+e/2;this._activeInstructions.push(new a(this._ctx.moveTo,[b,e]),new a(this._ctx.bezierCurveTo,[b,e-g,d-f,c,d,c]),new a(this._ctx.bezierCurveTo,[d+f,c,h,e-g,h,e]),new a(this._ctx.bezierCurveTo,[h,e+g,d+f,i,d,i]),new a(this._ctx.bezierCurveTo,[d-f,i,b,e+g,b,e]));return this};c.drawPolyStar=function(b,c,d,e,f,g){this._dirty=this._active=!0;null==f&&(f=0);f=1-f;g=null==g?0:g/(180/Math.PI);var h=Math.PI/e;this._activeInstructions.push(new a(this._ctx.moveTo,[b+Math.cos(g)*d,c+Math.sin(g)*d]));for(var i=0;i>3,n=c[m];if(!n||3&l)throw"bad path data (@"+e+"): "+k;k=d[m];m||(h=i=0);g.length=0;e++;l=(l>>2&1)+2;for(m=0;m>5?-1:1,o=(31&o)<<6|j[a.charAt(e+1)];3==l&&(o=o<<6|j[a.charAt(e+2)]);o=p*o/10;m%2?h=o+=h:i=o+=i;g[m]=o;e+=l}n.apply(this,g)}return this};c.clone=function(){var a=new b;a._instructions=this._instructions.slice();a._activeInstructions=this._activeInstructions.slice();a._oldInstructions=this._oldInstructions.slice();this._fillInstructions&&(a._fillInstructions=this._fillInstructions.slice());this._strokeInstructions&&(a._strokeInstructions=this._strokeInstructions.slice());this._strokeStyleInstructions&&(a._strokeStyleInstructions=this._strokeStyleInstructions.slice());a._active=this._active;a._dirty=this._dirty;return a};c.toString=function(){return"[Graphics]"};c.mt=c.moveTo;c.lt=c.lineTo;c.at=c.arcTo;c.bt=c.bezierCurveTo;c.qt=c.quadraticCurveTo;c.a=c.arc;c.r=c.rect;c.cp=c.closePath;c.c=c.clear;c.f=c.beginFill;c.lf=c.beginLinearGradientFill;c.rf=c.beginRadialGradientFill;c.bf=c.beginBitmapFill;c.ef=c.endFill;c.ss=c.setStrokeStyle;c.s=c.beginStroke;c.ls=c.beginLinearGradientStroke;c.rs=c.beginRadialGradientStroke;c.bs=c.beginBitmapStroke;c.es=c.endStroke;c.dr=c.drawRect;c.rr=c.drawRoundRect;c.rc=c.drawRoundRectComplex;c.dc=c.drawCircle;c.de=c.drawEllipse;c.dp=c.drawPolyStar;c.p=c.decodePath;c._updateInstructions=function(){this._instructions=this._oldInstructions.slice();this._instructions.push(b.beginCmd);this._instructions.push.apply(this._instructions,this._activeInstructions);this._fillInstructions&&this._instructions.push.apply(this._instructions,this._fillInstructions);this._strokeInstructions&&(this._strokeStyleInstructions&&this._instructions.push.apply(this._instructions,this._strokeStyleInstructions),this._instructions.push.apply(this._instructions,this._strokeInstructions),this._ignoreScaleStroke?this._instructions.push(new a(this._ctx.save,[],!1),new a(this._ctx.setTransform,[1,0,0,1,0,0],!1),b.strokeCmd,new a(this._ctx.restore,[],!1)):this._instructions.push(b.strokeCmd))};c._newPath=function(){this._dirty&&this._updateInstructions();this._oldInstructions=this._instructions;this._activeInstructions=[];this._active=this._dirty=!1};c._setProp=function(a,b){this[a]=b};createjs.Graphics=b}();this.createjs=this.createjs||{};!function(){var a=function(){this.initialize()},b=a.prototype;a.suppressCrossDomainErrors=!1;a._hitTestCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");a._hitTestCanvas.width=a._hitTestCanvas.height=1;a._hitTestContext=a._hitTestCanvas.getContext("2d");a._nextCacheID=1;b.alpha=1;b.cacheCanvas=null;b.id=-1;b.mouseEnabled=!0;b.name=null;b.parent=null;b.regX=0;b.regY=0;b.rotation=0;b.scaleX=1;b.scaleY=1;b.skewX=0;b.skewY=0;b.shadow=null;b.visible=!0;b.x=0;b.y=0;b.compositeOperation=null;b.snapToPixel=!1;b.onPress=null;b.onClick=null;b.onDoubleClick=null;b.onMouseOver=null;b.onMouseOut=null;b.onTick=null;b.filters=null;b.cacheID=0;b.mask=null;b.hitArea=null;b.cursor=null;b.addEventListener=null;b.removeEventListener=null;b.removeAllEventListeners=null;b.dispatchEvent=null;b.hasEventListener=null;b._listeners=null;createjs.EventDispatcher.initialize(b);b._cacheOffsetX=0;b._cacheOffsetY=0;b._cacheScale=1;b._cacheDataURLID=0;b._cacheDataURL=null;b._matrix=null;b.initialize=function(){this.id=createjs.UID.get();this._matrix=new createjs.Matrix2D};b.isVisible=function(){return!(!this.visible||!(0d||d>this.children.length)return arguments[c-2];if(2a||a>this.children.length-1)return!1;(b=this.children[a])&&(b.parent=null);this.children.splice(a,1);return!0};b.removeAllChildren=function(){for(var a=this.children;a.length;)a.pop().parent=null};b.getChildAt=function(a){return this.children[a]};b.getChildByName=function(a){for(var b=this.children,c=0,d=b.length;cb||b>=d)){for(var e=0;e=a)return;var b=this;this._mouseOverIntervalID=setInterval(function(){b._testMouseOver()},1e3/Math.min(50,a))};b.enableDOMEvents=function(a){null==a&&(a=!0);var b,c=this._eventListeners;if(!a&&c){for(b in c)a=c[b],a.t.removeEventListener(b,a.f);this._eventListeners=null}else if(a&&!c&&this.canvas){a=window.addEventListener?window:document;var d=this,c=this._eventListeners={};c.mouseup={t:a,f:function(a){d._handleMouseUp(a)}};c.mousemove={t:a,f:function(a){d._handleMouseMove(a)}};c.dblclick={t:a,f:function(a){d._handleDoubleClick(a)}};c.mousedown={t:this.canvas,f:function(a){d._handleMouseDown(a)}};for(b in c)a=c[b],a.t.addEventListener(b,a.f)}};b.clone=function(){var b=new a(null);this.cloneProps(b);return b};b.toString=function(){return"[Stage (name="+this.name+")]"};b._getPointerData=function(a){var b=this._pointerData[a];b||(b=this._pointerData[a]={x:0,y:0},null!=this._primaryPointerID&&-1!=this._primaryPointerID)||(this._primaryPointerID=a);return b};b._handleMouseMove=function(a){a||(a=window.event);this._handlePointerMove(-1,a,a.pageX,a.pageY)};b._handlePointerMove=function(a,b,c,d){if(this.canvas){var e=this._getPointerData(a),f=e.inBounds;this._updatePointerPosition(a,c,d) +;if(f||e.inBounds||this.mouseMoveOutside){(this.onMouseMove||this.hasEventListener("stagemousemove"))&&(c=new createjs.MouseEvent("stagemousemove",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseMove&&this.onMouseMove(c),this.dispatchEvent(c));(d=e.event)&&(d.onMouseMove||d.hasEventListener("mousemove"))&&(c=new createjs.MouseEvent("mousemove",e.x,e.y,d.target,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onMouseMove&&d.onMouseMove(c),d.dispatchEvent(c,d.target))}}};b._updatePointerPosition=function(a,b,c){var d=this._getElementRect(this.canvas);b-=d.left;c-=d.top;var e=this.canvas.width,f=this.canvas.height;b/=(d.right-d.left)/e;c/=(d.bottom-d.top)/f;d=this._getPointerData(a);(d.inBounds=0<=b&&0<=c&&b<=e-1&&c<=f-1)?(d.x=b,d.y=c):this.mouseMoveOutside&&(d.x=0>b?0:b>e-1?e-1:b,d.y=0>c?0:c>f-1?f-1:c);d.rawX=b;d.rawY=c;a==this._primaryPointerID&&(this.mouseX=d.x,this.mouseY=d.y,this.mouseInBounds=d.inBounds)};b._getElementRect=function(a){var b;try{b=a.getBoundingClientRect()}catch(c){b={top:a.offsetTop,left:a.offsetLeft,width:a.offsetWidth,height:a.offsetHeight}}var c=(window.pageXOffset||document.scrollLeft||0)-(document.clientLeft||document.body.clientLeft||0),d=(window.pageYOffset||document.scrollTop||0)-(document.clientTop||document.body.clientTop||0),e=window.getComputedStyle?getComputedStyle(a):a.currentStyle;a=parseInt(e.paddingLeft)+parseInt(e.borderLeftWidth);var f=parseInt(e.paddingTop)+parseInt(e.borderTopWidth),g=parseInt(e.paddingRight)+parseInt(e.borderRightWidth),e=parseInt(e.paddingBottom)+parseInt(e.borderBottomWidth);return{left:b.left+c+a,right:b.right+c-g,top:b.top+d+f,bottom:b.bottom+d-e}};b._handleMouseUp=function(a){this._handlePointerUp(-1,a,!1)};b._handlePointerUp=function(a,b,c){var d,e=this._getPointerData(a);(this.onMouseMove||this.hasEventListener("stagemouseup"))&&(d=new createjs.MouseEvent("stagemouseup",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseUp&&this.onMouseUp(d),this.dispatchEvent(d));var f=e.event;f&&(f.onMouseUp||f.hasEventListener("mouseup"))&&(d=new createjs.MouseEvent("mouseup",e.x,e.y,f.target,b,a,a==this._primaryPointerID,e.rawX,e.rawY),f.onMouseUp&&f.onMouseUp(d),f.dispatchEvent(d,f.target));(f=e.target)&&(f.onClick||f.hasEventListener("click"))&&this._getObjectsUnderPoint(e.x,e.y,null,!0,this._mouseOverIntervalID?3:1)==f&&(d=new createjs.MouseEvent("click",e.x,e.y,f,b,a,a==this._primaryPointerID,e.rawX,e.rawY),f.onClick&&f.onClick(d),f.dispatchEvent(d));c?(a==this._primaryPointerID&&(this._primaryPointerID=null),delete this._pointerData[a]):e.event=e.target=null};b._handleMouseDown=function(a){this._handlePointerDown(-1,a,!1)};b._handlePointerDown=function(a,b,c,d){var e=this._getPointerData(a);null!=d&&this._updatePointerPosition(a,c,d);(this.onMouseDown||this.hasEventListener("stagemousedown"))&&(c=new createjs.MouseEvent("stagemousedown",e.x,e.y,this,b,a,a==this._primaryPointerID,e.rawX,e.rawY),this.onMouseDown&&this.onMouseDown(c),this.dispatchEvent(c));(d=this._getObjectsUnderPoint(e.x,e.y,null,this._mouseOverIntervalID?3:1))&&(e.target=d,d.onPress||d.hasEventListener("mousedown"))&&(c=new createjs.MouseEvent("mousedown",e.x,e.y,d,b,a,a==this._primaryPointerID,e.rawX,e.rawY),d.onPress&&d.onPress(c),d.dispatchEvent(c),c.onMouseMove||c.onMouseUp||c.hasEventListener("mousemove")||c.hasEventListener("mouseup"))&&(e.event=c)};b._testMouseOver=function(){if(-1==this._primaryPointerID&&(this.mouseX!=this._mouseOverX||this.mouseY!=this._mouseOverY||!this.mouseInBounds)){var a=null;this.mouseInBounds&&(a=this._getObjectsUnderPoint(this.mouseX,this.mouseY,null,3),this._mouseOverX=this.mouseX,this._mouseOverY=this.mouseY);var b=this._mouseOverTarget;if(b!=a){var c=this._getPointerData(-1);if(b&&(b.onMouseOut||b.hasEventListener("mouseout"))){var d=new createjs.MouseEvent("mouseout",c.x,c.y,b,null,-1,c.rawX,c.rawY);b.onMouseOut&&b.onMouseOut(d);b.dispatchEvent(d)}b&&(this.canvas.style.cursor="");a&&(a.onMouseOver||a.hasEventListener("mouseover"))&&(d=new createjs.MouseEvent("mouseover",c.x,c.y,a,null,-1,c.rawX,c.rawY),a.onMouseOver&&a.onMouseOver(d),a.dispatchEvent(d));a&&(this.canvas.style.cursor=a.cursor||"");this._mouseOverTarget=a}}};b._handleDoubleClick=function(a){var b=this._getPointerData(-1),c=this._getObjectsUnderPoint(b.x,b.y,null,this._mouseOverIntervalID?3:1);c&&(c.onDoubleClick||c.hasEventListener("dblclick"))&&(evt=new createjs.MouseEvent("dblclick",b.x,b.y,c,a,-1,!0,b.rawX,b.rawY),c.onDoubleClick&&c.onDoubleClick(evt),c.dispatchEvent(evt))};createjs.Stage=a}();this.createjs=this.createjs||{};!function(){var a=function(a){this.initialize(a)},b=a.prototype=new createjs.DisplayObject;b.image=null;b.snapToPixel=!0;b.sourceRect=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();"string"==typeof a?(this.image=new Image,this.image.src=a):this.image=a};b.isVisible=function(){var a=this.cacheCanvas||this.image&&(this.image.complete||this.image.getContext||2<=this.image.readyState);return!(!this.visible||!(0=a){var e=b.next;this._dispatchAnimationEnd(b,c,d,e,a-1)||(e?this._goto(e):(this.paused=!0,this.currentAnimationFrame=b.frames.length-1,this.currentFrame=b.frames[this.currentAnimationFrame]))}else this.currentFrame=b.frames[this.currentAnimationFrame];else a=this.spriteSheet.getNumFrames(),c>=a&&!this._dispatchAnimationEnd(b,c,d,a-1)&&(this.currentFrame=0)};b._dispatchAnimationEnd=function(a,b,c,d,e){var f=a?a.name:null;this.onAnimationEnd&&this.onAnimationEnd(this,f,d);this.dispatchEvent({type:"animationend",name:f,next:d});!c&&this.paused&&(this.currentAnimationFrame=e);return this.paused!=c||this._animation!=a||this.currentFrame!=b};b.DisplayObject_cloneProps=b.cloneProps;b.cloneProps=function(a){this.DisplayObject_cloneProps(a);a.onAnimationEnd=this.onAnimationEnd;a.currentFrame=this.currentFrame;a.currentAnimation=this.currentAnimation;a.paused=this.paused;a.offset=this.offset;a._animation=this._animation;a.currentAnimationFrame=this.currentAnimationFrame};b._goto=function(a){if(isNaN(a)){var b=this.spriteSheet.getAnimation(a);b&&(this.currentAnimationFrame=0,this._animation=b,this.currentAnimation=a,this._normalizeFrame())}else this.currentAnimation=this._animation=null,this.currentFrame=a};createjs.BitmapAnimation=a}();this.createjs=this.createjs||{};!function(){var a=function(a){this.initialize(a)},b=a.prototype=new createjs.DisplayObject;b.graphics=null;b.DisplayObject_initialize=b.initialize;b.initialize=function(a){this.DisplayObject_initialize();this.graphics=a?a:new createjs.Graphics};b.isVisible=function(){var a=this.cacheCanvas||this.graphics&&!this.graphics.isEmpty();return!(!this.visible||!(0this.lineWidth?(b&&this._drawTextLine(a,i,e*d),e++,i=h[j+1]):i+=h[j]+h[j+1];b&&this._drawTextLine(a,i,e*d)}e++}return e};b._drawTextLine=function(a,b,c){this.outline?a.strokeText(b,0,c,this.maxWidth||65535):a.fillText(b,0,c,this.maxWidth||65535)};createjs.Text=a}();this.createjs=this.createjs||{};!function(){var a=function(){throw"SpriteSheetUtils cannot be instantiated"};a._workingCanvas=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");a._workingContext=a._workingCanvas.getContext("2d");a.addFlippedFrames=function(b,c,d,e){if(c||d||e){var f=0;c&&a._flip(b,++f,!0,!1);d&&a._flip(b,++f,!1,!0);e&&a._flip(b,++f,!0,!0)}};a.extractFrame=function(b,c){isNaN(c)&&(c=b.getAnimation(c).frames[0]);var d=b.getFrame(c);if(!d)return null;var e=d.rect,f=a._workingCanvas;f.width=e.width;f.height=e.height;a._workingContext.drawImage(d.image,e.x,e.y,e.width,e.height,0,0,e.width,e.height);d=new Image;d.src=f.toDataURL("image/png");return d};a.mergeAlpha=function(a,b,c){c||(c=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas"));c.width=Math.max(b.width,a.width);c.height=Math.max(b.height,a.height);var d=c.getContext("2d");d.save();d.drawImage(a,0,0);d.globalCompositeOperation="destination-in";d.drawImage(b,0,0);d.restore();return c};a._flip=function(b,c,d,e){for(var f=b._images,g=a._workingCanvas,h=a._workingContext,i=f.length/c,j=0;jthis.maxHeight)throw a.ERR_DIMENSIONS;for(var e=0,f=0,g=0;d.length;){var h=this._fillRow(d,e,g,c,b);h.w>f&&(f=h.w);e+=h.h;if(!h.h||!d.length){var i=createjs.createCanvas?createjs.createCanvas():document.createElement("canvas");i.width=this._getSize(f,this.maxWidth);i.height=this._getSize(e,this.maxHeight);this._data.images[g]=i;h.h||(f=e=0,g++)}}};b._getSize=function(a,b){for(var c=4;Math.pow(2,++c)g)throw a.ERR_DIMENSIONS;r>h||i+n>g||(l.img=d,l.rect=new createjs.Rectangle(i,c,n,r),j=j||r,b.splice(k,1),e[l.index]=[i,c,n,r,d,Math.round(-p+m*o.regX-f),Math.round(-q+m*o.regY-f)],i+=n)}return{w:i,h:j}};b._endBuild=function(){this.spriteSheet=new createjs.SpriteSheet(this._data);this._data=null;this.progress=1;this.onComplete&&this.onComplete(this);this.dispatchEvent("complete")};b._run=function(){for(var a=50*Math.max(.01,Math.min(.99,this.timeSlice||.3)),b=(new Date).getTime()+a,c=!1;b>(new Date).getTime();)if(!this._drawNext()){c=!0;break}if(c)this._endBuild();else{var d=this;this._timerID=setTimeout(function(){d._run()},50-a)}a=this.progress=this._index/this._frames.length;this.onProgress&&this.onProgress(this,a);this.dispatchEvent({type:"progress",progress:a})};b._drawNext=function(){var a=this._frames[this._index],b=a.scale*this._scale,c=a.rect,d=a.sourceRect,e=this._data.images[a.img].getContext("2d");a.funct&&a.funct.apply(a.scope,a.params);e.save();e.beginPath();e.rect(c.x,c.y,c.width,c.height);e.clip();e.translate(Math.ceil(c.x-d.x*b),Math.ceil(c.y-d.y*b));e.scale(b,b);a.source.draw(e);e.restore();return++this._index'+(g[a.status]||h)+"
").appendTo(b))}).always(function(){e&&e.$progress&&e.$progress.parent().length>0&&e.$progress.remove()}).progress(function(){!e||e.$progress&&0!==e.$progress.parent().length||(e.$progress=c('
fetching data...
').appendTo(b))})};d.Data.filterData=function(a,b,e,f,g,h){var i,j={};g=g||1;c.each(a,function(a,k){var l,m;l=d.Date.parse(k.x);if(l&&l>=e&&l<=b)if(h){m=d.Date.createId(l,"daily");j[m]=k}else{"weekly"===f&&(l=d.Date.getWeekStartday(l));m=d.Date.createId(l,f);if(j[m])for(a=0;anew Date&&(b=new Date);a>b&&(a=b);e=d.Range.getLength(a,b,g);if(e>f){e=f;a=d.Date.calcDate(b,e,g,!0)}return{start:a,end:b,length:e,maxLength:f,unit:g,dataType:h,max:d.Range.getEndDate(b,g),min:d.Range.getStartDate(a,g),isTimeline:!0}};d.Range.calcNum=function(a,b,d,e,f,g,h){d=d||10;if(h){var i=c(window).width();e=Math.min(Math.ceil(.021875*i),e);d=Math.min(d,e)}if(!a&&!b){a=0;b=d-1}a=parseInt(a,10)||(0===a?0:null);b=parseInt(b,10)||(0===b?0:null);if(null===a){a=b-d;a<0&&(a=0)}null===b&&(b=a+d);a>b&&(a=b);d=b-a+1;if(d>e){d=e;a=b-e}return{start:a,end:b,length:d,maxLength:e,dataType:g,unit:null,max:b,min:a,isTimeline:!1}};d.Range.getStartDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,0,1,0,0,0)},monthly:function(){c=new Date(d,e,1,0,0,0)},quarter:function(){c=new Date(d,e,1,0,0,0)},weekly:function(){c=new Date(d,e,f-a.getDay(),0,0,0)},daily:function(){c=new Date(d,e,f,0,0,0)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c};d.Range.getEndDate=function(a,b){var c,d=a.getFullYear(),e=a.getMonth(),f=a.getDate();({yearly:function(){c=new Date(d,11,31,23,59,59)},monthly:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},quarter:function(){c=new Date(new Date(d,e+1,1,0,0,0).valueOf()-1)},weekly:function(){c=new Date(d,e,f-a.getDay()+6,23,59,59)},daily:function(){c=new Date(d,e,f,23,59,59)},hourly:function(){c=new Date(d,e,f,a.getHours(),0,0)}})[b]();return c0?e+1:1};d.Graph=function(a,c){this.config=b.extend({type:"morris.bar",staticPath:"",data:"graph.json"},a);this.config.id="graph-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config.yLength=parseInt(this.config.yLength,10)||1;this.range=d.Range.generate(c);if("string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}this.graphData={};this.graphData[this.range.unit]=b.Deferred();this.getData(b.proxy(function(a){this.graphData[this.range.unit].resolve(this.generateGraphData(a))},this));this.$graphContainer=b('
');this.$graphContainer.on("UPDATE",b.proxy(function(a,c,d){this.update_(c,d);return b(this.$graphContainer)},this));this.$graphContainer.on("REMOVE",b.proxy(function(){this.remove_()},this));var e=b(window).width();this.updateFunc=b.proxy(function(){if(e&&e!==b(window).width()){e=b(window).width();this.update_()}},this);a.autoResize&&b(window).on("orientationchange debouncedresize",this.updateFunc);this.$graphContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){b.proxy(this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("GET_LABEL",b.proxy(function(a,c,d){b.proxy(this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this),this));return b(this.$graphContainer)},this));this.$graphContainer.on("APPEND_TO",b.proxy(function(a,c){this.$graphContainer.appendTo(c);this.graphData[this.range.unit].done(b.proxy(function(a){var c;c=this.range.isTimeline?b.grep(a,b.proxy(function(a){return this.range.start<=a.timestamp&&a.timestamp<=this.range.end},this)):a.slice(this.range.min,this.range.max+1);this.draw_(c)},this));return b(this.$graphContainer)},this));return this.$graphContainer};d.Graph.prototype.getData=function(a){d.Data.getData(this.origData_,this.$graphContainer,a,this)};d.Graph.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.Graph.prototype.getTotalCount_=function(a,c){var d=0,e="y"+(c||"");b.each(a,function(a,b){d+=parseInt(b[e]||b.value||0,10)});return d};d.Graph.prototype.getDelta_=function(a,b){var c,d,e,f,g=a.length;f="y"+(b||"");c=a[g-1];d=a[g-2];e=d&&c&&d[f]?c[f]-d[f]:c[f];return void 0===e?"":e};d.Graph.presetColors=function(){return["#6AAC2B","#FFBE00","#CF6DD3","#8F2CFF","#2D85FF","#5584D4","#5ED2B8","#9CCF41","#F87085","#2C8087","#8EEC6A","#FFE700","#FF5E19","#FF4040","#976BD6","#503D99","#395595"]};d.Graph.getChartColors=function(a,b){return{reverse:function(a){return a.reverse()}, +shuffle:function(a){var b,c,d,e;d=a.length;for(b=0;b';this.generateLabel(this.labelTemplate)}if(g.fallback&&g.fallback.test&&!d.Graph.test[g.fallback.test]()){c=g.fallback.type.split(".");e=c[0];f=c[1];g=b.extend(g,g.fallback)}g.chartColors&&"string"==typeof g.chartColors&&(g.chartColors=g.chartColors.split(","));this.graphObject=d.Graph[e][f](a,g,this.range,this.$graphContainer)};d.Graph.test={};d.Graph.test.canvas=function(){var a=document.createElement("canvas");return a.getContext&&a.getContext("2d")};d.Graph.test.svg=function(){var a={svg:"http://www.w3.org/2000/svg"};return!!document.createElementNS&&!!document.createElementNS(a.svg,"svg").createSVGRect};d.Graph.test.vml=function(){var a,b=d.Graph.test.svg();if(!b){var c=document.body.appendChild(document.createElement("div"));c.innerHTML='';var e=c.firstChild;e.style.behavior="url(#default#VML)";a=!e||"object"==typeof e.adj;c.parentNode.removeChild(c)}return b||a};d.Graph.prototype.generateLabel=function(a){var c,e=this.config.label.template&&this.config.label.data?this.config.label.data:{},f=this.config.label.yLength||this.config.yLength,g=b.proxy(function(){this.labels=new d.Graph.Labels(this.$graphContainer,f,a);this.getData(b.proxy(function(a){for(var b=0;b
');e&&b('
').html(e).prependTo(this.$labelContainer);this.totals={};for(f=0;f
').appendTo(a)};d.Graph.Labels.Total.prototype.createTotalCount=function(a){c('"+a+" ").appendTo(this.$totalContainer)};d.Graph.Labels.Total.prototype.createDeltaCount=function(a){var b=a?a<0?"minus ":"plus ":"zero ";c('('+a+")").appendTo(this.$totalContainer)};d.Graph.css={};d.Graph.css.Base=function(a,c){this.len=a.length;this.$graphEl=b('
')};d.Graph.css.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.css.Base.prototype.horizontalBar=function(a,c,e,f){c.width&&this.$graphEl.css({width:c.width,"max-width":"100%",margin:"0 auto"});for(var g,h,i,j,k,l,m=c.barColor||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod)[1],n=c.barBackgroundColor||"#f0f0f0",o=c.dateColor||"#999999",p=c.dateColorSaturday||o,q=c.dateColorSunday||o,r=c.labelColor||"#999999",s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=parseInt(c.dateLabelSize,10)||v,x=function(){return b('
')},y=b.map(a,function(a){return parseInt(a.y,10)}),z=b.map(a,function(a){return{value:""+parseInt(a.x.substr(a.x.lastIndexOf("-")+1),10),weekday:d.Date.parse(a.x)?d.Date.parse(a.x).getDay():null}}),A=Math.max.apply(null,y)||1,B=c.yLabel||y,C=this.len;C>0;){C-=1;g=Math.floor(y[C]/A*100)-15;h=x();i=h.find(".css-graph-bar-background");i.css({"background-color":n});if(c.showDate){l=h.find(".css-graph-date");l.text(z[C].value).css({color:o,"font-size":w+"px","line-height":s+"px"});6===z[C].weekday?l.addClass("saturday").css({color:p}):0===z[C].weekday&&l.addClass("sunday").css({color:q});h.find(".css-graph-bar-container").css({"margin-left":t+"px"})}j=h.find(".css-graph-bar");j.css({width:g+"%","background-color":m});k=h.find(".css-graph-bar-count");k.text(B[C]).css({color:r,"font-size":v+"px","line-height":s+"px"});h.appendTo(this.$graphEl)}this.$graphEl.appendTo(f)};d.Graph.css.Base.prototype.ratioHorizontalBar=function(a,c,e,f){var g,h,i,j,k,l,m,n,o,p,q,r=c.yLength,s=parseInt(c.barWidth,10)||30,t=parseInt(c.barMarginLeft,10)||30,u=parseInt(c.barInterval,10)||5,v=parseInt(c.labelSize,10)||.45*s,w=c.dateColor||"#999999",x=c.barColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),y=c.labelColors,z=c.labelClasses;for(g=0;g
').appendTo(this.$graphEl);if(c.showDate&&i.x){o=""+parseInt(i.x.substr(i.x.lastIndexOf("-")+1),10);b('
'+o+"
").appendTo(l)}m=b('
').appendTo(l);c.showDate&&m.css({"margin-left":t+"px"});for(h=0;h
');n.css({width:p+"%","background-color":x[h]});c.showCount&&n.text(j[h]);z&&z[h]&&n.addClass(z[h]);y&&y[h]&&n.css({color:y[h]});n.appendTo(m)}}m.appendTo(l)}this.$graphEl.appendTo(f)};d.Graph.css.horizontalBar=d.Graph.css.ratioHorizontalBar=function(a,b,c,e){var f=new d.Graph.css.Base(a,b,c,e);f[b.type.slice(b.type.lastIndexOf(".")+1)](a,b,c,e);return f};d.Graph.easel={};d.Graph.easel.Base=function(a,c,d,e){this.data=a;this.config=c;this.range=d;this.$container=e;if(window.createjs||"function"!=typeof window.require){parseInt(c.width||e.width(),10)?this.buildCanvas(createjs):setTimeout(b.proxy(function(){this.buildCanvas(createjs)},this),100)}else require(["easeljs"],b.proxy(function(){this.buildCanvas(createjs)},this))};d.Graph.easel.Base.prototype.buildCanvas=function(a){this.width=parseInt(this.config.width||this.$container.width(),10)||300;this.height=parseInt(this.config.height||this.$container.height(),10)||300;this.$canvas=b('').appendTo(this.$container);this.canvas=this.$canvas.get(0);this.canvas.getContext("2d");this.stage=this.graph=new a.Stage(this.canvas);this.stage.update();this[this.config.type.split(".")[1]](this.data,this.config)};d.Graph.easel.Base.prototype.remove=function(){this.$canvas.remove()};d.Graph.easel.Base.prototype.bar=function(a,c){for(var e,f,g,h,i,j=a.length,k=c.chartColorsAlpha?c.chartColorsAlpha[0]:1,l=c.chartColors||d.Graph.getCachedChartColors(c.id,null,c.chartColorsMethod),m=this.convertColor(l[0],k),n=parseInt(c.barMargin,10)||10,o=Math.floor(this.width/j),p=o-n,q=Math.floor((this.width-o*j)/2)+n/2,r=b.map(a,function(a){return parseInt(a.y,10)}),s=Math.max.apply(null,r)||1,t=0;t0){var f=a[b-1],g=f+Math.floor((d-f)/2);g=Math.floor(g/y*e)+p;d=Math.floor(d/y*e)+p;c=c.concat([g,d])}else{d=Math.floor(d/y*e)+p;c.push(d)}});return c};b.each(u,function(a,b){z.push(A(b))});var B,C,D,E=[],F=[],G=s,H=[];for(w=0;w
').css({height:n+"px",width:m+"px"}).prependTo(g);e=b.extend({},e,{element:e.id,data:c,xkey:"x",labels:this.getYLabels_(l,e.labels),ykeys:this.getYKeys_(l),ymax:this.getYMax_(c,k,l),ymin:e.ymin||0,lineWidth:parseInt(e.lineWidth,10)||6,pointSize:parseInt(e.pointSize,10)||6,smooth:e.smooth||!1});e.barColors=e.barColors||this.getChartColors(e);e.colors=e.colors||this.getChartColors(e);e.lineColors=e.lineColors||this.getChartColors(e);e.numLines=parseInt(e.numLines,10)||this.getNumLines_(e.ymax,n);e.pointStrokeColors=e.pointStrokeColors?e.pointStrokeColors.split(/,/):[];if(!e.pointStrokeColors.length)for(h=0;h=18?9:2===a?3:a/2+1;c=Math.min(c||1,Math.floor(b/56));return c};d.Graph.morris.Base.prototype.getTotalCount_=function(a,c){var d,e=0,f="y"+(c||"");b.each(a,function(a,b){d=b[f]||b.value||0;"string"==typeof d&&(d=parseFloat(d.replace(/,/g,""),10));e+=d});return e};d.Graph.morris.Base.prototype.remove=function(){this.$graphEl.remove()};d.Graph.morris.bar=d.Graph.morris.line=d.Graph.morris.donut=d.Graph.morris.area=function(a,b,c,e){if(d.Graph.test.vml()){return new d.Graph.morris.Base(a,b,c,e)}console.warn("Morris graph requires for SVG/VML capability");e.trigger("REMOVE")};d.Slider=function(a,c,e,f,g){if(!b.ui||!b.ui.slider)throw"ChartAPI.Slider requied jQuery UI Slider";var h=this;this.id="slider-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.range=d.Range.generate(c);this.$dataRangeTarget=e;this.$sliderContainer=b('
');this.eventTargetList={update:this.initEventTarget(),amount:this.initEventTarget()};b.each(f,function(a,b){h.eventTargetList.update.add(b)});b.each(g,function(a,b){h.eventTargetList.amount.add(b)});this.$sliderContainer.on("APPEND_TO",function(a,c){h.$container=c;h.draw_(c);return b(this)});this.$sliderContainer.on("BUILD_SLIDER",function(){h.$dataRangeTarget.trigger("GET_DATA_RANGE",function(a){h.buildSlider(a.min,a.max)});return b(this)});this.$sliderContainer.on("SET_DATA_RANGE",function(a,c){h.$dataRangeTarget=c;return b(this)});this.$sliderContainer.on("ADD_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].add(b)});return b(this)});this.$sliderContainer.on("REMOVE_EVENT_LIST",function(a,c,d){d=b.isArray(d)?d:[d];b.each(d,function(a,b){h.eventTargetList[c].remove(b)});return b(this)});this.$sliderContainer.on("ERASE",function(){h.erase_();return b(this)});this.$sliderContainer.on("REDRAW",function(){b(this).trigger("BUILD_SLIDER").trigger("APPEND_TO",[h.$container]);return b(this)});this.$sliderContainer.on("UPDATE",function(a,c){h.$slider("values",c);h.updateSliderAmount(c);return b(this)});return this.$sliderContainer};d.Slider.prototype.initEventTarget=function(){var a=[];return{add:function(b){a.push(b)},remove:function(c){a=b.grep(a,function(a){return a!==c})},get:function(){return a}}};d.Slider.prototype.buildSlider=function(a,c,d){var e,f,g=["change","create","slide","start","stop"],h=this;d=d||[this.range.min,this.range.max];if(this.$slider){this.$slider.destroy();this.$slider.remove()}e={range:!0,min:a,max:c,values:d,slide:function(a,b){h.updateSliderAmount(b.values,b)},stop:function(a,b){h.updateGraphAndList(b.values)}};g.forEach(function(a){if(h.config.callback[a]){f=e[a];e[a]=function(b,c){h.config.callback[a](b,c);f&&f(b,c)}}});this.$slider=b('
').slider(e).appendTo(h.$sliderContainer);if(!this.config.hideSliderAmount){this.$amount=b('
');this.config.appendSliderAmountBottom?this.$amount.appendTo(this.$sliderContainer):this.$amount.prependTo(this.$sliderContainer);this.updateSliderAmount(d)}};d.Slider.prototype.draw_=function(a){this.$sliderContainer.appendTo(a)};d.Slider.prototype.erase_=function(){this.$slider&&this.$slider.destroy();this.$sliderContainer.html("")};d.Slider.prototype.updateSliderAmount=function(a,c){var e,f,g,h,i=this.range.maxLength,j=this.$amount;if(this.range.isTimeline){e=d.Date.parse(a[0]);f=d.Date.parse(a[1]);g=this.range.unit;h=d.Range.getLength(e,f,g);if(c&&h>i)if(c.value===c.values[0]){f=d.Date.calcDate(e,i,g,!1);this.$slider.slider("values",1,f.valueOf())}else{e=d.Date.calcDate(f,i,g,!0);this.$slider.slider("values",0,e.valueOf())}j&&j.text([d.Date.createXLabel(e,g),d.Date.createXLabel(f,g)].join(" - "))}else{e=a[0];f=a[1];if(f-e>i)if(c.value===c.values[0]){f=i-e;this.$slider.slider("values",1,f)}else{e=f-i;this.$slider.slider("values",0,e)}j&&b.each(this.eventTargetList.amount.get(),function(a,b){b.trigger("GET_LABEL",[[e,f],function(a){j.text([a[0],a[1]].join(" - "))}])})}};d.Slider.prototype.updateGraphAndList=function(a,c){b.each(this.eventTargetList.update.get(),function(b,d){d.trigger("UPDATE",[a,c])})};d.Slider.prototype.update_=function(a,b){this.$slider.slider("values",a,b)};d.List=function(a,c){this.id="list-"+(new Date).valueOf()+Math.floor(100*Math.random());this.config=a;this.config.staticPath=this.config.staticPath||"";if(this.config.data&&"string"==typeof this.config.data)this.origData_=b.getJSON(this.config.staticPath+this.config.data);else{this.origData_=b.Deferred();this.origData_.resolve(this.config.data)}if(this.config.template){if(window.require&&"function"==typeof require){var e=this.config.type||"text";this.template_=b.Deferred();require([e+"!"+this.config.staticPath+this.config.template],b.proxy(function(a){this.template_.resolve(a)},this))}else this.template_=b.get(this.config.staticPath+this.config.template,"text");this.range=d.Range.generate(c);this.$listContainer=b('
');this.$listContainer.on("UPDATE",b.proxy(function(a,b){this.update_(b)},this));this.$listContainer.on("GET_DATA_RANGE",b.proxy(function(a,c){this.getData(b.proxy(function(a){c(d.Range.getDataRange(a,this.range.isTimeline))},this));return this.$listContainer},this));this.$listContainer.on("GET_LABEL",b.proxy(function(a,c,d){this.getData(b.proxy(function(a){d(this.getDataLabelByIndex(c,a))},this));return this.$listContainer},this));this.$listContainer.on("APPEND_TO",b.proxy(function(a,c){this.$listContainer.appendTo(c);this.getData(b.proxy(function(a){this.draw_(a)},this));return this.$listContainer},this));return this.$listContainer}};d.List.prototype.getData=function(a){this.config.data?d.Data.getData(this.origData_,this.$listContainer,a,this):a()};d.List.prototype.getTemplate=function(a){d.Data.getData(this.template_,this.$listContainer,a,this)};d.List.prototype.draw_=function(a){var b=this;this.getTemplate(function(c){a=b.createListData(a);b.$listContainer.html(_.template(c,a))})};d.List.prototype.getDataLabelByIndex=function(a,c){var d=this.config.dataLabel||"x";return b.map(a,function(a){return c[a][d]})};d.List.prototype.createListData=function(a){var b="";a&&(b=this.range.isTimeline?d.Data.filterData(a,this.range.max,this.range.min,this.range.unit,1,!0):a.slice(this.range.min,this.range.max+1));return{data:b}};d.List.prototype.update_=function(a,b){var c=this;a=a||[];b=b||this.range.unit;this.range=d.Range.generate({start:a[0]||this.range.start,end:a[1]||this.range.end,length:null,maxLength:this.range.maxLength,unit:b,dataType:this.range.dataType});this.getData(function(a){c.draw_(a)})};d.Build=function(a){var c;if("string"==typeof a&&/\.json$/.test(a)){c=b('
');d.Data.getData(b.getJSON(a),null,function(a){a.$container=c;d.Build_(a).trigger("APPEND")})}else c=d.Build_(a).trigger("APPEND");return c};d.Build_=function(a){var c,e,f,g,h,i,j;c=a.$container||b('
');i=[];if(a.graph){e=new d.Graph(a.graph,a.range);i.push(e)}if(a.list){g=new d.List(a.list,a.range);a.list.data&&i.push(g)}if(a.graph&&"donut"!==a.graph.type){h=e;j=[e]}else{h=g;j=[g]}var k=function(){var a=window.navigator?window.navigator.userAgent:"";return/android|iphone|ipod|ipad/i.test(a)};!a.slider||!a.slider.force&&k()||(f=new d.Slider(a.slider,a.range,h,i,j));c.on("APPEND",function(){e&&e.trigger("APPEND_TO",[c]);f&&f.trigger("BUILD_SLIDER").trigger("APPEND_TO",[c]);g&&g.trigger("APPEND_TO",[c])});c.on("GET_CONTAINER",function(a,b,c){c({graph:e,slider:f,list:g}[b])});return c};return d}(this,jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 08714f0..3ee6cce 100644 --- a/package.json +++ b/package.json @@ -22,15 +22,15 @@ "node": ">= 0.8.0" }, "devDependencies": { - "grunt-contrib-concat": "~0.1.2", - "grunt-contrib-uglify": "~0.1.1", - "grunt-contrib-jshint": "~0.1.1", - "grunt-contrib-watch": "~0.2.0", - "grunt": "~0.4.1", - "matchdep": "~0.1.2", - "grunt-preprocess": "~2.3.0", - "grunt-contrib-cssmin": "~0.6.0", - "grunt-contrib-clean": "~0.4.1", - "grunt-contrib-copy": "~0.4.1" + "grunt-contrib-concat": "~1.0.1", + "grunt-contrib-uglify": "~2.2.0", + "grunt-contrib-jshint": "~1.1.0", + "grunt-contrib-watch": "~1.0.0", + "grunt": "~1.0.1", + "matchdep": "~1.0.1", + "grunt-preprocess": "~5.1.0", + "grunt-contrib-cssmin": "~2.0.0", + "grunt-contrib-clean": "~1.0.0", + "grunt-contrib-copy": "~1.0.0" } } diff --git a/src/slider.js b/src/slider.js index e0e428a..3893bfb 100644 --- a/src/slider.js +++ b/src/slider.js @@ -150,14 +150,14 @@ ChartAPI.Slider.prototype.initEventTarget = function () { * @return nothing */ ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) { - var that = this; + var options, defaultCallback, events = ['change', 'create', 'slide', 'start', 'stop'], that = this; values = values || [this.range.min, this.range.max]; if (this.$slider) { this.$slider.destroy(); this.$slider.remove(); } - this.$slider = $('
').slider({ + options = { 'range': true, 'min': sliderMin, 'max': sliderMax, @@ -168,7 +168,19 @@ ChartAPI.Slider.prototype.buildSlider = function (sliderMin, sliderMax, values) 'stop': function (e, ui) { that.updateGraphAndList(ui.values); } - }).appendTo(that.$sliderContainer); + }; + events.forEach(function(value) { + if (that.config.callback[value]) { + defaultCallback = options[value]; + options[value] = function(e, ui) { + that.config.callback[value](e, ui); + if (defaultCallback) { + defaultCallback(e, ui); + } + }; + } + }); + this.$slider = $('
').slider(options).appendTo(that.$sliderContainer); if (!this.config.hideSliderAmount) { this.$amount = $('
');