hide invisible blocks

This commit is contained in:
Martin Kavík 2024-06-14 01:50:45 +02:00
parent e934ac031d
commit 257b83b582
3 changed files with 18 additions and 13 deletions

View file

@ -35219,14 +35219,14 @@ var PixiController = class {
} }
async zoom_or_pan(wheel_delta_y, shift_key, offset_x) { async zoom_or_pan(wheel_delta_y, shift_key, offset_x) {
if (shift_key) { if (shift_key) {
this.timeline_viewport_x -= Math.sign(wheel_delta_y) * 20; this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20;
} else { } else {
const offset_x_ratio = offset_x / this.timeline_viewport_width; const offset_x_ratio = offset_x / this.timeline_viewport_width;
const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; 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 new_timeline_width = this.timeline_viewport_width * this.timeline_zoom;
const timeline_width_difference = new_timeline_width - old_timeline_width; 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(); this.redraw_all_rows();
} }
@ -35304,7 +35304,7 @@ var VarSignalRow = class {
this.draw(); this.draw();
} }
draw() { draw() {
if (this.app.screen === null) { if (this.app === null || this.app.screen === null) {
return; return;
} }
this.row_container_background.width = this.app.screen.width; this.row_container_background.width = this.app.screen.width;

View file

@ -149,15 +149,15 @@ export class PixiController {
async zoom_or_pan(wheel_delta_y: number, shift_key: boolean, offset_x: number) { async zoom_or_pan(wheel_delta_y: number, shift_key: boolean, offset_x: number) {
if (shift_key) { if (shift_key) {
this.timeline_viewport_x -= Math.sign(wheel_delta_y) * 20; this.timeline_viewport_x += Math.sign(wheel_delta_y) * 20;
} else { } else {
// @TODO fix, bounds // @TODO bounds
const offset_x_ratio = offset_x / this.timeline_viewport_width; const offset_x_ratio = offset_x / this.timeline_viewport_width;
const old_timeline_width = this.timeline_viewport_width * this.timeline_zoom; 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 new_timeline_width = this.timeline_viewport_width * this.timeline_zoom;
const timeline_width_difference = new_timeline_width - old_timeline_width; 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(); this.redraw_all_rows();
} }
@ -265,7 +265,7 @@ class VarSignalRow {
draw() { draw() {
// Screen can be null when we are, for instance, switching between miller columns and tree layout // Screen can be null when we are, for instance, switching between miller columns and tree layout
// and then the canvas has to be recreated // and then the canvas has to be recreated
if (this.app.screen === null) { if (this.app === null || this.app.screen === null) {
return; return;
} }

View file

@ -23,14 +23,12 @@ pub fn signal_to_timeline(
let timeline_viewport_x = timeline_viewport_x as f64; let timeline_viewport_x = timeline_viewport_x as f64;
let timeline_width = timeline_viewport_width as f64 * timeline_zoom; let timeline_width = timeline_viewport_width as f64 * timeline_zoom;
// @TODO hide blocks not visible in the viewport
let mut x_value_pairs = signal let mut x_value_pairs = signal
.iter_changes() .iter_changes()
.map(|(index, value)| { .map(|(index, value)| {
let index = index as usize; let index = index as usize;
let time = time_table[index] as f64; 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) (x, value)
}) })
.peekable(); .peekable();
@ -38,16 +36,23 @@ pub fn signal_to_timeline(
// @TODO parallelize? // @TODO parallelize?
let mut blocks = Vec::new(); let mut blocks = Vec::new();
while let Some((block_x, value)) = x_value_pairs.next() { 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() { let next_block_x = if let Some((next_block_x, _)) = x_value_pairs.peek() {
*next_block_x *next_block_x
} else { } else {
timeline_width + timeline_viewport_x timeline_width - timeline_viewport_x
}; };
let block_width = (next_block_x - block_x) as u32; let block_width = (next_block_x - block_x) as u32;
if block_width < MIN_BLOCK_WIDTH { if block_width < MIN_BLOCK_WIDTH {
continue; continue;
} }
if block_x + (block_width as f64) <= 0. {
continue;
}
// @TODO cache? // @TODO cache?
let value = var_format.format(value); let value = var_format.format(value);