Skip to content

Commit

Permalink
wip chart library
Browse files Browse the repository at this point in the history
  • Loading branch information
briansztamfater committed Jul 27, 2023
1 parent eb3de97 commit 40069b4
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ run-android: export TARGET := android
run-android: ##@run Build Android APK and start it on the device
npx react-native run-android --appIdSuffix debug

SIMULATOR=iPhone 11 Pro
SIMULATOR=iPhone 14 Plus
run-ios: export TARGET := ios
run-ios: ##@run Build iOS app and start it in a simulator/device
ifneq ("$(SIMULATOR)", "")
Expand Down
30 changes: 17 additions & 13 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PODS:
- BigInt (5.2.0)
- boost (1.76.0)
- BVLinearGradient (2.5.6):
- React
- CryptoSwift (1.5.1)
- BVLinearGradient (2.8.0):
- React-Core
- CryptoSwift (1.7.1)
- DoubleConversion (1.1.6)
- FBLazyVector (0.69.10)
- FBReactNativeSpec (0.69.10):
Expand All @@ -16,6 +17,7 @@ PODS:
- glog (0.3.5)
- HMSegmentedControl (1.5.6)
- Keycard (3.0.6):
- BigInt
- CryptoSwift
- secp256k1
- SSZipArchive
Expand Down Expand Up @@ -425,8 +427,8 @@ PODS:
- React-Core
- RNStaticSafeAreaInsets (2.2.0):
- React-Core
- RNSVG (9.13.6):
- React
- RNSVG (13.10.0):
- React-Core
- SDWebImage (5.11.1):
- SDWebImage/Core (= 5.11.1)
- SDWebImage/Core (5.11.1)
Expand Down Expand Up @@ -527,6 +529,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- BigInt
- CryptoSwift
- fmt
- HMSegmentedControl
Expand Down Expand Up @@ -692,24 +695,25 @@ EXTERNAL SOURCES:

CHECKOUT OPTIONS:
Keycard:
:commit: 17381678bb981c3c553bb7202a26e642cecb1817
:commit: 2cca3b1f0ac03d0300189c92048438861042bf1b
:git: https://github.com/status-im/Keycard.swift.git
secp256k1:
:commit: 46a1fa30d9b8babeae85ff519050f42394ab5fcc
:git: https://github.com/status-im/secp256k1.swift.git
:submodules: true

SPEC CHECKSUMS:
BigInt: f668a80089607f521586bbe29513d708491ef2f7
boost: a7c83b31436843459a1961bfd74b96033dc77234
BVLinearGradient: e3aad03778a456d77928f594a649e96995f1c872
CryptoSwift: c4f2debceb38bf44c80659afe009f71e23e4a082
BVLinearGradient: 612a04ff38e8480291f3379ee5b5a2c571f03fe0
CryptoSwift: d3d18dc357932f7e6d580689e065cf1f176007c1
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: a8af91c2b5a0029d12ff6b32e428863d63c48991
FBReactNativeSpec: 1b2309b096448a1dc9d0c43999216f8fda809ae8
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: d93527a855523adb8c113837db4be68fb00e230d
HMSegmentedControl: 34c1f54d822d8308e7b24f5d901ec674dfa31352
Keycard: ac6df4d91525c3c82635ac24d4ddd9a80aca5fc8
Keycard: 6356090b25a4d0e10ee50ef3075fb2cdfa97f36e
libwebp: f62cb61d0a484ba548448a4bd52aabf150ff6eef
Permission-Camera: afad27bf90337684d4a86f3825112d648c8c4d3b
Permission-Microphone: 0ffabc3fe1c75cfb260525ee3f529383c9f4368c
Expand Down Expand Up @@ -772,10 +776,10 @@ SPEC CHECKSUMS:
RNLanguages: 962e562af0d34ab1958d89bcfdb64fafc37c513e
RNPermissions: ad71dd4f767ec254f2cd57592fbee02afee75467
RNReactNativeHapticFeedback: 2566b468cc8d0e7bb2f84b23adc0f4614594d071
RNReanimated: 43adb0307a62c1ce9694f36f124ca3b51a15272a
RNReanimated: e807e10fd715e909c2088e66fc4f2975d5ad186f
RNShare: d82e10f6b7677f4b0048c23709bd04098d5aee6c
RNStaticSafeAreaInsets: 055ddbf5e476321720457cdaeec0ff2ba40ec1b8
RNSVG: 8ba35cbeb385a52fd960fd28db9d7d18b4c2974f
RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
secp256k1: f61d67e6fdcb85fd727acf1bf35ace6036db540c
Expand All @@ -785,6 +789,6 @@ SPEC CHECKSUMS:
TouchID: ba4c656d849cceabc2e4eef722dea5e55959ecf4
Yoga: d24d6184b6b85f742536bd93bd07d69d7b9bb4c1

