Skip to content

Commit

Permalink
API calls and adding Positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
luizguilhermesj committed Aug 24, 2018
1 parent 38b581e commit 62da546
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
20 changes: 5 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class App extends Component {

componentWillMount() {
this.fetchEntity()
.then(root => this.hydrateEntities(root))
.then(root => this.hydrateObjectives(root))
.then(root => Positioning.tree(root));
.then(root => Positioning.tree(root))
.then(root => this.hydrateObjectives(root));
}

fetchEntity() {
Expand All @@ -35,27 +34,18 @@ class App extends Component {
return fetch("https://okr.r3connect.me/api/entities/the-iconic/objectives").then(res => res.json()).then(res => res.data);
}

hydrateEntities(root) {
root.children = root.child_entities || [];

if (! root.child_entities) return root;

root.child_entities.forEach(this.hydrateEntities);

return root;
}

hydrateObjectives(root) {
return this.fetchEntityObjectives()
.then(objectives => objectives.map(objective => root.objective = objective))
.then(objectives => this.setState({ root: root }));
.then(objectives => this.setState({ root: root }))
.then(e => root);
}

render() {
const { root } = this.state;

if (!root) {
return <div />
return null;
}

return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ class Container extends Component {
label: root.name,
type: root.name,
depth: depth,
position: root.position
});

root.children.forEach(child => this.hydrateNodes(child, nodeId, depth + 1));
if (! root.child_entities) root.child_entities = [];
root.child_entities.forEach(child => this.hydrateNodes(child, nodeId, depth + 1));
}

getEdges(depthMap = null) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Viewport extends Component {
createNodesForDom() {
const domNodes = [];
const { depthMap, edges } = this.props;

console.log(this.props);
const rows = {};

Object.keys(depthMap).forEach(depth => {
Expand Down
36 changes: 36 additions & 0 deletions src/services/Positioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const DEFAULTS = {
canvas: {
height: 1000,
width: 1000
},
nodes: {
width: 100,
height: 100,
}
}

class Positioning {

updateTreePosition(root, levelNodesCount = 1) {
let nodes_width = DEFAULTS.nodes.width * levelNodesCount;
let in_between = Math.floor((DEFAULTS.canvas.height - nodes_width) / levelNodesCount);

root.position = {
width: DEFAULTS.nodes.width,
in_between: in_between
}

if (! root.child_entities) return root;

levelNodesCount = root.child_entities.length;
root.child_entities.forEach(child => this.updateTreePosition(child, levelNodesCount));

return root;
}

tree(root) {
return this.updateTreePosition(root);
}
}

export default new Positioning();

0 comments on commit 62da546

Please sign in to comment.