1
0
mirror of https://github.com/yldio/copilot.git synced 2024-12-24 02:40:05 +02:00
copilot/legacy/spikes/graphs-matrix/chartjs-whiskers/client/matrix.js

90 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-11-18 14:28:37 +02:00
const React = require('react');
const buildArray = require('build-array');
const ReactRedux = require('react-redux');
const Chart = require('./chart');
const actions = require('./actions');
const {
connect
} = ReactRedux;
const {
subscribe,
unsubscribe
} = actions;
const mapStateToProps = (state, ownProps) => {
return {
windowSize: state.windowSize,
data: state[ownProps.id]
};
};
const mapDispatchToProps = (dispatch, ownProps) => {
return {
subscribe: () => {
return dispatch(subscribe(ownProps.id));
},
unsubscribe: () => {
return unsubscribe(ownProps.id);
}
}
};
const Row = connect(
mapStateToProps,
mapDispatchToProps,
)(React.createClass({
componentWillMount: function() {
this.props.subscribe();
},
componentWillUnmount: function() {
this.props.unsubscribe();
},
render: function() {
const {
data = {},
windowSize
} = this.props;
const charts = Object.keys(data).map((key, i, arr) => {
if (!Chart[key]) {
return null;
}
const chart = React.createElement(Chart[key], {
data: data[key],
windowSize
});
return (
<div key={key} className={`col-xs-${12 / arr.length}`}>
{chart}
</div>
);
});
return (
<div className='row'>
{charts}
</div>
);
}
}));
module.exports = ({
rows
}) => {
const _rows = buildArray(rows).map((v, i) => {
return (
<Row id={i} key={i} />
);
});
return (
<div>
{_rows}
</div>
);
};