Skip to content

Commit 4c07ac5

Browse files
committed
Upgraded to Polymer 1.9 and added support for travis
1 parent 1cf2efd commit 4c07ac5

File tree

12 files changed

+156
-56
lines changed

12 files changed

+156
-56
lines changed

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"rules": {
4+
"no-console": 0
5+
},
6+
"env": {
7+
"browser": true
8+
},
9+
"plugins": [
10+
"html"
11+
],
12+
"globals": {
13+
"CustomElements": false,
14+
"HTMLImports": false,
15+
"Polymer": false,
16+
"WeakMap": false
17+
}
18+
}

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
sudo: required
3+
before_script:
4+
- npm install -g bower polylint web-component-tester eslint eslint-plugin-html
5+
- bower install
6+
- polylint
7+
- eslint *.html test/*.html
8+
node_js: '6'
9+
addons:
10+
firefox: latest
11+
apt:
12+
sources:
13+
- google-chrome
14+
packages:
15+
- google-chrome-stable
16+
script:
17+
- xvfb-run wct
18+
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s ''default''; fi'
19+
dist: trusty

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"eslint.enable": true,
3+
"eslint.validate": [
4+
"javascript",
5+
"javascriptreact",
6+
"html"
7+
]
8+
}

.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "0.1.0",
3+
"windows": {
4+
"command": "eslint"
5+
},
6+
"linux": {
7+
"command": "/home/timeu/.nvm/versions/node/v6.10.0/bin/eslint"
8+
},
9+
"osx": {
10+
"command": "eslint"
11+
},
12+
"isShellCommand": true,
13+
"args": ["*.html","test/*.html"],
14+
"showOutput": "silent",
15+
"problemMatcher": "$eslint-stylish"
16+
}

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
> A web-component to draw a piechart using Polymer and SVG.
44
55
## Demo
6-
> [Check it live](http://timeu.github.io/svg-piechart/components/svg-piechart/demo/index.html).
6+
> [Check it live](https://www.webcomponents.org/element/timeu/svg-piechart).
77
88
## Install
99

1010
Install the component using [Bower](http://bower.io/):
1111

1212
```sh
13-
$ bower install --save svg-piechart
13+
$ bower install --save svg-piechart
1414
```
1515

1616
Or [download as ZIP](https://github.com/timeu/svg-piechart/archive/master.zip).
@@ -46,16 +46,6 @@ Or [download as ZIP](https://github.com/timeu/svg-piechart/archive/master.zip).
4646
<svg-piechart size="250" data="[10,20,50,20]"></svg-piechart>
4747
```
4848

49-
## Options
50-
51-
See the [component page](http://timeu.github.io/svg-piechart) for more information.
52-
53-
54-
## Browser Support
55-
56-
![IE](https://raw.github.com/paulirish/browser-logos/master/internet-explorer/internet-explorer_48x48.png) | ![Chrome](https://raw.github.com/paulirish/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/paulirish/browser-logos/master/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/paulirish/browser-logos/master/opera/opera_48x48.png) | ![Safari](https://raw.github.com/paulirish/browser-logos/master/safari/safari_48x48.png)
57-
--- | --- | --- | --- | --- |
58-
IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
5949

6050
## Contributing
6151

bower.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svg-piechart",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"authors": ["Uemit Seren <uemit.seren@gmail.com>"],
55
"description": "Element to draw a piechart on a SVG.",
66
"keywords": "svg, piechart, polymer, web-components",
@@ -12,10 +12,12 @@
1212
"/test/"
1313
],
1414
"dependencies": {
15-
"polymer": "Polymer/polymer#^1.0.0"
15+
"polymer": "Polymer/polymer#^1.9.0"
1616
},
1717
"devDependencies": {
1818
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
19-
"web-component-tester": "*"
19+
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0",
20+
"web-component-tester": "Polymer/web-component-tester#^6.0.0",
21+
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
2022
}
2123
}

demo/index.html

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
<html>
33
<head>
44
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
5-
<title>svg-piechart</title>
5+
<title>svg-piechart demo</title>
66

77
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
8+
9+
<link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html">
10+
<link rel="import" href="../../iron-demo-helpers/demo-snippet.html">
11+
812
<link rel="import" href="../svg-piechart.html">
9-
<link rel="import" href="../../paper-styles/demo-pages.html">
1013

11-
<style is="custom-style">
14+
<style is="custom-style" include="demo-pages-shared-styles">
1215
.vertical-section-container {
1316
max-width: 48em;
1417
margin: 0 auto;
@@ -19,50 +22,73 @@
1922
</style>
2023
</head>
2124
<body>
22-
23-
<div class="vertical-section-container">
25+
<div class="vertical-section-container centered">
2426
<div>
2527
<h4>Normal</h4>
2628
<div class="horizontal-section">
27-
<svg-piechart data="[10,50,20,10]"></svg-piechart>
29+
<demo-snippet>
30+
<template>
31+
<svg-piechart data="[10,50,20,10]"></svg-piechart>
32+
</template>
33+
</demo-snippet>
2834
</div>
2935
</div>
3036
<div>
3137
<h4>Bigger (<code>size</code> is <code>250</code>)</h4>
3238
<div class="horizontal-section">
33-
<svg-piechart size="250" data="[10,50,20,10]"></svg-piechart>
39+
<demo-snippet>
40+
<template>
41+
<svg-piechart size="250" data="[10,50,20,10]"></svg-piechart>
42+
</template>
43+
</demo-snippet>
3444
</div>
3545
</div>
3646
<div>
3747
<h4>Custom colors</h4>
3848
<div class="horizontal-section">
39-
<svg-piechart
49+
<demo-snippet>
50+
<template>
51+
<svg-piechart
4052
colors='[
4153
"rgba(255, 0, 0, .1)",
4254
"rgba(255, 0, 0, .3)",
4355
"rgba(255, 0, 0, .5)",
4456
"rgba(255, 0, 0, .7)",
4557
"rgba(255, 0, 0, .9)"]'
4658
data="[1,1,1,1,1]">
47-
</svg-piechart>
59+
</svg-piechart>
60+
</template>
61+
</demo-snippet>
4862
</div>
4963
</div>
5064
<div>
5165
<h4>Smallest default color palette (up to 4 different colors)</h4>
5266
<div class="horizontal-section">
53-
<svg-piechart data="[1,1,1,1]"></svg-piechart>
67+
<demo-snippet>
68+
<template>
69+
<svg-piechart data="[1,1,1,1]"></svg-piechart>
70+
</template>
71+
</demo-snippet>
5472
</div>
5573
</div>
5674
<div>
5775
<h4>Mid-size default color palette (up to 8 different colors)</h4>
5876
<div class="horizontal-section">
59-
<svg-piechart data="[1,1,1,1,1,1,1,1]"></svg-piechart>
77+
<demo-snippet>
78+
<template>
79+
<svg-piechart data="[1,1,1,1,1,1,1,1]"></svg-piechart>
80+
</template>
81+
</demo-snippet>
6082
</div>
6183
</div>
6284
<div>
6385
<h4>Biggest default color palette (up to 16 different colors)</h4>
6486
<div class="horizontal-section">
65-
<svg-piechart data="[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]"></svg-piechart>
87+
<demo-snippet>
88+
<template>
89+
<svg-piechart data="[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]"></svg-piechart>
90+
</template>
91+
</demo-snippet>
6692
</div>
6793
</div>
6894
</div>

polymer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"lint": {
3+
"rules": [
4+
"polymer-1"
5+
]
6+
}
7+
}

svg-piechart.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
display:block;
3434
}
3535
</style>
36-
36+
3737
<template>
3838
<svg id="svg" width$="[[size]]" height$="[[size]]" viewBox="0 0 360 360">
3939
<!-- <template is="dom-repeat" items={{_arcs}}>
4040
<path class="slice" d="M180,180 L{{item.x1}},{{item.y1}} A180,180 0 {{item.largeArcFlag}},1 {{item.x2}},{{item.y2}} z"style="fill: {{item.color}}" />
4141
</template> -->
4242
</svg>
4343
</template>
44-
44+
4545
</dom-module>
4646

4747
<script>
@@ -91,7 +91,7 @@
9191
/**
9292
* The `colors` attribute specifies the colors to be used for each slice.
9393
* If no colors are specified then the default-colors are used.
94-
*
94+
*
9595
* @attribute colors
9696
*/
9797
colors: {
@@ -101,7 +101,7 @@
101101

102102
/**
103103
* The `size` property specifies the size of the piechart (Default: 150).
104-
*
104+
*
105105
* @attribute size
106106
*/
107107
size: {
@@ -111,7 +111,7 @@
111111

112112
/**
113113
* The `data` property specifies the values for each slice .
114-
*
114+
*
115115
* @attribute data
116116
*/
117117
data: {
@@ -153,7 +153,7 @@
153153

154154
_calculateArcs: function(colors, data) {
155155
var total = this._calculateTotal(data);
156-
var colors = this._getColors(colors);
156+
colors = this._getColors(colors);
157157
var startAngle = 0;
158158
var endAngle = -90;
159159
var arcs = [];
@@ -176,7 +176,7 @@
176176
color: colors[i]
177177
};
178178
if (arc.x2 > 179.9 && arc.y2 === 0 && arc.largeArcFlag === 1) {
179-
arc.x2 = 179.99;
179+
arc.x2 = 179.99;
180180
}
181181
arcs.push(arc);
182182
}
@@ -192,7 +192,7 @@
192192
svg.removeChild(svg.firstChild);
193193
}
194194

195-
for (i = 0; i < arcs.length; i++) {
195+
for (var i = 0; i < arcs.length; i++) {
196196
var path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
197197
path.classList.add('slice');
198198
path.style.fill = arcs[i].color;

test/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
},
5+
"globals": {
6+
"assert": true,
7+
"WCT": true,
8+
"fixture": true,
9+
"Polymer": true,
10+
"async": true
11+
}
12+
}

test/basic-test.html

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,52 @@
2222
<body>
2323

2424
<!-- You can use the document as a place to set up your fixtures. -->
25-
<svg-piechart></svg-piechart>
25+
<test-fixture id="basic">
26+
<template>
27+
<svg-piechart></svg-piechart>
28+
</template>
29+
</test-fixture>
2630

2731
<script>
28-
var myEl = document.querySelector('svg-piechart');
2932

3033
suite('<css-piechart>', function() {
34+
var myEl;
35+
setup(function() {
36+
myEl = fixture('basic')
37+
});
3138
// Clean up after ourselves.
32-
teardown(function(done) {
39+
/*teardown(function(done) {
3340
myEl.colors = [];
3441
myEl.data = []
3542
myEl.size = 50;
3643
flush(done);
37-
});
38-
44+
});*/
45+
3946
test('defaults', function() {
4047
assert.equal(myEl.colors.length,0);
4148
assert.equal(myEl.size,150);
4249
assert.equal(myEl.data.length,0);
4350
});
44-
51+
4552
test('get custom colors when defined',function() {
46-
var customColors = ['red','green','blue'];
53+
var customColors = ['red','green','blue'];
4754
myEl.colors = customColors;
48-
assert.equal(myEl.colors,customColors);
55+
assert.equal(myEl.colors,customColors);
4956
assert.equal(myEl._getColors(customColors),customColors);
5057
});
51-
58+
5259
test('get 4 colors when slices <8',function() {
53-
assert.equal(myEl.colors.length,0);
60+
assert.equal(myEl.colors.length,0);
5461
assert.equal(myEl._getColors([]).length,4);
5562
});
5663
test('get 8 colors when slices > 4',function() {
5764
assert.equal(myEl.colors.length,0);
58-
myEl.data = [1,2,3,4,5];
65+
myEl.data = [1,2,3,4,5];
5966
assert.equal(myEl._getColors().length,8);
60-
});
67+
});
6168
test('get 16 colors when slices > 8',function() {
6269
assert.equal(myEl.colors.length,0);
63-
myEl.data = [1,2,3,4,5,6,7,8,9];
70+
myEl.data = [1,2,3,4,5,6,7,8,9];
6471
assert.equal(myEl._getColors().length,16);
6572
});
6673
test('calculate total',function() {
@@ -89,8 +96,8 @@
8996
myEl.data = [20,40,40];
9097
myEl.colors = ['red','green','blue'];
9198
var background = Polymer.dom(myEl.root).querySelector("#svg");
92-
assert.equal(background.getAttribute("width"),50);
93-
assert.equal(background.getAttribute("height"),50);
99+
assert.equal(background.getAttribute("width"),150);
100+
assert.equal(background.getAttribute("height"),150);
94101
async.nextTick(function() {
95102
var slicesEl = Polymer.dom(myEl.root).querySelectorAll('.slice');
96103
assert.equal(slicesEl.length,3);

0 commit comments

Comments
 (0)