Skip to content

Commit

Permalink
Fixed time estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
christos-h committed Feb 24, 2020
1 parent a4decca commit 590ad93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/components/node-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import * as React from 'react';
import GraphUtils from '../utilities/graph-util';
import { type INode } from './node';
import {Status} from '../components/node';

type INodeTextProps = {
data: INode,
Expand All @@ -37,10 +38,10 @@ class NodeText extends React.Component<INodeTextProps> {
}
}

completionDateIn(days) {
completionDateIn(days, status) {
let today = new Date();
let endDate = "", count = 0;
if(days === 0) return today;
if(days === 0 || status === Status.done) return today;
while(count < days) {
endDate = new Date(today.setDate(today.getDate() + 1));
if (endDate.getDay() !== 0 && endDate.getDay() !== 6) {
Expand All @@ -57,7 +58,7 @@ class NodeText extends React.Component<INodeTextProps> {
const title = data.title;
const description = data.description;
const timeEstimate = data.timeEstimate;
const completionDate = this.completionDateIn(data.totalTimeEstimate);
const completionDate = this.completionDateIn(data.totalTimeEstimate, data.status);
let formatted_date = completionDate.getFullYear() + "-" + (completionDate.getMonth() + 1) + "-" + completionDate.getDate()

const className = GraphUtils.classNames('node-text', {
Expand Down
7 changes: 5 additions & 2 deletions src/examples/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as React from 'react';

import {GraphView, type IEdgeType as IEdge, type INodeType as INode, type LayoutEngineType,} from '../';
import GraphConfig, {EMPTY_EDGE_TYPE, EMPTY_TYPE, NODE_KEY,} from './graph-config';
import Node, {Status} from '../components/node';
import {Status} from '../components/node';


type IGraph = {
Expand Down Expand Up @@ -207,6 +207,8 @@ class Graph extends React.Component<IGraphProps, IGraphState> {
this.setState({graph, selected: null}, this.redrawAndSave());
};



calculateDateEstimates() {
// We estimate the predicted time of completion of root nodes,
// By summing the time of their dependencies recursively.
Expand Down Expand Up @@ -257,7 +259,7 @@ class Graph extends React.Component<IGraphProps, IGraphState> {
}

updateTotalTimeEstimate(node, graph) {
if (node === undefined || node.status === 'Done') return 0;
if (node === undefined || node.status === Status.done) return 0;
// Update the total time estimates for a node recursively
node.totalTimeEstimate = parseFloat(node.timeEstimate);

Expand Down Expand Up @@ -390,6 +392,7 @@ class Graph extends React.Component<IGraphProps, IGraphState> {
this.forceUpdate();
};


redrawAndSave = () => {
this.calculateDateEstimates();

Expand Down

0 comments on commit 590ad93

Please sign in to comment.