Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jtblin committed Dec 5, 2016
1 parent a4eebb5 commit 84720ec
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-chart.js",
"version": "1.0.3",
"version": "1.1.0",
"main": [
"./dist/angular-chart.js"
],
Expand Down
52 changes: 38 additions & 14 deletions dist/angular-chart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* angular-chart.js - An angular.js wrapper for Chart.js
* http://jtblin.github.io/angular-chart.js/
* Version: 1.0.3
* Version: 1.1.0
*
* Copyright 2016 Jerome Touffe-Blin
* Released under the BSD-2-Clause license
Expand All @@ -19,8 +19,11 @@
define(['angular', 'chart'], factory);
} else {
// Browser globals
if (typeof angular === 'undefined' || typeof Chart === 'undefined')
if (typeof angular === 'undefined') {
throw new Error('AngularJS framework needs to be included, see https://angularjs.org/');
} else if (typeof Chart === 'undefined') {
throw new Error('Chart.js library needs to be included, see http://jtblin.github.io/angular-chart.js/');
}
factory(angular, Chart);
}
}(function (angular, Chart) {
Expand Down Expand Up @@ -180,7 +183,6 @@

scope.chartGetColor = getChartColorFn(scope);
var data = getChartData(type, scope);

// Destroy old chart if it exists to avoid ghost charts issue
// https://github.com/jtblin/angular-chart.js/issues/187
destroyChart(scope);
Expand Down Expand Up @@ -209,14 +211,23 @@
}

function getEventHandler (scope, action, triggerOnlyOnChange) {
var lastState = null;
var lastState = {
point: void 0,
points: void 0
};
return function (evt) {
var atEvent = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
if (atEvent) {
var activePoints = atEvent.call(scope.chart, evt);
if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {
lastState = activePoints;
scope[action](activePoints, evt);
var atEvent = scope.chart.getElementAtEvent || scope.chart.getPointAtEvent;
var atEvents = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
if (atEvents) {
var points = atEvents.call(scope.chart, evt);
var point = atEvent ? atEvent.call(scope.chart, evt)[0] : void 0;

if (triggerOnlyOnChange === false ||
(! angular.equals(lastState.points, points) && ! angular.equals(lastState.point, point))
) {
lastState.point = point;
lastState.points = points;
scope[action](points, evt, point);
}
}
};
Expand All @@ -238,8 +249,12 @@
}

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

Expand All @@ -249,13 +264,15 @@
}

function getColor (color) {
var alpha = color[3] || 1;
color = color.slice(0, 3);
return {
backgroundColor: rgba(color, 0.2),
pointBackgroundColor: rgba(color, 1),
pointBackgroundColor: rgba(color, alpha),
pointHoverBackgroundColor: rgba(color, 0.8),
borderColor: rgba(color, 1),
borderColor: rgba(color, alpha),
pointBorderColor: '#fff',
pointHoverBorderColor: rgba(color, 1)
pointHoverBorderColor: rgba(color, alpha)
};
}

Expand All @@ -278,6 +295,13 @@
return [r, g, b];
}

function rgbStringToRgb (color) {
var match = color.match(/^rgba?\(([\d,.]+)\)$/);
if (! match) throw new Error('Cannot parse rgb value');
color = match[1].split(',');
return color.map(Number);
}

function hasData (scope) {
return scope.chartData && scope.chartData.length;
}
Expand Down
Binary file modified dist/angular-chart.js.tar.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/angular-chart.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-chart.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions examples/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ <h1>
<p>
<a class="btn btn-default btn-lg" href="https://github.com/jtblin/angular-chart"><i class="icon-github"></i>Code on Github</a>
<a class="btn btn-success btn-lg" href="../dist/angular-chart.js.tar.gz" download="angular-chart.js.tar.gz">
<i class="fa fa-download"></i> Download <small>(1.0.3)</small>
<i class="fa fa-download"></i> Download <small>(1.1.0)</small>
</a>
</p>
</div>
Expand Down Expand Up @@ -185,8 +185,8 @@ <h1>Directives</h1>
<tab heading="Markup">
<pre><code data-language="html">&lt;canvas id=&quot;line&quot; class=&quot;chart chart-line&quot; chart-data=&quot;data&quot;
chart-labels=&quot;labels&quot; chart-series=&quot;series&quot; chart-options=&quot;options&quot;
chart-dataset-override=&quot;datasetOverride&quot; chart-click=&quot;onClick&quot;
&lt;/canvas&gt; </code></pre>
chart-dataset-override=&quot;datasetOverride&quot; chart-click=&quot;onClick&quot;&gt;
&lt;/canvas&gt;</code></pre>
</tab>
<tab heading="Javascript">
<pre><code data-language="javascript">angular.module("app", ["chart.js"]).controller("LineCtrl", function ($scope) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-chart.js",
"version": "1.0.3",
"version": "1.1.0",
"description": "An angular.js wrapper for Chart.js",
"homepage": "http://jtblin.github.io/angular-chart.js/",
"main": "dist/angular-chart.js",
Expand Down

0 comments on commit 84720ec

Please sign in to comment.