Prettify chart files

This commit is contained in:
Sofiya Tepikin
2022-08-23 12:52:38 +02:00
parent f72994082c
commit 732f19ed63
8 changed files with 67 additions and 73 deletions
+4 -4
View File
@@ -18,21 +18,21 @@ const ChartLegend = ({ height }) => {
} }
ChartLegend.propTypes = { ChartLegend.propTypes = {
height: PropTypes.number.isRequired height: PropTypes.number.isRequired,
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
alignItems: 'center', alignItems: 'center',
justifyContent: 'flex-end', justifyContent: 'flex-end',
width: CHART_YAXIS_WIDTH width: CHART_YAXIS_WIDTH,
}, },
text: { text: {
...Typography.label, ...Typography.label,
}, },
textBold: { textBold: {
...Typography.labelBold ...Typography.labelBold,
} },
}) })
export default ChartLegend export default ChartLegend
+10 -9
View File
@@ -5,18 +5,19 @@ import { StyleSheet, View } from 'react-native'
import { getTickPositions } from '../helpers/chart' import { getTickPositions } from '../helpers/chart'
import { Colors } from '../../styles' import { Colors } from '../../styles'
import { CHART_GRID_LINE_HORIZONTAL_WIDTH, CHART_YAXIS_WIDTH } from '../../config' import {
CHART_GRID_LINE_HORIZONTAL_WIDTH,
CHART_YAXIS_WIDTH,
} from '../../config'
const HorizontalGrid = ({ height }) => { const HorizontalGrid = ({ height }) => {
return getTickPositions(height).map(tick => { return getTickPositions(height).map((tick) => {
return ( return <View key={tick} top={tick} {...styles.line} />
<View key={tick} top={tick} {...styles.line}/>
)
}) })
} }
HorizontalGrid.propTypes = { HorizontalGrid.propTypes = {
height: PropTypes.number height: PropTypes.number,
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@@ -25,9 +26,9 @@ const styles = StyleSheet.create({
borderBottomColor: Colors.grey, borderBottomColor: Colors.grey,
borderBottomWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH, borderBottomWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
left: CHART_YAXIS_WIDTH, left: CHART_YAXIS_WIDTH,
position:'absolute', position: 'absolute',
right: 0 right: 0,
} },
}) })
export default HorizontalGrid export default HorizontalGrid
+12 -15
View File
@@ -6,7 +6,7 @@ import { Colors, Containers } from '../../styles'
import { import {
CHART_COLUMN_WIDTH, CHART_COLUMN_WIDTH,
CHART_DOT_RADIUS, CHART_DOT_RADIUS,
CHART_GRID_LINE_HORIZONTAL_WIDTH CHART_GRID_LINE_HORIZONTAL_WIDTH,
} from '../../config' } from '../../config'
const SymptomCell = ({ const SymptomCell = ({
@@ -14,11 +14,11 @@ const SymptomCell = ({
index, index,
symptom, symptom,
symptomValue, symptomValue,
isSymptomDataComplete isSymptomDataComplete,
}) => { }) => {
const shouldDrawDot = symptomValue !== false const shouldDrawDot = symptomValue !== false
const styleCell = index !== 0 const styleCell =
index !== 0
? [styles.cell, { height, width: CHART_COLUMN_WIDTH }] ? [styles.cell, { height, width: CHART_COLUMN_WIDTH }]
: [styles.cell, { height, width: CHART_COLUMN_WIDTH }, styles.topBorder] : [styles.cell, { height, width: CHART_COLUMN_WIDTH }, styles.topBorder]
let styleDot let styleDot
@@ -26,10 +26,10 @@ const SymptomCell = ({
if (shouldDrawDot) { if (shouldDrawDot) {
const styleSymptom = Colors.iconColors[symptom] const styleSymptom = Colors.iconColors[symptom]
const symptomColor = styleSymptom.shades[symptomValue] const symptomColor = styleSymptom.shades[symptomValue]
const isMucusOrCervix = (symptom === 'mucus') || (symptom === 'cervix') const isMucusOrCervix = symptom === 'mucus' || symptom === 'cervix'
const backgroundColor = (isMucusOrCervix && !isSymptomDataComplete) ? const backgroundColor =
'white' : symptomColor isMucusOrCervix && !isSymptomDataComplete ? 'white' : symptomColor
const borderWidth = (isMucusOrCervix && !isSymptomDataComplete) ? 2 : 0 const borderWidth = isMucusOrCervix && !isSymptomDataComplete ? 2 : 0
const borderColor = symptomColor const borderColor = symptomColor
styleDot = [styles.dot, { backgroundColor, borderColor, borderWidth }] styleDot = [styles.dot, { backgroundColor, borderColor, borderWidth }]
} }
@@ -45,10 +45,7 @@ SymptomCell.propTypes = {
height: PropTypes.number, height: PropTypes.number,
index: PropTypes.number.isRequired, index: PropTypes.number.isRequired,
symptom: PropTypes.string, symptom: PropTypes.string,
symptomValue: PropTypes.oneOfType([ symptomValue: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
PropTypes.bool,
PropTypes.number,
]),
isSymptomDataComplete: PropTypes.bool, isSymptomDataComplete: PropTypes.bool,
} }
@@ -59,7 +56,7 @@ const styles = StyleSheet.create({
borderBottomWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH, borderBottomWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
borderLeftColor: Colors.grey, borderLeftColor: Colors.grey,
borderLeftWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH, borderLeftWidth: CHART_GRID_LINE_HORIZONTAL_WIDTH,
...Containers.centerItems ...Containers.centerItems,
}, },
topBorder: { topBorder: {
borderTopColor: Colors.grey, borderTopColor: Colors.grey,
@@ -68,7 +65,7 @@ const styles = StyleSheet.create({
dot: { dot: {
width: CHART_DOT_RADIUS * 2, width: CHART_DOT_RADIUS * 2,
height: CHART_DOT_RADIUS * 2, height: CHART_DOT_RADIUS * 2,
borderRadius: 50 borderRadius: 50,
} },
}) })
export default SymptomCell export default SymptomCell
+3 -3
View File
@@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { StyleSheet , View } from 'react-native' import { StyleSheet, View } from 'react-native'
import DripIcon from '../../assets/drip-icons' import DripIcon from '../../assets/drip-icons'
@@ -26,8 +26,8 @@ SymptomIcon.propTypes = {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
...Containers.centerItems ...Containers.centerItems,
} },
}) })
export default SymptomIcon export default SymptomIcon
+5 -7
View File
@@ -7,12 +7,10 @@ import Tick from './tick'
import { getTickList } from '../helpers/chart' import { getTickList } from '../helpers/chart'
const TickList = ({ height }) => { const TickList = ({ height }) => {
return ( return (
<View style={[styles.container, height]}> <View style={[styles.container, height]}>
{ {getTickList(height).map(
getTickList(height) ({ isBold, label, position, shouldShowLabel, tickHeight }) => {
.map(({ isBold, label, position, shouldShowLabel, tickHeight}) => {
return ( return (
<Tick <Tick
height={tickHeight} height={tickHeight}
@@ -23,8 +21,8 @@ const TickList = ({ height }) => {
yPosition={position} yPosition={position}
/> />
) )
})
} }
)}
</View> </View>
) )
} }
@@ -35,8 +33,8 @@ TickList.propTypes = {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1 flex: 1,
} },
}) })
export default TickList export default TickList
+6 -7
View File
@@ -9,10 +9,10 @@ import { CHART_TICK_WIDTH } from '../../config'
const Tick = ({ yPosition, height, isBold, shouldShowLabel, label }) => { const Tick = ({ yPosition, height, isBold, shouldShowLabel, label }) => {
const top = yPosition - height / 2 const top = yPosition - height / 2
const containerStyle = [ styles.container, { flexBasis: height, height, top }] const containerStyle = [styles.container, { flexBasis: height, height, top }]
const textStyle = isBold ? styles.textBold : styles.textNormal const textStyle = isBold ? styles.textBold : styles.textNormal
return( return (
<View style={containerStyle}> <View style={containerStyle}>
<AppText style={textStyle}>{shouldShowLabel && label}</AppText> <AppText style={textStyle}>{shouldShowLabel && label}</AppText>
</View> </View>
@@ -27,7 +27,6 @@ Tick.propTypes = {
label: PropTypes.string, label: PropTypes.string,
} }
const text = { const text = {
textAlign: 'right', textAlign: 'right',
} }
@@ -36,17 +35,17 @@ const styles = StyleSheet.create({
justifyContent: 'center', justifyContent: 'center',
position: 'absolute', position: 'absolute',
right: 0, right: 0,
width: CHART_TICK_WIDTH width: CHART_TICK_WIDTH,
}, },
textBold: { textBold: {
fontSize: Sizes.base, fontSize: Sizes.base,
fontWeight: 'bold', fontWeight: 'bold',
...text ...text,
}, },
textNormal: { textNormal: {
fontSize: Sizes.small, fontSize: Sizes.small,
...text ...text,
} },
}) })
export default Tick export default Tick
+6 -6
View File
@@ -13,7 +13,7 @@ const image = require('../../assets/swipe.png')
const Tutorial = ({ onClose }) => { const Tutorial = ({ onClose }) => {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Image resizeMode='contain' source={image} style={styles.image} /> <Image resizeMode="contain" source={image} style={styles.image} />
<View style={styles.textContainer}> <View style={styles.textContainer}>
<AppText>{chart.tutorial}</AppText> <AppText>{chart.tutorial}</AppText>
</View> </View>
@@ -23,20 +23,20 @@ const Tutorial = ({ onClose }) => {
} }
Tutorial.propTypes = { Tutorial.propTypes = {
onClose: PropTypes.func.isRequired onClose: PropTypes.func.isRequired,
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
...Containers.rowContainer, ...Containers.rowContainer,
padding: Spacing.large padding: Spacing.large,
}, },
image: { image: {
height: 40 height: 40,
}, },
textContainer: { textContainer: {
width: '70%' width: '70%',
} },
}) })
export default Tutorial export default Tutorial
+7 -8
View File
@@ -13,7 +13,7 @@ const YAxis = ({
symptomsToDisplay, symptomsToDisplay,
symptomsSectionHeight, symptomsSectionHeight,
shouldShowTemperatureColumn, shouldShowTemperatureColumn,
xAxisHeight xAxisHeight,
}) => { }) => {
const symptomIconHeight = symptomsSectionHeight / symptomsToDisplay.length const symptomIconHeight = symptomsSectionHeight / symptomsToDisplay.length
@@ -21,15 +21,14 @@ const YAxis = ({
<View> <View>
{shouldShowTemperatureColumn && <TickList height={height} />} {shouldShowTemperatureColumn && <TickList height={height} />}
<ChartLegend height={xAxisHeight} /> <ChartLegend height={xAxisHeight} />
<View style={[styles.yAxis, {height: symptomsSectionHeight}]}> <View style={[styles.yAxis, { height: symptomsSectionHeight }]}>
{symptomsToDisplay.map(symptom => ( {symptomsToDisplay.map((symptom) => (
<SymptomIcon <SymptomIcon
key={symptom} key={symptom}
symptom={symptom} symptom={symptom}
height={symptomIconHeight} height={symptomIconHeight}
/> />
) ))}
)}
</View> </View>
</View> </View>
) )
@@ -40,13 +39,13 @@ YAxis.propTypes = {
symptomsToDisplay: PropTypes.array, symptomsToDisplay: PropTypes.array,
symptomsSectionHeight: PropTypes.number, symptomsSectionHeight: PropTypes.number,
shouldShowTemperatureColumn: PropTypes.bool, shouldShowTemperatureColumn: PropTypes.bool,
xAxisHeight: PropTypes.number.isRequired xAxisHeight: PropTypes.number.isRequired,
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
yAxis: { yAxis: {
width: CHART_YAXIS_WIDTH width: CHART_YAXIS_WIDTH,
} },
}) })
export default YAxis export default YAxis