react-sigma
Version:
Lightweight but powerful library for drawing network graphs built on top of SigmaJS
58 lines (42 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _tools = require("./tools");
var _propTypes = _interopRequireDefault(require("prop-types"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
RandomizeNodePositions component, sets random positions to all nodes.
Can be used within Sigma component with predefined graph or within graph loader component.
**/
class RandomizeNodePositions extends _react.default.PureComponent {
constructor(props) {
super(props);
if (this.props.sigma) {
this.props.sigma.graph.nodes().forEach(n => {
n.x = Math.random();
n.y = Math.random();
});
}
if (this.props.sigma) this.props.sigma.refresh();
}
componentDidMount() {
if (this.props.sigma) this.props.sigma.refresh();
}
render() {
return /*#__PURE__*/_react.default.createElement("div", null, (0, _tools.embedProps)(this.props.children, {
sigma: this.props.sigma
}));
}
}
_defineProperty(RandomizeNodePositions, "propTypes", {
children: _propTypes.default.any,
sigma: function () {
return (typeof sigma === "function" ? _propTypes.default.instanceOf(sigma) : _propTypes.default.any).apply(this, arguments);
}
});
var _default = RandomizeNodePositions;
exports.default = _default;