Skip to content

Commit 02f0180

Browse files
committed
📝 update examples for new api
1 parent 129b471 commit 02f0180

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

examples/fetch-from-binance.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,22 @@ fn main() -> Result<(), Box<dyn Error>> {
3030
candle.high.parse::<f64>().unwrap(),
3131
candle.low.parse::<f64>().unwrap(),
3232
candle.close.parse::<f64>().unwrap(),
33+
Some(candle.volume.parse::<f64>().unwrap()),
34+
Some(candle.open_time as i64),
3335
)
3436
})
3537
.collect::<Vec<Candle>>();
3638

3739
let mut chart = Chart::new(&candles);
3840

39-
// Set the chart title
4041
chart.set_name(String::from("BTC/USDT"));
41-
42-
// Set customs colors
43-
chart.set_bear_color(1, 205, 254);
44-
chart.set_bull_color(255, 107, 153);
42+
chart.set_bull_color(1, 205, 254);
43+
chart.set_bear_color(255, 107, 153);
44+
chart.set_vol_bull_color(1, 205, 254);
45+
chart.set_vol_bear_color(255, 107, 153);
46+
chart.set_volume_pane_height(5);
47+
chart.set_volume_pane_enabled(true);
48+
chart.set_volume_pane_unicode_fill('🚀');
4549

4650
chart.draw();
4751

src/chart.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::{borrow::BorrowMut, cell::RefCell, rc::Rc};
2-
31
use crate::{
42
chart_data::ChartData, chart_renderer::ChartRenderer, info_bar::InfoBar,
53
volume_pane::VolumePane, y_axis::YAxis,
64
};
5+
use std::cell::RefCell;
6+
use std::rc::Rc;
77

88
#[derive(Debug, Clone)]
99
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
@@ -69,10 +69,7 @@ impl Chart {
6969
(chart_data.borrow().terminal_size.1 / 6) as i64,
7070
);
7171

72-
chart_data
73-
.borrow_mut()
74-
.get_mut()
75-
.compute_height(&volume_pane);
72+
chart_data.borrow_mut().compute_height(&volume_pane);
7673

7774
Chart {
7875
renderer,

src/chart_renderer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ impl ChartRenderer {
8888
pub fn render(&self, chart: &Chart) {
8989
let mut output_str = "".to_owned();
9090

91-
let chart_data = chart.chart_data.borrow();
92-
91+
let mut chart_data = chart.chart_data.borrow_mut();
9392
chart_data.compute_height(&chart.volume_pane);
93+
drop(chart_data);
94+
95+
let chart_data = chart.chart_data.borrow();
9496

9597
for y in (1..chart_data.height as u16).rev() {
9698
output_str += "\n";

0 commit comments

Comments
 (0)