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

Commit afac2df

Browse files
committed
Merge pull request #12 from tyba/master
Allow custom chart types.
2 parents c7449c1 + eb2c1f0 commit afac2df

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ module.exports = {
44
Line: require('./lib/line'),
55
Pie: require('./lib/pie'),
66
PolarArea: require('./lib/polar-area'),
7-
Radar: require('./lib/radar')
7+
Radar: require('./lib/radar'),
8+
createClass: require('./lib/core').createClass
89
};

lib/core.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
createClass: function(chartType, methodNames) {
2+
createClass: function(chartType, methodNames, dataKey) {
33
var classData = {
44
displayName: chartType + 'Chart',
55
getInitialState: function() { return {}; },
@@ -40,7 +40,8 @@ module.exports = {
4040
chart.destroy();
4141
this.initializeChart(nextProps);
4242
} else {
43-
updatePoints(nextProps, chart);
43+
dataKey = dataKey || dataKeys[chart.name];
44+
updatePoints(nextProps, chart, dataKey);
4445
chart.update();
4546
}
4647
};
@@ -82,15 +83,14 @@ var dataKeys = {
8283
'Bar': 'bars'
8384
};
8485

85-
var updatePoints = function(nextProps, chart) {
86+
var updatePoints = function(nextProps, chart, dataKey) {
8687
var name = chart.name;
8788

8889
if (name === 'PolarArea' || name === 'Pie' || name === 'Doughnut') {
8990
nextProps.data.forEach(function(segment, segmentIndex) {
9091
chart.segments[segmentIndex].value = segment.value;
9192
});
9293
} else {
93-
var dataKey = dataKeys[name];
9494
nextProps.data.datasets.forEach(function(set, setIndex) {
9595
set.data.forEach(function(val, pointIndex) {
9696
chart.datasets[setIndex][dataKey][pointIndex].value = val;

0 commit comments

Comments
 (0)