diff --git a/components/chart.js b/components/chart.js
index e1d1f00..cf8a0da 100644
--- a/components/chart.js
+++ b/components/chart.js
@@ -11,45 +11,30 @@ import Svg,{
import { LocalDate } from 'js-joda'
import { getCycleDay, getOrCreateCycleDay, cycleDaysSortedByDate } from '../db'
import getCycleDayNumberModule from '../get-cycle-day-number'
+import styles from './styles'
+import config from './config'
const getCycleDayNumber = getCycleDayNumberModule()
-const chartLength = 350
-const columnWidth = 30
-const middle = columnWidth / 2
-const xAxis = {
- top: chartLength - 15,
- margin: 3
-}
-const dateRowY = xAxis.top - xAxis.margin
-const cycleDayNumberRowY = chartLength - xAxis.margin
-
-const temperatureScale = {
- low: 33,
- high: 40
-}
-const cycleDaysToShow = 40
-const dotRadius = 4
-const curveColor = 'darkblue'
export default class CycleChart extends Component {
constructor(props) {
super(props)
this.state = {
- columns: makeColumnInfo(cycleDaysToShow)
+ columns: makeColumnInfo(config.cycleDaysToShow)
}
- this.recalculateChartInfo = (function(Chart) {
+ this.reCalculateChartInfo = (function(Chart) {
return function() {
- Chart.setState({columns: makeColumnInfo(cycleDaysToShow)})
+ Chart.setState({columns: makeColumnInfo(config.cycleDaysToShow)})
}
})(this)
- cycleDaysSortedByDate.addListener(this.recalculateChartInfo)
+ cycleDaysSortedByDate.addListener(this.reCalculateChartInfo)
}
componentWillUnmount() {
- cycleDaysSortedByDate.removeListener(this.recalculateChartInfo)
+ cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
}
passDateToDayView(dateString) {
@@ -59,36 +44,23 @@ export default class CycleChart extends Component {
makeDayColumn({ dateString, cycleDay, y }, index) {
const cycleDayNumber = getCycleDayNumber(dateString)
- const labelProps = {
- stroke: "grey",
- fontSize: "10",
- x: 0,
- }
-
+ const labelProps = styles.column.label
const dateLabel = dateString.split('-').slice(1).join('-')
return (
this.passDateToDayView(dateString)}>
-
- {cycleDayNumber}
- {dateLabel}
+
+ {cycleDayNumber}
+ {dateLabel}
- {cycleDay && cycleDay.bleeding ? : null}
+ {cycleDay && cycleDay.bleeding ? : null}
- {y ? this.drawDotAndLine(y, index) : null}
+ {y ? this.drawDotAndLines(y, index) : null}
)
}
- drawDotAndLine(currY, index) {
+ drawDotAndLines(currY, index) {
let lineToRight
let lineToLeft
const cols = this.state.columns
@@ -97,12 +69,11 @@ export default class CycleChart extends Component {
const middleY = ((otherColY - currY) / 2) + currY
const rightTarget = [x, middleY]
return
}
@@ -110,7 +81,7 @@ export default class CycleChart extends Component {
const thereIsADotToTheLeft = index < cols.length - 1 && cols[index + 1].y
if (thereIsADotToTheRight) {
- lineToRight = makeLine(cols[index - 1].y, columnWidth)
+ lineToRight = makeLine(cols[index - 1].y, config.columnWidth)
}
if (thereIsADotToTheLeft) {
lineToLeft = makeLine(cols[index + 1].y, 0)
@@ -118,10 +89,9 @@ export default class CycleChart extends Component {
return (
{lineToRight}
{lineToLeft}
@@ -136,7 +106,7 @@ export default class CycleChart extends Component {
data={this.state.columns}
renderItem={({item, index}) => {
return (
-