All Projects → rainbow-me → React Native Animated Charts

rainbow-me / React Native Animated Charts

Licence: mit
Set of components and helpers for building complex and beautifully animated charts

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Animated Charts

Gta V Data Dumps
GTA V Data dumps useful for modding & scripting
Stars: ✭ 148 (-66.59%)
Mutual labels:  animations, native
Qt Nice Frameless Window
Qt Frameless Window for both Windows and OS X, support Aero Snap, drop shadow on Windows, and support Native Style such as round corner, drop shadow on OS X. Based on QMainWindow.
Stars: ✭ 430 (-2.93%)
Mutual labels:  native
Vmprof Python
vmprof - a statistical program profiler
Stars: ✭ 395 (-10.84%)
Mutual labels:  native
Flutter echarts
A Flutter widget to use Apache ECharts (incubating) in a reactive way.
Stars: ✭ 420 (-5.19%)
Mutual labels:  charts
Pywaffle
🧇 Make Waffle Charts in Python.
Stars: ✭ 406 (-8.35%)
Mutual labels:  charts
Aachartcore
📈📊☕️☕️☕️An elegant modern declarative data visualization chart framework for Android. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 424 (-4.29%)
Mutual labels:  charts
Hycharts
柱状图、折/曲线图、K线图(主图、交易量图、辅助图), 图与图可以自由组合, 支持分页加载数据 -----> 低内存、低耗电、滑动缩放顺滑
Stars: ✭ 394 (-11.06%)
Mutual labels:  charts
Azteceditor Ios
A reusable native iOS visual HTML text editor component.
Stars: ✭ 437 (-1.35%)
Mutual labels:  native
Nextjs Page Transitions
Travel App, Native-like Page Transitions (:atom: with React & Next.js)
Stars: ✭ 424 (-4.29%)
Mutual labels:  animations
Advanceddlsupport
Delegate-based C# P/Invoke alternative - compatible with all platforms and runtimes.
Stars: ✭ 419 (-5.42%)
Mutual labels:  native
Scala Native
Your favorite language gets closer to bare metal.
Stars: ✭ 4,053 (+814.9%)
Mutual labels:  native
React Espanol
Recursos para aprender ReactJS en español
Stars: ✭ 409 (-7.67%)
Mutual labels:  native
Progressview
🌊 A polished and flexible ProgressView, fully customizable with animations.
Stars: ✭ 425 (-4.06%)
Mutual labels:  animations
Chartjs.blazor
Brings Chart.js charts to Blazor
Stars: ✭ 402 (-9.26%)
Mutual labels:  charts
Awesome Android Performance
🏆Explore Android performance optimization in depth(continuous updating ...)
Stars: ✭ 433 (-2.26%)
Mutual labels:  native
Flutter Examples
Personal collection of Flutter apps.
Stars: ✭ 394 (-11.06%)
Mutual labels:  animations
Entitycomponentsystemsamples
No description or website provided.
Stars: ✭ 4,218 (+852.14%)
Mutual labels:  native
Charts
Helm charts for applications you run at home
Stars: ✭ 421 (-4.97%)
Mutual labels:  charts
Booksearch
A digital BookShelf for your reading progress.
Stars: ✭ 441 (-0.45%)
Mutual labels:  animations
Sketchcachecleaner
💻 Sketch Cache Cleaner - Deletes hidden Sketch history files that can take a lot of space on your hard drive and that you would probably never use.
Stars: ✭ 435 (-1.81%)
Mutual labels:  native

React Native Animated Charts

Set of components and helpers for building complex and beautifully animated charts.

The library was designed to create aesthetic, animated (so far only linear) charts based on a given input. The main assumptions of the library were to create smooth transitions between subsequent data sets. For this reason, we have discovered a shortage of existing libraries related to the charts. The current package was created as part of the Rainbow.me project and for this reason it was not designed as a complete and comprehensive solution for displaying various types of charts. However, we will be now using more charts in the whole application, so we believe that the number of functionalities in the application will gradually grow.

Additionally, we are open to new Pull Requests. We want this library to become popular and complete thanks to community activity.

It's a part of the Rainbow.me project.

Installation

  1. Install react-native-reanimated in the newest version.
yarn add @rainbow-me/animated-charts

The library has been verified with 2.0.0-alpha.6 version of reanimated.

Reanimated

Using TurboModules might have an impact on your current development flow and most likely you don't want to decrease your DX. Since we're not using reanimated in other places in the app, we made some tweaks to disable charts in development mode with compilation macros on iOS. You can find it here

