Skip to content

Commit

Permalink
Support commonJS and browserify. Cleanup of #572
Browse files Browse the repository at this point in the history
  • Loading branch information
pablojim committed Mar 26, 2017
1 parent c365672 commit 508df11
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 38 deletions.
12 changes: 10 additions & 2 deletions dist/highcharts-ng.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* highcharts-ng
* @version v1.0.2-dev - 2017-03-02
* @version v1.0.2-dev - 2017-03-26
* @link https://github.com/pablojim/highcharts-ng
* @author Barry Fitzgerald <>
* @license MIT License, http://www.opensource.org/licenses/MIT
Expand All @@ -12,7 +12,15 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex

(function () {
'use strict';
/*global angular: false, Highcharts: false */
/*global angular: false*/
var Highcharts = null;

if (window && window.Highcharts) {
Highcharts = window.Highcharts;
}
if (module && module.exports === 'highcharts-ng') {
Highcharts = require('highcharts');
}


angular.module('highcharts-ng', [])
Expand Down
4 changes: 2 additions & 2 deletions dist/highcharts-ng.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function(config) {
'node_modules/angular/angular.js',
'node_modules/jquery/dist/jquery.js',
'node_modules/angular-mocks/angular-mocks.js',
'test/highcharts-mock.js',
'src/*.js',
'test/spec/*.js'
],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
"test": "grunt test"
},
"main": "./dist/highcharts-ng",
"dependencies": {}
"dependencies": {
"highcharts": "^5.0.9"
}
}
10 changes: 9 additions & 1 deletion src/highcharts-ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ if (typeof module !== 'undefined' && typeof exports !== 'undefined' && module.ex

(function () {
'use strict';
/*global angular: false, Highcharts: false */
/*global angular: false*/
var Highcharts = null;

if (window && window.Highcharts) {
Highcharts = window.Highcharts;
}
if (module && module.exports === 'highcharts-ng') {
Highcharts = require('highcharts');
}


angular.module('highcharts-ng', [])
Expand Down
38 changes: 38 additions & 0 deletions test/highcharts-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

window.Highcharts = (function () {
var ns = {};

ns.reset = function () {
ns.chart = jasmine.createSpyObj('chart', [
'redraw',
'setTitle',
'hideLoading',
'destroy',
'get',
'addSeries',
'update']);
ns.chart.series = [];
ns.usedChartConstructor = null;
ns.options = null;
};

ns.Chart = function (opt) {
ns.options = opt;
ns.usedChartConstructor = 'Chart';
return ns.chart;
};
ns.StockChart = function (opt) {
ns.options = opt;
ns.usedChartConstructor = 'StockChart';
return this.chart;
};
ns.Map = function (opt) {
ns.options = opt;
ns.usedChartConstructor = 'Map';
return ns.chart;
};
return ns;
}());


38 changes: 6 additions & 32 deletions test/spec/highcharts-ng.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,18 @@ describe('Module: highchartsNg', function () {
usedChartConstructor,
chart;


// load the controller's module
beforeEach(module('highcharts-ng'));

beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_) {
title = {};
destroyed = false;
usedChartConstructor = '';

chart = jasmine.createSpyObj('chart', [
'redraw',
'setTitle',
'hideLoading',
'destroy',
'get',
'addSeries',
'update']);
chart.series = [];

window.Highcharts = {
Chart: function (opt) {
options = opt;
usedChartConstructor = 'Chart';

return chart;
},
StockChart: function (opt) {
options = opt;
usedChartConstructor = 'StockChart';
scope = $rootScope;

return chart;
},
Map: function (opt) {
options = opt;
usedChartConstructor = 'Map';
window.Highcharts.reset();
chart = window.Highcharts.chart;

return chart;
}
};
scope = $rootScope;
$compile = _$compile_;
$timeout = _$timeout_;

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

it('passes options to highcharts', function () {
compileDirective('simpleChartConfig');

options = window.Highcharts.options;
expect(options.chart.type).toBe('bar');
expect(options.chart.series).toBe(templates.simpleChartConfig.series);
});
Expand All @@ -113,6 +86,7 @@ describe('Module: highchartsNg', function () {
});

it('uses highstocks', function () {
usedChartConstructor = window.Highcharts.usedChartConstructor;
expect(usedChartConstructor).toBe('StockChart');
});
});
Expand Down

0 comments on commit 508df11

Please sign in to comment.