Add first version of y axis

This commit is contained in:
Julia Friesel
2018-06-26 01:37:00 +02:00
parent c01760aa3e
commit d1759b0cff
3 changed files with 52 additions and 20 deletions
+43 -16
View File
@@ -1,5 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { FlatList } from 'react-native' import { View, FlatList } from 'react-native'
import range from 'date-range' import range from 'date-range'
import Svg,{ import Svg,{
G, G,
@@ -112,22 +112,49 @@ export default class CycleChart extends Component {
</G>) </G>)
} }
placeTicksForYAxis() {
const scaleMin = config.temperatureScale.low
const scaleMax = config.temperatureScale.high
const numberOfTicks = (scaleMax - scaleMin) * 2
const tickDistance = config.chartHeight / numberOfTicks
const ticks = []
const labelStyle = styles.column.label.date
for (let i = 0; i < numberOfTicks; i++) {
const y = tickDistance * i
ticks.push(
<G key={i}>
<Line
x1={18} y1={y} x2={22} y2={y}
{...styles.yAxis}
/>
<Text {...labelStyle} y={y}>{scaleMax - i * 0.5}</Text>
</G>
)
}
return ticks
}
render() { render() {
return ( return (
<FlatList <View style={{flex: 1, flexDirection: 'row'}}>
horizontal={true} <Svg {...styles.yAxis}>
inverted={true} {this.placeTicksForYAxis()}
data={this.state.columns} </Svg>
renderItem={({item, index}) => { <FlatList
return ( horizontal={true}
<Svg width={config.columnWidth} height={config.chartLength}> inverted={true}
{this.makeDayColumn(item, index)} data={this.state.columns}
</Svg> renderItem={({ item, index }) => {
) return (
}} <Svg width={config.columnWidth} height={config.chartHeight}>
keyExtractor={item => item.dateString} {this.makeDayColumn(item, index)}
> </Svg>
</FlatList> )
}}
keyExtractor={item => item.dateString}
>
</FlatList>
</View>
) )
} }
} }
@@ -163,6 +190,6 @@ function getPreviousDays(n) {
function normalizeToScale(temp) { function normalizeToScale(temp) {
const temperatureScale = config.temperatureScale const temperatureScale = config.temperatureScale
const valueRelativeToScale = (temperatureScale.high - temp) / (temperatureScale.high - temperatureScale.low) const valueRelativeToScale = (temperatureScale.high - temp) / (temperatureScale.high - temperatureScale.low)
const scaleHeight = config.chartLength const scaleHeight = config.chartHeight
return scaleHeight * valueRelativeToScale return scaleHeight * valueRelativeToScale
} }
+3 -3
View File
@@ -1,5 +1,5 @@
const config = { const config = {
chartLength: 350, chartHeight: 350,
columnWidth: 30, columnWidth: 30,
temperatureScale: { temperatureScale: {
low: 33, low: 33,
@@ -10,7 +10,7 @@ const config = {
const margin = 3 const margin = 3
config.columnMiddle = config.columnWidth / 2, config.columnMiddle = config.columnWidth / 2,
config.dateRowY = config.chartLength - 15 - margin config.dateRowY = config.chartHeight - 15 - margin
config.cycleDayNumberRowY = config.chartLength - margin config.cycleDayNumberRowY = config.chartHeight - margin
export default config export default config
+6 -1
View File
@@ -38,7 +38,7 @@ const styles = {
x: 0, x: 0,
y: 0, y: 0,
width: config.columnWidth, width: config.columnWidth,
height: config.chartLength height: config.chartHeight
} }
}, },
bleedingIcon: { bleedingIcon: {
@@ -46,6 +46,11 @@ const styles = {
scale: 0.6, scale: 0.6,
x: 7, x: 7,
y: 3 y: 3
},
yAxis: {
height: config.chartHeight,
width: config.columnWidth,
stroke: 'grey'
} }
} }