Also, because we're using libraries which currently do not support reanimated 2, we patched exports in reanimated

Furthermore, we found few differences in how the Animated module works with and without TurboModules support, so we made a trick to fallback to the not-TM version of Animated.

Most likely, you don't need any of those patches.

Example app

We made a generic example to show briefly what's possible to achieve with this library. A Real-life example is available inside Rainbow!

In order to run an example clone this repo and navigate to Example then:

yarn && cd ios && pod install && cd ..
react-native run-android
react-native run-ios

API

The library has been designed to provide as much flexibility as possible with the component-based API for easy integration with existing applications.

Basic API Example

import React from 'react';
import {Dimensions, View} from 'react-native';
import {ChartDot, ChartPath, ChartPathProvider, monotoneCubicInterpolation} from '@rainbow-me/animated-charts';

export const {width: SIZE} = Dimensions.get('window');

export const data = [
  {x: 1453075200, y: 1.47}, {x: 1453161600, y: 1.37},
  {x: 1453248000, y: 1.53}, {x: 1453334400, y: 1.54},
  {x: 1453420800, y: 1.52}, {x: 1453507200, y: 2.03},
  {x: 1453593600, y: 2.10}, {x: 1453680000, y: 2.50},
  {x: 1453766400, y: 2.30}, {x: 1453852800, y: 2.42},
  {x: 1453939200, y: 2.55}, {x: 1454025600, y: 2.41},
  {x: 1454112000, y: 2.43}, {x: 1454198400, y: 2.20},
];

const points = monotoneCubicInterpolation(data)(40);

const BasicExample = () => (
  <View style={{ backgroundColor: 'black' }}>
    <ChartPathProvider data={{ points, smoothingStrategy: 'bezier' }}>
      <ChartPath height={SIZE / 2} stroke="yellow" width={SIZE} />
      <ChartDot style={{ backgroundColor: 'blue' }} />
    </ChartPathProvider>
  </View>
);

The code above generates the chart below:

Linear charts

ChartPathProvider

The whole chart's structure has to be wrapped with ChartProvider. It's responsible for data managing and itself does not have a visual impact on the layout. Under the hood, it uses context API to simplify manipulation with other components. The rule is to use one data series for each wrapper. It's important to have it as a separated component because under this component it's possible useChartData hook and put ChartDot component. However, if you don't need those features, you can pass data directly to ChartPath and drop this wrapper.

Prop name type default / obligatory description
data { points: [Point], nativePoints: [Point], smoothingStrategy?: 'bezier'|'simple'|'complex', smoothingFactor } obligatory Object containing data structure and way to display them. Each of the properties is explained below.
  • points is an array containing Points to be displayed. A Point is an object containing x and y as a number.
  • originalData is an array of points that will not be drawn. However, if you used some strategy of interpolating data or simplifying you might want to present data slightly different from the real one. Then if you'd like labels to be fully correct you may want to provide real data before adjusting them.
  • smoothingStrategy. While presenting points path can be drawn with different approaches.
    • If smoothingStrategy is not provided (or set to any other value but for listed here), connects points using linear interpolation.
    • The bezier strategy connects points with a bezier path inspired by d3 shape. It's not parametrized by smoothingFactor.
    • The complex strategy uses approach explained here using cubic splines. It's parametrized by smoothingFactor.
    • The simple strategy is a bit simplified complex strategy using quadratic splines. It's parametrized by smoothingFactor.
  • smoothingFactor. Is a value from 0 to 1 defining how smooth a presentation should be. 0 means no smoothing, and it's the default. smoothingFactor has an impact if smoothingStrategy is simple or complex.
  • yRange. 2-elements array with numbers describing minY and maxY in this order. When not applied, charts are automatically adjusted vertically. However, when data are monotonical, they might present incorrectly without bounding due to numerical issues.

ChartPath

This component is used for showing the path itself.

