Skip to content

Commit

Permalink
(FIX) Progress percent when url has year param
Browse files Browse the repository at this point in the history
  • Loading branch information
elstr committed Feb 20, 2018
1 parent 3f5d97f commit 7d7b9bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The chart should have these features:


## Pending:
[ ] (FIX) When url has year param, calculate the progress percent and render progress bar from there
[ X ] (FIX) When url has year param, calculate the progress percent and render progress bar from there

[ ] Make progress bar responsive

Expand Down
15 changes: 14 additions & 1 deletion src/Components/Chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,29 @@ class Chart extends Component {
}
}

calculateProgress(yearFrom) {
const {minYear, progress} = this.state
/* Need to use a correction value + 1
* To solve 2001 - 2000 = 1 => 16,66% and should be 33,2%,
* Minimum year should be minimum percent (the result of percentPerYear), 2000 should be 16,66% */
const value = yearFrom - minYear + 1
return value > 0 ? value * progress : progress
}

componentWillMount() {
const {minYear} = this.state
const {paused, year} = qs.parse(this.props.location.search)

const yearFrom = validateYear(year, minYear)

const progress = this.calculateProgress(yearFrom)

console.log(progress)

/* Paused is a string. If paused is true, set Boolean value true, else set Boolean value false */
const isPaused = paused ? getParamValue(paused) === 'true' : false

this.setState({yearFrom, isPaused})
this.setState({yearFrom, isPaused, progress})
}

componentDidMount() {
Expand Down

0 comments on commit 7d7b9bd

Please sign in to comment.