!PNVJpPVfXjgFKGFolb:matrix.org

Ratatui General

575 Members
A Rust crate for cooking up Terminal User Interfaces https://ratatui.rs17 Servers

Load older messages


SenderMessageTime
3 Jun 2024
@_discord_820173014044901406:t2bot.io_desligado joined the room.17:56:12
@_discord_512504899817308180:t2bot.iodekirisu joined the room.18:09:47
@yuirivict:matrix.orgyuri@FreeBSD

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)]));
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data)
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
23:51:07
@yuirivict:matrix.orgyuri@FreeBSD *

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)])); // static array here
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data) // dynamic array here
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
23:51:54
4 Jun 2024
@yuirivict:matrix.orgyuri@FreeBSD *

How to fill datasets for the Chart object dynamically?

This code with static dataset elements (like in Ratatui examples) compiles fine:

pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&[(1., 2.), (3., 4.)])); // static array here
    }
    
    let chart = Chart::new(datasets);
}   

but a similar code with the dynamic array fails:

pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
    let mut datasets = Vec::new();
    
    for n in 1..10 {
        let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
        datasets.push(
            Dataset::default()
            .marker(Marker::Braille)
            .style(Style::default().fg(Color::Red))
            .graph_type(GraphType::Line)
            .data(&data) // dynamic array here
        );
    }
    
    let chart = Chart::new(datasets);
}   

It fails like this:

53 |             let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
   |                 ---- binding `data` declared here
...
60 |                 .data(data.as_slice())
   |                       ^^^^ borrowed value does not live long enough
...
63 |         }
   |         - `data` dropped here while still borrowed
01:37:49
7 Jun 2024
@awiteb:4rs.nl@awiteb:4rs.nl joined the room.11:45:50
@awiteb:4rs.nl@awiteb:4rs.nl left the room.11:51:06
@awiteb:4rs.nl@awiteb:4rs.nl joined the room.11:51:21
@awiteb:4rs.nl@awiteb:4rs.nl left the room.11:52:56
8 Jun 2024
@max_ishere:matrix.orgmax_ishere changed their profile picture.10:12:18
11 Jun 2024
@azizemir:matrix.orgAziz Emir joined the room.16:51:35
19 Jun 2024
@burntk:matrix.orgSam O’nella joined the room.05:39:48
21 Jun 2024
@auronandace:matrix.org@auronandace:matrix.org left the room.08:18:48
23 Jun 2024
@joao00066joao:matrix.org@joao00066joao:matrix.org joined the room.18:59:05
@joao00066joao:matrix.org@joao00066joao:matrix.org left the room.18:59:58
27 Jun 2024
@alemi:alemi.dev@alemi:alemi.dev left the room.16:19:47
29 Jun 2024
@burntk:matrix.orgSam O’nella changed their display name from burntkrispe to BurntKrispe.05:28:40
30 Jun 2024
@avery71:matrix.orgAvery set a profile picture.00:06:06
@avery71:matrix.orgAvery changed their profile picture.00:07:44
@avery71:matrix.orgAvery set their display name to Avery.01:29:06
8 Jul 2024
@burntk:matrix.orgSam O’nella changed their display name from BurntKrispe to Sam O’nella.04:55:28
@burntk:matrix.orgSam O’nella changed their profile picture.16:45:13
10 Jul 2024
@modev:bsd.cafe@modev:bsd.cafe joined the room.14:58:54
11 Jul 2024
@modev:bsd.cafe@modev:bsd.cafe left the room.04:08:46
@Ninmi:matrix.orgNinmi joined the room.21:49:55
12 Jul 2024
@yak0yakee0d:matrix.orgyak0yakee0d joined the room.00:11:36
@yak0yakee0d:matrix.orgyak0yakee0dHi there!00:12:12
@mur1chan:sakura.pm@mur1chan:sakura.pm left the room.05:57:00
14 Jul 2024
@stappers:fosdem.orgstappersWelcome18:43:30
19 Jul 2024
@ammernico:matrix.niko.moeNico joined the room.10:49:28

There are no newer messages yet.


Back to Room ListRoom Version: 10