PODFILE CHECKSUM: a7c3cb360cf217ab90667d67deeab588677d540a
PODFILE CHECKSUM: 1b60eee24bff3a6287f8b33e57657289b2966342

COCOAPODS: 1.12.1
COCOAPODS: 1.12.0
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@
"react-native-fetch-polyfill": "^1.1.2",
"react-native-fs": "^2.14.1",
"react-native-gesture-handler": "2.6.1",
"react-native-gifted-charts": "^1.3.2",
"react-native-haptic-feedback": "^1.9.0",
"react-native-hole-view": "git+https://github.com/status-im/react-native-hole-view.git#refs/tags/v2.1.3-status",
"react-native-image-crop-picker": "git+https://github.com/status-im/react-native-image-crop-picker.git#refs/tags/v0.36.2-status.0",
"react-native-image-resizer": "^1.2.3",
"react-native-image-viewing": "git+https://github.com/status-im/react-native-image-viewing.git#refs/tags/v0.2.1.status",
"react-native-keychain": "git+https://github.com/status-im/react-native-keychain.git#refs/tags/v.3.0.0-5-status",
"react-native-languages": "^3.0.2",
"react-native-linear-gradient": "^2.5.6",
"react-native-linear-gradient": "2.8.0",
"react-native-lottie-splash-screen": "^1.0.1",
"react-native-mail": "git+https://github.com/status-im/react-native-mail.git#refs/tags/v6.1.2-status",
"react-native-navigation": "^7.27.1",
Expand All @@ -65,11 +66,11 @@
"react-native-randombytes": "^3.6.1",
"react-native-reanimated": "2.11.0",
"react-native-redash": "^16.0.11",
"react-native-svg": "13.10.0",
"react-native-shake": "^3.3.1",
"react-native-share": "^8.2.2",
"react-native-static-safe-area-insets": "^2.2.0",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#refs/tags/v2.5.39",
"react-native-svg": "^9.8.4",
"react-native-touch-id": "^4.4.1",
"react-native-transparent-video": "git+https://github.com/status-im/react-native-transparent-video.git#refs/tags/0.0.9",
"react-native-webview": "git+https://github.com/status-im/react-native-webview.git#refs/tags/v11.16.0-status",
Expand Down
10 changes: 10 additions & 0 deletions src/quo2/components/graph/wallet_graph/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns quo2.components.graph.wallet-graph.style)

(def gradient-background
{:height 294
:justify-content :flex-end})

(def x-axis-label-text-style
{:margin-bottom -3
:padding-top -10
:height 0})
86 changes: 86 additions & 0 deletions src/quo2/components/graph/wallet_graph/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(ns quo2.components.graph.wallet-graph.view
(:require [quo2.theme :as theme]
[react-native.linear-gradient :as linear-gradient]
[react-native.charts :as charts]
[react-native.core :as rn]
[quo2.components.graph.wallet-graph.style :as style]
[quo2.foundations.colors :as colors]))

(defn find-highest-value
[maps]
(reduce (fn [max-value map]
(let [value (:value map)]
(if (nil? max-value) ; Check if it's the first element
value
(if (> value max-value)
value
max-value))))
nil
maps))

(defn downsample-data
[data max-array-size]
(let [data-size (count data)
aggregation-interval (max (/ data-size max-array-size) 1)]
(loop [i 0
aggregated-data []
current-aggregation []
num-points 0]
(if (>= i data-size)
(vec (reverse aggregated-data))
(let [point (nth data i)]
(if (< num-points aggregation-interval)
(recur (inc i) aggregated-data (conj current-aggregation point) (inc num-points))
(let [aggregated-value (/ (reduce + (map :value current-aggregation)) aggregation-interval)]
(recur (inc i) (conj aggregated-data {:value aggregated-value}) [point] 1))))))))

(defn- wallet-graph-internal
[{:keys [data state time-frame theme]}]
(let [max-value (find-highest-value data)
width (:width (rn/get-screen))
line-color (if (= state :positive)
(colors/theme-colors colors/success-50 colors/success-60 theme)
(colors/theme-colors colors/danger-50 colors/danger-60 theme))
gradient-colors [(colors/alpha line-color 0.1) (colors/alpha line-color 0)]
fill-color (colors/theme-colors colors/white colors/neutral-95)
max-data-points (case time-frame
:empty 0
:1-week 7
:1-month 30
:3-months 90
:1-year 365
500)
data (if (> (count data) max-data-points)
(downsample-data data max-data-points)
data)]
[linear-gradient/linear-gradient
{:colors gradient-colors
:start {:x 0 :y 1}
:end {:x 0 :y 0}
:style style/gradient-background}
[charts/line-chart
{:height 96
:width (+ width 1)
:max-value max-value
:min-value 0
:adjust-to-width true
:data data
:area-chart true
:start-fill-color fill-color
:end-fill-color fill-color
:hide-data-points true
:hide-rules true
:hide-y-axis-text true
:x-axis-indices-height 100
:thickness 2
:color line-color
:y-axis-thickness 0
:x-axis-thickness 0
:initial-spacing 0
:end-spacing 0
:disable-scroll true
:y-axis-label-width 0.01
:labels-extra-height -36
:x-axis-label-text-style style/x-axis-label-text-style}]]))

