-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathangular-chart.min.js
1 lines (1 loc) · 10.6 KB
/
angular-chart.min.js
1
!function(){"use strict";function t(){return{restrict:"EA",scope:{options:"=",instance:"=?"},controller:"AngularChartController"}}var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0,n=e.module("angularChart",[]);n.directive("angularChart",t),n.directive("angularchart",t),"function"==typeof define&&define.amd?define("angularChart",["c3","angular"],n):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=n)}(),function(){"use strict";function t(){function t(t){var e={scope:t,dimensionsCallback:null,dimensionsTypeCallback:null,chartCallback:null,stateCallback:null,dataCallback:null,dataSmallWatcher:null,dataBigWatcher:null,disableStateWatcher:!1};return n(e),a(e),i(e),o(e),s(e),r(e),e}function n(t){t.scope.$watch(function(){var n=t.scope.options&&t.scope.options.dimensions;return e.isObject(n)&&(n=e.copy(n),e.forEach(n,function(t){t.type&&delete t.type})),n},function(){e.isFunction(t.dimensionsCallback)&&t.dimensionsCallback()},!0)}function a(t){t.scope.$watch(function(){var n={};return t.scope.options&&t.scope.options.dimensions&&e.forEach(t.scope.options.dimensions,function(t,e){n[e]=t.type}),n},function(){e.isFunction(t.dimensionsTypeCallback)&&t.dimensionsTypeCallback()},!0)}function i(t){t.scope.$watch("options.chart",function(){t.chartCallback&&t.chartCallback()},!0)}function o(t){t.scope.$watch("options.state",function(){!t.disableStateWatcher&&e.isFunction(t.stateCallback)&&t.stateCallback()},!0)}function s(t){t.scope.$watch("options.chart.data.watchLimit",function(){r(t)})}function r(t){var n=e.isObject(t.scope.options)&&e.isObject(t.scope.options.chart)&&t.scope.options.chart.data&&e.isNumber(t.scope.options.chart.data.watchLimit)?t.scope.options.chart.data.watchLimit:100,a=0;e.isObject(t.scope.options)&&e.isArray(t.scope.options.data)&&(a=t.scope.options.data.length),n>a?(t.dataSmallWatcher||(t.dataSmallWatcher=c(t)),t.dataBigWatcher&&(t.dataBigWatcher(),t.dataBigWatcher=void 0)):(t.dataBigWatcher||(t.dataBigWatcher=u(t)),t.dataSmallWatcher&&(t.dataSmallWatcher(),t.dataSmallWatcher=void 0))}function c(t){return t.scope.$watch("options.data",function(){e.isFunction(t.dataCallback)&&t.dataCallback(),r(t)},!0)}function u(t){return t.scope.$watch(function(){return t.scope.options.data&&e.isArray(t.scope.options.data)?t.scope.options.data.length:0},function(){e.isFunction(t.dataCallback)&&t.dataCallback(),r(t)})}function l(t,e){t.disableStateWatcher=!0,t.scope.$apply(e),t.disableStateWatcher=!1}function d(t,e){t.scope.$apply(e)}var h={init:t,updateState:l,applyFunction:d};return h}var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0;e.module("angularChart").service("AngularChartWatcher",t)}(),function(){"use strict";function t(t){function n(t,n){e.isObject(t.state)&&e.isObject(t.state)&&e.isArray(t.state.range)?n.zoom(t.state.range):n.unzoom()}function a(t){e.isObject(t.state)||(t.state={}),e.isObject(t.state.range)||(t.state.range=[])}function i(n,i,o){e.isObject(n.chart)&&e.isObject(n.chart.zoom)&&n.chart.zoom.enabled===!0&&(i.zoom.onzoomend=function(i){t.updateState(o,function(){a(n),n.state.range=i}),e.isFunction(n.chart.zoom.onzoomend)&&t.applyFunction(o,function(){n.chart.zoom.onzoomend(i)})}),e.isObject(n.chart)&&e.isObject(n.chart.subchart)&&n.chart.subchart.show===!0&&(i.subchart.onbrush=function(i){t.updateState(o,function(){a(n),n.state.range=i}),e.isFunction(n.chart.subchart.onbrush)&&t.applyFunction(o,function(){n.chart.subchart.onbrush(i)})})}function o(t,e){l.disableSelectionListener=!0,e.forEach(function(e){t.select([e.id],[e.index])}),l.disableSelectionListener=!1}function s(t){l.disableSelectionListener=!0,t.unselect(),l.disableSelectionListener=!1}function r(t,n){e.isObject(t.state)&&e.isArray(t.state.selected)?o(n,t.state.selected):s(n)}function c(t){e.isObject(t.state)||(t.state={}),e.isArray(t.state.selected)||(t.state.selected=[])}function u(n,a,i){e.isObject(n.chart)&&e.isObject(n.chart.data)&&e.isObject(n.chart.data.selection)&&n.chart.data.selection.enabled===!0&&(a.data.onselected=function(a,o){l.disableSelectionListener||(t.updateState(i,function(){c(n),n.state.selected.push(a)}),e.isFunction(n.chart.data.onselected)&&t.applyFunction(i,function(){n.chart.data.onselected(a,o)}))},a.data.onunselected=function(a,o){l.disableSelectionListener||(t.updateState(i,function(){c(n),n.state.selected=n.state.selected.filter(function(t){return t.id!==a.id||t.index!==a.index})}),e.isFunction(n.chart.data.onunselected)&&t.applyFunction(i,function(){n.chart.data.onunselected(a,o)}))})}var l={disableSelectionListener:!1,synchronizeZoom:i,applyZoom:n,synchronizeSelection:u,applySelection:r};return l}t.$inject=["AngularChartWatcher"];var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0;e.module("angularChart").service("AngularChartState",t)}(),function(){"use strict";function t(t,a,i,o,s){function r(t,n){return n=n||{},Object.keys(n).forEach(function(a){t[a]=e.isObject(n[a])&&n[a]&&t[a]?r(t[a],n[a]):n[a]}),t}var c=function(t,e){this.deferredChart=a.defer(),this.chart=this.deferredChart.promise,this.baseConfiguration={},this.configuration={},this.scopeReference=null,this.options={},this.watcher=null,this.init(t,e)};return c.prototype.init=function(e,n){this.watcher=i.init(n),this.baseConfiguration=e,this.scopeReference=n,this.updateCallback();var a=this;t(function(){a.registerCallbacks()})},c.prototype.registerCallbacks=function(){var t=this;this.watcher.dimensionsCallback=function(){t.updateCallback()},this.watcher.chartCallback=function(){t.updateCallback()},this.watcher.dataCallback=function(){t.updateCallback()},this.watcher.dimensionsTypeCallback=function(){t.transformCallback()},this.watcher.stateCallback=function(){t.stateCallback()}},c.prototype.updateCallback=function(){this.configuration=e.copy(this.baseConfiguration),this.buildOptions(),this.convertOptions(),this.applyChartOptions(),this.synchronizeState();var n=this;t(function(){n.generateChart(n),n.stateCallback()})},c.prototype.transformCallback=function(){var t=this;t.options&&t.options.dimensions&&e.forEach(t.options.dimensions,function(e,n){t.chart.transform(e.type,n)})},c.prototype.buildOptions=function(){this.options=e.isObject(this.scopeReference.options)?this.scopeReference.options:{}},c.prototype.convertOptions=function(){o.convertData(this.options,this.configuration),o.convertDimensions(this.options,this.configuration)},c.prototype.applyChartOptions=function(){this.merge(this.configuration,this.options.chart)},c.prototype.synchronizeState=function(){s.synchronizeZoom(this.options,this.configuration,this.watcher),s.synchronizeSelection(this.options,this.configuration,this.watcher)},c.prototype.generateChart=function(t){var e=n.generate(t.configuration);t.deferredChart.resolve(e),t.scopeReference.instance=e,t.chart=e,this.scopeReference.$emit("angular-chart-rendered",t.configuration,t.chart)},c.prototype.stateCallback=function(){s.applyZoom(this.options,this.chart),s.applySelection(this.options,this.chart)},c.prototype.destroyChart=function(){this.chart.destroy&&this.chart.destroy()},c.prototype.merge=e.merge||r,{getInstance:function(t,e){return new c(t,e)}}}t.$inject=["$timeout","$q","AngularChartWatcher","AngularChartConverter","AngularChartState"];var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0,n=window.c3?window.c3:"undefined"!=typeof require?require("c3"):void 0;e.module("angularChart").factory("AngularChartService",t)}(),function(){"use strict";function t(){function t(t,n){e.isArray(t.data)&&(n.data.json=t.data)}function n(t,n){if(e.isObject(t.dimensions)){n.axis.y.show=!1;var a={isUse:!1,y:[],y2:[]};e.forEach(t.dimensions,function(i,o){(!e.isDefined(i.show)||i.show)&&n.data.keys.value.push(o),e.isString(i.name)&&(n.data.names[o]=i.name),e.isDefined(i.type)&&(n.data.types[o]=i.type),e.isString(i.color)&&(n.data.colors[o]=i.color),"y2"===i.axis?(n.data.axes[o]="y2",n.axis.y2.show=!0,a.y2.push(o)):"x"!==i.axis&&(n.axis.y.show=!0,a.y.push(o)),a[o]=!0,e.isDefined(i.displayFormat)?(a.inUse=!0,a[o]=i.displayFormat):(e.isDefined(i.prefix)||e.isDefined(i.postfix))&&(a.inUse=!0,a[o]=function(t){return(i.prefix||"")+t+(i.postfix||"")}),i.label===!0&&(n.data.labels.format[o]=a[o]),"x"===i.axis&&(n.data.keys.x=o,n.data.x=o,(e.isString(a[o])||e.isFunction(a[o]))&&(n.axis.x.tick.format=a[o]),-1!==["datetime","date","timeseries"].indexOf(i.dataType)?(n.axis.x.type="timeseries",i.dataFormat&&(n.data.xFormat=i.dataFormat)):-1!==["numeric","number","indexed"].indexOf(i.dataType)?n.axis.x.type="indexed":("category"===i.dataType||e.isArray(t.data)&&t.data[0]&&t.data[0][o]&&t.data[0][o]&&!e.isNumber(t.data[0][o]))&&(n.axis.x.type="category"))}),a.inUse&&(n.tooltip={format:{value:function(t,n,i){return e.isFunction(a[i])?a[i](t):t}}}),e.forEach(["y","y2"],function(i){var o=null,s=null;e.forEach(a[i],function(n){null===o?(o=a[n],s=n):o===a[n]||!e.isFunction(t.dimensions[s].displayFormat)&&!e.isFunction(t.dimensions[n].displayFormat)&&(!e.isDefined(t.dimensions[s].prefix)&&!e.isDefined(t.dimensions[n].prefix)||e.isDefined(t.dimensions[s].prefix)&&e.isDefined(t.dimensions[n].prefix)&&t.dimensions[s].prefix===t.dimensions[n].prefix)&&(!e.isDefined(t.dimensions[s].postfix)&&!e.isDefined(t.dimensions[n].postfix)||e.isDefined(t.dimensions[s].postfix)&&e.isDefined(t.dimensions[n].postfix)&&t.dimensions[s].postfix===t.dimensions[n].postfix)||(o=!1)}),o!==!1&&o!==!0&&null!==o&&(n.axis[i].tick.format=o)})}}var a={convertData:t,convertDimensions:n};return a}var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0;e.module("angularChart").service("AngularChartConverter",t)}(),function(){"use strict";function t(t,n,a,i,o){function s(){r(),c(),u(),l(),d()}function r(){a.when(t.options,function(e){t.options=e})}function c(){t.dataAttributeChartID="chartid"+Math.floor(1000000001*Math.random()),e.element(n).attr("id",t.dataAttributeChartID),h.bindto="#"+t.dataAttributeChartID}function u(){e.element(n).css("display","block")}function l(){p=o.getInstance(h,t),t.instance=p.chart}function d(){t.$on("$destroy",function(){p.destroyChart(h),n.remove()})}var h=e.copy(i),p=null;s()}t.$inject=["$scope","$element","$q","baseConfiguration","AngularChartService"];var e=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0;e.module("angularChart").controller("AngularChartController",t)}(),function(){"use strict";var t=window.angular?window.angular:"undefined"!=typeof require?require("angular"):void 0,e={data:{json:[],keys:{value:[]},names:{},types:{},colors:{},axes:{},labels:{format:{}}},axis:{y:{show:!0,tick:{}},y2:{tick:{}},x:{tick:{}}},zoom:{},subchart:{},tooltip:{format:{}}};t.module("angularChart").value("baseConfiguration",e)}();