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
Created April 7, 2017 15:56
createPoint
export const createPoint = (coordinates, color, size = 8) => {
return {
backgroundColor: color,
left: coordinates.x - 3,
bottom: coordinates.y - 2,
position: 'absolute',
borderRadius: 50,
width: size,
height: size
};
@mvbattan
mvbattan / PointsPath.js
Created April 7, 2017 16:01
createLine
export const createLine = (dist, angle, color, opacity, startingPoint) => {
return {
backgroundColor: color,
height: 4,
width: dist,
bottom: dist * Math.sin(angle) / 2 + startingPoint.y,
left: -dist * (1 - Math.cos(angle)) / 2 + startingPoint.x,
position: 'absolute',
opacity,
transform: [
@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)}