Skip to content

Commit c496537

Browse files
committed
build: update dist assets for v2.0.0
1 parent 65e3a7f commit c496537

4 files changed

Lines changed: 55 additions & 64 deletions

File tree

dist/angular-chart.js

Lines changed: 52 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* angular-chart.js - An angular.js wrapper for Chart.js
33
* http://jtblin.github.io/angular-chart.js/
4-
* Version: 1.1.1
4+
* Version: 2.0.0
55
*
66
* Copyright 2016 Jerome Touffe-Blin
77
* Released under the BSD-2-Clause license
@@ -14,13 +14,13 @@
1414
module.exports = factory(
1515
typeof angular !== 'undefined' ? angular : require('angular'),
1616
typeof Chart !== 'undefined' ? Chart : require('chart.js'));
17-
} else if (typeof define === 'function' && define.amd) {
17+
} else if (typeof define === 'function' && define.amd) {
1818
// AMD. Register as an anonymous module.
1919
define(['angular', 'chart'], factory);
2020
} else {
2121
// Browser globals
2222
if (typeof angular === 'undefined') {
23-
throw new Error('AngularJS framework needs to be included, see https://angularjs.org/');
23+
throw new Error('AngularJS framework needs to be included, see https://angularjs.org/');
2424
} else if (typeof Chart === 'undefined') {
2525
throw new Error('Chart.js library needs to be included, see http://jtblin.github.io/angular-chart.js/');
2626
}
@@ -44,7 +44,7 @@
4444
'#4D5360' // dark grey
4545
];
4646

47-
var useExcanvas = typeof window.G_vmlCanvasManager === 'object' &&
47+
const useExcanvas = typeof window.G_vmlCanvasManager === 'object' &&
4848
window.G_vmlCanvasManager !== null &&
4949
typeof window.G_vmlCanvasManager.initElement === 'function';
5050

@@ -53,15 +53,15 @@
5353
return angular.module('chart.js', [])
5454
.provider('ChartJs', ChartJsProvider)
5555
.factory('ChartJsFactory', ['ChartJs', '$timeout', ChartJsFactory])
56-
.directive('chartBase', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory(); }])
57-
.directive('chartLine', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('line'); }])
58-
.directive('chartBar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('bar'); }])
59-
.directive('chartHorizontalBar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('horizontalBar'); }])
60-
.directive('chartRadar', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('radar'); }])
61-
.directive('chartDoughnut', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('doughnut'); }])
62-
.directive('chartPie', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('pie'); }])
63-
.directive('chartPolarArea', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('polarArea'); }])
64-
.directive('chartBubble', ['ChartJsFactory', function (ChartJsFactory) { return new ChartJsFactory('bubble'); }])
56+
.directive('chartBase', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory()])
57+
.directive('chartLine', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('line')])
58+
.directive('chartBar', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('bar')])
59+
.directive('chartHorizontalBar', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('horizontalBar')])
60+
.directive('chartRadar', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('radar')])
61+
.directive('chartDoughnut', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('doughnut')])
62+
.directive('chartPie', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('pie')])
63+
.directive('chartPolarArea', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('polarArea')])
64+
.directive('chartBubble', ['ChartJsFactory', (ChartJsFactory) => new ChartJsFactory('bubble')])
6565
.name;
6666

