forked from GraFiddle/angular-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-chart.min.js
More file actions
1 lines (1 loc) · 10.3 KB
/
angular-chart.min.js
File metadata and controls
1 lines (1 loc) · 10.3 KB
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,a=n.module("angularChart",[]);a.directive("angularChart",t),a.directive("angularchart",t),"function"==typeof define&&define.amd?define("angularChart",["c3","angular"],a):"undefined"!=typeof exports&&"undefined"!=typeof module&&(module.exports=a)}(),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 a(n),e(n),i(n),o(n),s(n),r(n),n}function a(t){t.scope.$watch(function(){var a=t.scope.options&&t.scope.options.dimensions;return n.isObject(a)&&(a=n.copy(a),n.forEach(a,function(t){t.type&&delete t.type})),a},function(){n.isFunction(t.dimensionsCallback)&&t.dimensionsCallback()},!0)}function e(t){t.scope.$watch(function(){var a={};return t.scope.options&&t.scope.options.dimensions&&n.forEach(t.scope.options.dimensions,function(t,n){a[n]=t.type}),a},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 a=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,e=0;n.isObject(t.scope.options)&&n.isArray(t.scope.options.data)&&(e=t.scope.options.data.length),a>e?(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 a(t,a){n.isObject(t.state)&&n.isObject(t.state)&&n.isArray(t.state.range)?a.zoom(t.state.range):a.unzoom()}function e(t){n.isObject(t.state)||(t.state={}),n.isObject(t.state.range)||(t.state.range=[])}function i(a,i,o){n.isObject(a.chart)&&n.isObject(a.chart.zoom)&&a.chart.zoom.enabled===!0&&(i.zoom.onzoomend=function(i){t.updateState(o,function(){e(a),a.state.range=i}),n.isFunction(a.chart.zoom.onzoomend)&&t.applyFunction(o,function(){a.chart.zoom.onzoomend(i)})}),n.isObject(a.chart)&&n.isObject(a.chart.subchart)&&a.chart.subchart.show===!0&&(i.subchart.onbrush=function(i){t.updateState(o,function(){e(a),a.state.range=i}),n.isFunction(a.chart.subchart.onbrush)&&t.applyFunction(o,function(){a.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,a){n.isObject(t.state)&&n.isArray(t.state.selected)?o(a,t.state.selected):s(a)}function c(t){n.isObject(t.state)||(t.state={}),n.isArray(t.state.selected)||(t.state.selected=[])}function u(a,e,i){n.isObject(a.chart)&&n.isObject(a.chart.data)&&n.isObject(a.chart.data.selection)&&a.chart.data.selection.enabled===!0&&(e.data.onselected=function(e,o){l.disableSelectionListener||(t.updateState(i,function(){c(a),a.state.selected.push(e)}),n.isFunction(a.chart.data.onselected)&&t.applyFunction(i,function(){a.chart.data.onselected(e,o)}))},e.data.onunselected=function(e,o){l.disableSelectionListener||(t.updateState(i,function(){c(a),a.state.selected=a.state.selected.filter(function(t){return t.id!==e.id||t.index!==e.index})}),n.isFunction(a.chart.data.onunselected)&&t.applyFunction(i,function(){a.chart.data.onunselected(e,o)}))})}var l={disableSelectionListener:!1,synchronizeZoom:i,applyZoom:a,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,e,i,o){function s(t,a){return a=a||{},Object.keys(a).forEach(function(e){n.isObject(a[e])&&a[e]&&t[e]?t[e]=s(t[e],a[e]):t[e]=a[e]}),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,a){this.watcher=e.init(a),this.baseConfiguration=n,this.scopeReference=a,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,a){t.chart.transform(n.type,a)})},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=a.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,a=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,a){n.isArray(t.data)&&(a.data.json=t.data)}function a(t,a){if(n.isObject(t.dimensions)){a.axis.y.show=!1;var e={isUse:!1,y:[],y2:[]};n.forEach(t.dimensions,function(i,o){(!n.isDefined(i.show)||i.show)&&a.data.keys.value.push(o),n.isString(i.name)&&(a.data.names[o]=i.name),n.isDefined(i.type)&&(a.data.types[o]=i.type),n.isString(i.color)&&(a.data.colors[o]=i.color),"y2"===i.axis?(a.data.axes[o]="y2",a.axis.y2.show=!0,e.y2.push(o)):"x"!==i.axis&&(a.axis.y.show=!0,e.y.push(o)),e[o]=!0,n.isDefined(i.displayFormat)?(e.inUse=!0,e[o]=i.displayFormat):(n.isDefined(i.prefix)||n.isDefined(i.postfix))&&(e.inUse=!0,e[o]=function(t){return(i.prefix||"")+t+(i.postfix||"")}),i.label===!0&&(a.data.labels.format[o]=e[o]),"x"===i.axis&&(a.data.keys.x=o,a.data.x=o,(n.isString(e[o])||n.isFunction(e[o]))&&(a.axis.x.tick.format=e[o]),-1!==["datetime","date","timeseries"].indexOf(i.dataType)?(a.axis.x.type="timeseries",i.dataFormat&&(a.data.xFormat=i.dataFormat)):-1!==["numeric","number","indexed"].indexOf(i.dataType)?a.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]))&&(a.axis.x.type="category"))}),e.inUse&&(a.tooltip={format:{value:function(t,a,i){return n.isFunction(e[i])?e[i](t):t}}}),n.forEach(["y","y2"],function(i){var o=null,s=null;n.forEach(e[i],function(a){null===o?(o=e[a],s=a):o===e[a]||!n.isFunction(t.dimensions[s].displayFormat)&&!n.isFunction(t.dimensions[a].displayFormat)&&(!n.isDefined(t.dimensions[s].prefix)&&!n.isDefined(t.dimensions[a].prefix)||n.isDefined(t.dimensions[s].prefix)&&n.isDefined(t.dimensions[a].prefix)&&t.dimensions[s].prefix===t.dimensions[a].prefix)&&(!n.isDefined(t.dimensions[s].postfix)&&!n.isDefined(t.dimensions[a].postfix)||n.isDefined(t.dimensions[s].postfix)&&n.isDefined(t.dimensions[a].postfix)&&t.dimensions[s].postfix===t.dimensions[a].postfix)||(o=!1)}),o!==!1&&o!==!0&&null!==o&&(a.axis[i].tick.format=o)})}}var e={convertData:t,convertDimensions:a};return e}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,a,e,i,o){function s(){r(),c(),u(),p=o.getInstance(d,t),a.data("chart",p.chart),l()}function r(){e.when(t.options,function(n){t.options=n})}function c(){t.dataAttributeChartID="chartid"+Math.floor(1000000001*Math.random()),n.element(a).attr("id",t.dataAttributeChartID),d.bindto="#"+t.dataAttributeChartID}function u(){n.element(a).css("display","block")}function l(){t.$on("$destroy",function(){p.destroyChart(d),a.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)}();