From 257b83b5822d82a88a6214a89425d13499e1c6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kav=C3=ADk?= Date: Fri, 14 Jun 2024 01:50:45 +0200 Subject: [PATCH] hide invisible blocks --- frontend/typescript/bundles/pixi_canvas.js | 8 ++++---- frontend/typescript/pixi_canvas/pixi_canvas.ts | 10 +++++----- shared/src/signal_to_timeline.rs | 13 +++++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend/typescript/bundles/pixi_canvas.js b/frontend/typescript/bundles/pixi_canvas.js index 469c0c7..27976c4 100644 --- a/frontend/typescript/bundles/pixi_canvas.js +++ b/frontend/typescript/bundles/pixi_canvas.js @@ -35219,14 +35219,14 @@ var PixiController = class { } async zoom_or_pan(wheel_delta_y, shift_key, offset_x) { if (shift_key) { - this.timeline_viewport_x -= Math.sign(wheel_delta_y) * 20; + this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20; } else { const offset_x_ratio = offset_x / this.timeline_viewport_width; const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; - this.timeline_zoom -= Math.sign(wheel_delta_y) * 0.1; + this.timeline_zoom -= Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5; const new_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const timeline_width_difference = new_timeline_width - old_timeline_width; - this.timeline_viewport_x -= timeline_width_difference * offset_x_ratio; + this.timeline_viewport_x += timeline_width_difference * offset_x_ratio; } this.redraw_all_rows(); } @@ -35304,7 +35304,7 @@ var VarSignalRow = class { this.draw(); } draw() { - if (this.app.screen === null) { + if (this.app === null || this.app.screen === null) { return; } this.row_container_background.width = this.app.screen.width; diff --git a/frontend/typescript/pixi_canvas/pixi_canvas.ts b/frontend/typescript/pixi_canvas/pixi_canvas.ts index ca82560..f3c60b9 100644 --- a/frontend/typescript/pixi_canvas/pixi_canvas.ts +++ b/frontend/typescript/pixi_canvas/pixi_canvas.ts @@ -149,15 +149,15 @@ export class PixiController { async zoom_or_pan(wheel_delta_y: number, shift_key: boolean, offset_x: number) { if (shift_key) { - this.timeline_viewport_x -= Math.sign(wheel_delta_y) * 20; + this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20; } else { - // @TODO fix, bounds + // @TODO bounds const offset_x_ratio = offset_x / this.timeline_viewport_width; const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; - this.timeline_zoom -= Math.sign(wheel_delta_y) * 0.1; + this.timeline_zoom -= Math.sign(wheel_delta_y) * this.timeline_zoom * 0.5; const new_timeline_width = this.timeline_viewport_width * this.timeline_zoom; const timeline_width_difference = new_timeline_width - old_timeline_width; - this.timeline_viewport_x -= timeline_width_difference * offset_x_ratio; + this.timeline_viewport_x += timeline_width_difference * offset_x_ratio; } this.redraw_all_rows(); } @@ -265,7 +265,7 @@ class VarSignalRow { draw() { // Screen can be null when we are, for instance, switching between miller columns and tree layout // and then the canvas has to be recreated - if (this.app.screen === null) { + if (this.app === null || this.app.screen === null) { return; } diff --git a/shared/src/signal_to_timeline.rs b/shared/src/signal_to_timeline.rs index cdd6505..e9fc24f 100644 --- a/shared/src/signal_to_timeline.rs +++ b/shared/src/signal_to_timeline.rs @@ -23,14 +23,12 @@ pub fn signal_to_timeline( let timeline_viewport_x = timeline_viewport_x as f64; let timeline_width = timeline_viewport_width as f64 * timeline_zoom; - // @TODO hide blocks not visible in the viewport - let mut x_value_pairs = signal .iter_changes() .map(|(index, value)| { let index = index as usize; let time = time_table[index] as f64; - let x = time / last_time * timeline_width + timeline_viewport_x; + let x = time / last_time * timeline_width - timeline_viewport_x; (x, value) }) .peekable(); @@ -38,16 +36,23 @@ pub fn signal_to_timeline( // @TODO parallelize? let mut blocks = Vec::new(); while let Some((block_x, value)) = x_value_pairs.next() { + if block_x >= (timeline_viewport_width as f64) { + break; + } + let next_block_x = if let Some((next_block_x, _)) = x_value_pairs.peek() { *next_block_x } else { - timeline_width + timeline_viewport_x + timeline_width - timeline_viewport_x }; let block_width = (next_block_x - block_x) as u32; if block_width < MIN_BLOCK_WIDTH { continue; } + if block_x + (block_width as f64) <= 0. { + continue; + } // @TODO cache? let value = var_format.format(value);