diff --git a/bower.json b/bower.json index 7eeafc7b..1c6e7535 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-chart.js", - "version": "1.0.0-alpha2", + "version": "1.0.0-alpha3", "main": [ "./dist/angular-chart.js" ], diff --git a/dist/angular-chart.js b/dist/angular-chart.js index bb068b73..7d083a74 100644 --- a/dist/angular-chart.js +++ b/dist/angular-chart.js @@ -96,7 +96,8 @@ chartSeries: '=?', chartColors: '=?', chartClick: '=?', - chartHover: '=?' + chartHover: '=?', + chartYAxes: '=?' }, link: function (scope, elem/*, attrs */) { var chart; @@ -106,7 +107,10 @@ // Order of setting "watch" matter scope.$watch('chartData', function (newVal, oldVal) { - if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) return; + if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) { + destroyChart(chart, scope); + return; + } var chartType = type || scope.chartType; if (! chartType) return; @@ -128,7 +132,7 @@ }); scope.$on('$destroy', function () { - if (chart) chart.destroy(); + destroyChart(chart, scope); }); function resetChart (newVal, oldVal) { @@ -154,13 +158,14 @@ var colors = getColors(type, scope); var cvs = elem[0], ctx = cvs.getContext('2d'); var data = Array.isArray(scope.chartData[0]) ? - getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors) : + getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors, scope.chartYAxes) : getData(scope.chartLabels, scope.chartData, colors); var options = angular.extend({}, ChartJs.getOptions(type), scope.chartOptions); // Destroy old chart if it exists to avoid ghost charts issue // https://github.com/jtblin/angular-chart.js/issues/187 - if (chart) chart.destroy(); + destroyChart(chart, scope); + chart = new ChartJs.Chart(ctx, { type: type, data: data, @@ -199,7 +204,6 @@ if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) { lastState = activePoints; scope[action](activePoints, evt); - scope.$apply(); } } }; @@ -265,14 +269,18 @@ return [r, g, b]; } - function getDataSets (labels, data, series, colors) { + function getDataSets (labels, data, series, colors, yaxis) { return { labels: labels, datasets: data.map(function (item, i) { - return angular.extend({}, colors[i], { + var dataset = angular.extend({}, colors[i], { label: series[i], data: item }); + if (yaxis) { + dataset.yAxisID = 'y-axis-' + (i + 1); + } + return dataset; }) }; } @@ -315,5 +323,11 @@ var options = angular.extend({}, Chart.defaults.global, ChartJs.getOptions(type), scope.chartOptions); return options.responsive; } + + function destroyChart(chart, scope) { + if(! chart) return; + chart.destroy(); + scope.$emit('chart-destroy', chart); + } } })); diff --git a/dist/angular-chart.js.tar.gz b/dist/angular-chart.js.tar.gz index 3e5ee18e..458b7958 100644 Binary files a/dist/angular-chart.js.tar.gz and b/dist/angular-chart.js.tar.gz differ diff --git a/dist/angular-chart.min.js b/dist/angular-chart.min.js index 399477cb..d258c768 100644 --- a/dist/angular-chart.min.js +++ b/dist/angular-chart.min.js @@ -1,2 +1,2 @@ -!function(t){"use strict";"object"==typeof exports?module.exports=t("undefined"!=typeof angular?angular:require("angular"),"undefined"!=typeof Chart?Chart:require("chart.js")):"function"==typeof define&&define.amd?define(["angular","chart"],t):t(angular,Chart)}(function(t,r){"use strict";function a(){var a={},n={Chart:r,getOptions:function(r){var n=r&&a[r]||{};return t.extend({},a,n)}};this.setOptions=function(r,n){return n?void(a[r]=t.extend(a[r]||{},n)):(n=r,void(a=t.extend(a,n)))},this.$get=function(){return n}}function n(a,n){function o(t,r){return t&&r&&t.length&&r.length?Array.isArray(t[0])?t.length===r.length&&t.every(function(t,a){return t.length===r[a].length}):r.reduce(c,0)>0?t.length===r.length:!1:!1}function c(t,r){return t+r}function i(r,a,n,e){var o=null;return function(c){var i=a.getElementsAtEvent||a.getPointsAtEvent;if(i){var u=i.call(a,c);e!==!1&&t.equals(o,u)!==!1||(o=u,r[n](u,c),r.$apply())}}}function u(n,e){for(var o=t.copy(e.chartColors||a.getOptions(n).chartColors||r.defaults.global.colors),c=o.length>16&255,n=r>>8&255,e=255&r;return[a,n,e]}function p(r,a,n,e){return{labels:r,datasets:a.map(function(r,a){return t.extend({},e[a],{label:n[a],data:r})})}}function C(t,r,a){return{labels:t,datasets:[{data:r,backgroundColor:a.map(function(t){return t.pointBackgroundColor}),hoverBackgroundColor:a.map(function(t){return t.backgroundColor})}]}}function v(t,r,a){Array.isArray(a.chartData[0])?t.data.datasets.forEach(function(t,a){t.data=r[a]}):t.data.datasets[0].data=r,t.update(),a.$emit("chart-update",t)}function y(t){return!t||Array.isArray(t)&&!t.length||"object"==typeof t&&!Object.keys(t).length}function b(n,e){var o=t.extend({},r.defaults.global,a.getOptions(n),e.chartOptions);return o.responsive}return function(r){return{restrict:"CA",scope:{chartGetColor:"=?",chartType:"=",chartData:"=?",chartLabels:"=?",chartOptions:"=?",chartSeries:"=?",chartColors:"=?",chartClick:"=?",chartHover:"=?"},link:function(c,l){function s(a,n){if(!y(a)&&!t.equals(a,n)){var e=r||c.chartType;e&&f(e)}}function f(r){if(b(r,c)&&0===l[0].clientHeight)return n(function(){f(r)},50,!1);if(c.chartData&&c.chartData.length){c.chartGetColor="function"==typeof c.chartGetColor?c.chartGetColor:h;var e=u(r,c),o=l[0],s=o.getContext("2d"),g=Array.isArray(c.chartData[0])?p(c.chartLabels,c.chartData,c.chartSeries||[],e):C(c.chartLabels,c.chartData,e),v=t.extend({},a.getOptions(r),c.chartOptions);d&&d.destroy(),d=new a.Chart(s,{type:r,data:g,options:v}),c.$emit("chart-create",d),o.onclick=c.chartClick?i(c,d,"chartClick",!1):t.noop,o.onmousemove=c.chartHover?i(c,d,"chartHover",!0):t.noop}}var d;e&&window.G_vmlCanvasManager.initElement(l[0]),c.$watch("chartData",function(t,a){if(t&&t.length&&(!Array.isArray(t[0])||t[0].length)){var n=r||c.chartType;if(n)return d&&o(t,a)?v(d,t,c):void f(n)}},!0),c.$watch("chartSeries",s,!0),c.$watch("chartLabels",s,!0),c.$watch("chartOptions",s,!0),c.$watch("chartColors",s,!0),c.$watch("chartType",function(r,a){y(r)||t.equals(r,a)||f(r)}),c.$on("$destroy",function(){d&&d.destroy()})}}}}r.defaults.global.multiTooltipTemplate="<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>",r.defaults.global.elements.line.borderWidth=2,r.defaults.global.elements.rectangle.borderWidth=2,r.defaults.global.colors=["#97BBCD","#DCDCDC","#F7464A","#46BFBD","#FDB45C","#949FB1","#4D5360"];var e="object"==typeof window.G_vmlCanvasManager&&null!==window.G_vmlCanvasManager&&"function"==typeof window.G_vmlCanvasManager.initElement;return e&&(r.defaults.global.animation=!1),t.module("chart.js",[]).provider("ChartJs",a).factory("ChartJsFactory",["ChartJs","$timeout",n]).directive("chartBase",["ChartJsFactory",function(t){return new t}]).directive("chartLine",["ChartJsFactory",function(t){return new t("line")}]).directive("chartBar",["ChartJsFactory",function(t){return new t("bar")}]).directive("chartRadar",["ChartJsFactory",function(t){return new t("radar")}]).directive("chartDoughnut",["ChartJsFactory",function(t){return new t("doughnut")}]).directive("chartPie",["ChartJsFactory",function(t){return new t("pie")}]).directive("chartPolarArea",["ChartJsFactory",function(t){return new t("polarArea")}])}); +!function(t){"use strict";"object"==typeof exports?module.exports=t("undefined"!=typeof angular?angular:require("angular"),"undefined"!=typeof Chart?Chart:require("chart.js")):"function"==typeof define&&define.amd?define(["angular","chart"],t):t(angular,Chart)}(function(t,r){"use strict";function a(){var a={},e={Chart:r,getOptions:function(r){var e=r&&a[r]||{};return t.extend({},a,e)}};this.setOptions=function(r,e){return e?void(a[r]=t.extend(a[r]||{},e)):(e=r,void(a=t.extend(a,e)))},this.$get=function(){return e}}function e(a,e){function o(t,r){return t&&r&&t.length&&r.length?Array.isArray(t[0])?t.length===r.length&&t.every(function(t,a){return t.length===r[a].length}):r.reduce(c,0)>0?t.length===r.length:!1:!1}function c(t,r){return t+r}function i(r,a,e,n){var o=null;return function(c){var i=a.getElementsAtEvent||a.getPointsAtEvent;if(i){var u=i.call(a,c);n!==!1&&t.equals(o,u)!==!1||(o=u,r[e](u,c))}}}function u(e,n){for(var o=t.copy(n.chartColors||a.getOptions(e).chartColors||r.defaults.global.colors),c=o.length>16&255,e=r>>8&255,n=255&r;return[a,e,n]}function p(r,a,e,n,o){return{labels:r,datasets:a.map(function(r,a){var c=t.extend({},n[a],{label:e[a],data:r});return o&&(c.yAxisID="y-axis-"+(a+1)),c})}}function C(t,r,a){return{labels:t,datasets:[{data:r,backgroundColor:a.map(function(t){return t.pointBackgroundColor}),hoverBackgroundColor:a.map(function(t){return t.backgroundColor})}]}}function v(t,r,a){Array.isArray(a.chartData[0])?t.data.datasets.forEach(function(t,a){t.data=r[a]}):t.data.datasets[0].data=r,t.update(),a.$emit("chart-update",t)}function y(t){return!t||Array.isArray(t)&&!t.length||"object"==typeof t&&!Object.keys(t).length}function b(e,n){var o=t.extend({},r.defaults.global,a.getOptions(e),n.chartOptions);return o.responsive}function m(t,r){t&&(t.destroy(),r.$emit("chart-destroy",t))}return function(r){return{restrict:"CA",scope:{chartGetColor:"=?",chartType:"=",chartData:"=?",chartLabels:"=?",chartOptions:"=?",chartSeries:"=?",chartColors:"=?",chartClick:"=?",chartHover:"=?",chartYAxes:"=?"},link:function(c,l){function s(a,e){if(!y(a)&&!t.equals(a,e)){var n=r||c.chartType;n&&f(n)}}function f(r){if(b(r,c)&&0===l[0].clientHeight)return e(function(){f(r)},50,!1);if(c.chartData&&c.chartData.length){c.chartGetColor="function"==typeof c.chartGetColor?c.chartGetColor:h;var n=u(r,c),o=l[0],s=o.getContext("2d"),g=Array.isArray(c.chartData[0])?p(c.chartLabels,c.chartData,c.chartSeries||[],n,c.chartYAxes):C(c.chartLabels,c.chartData,n),v=t.extend({},a.getOptions(r),c.chartOptions);m(d,c),d=new a.Chart(s,{type:r,data:g,options:v}),c.$emit("chart-create",d),o.onclick=c.chartClick?i(c,d,"chartClick",!1):t.noop,o.onmousemove=c.chartHover?i(c,d,"chartHover",!0):t.noop}}var d;n&&window.G_vmlCanvasManager.initElement(l[0]),c.$watch("chartData",function(t,a){if(!t||!t.length||Array.isArray(t[0])&&!t[0].length)return void m(d,c);var e=r||c.chartType;if(e)return d&&o(t,a)?v(d,t,c):void f(e)},!0),c.$watch("chartSeries",s,!0),c.$watch("chartLabels",s,!0),c.$watch("chartOptions",s,!0),c.$watch("chartColors",s,!0),c.$watch("chartType",function(r,a){y(r)||t.equals(r,a)||f(r)}),c.$on("$destroy",function(){m(d,c)})}}}}r.defaults.global.multiTooltipTemplate="<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>",r.defaults.global.elements.line.borderWidth=2,r.defaults.global.elements.rectangle.borderWidth=2,r.defaults.global.colors=["#97BBCD","#DCDCDC","#F7464A","#46BFBD","#FDB45C","#949FB1","#4D5360"];var n="object"==typeof window.G_vmlCanvasManager&&null!==window.G_vmlCanvasManager&&"function"==typeof window.G_vmlCanvasManager.initElement;return n&&(r.defaults.global.animation=!1),t.module("chart.js",[]).provider("ChartJs",a).factory("ChartJsFactory",["ChartJs","$timeout",e]).directive("chartBase",["ChartJsFactory",function(t){return new t}]).directive("chartLine",["ChartJsFactory",function(t){return new t("line")}]).directive("chartBar",["ChartJsFactory",function(t){return new t("bar")}]).directive("chartRadar",["ChartJsFactory",function(t){return new t("radar")}]).directive("chartDoughnut",["ChartJsFactory",function(t){return new t("doughnut")}]).directive("chartPie",["ChartJsFactory",function(t){return new t("pie")}]).directive("chartPolarArea",["ChartJsFactory",function(t){return new t("polarArea")}])}); //# sourceMappingURL=angular-chart.min.js.map diff --git a/dist/angular-chart.min.js.map b/dist/angular-chart.min.js.map index 68ee8401..6e0a6d85 100644 --- a/dist/angular-chart.min.js.map +++ b/dist/angular-chart.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["angular-chart.min.js"],"names":["factory","exports","module","angular","require","Chart","define","amd","ChartJsProvider","options","ChartJs","getOptions","type","typeOptions","extend","this","setOptions","customOptions","$get","ChartJsFactory","$timeout","canUpdateChart","newVal","oldVal","length","Array","isArray","every","element","index","reduce","sum","carry","val","getEventHandler","scope","chart","action","triggerOnlyOnChange","lastState","evt","atEvent","getElementsAtEvent","getPointsAtEvent","activePoints","call","equals","$apply","getColors","colors","copy","chartColors","defaults","global","notEnoughColors","chartData","push","chartGetColor","map","convertColor","color","getColor","hexToRgb","substr","getRandomColor","getRandomInt","backgroundColor","rgba","borderColor","pointBackgroundColor","pointBorderColor","pointHoverBackgroundColor","pointHoverBorderColor","min","max","Math","floor","random","alpha","usingExcanvas","join","concat","hex","bigint","parseInt","r","g","b","getDataSets","labels","data","series","datasets","item","i","label","getData","hoverBackgroundColor","updateChart","values","forEach","dataset","update","$emit","isEmpty","value","Object","keys","isResponsive","chartOptions","responsive","restrict","chartType","chartLabels","chartSeries","chartClick","chartHover","link","elem","resetChart","createChart","clientHeight","cvs","ctx","getContext","destroy","onclick","noop","onmousemove","window","G_vmlCanvasManager","initElement","$watch","$on","multiTooltipTemplate","elements","line","borderWidth","rectangle","animation","provider","directive"],"mappings":"CAAC,SAAUA,GACT,YACuB,iBAAZC,SAETC,OAAOD,QAAUD,EACI,mBAAZG,SAA0BA,QAAUC,QAAQ,WAClC,mBAAVC,OAAwBA,MAAQD,QAAQ,aACrB,kBAAXE,SAAyBA,OAAOC,IAEjDD,QAAQ,UAAW,SAAUN,GAG7BA,EAAQG,QAASE,QAEnB,SAAUF,EAASE,GACnB,YAyCA,SAASG,KACP,GAAIC,MACAC,GACFL,MAAOA,EACPM,WAAY,SAAUC,GACpB,GAAIC,GAAcD,GAAQH,EAAQG,MAClC,OAAOT,GAAQW,UAAWL,EAASI,IAOvCE,MAAKC,WAAa,SAAUJ,EAAMK,GAEhC,MAAMA,QAMNR,EAAQG,GAAQT,EAAQW,OAAOL,EAAQG,OAAaK,KALlDA,EAAgBL,OAChBH,EAAUN,EAAQW,OAAOL,EAASQ,MAOtCF,KAAKG,KAAO,WACV,MAAOR,IAIX,QAASS,GAAgBT,EAASU,GA6FhC,QAASC,GAAgBC,EAAQC,GAC/B,MAAID,IAAUC,GAAUD,EAAOE,QAAUD,EAAOC,OACvCC,MAAMC,QAAQJ,EA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F0H,UAAU,aAAc,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe,WAChG0H,UAAU,YAAa,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe,UAC/F0H,UAAU,cAAe,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe,YACjG0H,UAAU,iBAAkB,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe,eACpG0H,UAAU,YAAa,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe,UAC/F0H,UAAU,kBAAmB,iBAAkB,SAAU1H,GAAkB,MAAO,IAAIA,GAAe","file":"angular-chart.min.js","sourcesContent":["(function (factory) {\n 'use strict';\n if (typeof exports === 'object') {\n // Node/CommonJS\n module.exports = factory(\n typeof angular !== 'undefined' ? angular : require('angular'),\n typeof Chart !== 'undefined' ? Chart : require('chart.js'));\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(['angular', 'chart'], factory);\n } else {\n // Browser globals\n factory(angular, Chart);\n }\n}(function (angular, Chart) {\n 'use strict';\n\n Chart.defaults.global.multiTooltipTemplate = '<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>';\n Chart.defaults.global.elements.line.borderWidth = 2;\n Chart.defaults.global.elements.rectangle.borderWidth = 2;\n Chart.defaults.global.colors = [\n '#97BBCD', // blue\n '#DCDCDC', // light grey\n '#F7464A', // red\n '#46BFBD', // green\n '#FDB45C', // yellow\n '#949FB1', // grey\n '#4D5360' // dark grey\n ];\n\n var usingExcanvas = typeof window.G_vmlCanvasManager === 'object' &&\n window.G_vmlCanvasManager !== null &&\n typeof window.G_vmlCanvasManager.initElement === 'function';\n\n if (usingExcanvas) Chart.defaults.global.animation = false;\n\n return angular.module('chart.js', [])\n .provider('ChartJs', ChartJsProvider)\n .factory('ChartJsFactory', ['ChartJs', '$timeout', ChartJsFactory])\n .directive('chartBase', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory(); }])\n .directive('chartLine', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('line'); }])\n .directive('chartBar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('bar'); }])\n .directive('chartRadar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('radar'); }])\n .directive('chartDoughnut', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('doughnut'); }])\n .directive('chartPie', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('pie'); }])\n .directive('chartPolarArea', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('polarArea'); }]);\n\n /**\n * Wrapper for chart.js\n * Allows configuring chart js using the provider\n *\n * angular.module('myModule', ['chart.js']).config(function(ChartJsProvider) {\n * ChartJsProvider.setOptions({ responsive: true });\n * ChartJsProvider.setOptions('Line', { responsive: false });\n * })))\n */\n function ChartJsProvider () {\n var options = {};\n var ChartJs = {\n Chart: Chart,\n getOptions: function (type) {\n var typeOptions = type && options[type] || {};\n return angular.extend({}, options, typeOptions);\n }\n };\n\n /**\n * Allow to set global options during configuration\n */\n this.setOptions = function (type, customOptions) {\n // If no type was specified set option for the global object\n if (! customOptions) {\n customOptions = type;\n options = angular.extend(options, customOptions);\n return;\n }\n // Set options for the specific chart\n options[type] = angular.extend(options[type] || {}, customOptions);\n };\n\n this.$get = function () {\n return ChartJs;\n };\n }\n\n function ChartJsFactory (ChartJs, $timeout) {\n return function chart (type) {\n return {\n restrict: 'CA',\n scope: {\n chartGetColor: '=?',\n chartType: '=',\n chartData: '=?',\n chartLabels: '=?',\n chartOptions: '=?',\n chartSeries: '=?',\n chartColors: '=?',\n chartClick: '=?',\n chartHover: '=?'\n },\n link: function (scope, elem/*, attrs */) {\n var chart;\n\n if (usingExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);\n\n // Order of setting \"watch\" matter\n\n scope.$watch('chartData', function (newVal, oldVal) {\n if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) return;\n var chartType = type || scope.chartType;\n if (! chartType) return;\n\n if (chart && canUpdateChart(newVal, oldVal))\n return updateChart(chart, newVal, scope);\n\n createChart(chartType);\n }, true);\n\n scope.$watch('chartSeries', resetChart, true);\n scope.$watch('chartLabels', resetChart, true);\n scope.$watch('chartOptions', resetChart, true);\n scope.$watch('chartColors', resetChart, true);\n\n scope.$watch('chartType', function (newVal, oldVal) {\n if (isEmpty(newVal)) return;\n if (angular.equals(newVal, oldVal)) return;\n createChart(newVal);\n });\n\n scope.$on('$destroy', function () {\n if (chart) chart.destroy();\n });\n\n function resetChart (newVal, oldVal) {\n if (isEmpty(newVal)) return;\n if (angular.equals(newVal, oldVal)) return;\n var chartType = type || scope.chartType;\n if (! chartType) return;\n\n // chart.update() doesn't work for series and labels\n // so we have to re-create the chart entirely\n createChart(chartType);\n }\n\n function createChart (type) {\n // TODO: check parent?\n if (isResponsive(type, scope) && elem[0].clientHeight === 0) {\n return $timeout(function () {\n createChart(type);\n }, 50, false);\n }\n if (! scope.chartData || ! scope.chartData.length) return;\n scope.chartGetColor = typeof scope.chartGetColor === 'function' ? scope.chartGetColor : getRandomColor;\n var colors = getColors(type, scope);\n var cvs = elem[0], ctx = cvs.getContext('2d');\n var data = Array.isArray(scope.chartData[0]) ?\n getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors) :\n getData(scope.chartLabels, scope.chartData, colors);\n\n var options = angular.extend({}, ChartJs.getOptions(type), scope.chartOptions);\n // Destroy old chart if it exists to avoid ghost charts issue\n // https://github.com/jtblin/angular-chart.js/issues/187\n if (chart) chart.destroy();\n chart = new ChartJs.Chart(ctx, {\n type: type,\n data: data,\n options: options\n });\n scope.$emit('chart-create', chart);\n\n // Bind events\n cvs.onclick = scope.chartClick ? getEventHandler(scope, chart, 'chartClick', false) : angular.noop;\n cvs.onmousemove = scope.chartHover ? getEventHandler(scope, chart, 'chartHover', true) : angular.noop;\n }\n }\n };\n };\n\n function canUpdateChart (newVal, oldVal) {\n if (newVal && oldVal && newVal.length && oldVal.length) {\n return Array.isArray(newVal[0]) ?\n newVal.length === oldVal.length && newVal.every(function (element, index) {\n return element.length === oldVal[index].length; }) :\n oldVal.reduce(sum, 0) > 0 ? newVal.length === oldVal.length : false;\n }\n return false;\n }\n\n function sum (carry, val) {\n return carry + val;\n }\n\n function getEventHandler (scope, chart, action, triggerOnlyOnChange) {\n var lastState = null;\n return function (evt) {\n var atEvent = chart.getElementsAtEvent || chart.getPointsAtEvent;\n if (atEvent) {\n var activePoints = atEvent.call(chart, evt);\n if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {\n lastState = activePoints;\n scope[action](activePoints, evt);\n scope.$apply();\n }\n }\n };\n }\n\n function getColors (type, scope) {\n var colors = angular.copy(scope.chartColors ||\n ChartJs.getOptions(type).chartColors ||\n Chart.defaults.global.colors\n );\n var notEnoughColors = colors.length < scope.chartData.length;\n while (colors.length < scope.chartData.length) {\n colors.push(scope.chartGetColor());\n }\n // mutate colors in this case as we don't want\n // the colors to change on each refresh\n if (notEnoughColors) scope.chartColors = colors;\n return colors.map(convertColor);\n }\n\n function convertColor (color) {\n if (typeof color === 'object' && color !== null) return color;\n if (typeof color === 'string' && color[0] === '#') return getColor(hexToRgb(color.substr(1)));\n return getRandomColor();\n }\n\n function getRandomColor () {\n var color = [getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255)];\n return getColor(color);\n }\n\n function getColor (color) {\n return {\n backgroundColor: rgba(color, 0.2),\n borderColor: rgba(color, 1),\n pointBackgroundColor: rgba(color, 1),\n pointBorderColor: '#fff',\n pointHoverBackgroundColor: '#fff',\n pointHoverBorderColor: rgba(color, 0.8)\n };\n }\n\n function getRandomInt (min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n }\n\n function rgba (color, alpha) {\n if (usingExcanvas) {\n // rgba not supported by IE8\n return 'rgb(' + color.join(',') + ')';\n } else {\n return 'rgba(' + color.concat(alpha).join(',') + ')';\n }\n }\n\n // Credit: http://stackoverflow.com/a/11508164/1190235\n function hexToRgb (hex) {\n var bigint = parseInt(hex, 16),\n r = (bigint >> 16) & 255,\n g = (bigint >> 8) & 255,\n b = bigint & 255;\n\n return [r, g, b];\n }\n\n function getDataSets (labels, data, series, colors) {\n return {\n labels: labels,\n datasets: data.map(function (item, i) {\n return angular.extend({}, colors[i], {\n label: series[i],\n data: item\n });\n })\n };\n }\n\n function getData (labels, data, colors) {\n return {\n labels: labels,\n datasets: [{\n data: data,\n backgroundColor: colors.map(function (color) {\n return color.pointBackgroundColor;\n }),\n hoverBackgroundColor: colors.map(function (color) {\n return color.backgroundColor;\n })\n }]\n };\n }\n\n function updateChart (chart, values, scope) {\n if (Array.isArray(scope.chartData[0])) {\n chart.data.datasets.forEach(function (dataset, i) {\n dataset.data = values[i];\n });\n } else {\n chart.data.datasets[0].data = values;\n }\n\n chart.update();\n scope.$emit('chart-update', chart);\n }\n\n function isEmpty (value) {\n return ! value ||\n (Array.isArray(value) && ! value.length) ||\n (typeof value === 'object' && ! Object.keys(value).length);\n }\n\n function isResponsive (type, scope) {\n var options = angular.extend({}, Chart.defaults.global, ChartJs.getOptions(type), scope.chartOptions);\n return options.responsive;\n }\n }\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["angular-chart.min.js"],"names":["factory","exports","module","angular","require","Chart","define","amd","ChartJsProvider","options","ChartJs","getOptions","type","typeOptions","extend","this","setOptions","customOptions","$get","ChartJsFactory","$timeout","canUpdateChart","newVal","oldVal","length","Array","isArray","every","element","index","reduce","sum","carry","val","getEventHandler","scope","chart","action","triggerOnlyOnChange","lastState","evt","atEvent","getElementsAtEvent","getPointsAtEvent","activePoints","call","equals","getColors","colors","copy","chartColors","defaults","global","notEnoughColors","chartData","push","chartGetColor","map","convertColor","color","getColor","hexToRgb","substr","getRandomColor","getRandomInt","backgroundColor","rgba","borderColor","pointBackgroundColor","pointBorderColor","pointHoverBackgroundColor","pointHoverBorderColor","min","max","Math","floor","random","alpha","usingExcanvas","join","concat","hex","bigint","parseInt","r","g","b","getDataSets","labels","data","series","yaxis","datasets","item","i","dataset","label","yAxisID","getData","hoverBackgroundColor","updateChart","values","forEach","update","$emit","isEmpty","value","Object","keys","isResponsive","chartOptions","responsive","destroyChart","destroy","restrict","chartType","chartLabels","chartSeries","chartClick","chartHover","chartYAxes","link","elem","resetChart","createChart","clientHeight","cvs","ctx","getContext","onclick","noop","onmousemove","window","G_vmlCanvasManager","initElement","$watch","$on","multiTooltipTemplate","elements","line","borderWidth","rectangle","animation","provider","directive"],"mappings":"CAAC,SAAUA,GACT,YACuB,iBAAZC,SAETC,OAAOD,QAAUD,EACI,mBAAZG,SAA0BA,QAAUC,QAAQ,WAClC,mBAAVC,OAAwBA,MAAQD,QAAQ,aACrB,kBAAXE,SAAyBA,OAAOC,IAEjDD,QAAQ,UAAW,SAAUN,GAG7BA,EAAQG,QAASE,QAEnB,SAAUF,EAASE,GACnB,YAyCA,SAASG,KACP,GAAIC,MACAC,GACFL,MAAOA,EACPM,WAAY,SAAUC,GACpB,GAAIC,GAAcD,GAAQH,EAAQG,MAClC,OAAOT,GAAQW,UAAWL,EAASI,IAOvCE,MAAKC,WAAa,SAAUJ,EAAMK,GAEhC,MAAMA,QAMNR,EAAQG,GAAQT,EAAQW,OAAOL,EAAQG,OAAaK,KALlDA,EAAgBL,OAChBH,EAAUN,EAAQW,OAAOL,EAASQ,MAOtCF,KAAKG,KAAO,WACV,MAAOR,IAIX,QAASS,GAAgBT,EAASU,GAkGhC,QAASC,GAAgBC,EAAQC,GAC/B,MAAID,IAAUC,GAAUD,EAAOE,QAAUD,EAAOC,OACvCC,MAAMC,QAAQJ,EAAO,IAC5BA,EAAOE,SAAWD,EAAOC,QAAUF,EAAOK,MAAM,SAAUC,EAASC,GACjE,MAAOD,GAAQJ,SAAWD,EAAOM,GAAOL,SACxCD,EAAOO,OAAOC,EAAK,GAAK,EAAIT,EAAOE,SAAWD,EAAOC,QAAS,GAE3D,EAGT,QAASO,GAAKC,E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U7H,GAAkB,MAAO,IAAIA,GAAe,WAChG6H,UAAU,YAAa,iBAAkB,SAAU7H,GAAkB,MAAO,IAAIA,GAAe,UAC/F6H,UAAU,cAAe,iBAAkB,SAAU7H,GAAkB,MAAO,IAAIA,GAAe,YACjG6H,UAAU,iBAAkB,iBAAkB,SAAU7H,GAAkB,MAAO,IAAIA,GAAe,eACpG6H,UAAU,YAAa,iBAAkB,SAAU7H,GAAkB,MAAO,IAAIA,GAAe,UAC/F6H,UAAU,kBAAmB,iBAAkB,SAAU7H,GAAkB,MAAO,IAAIA,GAAe","file":"angular-chart.min.js","sourcesContent":["(function (factory) {\n 'use strict';\n if (typeof exports === 'object') {\n // Node/CommonJS\n module.exports = factory(\n typeof angular !== 'undefined' ? angular : require('angular'),\n typeof Chart !== 'undefined' ? Chart : require('chart.js'));\n } else if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module.\n define(['angular', 'chart'], factory);\n } else {\n // Browser globals\n factory(angular, Chart);\n }\n}(function (angular, Chart) {\n 'use strict';\n\n Chart.defaults.global.multiTooltipTemplate = '<%if (datasetLabel){%><%=datasetLabel%>: <%}%><%= value %>';\n Chart.defaults.global.elements.line.borderWidth = 2;\n Chart.defaults.global.elements.rectangle.borderWidth = 2;\n Chart.defaults.global.colors = [\n '#97BBCD', // blue\n '#DCDCDC', // light grey\n '#F7464A', // red\n '#46BFBD', // green\n '#FDB45C', // yellow\n '#949FB1', // grey\n '#4D5360' // dark grey\n ];\n\n var usingExcanvas = typeof window.G_vmlCanvasManager === 'object' &&\n window.G_vmlCanvasManager !== null &&\n typeof window.G_vmlCanvasManager.initElement === 'function';\n\n if (usingExcanvas) Chart.defaults.global.animation = false;\n\n return angular.module('chart.js', [])\n .provider('ChartJs', ChartJsProvider)\n .factory('ChartJsFactory', ['ChartJs', '$timeout', ChartJsFactory])\n .directive('chartBase', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory(); }])\n .directive('chartLine', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('line'); }])\n .directive('chartBar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('bar'); }])\n .directive('chartRadar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('radar'); }])\n .directive('chartDoughnut', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('doughnut'); }])\n .directive('chartPie', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('pie'); }])\n .directive('chartPolarArea', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('polarArea'); }]);\n\n /**\n * Wrapper for chart.js\n * Allows configuring chart js using the provider\n *\n * angular.module('myModule', ['chart.js']).config(function(ChartJsProvider) {\n * ChartJsProvider.setOptions({ responsive: true });\n * ChartJsProvider.setOptions('Line', { responsive: false });\n * })))\n */\n function ChartJsProvider () {\n var options = {};\n var ChartJs = {\n Chart: Chart,\n getOptions: function (type) {\n var typeOptions = type && options[type] || {};\n return angular.extend({}, options, typeOptions);\n }\n };\n\n /**\n * Allow to set global options during configuration\n */\n this.setOptions = function (type, customOptions) {\n // If no type was specified set option for the global object\n if (! customOptions) {\n customOptions = type;\n options = angular.extend(options, customOptions);\n return;\n }\n // Set options for the specific chart\n options[type] = angular.extend(options[type] || {}, customOptions);\n };\n\n this.$get = function () {\n return ChartJs;\n };\n }\n\n function ChartJsFactory (ChartJs, $timeout) {\n return function chart (type) {\n return {\n restrict: 'CA',\n scope: {\n chartGetColor: '=?',\n chartType: '=',\n chartData: '=?',\n chartLabels: '=?',\n chartOptions: '=?',\n chartSeries: '=?',\n chartColors: '=?',\n chartClick: '=?',\n chartHover: '=?',\n chartYAxes: '=?'\n },\n link: function (scope, elem/*, attrs */) {\n var chart;\n\n if (usingExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);\n\n // Order of setting \"watch\" matter\n\n scope.$watch('chartData', function (newVal, oldVal) {\n if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) {\n destroyChart(chart, scope);\n return;\n }\n var chartType = type || scope.chartType;\n if (! chartType) return;\n\n if (chart && canUpdateChart(newVal, oldVal))\n return updateChart(chart, newVal, scope);\n\n createChart(chartType);\n }, true);\n\n scope.$watch('chartSeries', resetChart, true);\n scope.$watch('chartLabels', resetChart, true);\n scope.$watch('chartOptions', resetChart, true);\n scope.$watch('chartColors', resetChart, true);\n\n scope.$watch('chartType', function (newVal, oldVal) {\n if (isEmpty(newVal)) return;\n if (angular.equals(newVal, oldVal)) return;\n createChart(newVal);\n });\n\n scope.$on('$destroy', function () {\n destroyChart(chart, scope);\n });\n\n function resetChart (newVal, oldVal) {\n if (isEmpty(newVal)) return;\n if (angular.equals(newVal, oldVal)) return;\n var chartType = type || scope.chartType;\n if (! chartType) return;\n\n // chart.update() doesn't work for series and labels\n // so we have to re-create the chart entirely\n createChart(chartType);\n }\n\n function createChart (type) {\n // TODO: check parent?\n if (isResponsive(type, scope) && elem[0].clientHeight === 0) {\n return $timeout(function () {\n createChart(type);\n }, 50, false);\n }\n if (! scope.chartData || ! scope.chartData.length) return;\n scope.chartGetColor = typeof scope.chartGetColor === 'function' ? scope.chartGetColor : getRandomColor;\n var colors = getColors(type, scope);\n var cvs = elem[0], ctx = cvs.getContext('2d');\n var data = Array.isArray(scope.chartData[0]) ?\n getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors, scope.chartYAxes) :\n getData(scope.chartLabels, scope.chartData, colors);\n\n var options = angular.extend({}, ChartJs.getOptions(type), scope.chartOptions);\n // Destroy old chart if it exists to avoid ghost charts issue\n // https://github.com/jtblin/angular-chart.js/issues/187\n destroyChart(chart, scope);\n\n chart = new ChartJs.Chart(ctx, {\n type: type,\n data: data,\n options: options\n });\n scope.$emit('chart-create', chart);\n\n // Bind events\n cvs.onclick = scope.chartClick ? getEventHandler(scope, chart, 'chartClick', false) : angular.noop;\n cvs.onmousemove = scope.chartHover ? getEventHandler(scope, chart, 'chartHover', true) : angular.noop;\n }\n }\n };\n };\n\n function canUpdateChart (newVal, oldVal) {\n if (newVal && oldVal && newVal.length && oldVal.length) {\n return Array.isArray(newVal[0]) ?\n newVal.length === oldVal.length && newVal.every(function (element, index) {\n return element.length === oldVal[index].length; }) :\n oldVal.reduce(sum, 0) > 0 ? newVal.length === oldVal.length : false;\n }\n return false;\n }\n\n function sum (carry, val) {\n return carry + val;\n }\n\n function getEventHandler (scope, chart, action, triggerOnlyOnChange) {\n var lastState = null;\n return function (evt) {\n var atEvent = chart.getElementsAtEvent || chart.getPointsAtEvent;\n if (atEvent) {\n var activePoints = atEvent.call(chart, evt);\n if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {\n lastState = activePoints;\n scope[action](activePoints, evt);\n }\n }\n };\n }\n\n function getColors (type, scope) {\n var colors = angular.copy(scope.chartColors ||\n ChartJs.getOptions(type).chartColors ||\n Chart.defaults.global.colors\n );\n var notEnoughColors = colors.length < scope.chartData.length;\n while (colors.length < scope.chartData.length) {\n colors.push(scope.chartGetColor());\n }\n // mutate colors in this case as we don't want\n // the colors to change on each refresh\n if (notEnoughColors) scope.chartColors = colors;\n return colors.map(convertColor);\n }\n\n function convertColor (color) {\n if (typeof color === 'object' && color !== null) return color;\n if (typeof color === 'string' && color[0] === '#') return getColor(hexToRgb(color.substr(1)));\n return getRandomColor();\n }\n\n function getRandomColor () {\n var color = [getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255)];\n return getColor(color);\n }\n\n function getColor (color) {\n return {\n backgroundColor: rgba(color, 0.2),\n borderColor: rgba(color, 1),\n pointBackgroundColor: rgba(color, 1),\n pointBorderColor: '#fff',\n pointHoverBackgroundColor: '#fff',\n pointHoverBorderColor: rgba(color, 0.8)\n };\n }\n\n function getRandomInt (min, max) {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n }\n\n function rgba (color, alpha) {\n if (usingExcanvas) {\n // rgba not supported by IE8\n return 'rgb(' + color.join(',') + ')';\n } else {\n return 'rgba(' + color.concat(alpha).join(',') + ')';\n }\n }\n\n // Credit: http://stackoverflow.com/a/11508164/1190235\n function hexToRgb (hex) {\n var bigint = parseInt(hex, 16),\n r = (bigint >> 16) & 255,\n g = (bigint >> 8) & 255,\n b = bigint & 255;\n\n return [r, g, b];\n }\n\n function getDataSets (labels, data, series, colors, yaxis) {\n return {\n labels: labels,\n datasets: data.map(function (item, i) {\n var dataset = angular.extend({}, colors[i], {\n label: series[i],\n data: item\n });\n if (yaxis) {\n dataset.yAxisID = 'y-axis-' + (i + 1);\n }\n return dataset;\n })\n };\n }\n\n function getData (labels, data, colors) {\n return {\n labels: labels,\n datasets: [{\n data: data,\n backgroundColor: colors.map(function (color) {\n return color.pointBackgroundColor;\n }),\n hoverBackgroundColor: colors.map(function (color) {\n return color.backgroundColor;\n })\n }]\n };\n }\n\n function updateChart (chart, values, scope) {\n if (Array.isArray(scope.chartData[0])) {\n chart.data.datasets.forEach(function (dataset, i) {\n dataset.data = values[i];\n });\n } else {\n chart.data.datasets[0].data = values;\n }\n\n chart.update();\n scope.$emit('chart-update', chart);\n }\n\n function isEmpty (value) {\n return ! value ||\n (Array.isArray(value) && ! value.length) ||\n (typeof value === 'object' && ! Object.keys(value).length);\n }\n\n function isResponsive (type, scope) {\n var options = angular.extend({}, Chart.defaults.global, ChartJs.getOptions(type), scope.chartOptions);\n return options.responsive;\n }\n\n function destroyChart(chart, scope) {\n if(! chart) return;\n chart.destroy();\n scope.$emit('chart-destroy', chart);\n }\n }\n}));\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/examples/charts.html b/examples/charts.html index 95efff1d..d021dd13 100644 --- a/examples/charts.html +++ b/examples/charts.html @@ -61,7 +61,7 @@

