move text stuff to json
This commit is contained in:
parent
1fd234d33d
commit
781aced325
@ -30,6 +30,7 @@ exmex = { git = "https://github.com/bertiqwerty/exmex.git", branch = "main", fea
|
||||
lazy_static = "1.4.0"
|
||||
tar = "0.4.38"
|
||||
ruzstd = { git = "https://github.com/KillingSpark/zstd-rs.git" }
|
||||
serde_json = "1.0.79"
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = "0.9"
|
||||
|
||||
37
assets/text.json
Normal file
37
assets/text.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"help_expr": [
|
||||
"- sqrt(x): square root of x",
|
||||
"- abs(x): absolute value of x",
|
||||
"- ln(x): log with base e",
|
||||
"- log10(x): base 10 logarithm of x",
|
||||
"- log(x): same as log10(x)",
|
||||
"- sin(x): Sine of x",
|
||||
"- cos(x): Cosine of x",
|
||||
"- tan(x): Tangent of x",
|
||||
"- asin(x): arcsine of x",
|
||||
"- acos(x): arccosine of x",
|
||||
"- atan(x): arctangent of x",
|
||||
"- atan2, sinh, cosh, tanh, asinh, acosh, atanh",
|
||||
"- floor, ceil, round, signum"
|
||||
],
|
||||
"help_vars": [
|
||||
"- Euler's number is supported via 'E' (note it being uppercase)",
|
||||
"- PI is available through 'pi' or 'π'"
|
||||
],
|
||||
"help_panel": [
|
||||
"- The 'Panel' button on the top bar toggles if the side bar should be shown or not.",
|
||||
"- The 'Add Function' button on the top panel adds a new function to be graphed. You can then configure that function in the side panel.",
|
||||
"- The 'Help' button on the top bar opens and closes this window!",
|
||||
"- The 'Info' button provides information on the build currently running.",
|
||||
"- The Sun/Moon button toggles Dark and Light mode."
|
||||
],
|
||||
"help_function": [
|
||||
"- The 'X' button before the '∫' button allows you to delete the function in question. Deleting a function is prevented if only 1 function exists.",
|
||||
"- The ∫ button (between the 'X' and 'd/dx' buttons) indicates whether to integrate the function in question.",
|
||||
"- The 'd/dx' button next to the function input indicates whether or not calculating the derivative is enabled or not."
|
||||
],
|
||||
"help_other": [
|
||||
"- Extrema (local minimums and maximums) and Roots (intersections with the x-axis) are displayed though yellow and light blue points on the graph. You can toggle these in the Side Panel.",
|
||||
"- In some edge cases, math functions may not parse correctly. More specifically with implicit multiplication. If you incounter this issue, please do report it on the project's Github page (linked on the side panel). But a current workaround would be explicitly stating a multiplication operation through the use of an asterisk."
|
||||
]
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
- sqrt(x): square root of x
|
||||
- abs(x): absolute value of x
|
||||
- ln(x): log with base e
|
||||
- log10(x): base 10 logarithm of x
|
||||
- log(x): same as log10(x)
|
||||
- sin(x): Sine of x
|
||||
- cos(x): Cosine of x
|
||||
- tan(x): Tangent of x
|
||||
- asin(x): arcsine of x
|
||||
- acos(x): arccosine of x
|
||||
- atan(x): arctangent of x
|
||||
- atan2, sinh, cosh, tanh, asinh, acosh, atanh
|
||||
- floor, ceil, round, signum
|
||||
@ -1,3 +0,0 @@
|
||||
- The 'X' button before the '∫' button allows you to delete the function in question. Deleting a function is prevented if only 1 function exists.
|
||||
- The ∫ button (between the 'X' and 'd/dx' buttons) indicates whether to integrate the function in question.
|
||||
- The 'd/dx' button next to the function input indicates whether or not calculating the derivative is enabled or not.
|
||||
@ -1,2 +0,0 @@
|
||||
- Extrema (local minimums and maximums) and Roots (intersections with the x-axis) are displayed though yellow and light blue points on the graph. You can toggle these in the Side Panel.
|
||||
- In some edge cases, math functions may not parse correctly. More specifically with implicit multiplication. If you incounter this issue, please do report it on the project's Github page (linked on the side panel). But a current workaround would be explicitly stating a multiplication operation through the use of an asterisk.
|
||||
@ -1,5 +0,0 @@
|
||||
- The 'Panel' button on the top bar toggles if the side bar should be shown or not.
|
||||
- The 'Add Function' button on the top panel adds a new function to be graphed. You can then configure that function in the side panel.
|
||||
- The 'Help' button on the top bar opens and closes this window!
|
||||
- The 'Info' button provides information on the build currently running.
|
||||
- The Sun/Moon button toggles Dark and Light mode.
|
||||
@ -1,2 +0,0 @@
|
||||
- Euler's number is supported via 'E' (note it being uppercase)
|
||||
- PI is available through 'pi' or 'π'
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTION_ENTRY};
|
||||
use crate::misc::{debug_log, log_helper};
|
||||
use crate::misc::{debug_log, log_helper, parse_value};
|
||||
use crate::parsing::{process_func_str, test_func};
|
||||
|
||||
use const_format::formatc;
|
||||
@ -11,6 +11,7 @@ use egui::{
|
||||
};
|
||||
use epi::{Frame, Storage};
|
||||
use instant::Duration;
|
||||
use serde_json::Value;
|
||||
use shadow_rs::shadow;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
@ -112,24 +113,18 @@ lazy_static::lazy_static! {
|
||||
panic!("Font File {} not expected!", path_string);
|
||||
}
|
||||
}
|
||||
} else if path_string.ends_with(".txt") {
|
||||
// Parse text files
|
||||
} else if path_string.ends_with(".json") {
|
||||
// Parse json file
|
||||
let string_data = str::from_utf8(&data).unwrap().to_string();
|
||||
match path_string.as_ref() {
|
||||
"text_help_expr.txt" => {
|
||||
text_help_expr = Some(string_data);
|
||||
},
|
||||
"text_help_vars.txt" => {
|
||||
text_help_vars = Some(string_data);
|
||||
},
|
||||
"text_help_panel.txt" => {
|
||||
text_help_panel = Some(string_data);
|
||||
},
|
||||
"text_help_function.txt" => {
|
||||
text_help_function = Some(string_data);
|
||||
},
|
||||
"text_help_other.txt" => {
|
||||
text_help_other = Some(string_data);
|
||||
"text.json" => {
|
||||
let json_data: Value = serde_json::from_str(&string_data).unwrap();
|
||||
text_help_expr = Some(parse_value(&json_data["help_expr"]));
|
||||
text_help_vars = Some(parse_value(&json_data["help_vars"]));
|
||||
text_help_panel = Some(parse_value(&json_data["help_panel"]));
|
||||
text_help_function = Some(parse_value(&json_data["help_function"]));
|
||||
text_help_other = Some(parse_value(&json_data["help_other"]));
|
||||
|
||||
},
|
||||
_ => {
|
||||
panic!("Text file {} not expected!", path_string);
|
||||
@ -197,25 +192,28 @@ fn test_file_data() {
|
||||
FontData::from_owned(include_bytes!("../assets/Hack-Regular.ttf").to_vec())
|
||||
);
|
||||
|
||||
let json_data: Value = serde_json::from_str(&include_str!("../assets/text.json")).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
FILE_DATA.text_help_expr,
|
||||
include_str!("../assets/text_help_expr.txt")
|
||||
parse_value(&json_data["help_expr"])
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
FILE_DATA.text_help_vars,
|
||||
include_str!("../assets/text_help_vars.txt")
|
||||
parse_value(&json_data["help_vars"])
|
||||
);
|
||||
assert_eq!(
|
||||
FILE_DATA.text_help_panel,
|
||||
include_str!("../assets/text_help_panel.txt")
|
||||
parse_value(&json_data["help_panel"])
|
||||
);
|
||||
assert_eq!(
|
||||
FILE_DATA.text_help_function,
|
||||
include_str!("../assets/text_help_function.txt")
|
||||
parse_value(&json_data["help_function"])
|
||||
);
|
||||
assert_eq!(
|
||||
FILE_DATA.text_help_other,
|
||||
include_str!("../assets/text_help_other.txt")
|
||||
parse_value(&json_data["help_other"])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
14
src/misc.rs
14
src/misc.rs
@ -179,3 +179,17 @@ pub fn newtons_method(
|
||||
}
|
||||
output_list
|
||||
}
|
||||
|
||||
pub fn parse_value(value: &serde_json::Value) -> String {
|
||||
let string_vector: Vec<&str> = value
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|ele| ele.as_str().unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
string_vector
|
||||
.iter()
|
||||
.fold(String::new(), |s, l| s + l + "\n")
|
||||
.trim()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user