react-sigma
Version:
Lightweight but powerful library for drawing network graphs built on top of SigmaJS
114 lines (84 loc) • 5.57 kB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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; }
import React from 'react';
import '../sigma/parsers.gexf';
import { embedProps } from './tools';
/**
LoadGEXF component, interface for parsers.json sigma plugin. Can be used within Sigma component.
Can be composed with other plugins: on load it mounts all child components (e.g. other sigma plugins).
Child's componentWillMount should be used to enable plugins on loaded graph.
@param {string} path path to the GEXF file
@param {Function} onGraphLoaded Optional callback for graph update
[see sigma plugin page for more details](https://github.com/jacomyal/sigma.js/tree/master/plugins/sigma.neo4j.cypher)
**/
var LoadGEXF = /*#__PURE__*/function (_React$Component) {
_inherits(LoadGEXF, _React$Component);
var _super = _createSuper(LoadGEXF);
function LoadGEXF(props) {
var _this;
_classCallCheck(this, LoadGEXF);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "onLoad", function () {
if (_this.props.sigma) _this.props.sigma.refresh();
_this.setState({
loaded: true
});
if (_this.props.onGraphLoaded) return _this.props.onGraphLoaded();
});
_this.state = {
loaded: false
};
return _this;
}
_createClass(LoadGEXF, [{
key: "componentDidMount",
value: function componentDidMount() {
this._load(this.props.path);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(props) {
// reload only if path changes
if (this.props.path !== props.path) {
this.setState({
loaded: false
});
this._load(props.path);
}
}
}, {
key: "render",
value: function render() {
if (!this.state.loaded) return null;
return /*#__PURE__*/React.createElement("div", null, embedProps(this.props.children, {
sigma: this.props.sigma
}));
}
}, {
key: "_load",
value: function _load(url) {
sigma.parsers.gexf(this.props.path, this.props.sigma, this.onLoad);
}
}]);
return LoadGEXF;
}(React.Component);
_defineProperty(LoadGEXF, "propTypes", {
path: PropTypes.string.isRequired,
onGraphLoaded: PropTypes.func,
children: PropTypes.any,
sigma: function sigma() {
return (typeof Sigma === "function" ? PropTypes.instanceOf(Sigma) : PropTypes.any).apply(this, arguments);
}
});
export default LoadGEXF;
import PropTypes from "prop-types";