Skip to content

Commit b15b5e4

Browse files
committed
Code review fixes
1 parent f5a0d9d commit b15b5e4

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

tools/crate-hierarchy-viz/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ fn collect_all_dependencies(crate_name: &str, dep_map: &HashMap<String, HashSet<
8383
}
8484

8585
fn main() -> Result<()> {
86-
let output_path = std::env::args().nth(1).map(PathBuf::from).unwrap_or_else(|| {
87-
eprintln!("Usage: crate-hierarchy-viz <output-file>");
88-
std::process::exit(1);
89-
});
86+
let output_path = std::env::args().nth(1).map(PathBuf::from).ok_or_else(|| anyhow::anyhow!("Usage: crate-hierarchy-viz <output-file>"))?;
9087

9188
let workspace_root = std::env::current_dir().unwrap();
9289
let workspace_toml_path = workspace_root.join("Cargo.toml");
@@ -217,7 +214,12 @@ fn generate_dot(crates: &[CrateInfo]) -> String {
217214
"lightblue",
218215
Box::new(|c| c.path.to_string_lossy().replace('\\', "/").contains("node-graph/nodes")),
219216
),
220-
("cluster_desktop", "Desktop", "lightgreen", Box::new(|c| c.path.to_string_lossy().contains("desktop"))),
217+
(
218+
"cluster_desktop",
219+
"Desktop",
220+
"lightgreen",
221+
Box::new(|c| c.path.to_string_lossy().replace('\\', "/").contains("desktop")),
222+
),
221223
];
222224

223225
for (id, label, color, filter) in clusters {

tools/editor-message-tree/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ use editor::utility_types::DebugMessageTree;
33
use std::io::Write;
44
use std::path::PathBuf;
55

6-
fn main() {
7-
let output_path = std::env::args().nth(1).map(PathBuf::from).unwrap_or_else(|| {
8-
eprintln!("Usage: editor-message-tree <output-file>");
9-
std::process::exit(1);
10-
});
6+
fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
let output_path = std::env::args().nth(1).map(PathBuf::from).ok_or("Usage: editor-message-tree <output-file>")?;
118

129
if let Some(parent) = output_path.parent() {
1310
std::fs::create_dir_all(parent).unwrap();
@@ -22,6 +19,8 @@ fn main() {
2219
print_tree_node(variant, "", is_last, &mut file);
2320
}
2421
}
22+
23+
Ok(())
2524
}
2625

2726
fn print_tree_node(tree: &DebugMessageTree, prefix: &str, is_last: bool, file: &mut std::fs::File) {

tools/node-docs/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ use crate::utility::*;
77
use convert_case::{Case, Casing};
88
use std::collections::HashMap;
99

10-
fn main() {
11-
let output_path = std::env::args().nth(1).unwrap_or_else(|| {
12-
eprintln!("Usage: node-docs <output-directory>");
13-
std::process::exit(1);
14-
});
10+
fn main() -> Result<(), Box<dyn std::error::Error>> {
11+
let output_path = std::env::args().nth(1).ok_or("Usage: node-docs <output-directory>")?;
1512

1613
// TODO: Also obtain document nodes, not only proto nodes
1714
let nodes = graphene_std::registry::NODE_METADATA.lock().unwrap();
@@ -45,4 +42,6 @@ fn main() {
4542
page_node::write_node_page(index, id, metadata, &category_path);
4643
}
4744
}
45+
46+
Ok(())
4847
}

website/static/js/page/contributor-guide/crate-hierarchy.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,26 @@ document.addEventListener("DOMContentLoaded", () => {
2424
const zoomOutBtn = controls.querySelector(".zoom-out");
2525
if (!(zoomInBtn instanceof HTMLButtonElement) || !(zoomOutBtn instanceof HTMLButtonElement)) return;
2626

27-
// Lock the viewport height to the SVG's natural rendered height
28-
viewport.style.height = `${svg.getBoundingClientRect().height}px`;
27+
// Lock the viewport height to the SVG's natural rendered height (ignoring any zoom transform)
28+
const updateViewportHeight = () => {
29+
const prevTransform = svg.style.transform;
30+
svg.style.transform = "";
31+
viewport.style.height = `${svg.getBoundingClientRect().height}px`;
32+
svg.style.transform = prevTransform;
33+
};
34+
updateViewportHeight();
35+
window.addEventListener("resize", updateViewportHeight);
2936

3037
const MIN_SCALE = 1;
31-
const MAX_SCALE = 2.5;
38+
const MAX_SCALE = 4;
3239
const ZOOM_STEP = 0.15;
3340
const BUTTON_ZOOM_STEP = 0.5;
3441
const ANIMATION_DURATION = 200;
3542

3643
let scale = MIN_SCALE;
3744
let panX = 0;
3845
let panY = 0;
46+
let animationFrameId = 0;
3947
let isDragging = false;
4048
let dragStartX = 0;
4149
let dragStartY = 0;
@@ -92,6 +100,8 @@ document.addEventListener("DOMContentLoaded", () => {
92100
}
93101

94102
function animateZoomAt(/** @type {number} */ clientX, /** @type {number} */ clientY, /** @type {number} */ newTargetScale) {
103+
cancelAnimationFrame(animationFrameId);
104+
95105
const targetScale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, newTargetScale));
96106
const startScale = scale;
97107
const startPanX = panX;
@@ -107,16 +117,16 @@ document.addEventListener("DOMContentLoaded", () => {
107117
const targetPanY = pointY - contentY * targetScale;
108118

109119
const startTime = performance.now();
110-
function step(/** @type {number} */ now) {
120+
const step = (/** @type {number} */ now) => {
111121
const t = Math.min(1, (now - startTime) / ANIMATION_DURATION);
112122
const ease = t * (2 - t); // ease-out quadratic
113123
scale = startScale + (targetScale - startScale) * ease;
114124
panX = startPanX + (targetPanX - startPanX) * ease;
115125
panY = startPanY + (targetPanY - startPanY) * ease;
116126
applyTransform();
117-
if (t < 1) requestAnimationFrame(step);
118-
}
119-
requestAnimationFrame(step);
127+
if (t < 1) animationFrameId = requestAnimationFrame(step);
128+
};
129+
animationFrameId = requestAnimationFrame(step);
120130
}
121131

122132
// Scroll wheel zoom

0 commit comments

Comments
 (0)