Skip to content

Commit

Permalink
addes guage import version
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernardo Orozco Garza committed Dec 1, 2017
1 parent c5ebe30 commit 1c45360
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 99 deletions.
184 changes: 89 additions & 95 deletions App/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React, { Component, PropTypes } from "react";
import React, { Component, PropTypes, } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
WebView,
Image,
Dimensions
} from "react-native";
AppRegistry,
StyleSheet,
Text,
View,
WebView,
Image,
Dimensions
} from 'react-native';

const win = Dimensions.get("window");
const win = Dimensions.get('window');
class ChartWeb extends Component {
constructor(props) {
super(props);
constructor(props){
super(props);

this.state = {
init: `<html>
this.state={
init:`<html>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
<style media="screen" type="text/css">
#container {
Expand All @@ -32,25 +32,18 @@ class ChartWeb extends Component {
</style>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
${this.props.stock
? '<script src="https://code.highcharts.com/stock/highstock.js"></script>'
: '<script src="https://code.highcharts.com/highcharts.js"></script>'}
${this.props.more
? '<script src="https://code.highcharts.com/highcharts-more.js"></script>'
: ""}
${this.props.heatMap
? '<script src="https://code.highcharts.com/modules/heatmap.js"></script>'
: ""}
${this.props.stock ? '<script src="https://code.highcharts.com/stock/highstock.js"></script>'
: '<script src="https://code.highcharts.com/highcharts.js"></script>'}
${this.props.more ? '<script src="https://code.highcharts.com/highcharts-more.js"></script>'
: ''}
${this.props.guage ? '<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>'
: ''}
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script>
$(function () {
Highcharts.setOptions(${JSON.stringify(
this.props.options
)});
Highcharts.${this.props.stock
? "stockChart"
: "chart"}('container', `,
end: ` );
Highcharts.setOptions(${JSON.stringify(this.props.options)});
Highcharts.${this.props.stock ? 'stockChart' : 'chart'}('container', `,
end:` );
});
</script>
</head>
Expand All @@ -59,81 +52,82 @@ class ChartWeb extends Component {
</div>
</body>
</html>`,
Wlayout: {
height: win.height,
width: win.width
}
};
}
Wlayout:{
height:win.height,
width:win.width
}
}
}

// used to resize on orientation of display
reRenderWebView(e) {
this.setState({
height: e.nativeEvent.layout.height,
width: e.nativeEvent.layout.width
});
}
// used to resize on orientation of display
reRenderWebView(e) {
this.setState({
height: e.nativeEvent.layout.height,
width: e.nativeEvent.layout.width,
})
}

render() {
let config = JSON.stringify(this.props.config, function(key, value) {
//create string of json but if it detects function it uses toString()
return typeof value === "function" ? value.toString() : value;
});
render() {
let config = JSON.stringify(this.props.config, function (key, value) {//create string of json but if it detects function it uses toString()
return (typeof value === 'function') ? value.toString() : value;
});

config = JSON.parse(config);
let concatHTML = `${this.state.init}${flattenObject(config)}${this.state
.end}`;

return (
<View style={this.props.style}>
<WebView
onLayout={this.reRenderWebView}
style={styles.full}
source={{ html: concatHTML, baseUrl: "web/" }}
javaScriptEnabled={true}
domStorageEnabled={true}
scalesPageToFit={true}
scrollEnabled={false}
automaticallyAdjustContentInsets={true}
/>
</View>
);
}
}
config = JSON.parse(config)
let concatHTML = `${this.state.init}${flattenObject(config)}${this.state.end}`;

return (
<View style={this.props.style}>
<WebView
onLayout={this.reRenderWebView}
style={styles.full}
source={{ html: concatHTML, baseUrl: 'web/' }}
javaScriptEnabled={true}
domStorageEnabled={true}
scalesPageToFit={true}
scrollEnabled={false}
automaticallyAdjustContentInsets={true}
{...this.props}
/>
</View>
);
};
};

var flattenObject = function(obj, str = "{") {
Object.keys(obj).forEach(function(key) {
str += `${key}: ${flattenText(obj[key])}, `;
});
return `${str.slice(0, str.length - 2)}}`;
var flattenObject = function (obj, str='{') {
Object.keys(obj).forEach(function(key) {
str += `${key}: ${flattenText(obj[key])}, `
})
return `${str.slice(0, str.length - 2)}}`
};

var flattenText = function(item) {
var str = "";
if (item && typeof item === "object" && item.length == undefined) {
str += flattenObject(item);
} else if (item && typeof item === "object" && item.length !== undefined) {
str += "[";
item.forEach(function(k2) {
str += `${flattenText(k2)}, `;
});
str = str.slice(0, str.length - 2);
str += "]";
} else if (typeof item === "string" && item.slice(0, 8) === "function") {
str += `${item}`;
} else if (typeof item === "string") {
str += `\"${item.replace(/"/g, '\\"')}\"`;
} else {
str += `${item}`;
}
return str;
var flattenText = function(item,key) {
if(key=="y") console.log(item, typeof item);
var str = ''
if (item && typeof item === 'object' && item.length == undefined) {
str += flattenObject(item)
} else if (item && typeof item === 'object' && item.length !== undefined) {
str += '['
item.forEach(function(k2) {
str += `${flattenText(k2)}, `
})
if(item.length>0) str = str.slice(0, str.length - 2)
str += ']'
} else if(typeof item === 'string' && item.slice(0, 8) === 'function') {
str += `${item}`
} else if(typeof item === 'string') {
str += `\"${item.replace(/"/g, '\\"')}\"`
} else {
str += `${item}`
}
return str
};

var styles = StyleSheet.create({
full: {
flex: 1,
backgroundColor: "transparent"
}
full: {
flex:1,
backgroundColor:'transparent'
}
});

module.exports = ChartWeb;
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ render() {
| heatMap | false | Default false; use HeatMap |
| style | false | Style object to be passed onto the WebView |
| options | false | Pass global and lang options from Highcharts |
| guage | false | Import gauge library from highcharts |


props added to WebView

## NOTE
if not rendering in real device add this two props to the component
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-highcharts",
"version": "0.2.1",
"version": "1.1",
"description":
"JavaScript implementation of a view container that can flip between its front and back, where the back has a console.log and the front is your aplication.",
"main": "react-native-highcharts.js",
Expand Down
10 changes: 7 additions & 3 deletions react-native-highcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class ChartWeb extends Component {
: '<script src="https://code.highcharts.com/highcharts.js"></script>'}
${this.props.more ? '<script src="https://code.highcharts.com/highcharts-more.js"></script>'
: ''}
${this.props.guage ? '<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>'
: ''}
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script>
$(function () {
Expand Down Expand Up @@ -73,7 +75,7 @@ class ChartWeb extends Component {

config = JSON.parse(config)
let concatHTML = `${this.state.init}${flattenObject(config)}${this.state.end}`;

return (
<View style={this.props.style}>
<WebView
Expand All @@ -85,6 +87,7 @@ class ChartWeb extends Component {
scalesPageToFit={true}
scrollEnabled={false}
automaticallyAdjustContentInsets={true}
{...this.props}
/>
</View>
);
Expand All @@ -98,7 +101,8 @@ var flattenObject = function (obj, str='{') {
return `${str.slice(0, str.length - 2)}}`
};

var flattenText = function(item) {
var flattenText = function(item,key) {
if(key=="y") console.log(item, typeof item);
var str = ''
if (item && typeof item === 'object' && item.length == undefined) {
str += flattenObject(item)
Expand All @@ -107,7 +111,7 @@ var flattenText = function(item) {
item.forEach(function(k2) {
str += `${flattenText(k2)}, `
})
str = str.slice(0, str.length - 2)
if(item.length>0) str = str.slice(0, str.length - 2)
str += ']'
} else if(typeof item === 'string' && item.slice(0, 8) === 'function') {
str += `${item}`
Expand Down

0 comments on commit 1c45360

Please sign in to comment.