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

Commit

Permalink
Merge pull request #12 from tyba/master
Browse files Browse the repository at this point in the history
Allow custom chart types.
  • Loading branch information
jhudson8 committed Mar 26, 2015
2 parents c7449c1 + eb2c1f0 commit afac2df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ module.exports = {
Line: require('./lib/line'),
Pie: require('./lib/pie'),
PolarArea: require('./lib/polar-area'),
Radar: require('./lib/radar')
Radar: require('./lib/radar'),
createClass: require('./lib/core').createClass
};
8 changes: 4 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
createClass: function(chartType, methodNames) {
createClass: function(chartType, methodNames, dataKey) {
var classData = {
displayName: chartType + 'Chart',
getInitialState: function() { return {}; },
Expand Down Expand Up @@ -40,7 +40,8 @@ module.exports = {
chart.destroy();
this.initializeChart(nextProps);
} else {
updatePoints(nextProps, chart);
dataKey = dataKey || dataKeys[chart.name];
updatePoints(nextProps, chart, dataKey);
chart.update();
}
};
Expand Down Expand Up @@ -82,15 +83,14 @@ var dataKeys = {
'Bar': 'bars'
};

var updatePoints = function(nextProps, chart) {
var updatePoints = function(nextProps, chart, dataKey) {
var name = chart.name;

if (name === 'PolarArea' || name === 'Pie' || name === 'Doughnut') {
nextProps.data.forEach(function(segment, segmentIndex) {
chart.segments[segmentIndex].value = segment.value;
});
} else {
var dataKey = dataKeys[name];
nextProps.data.datasets.forEach(function(set, setIndex) {
set.data.forEach(function(val, pointIndex) {
chart.datasets[setIndex][dataKey][pointIndex].value = val;
Expand Down

0 comments on commit afac2df

Please sign in to comment.