Created
September 5, 2017 19:43
-
-
Save MaksimAbramchuk/b1ba234d6f1f605fe439c363ca19f94f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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