Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
refactor to only use CommonJS
Browse files Browse the repository at this point in the history
  • Loading branch information
jhudson8 committed Feb 6, 2015
1 parent 754b219 commit 1a28230
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 397 deletions.
24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,16 @@ rich interactive react charting components using [chart.js](http://www.chartjs.o

Installation
------------
### Browser
This is a CommonJS component only (to be used with something like Webpack or Browserify)
```
<!-- chart.js must be loaded before react-chartjs -->
<script src="path/to/chart.js"></script>
<script src="path/to/react-chartjs.js"></script>
```

### CommonJS
```
// nothing you need to do here for initialization
```

### AMD
```
define('path/to/chart.js', 'react', 'react-chartjs', function(Chart, React, ReactChart) {
// initialize ReactChartjs
ReactChart(Chart, React);
/// now you can refer to React charts as Chart.React.*
});
npm install --save react-chartjs
```
You must also include the [chartjs](http://www.chartjs.org/) script on your html page

Example Usage
-------------
```
var LineChart = Chart.React.Line; // for browser or AMD (using define('path/to/chart.js'))
var LineChart = require("react-chartjs/line"); // for commonJS
var LineChart = require("react-chartjs").Line;
var MyComponent = React.createClass({
render: function() {
Expand Down
29 changes: 0 additions & 29 deletions bower.json

This file was deleted.

31 changes: 8 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
(function(main) {
if (typeof Chart === 'function') {
// script include
main(Chart);
} else {
// AMD
define([], function() {
return main;
});
}
})(function(Chart, React) {
require('./vars').React = React;
Chart.React = {
Bar: require('./bar'),
Doughnut: require('./doughnut'),
Line: require('./line'),
Pie: require('./pie'),
PolarArea: require('./polar-area'),
Radar: require('./radar')
};
return Chart;
});

module.exports = {
Bar: require('./lib/bar'),
Doughnut: require('./lib/doughnut'),
Line: require('./lib/line'),
Pie: require('./lib/pie'),
PolarArea: require('./lib/polar-area'),
Radar: require('./lib/radar')
};
2 changes: 1 addition & 1 deletion bar.js → lib/bar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('Bar', ['getBarsAtEvent']);
10 changes: 1 addition & 9 deletions vars.js → lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,7 @@ module.exports = {
}
}

var React = this.React || global.React;
if (!React && (typeof require !== 'undefined') && (typeof define !== 'function')) {
// allow the charts to not need to be initialized for commonJS
React = this.React = require('react');
}
if (!React) {
throw new Error("The charts were not initialized with the React instance");
}

var React = require('react');
return React.createClass(classData);
}
};
2 changes: 1 addition & 1 deletion doughnut.js → lib/doughnut.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('Doughnut', ['getSegmentsAtEvent']);
2 changes: 1 addition & 1 deletion line.js → lib/line.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('Line', ['getPointsAtEvent']);
2 changes: 1 addition & 1 deletion pie.js → lib/pie.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('Pie', ['getSegmentsAtEvent']);
2 changes: 1 addition & 1 deletion polar-area.js → lib/polar-area.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('PolarArea', ['getSegmentsAtEvent']);
2 changes: 1 addition & 1 deletion radar.js → lib/radar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var vars = require('./vars');
var vars = require('./core');

module.exports = vars.createClass('Radar', ['getPointsAtEvent']);
Loading

0 comments on commit 1a28230

Please sign in to comment.