Skip to content

Instantly share code, notes, and snippets.

@MaksimAbramchuk
Created September 5, 2017 19:43
Show Gist options
  • Save MaksimAbramchuk/b1ba234d6f1f605fe439c363ca19f94f to your computer and use it in GitHub Desktop.
Save MaksimAbramchuk/b1ba234d6f1f605fe439c363ca19f94f to your computer and use it in GitHub Desktop.
renderAllStoryBlocks() {
const blocksTree = arrayToTree(this.state.stories, {parentProperty: 'parentId'});
blocksTree.forEach((story, index) => {
this.renderStoryBlock(story, index, 0, window.innerHeight);
});
}
renderStoryBlock(story, index, left, right) {
const position = (left + right) / 2;
const coords = {
X: 300 * index,
Y: position,
};
const storyBlock = <StoryBlock
rectY={coords.Y}
rectX={coords.X}
/>;
this.storyBlocks.push(storyBlock);
const dif = right - left;
if (story.children && story.children.length > 0) {
const x = dif / story.children.length / 2;
story.children.forEach((child, childNumber) => {
const position2 = left + (x + x * 2 * childNumber)
this.renderStoryBlock(child, index + 1, position2 - x, position2 + x)
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment