Skip to content

Commit

Permalink
Partials chart should be mostly done now
Browse files Browse the repository at this point in the history
  • Loading branch information
ronickg committed Nov 26, 2021
1 parent 3045fd6 commit 0ecb41e
Show file tree
Hide file tree
Showing 29 changed files with 1,701 additions and 316 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ android {
applicationId "com.openchia"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 10
versionName "1.1.0"
versionCode 11
versionName "1.1.1"
missingDimensionStrategy 'react-native-camera', 'general'
}
splits {
Expand Down
17 changes: 17 additions & 0 deletions src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ export const getPartialsFromID = (launcherID, timestamp) =>
console.log(error);
});

export const getPartialsFromIDTest = (launcherID, timestamp) =>
fetch(
`${REST_API}partial/?ordering=-timestamp&min_timestamp=${timestamp.toString()}&launcher=${launcherID}&limit=2000`
// `https://openchia.io/api/v1.0/partial/?ordering=-timestamp&min_timestamp=${timestamp}&launcher=${launcherID}/?format=json`
// `https://openchia.io/api/v1.0/partial/?limit=200&offset=200`
)
.then((response) => {
if (response.ok) {
return response.json();
}
throw Error(response.statusText);
})
.then((json) => json)
.catch((error) => {
console.log(error);
});

export const getChiaPlotPosts = () =>
fetch(`${CHIA_PLOT_REST_API}posts`)
.then((response) => {
Expand Down
7 changes: 5 additions & 2 deletions src/ApplicationNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import PayoutScreen from './screens/PayoutScreen';
import ScanScreen from './screens/ScanScreen';
import FarmerScreen, { getHeaderTitle } from './screens/farmer/FarmerScreen';
import SettingsScreen from './screens/SettingsScreen';
import { initialRouteState, launcherIDsState, settingsState } from './Atoms';
import { currencyState, initialRouteState, launcherIDsState, settingsState } from './Atoms';
import LanguageSelectorScreen from './screens/LanguageSelectorScreen';
import CurrencySelectionScreen from './screens/CurrencySelectionScreen';
import CustomDrawerContent from './components/CustomDrawerContent';
Expand Down Expand Up @@ -111,6 +111,7 @@ const LightTheme = {
borderColor: 'rgba(0,0,0,0.05)',
tabNavigator: '#436B34',
tabNavigatorText: '#f5f5f5',
jellyBarText: '#424242',
},
};

Expand Down Expand Up @@ -145,6 +146,7 @@ const DarkTheme = {
borderColor: 'rgba(0,0,0,0.05)',
tabNavigator: '#436B34',
tabNavigatorText: '#f5f5f5',
jellyBarText: '#f5f5f5',
},
};

Expand Down Expand Up @@ -292,7 +294,7 @@ const AppRoot = ({ theme, toggleTheme, launcherIDsArray, isThemeDark, initialRou
name="Farmer Details"
component={FarmerScreen}
options={({ route }) => ({
title: getHeaderTitle(route, t),
// title: getHeaderTitle(route, t),
headerRight: () => (
<Button onPress={() => alert('This is a button!')} title="Info" color="#fff" />
),
Expand Down Expand Up @@ -358,6 +360,7 @@ const ApplicationNavigator = () => {
const settings = useRecoilValue(settingsState);
const launcherIDs = useRecoilValue(launcherIDsState);
const initialRoute = useRecoilValue(initialRouteState);
const currency = useRecoilValue(currencyState);

useEffect(() => {
SplashScreen.hide();
Expand Down
5 changes: 5 additions & 0 deletions src/Atoms.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,8 @@ export const newsRefreshState = atomFamily({
key: 'newsRefreshState',
default: 0,
});

export const partialRefreshState = atomFamily({
key: 'partialRefreshState',
default: 0,
});
11 changes: 11 additions & 0 deletions src/charts/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ export const NetspaceChartIntervals = [
{ time: 24 * 90, value: 5, label: '90d' },
{ time: -1, value: 6, label: 'All' },
];

export const PartChartIntervals = [
{ time: 4, interval: 1, label: '4h' },
{ time: 6, interval: 1, label: '6h' },
{ time: 8, interval: 1, label: '8h' },
{ time: 12, interval: 1, label: '12h' },
{ time: 24, interval: 2, label: '24h' },
{ time: 24 * 2, interval: 4, label: '2d' },
{ time: 24 * 3, interval: 6, label: '3d' },
// { time: -1, value: 6, label: 'All' },
];
67 changes: 67 additions & 0 deletions src/charts/Cursor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated, {
useAnimatedGestureHandler,
useSharedValue,
useAnimatedStyle,
withSpring,
} from 'react-native-reanimated';

const CURSOR = 50;
const styles = StyleSheet.create({
cursor: {
width: CURSOR,
height: CURSOR,
borderRadius: CURSOR / 2,
backgroundColor: 'rgba(0, 0, 0, 0.1)',
justifyContent: 'center',
alignItems: 'center',
},
cursorBody: {
width: 15,
height: 15,
borderRadius: 7.5,
backgroundColor: 'black',
},
});

const Cursor = ({ index, translation }) => {
const isActive = useSharedValue(false);
const onGestureEvent = useAnimatedGestureHandler({
onStart: () => {
console.log('Start');
isActive.value = true;
},
onActive: (event) => {
// translation.x.value = event.x;
// translation.y.value = getYForX(graphs[index.value].data.path, translation.x.value) || 0;
},
onEnd: () => {
console.log('End');
isActive.value = false;
},
});

// const style = useAnimatedStyle(() => {
// const translateX = translation.x.value - CURSOR / 2;
// const translateY = translation.y.value - CURSOR / 2;
// return {
// transform: [{ translateX }, { translateY }, { scale: withSpring(isActive.value ? 1 : 0) }],
// };
// });

return (
<View style={StyleSheet.absoluteFill}>
<PanGestureHandler {...{ onGestureEvent }}>
<Animated.View style={StyleSheet.absoluteFill}>
{/* <Animated.View style={[styles.cursor, style]}>
<View style={styles.cursorBody} />
</Animated.View> */}
</Animated.View>
</PanGestureHandler>
</View>
);
};

export default Cursor;
14 changes: 8 additions & 6 deletions src/charts/PoolspaceChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ const PoolspaceChart = ({ data, maxSize }) => {
<View
style={[StyleSheet.absoluteFill, { marginTop: 4, marginBottom: 4, marginStart: 4 }]}
>
<Animated.View style={[styles.backgroundSelection, style]} />
<Animated.View
style={[
styles.backgroundSelection,
{ backgroundColor: theme.colors.accent },
style,
]}
/>
</View>
{NetspaceChartIntervals.map((item, index) => (
<TouchableWithoutFeedback
Expand All @@ -157,13 +163,9 @@ const PoolspaceChart = ({ data, maxSize }) => {
<Animated.View style={[styles.labelContainer]}>
<Text
adjustsFontSizeToFit
style={[
styles.label,
{ color: index === current.value ? 'black' : theme.colors.text },
]}
style={[styles.label, { color: theme.colors.jellyBarText }]}
>
{t(`${item.label}`)}
{/* {item.label} */}
</Text>
</Animated.View>
</TouchableWithoutFeedback>
Expand Down
112 changes: 43 additions & 69 deletions src/charts/TestStackedBarChart.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,63 @@
/* eslint-disable no-restricted-globals */
import React from 'react';
import { useWindowDimensions, View } from 'react-native';
import * as shape from 'd3-shape';
import * as array from 'd3-array';
import * as scale from 'd3-scale';
import { Text } from 'react-native-paper';
import { Svg, Rect, Path } from 'react-native-svg';
import Animated, { useAnimatedProps, useSharedValue } from 'react-native-reanimated';
import { mixPath } from 'react-native-redash';
import { View } from 'react-native';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated, { useAnimatedGestureHandler, useSharedValue } from 'react-native-reanimated';
import { Path, Svg } from 'react-native-svg';
import useAnimatedPath from './useAnimatedPath';
import { createPaths } from './Utils';

const AnimatedPath = Animated.createAnimatedComponent(Path);

const TestStackedBarChart = ({ data, height, keys, colors }) => {
const { width } = useWindowDimensions();
const spacingInner = 0.05;
const spacingOuter = 0.05;
const previous = useSharedValue(0);
const current = useSharedValue(0);
const transition = useSharedValue(0);
const Bar = ({ color, path, itemKey, points, pressed, selectedPoints }) => {
const { animatedProps } = useAnimatedPath({
enabled: true,
itemKey,
pressed,
path,
});

const eventHandler = useAnimatedGestureHandler({
onStart: (event, ctx) => {
selectedPoints.value = points;
pressed.value = itemKey;
},

onFinish: (event, ctx) => {
selectedPoints.value = null;
pressed.value = -1;
},
});

const valueAccessor = ({ item, key }) => item[key];

const series = shape
.stack()
.keys(keys)
.order(shape.stackOrderNone)
.value((item, key) => valueAccessor({ item, key }))
.offset(shape.stackOffsetNone)(data);

const values = array.merge(array.merge(series));
const indexes = values.map((_, index) => index);

const extent = array.extent([...values, 0, height]);

const y = scale.scaleLinear().domain(extent).range([height, 0]);
const x = scale
.scaleBand()
.domain(data.map((_, index) => index))
.range([0, width])
.paddingInner([spacingInner])
.paddingOuter([spacingOuter]);

const bandwidth = x.bandwidth();

const areas = array.merge(
series.map((serie, keyIndex) =>
serie.map((entry, entryIndex) => {
const path = shape
.area()
.y0((d) => y(d[0]))
.y1((d) => y(d[1]))
.x((d, _index) => (_index === 0 ? x(entryIndex) : x(entryIndex) + x.bandwidth()))
.defined((d) => !isNaN(d[0]) && !isNaN(d[1]))([entry, entry]);

return {
path,
color: colors[keyIndex],
key: keys[keyIndex],
};
})
)
return (
<PanGestureHandler onGestureEvent={eventHandler}>
<AnimatedPath animatedProps={animatedProps} fill={color} />
</PanGestureHandler>
);
};

const TestStackedBarChart = ({ data, height, width, keys, colors, selectedPoints }) => {
const pressed = useSharedValue(false);
return (
<View height={height}>
<Svg height={height} width={width}>
{areas.map((bar, index) => {
<Svg width={width} height={height}>
{createPaths({ data, keys, colors, height, width }).map((bar, index) => {
const keyIndex = index % data.length;
const key = `${keyIndex}-${bar.key}`;
const { svg } = data[keyIndex][bar.key];

return (
// <AnimatedPath
// animatedProps={animatedProps}
// {...svg}
// fill={bar.color}
// // stroke="black"
// // strokeWidth={3}
// />
<Path key={key} fill={bar.color} {...svg} d={bar.path} />
<Bar
key={key}
itemKey={keyIndex}
selectedPoints={selectedPoints}
color={bar.color}
points={bar.points}
path={bar.path}
pressed={pressed}
/>
);
})}
</Svg>
</View>
);
};

export default TestStackedBarChart;
52 changes: 52 additions & 0 deletions src/charts/Utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable no-restricted-globals */
import * as shape from 'd3-shape';
import * as array from 'd3-array';
import * as scale from 'd3-scale';

export const createPaths = ({ data, keys, colors, height, width }) => {
const spacingInner = 0.05;
const spacingOuter = 0.05;

const valueAccessor = ({ item, key }) => item[key];

const series = shape
.stack()
.keys(keys)
.order(shape.stackOrderNone)
.value((item, key) => valueAccessor({ item, key }))
.offset(shape.stackOffsetNone)(data);

const values = array.merge(array.merge(series));

const extent = array.extent([...values, 0, 0]);

const y = scale.scaleLinear().domain(extent).range([height, 0]);
const x = scale
.scaleBand()
.domain(data.map((_, index) => index))
.range([0, width])
.paddingInner([spacingInner])
.paddingOuter([spacingOuter]);

const test = array.merge(
series.map((serie, keyIndex) =>
serie.map((entry, entryIndex) => {
const path = shape
.area()
.y0((d) => y(d[0]))
.y1((d) => y(d[1]))
.x((d, _index) => (_index === 0 ? x(entryIndex) : x(entryIndex) + x.bandwidth()))
.defined((d) => !isNaN(d[0]) && !isNaN(d[1]))([entry, entry]);

return {
points: data[entryIndex],
path,
color: colors[keyIndex],
key: keys[keyIndex],
};
})
)
);
return test;
};
Loading

0 comments on commit 0ecb41e

Please sign in to comment.