From 10fa9395581bf9b86bef1db66badc614f1a5cd18 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Thu, 19 Sep 2024 15:10:46 +0200 Subject: [PATCH] Make proper line chart with random data --- src-tauri/Cargo.lock | 3 +++ src-tauri/Cargo.toml | 1 + src-tauri/src/main.rs | 24 +++++++++++++--------- src/components/Graph.vue | 43 ++++++++++++++++++++++++++++++---------- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 36287c2..ca8b2cc 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -306,8 +306,10 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.6", ] @@ -2731,6 +2733,7 @@ dependencies = [ name = "tauri-eval" version = "0.1.0" dependencies = [ + "chrono", "rand 0.8.5", "serde", "serde_json", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 359df62..5b31754 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -15,6 +15,7 @@ tauri = { version = "1", features = ["shell-open"] } serde = { version = "1", features = ["derive"] } serde_json = "1" rand = "0.8.5" +chrono = "0.4.38" [features] # This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!! diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 9ee168f..9cce092 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,7 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use chrono::prelude::*; use rand::Rng; use serde::Serialize; @@ -11,20 +12,25 @@ fn greet(name: &str) -> String { } #[derive(Serialize)] -struct Dataset { - data: [u8; 3], +struct DataPoint { + value: f32, + timestamp: String, } #[tauri::command] -fn random_data() -> Dataset { +fn random_data() -> Vec { let mut rng = rand::thread_rng(); - Dataset { - data: [ - rng.gen_range(0..100), - rng.gen_range(0..100), - rng.gen_range(0..100), - ], + + let mut data: Vec = Vec::with_capacity(100); + + for _ in 0..100 { + data.push(DataPoint { + value: rng.gen_range(0..100) as f32, + timestamp: Utc::now().format("%H:%M:%S").to_string(), + }) } + + data } fn main() { diff --git a/src/components/Graph.vue b/src/components/Graph.vue index 55d46c1..badbbc3 100644 --- a/src/components/Graph.vue +++ b/src/components/Graph.vue @@ -1,18 +1,23 @@