UNPKG

wui-bigdata

Version:

Big data visualization library for WUI framework.

113 lines (91 loc) 5.05 kB
'use strict'; 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 ChordDiagram = function (_Component) { _inherits(ChordDiagram, _Component); function ChordDiagram() { _classCallCheck(this, ChordDiagram); return _possibleConstructorReturn(this, Object.getPrototypeOf(ChordDiagram).apply(this, arguments)); } _createClass(ChordDiagram, [{ key: 'render', value: function render() { var continent = ['亚洲', '欧洲', '非洲', '美洲', '大洋洲']; var population = [[9000, 870, 3000, 1000, 5200], [3400, 8000, 2300, 4922, 374], [2000, 2000, 7700, 4881, 1050], [3000, 8012, 5531, 500, 400], [3540, 4310, 1500, 1900, 300]]; var chord = _d2.default.layout.chord().padding(0.03).sortSubgroups(_d2.default.ascending).matrix(population); var width = 600; var height = 600; var color20 = _d2.default.scale.category20(); var innerRadius = width / 2 * 0.7; var outerRadius = innerRadius * 1.1; var arcOuter = _d2.default.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius); var arcInner = _d2.default.svg.chord().radius(innerRadius); var innerPaths = _d2.default.select(this.refs['chord-svg']).selectAll('.innerPath').data(chord.chords()); var fade = function fade(opacity, index) { return function () { innerPaths.filter(function (d) { return d.source.index != index && d.target.index != index; }).transition().style('opacity', opacity); }; }; return _react2.default.createElement( 'svg', { ref: 'chord-svg', width: width, height: height }, _react2.default.createElement( 'g', { transform: 'translate(' + width / 2 + ', ' + height / 2 + ')' }, _react2.default.createElement( 'g', null, chord.groups().map(function (d, index) { return _react2.default.createElement('path', { className: 'outerPath', onMouseEnter: fade(0, index), onMouseLeave: fade(1, index), key: index, fill: color20(d.index), d: arcOuter(d) }); }), chord.groups().map(function (d, index) { var angle = (d.startAngle + d.endAngle) / 2; var transform = 'rotate(' + angle * 180 / Math.PI + ')'; transform += 'translate(0, ' + -1.0 * (outerRadius + 10) + ')'; if (angle > Math.PI * 3 / 4 && angle < Math.PI * 5 / 4) { transform += 'rotate(180)'; } return _react2.default.createElement( 'text', { key: index, className: 'outerText', dy: '.35em', transform: transform }, continent[index] ); }) ), _react2.default.createElement( 'g', null, chord.chords().map(function (d, index) { return _react2.default.createElement('path', { key: index, className: 'innerPath', d: arcInner(d), fill: color20(d.source.index) }); }) ) ) ); } }]); return ChordDiagram; }(_react.Component); exports.default = ChordDiagram;