Code on Github - Download (1.0.0-alpha1) + Download (1.0.0-alpha3)

@@ -126,7 +126,7 @@

Directives

Line Chart
+ chart-click="onClick" chart-hover="onHover" chart-series="series" chart-options="options" chart-y-axes="multiAxis">
@@ -143,13 +143,14 @@

Directives

  • chart-click (optional): onclick event handler
  • chart-hover (optional): onmousemove event handler
  • chart-colors (default to global colors): colors for the chart
  • +
  • chart-y-axes (optional): if true add multiple axis, required: ids y-axis-{n} in the options (view Javascript)
  • -
    <canvas id="line" class="chart chart-line" chart-data="data"
    -  chart-labels="labels" chart-series="series"
    -  chart-click="onClick" >
    +            
    <canvas id="line" class="chart chart-line" chart-data="data"
    +chart-labels="labels" chart-series="series" chart-options="options"
    +chart-y-axes="true" chart-click="onClick"
     </canvas> 
    @@ -164,6 +165,24 @@

    Directives

    $scope.onClick = function (points, evt) { console.log(points, evt); }; + $scope.options = { + scales: { + yAxes: [ + { + id: 'y-axis-1', + type: 'linear', + display: true, + position: 'left' + }, + { + id: 'y-axis-2', + type: 'linear', + display: true, + position: 'right' + } + ] + } + }; });
    @@ -184,6 +203,7 @@

    Directives

  • chart-click (optional): onclick event handler
  • chart-hover (optional): onmousemove event handler
  • chart-colors (default to global colors): colors for the chart
  • +
  • chart-y-axes (optional): if true add multiple axis, required:: ids y-axis-{n} in the options
  • diff --git a/examples/charts.template.html b/examples/charts.template.html index bc0802ac..0e455cc2 100644 --- a/examples/charts.template.html +++ b/examples/charts.template.html @@ -169,16 +169,16 @@

    Directives

    scales: { yAxes: [ { - id: "y-axis-1", - type: "linear", + id: 'y-axis-1', + type: 'linear', display: true, - position: "left" + position: 'left' }, { - id: "y-axis-2", - type: "linear", + id: 'y-axis-2', + type: 'linear', display: true, - position: "right" + position: 'right' } ] } diff --git a/package.json b/package.json index ea3db4b7..490c21f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-chart.js", - "version": "1.0.0-alpha2", + "version": "1.0.0-alpha3", "description": "An angular.js wrapper for Chart.js", "main": "dist/angular-chart.js", "directories": {