2016-11-18 14:28:37 +02:00
|
|
|
const buildArray = require('build-array');
|
|
|
|
const Chart = require('chart.js');
|
|
|
|
const React = require('react');
|
2017-01-04 18:45:31 +02:00
|
|
|
const whisker = require('chartjs-chart-box-plot');
|
2016-11-18 14:28:37 +02:00
|
|
|
whisker(Chart);
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
ref: function(name) {
|
|
|
|
this._refs = this._refs || {};
|
|
|
|
|
|
|
|
return (el) => {
|
|
|
|
this._refs[name] = el;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
const {
|
|
|
|
datasets = [],
|
|
|
|
labels = 0,
|
|
|
|
stacked = false,
|
|
|
|
xAxe = false,
|
|
|
|
yAxe = false,
|
2016-11-21 16:09:52 +02:00
|
|
|
legend = false,
|
|
|
|
max = 100,
|
|
|
|
min = 0
|
2016-11-18 14:28:37 +02:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const _labels = !Array.isArray(labels)
|
|
|
|
? buildArray(labels).map((v, i) => '')
|
|
|
|
: labels;
|
|
|
|
|
|
|
|
this._chart = new Chart(this._refs.component, {
|
|
|
|
type: 'whisker',
|
|
|
|
responsive: true,
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
2016-11-21 13:12:22 +02:00
|
|
|
barPercentage: 1.0,
|
2016-11-21 16:09:52 +02:00
|
|
|
categoryPercentage: 1.0
|
2016-11-18 14:28:37 +02:00
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
ticks: {
|
2016-11-21 16:09:52 +02:00
|
|
|
min: min,
|
|
|
|
max: max
|
|
|
|
}
|
2016-11-18 14:28:37 +02:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
display: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
labels: _labels,
|
|
|
|
datasets: datasets
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
const {
|
|
|
|
datasets = [],
|
|
|
|
labels = 0
|
|
|
|
} = this.props;
|
2016-11-25 03:37:38 +02:00
|
|
|
|
2016-11-18 14:28:37 +02:00
|
|
|
this._chart.data.datasets = datasets;
|
|
|
|
this._chart.data.labels = buildArray(labels).map((v, i) => '');
|
|
|
|
this._chart.update(0);
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<canvas
|
|
|
|
ref={this.ref('component')}
|
|
|
|
width='400'
|
|
|
|
height='400'
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|