import React from 'react';
import { Motion, spring } from 'react-motion';
import dagre from 'dagre';
import prettyFormat from 'pretty-format';
import reactElement from 'pretty-format/plugins/ReactElement';
function getFiberColor(fibers, id) {
if (fibers.currentIDs.indexOf(id) > -1) {
return 'lightgreen';
}
if (id === fibers.workInProgressID) {
return 'yellow';
}
return 'lightyellow';
}
function Graph(props) {
var g = new dagre.graphlib.Graph();
g.setGraph({
width: 1000,
height: 1000,
nodesep: 50,
edgesep: 150,
ranksep: 150,
marginx: 100,
marginy: 100,
});
var edgeLabels = {};
React.Children.forEach(props.children, function(child) {
if (!child) {
return;
}
if (child.type.isVertex) {
g.setNode(child.key, {
label: child,
width: child.props.width,
height: child.props.height
});
} else if (child.type.isEdge) {
const relationshipKey = child.props.source + ':' + child.props.target;
if (!edgeLabels[relationshipKey]) {
edgeLabels[relationshipKey] = [];
}
edgeLabels[relationshipKey].push(child);
}
});
Object.keys(edgeLabels).forEach(key => {
const children = edgeLabels[key];
const child = children[0];
g.setEdge(child.props.source, child.props.target, {
label: child,
allChildren: children.map(c => c.props.children),
weight: child.props.weight
});
});
dagre.layout(g);
var nodes = g.nodes().map(v => {
var node = g.node(v);
return (
{interpolatingStyle =>
React.cloneElement(node.label, {
x: interpolatingStyle.x + props.dx,
y: interpolatingStyle.y + props.dy
})
}
);
});
var edges = g.edges().map(e => {
var edge = g.edge(e);
let idx = 0;
return (
{
bag[idx + ':x'] = props.isDragging ? point.x : spring(point.x);
bag[idx + ':y'] = props.isDragging ? point.y : spring(point.y);
idx++;
return bag;
}, {})} key={edge.label.key}>
{interpolatedStyle => {
let points = [];
Object.keys(interpolatedStyle).forEach(key => {
const [idx, prop] = key.split(':');
if (!points[idx]) {
points[idx] = { x: props.dx, y: props.dy };
}
points[idx][prop] += interpolatedStyle[key];
});
return React.cloneElement(edge.label, {
points,
id: edge.label.key,
children: edge.allChildren.join(', ')
});
}}
);
});
return (
{edges}
{nodes}
);
}
function Vertex(props) {
return (
);
}
Vertex.isVertex = true;
const strokes = {
alt: 'blue',
child: 'green',
sibling: 'darkgreen',
return: 'red',
fx: 'purple',
progressedChild: 'cyan',
progressedDel: 'brown'
};
function Edge(props) {
var points = props.points;
var path = "M" + points[0].x + " " + points[0].y + " ";
if (!points[0].x || !points[0].y) {
return null;
}
for (var i = 1; i < points.length; i++) {
path += "L" + points[i].x + " " + points[i].y + " ";
if (!points[i].x || !points[i].y) {
return null;
}
}
var lineID = props.id;
return (
);
}
Edge.isEdge = true;
export default function Fibers({ fibers, show, ...rest }) {
const items = Object.keys(fibers.descriptions).map(id =>
fibers.descriptions[id]
);
const isDragging = rest.className.indexOf('dragging') > -1;
const [_, sdx, sdy] = rest.style.transform.match(/translate\((\-?\d+)px,(\-?\d+)px\)/) || [];
const dx = Number(sdx);
const dy = Number(sdy);
return (
{items.map(fiber => [
{fiber.tag} #{fiber.id}
{fiber.type}
Priority: {fiber.pendingWorkPriority} pend, {fiber.progressedPriority} prog
,
fiber.child && show.child &&
child
,
fiber.progressedChild && show.progressedChild &&
pChild
,
fiber.sibling && show.sibling &&
sibling
,
fiber.return && show.return &&
return
,
fiber.nextEffect && show.fx &&
nextFx
,
fiber.firstEffect && show.fx &&
firstFx
,
fiber.lastEffect && show.fx &&
lastFx
,
fiber.progressedFirstDeletion && show.progressedDel &&
pFDel
,
fiber.progressedLastDeletion && show.progressedDel &&
pLDel
,
fiber.alternate && show.alt &&
alt
,
])}
);
}