(def wallet-graph (theme/with-theme wallet-graph-internal))
4 changes: 4 additions & 0 deletions src/quo2/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
quo2.components.drawers.permission-context.view
quo2.components.dropdowns.dropdown
quo2.components.empty-state.empty-state.view
quo2.components.graph.wallet-graph.view
quo2.components.header
quo2.components.icon
quo2.components.info.info-message
Expand Down Expand Up @@ -186,6 +187,9 @@
;;;; EMPTY STATE
(def empty-state quo2.components.empty-state.empty-state.view/empty-state)

;;;; GRAPH
(def wallet-graph quo2.components.graph.wallet-graph.view/wallet-graph)

;;;; INPUTS
(def input quo2.components.inputs.input.view/input)
(def profile-input quo2.components.inputs.profile-input.view/profile-input)
Expand Down
5 changes: 5 additions & 0 deletions src/react_native/charts.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns react-native.charts
(:require ["react-native-gifted-charts" :as gifted-charts]
[reagent.core :as reagent]))

(def line-chart (reagent/adapt-react-class (.-LineChart gifted-charts)))
90 changes: 90 additions & 0 deletions src/status_im2/contexts/quo_preview/graph/wallet_graph.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(ns status-im2.contexts.quo-preview.graph.wallet-graph
(:require [quo2.core :as quo]
[quo2.foundations.colors :as colors]
[react-native.core :as rn]
[reagent.core :as reagent]
[status-im2.contexts.quo-preview.preview :as preview]))

(defn generate-crypto-token-prices
[num-elements volatility]
(loop [n num-elements
prices []
prev-price (rand-int 100000)
volatility volatility]
(if (zero? n)
(vec (reverse prices))
(let [fluctuation (* prev-price volatility)
random-delta (- (rand fluctuation) (/ fluctuation 2))
new-price (+ prev-price random-delta)
new-price (if (< new-price 1) 1 new-price)
new-prices (conj prices {:value new-price})]
(recur (dec n) new-prices new-price volatility)))))

(def descriptor
[{:label "State:"
:key :state
:type :select
:options [{:key :positive
:value "Positive"}
{:key :negative
:value "Negative"}]}
{:label "Time frame:"
:key :time-frame
:type :select
:options [{:key :empty
:value "Empty"}
{:key :1-week
:value "1 Week"}
{:key :1-month
:value "1 Month"}
{:key :3-months
:value "3 Months"}
{:key :1-year
:value "1 Year"}
{:key :all-time
:value "All time (500 years data)"}]}])

(defn generate-data
[time-frame]
(let [data-points (case time-frame
:empty 0
:1-week 7
:1-month 30
:3-months 90
:1-year 365
(* 365 500))
volatility (case time-frame
:empty 0
:1-week 2
:1-month 1
:3-months 0.5
:1-year 0.05
0.005)]
(generate-crypto-token-prices data-points volatility)))

(defn cool-preview
[]
(let [state (reagent/atom {:state :positive
:time-frame :1-week})]
(fn []
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!}
[rn/view {:padding-bottom 150}
[preview/customizer state descriptor]
[:<>
[quo/wallet-graph
{:data (generate-data (:time-frame @state))
:state (:state @state)
:time-frame (:time-frame @state)}]]]])))

(defn preview-wallet-graph
[]
[rn/view
{:background-color (colors/theme-colors
colors/white
colors/neutral-95)
:flex 1}
[rn/flat-list
{:flex 1
:keyboard-should-persist-taps :always
:header [cool-preview]
:key-fn str}]])
4 changes: 4 additions & 0 deletions src/status_im2/contexts/quo_preview/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[status-im2.contexts.quo-preview.buttons.predictive-keyboard :as predictive-keyboard]
[status-im2.contexts.quo-preview.browser.browser-input :as browser-input]
[status-im2.contexts.quo-preview.code.snippet :as code-snippet]
[status-im2.contexts.quo-preview.graph.wallet-graph :as wallet-graph]
[status-im2.contexts.quo-preview.colors.color-picker :as color-picker]
[status-im2.contexts.quo-preview.community.community-card-view :as community-card]
[status-im2.contexts.quo-preview.community.community-membership-list-view :as
Expand Down Expand Up @@ -203,6 +204,9 @@
:empty-state [{:name :empty-state
:options {:topBar {:visible true}}
:component empty-state/preview-empty-state}]
:graph [{:name :wallet-graph
:options {:topBar {:visible true}}
:component wallet-graph/preview-wallet-graph}]
:info [{:name :info-message
:options {:topBar {:visible true}}
:component info-message/preview-info-message}
Expand Down
Loading

0 comments on commit 40069b4

Please sign in to comment.