diff --git a/.gitignore b/.gitignore
index eb1535e..8371342 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
-# OSX
-#
-.DS_Store
+# Editor
+*.swp
+*.swo
# Xcode
#
diff --git a/android/app/src/main/java/com/counter/MainActivity.java b/android/app/src/main/java/com/exactresistorcalculator/MainActivity.java
similarity index 100%
rename from android/app/src/main/java/com/counter/MainActivity.java
rename to android/app/src/main/java/com/exactresistorcalculator/MainActivity.java
diff --git a/android/app/src/main/java/com/counter/MainApplication.java b/android/app/src/main/java/com/exactresistorcalculator/MainApplication.java
similarity index 100%
rename from android/app/src/main/java/com/counter/MainApplication.java
rename to android/app/src/main/java/com/exactresistorcalculator/MainApplication.java
diff --git a/imagesrc/menulogo.svg b/imagesrc/menulogo.svg
new file mode 100644
index 0000000..c69b2ce
--- /dev/null
+++ b/imagesrc/menulogo.svg
@@ -0,0 +1,137 @@
+
+
+
+
diff --git a/src/components/calc.js b/src/components/calc.js
index ca1c0a4..0efe127 100644
--- a/src/components/calc.js
+++ b/src/components/calc.js
@@ -18,6 +18,18 @@ function getUnit(n) {
}
}
+function significantDigits(num) {
+ // http://bateru.com/news/2011/04/code-of-the-day-javascript-significant-figures/
+ var n = String(num).trim(),
+ FIND_FRONT_ZEROS_SIGN_DOT_EXP = /^[\D0]+|\.|([e][^e]+)$/g,
+ FIND_RIGHT_ZEROS = /0+$/g;
+
+ if (!/\./.test(num)) {
+ n = n.replace(FIND_RIGHT_ZEROS, "");
+ }
+ return n.replace(FIND_FRONT_ZEROS_SIGN_DOT_EXP, "").length;
+};
+
const styles = {
table: {
borderBottomColor: 'lightgrey',
@@ -40,20 +52,14 @@ export default class Calc extends Component {
const haveAllValid = state.have.every((x) => x.valid);
const haveNonEmpty = state.have.some((x) => x.value);
- const precision = () => {
- if (targetValid && targetNonEmpty) {
- const pieces = state.target.value.split('.');
- if (pieces[1]) {
- if (pieces[1].length > 20) {
- return 20; // Max toFixed() allows
- }
- if (pieces[1].length > 2) {
- return pieces[1].length;
- }
- }
- }
- return 2;
- };
+ const sigDigs = targetValid && targetNonEmpty ?
+ significantDigits(state.target.value) : 0;
+
+ let precision = 3;
+ if (sigDigs > 3) {
+ // toPrecision() has a max of 20
+ precision = sigDigs > 20 ? 20 : sigDigs;
+ }
const targetRes = state.target.value * state.target.mult;
@@ -71,7 +77,7 @@ export default class Calc extends Component {
if (haveAllValid && haveNonEmpty) {
const {unit, mult} = getUnit(sum);
const val = sum / mult;
- return val.toFixed(precision()) + unit;
+ return val.toPrecision(precision) + unit;
} else {
return '---';
}
@@ -81,18 +87,17 @@ export default class Calc extends Component {
if (targetValid && targetNonEmpty && haveAllValid && haveNonEmpty) {
// Check if the 'overall resistor value' matches the target
const {unit, mult} = getUnit(targetRes);
- console.log((targetRes / mult).toFixed(precision()) + unit);
- if (printSum() === (targetRes / mult).toFixed(precision()) + unit) {
- return (0.0).toFixed(precision());
+ if (printSum() === (targetRes / mult).toPrecision(precision) + unit) {
+ return (0.0).toPrecision(precision);
}
- return percentError.toFixed(precision());
+ return percentError.toPrecision(precision);
} else {
return '---';
}
};
const printNextRes= () => {
- if (targetValid && targetNonEmpty && haveAllValid && haveNonEmpty) {
+ if (targetValid && targetNonEmpty && haveAllValid) {
// Check if we are done because error is 0 or value's exact
if (nextRes == Infinity || printPercentError() == 0.0) {
return 'Done.';
@@ -101,7 +106,7 @@ export default class Calc extends Component {
}
const {unit, mult} = getUnit(nextRes);
const val = nextRes / mult;
- return val.toFixed(precision()) + unit;
+ return val.toPrecision(precision) + unit;
} else {
return '---';
}
diff --git a/src/components/menu.js b/src/components/menu.js
index 89c8fcd..ec4ca0e 100644
--- a/src/components/menu.js
+++ b/src/components/menu.js
@@ -1,14 +1,20 @@
import React, {Component} from 'react';
-import {StyleSheet, View, Text, TouchableOpacity} from 'react-native';
+import {Image, ScrollView, StyleSheet, View, TouchableOpacity} from 'react-native';
-const styles = StyleSheet.create({
+import MyText from './mytext.js';
+
+const styles = {
main: {
backgroundColor: '#ffffff',
flex: 1,
- alignItems: 'center',
- justifyContent: 'center',
},
-});
+ menutable: {
+ borderBottomColor: 'lightgrey',
+ borderBottomWidth: 1,
+ padding: 15,
+ fontSize: 16,
+ },
+};
export default class Menu extends Component {
constructor(props) {
@@ -20,9 +26,13 @@ export default class Menu extends Component {
return (
- Calculator
- Help
- Link 4
+
+
+ Calculator
+ Help
+ Tips
+ About
+
);
}
diff --git a/src/components/resistor.js b/src/components/resistor.js
index 4645113..64cd518 100644
--- a/src/components/resistor.js
+++ b/src/components/resistor.js
@@ -52,7 +52,7 @@ class Resistor extends Component {
updatemult('1');
}
- return (
+ return data ? (
Clear
- );
+ ) : null;
}
}
diff --git a/src/containers/nav.js b/src/containers/nav.js
index b0c998c..26ed3a7 100644
--- a/src/containers/nav.js
+++ b/src/containers/nav.js
@@ -1,6 +1,6 @@
'use strict';
import React, {Component} from 'react';
-import {View, StyleSheet} from 'react-native';
+import {Navigator, View, StyleSheet} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import Ionicons from 'react-native-vector-icons/Ionicons';
@@ -8,6 +8,8 @@ import Drawer from 'react-native-drawer';
import * as menuActions from '../actions/menuActions';
import MenuApp from '../containers/menuApp';
+import CalcApp from '../containers/calcApp';
+import HelpApp from '../containers/helpApp';
class Nav extends Component {
constructor(props) {
@@ -52,7 +54,18 @@ class Nav extends Component {
title="Exact Resistor Calculator"
/>
- {state.page}
+ {
+ switch (state.page) {
+ case 'main':
+ return ;
+ case 'help':
+ return ;
+ default:
+ return ;
+ }
+ }}
+ />
);
diff --git a/src/images/menulogo.png b/src/images/menulogo.png
new file mode 100644
index 0000000..8e3f03d
Binary files /dev/null and b/src/images/menulogo.png differ
diff --git a/src/reducers/menu.js b/src/reducers/menu.js
index cddd230..47e287a 100644
--- a/src/reducers/menu.js
+++ b/src/reducers/menu.js
@@ -1,13 +1,10 @@
import React, {Component} from 'react';
import * as types from '../actions/actionTypes';
-import CalcApp from '../containers/calcApp';
-import HelpApp from '../containers/helpApp';
-
const initialState = {
isOpen: false,
refdrawer: null,
- page: ,
+ page: 'main',
subtitle: 'Calculator Page',
};
@@ -27,14 +24,14 @@ export default function menu(state = initialState, action = {}) {
return {
...state,
isOpen: false,
- page: ,
+ page: 'main',
subtitle: 'Calculator Page',
};
case types.HELP:
return {
...state,
isOpen: false,
- page: ,
+ page: 'help',
subtitle: 'Help',
};
default: