Skip to content

Instantly share code, notes, and snippets.

View mvbattan's full-sized avatar

Batu mvbattan

  • Buenos Aires
View GitHub Profile
@mvbattan
mvbattan / LevelSeparator.js
Created April 7, 2017 14:40
LevelSeparator.js
import React from 'react';
import { View, StyleSheet, Text } from 'react-native';
export default function LevelSeparator({ label, height }) {
return (
<View style={[styles.container, { height }]}>
<Text style={styles.label}>
{label.toFixed(0)}
</Text>
<View style={styles.separatorRow}/>
@mvbattan
mvbattan / index.js
Created April 7, 2017 14:43
index - v1
export default class lineChartExample extends Component {
render() {
return (
<View style={styles.container}>
<LevelSeparator height={30} label={10} />
</View>
);
}
}
@mvbattan
mvbattan / SeparatorsLayer.js
Created April 7, 2017 14:47
SeparatorsLayer.js
import React from 'react';
import { View, StyleSheet } from 'react-native';
import LevelSeparator from './LevelSeparator';
export const range = (n) => {
return [...Array(n).keys()];
};
function createSeparator(totalCount, topValue, index, height) {
@mvbattan
mvbattan / index.js
Created April 7, 2017 14:50
index - v2
export default class lineChartExample extends Component {
render() {
return (
<View style={styles.container}>
<SeparatorsLayer topValue={10} separators={5} height={100} />
</View>
);
}
}
@mvbattan
mvbattan / Scaler.js
Created April 7, 2017 14:56
Scaler.js
import { Point } from './pointUtils';
export const startingPoint = Point(-20 , 8);
const endingPoint = Point(242, 100);
export function vectorTransform(point, maxValue, scaleCount) {
return Point(
point.x * (endingPoint.x / scaleCount) + endingPoint.x / scaleCount,
point.y * (endingPoint.y / maxValue)
);
@mvbattan
mvbattan / pointUtils.js
Created April 7, 2017 14:57
pointUtils.js
import React from 'react';
export const Point = (x, y) => {
return { x, y };
};
export const dist = (pointA, pointB) => {
return Math.sqrt(
(pointA.x - pointB.x) * (pointA.x - pointB.x) +
(pointA.y - pointB.y) * (pointA.y - pointB.y)
@mvbattan
mvbattan / keyUtils.js
Created April 7, 2017 14:58
keyUtils.js
export const keyGen = (serializable, anotherSerializable) => {
return `${JSON.stringify(serializable)}-${JSON.stringify(anotherSerializable)}`;
};
@mvbattan
mvbattan / PointsPath.js
Last active April 10, 2017 14:03
PointsPath.js
import React from 'react';
import { View } from 'react-native';
import { dist, angle, pointPropTypes, add } from './pointUtils';
import { keyGen } from './keyUtils';
function toLine(pointA, pointB, color, opacity) {
return (
<View
key={keyGen(pointA, pointB)}
@mvbattan
mvbattan / index.js
Last active April 13, 2017 14:17
index.js - v3
import SeparatorsLayer from './SeparatorsLayer';
import PointsPath from './PointsPath';
import { Point } from './pointUtils';
import { startingPoint, vectorTransform } from './Scaler';
const lightBlue = '#40C4FE';
const green = '#53E69D';
const lightBluePoints = [Point(0, 0), Point(1, 2), Point(2, 3), Point(3, 6), Point(5, 6)];
const greenPoints = [Point(0, 2), Point(3, 4), Point(4, 0), Point(5, 10)];
@mvbattan
mvbattan / index.js
Last active April 13, 2017 14:22
index.js - full
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
import SeparatorsLayer from './SeparatorsLayer';
import PointsPath from './PointsPath';