Skip to content

Commit

Permalink
Bump to 1.0.0-alpha3 as forgot to build the assets previously
Browse files Browse the repository at this point in the history
  • Loading branch information
jtblin committed Mar 27, 2016
1 parent 3a5dd4f commit 3cfe7b2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 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.0-alpha2",
"version": "1.0.0-alpha3",
"main": [
"./dist/angular-chart.js"
],
Expand Down
30 changes: 22 additions & 8 deletions dist/angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
chartSeries: '=?',
chartColors: '=?',
chartClick: '=?',
chartHover: '=?'
chartHover: '=?',
chartYAxes: '=?'
},
link: function (scope, elem/*, attrs */) {
var chart;
Expand All @@ -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;

Expand All @@ -128,7 +132,7 @@
});

scope.$on('$destroy', function () {
if (chart) chart.destroy();
destroyChart(chart, scope);
});

function resetChart (newVal, oldVal) {
Expand All @@ -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,
Expand Down Expand Up @@ -199,7 +204,6 @@
if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {
lastState = activePoints;
scope[action](activePoints, evt);
scope.$apply();
}
}
};
Expand Down Expand Up @@ -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;
})
};
}
Expand Down Expand Up @@ -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);
}
}
}));
Binary file modified dist/angular-chart.js.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion 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.

30 changes: 25 additions & 5 deletions examples/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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.0-alpha1)</small>
<i class="fa fa-download"></i> Download <small>(1.0.0-alpha3)</small>
</a>
</p>
</div>
Expand Down Expand Up @@ -126,7 +126,7 @@ <h1>Directives</h1>
<div class="panel-heading">Line Chart</div>
<div class="panel-body">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels"
chart-click="onClick" chart-hover="onHover" chart-series="series"></canvas>
chart-click="onClick" chart-hover="onHover" chart-series="series" chart-options="options" chart-y-axes="multiAxis"></canvas>
</div>
</div>
</div>
Expand All @@ -143,13 +143,14 @@ <h1>Directives</h1>
<li><code>chart-click</code> (optional): onclick event handler</li>
<li><code>chart-hover</code> (optional): onmousemove event handler</li>
<li><code>chart-colors</code> (default to global colors): colors for the chart</li>
<li><code>chart-y-axes</code> (optional): if true add multiple axis, <strong>required:</strong> ids y-axis-{n} in the options (view Javascript)</li>
</ul>
</div>
</tab>
<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-click=&quot;onClick&quot; &gt;
<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-y-axes=&quot;true&quot; chart-click=&quot;onClick&quot;
&lt;/canvas&gt; </code></pre>
</tab>
<tab heading="Javascript">
Expand All @@ -164,6 +165,24 @@ <h1>Directives</h1>
$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'
}
]
}
};
});
</code></pre>
</tab>
Expand All @@ -184,6 +203,7 @@ <h1>Directives</h1>
<li><code>chart-click</code> (optional): onclick event handler</li>
<li><code>chart-hover</code> (optional): onmousemove event handler</li>
<li><code>chart-colors</code> (default to global colors): colors for the chart</li>
<li><code>chart-y-axes</code> (optional): if true add multiple axis, <strong>required:</strong>: ids y-axis-{n} in the options</li>
</ul>
</div>
</tab>
Expand Down
12 changes: 6 additions & 6 deletions examples/charts.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ <h1>Directives</h1>
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'
}
]
}
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.0-alpha2",
"version": "1.0.0-alpha3",
"description": "An angular.js wrapper for Chart.js",
"main": "dist/angular-chart.js",
"directories": {
Expand Down

0 comments on commit 3cfe7b2

Please sign in to comment.