diff --git a/src/components/periods/Timeline.js b/src/components/periods/Timeline.js
index 62c2a22d1..65138bad4 100644
--- a/src/components/periods/Timeline.js
+++ b/src/components/periods/Timeline.js
@@ -8,61 +8,56 @@ import {
getPeriodTypeFromId,
getPeriodLevelFromPeriodType,
} from '../../util/periods.js'
+import { doubleTicksPeriods } from '../../constants/periods.js'
import timeTicks from '../../util/timeTicks.js'
import styles from './styles/Timeline.module.css'
-const paddingLeft = 40
-const paddingRight = 20
-const labelWidth = 80
-const delay = 1500
-const playBtn =
-const pauseBtn =
-const doubleTicksPeriods = ['LAST_6_BIMONTHS', 'BIMONTHS_THIS_YEAR']
-const rectHeight = 7
-const rectOffset = 10
-
-const addPeriodTypeAndLevel = (item) => {
- item.type = getPeriodTypeFromId(item.id)
- item.level = getPeriodLevelFromPeriodType(item.type)
- return item
+// Constants
+const PADDING_LEFT = 40
+const PADDING_RIGHT = 20
+const LABEL_WIDTH = 80
+const RECT_HEIGHT = 8
+const RECT_OFFSET = 8
+const DELAY = 1500
+const PLAY_ICON =
+const PAUSE_ICON =
+
+// Utility Functions
+const addPeriodDetails = (period) => {
+ const type = getPeriodTypeFromId(period.id)
+ const level = getPeriodLevelFromPeriodType(type)
+ return { ...period, type, level }
}
-const listLevelsFromPeriods = (periodsWithType) => [
- ...new Set(periodsWithType.map((item) => item.level)),
+const getUniqueLevels = (periodsWithLevel) => [
+ ...new Set(periodsWithLevel.map((item) => item.level)),
]
const countUniqueRanks = (periods) => {
- const periodsWithType = periods.map((item) => addPeriodTypeAndLevel(item))
- return listLevelsFromPeriods(periodsWithType).length
+ const periodsWithDetails = periods.map(addPeriodDetails)
+ return getUniqueLevels(periodsWithDetails).length
}
const sortPeriodsByLevelRank = (periods) => {
- let periodsWithDetails
- periodsWithDetails = periods.map((item) => addPeriodTypeAndLevel(item))
-
- const sortedLevels = listLevelsFromPeriods(periodsWithDetails).sort(
+ const periodsWithDetails = periods.map(addPeriodDetails)
+ const sortedLevels = getUniqueLevels(periodsWithDetails).sort(
(a, b) => b - a
)
- periodsWithDetails = periodsWithDetails.map((item) => ({
- ...item,
- levelRank: sortedLevels.indexOf(item.level),
- }))
-
- const sortedPeriods = periodsWithDetails.sort(
- (a, b) => a.levelRank - b.levelRank
- )
- return sortedPeriods
+ return periodsWithDetails
+ .map((item) => ({
+ ...item,
+ levelRank: sortedLevels.indexOf(item.level),
+ }))
+ .sort((a, b) => a.levelRank - b.levelRank)
}
-const sortPeriodsByLevelAndStartDate = (periods) => {
- let sortedPeriods
- sortedPeriods = periods.sort((a, b) => b.level - a.level)
- sortedPeriods = periods.sort(
- (a, b) => new Date(a.startDate) - new Date(b.startDate)
- )
- return sortedPeriods
-}
+const sortPeriodsByLevelAndStartDate = (periods) =>
+ periods
+ .map(addPeriodDetails)
+ .sort((a, b) => b.level - a.level)
+ .sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
+// Timeline Component
class Timeline extends Component {
static contextTypes = {
map: PropTypes.object,
@@ -98,7 +93,7 @@ class Timeline extends Component {
const uniqueRanks = countUniqueRanks(this.props.periods)
this.setTimeScale()
- const rectTotalHeight = rectHeight + (uniqueRanks - 1) * rectOffset
+ const rectTotalHeight = RECT_HEIGHT + (uniqueRanks - 1) * RECT_OFFSET
return (