wui-bigdata
Version:
Big data visualization library for WUI framework.
101 lines (78 loc) • 4.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _d = require('d3');
var _d2 = _interopRequireDefault(_d);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var BrushSample = function (_Component) {
_inherits(BrushSample, _Component);
function BrushSample() {
_classCallCheck(this, BrushSample);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(BrushSample).call(this));
_this.dataset = [];
for (var i = 0; i < 150; i++) {
_this.dataset.push([Math.random() * 10, Math.random() * 10]);
}
_this.state = {
xmin: 0,
xmax: 0,
ymin: 0,
ymax: 0
};
return _this;
}
_createClass(BrushSample, [{
key: 'onBrushed',
value: function onBrushed() {
var extent = this.brush.extent();
var xmin = extent[0][0];
var xmax = extent[1][0];
var ymin = extent[0][1];
var ymax = extent[1][1];
this.setState({
xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax
});
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
this.brush = _d2.default.svg.brush().x(this.xScale).y(this.yScale).extent([[0, 0], [0, 0]]).on('brush', this.onBrushed.bind(this));
_d2.default.select(this.refs.brush).call(this.brush).selectAll('rect').style('fill-opacity', 0.3);
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var width = 600;
var height = 600;
var padding = { left: 50, right: 50, top: 50, bottom: 50 };
this.xScale = _d2.default.scale.linear().domain([0, 10]).range([padding.left, width - padding.right]);
this.yScale = _d2.default.scale.linear().domain([10, 0]).range([padding.top, height - padding.bottom]);
return _react2.default.createElement(
'svg',
{ width: width, height: height },
this.dataset.map(function (d, i) {
var color = 'black';
if (d[0] >= _this2.state.xmin && d[0] <= _this2.state.xmax && d[1] >= _this2.state.ymin && d[1] <= _this2.state.ymax) {
color = 'red';
}
return _react2.default.createElement('circle', { key: i,
cx: _this2.xScale(d[0]),
cy: _this2.yScale(d[1]),
r: 5,
fill: color });
}),
_react2.default.createElement('g', { ref: 'brush' })
);
}
}]);
return BrushSample;
}(_react.Component);
exports.default = BrushSample;