Skip to content

Commit

Permalink
tidies up code, related to ##286
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyb7 committed Apr 27, 2017
1 parent 9ac0335 commit ed63505
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
28 changes: 15 additions & 13 deletions app/components/view-goal/line-chart-detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import LineChart from './line-chart.jsx';

const defaultWidth = 400;
const animationName = 'scroll';
const animationDuration = 1;

const getAnimationFrame = (name, width, defaultWidth) => `
@keyframes ${name} {
from { margin-left: 0; }
to { margin-left: ${0 - width + defaultWidth}px; }
}
`;

class LineChartDetail extends React.Component {

Expand All @@ -29,13 +37,15 @@ class LineChartDetail extends React.Component {
.scrollLeft += 1000;
this.props.onSelectRating(latestRating.id);
}
}, 1500);
}, (animationDuration * 1000 + 500));
}

render() {

const currentGoal = this.props.currentGoal;

const allRatings = currentGoal.ratings.slice(0).reverse();

const feedbackStyle = {
opacity: currentGoal.ratingSelected
? 1
Expand All @@ -54,16 +64,9 @@ class LineChartDetail extends React.Component {
? currentGoal.ratingSelected.comment
: '';

const animation = `
@keyframes ${animationName} {
from {
margin-left: 0;
}
to {
margin-left: ${0 - this.state.customWidth + defaultWidth}px;
}
}
`;
const animation = getAnimationFrame(
animationName, this.state.width, defaultWidth
);

const stylesheet = document.styleSheets[0];
stylesheet.insertRule(animation, stylesheet.cssRules.length);
Expand All @@ -74,12 +77,11 @@ class LineChartDetail extends React.Component {
width: this.state.customWidth,
animationName: animationName,
animationTimingFunction: 'ease-in-out',
animationDuration: '1s',
animationDuration: `${animationDuration}s`,
marginLeft: 0 - this.state.customWidth + defaultWidth,
};

return (

<div className="line-chart-detail goal-detail-page">
<div className="goal-detail-goal-tile-container">
<GoalTileComponent goal={ currentGoal } />
Expand Down
3 changes: 0 additions & 3 deletions app/components/view-goal/line-chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ const compileData = arr => arr.length
? [0,].concat(getScores(arr)).concat(arr[arr.length - 1].score)
: [];

// const getStyles = (arr, avatar) =>
// ['circle',].concat(Array(arr.length).fill(avatar));

const getStyles = (arr, avatar, selectedIndex) =>
Array(arr.length + 1).fill('circle')
.map((point, index) => index === selectedIndex ? avatar : point);
Expand Down

0 comments on commit ed63505

Please sign in to comment.