Skip to content

Commit 2605588

Browse files
authored
Refactor demo into individual examples and update gallery (#179)
Demo gallery has been updated to show example thumbnail and source code. Examples have been split to be separately in `examples/` directory, with metadata provided by `PlotExample` trait that are consumed by the demo gallery.
1 parent f436cd7 commit 2605588

File tree

127 files changed

+3107
-1685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+3107
-1685
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ jobs:
137137
uses: Swatinem/rust-cache@v2
138138

139139
- name: Run tests
140-
run: cargo test --all-features
140+
run: RUST_BACKTRACE=1 cargo test --all-features
141141

142142
- name: Run doc-tests
143-
run: cargo test --all-features --doc
143+
run: RUST_BACKTRACE=1 cargo test --all-features --doc
144144

145145
- name: Upload artifacts
146146
uses: actions/upload-artifact@v4

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ let Some(first) = vec.first() else {
121121
return;
122122
};
123123
```
124+
125+
### Example Screenshots
126+
127+
- Each crate under `examples/` has a screenshot test generated by the `examples_utils::make_main!` macro.
128+
- Update a screenshot locally with `UPDATE_SNAPSHOTS=1 cargo test -p <example_name>`.
129+
- The refreshed image is written to `examples/<example_name>/screenshot.png`; `.diff.png` / `.new.png` helpers stay untracked for local review.

Cargo.lock

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,17 @@ dependencies = [
588588
"eframe",
589589
"egui_plot",
590590
"env_logger",
591+
"examples_utils",
592+
]
593+
594+
[[package]]
595+
name = "box_plot"
596+
version = "0.1.0"
597+
dependencies = [
598+
"eframe",
599+
"egui_plot",
600+
"env_logger",
601+
"examples_utils",
591602
]
592603

593604
[[package]]
@@ -855,26 +866,51 @@ version = "1.2.0"
855866
source = "registry+https://github.com/rust-lang/crates.io-index"
856867
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
857868

869+
[[package]]
870+
name = "custom_axes"
871+
version = "0.1.0"
872+
dependencies = [
873+
"eframe",
874+
"egui_plot",
875+
"env_logger",
876+
"examples_utils",
877+
]
878+
858879
[[package]]
859880
name = "custom_plot_manipulation"
860881
version = "0.1.0"
861882
dependencies = [
862883
"eframe",
863884
"egui_plot",
864885
"env_logger",
886+
"examples_utils",
865887
]
866888

867889
[[package]]
868890
name = "demo"
869891
version = "0.34.0"
870892
dependencies = [
893+
"borrow_points",
894+
"box_plot",
895+
"custom_axes",
896+
"custom_plot_manipulation",
871897
"eframe",
872898
"egui",
873-
"egui_kittest",
874-
"egui_plot",
899+
"egui_chip",
875900
"env_logger",
901+
"examples_utils",
902+
"histogram",
903+
"image",
904+
"interaction",
905+
"items",
906+
"legend",
907+
"legend_sort",
908+
"lines",
909+
"linked_axes",
876910
"log",
877-
"serde",
911+
"markers",
912+
"save_plot",
913+
"stacked_bar",
878914
"wasm-bindgen-futures",
879915
"web-sys",
880916
]
@@ -1065,6 +1101,18 @@ dependencies = [
10651101
"winit",
10661102
]
10671103

1104+
[[package]]
1105+
name = "egui_chip"
1106+
version = "0.3.1"
1107+
source = "registry+https://github.com/rust-lang/crates.io-index"
1108+
checksum = "17e35f20a867cf197c0ccbd0618aa54808ac882173d9ffac7950199e0d5445af"
1109+
dependencies = [
1110+
"egui",
1111+
"serde",
1112+
"wasm-bindgen-futures",
1113+
"web-sys",
1114+
]
1115+
10681116
[[package]]
10691117
name = "egui_glow"
10701118
version = "0.33.0"
@@ -1255,6 +1303,15 @@ dependencies = [
12551303
"pin-project-lite",
12561304
]
12571305

1306+
[[package]]
1307+
name = "examples_utils"
1308+
version = "0.1.0"
1309+
dependencies = [
1310+
"eframe",
1311+
"egui",
1312+
"egui_kittest",
1313+
]
1314+
12581315
[[package]]
12591316
name = "fastrand"
12601317
version = "2.3.0"
@@ -1639,6 +1696,16 @@ version = "0.2.1"
16391696
source = "registry+https://github.com/rust-lang/crates.io-index"
16401697
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
16411698

1699+
[[package]]
1700+
name = "histogram"
1701+
version = "0.1.0"
1702+
dependencies = [
1703+
"eframe",
1704+
"egui_plot",
1705+
"env_logger",
1706+
"examples_utils",
1707+
]
1708+
16421709
[[package]]
16431710
name = "home"
16441711
version = "0.5.11"
@@ -1779,6 +1846,16 @@ dependencies = [
17791846
"hashbrown 0.15.5",
17801847
]
17811848

1849+
[[package]]
1850+
name = "interaction"
1851+
version = "0.1.0"
1852+
dependencies = [
1853+
"eframe",
1854+
"egui_plot",
1855+
"env_logger",
1856+
"examples_utils",
1857+
]
1858+
17821859
[[package]]
17831860
name = "is-docker"
17841861
version = "0.2.0"
@@ -1804,6 +1881,16 @@ version = "1.70.1"
18041881
source = "registry+https://github.com/rust-lang/crates.io-index"
18051882
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
18061883

1884+
[[package]]
1885+
name = "items"
1886+
version = "0.1.0"
1887+
dependencies = [
1888+
"eframe",
1889+
"egui_plot",
1890+
"env_logger",
1891+
"examples_utils",
1892+
]
1893+
18071894
[[package]]
18081895
name = "jiff"
18091896
version = "0.2.15"
@@ -1904,13 +1991,24 @@ version = "1.5.0"
19041991
source = "registry+https://github.com/rust-lang/crates.io-index"
19051992
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
19061993

1994+
[[package]]
1995+
name = "legend"
1996+
version = "0.1.0"
1997+
dependencies = [
1998+
"eframe",
1999+
"egui_plot",
2000+
"env_logger",
2001+
"examples_utils",
2002+
]
2003+
19072004
[[package]]
19082005
name = "legend_sort"
19092006
version = "0.1.0"
19102007
dependencies = [
19112008
"eframe",
19122009
"egui_plot",
19132010
"env_logger",
2011+
"examples_utils",
19142012
]
19152013

19162014
[[package]]
@@ -1946,6 +2044,26 @@ dependencies = [
19462044
"redox_syscall 0.5.17",
19472045
]
19482046

2047+
[[package]]
2048+
name = "lines"
2049+
version = "0.1.0"
2050+
dependencies = [
2051+
"eframe",
2052+
"egui_plot",
2053+
"env_logger",
2054+
"examples_utils",
2055+
]
2056+
2057+
[[package]]
2058+
name = "linked_axes"
2059+
version = "0.1.0"
2060+
dependencies = [
2061+
"eframe",
2062+
"egui_plot",
2063+
"env_logger",
2064+
"examples_utils",
2065+
]
2066+
19492067
[[package]]
19502068
name = "linux-raw-sys"
19512069
version = "0.4.15"
@@ -1994,6 +2112,16 @@ dependencies = [
19942112
"libc",
19952113
]
19962114

2115+
[[package]]
2116+
name = "markers"
2117+
version = "0.1.0"
2118+
dependencies = [
2119+
"eframe",
2120+
"egui_plot",
2121+
"env_logger",
2122+
"examples_utils",
2123+
]
2124+
19972125
[[package]]
19982126
name = "memchr"
19992127
version = "2.7.5"
@@ -2924,6 +3052,7 @@ dependencies = [
29243052
"eframe",
29253053
"egui_plot",
29263054
"env_logger",
3055+
"examples_utils",
29273056
"image",
29283057
"rfd",
29293058
]
@@ -3096,6 +3225,16 @@ version = "1.2.0"
30963225
source = "registry+https://github.com/rust-lang/crates.io-index"
30973226
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
30983227

3228+
[[package]]
3229+
name = "stacked_bar"
3230+
version = "0.1.0"
3231+
dependencies = [
3232+
"eframe",
3233+
"egui_plot",
3234+
"env_logger",
3235+
"examples_utils",
3236+
]
3237+
30993238
[[package]]
31003239
name = "static_assertions"
31013240
version = "1.1.0"

Cargo.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["egui_plot", "demo", "examples/*"]
3+
members = ["egui_plot", "demo", "examples/*", "examples_utils"]
44

55

66
[workspace.package]
@@ -20,6 +20,22 @@ opt-level = 2
2020

2121
[workspace.dependencies]
2222
egui_plot = { version = "0.34.0", path = "egui_plot", default-features = false }
23+
examples_utils = { version = "0.1.0", path = "examples_utils" }
24+
25+
borrow_points = { version = "0.1.0", path = "examples/borrow_points" }
26+
box_plot = { version = "0.1.0", path = "examples/box_plot" }
27+
custom_axes = { version = "0.1.0", path = "examples/custom_axes" }
28+
custom_plot_manipulation = { version = "0.1.0", path = "examples/custom_plot_manipulation" }
29+
histogram = { version = "0.1.0", path = "examples/histogram" }
30+
interaction = { version = "0.1.0", path = "examples/interaction" }
31+
items = { version = "0.1.0", path = "examples/items" }
32+
legend = { version = "0.1.0", path = "examples/legend" }
33+
legend_sort = { version = "0.1.0", path = "examples/legend_sort" }
34+
lines = { version = "0.1.0", path = "examples/lines" }
35+
linked_axes = { version = "0.1.0", path = "examples/linked_axes" }
36+
markers = { version = "0.1.0", path = "examples/markers" }
37+
save_plot = { version = "0.1.0", path = "examples/save_plot" }
38+
stacked_bar = { version = "0.1.0", path = "examples/stacked_bar" }
2339

2440
ahash = { version = "0.8.11", default-features = false, features = [
2541
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead

Makefile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
THREADS ?= $(shell nproc)
33
BROWSER ?= firefox
44
TRUNK_OPTS ?=
5-
CARGO_OPTS ?= --verbose -j $(THREADS)
5+
CARGO_OPTS ?= -j $(THREADS)
66

77
export RUST_LOG ?= debug
88
export CARGO_TERM_COLOR ?= always
@@ -25,6 +25,7 @@ CARGO_TOOLS = \
2525
2626
2727
28+
2829
2930
3031

@@ -61,6 +62,7 @@ dry_push: check_branch_name \
6162
build \
6263
run_checks \
6364
test \
65+
trunk \
6466
check_git_clean_status
6567
echo "All checks passed, ready to push."
6668

@@ -79,7 +81,6 @@ build_linux:
7981
build_wasm:
8082
cargo build -p egui_plot -p demo --all-features --lib --tests --bins --examples --target $(TARGET_WASM) $(CARGO_OPTS) $(BUILD_PROFILE)
8183

82-
# Builds the frontend using trunk.
8384
trunk:
8485
trunk build $(TRUNK_OPTS)
8586

@@ -116,6 +117,8 @@ run_checks: check_no_commented_out_code \
116117
check_license \
117118
check_cycles \
118119
checks_no_unfinished \
120+
check_shear \
121+
check_deny \
119122
check_pub_change_intentional
120123

121124
# Performs a compilation check of all crates in the workspace, without building.
@@ -133,9 +136,9 @@ check_newlines:
133136
# Runs clippy on all crates in the workspace.
134137
check_clippy: check_clippy_linux check_clippy_wasm
135138
check_clippy_linux:
136-
cargo clippy --workspace --no-deps --examples --target $(TARGET_LINUX) -j $(THREADS) $(BUILD_PROFILE) -- -D warnings
139+
cargo clippy --workspace --no-deps --examples --lib --target $(TARGET_LINUX) -j $(THREADS) $(BUILD_PROFILE) -- -D warnings
137140
check_clippy_wasm:
138-
cargo clippy -p demo -p egui_plot --no-deps --examples --target $(TARGET_WASM) -j $(THREADS) $(BUILD_PROFILE) -- -D warnings
141+
cargo clippy -p demo -p egui_plot --no-deps --examples --lib --target $(TARGET_WASM) -j $(THREADS) $(BUILD_PROFILE) -- -D warnings
139142
check_clippy_docs: check_clippy_docs_linux check_clippy_docs_wasm
140143
check_clippy_docs_linux:
141144
cargo clippy --workspace --no-deps --message-format=short --target $(TARGET_LINUX) -j $(THREADS) $(BUILD_PROFILE) -- -D missing-docs 2>&1 | grep -P 'mod.rs|lib.rs' | grep -vP 'crate|module' && exit 1 || exit 0
@@ -148,7 +151,7 @@ check_license:
148151

149152
# Checks for dependency cycles between modules.
150153
check_cycles:
151-
cargo-cycles --verbose
154+
cargo-cycles
152155

153156
check_pub_change_intentional:
154157
if [ "$$(cargo public-api diff latest -p egui_plot -sss --deny all)" != "" ]; then \
@@ -200,6 +203,12 @@ check_no_commented_out_code:
200203
# There should not be commented out code
201204
git ls-files | grep -P '\.rs$$' | xargs grep -Pi '^\s*//(?!/|\!)\S' || exit 0; exit 1
202205

206+
check_shear:
207+
cargo shear
208+
209+
check_deny:
210+
cargo deny check
211+
203212
clean:
204213
cargo clean
205214
trunk clean

0 commit comments

Comments
 (0)