WIP: Draw curve on current grid

This commit is contained in:
Julia Friesel
2018-06-19 11:01:38 +02:00
parent c73d7cced6
commit 7c6ceb06f5
9 changed files with 238 additions and 3 deletions
+1
View File
@@ -137,6 +137,7 @@ android {
}
dependencies {
compile project(':react-native-svg')
compile project(':realm')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
@@ -3,6 +3,7 @@ package com.drip;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.horcrux.svg.SvgPackage;
import io.realm.react.RealmReactPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
@@ -24,6 +25,7 @@ public class MainApplication extends Application implements ReactApplication {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SvgPackage(),
new RealmReactPackage()
);
}
+2
View File
@@ -1,4 +1,6 @@
rootProject.name = 'drip'
include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android')
include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')
+3 -1
View File
@@ -3,6 +3,7 @@ import Home from './home'
import Calendar from './calendar'
import CycleDay from './cycle-day'
import Chart from './chart'
// this is until react native fixes this bug, see https://github.com/facebook/react-native/issues/18868#issuecomment-382671739
import { YellowBox } from 'react-native'
@@ -11,5 +12,6 @@ YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated'])
export default createStackNavigator({
home: { screen: Home },
calendar: { screen: Calendar },
cycleDay: { screen: CycleDay }
cycleDay: { screen: CycleDay },
chart: { screen: Chart }
})
+103
View File
@@ -0,0 +1,103 @@
import React, { Component } from 'react'
import { ScrollView } from 'react-native'
import { temperatureDaysSortedByDate } from './db'
import range from 'date-range'
import Svg,{
G,
Polyline,
Rect,
Text,
} from 'react-native-svg'
import { LocalDate } from 'js-joda'
const right = 350
const top = 10
const bottom = 350
const columnWidth = 30
const dateRow = {
height: 30,
width: right
}
function makeDayColumn(labelInfo) {
return (
<G>
<Rect
x={labelInfo.rightOffset}
y={top}
width={columnWidth}
height={bottom - top - dateRow.height}
fill="lightgrey"
strokeWidth="1"
stroke="grey"
/>
<Text
stroke="purple"
fontSize="10"
x={labelInfo.rightOffset}
y={bottom - top - dateRow.height}
>{labelInfo.label.split('-')[2]}</Text>
</G>
)
}
function getPreviousDays(n) {
const today = new Date()
today.setHours(0); today.setMinutes(0); today.setSeconds(0); today.setMilliseconds(0)
const twoWeeksAgo = new Date(today - (range.DAY * n))
return range(twoWeeksAgo, today).reverse()
}
const xAxisDates = getPreviousDays(14).map(jsDate => {
return LocalDate.of(
jsDate.getFullYear(),
jsDate.getMonth() + 1,
jsDate.getDate()
).toString()
})
const xAxisDatesWithRightOffset = xAxisDates.map((datestring, columnIndex) => {
const rightOffset = right - (columnWidth * (columnIndex + 1))
return {
label: datestring,
rightOffset
}
})
function determineCurvePoints(temperatureDaysSortedByDate, xAxisDatesWithRightOffset) {
return temperatureDaysSortedByDate.map(cycleDay => {
const x = xAxisDatesWithRightOffset.find(tick => tick.label === cycleDay.date).rightOffset
const y = normalizeToScale(cycleDay.temperature.value)
return [x,y].join()
}).join(' ')
}
function normalizeToScale(temp) {
const scale = {
low: 33,
high: 40
}
const tempInScaleDecs = (scale.high - temp) / (scale.high - scale.low)
const scaleHeight = bottom - top
return scaleHeight * tempInScaleDecs
}
export default class SvgExample extends Component {
render() {
return (
<ScrollView horizontal={true}>
<Svg
height="350"
width="2000"
>
{xAxisDatesWithRightOffset.map(makeDayColumn)}
<Polyline
points={determineCurvePoints(temperatureDaysSortedByDate, xAxisDatesWithRightOffset)}
fill="none"
stroke="black"
strokeWidth="2"
/>
</Svg>
</ScrollView>
)
}
}
+6
View File
@@ -65,6 +65,12 @@ export default class Home extends Component {
title="Go to calendar">
</Button>
</View>
<View>
<Button
onPress={() => navigate('chart')}
title="Go to chart">
</Button>
</View>
<View>
<Button
onPress={() => deleteAll()}
+71 -2
View File
@@ -5,7 +5,6 @@
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; };
@@ -38,6 +37,8 @@
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
4DD9342A0EA14FF399CBC625 /* libRNSVG.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 154304354E2E4612B01C5232 /* libRNSVG.a */; };
2F7162338C9C4298AAF05308 /* libRNSVG-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F597327061840D088EE7B05 /* libRNSVG-tvOS.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -343,6 +344,9 @@
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
ADBDB91F1DFEBF0600ED6528 /* RCTBlob.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTBlob.xcodeproj; path = "../node_modules/react-native/Libraries/Blob/RCTBlob.xcodeproj"; sourceTree = "<group>"; };
E20F46E373F5493594D234EB /* RNSVG.xcodeproj */ = {isa = PBXFileReference; name = "RNSVG.xcodeproj"; path = "../node_modules/react-native-svg/ios/RNSVG.xcodeproj"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
154304354E2E4612B01C5232 /* libRNSVG.a */ = {isa = PBXFileReference; name = "libRNSVG.a"; path = "libRNSVG.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
0F597327061840D088EE7B05 /* libRNSVG-tvOS.a */ = {isa = PBXFileReference; name = "libRNSVG-tvOS.a"; path = "libRNSVG-tvOS.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -371,6 +375,7 @@
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
4DD9342A0EA14FF399CBC625 /* libRNSVG.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -386,6 +391,7 @@
2D02E4C61E0B4AEC006451C7 /* libRCTSettings-tvOS.a in Frameworks */,
2D02E4C71E0B4AEC006451C7 /* libRCTText-tvOS.a in Frameworks */,
2D02E4C81E0B4AEC006451C7 /* libRCTWebSocket-tvOS.a in Frameworks */,
2F7162338C9C4298AAF05308 /* libRNSVG-tvOS.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -557,6 +563,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
E20F46E373F5493594D234EB /* RNSVG.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@@ -685,7 +692,7 @@
83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0610;
LastUpgradeCheck = 610;
ORGANIZATIONNAME = Facebook;
TargetAttributes = {
00E356ED1AD99517003FC87E = {
@@ -1181,6 +1188,15 @@
);
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/drip.app/drip";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Debug;
};
@@ -1198,6 +1214,15 @@
);
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/drip.app/drip";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Release;
};
@@ -1216,6 +1241,10 @@
);
PRODUCT_NAME = drip;
VERSIONING_SYSTEM = "apple-generic";
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Debug;
};
@@ -1233,6 +1262,10 @@
);
PRODUCT_NAME = drip;
VERSIONING_SYSTEM = "apple-generic";
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Release;
};
@@ -1259,6 +1292,15 @@
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.2;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Debug;
};
@@ -1285,6 +1327,15 @@
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.2;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Release;
};
@@ -1310,6 +1361,15 @@
SDKROOT = appletvos;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/drip-tvOS.app/drip-tvOS";
TVOS_DEPLOYMENT_TARGET = 10.1;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Debug;
};
@@ -1335,6 +1395,15 @@
SDKROOT = appletvos;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/drip-tvOS.app/drip-tvOS";
TVOS_DEPLOYMENT_TARGET = 10.1;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
"\"$(SRCROOT)/$(TARGET_NAME)\"",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../node_modules/react-native-svg/ios/**",
);
};
name = Release;
};
+48
View File
@@ -2329,6 +2329,15 @@
"object-visit": "^1.0.0"
}
},
"color": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color/-/color-2.0.1.tgz",
"integrity": "sha512-ubUCVVKfT7r2w2D3qtHakj8mbmKms+tThR8gI8zEYCbUBl8/voqFGt3kgBqGwXAopgXybnkuOq+qMYCRrp4cXw==",
"requires": {
"color-convert": "^1.9.1",
"color-string": "^1.5.2"
}
},
"color-convert": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz",
@@ -2342,6 +2351,15 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"color-string": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.2.tgz",
"integrity": "sha1-JuRYFLw8mny9Z1FkikFDRRSnc6k=",
"requires": {
"color-name": "^1.0.0",
"simple-swizzle": "^0.2.2"
}
},
"color-support": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz",
@@ -2506,6 +2524,11 @@
}
}
},
"date-range": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/date-range/-/date-range-0.0.2.tgz",
"integrity": "sha1-OVHZ5SWZgu3VMewx5APYImPvbjk="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -6272,6 +6295,16 @@
"resolved": "https://registry.npmjs.org/react-native-simple-radio-button/-/react-native-simple-radio-button-2.7.1.tgz",
"integrity": "sha512-O3RIKBl1GgSAITAEhf4BscrEa3jWdW82xP6yCC40+h7rliQpHEL/3lYTyO9V4wYi3RV8kwvDbxiF4v1+fR0k3w=="
},
"react-native-svg": {
"version": "6.3.1",
"resolved": "https://registry.npmjs.org/react-native-svg/-/react-native-svg-6.3.1.tgz",
"integrity": "sha512-0kmfUwKUBWnPuJpy+bdGIYKkXHg/M/X57ji8b3d3ZFB2rRTWMRkwI1D+AJ6FQRX109+FJn6L6hsIokDj1lckzA==",
"requires": {
"color": "^2.0.1",
"lodash": "^4.16.6",
"pegjs": "^0.10.0"
}
},
"react-native-tab-view": {
"version": "0.0.77",
"resolved": "https://registry.npmjs.org/react-native-tab-view/-/react-native-tab-view-0.0.77.tgz",
@@ -7222,6 +7255,21 @@
}
}
},
"simple-swizzle": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
"integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=",
"requires": {
"is-arrayish": "^0.3.1"
},
"dependencies": {
"is-arrayish": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.1.tgz",
"integrity": "sha1-wt/DhquqDD4zxI2z/ocFnmkGXv0="
}
}
},
"slash": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
+2
View File
@@ -14,12 +14,14 @@
"lint": "eslint app test"
},
"dependencies": {
"date-range": "0.0.2",
"js-joda": "^1.8.2",
"moment": "^2.22.1",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-calendars": "^1.19.3",
"react-native-simple-radio-button": "^2.7.1",
"react-native-svg": "^6.3.1",
"react-navigation": "^2.0.4",
"realm": "^2.7.1",
"uuid": "^3.2.1"