6767
/**
@@ -74,11 +74,11 @@
7474
* })))
7575
*/
7676
function ChartJsProvider () {
77-
var options = { responsive: true };
78-
var ChartJs = {
77+
let options = { responsive: true };
78+
const ChartJs = {
7979
Chart: Chart,
80-
getOptions: function (type) {
81-
var typeOptions = type && options[type] || {};
80+
getOptions: (type) => {
81+
const typeOptions = type && options[type] || {};
8282
return angular.extend({}, options, typeOptions);
8383
}
8484
};
@@ -99,9 +99,7 @@
9999
angular.merge(ChartJs.Chart.defaults, options);
100100
};
101101

102-
this.$get = function () {
103-
return ChartJs;
104-
};
102+
this.$get = () => ChartJs;
105103
}
106104

107105
function ChartJsFactory (ChartJs, $timeout) {
@@ -132,11 +130,9 @@
132130
scope.$watch('chartDatasetOverride', watchOther, true);
133131
scope.$watch('chartType', watchType, false);
134132

135-
scope.$on('$destroy', function () {
136-
destroyChart(scope);
137-
});
133+
scope.$on('$destroy', () => destroyChart(scope));
138134

139-
scope.$on('$resize', function () {
135+
scope.$on('$resize', () => {
140136
if (scope.chart) scope.chart.resize();
141137
});
142138

@@ -145,7 +141,7 @@
145141
destroyChart(scope);
146142
return;
147143
}
148-
var chartType = type || scope.chartType;
144+
const chartType = type || scope.chartType;
149145
if (! chartType) return;
150146

151147
if (scope.chart && canUpdateChart(newVal, oldVal))
@@ -157,7 +153,7 @@
157153
function watchOther (newVal, oldVal) {
158154
if (isEmpty(newVal)) return;
159155
if (angular.equals(newVal, oldVal)) return;
160-
var chartType = type || scope.chartType;
156+
const chartType = type || scope.chartType;
161157
if (! chartType) return;
162158

163159
// chart.update() doesn't work for series and labels
@@ -175,14 +171,14 @@
175171
};
176172

177173
function createChart (type, scope, elem) {
178-
var options = getChartOptions(type, scope);
174+
const options = getChartOptions(type, scope);
179175
if (! hasData(scope) || ! canDisplay(type, scope, elem, options)) return;
180176

181-
var cvs = elem[0];
182-
var ctx = cvs.getContext('2d');
177+
const cvs = elem[0];
178+
const ctx = cvs.getContext('2d');
183179

184180
scope.chartGetColor = getChartColorFn(scope);
185-
var data = getChartData(type, scope);
181+
const data = getChartData(type, scope);
186182
// Destroy old chart if it exists to avoid ghost charts issue
187183
// https://github.com/jtblin/angular-chart.js/issues/187
188184
destroyChart(scope);
@@ -199,8 +195,7 @@
199195
function canUpdateChart (newVal, oldVal) {
200196
if (newVal && oldVal && newVal.length && oldVal.length) {
201197
return Array.isArray(newVal[0]) ?
202-
newVal.length === oldVal.length && newVal.every(function (element, index) {
203-
return element.length === oldVal[index].length; }) :
198+
newVal.length === oldVal.length && newVal.every((element, index) => element.length === oldVal[index].length) :
204199
oldVal.reduce(sum, 0) > 0 ? newVal.length === oldVal.length : false;
205200
}
206201
return false;
@@ -211,16 +206,16 @@
211206
}
212207

213208
function getEventHandler (scope, action, triggerOnlyOnChange) {
214-
var lastState = {
215-
point: void 0,
216-
points: void 0
209+
const lastState = {
210+
point: undefined,
211+
points: undefined
217212
};
218213
return function (evt) {
219-
var atEvent = scope.chart.getElementAtEvent || scope.chart.getPointAtEvent;
220-
var atEvents = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
214+
const atEvent = scope.chart.getElementAtEvent || scope.chart.getPointAtEvent;
215+
const atEvents = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
221216
if (atEvents) {
222-
var points = atEvents.call(scope.chart, evt);
223-
var point = atEvent ? atEvent.call(scope.chart, evt)[0] : void 0;
217+
const points = atEvents.call(scope.chart, evt);
218+
const point = atEvent ? atEvent.call(scope.chart, evt)[0] : undefined;
224219

225220
if (triggerOnlyOnChange === false ||
226221
(! angular.equals(lastState.points, points) && ! angular.equals(lastState.point, point))
@@ -234,11 +229,11 @@
234229
}
235230

236231
function getColors (type, scope) {
237-
var colors = angular.copy(scope.chartColors ||
232+
const colors = angular.copy(scope.chartColors ||
238233
ChartJs.getOptions(type).chartColors ||
239234
Chart.defaults.global.colors
240235
);
241-
var notEnoughColors = colors.length < scope.chartData.length;
236+
const notEnoughColors = colors.length < scope.chartData.length;
242237
while (colors.length < scope.chartData.length) {
243238
colors.push(scope.chartGetColor());
244239
}
@@ -259,12 +254,12 @@
259254
}
260255

261256
function getRandomColor () {
262-
var color = [getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255)];
257+
const color = [getRandomInt(0, 255), getRandomInt(0, 255), getRandomInt(0, 255)];
263258
return getColor(color);
264259
}
265260

266261
function getColor (color) {
267-
var alpha = color[3] || 1;
262+
const alpha = color[3] || 1;
268263
color = color.slice(0, 3);
269264
return {
270265
backgroundColor: rgba(color, 0.2),
@@ -282,21 +277,21 @@
282277

283278
function rgba (color, alpha) {
284279
// rgba not supported by IE8
285-
return useExcanvas ? 'rgb(' + color.join(',') + ')' : 'rgba(' + color.concat(alpha).join(',') + ')';
280+
return useExcanvas ? `rgb(${color.join(',')})` : `rgba(${color.concat(alpha).join(',')})`;
286281
}
287282

288283
// Credit: http://stackoverflow.com/a/11508164/1190235
289284
function hexToRgb (hex) {
290-
var bigint = parseInt(hex, 16),
291-
r = (bigint >> 16) & 255,
292-
g = (bigint >> 8) & 255,
293-
b = bigint & 255;
285+
const bigint = parseInt(hex, 16);
286+
const r = (bigint >> 16) & 255;
287+
const g = (bigint >> 8) & 255;
288+
const b = bigint & 255;
294289

295290
return [r, g, b];
296291
}
297292

298293
function rgbStringToRgb (color) {
299-
var match = color.match(/^rgba?\(([\d,.]+)\)$/);
294+
const match = color.match(/^rgba?\(([\d,.]+)\)$/);
300295
if (! match) throw new Error('Cannot parse rgb value');
301296
color = match[1].split(',');
302297
return color.map(Number);
@@ -311,7 +306,7 @@
311306
}
312307

313308
function getChartData (type, scope) {
314-
var colors = getColors(type, scope);
309+
const colors = getColors(type, scope);
315310
return Array.isArray(scope.chartData[0]) ?
316311
getDataSets(scope.chartLabels, scope.chartData, scope.chartSeries || [], colors, scope.chartDatasetOverride) :
317312
getData(scope.chartLabels, scope.chartData, colors, scope.chartDatasetOverride);
@@ -320,8 +315,8 @@
320315
function getDataSets (labels, data, series, colors, datasetOverride) {
321316
return {
322317
labels: labels,
323-
datasets: data.map(function (item, i) {
324-
var dataset = angular.extend({}, colors[i], {
318+
datasets: data.map((item, i) => {
319+
const dataset = angular.extend({}, colors[i], {
325320
label: series[i],
326321
data: item
327322
});
@@ -334,16 +329,12 @@
334329
}
335330

336331
function getData (labels, data, colors, datasetOverride) {
337-
var dataset = {
332+
const dataset = {
338333
labels: labels,
339334
datasets: [{
340335
data: data,
341-
backgroundColor: colors.map(function (color) {
342-
return color.pointBackgroundColor;
343-
}),
344-
hoverBackgroundColor: colors.map(function (color) {
345-
return color.backgroundColor;
346-
})
336+
backgroundColor: colors.map((color) => color.pointBackgroundColor),
337+
hoverBackgroundColor: colors.map((color) => color.backgroundColor)
347338
}]
348339
};
349340
if (datasetOverride) {
@@ -363,7 +354,7 @@
363354

364355
function updateChart (values, scope) {
365356
if (Array.isArray(scope.chartData[0])) {
366-
scope.chart.data.datasets.forEach(function (dataset, i) {
357+
scope.chart.data.datasets.forEach((dataset, i) => {
367358
dataset.data = values[i];
368359
});
369360
} else {
@@ -383,7 +374,7 @@
383374
function canDisplay (type, scope, elem, options) {
384375
// TODO: check parent?
385376
if (options.responsive && elem[0].clientHeight === 0) {
386-
$timeout(function () {
377+
$timeout(() => {
387378
createChart(type, scope, elem);
388379
}, 50, false);
389380
return false;

dist/angular-chart.js.tar.gz

-24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)