Skip to content

Commit 67a0a2f

Browse files
authored
Merge pull request #54 from aomran/version3
Version 3
2 parents abb7fff + 6defe5e commit 67a0a2f

21 files changed

+234
-469
lines changed

.npmignore

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
bower_components/
2-
tests/
3-
tmp/
4-
dist/
5-
1+
/bower_components
2+
/config/ember-try.js
3+
/dist
4+
/tests
5+
/tmp
6+
**/.gitkeep
67
.bowerrc
78
.editorconfig
89
.ember-cli
10+
.gitignore
11+
.jshintrc
12+
.watchmanconfig
913
.travis.yml
10-
.npmignore
11-
**/.gitkeep
1214
bower.json
13-
Brocfile.js
14-
testem.json
15+
ember-cli-build.js
16+
testem.js

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ cache:
1111

1212
env:
1313
- EMBER_TRY_SCENARIO=default
14+
- EMBER_TRY_SCENARIO=ember-1.13
1415
- EMBER_TRY_SCENARIO=ember-release
16+
- EMBER_TRY_SCENARIO=ember-beta
17+
- EMBER_TRY_SCENARIO=ember-canary
1518

1619
matrix:
1720
fast_finish: true
21+
allow_failures:
22+
- env: EMBER_TRY_SCENARIO=ember-canary
1823

1924
before_install:
2025
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH

