Skip to content

Commit a1f570f

Browse files
author
xuchenhui
committed
Add unittest
Add travis.CI Fix some bug
1 parent bd9de48 commit a1f570f

File tree

12 files changed

+465
-43
lines changed

12 files changed

+465
-43
lines changed

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
sudo: required
2+
dist: trusty
3+
4+
language: node_js
5+
node_js:
6+
- "6"
7+
- "6.1"
8+
- "5.11"
9+
10+
addons:
11+
firefox: latest
12+
apt:
13+
sources:
14+
- google-chrome
15+
packages:
16+
- google-chrome-stable
17+
18+
before_install:
19+
- "export CHROME_BIN=/usr/bin/google-chrome"
20+
# starting a GUI to run tests, per https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI
21+
- export DISPLAY=:99.0
22+
- sh -e /etc/init.d/xvfb start
23+
24+
before_script:
25+
- npm install -g gulp
26+
- npm install
27+
28+
script:
29+
- gulp test.ci

dist/chart.funnel.bundled.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* Chart.Funnel.js
33
* A funnel plugin for Chart.js(http://chartjs.org/)
4-
* Version: 0.1.0
4+
* Version: 0.1.1
55
*
66
* Copyright 2016 Jone Casaper
77
* Released under the MIT license
@@ -14589,7 +14589,7 @@ module.exports = function(Chart) {
1458914589
borderWidth: 0,
1459014590
borderColor: globalOpts.defaultColor,
1459114591
borderSkipped: 'bottom',
14592-
type: 'isosceles' // isosceles
14592+
type: 'isosceles' // isosceles, scalene
1459314593
};
1459414594

1459514595
// Thanks for https://github.com/substack/point-in-polygon
@@ -14614,13 +14614,15 @@ module.exports = function(Chart) {
1461414614
Chart.elements.Trapezium = Chart.Element.extend({
1461514615
getCorners: function () {
1461614616
var vm = this._view;
14617+
var globalOptionTrapeziumElements = globalOpts.elements.trapezium;
1461714618

1461814619
var corners = [],
14619-
type = vm.type || globalOpts.elements.trapezium.type,
14620+
type = vm.type || globalOptionTrapeziumElements.type,
1462014621
top = vm.y,
14622+
borderWidth = vm.borderWidth || globalOptionTrapeziumElements.borderWidth,
1462114623
upHalfWidth = vm.upperWidth / 2,
1462214624
botHalfWidth = vm.bottomWidth / 2,
14623-
halfStroke = vm.borderWidth / 2;
14625+
halfStroke = borderWidth / 2;
1462414626

1462514627
halfStroke = halfStroke < 0 ? 0 : halfStroke;
1462614628

@@ -14649,6 +14651,7 @@ module.exports = function(Chart) {
1464914651
];
1465014652
}
1465114653

14654+
1465214655
return corners;
1465314656
},
1465414657
draw: function () {
@@ -14688,24 +14691,38 @@ module.exports = function(Chart) {
1468814691
},
1468914692
height: function () {
1469014693
var vm = this._view;
14694+
if (!vm) {
14695+
return 0;
14696+
}
14697+
1469114698
return vm.base - vm.y;
1469214699
},
1469314700
inRange: function (mouseX, mouseY) {
1469414701
var vm = this._view;
14695-
14702+
if (!vm) {
14703+
return false;
14704+
}
1469614705
var corners = this._cornersCache ? this._cornersCache : this.getCorners();
14697-
1469814706
return pointInPolygon([mouseX, mouseY], corners);
1469914707
},
1470014708
inLabelRange: function (mouseX) {
1470114709
var x,
14702-
vm = this._view,
14703-
maxWidth = Math.max(this.upperWidth, this.bottomWidth);
14710+
vm = this._view;
14711+
14712+
if (!vm) {
14713+
return false;
14714+
}
1470414715

1470514716
if (vm.type == 'scalene') {
14706-
x = this.upperWidth === maxWidth ? vm.x1 : vm.x2;
14717+
if (vm.x1 > vm.x2) {
14718+
return mouseX >= vm.x2 - vm.bottomWidth / 2 && mouseX <= vm.x1 + vm.upperWidth / 2;
14719+
} else {
14720+
return mouseX <= vm.x2 + vm.bottomWidth / 2 && mouseX >= vm.x1 - vm.upperWidth / 2;
14721+
}
1470714722
}
14708-
return vm ? (mouseX >= vm.x - maxWidth / 2 && mouseX <= vm.x + maxWidth / 2) : false;
14723+
14724+
var maxWidth = Math.max(vm.upperWidth, vm.bottomWidth);
14725+
return mouseX >= vm.x - maxWidth / 2 && mouseX <= vm.x + maxWidth / 2;
1470914726

1471014727
},
1471114728
tooltipPosition: function () {

dist/chart.funnel.bundled.min.js

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

dist/chart.funnel.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* Chart.Funnel.js
33
* A funnel plugin for Chart.js(http://chartjs.org/)
4-
* Version: 0.1.0
4+
* Version: 0.1.1
55
*
66
* Copyright 2016 Jone Casaper
77
* Released under the MIT license
@@ -320,7 +320,7 @@ module.exports = function(Chart) {
320320
borderWidth: 0,
321321
borderColor: globalOpts.defaultColor,
322322
borderSkipped: 'bottom',
323-
type: 'isosceles' // isosceles
323+
type: 'isosceles' // isosceles, scalene
324324
};
325325

326326
// Thanks for https://github.com/substack/point-in-polygon
@@ -345,13 +345,15 @@ module.exports = function(Chart) {
345345
Chart.elements.Trapezium = Chart.Element.extend({
346346
getCorners: function () {
347347
var vm = this._view;
348+
var globalOptionTrapeziumElements = globalOpts.elements.trapezium;
348349

349350
var corners = [],
350-
type = vm.type || globalOpts.elements.trapezium.type,
351+
type = vm.type || globalOptionTrapeziumElements.type,
351352
top = vm.y,
353+
borderWidth = vm.borderWidth || globalOptionTrapeziumElements.borderWidth,
352354
upHalfWidth = vm.upperWidth / 2,
353355
botHalfWidth = vm.bottomWidth / 2,
354-
halfStroke = vm.borderWidth / 2;
356+
halfStroke = borderWidth / 2;
355357

356358
halfStroke = halfStroke < 0 ? 0 : halfStroke;
357359

@@ -380,6 +382,7 @@ module.exports = function(Chart) {
380382
];
381383
}
382384

385+
383386
return corners;
384387
},
385388
draw: function () {
@@ -419,24 +422,38 @@ module.exports = function(Chart) {
419422
},
420423
height: function () {
421424
var vm = this._view;
425+
if (!vm) {
426+
return 0;
427+
}
428+
422429
return vm.base - vm.y;
423430
},
424431
inRange: function (mouseX, mouseY) {
425432
var vm = this._view;
426-
433+
if (!vm) {
434+
return false;
435+
}
427436
var corners = this._cornersCache ? this._cornersCache : this.getCorners();
428-
429437
return pointInPolygon([mouseX, mouseY], corners);
430438
},
431439
inLabelRange: function (mouseX) {
432440
var x,
433-
vm = this._view,
434-
maxWidth = Math.max(this.upperWidth, this.bottomWidth);
441+
vm = this._view;
442+
443+
if (!vm) {
444+
return false;
445+
}
435446

436447
if (vm.type == 'scalene') {
437-
x = this.upperWidth === maxWidth ? vm.x1 : vm.x2;
448+
if (vm.x1 > vm.x2) {
449+
return mouseX >= vm.x2 - vm.bottomWidth / 2 && mouseX <= vm.x1 + vm.upperWidth / 2;
450+
} else {
451+
return mouseX <= vm.x2 + vm.bottomWidth / 2 && mouseX >= vm.x1 - vm.upperWidth / 2;
452+
}
438453
}
439-
return vm ? (mouseX >= vm.x - maxWidth / 2 && mouseX <= vm.x + maxWidth / 2) : false;
454+
455+
var maxWidth = Math.max(vm.upperWidth, vm.bottomWidth);
456+
return mouseX >= vm.x - maxWidth / 2 && mouseX <= vm.x + maxWidth / 2;
440457

441458
},
442459
tooltipPosition: function () {

dist/chart.funnel.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.

gulpfile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var concat = require('gulp-concat');
1111
var source = require('vinyl-source-stream');
1212
var merge = require('merge-stream');
1313
var collapse = require('bundle-collapser/plugin');
14+
var Server = require('karma').Server;
1415

1516
var package = require('./package.json');
1617
var header = "/*!\n" +
@@ -66,6 +67,16 @@ gulp.task('jshint',function(){
6667
.pipe(jshint.reporter('fail'));
6768
});
6869

70+
// For CI
71+
gulp.task('unittest.ci',function(done){
72+
new Server({
73+
configFile: __dirname + '/karma.conf.ci.js',
74+
singleRun: true
75+
}, done).start();
76+
});
77+
78+
gulp.task('test.ci', ['jshint', 'unittest.ci']);
79+
6980
gulp.task('default',function(){
7081
gulp.watch('src/**/*.js',['js']);
7182
});

0 commit comments

Comments
 (0)