From 23bcc71943155639e5866d821c14bb9c02291cb6 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Tue, 26 Jun 2018 21:06:43 +0200 Subject: [PATCH] Produce yAxis only once, return y axis tick positions --- components/chart.js | 57 +++++++++++++++++++++++--------------------- components/styles.js | 8 ++++++- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/components/chart.js b/components/chart.js index ad850aa..d13ca87 100644 --- a/components/chart.js +++ b/components/chart.js @@ -1,5 +1,5 @@ import React, { Component } from 'react' -import { View, FlatList } from 'react-native' +import { Text as ReactNativeText, View, FlatList } from 'react-native' import range from 'date-range' import Svg,{ G, @@ -17,6 +17,7 @@ import config from './config' const getCycleDayNumber = getCycleDayNumberModule() +const yAxis = makeYAxis(config) export default class CycleChart extends Component { constructor(props) { @@ -112,34 +113,10 @@ export default class CycleChart extends Component { ) } - 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( - - - {scaleMax - i * 0.5} - - ) - } - return ticks - } - render() { return ( - - {this.placeTicksForYAxis()} - + {yAxis.labels} + {scaleMax - i * 0.5} + + ) + tickPositions.push(y) + } + + return {labels, tickPositions} +} diff --git a/components/styles.js b/components/styles.js index cddb675..f570d37 100644 --- a/components/styles.js +++ b/components/styles.js @@ -50,7 +50,13 @@ const styles = { yAxis: { height: config.chartHeight, width: config.columnWidth, - stroke: 'grey' + }, + yAxisLabel: { + position: 'absolute', + right: 3, + color: 'grey', + fontSize: 12, + fontWeight: 'bold' } }