Meta2d.jsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from "react";
  2. import "./Meta2d.css";
  3. let meta2d = null;
  4. export default class Meta2d extends React.Component {
  5. constructor(props) {
  6. super(props);
  7. }
  8. componentDidMount() {
  9. meta2d = new window.Meta2d("meta2d",{
  10. background: '#1e2430',
  11. x: 32,
  12. y: 32,
  13. width: 1920,
  14. height: 1080,
  15. color: '#bdc7db',
  16. });
  17. window.registerCommonDiagram();
  18. this._fetch("/json/data.json", function (text) {
  19. var data = JSON.parse(text);
  20. data.locked = 1;
  21. meta2d.open(data);
  22. let fit =
  23. meta2d.store.data.scaleMode === '3'
  24. ? 'height'
  25. : meta2d.store.data.scaleMode === '2'
  26. ? 'width'
  27. : true;
  28. meta2d.fitSizeView(fit, 10);
  29. });
  30. }
  31. componentWillUnmount() {
  32. meta2d?.destroy();
  33. }
  34. _fetch(url, cb) {
  35. var xhr = new XMLHttpRequest();
  36. xhr.open("GET", url, true);
  37. xhr.send();
  38. xhr.onreadystatechange = function () {
  39. if (xhr.readyState == 4 && xhr.status == 200) {
  40. cb && cb(xhr.responseText);
  41. }
  42. };
  43. }
  44. render() {
  45. return (
  46. <div className="content">
  47. <div id="meta2d"></div>
  48. </div>
  49. );
  50. }
  51. }