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