Prop name type default / obligatory description
smoothingWhileTransitioningEnabled number false Although smoothing is not complex computing, it might impact performance in some low-end devices so while having a big set of data it might be worth disable smoothing while transitioning.
height number obligatory Height od the SVG canvas
width number obligatory Width od the SVG canvas
strokeWidth number 1 Width of the path.
selectedStrokeWidth number 1 Width of the path selected.
gestureEnabled boolean true Defines if interaction with the chart should be allowed or not
longPressGestureHandlerProps object {maxDist: 100000, minDurationMs: 0, shouldCancelWhenOutside: false} Under the hood we're using LongPressGestureHandler for handling interactions. It's recommended to not override its props. However, it might be useful while interacting with another GH.
selectedOpacity number 0.7 Target opacity of the path while touching the chart.
hitSlop number 0 While scrubbing the chart touching edges of the screen you may want make points on the edges more accessible. With hitSlop it's possible to access points on edges doubling the speed of scrubbing beyond this margin.
hapticsEnabled boolean false On pressing in/out on the chart it might be expected to make haptic feedback. It will happen with hapticsEnabled set to true.
springConfig object {damping: 15, mass: 1, stiffness: 600} Object defining the spring animation. This spring is used for a dot's scale.
timingFeedbackConfig object {duration: 80} Object defining the timing animation. timingFeedbackConfig is used for a path's opacity and width.
timingAnimationConfig object {duration: 300} Object defining the timing animation. timingAnimationConfig is used for the transition between chart's data.
...rest object {} Props applied to SVG Path.

ChartDot

Component for displaying the dot for scrubbing on the chart.

Prop name type default description
size number 10 Size of the dot.
...props object {} Rest of the props applied to Reanimated.View including style

ChartYLabel & ChartXLabel

Labels are useful while moving finger through the chart to show the exact value in given point.

Prop name type default description
format reanimated worklet a => a Worklet for formatting data from the chart. It can be useful when your data is a timestamp or currency.
...props object {} Rest of the props applied to TextInput including style

Candle Charts

TODO

Pie charts

TODO

Helpers

It's not essential in the library, but we have decided to include a lot of helpers we are (or we were) using for displaying charts.

Interpolations

We have two interpolators which share the most of the API: bSplineInterpolation and monotoneCubicInterpolation.

import { bSplineInterpolation as interpolator } from '@rainbow-me/animated-charts';
// import { monotoneCubicInterpolation as interpolator } from '@rainbow-me/animated-charts';

const interpolatedData = interpolator({data, range: 80});

Code above generates 80 equidistant points from given dataset. Generator accepts object of parameters as an argument:

  • data - input of points.

  • range is the number of points of the output.

  • includeExtremes. If it's vital to include extremes in the output, set to true. However, the data might not be fully equidistant.

  • removePointsSurroundingExtremes. Makes sense only if includeExtremes set to true. When disabled, it might be possible that extremes look very "pointy". To get rid of this, you can remove points surrounding extremes. E.g.

    • removePointsSurroundingExtremes = false

      o---------o----Min--o---------o---------o---------o---------o

    • removePointsSurroundingExtremes = true

      o--------------Min------------o---------o---------o---------o

bSplineInterpolation({ degree = 3, ...params })

bSplineInterpolation is inspired by victorian lib and uses B-spline interpolation of a given degree.

monotoneCubicInterpolation({ ...params })

This curve is inspired by d3 shape. "Produces a cubic spline that preserves monotonicity in y, assuming monotonicity in x, as proposed by Steffen in A simple method for monotonic interpolation in one dimension: “a smooth curve with continuous first-order derivatives that passes through any given set of data points without spurious oscillations. Local extrema can occur only at grid points where they are given by the data, but not in between two adjacent grid points.”

simplifyData(data, pickRange = 10, includeExtremes = true)

This helper takes only one point per pickRange. Might be useful for very dense data. If it's important, it's possible to include extremes with the includeExtremes flag. E.g.

pickRange = 3, includeExtremes = true

X are equidistant in this case

Y:0          1          7          2         -3          0          1          2
  S----------o----------E----------X----------E----------o----------X----------o----------S

X - points picked because index%3=0

S – the first and the last points are always included.

E – extremes.

useChartData

It's a bit advanced hook and contains information about current position of dot and corresponding values. Content of the result is changing often, so it's not worth deep documentation now.

TODO

The library has been released in a production-ready version. We use it inside the Rainbow.me project so it's verified for use in production. However, it relies on React Native Reanimated 2.0 in the alpha version thus it might not work perfectly. Test it deeply before using it. Until the stable release of Reanimated 2, I think it's worth not marking this library as stable. Although the library works with Reanimated without any changes, we faced a few issues related to our (quite advanced) usage of the library. Thus we made some hacks we're not very proud of and it's for 99% something you should not do. However, if you see some crashes, you may try one of our hacks.

There're a few things left to make it polished regarding linear charts:

  • [ ] Support for gestures - pinching, swiping, etc.
  • [ ] more parameters regarding interpolation, smoothing, and animations (i.e. allow to override springConfig and timingConfig)

License

Reanimated library is licensed under The MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].