Skip to content

Commit 84720ec

Browse files
committed
1.1.0
1 parent a4eebb5 commit 84720ec

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-chart.js",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"main": [
55
"./dist/angular-chart.js"
66
],

dist/angular-chart.js

Lines changed: 38 additions & 14 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.0.3
4+
* Version: 1.1.0
55
*
66
* Copyright 2016 Jerome Touffe-Blin
77
* Released under the BSD-2-Clause license
@@ -19,8 +19,11 @@
1919
define(['angular', 'chart'], factory);
2020
} else {
2121
// Browser globals
22-
if (typeof angular === 'undefined' || typeof Chart === 'undefined')
22+
if (typeof angular === 'undefined') {
23+
throw new Error('AngularJS framework needs to be included, see https://angularjs.org/');
24+
} else if (typeof Chart === 'undefined') {
2325
throw new Error('Chart.js library needs to be included, see http://jtblin.github.io/angular-chart.js/');
26+
}
2427
factory(angular, Chart);
2528
}
2629
}(function (angular, Chart) {
@@ -180,7 +183,6 @@
180183

181184
scope.chartGetColor = getChartColorFn(scope);
182185
var data = getChartData(type, scope);
183-
184186
// Destroy old chart if it exists to avoid ghost charts issue
185187
// https://github.com/jtblin/angular-chart.js/issues/187
186188
destroyChart(scope);
@@ -209,14 +211,23 @@
209211
}
210212

211213
function getEventHandler (scope, action, triggerOnlyOnChange) {
212-
var lastState = null;
214+
var lastState = {
215+
point: void 0,
216+
points: void 0
217+
};
213218
return function (evt) {
214-
var atEvent = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
215-
if (atEvent) {
216-
var activePoints = atEvent.call(scope.chart, evt);
217-
if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {
218-
lastState = activePoints;
219-
scope[action](activePoints, evt);
219+
var atEvent = scope.chart.getElementAtEvent || scope.chart.getPointAtEvent;
220+
var atEvents = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
221+
if (atEvents) {
222+
var points = atEvents.call(scope.chart, evt);
223+
var point = atEvent ? atEvent.call(scope.chart, evt)[0] : void 0;
224+
225+
if (triggerOnlyOnChange === false ||
226+
(! angular.equals(lastState.points, points) && ! angular.equals(lastState.point, point))
227+
) {
228+
lastState.point = point;
229+
lastState.points = points;
230+
scope[action](points, evt, point);
220231
}
221232
}
222233
};
@@ -238,8 +249,12 @@
238249
}
239250

240251
function convertColor (color) {
241-
if (typeof color === 'object' && color !== null) return color;
252+
// Allows RGB and RGBA colors to be input as a string: e.g.: "rgb(159,204,0)", "rgba(159,204,0, 0.5)"
253+
if (typeof color === 'string' && color[0] === 'r') return getColor(rgbStringToRgb(color));
254+
// Allows hex colors to be input as a string.
242255
if (typeof color === 'string' && color[0] === '#') return getColor(hexToRgb(color.substr(1)));
256+
// Allows colors to be input as an object, bypassing getColor() entirely
257+
if (typeof color === 'object' && color !== null) return color;
243258
return getRandomColor();
244259
}
245260

@@ -249,13 +264,15 @@
249264
}
250265

251266
function getColor (color) {
267+
var alpha = color[3] || 1;
268+
color = color.slice(0, 3);
252269
return {
253270
backgroundColor: rgba(color, 0.2),
254-
pointBackgroundColor: rgba(color, 1),
271+
pointBackgroundColor: rgba(color, alpha),
255272
pointHoverBackgroundColor: rgba(color, 0.8),
256-
borderColor: rgba(color, 1),
273+
borderColor: rgba(color, alpha),
257274
pointBorderColor: '#fff',
258-
pointHoverBorderColor: rgba(color, 1)
275+
pointHoverBorderColor: rgba(color, alpha)
259276
};
260277
}
261278

@@ -278,6 +295,13 @@
278295
return [r, g, b];
279296
}
280297

298+
function rgbStringToRgb (color) {
299+
var match = color.match(/^rgba?\(([\d,.]+)\)$/);
300+
if (! match) throw new Error('Cannot parse rgb value');
301+
color = match[1].split(',');
302+
return color.map(Number);
303+
}
304+
281305
function hasData (scope) {
282306
return scope.chartData && scope.chartData.length;
283307
}

dist/angular-chart.js.tar.gz

702 Bytes
Binary file not shown.

dist/angular-chart.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-chart.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/charts.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h1>
9595
<p>
9696
<a class="btn btn-default btn-lg" href="https://github.com/jtblin/angular-chart"><i class="icon-github"></i>Code on Github</a>
9797
<a class="btn btn-success btn-lg" href="../dist/angular-chart.js.tar.gz" download="angular-chart.js.tar.gz">
98-
<i class="fa fa-download"></i> Download <small>(1.0.3)</small>
98+
<i class="fa fa-download"></i> Download <small>(1.1.0)</small>
9999
</a>
100100
</p>
101101
</div>
@@ -185,8 +185,8 @@ <h1>Directives</h1>
185185
<tab heading="Markup">
186186
<pre><code data-language="html">&lt;canvas id=&quot;line&quot; class=&quot;chart chart-line&quot; chart-data=&quot;data&quot;
187187
chart-labels=&quot;labels&quot; chart-series=&quot;series&quot; chart-options=&quot;options&quot;
188-
chart-dataset-override=&quot;datasetOverride&quot; chart-click=&quot;onClick&quot;
189-
&lt;/canvas&gt; </code></pre>
188+
chart-dataset-override=&quot;datasetOverride&quot; chart-click=&quot;onClick&quot;&gt;
189+
&lt;/canvas&gt;</code></pre>
190190
</tab>
191191
<tab heading="Javascript">
192192
<pre><code data-language="javascript">angular.module("app", ["chart.js"]).controller("LineCtrl", function ($scope) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-chart.js",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "An angular.js wrapper for Chart.js",
55
"homepage": "http://jtblin.github.io/angular-chart.js/",
66
"main": "dist/angular-chart.js",

0 commit comments

Comments
 (0)