Skip to content

Commit 508df11

Browse files
committed
Support commonJS and browserify. Cleanup of #572
1 parent c365672 commit 508df11

7 files changed

+69
-38
lines changed

dist/highcharts-ng.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* highcharts-ng
3-
* @version v1.0.2-dev - 2017-03-02
3+
* @version v1.0.2-dev - 2017-03-26
44
* @link https://github.com/pablojim/highcharts-ng
55
* @author Barry Fitzgerald <>
66
* @license MIT License, http://www.opensource.org/licenses/MIT
@@ -12,7 +12,15 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex
1212

1313
(function () {
1414
'use strict';
15-
/*global angular: false, Highcharts: false */
15+
/*global angular: false*/
16+
var Highcharts = null;
17+
18+
if (window && window.Highcharts) {
19+
Highcharts = window.Highcharts;
20+
}
21+
if (module && module.exports === 'highcharts-ng') {
22+
Highcharts = require('highcharts');
23+
}
1624

1725

1826
angular.module('highcharts-ng', [])

dist/highcharts-ng.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = function(config) {
1616
'node_modules/angular/angular.js',
1717
'node_modules/jquery/dist/jquery.js',
1818
'node_modules/angular-mocks/angular-mocks.js',
19+
'test/highcharts-mock.js',
1920
'src/*.js',
2021
'test/spec/*.js'
2122
],

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@
4747
"test": "grunt test"
4848
},
4949
"main": "./dist/highcharts-ng",
50-
"dependencies": {}
50+
"dependencies": {
51+
"highcharts": "^5.0.9"
52+
}
5153
}

src/highcharts-ng.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex
44

55
(function () {
66
'use strict';
7-
/*global angular: false, Highcharts: false */
7+
/*global angular: false*/
8+
var Highcharts = null;
9+
10+
if (window && window.Highcharts) {
11+
Highcharts = window.Highcharts;
12+
}
13+
if (module && module.exports === 'highcharts-ng') {
14+
Highcharts = require('highcharts');
15+
}
816

917

1018
angular.module('highcharts-ng', [])

test/highcharts-mock.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
window.Highcharts = (function () {
4+
var ns = {};
5+
6+
ns.reset = function () {
7+
ns.chart = jasmine.createSpyObj('chart', [
8+
'redraw',
9+
'setTitle',
10+
'hideLoading',
11+
'destroy',
12+
'get',
13+
'addSeries',
14+
'update']);
15+
ns.chart.series = [];
16+
ns.usedChartConstructor = null;
17+
ns.options = null;
18+
};
19+
20+
ns.Chart = function (opt) {
21+
ns.options = opt;
22+
ns.usedChartConstructor = 'Chart';
23+
return ns.chart;
24+
};
25+
ns.StockChart = function (opt) {
26+
ns.options = opt;
27+
ns.usedChartConstructor = 'StockChart';
28+
return this.chart;
29+
};
30+
ns.Map = function (opt) {
31+
ns.options = opt;
32+
ns.usedChartConstructor = 'Map';
33+
return ns.chart;
34+
};
35+
return ns;
36+
}());
37+
38+

test/spec/highcharts-ng.js

+6-32
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,18 @@ describe('Module: highchartsNg', function () {
1111
usedChartConstructor,
1212
chart;
1313

14+
1415
// load the controller's module
1516
beforeEach(module('highcharts-ng'));
1617

1718
beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_) {
1819
title = {};
1920
destroyed = false;
20-
usedChartConstructor = '';
21-
22-
chart = jasmine.createSpyObj('chart', [
23-
'redraw',
24-
'setTitle',
25-
'hideLoading',
26-
'destroy',
27-
'get',
28-
'addSeries',
29-
'update']);
30-
chart.series = [];
31-
32-
window.Highcharts = {
33-
Chart: function (opt) {
34-
options = opt;
35-
usedChartConstructor = 'Chart';
36-
37-
return chart;
38-
},
39-
StockChart: function (opt) {
40-
options = opt;
41-
usedChartConstructor = 'StockChart';
21+
scope = $rootScope;
4222

43-
return chart;
44-
},
45-
Map: function (opt) {
46-
options = opt;
47-
usedChartConstructor = 'Map';
23+
window.Highcharts.reset();
24+
chart = window.Highcharts.chart;
4825

49-
return chart;
50-
}
51-
};
52-
scope = $rootScope;
5326
$compile = _$compile_;
5427
$timeout = _$timeout_;
5528

@@ -102,7 +75,7 @@ describe('Module: highchartsNg', function () {
10275

10376
it('passes options to highcharts', function () {
10477
compileDirective('simpleChartConfig');
105-
78+
options = window.Highcharts.options;
10679
expect(options.chart.type).toBe('bar');
10780
expect(options.chart.series).toBe(templates.simpleChartConfig.series);
10881
});
@@ -113,6 +86,7 @@ describe('Module: highchartsNg', function () {
11386
});
11487

11588
it('uses highstocks', function () {
89+
usedChartConstructor = window.Highcharts.usedChartConstructor;
11690
expect(usedChartConstructor).toBe('StockChart');
11791
});
11892
});

0 commit comments

Comments
 (0)