Resolve "Chart"
This commit is contained in:
@@ -9,7 +9,7 @@ import { CHART_STROKE_WIDTH, CHART_GRID_LINE_HORIZONTAL_WIDTH } from '../../conf
|
|||||||
const ChartLine = ({ path, isNfpLine }) => {
|
const ChartLine = ({ path, isNfpLine }) => {
|
||||||
const color = isNfpLine ? Colors.orange : Colors.grey
|
const color = isNfpLine ? Colors.orange : Colors.grey
|
||||||
const width = isNfpLine
|
const width = isNfpLine
|
||||||
? CHART_STROKE_WIDTH : CHART_GRID_LINE_HORIZONTAL_WIDTH
|
? CHART_STROKE_WIDTH : CHART_GRID_LINE_HORIZONTAL_WIDTH * 2.5
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Shape d={path} stroke={color} strokeWidth={width} />
|
<Shape d={path} stroke={color} strokeWidth={width} />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { ActivityIndicator, FlatList, StyleSheet, View } from 'react-native'
|
import { ActivityIndicator, FlatList, Dimensions, StyleSheet, View } from 'react-native'
|
||||||
|
|
||||||
import AppLoadingView from '../common/app-loading'
|
import AppLoadingView from '../common/app-loading'
|
||||||
import AppPage from '../common/app-page'
|
import AppPage from '../common/app-page'
|
||||||
@@ -63,10 +63,10 @@ class CycleChart extends Component {
|
|||||||
this.setState({ shouldShowHint: false })
|
this.setState({ shouldShowHint: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
onLayout = ({ nativeEvent }) => {
|
onLayout = () => {
|
||||||
if (this.state.chartHeight) return false
|
if (this.state.chartHeight) return false
|
||||||
|
|
||||||
this.reCalculateChartInfo(nativeEvent)
|
this.reCalculateChartInfo()
|
||||||
this.updateListeners(this.reCalculateChartInfo)
|
this.updateListeners(this.reCalculateChartInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,17 +100,17 @@ class CycleChart extends Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
reCalculateChartInfo = (nativeEvent) => {
|
reCalculateChartInfo = () => {
|
||||||
const { height, width } = nativeEvent.layout
|
const { width, height } = Dimensions.get('window')
|
||||||
|
|
||||||
this.xAxisHeight = height * CHART_XAXIS_HEIGHT_RATIO
|
this.xAxisHeight = height * 0.7 * CHART_XAXIS_HEIGHT_RATIO
|
||||||
const remainingHeight = height - this.xAxisHeight
|
const remainingHeight = height * 0.7 - this.xAxisHeight
|
||||||
this.symptomHeight = remainingHeight * CHART_SYMPTOM_HEIGHT_RATIO
|
this.symptomHeight = remainingHeight * CHART_SYMPTOM_HEIGHT_RATIO
|
||||||
this.symptomRowHeight = this.symptomRowSymptoms.length *
|
this.symptomRowHeight = this.symptomRowSymptoms.length *
|
||||||
this.symptomHeight
|
this.symptomHeight
|
||||||
this.columnHeight = remainingHeight - this.symptomRowHeight
|
this.columnHeight = remainingHeight - this.symptomRowHeight
|
||||||
const chartHeight = this.shouldShowTemperatureColumn ?
|
const chartHeight = this.shouldShowTemperatureColumn ?
|
||||||
height : (this.symptomRowHeight + this.xAxisHeight)
|
height * 0.7 : (this.symptomRowHeight + this.xAxisHeight)
|
||||||
const numberOfColumnsToRender = Math.round(width / CHART_COLUMN_WIDTH)
|
const numberOfColumnsToRender = Math.round(width / CHART_COLUMN_WIDTH)
|
||||||
const columns = makeColumnInfo()
|
const columns = makeColumnInfo()
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,11 @@ class DayColumn extends Component {
|
|||||||
date={dateString}
|
date={dateString}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{ symptomRowSymptoms.map(symptom => {
|
{ symptomRowSymptoms.map((symptom, i) => {
|
||||||
const hasSymptomData = this.data.hasOwnProperty(symptom)
|
const hasSymptomData = this.data.hasOwnProperty(symptom)
|
||||||
return (
|
return (
|
||||||
<SymptomCell
|
<SymptomCell
|
||||||
|
index={i}
|
||||||
key={symptom}
|
key={symptom}
|
||||||
symptom={symptom}
|
symptom={symptom}
|
||||||
symptomValue={hasSymptomData && this.data[symptom]}
|
symptomValue={hasSymptomData && this.data[symptom]}
|
||||||
|
|||||||
@@ -11,13 +11,16 @@ import {
|
|||||||
|
|
||||||
const SymptomCell = ({
|
const SymptomCell = ({
|
||||||
height,
|
height,
|
||||||
|
index,
|
||||||
symptom,
|
symptom,
|
||||||
symptomValue,
|
symptomValue,
|
||||||
isSymptomDataComplete
|
isSymptomDataComplete
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const shouldDrawDot = symptomValue !== false
|
const shouldDrawDot = symptomValue !== false
|
||||||
const styleCell = [styles.cell, { height, width: CHART_COLUMN_WIDTH }]
|
const styleCell = index !== 0
|
||||||
|
? [styles.cell, { height, width: CHART_COLUMN_WIDTH }]
|
||||||
|
: [styles.cell, { height, width: CHART_COLUMN_WIDTH }, styles.topBorder]
|
||||||
let styleDot
|
let styleDot
|
||||||
|
|
||||||
if (shouldDrawDot) {
|
if (shouldDrawDot) {
|
||||||
@@ -40,6 +43,7 @@ const SymptomCell = ({
|
|||||||
|
|
||||||
SymptomCell.propTypes = {
|
SymptomCell.propTypes = {
|
||||||
height: PropTypes.number,
|
height: PropTypes.number,
|
||||||
|
index: PropTypes.number.isRequired,
|
||||||
symptom: PropTypes.string,
|
symptom: PropTypes.string,
|
||||||
symptomValue: PropTypes.oneOfType([
|
symptomValue: PropTypes.oneOfType([
|
||||||
PropTypes.bool,
|
PropTypes.bool,
|
||||||
@@ -51,10 +55,16 @@ SymptomCell.propTypes = {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
cell: {
|
cell: {
|
||||||
backgroundColor: 'white',
|
backgroundColor: 'white',
|
||||||
borderColor: Colors.greyLight,
|
borderBottomColor: Colors.grey,
|
||||||
borderWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
|
borderBottomWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
|
||||||
|
borderLeftColor: Colors.grey,
|
||||||
|
borderLeftWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
|
||||||
...Containers.centerItems
|
...Containers.centerItems
|
||||||
},
|
},
|
||||||
|
topBorder: {
|
||||||
|
borderTopColor: Colors.grey,
|
||||||
|
borderTopWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
|
||||||
|
},
|
||||||
dot: {
|
dot: {
|
||||||
width: CHART_DOT_RADIUS * 2,
|
width: CHART_DOT_RADIUS * 2,
|
||||||
height: CHART_DOT_RADIUS * 2,
|
height: CHART_DOT_RADIUS * 2,
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export const CHART_DOT_RADIUS = 6
|
|||||||
export const CHART_GRID_LINE_HORIZONTAL_WIDTH = 0.3
|
export const CHART_GRID_LINE_HORIZONTAL_WIDTH = 0.3
|
||||||
export const CHART_ICON_SIZE = 20
|
export const CHART_ICON_SIZE = 20
|
||||||
export const CHART_STROKE_WIDTH = 3
|
export const CHART_STROKE_WIDTH = 3
|
||||||
export const CHART_SYMPTOM_HEIGHT_RATIO = 0.1
|
export const CHART_SYMPTOM_HEIGHT_RATIO = 0.08
|
||||||
export const CHART_XAXIS_HEIGHT_RATIO = 0.14
|
export const CHART_XAXIS_HEIGHT_RATIO = 0.1
|
||||||
export const CHART_YAXIS_WIDTH = 32
|
export const CHART_YAXIS_WIDTH = 32
|
||||||
|
|
||||||
export const TEMP_SCALE_MAX = 38
|
export const TEMP_SCALE_MAX = 38
|
||||||
|
|||||||
Reference in New Issue
Block a user