README.md

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/aomran/ember-cli-chart.svg)](https://travis-ci.org/aomran/ember-cli-chart)
44

5-
This is an Ember CLI addon for adding a [ChartJS](http://www.chartjs.org/) component. This addon is tested on Ember-CLI v1.13.15 and uses the `ember-try` addon to test against Ember v1.13.12 and the latest release.
5+
This Ember CLI addon is a simple wrapper for [ChartJS](http://www.chartjs.org/) (v2.1.1). This addon uses Ember-CLI v2.5.0.
66

77
### Installation
88

@@ -15,28 +15,21 @@ $ ember install ember-cli-chart
1515
In your handlebars template just do:
1616

1717
```
18-
{{ember-chart type=CHARTTYPE data=CHARTDATA options=CHARTOPTIONS width=CHARTWIDTH height=CHARTHEIGHT legend=LEGEND}}
18+
{{ember-chart type=CHARTTYPE data=CHARTDATA options=CHARTOPTIONS width=CHARTWIDTH height=CHARTHEIGHT}}
1919
```
2020

21-
* CHARTTYPE: String; one of the following -- `Line`, `Bar`, `Radar`, `PolarArea`, `Pie` or `Doughnut`.
21+
* CHARTTYPE: String; one of the following -- `line`, `bar`, `radar`, `polarArea`, `pie` or `doughnut`.
2222
* CHARTDATA: Array; refer to the ChartJS documentation
2323
* CHARTOPTIONS: Object; refer to the ChartJS documentation. This is optional.
24-
* CHARTWIDTH: Number; pixel width of the canvas element
25-
* CHARTHEIGHT: Number; pixel height of the canvas element
26-
* LEGEND: Boolean, true means add a legend. This is optional.
24+
* CHARTWIDTH: Number; pixel width of the canvas element. Only applies if the chart is NOT responsive.
25+
* CHARTHEIGHT: Number; pixel height of the canvas element. Only applies if the chart is NOT responsive.
2726

2827
#### Example
2928

3029
```
3130
{{ember-chart type='Pie' data=model.chartData width=200 height=200}}
3231
```
3332

34-
#### Example with Legend
35-
36-
```
37-
{{ember-chart type='Line' data=model.chartData width=200 height=200 legend=true}}
38-
```
39-
4033
#### More Resources
4134

4235
* [Screencast on creating bar charts with ember-cli-chart](https://www.emberscreencasts.com/posts/46-bar-charts-with-ember-cli-chart)

addon/chart-data-updater.js

-94
This file was deleted.

addon/components/ember-chart.js

+13-58
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,37 @@
11
import Ember from 'ember';
2-
import ChartDataUpdater from 'ember-cli-chart/chart-data-updater';
32
/* global Chart */
43

54
export default Ember.Component.extend({
65
tagName: 'canvas',
76
attributeBindings: ['width', 'height'],
87

9-
lineLegendTemp: "<ul class=\"<%=name.toLowerCase()%>-legend\" style=\"list-style-type: none;\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>; width: 8px;height: 8px;display: inline-block;border-radius: 10px;border: solid;border-width: 2px;margin: 5px 5px 0 0;\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>",
10-
pieLegendTemp: "<ul class=\"<%=name.toLowerCase()%>-legend\" style=\"list-style-type: none;\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>; width: 8px;height: 8px;display: inline-block;border-radius: 10px;border: solid;border-width: 2px;margin: 5px 5px 0 0;\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>",
11-
12-
138
didInsertElement: function(){
14-
var context = this.get('element').getContext('2d');
15-
var data = this.get('data');
16-
var type = Ember.String.classify(this.get('type'));
17-
var template;
18-
switch (type) {
19-
case "Line":
20-
template = this.get('lineLegendTemp');
21-
break;
22-
case "Pie":
23-
template = this.get('pieLegendTemp');
24-
break;
25-
case "Doughnut":
26-
template = this.get('pieLegendTemp');
27-
break;
28-
default:
29-
template = this.get('lineLegendTemp');
30-
break;
31-
}
32-
var options = Ember.merge({
33-
legendTemplate : template
34-
}, this.get('options'));
35-
var redraw = this.get('redraw');
36-
var chart = new Chart(context)[type](data, options);
9+
var context = this.get('element');
10+
var data = this.get('data');
11+
var type = this.get('type');
12+
var options = this.get('options');
3713

38-
if (this.get('legend')) {
39-
var legend = chart.generateLegend();
40-
this.$().wrap("<div class='chart-parent'></div>");
41-
this.$().parent().append(legend);
42-
}
43-
this.set('redraw', redraw);
14+
var chart = new Chart(context, {
15+
type: type,
16+
data: data,
17+
options: options
18+
});
4419
this.set('chart', chart);
4520
this.addObserver('data', this, this.updateChart);
4621
this.addObserver('data.[]', this, this.updateChart);
4722
this.addObserver('options', this, this.updateChart);
4823
},
4924

5025
willDestroyElement: function(){
51-
if (this.get('legend')) {
52-
this.$().parent().children('[class$=legend]').remove();
53-
}
54-
5526
this.get('chart').destroy();
5627
this.removeObserver('data', this, this.updateChart);
5728
this.removeObserver('data.[]', this, this.updateChart);
58-
this.removeObserver('options', this, this.updateChart);
5929
},
6030

6131
updateChart: function(){
62-
var chart = this.get('chart');
63-
var data = this.get('data');
64-
var redraw = ChartDataUpdater.create({
65-
data: data,
66-
chart: chart
67-
}).updateByType();
68-
69-
if (this.get('redraw') || redraw) {
70-
this.willDestroyElement();
71-
this.didInsertElement();
72-
} else {
73-
chart.update();
74-
}
75-
76-
if (this.get('legend')) {
77-
this.$().parent().children('[class$=legend]').remove();
78-
var legend = chart.generateLegend();
79-
this.$().parent().append(legend);
80-
}
32+
var chart = this.get('chart');
33+
var data = this.get('data');
34+
chart.config.data = data;
35+
chart.update();
8136
}
8237
});

blueprints/ember-cli-chart/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module.exports = {
22
normalizeEntityName: function() {},
33

44
afterInstall: function() {
5-
return this.addBowerPackageToProject('chartjs', '1.0.2');
5+
return this.addBowerPackageToProject('chartjs', '2.1.1');
66
}
77
};

bower.json

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
{
22
"name": "ember-cli-chart",
33
"dependencies": {
4-
"ember": "1.13.12",
5-
"ember-cli-shims": "0.0.6",
6-
"ember-cli-test-loader": "0.2.1",
7-
"ember-data": "1.13.15",
8-
"ember-load-initializers": "0.1.7",
9-
"ember-qunit": "0.4.16",
4+
"ember": "~2.5.0",
5+
"ember-cli-shims": "0.1.1",
6+
"ember-cli-test-loader": "0.2.2",
107
"ember-qunit-notifications": "0.1.0",
11-
"ember-resolver": "~0.1.20",
12-
"jquery": "1.11.3",
13-
"loader.js": "ember-cli/loader.js#3.4.0",
14-
"qunit": "~1.20.0",
15-
"chartjs": "1.0.2"
8+
"chartjs": "2.1.1"
169
}
17-
}
10+
}

config/ember-try.js

+43-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,52 @@ module.exports = {
33
scenarios: [
44
{
55
name: 'default',
6-
dependencies: { }
6+
bower: {
7+
dependencies: { }
8+
}
9+
},
10+
{
11+
name: 'ember-1.13',
12+
bower: {
13+
dependencies: {
14+
'ember': '~1.13.0'
15+
},
16+
resolutions: {
17+
'ember': '~1.13.0'
18+
}
19+
}
720
},
821
{
922
name: 'ember-release',
10-
dependencies: {
11-
'ember': 'components/ember#release'
12-
},
13-
resolutions: {
14-
'ember': 'release'
23+
bower: {
24+
dependencies: {
25+
'ember': 'components/ember#release'
26+
},
27+
resolutions: {
28+
'ember': 'release'
29+
}
30+
}
31+
},
32+
{
33+
name: 'ember-beta',
34+
bower: {
35+
dependencies: {
36+
'ember': 'components/ember#beta'
37+
},
38+
resolutions: {
39+
'ember': 'beta'
40+
}
41+
}
42+
},
43+
{
44+
name: 'ember-canary',
45+
bower: {
46+
dependencies: {
47+
'ember': 'components/ember#canary'
48+
},
49+
resolutions: {
50+
'ember': 'canary'
51+
}
1552
}
1653
}
1754
]

ember-cli-build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function(defaults) {
88
});
99

1010
/*
11-
This build file specifes the options for the dummy test app of this
11+
This build file specifies the options for the dummy test app of this
1212
addon, located in `/tests/dummy`
1313
This build file does *not* influence how the addon or the app using it
1414
behave. You most likely want to be modifying `./index.js` or app's build file

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = {
77
included: function included(app) {
88
this._super.included(app);
99

10-
app.import(app.bowerDirectory + '/chartjs/Chart.js');
10+
app.import(app.bowerDirectory + '/chartjs/dist/Chart.js');
1111
}
1212
};

0 commit comments

Comments
 (0)