Skip to content
Snippets Groups Projects
Commit 71e4c6d1 authored by mashazyu's avatar mashazyu
Browse files

Introduces ChartLine component

parent 03a235d8
No related branches found
No related tags found
No related merge requests found
import React from 'react'
import PropTypes from 'prop-types'
import { Shape } from 'react-native/Libraries/ART/ReactNativeART'
import styles from './styles'
const ChartLine = ({ path, isNfpLine = false }) => {
const strokeStyle =
isNfpLine ? styles.nfpLine.stroke : styles.column.stroke.color
const strokeWidth =
isNfpLine ? styles.nfpLine.strokeWidth : styles.column.stroke.width
return (
<Shape
stroke={strokeStyle}
strokeWidth={strokeWidth}
d={path}
/>
)
}
ChartLine.propTypes = {
path: PropTypes.object,
isNfpLine: PropTypes.bool,
}
export default ChartLine
...@@ -4,9 +4,7 @@ import { ...@@ -4,9 +4,7 @@ import {
} from 'react-native' } from 'react-native'
import { import {
Surface, Surface,
Group as G, Path
Path,
Shape
} from 'react-native/Libraries/ART/ReactNativeART' } from 'react-native/Libraries/ART/ReactNativeART'
import { connect } from 'react-redux' import { connect } from 'react-redux'
...@@ -21,6 +19,7 @@ import { getCycleDay } from '../../db' ...@@ -21,6 +19,7 @@ import { getCycleDay } from '../../db'
import DotAndLine from './dot-and-line' import DotAndLine from './dot-and-line'
import SymptomCell from './symptom-cell' import SymptomCell from './symptom-cell'
import ChartLine from './chart-line'
import { normalizeToScale } from '../helpers/chart' import { normalizeToScale } from '../helpers/chart'
...@@ -151,13 +150,12 @@ class DayColumn extends Component { ...@@ -151,13 +150,12 @@ class DayColumn extends Component {
xAxisHeight } = this.props xAxisHeight } = this.props
if(this.fhmAndLtl.drawLtlAt) { if(this.fhmAndLtl.drawLtlAt) {
const ltlLine = (<Shape const ltlLine = (<ChartLine
stroke={styles.nfpLine.stroke} path={new Path()
strokeWidth={styles.nfpLine.strokeWidth}
d={new Path()
.moveTo(0, this.fhmAndLtl.drawLtlAt) .moveTo(0, this.fhmAndLtl.drawLtlAt)
.lineTo(config.columnWidth, this.fhmAndLtl.drawLtlAt) .lineTo(config.columnWidth, this.fhmAndLtl.drawLtlAt)
} }
isNfpLine={true}
key='ltl' key='ltl'
/>) />)
columnElements.push(ltlLine) columnElements.push(ltlLine)
...@@ -165,11 +163,9 @@ class DayColumn extends Component { ...@@ -165,11 +163,9 @@ class DayColumn extends Component {
if (this.fhmAndLtl.drawFhmLine) { if (this.fhmAndLtl.drawFhmLine) {
const x = styles.nfpLine.strokeWidth / 2 const x = styles.nfpLine.strokeWidth / 2
const fhmLine = (<Shape const fhmLine = (<ChartLine
fill="red" path={new Path().moveTo(x, x).lineTo(x, columnHeight)}
stroke={styles.nfpLine.stroke} isNfpLine={true}
strokeWidth={styles.nfpLine.strokeWidth}
d={new Path().moveTo(x, x).lineTo(x, columnHeight)}
key='fhm' key='fhm'
/>) />)
columnElements.push(fhmLine) columnElements.push(fhmLine)
...@@ -215,17 +211,6 @@ class DayColumn extends Component { ...@@ -215,17 +211,6 @@ class DayColumn extends Component {
</Text> </Text>
) )
const column = (
<G>
<Shape
stroke={styles.column.stroke.color}
strokeWidth={styles.column.stroke.width}
d={new Path().lineTo(0, chartHeight)}
/>
{ columnElements }
</G>
)
return ( return (
<TouchableOpacity <TouchableOpacity
onPress={() => this.onDaySelect(dateString)} onPress={() => this.onDaySelect(dateString)}
...@@ -248,7 +233,10 @@ class DayColumn extends Component { ...@@ -248,7 +233,10 @@ class DayColumn extends Component {
)} )}
<Surface width={config.columnWidth} height={columnHeight}> <Surface width={config.columnWidth} height={columnHeight}>
{column} <ChartLine
path={new Path().lineTo(0, chartHeight)}
/>
{ columnElements }
</Surface> </Surface>
<View style={{height: xAxisHeight}}> <View style={{height: xAxisHeight}}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment