cleanup + git commit info

This commit is contained in:
Simon Gardling 2022-02-24 20:47:15 -05:00
parent 1ddc3774a1
commit 6f8a7c9cc2
7 changed files with 51 additions and 50 deletions

View File

@ -4,3 +4,18 @@ wasm-pack build --target web --release --no-typescript
wasm-opt -Oz -o pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm
mv pkg/integral_site_bg_2.wasm pkg/integral_site_bg.wasm
llvm-strip --strip-all pkg/integral_site_bg.wasm
rm -fr tmp | true #delete tmp folder if exists
mkdir tmp tmp/pkg
cp -r pkg/integral_site_bg.wasm pkg/integral_site.js tmp/pkg/
cp www/index.html www/style.css tmp/
sed -i 's/\.\.\/pkg/\.\/pkg/g' tmp/index.html
git ls-files --exclude-standard --others . >/dev/null 2>&1; ec=$?
if test "$ec" = 0; then
echo some untracked files
elif test "$ec" = 1; then
commit=$(git rev-parse HEAD)
sed -i "s/let commit = ''/let commit = '${commit}'/g" tmp/index.html
fi

14
push.sh
View File

@ -3,20 +3,6 @@ set -e #kill script if error occurs
bash build.sh
rm -fr tmp | true #delete tmp folder if exists
mkdir tmp tmp/pkg
cp -r pkg/integral_site_bg.wasm pkg/integral_site.js tmp/pkg/
cp www/index.html www/style.css tmp/
sed -i 's/\.\.\/pkg/\.\/pkg/g' tmp/index.html
# put the commit at the beginning of index.html
mv tmp/index.html tmp/index.html.bak
commit_comment="<!-- Commit: $(git rev-parse HEAD) -->"
echo $commit_comment > tmp/index.html
cat tmp/index.html.bak >> tmp/index.html
rm -fr tmp/index.html.bak
echo "rsyncing"
rsync -av --delete --info=progress2 tmp/ rpi-public:/mnt/hdd/http_share/integral-demo/
rsync -av --delete --info=progress2 --exclude=".git" tmp/ ../integral-demo/

View File

@ -5,7 +5,7 @@ use crate::misc::{digits_precision, test_func, Cache};
use eframe::{egui, epi};
use egui::plot::{Line, Plot, Value, Values};
use egui::widgets::plot::{Bar, BarChart};
use egui::Color32;
use egui::{Color32, TextStyle, Vec2, Layout};
pub struct MathApp {
func_str: String,
@ -16,10 +16,11 @@ pub struct MathApp {
chart_manager: ChartManager,
back_cache: Cache<Vec<Value>>,
front_cache: Cache<(Vec<Bar>, f64)>,
commit: String
}
impl Default for MathApp {
fn default() -> Self {
impl MathApp {
pub fn new(commit: String) -> Self {
let def_func = "x^2".to_string();
let def_min_x = -10.0;
let def_max_x = 10.0;
@ -35,11 +36,10 @@ impl Default for MathApp {
chart_manager: ChartManager::new(def_func, def_min_x, def_max_x, def_interval, def_resolution),
back_cache: Cache::new_empty(),
front_cache: Cache::new_empty(),
commit
}
}
}
impl MathApp {
#[inline]
fn get_back(&mut self) -> Line {
let data = if self.back_cache.is_valid() {
@ -102,15 +102,25 @@ impl epi::App for MathApp {
chart_manager,
back_cache,
front_cache,
commit,
} = self;
// Note: This Instant implementation does not show microseconds when using wasm.
let start = instant::Instant::now();
// Cute little window that lists supported functions!
// TODO: add more detail
egui::Window::new("Supported Functions").show(ctx, |ui| {
ui.label("- sqrt, abs");
ui.label("- exp, ln, log10 (log10 can also be called as log)");
ui.label("- sin, cos, tan, asin, acos, atan, atan2");
ui.label("- sinh, cosh, tanh, asinh, acosh, atanh");
ui.label("- floor, ceil, round");
ui.label("- signum, min, max");
});
let mut parse_error: String = "".to_string();
egui::SidePanel::left("side_panel").show(ctx, |ui| {
egui::SidePanel::left("side_panel").resizable(false).show(ctx, |ui| {
ui.heading("Side Panel");
ui.horizontal(|ui| {
@ -140,11 +150,21 @@ impl epi::App for MathApp {
}
ui.add(egui::Slider::new(num_interval, NUM_INTERVAL_RANGE).text("Interval"));
// ui.add_space(ui.text_style_height(&TextStyle::Body)*10.0);
ui.hyperlink_to(
"I'm Opensource! (and licensed under AGPLv3)",
"https://github.com/Titaniumtown/integral_site",
);
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::top_down_justified(egui::Align::Min), |ui| {
if commit.is_empty() {
ui.label(format!("Current build is untracked!"));
} else {
ui.label("Commit: ");
ui.hyperlink_to(commit.clone(), format!("https://github.com/Titaniumtown/integral_site/commit/{}", commit));
}
});
});
});
if parse_error.is_empty() {
@ -189,16 +209,5 @@ impl epi::App for MathApp {
duration
));
});
// Cute little window that lists supported functions!
// TODO: add more detail
egui::Window::new("Supported Functions").show(ctx, |ui| {
ui.label("- sqrt, abs");
ui.label("- exp, ln, log10 (log10 can also be called as log)");
ui.label("- sin, cos, tan, asin, acos, atan, atan2");
ui.label("- sinh, cosh, tanh, asinh, acosh, atanh");
ui.label("- floor, ceil, round");
ui.label("- signum, min, max");
});
}
}

View File

@ -23,7 +23,7 @@ extern "C" {
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
pub fn start(canvas_id: &str, commit: &str) -> Result<(), wasm_bindgen::JsValue> {
log("Initializing...");
// See performance in browser profiler!
@ -39,6 +39,6 @@ pub fn start(canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
log("Finished initializing!");
log("Starting App...");
let app = egui_app::MathApp::default();
let app = egui_app::MathApp::new(commit.to_string());
eframe::start_web(canvas_id, Box::new(app))
}

View File

@ -7,7 +7,7 @@ mod misc;
// For running the program natively! (Because why not?)
#[cfg(not(target_arch = "wasm32"))]
fn main() {
let app = egui_app::MathApp::default();
let app = egui_app::MathApp::new("".to_string());
let options = eframe::NativeOptions {
// Let's show off that we support transparent windows
transparent: true,

View File

@ -3,13 +3,4 @@ set -e
bash build.sh
rustup target add wasm32-unknown-unknown
if [ -z "$(cargo install --list | grep wasm-pack)" ]
then
cargo install wasm-pack
fi
wasm-pack build --release --target web --no-typescript
basic-http-server
basic-http-server tmp/

View File

@ -5,7 +5,6 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Integral Demonstration</title>
<link rel="stylesheet" href="style.css">
</head>
@ -18,9 +17,10 @@
import init, { start } from '../pkg/integral_site.js';
async function run() {
await init();
start("canvas");
await init();
let commit = '';
start("canvas", commit);
}
run();
</script>