From f31b7db67e160f32de9f8d74c0cde997a74cac38 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 22 Jul 2024 10:20:44 -0700 Subject: [PATCH] Only emit dynamic plots for console sessions (#444) * only emit dynamic plots for console sessions * more clarity around dynamic plots; use 4:3 aspect by default --- crates/ark/src/interface.rs | 1 + crates/ark/src/main.rs | 1 + crates/ark/src/plots/graphics_device.rs | 24 ++++++++++++------------ crates/ark/src/shell.rs | 8 ++++++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/ark/src/interface.rs b/crates/ark/src/interface.rs index 558ae2ad5..87513d6a5 100644 --- a/crates/ark/src/interface.rs +++ b/crates/ark/src/interface.rs @@ -124,6 +124,7 @@ use crate::startup; use crate::sys::console::console_to_utf8; /// An enum representing the different modes in which the R session can run. +#[derive(PartialEq, Clone)] pub enum SessionMode { /// A session with an interactive console (REPL), such as in Positron. Console, diff --git a/crates/ark/src/main.rs b/crates/ark/src/main.rs index bde707c56..00495c20b 100644 --- a/crates/ark/src/main.rs +++ b/crates/ark/src/main.rs @@ -94,6 +94,7 @@ fn start_kernel( kernel_init_rx, kernel_request_tx, kernel_request_rx, + session_mode.clone(), ); // Create the control handler; this is used to handle shutdown/interrupt and diff --git a/crates/ark/src/plots/graphics_device.rs b/crates/ark/src/plots/graphics_device.rs index 8e85f52e5..cc0d05f80 100644 --- a/crates/ark/src/plots/graphics_device.rs +++ b/crates/ark/src/plots/graphics_device.rs @@ -1,7 +1,7 @@ // // graphics_device.rs // -// Copyright (C) 2022 by Posit Software, PBC +// Copyright (C) 2022-2024 by Posit Software, PBC // /// @@ -133,13 +133,13 @@ impl DeviceContext { &mut self, comm_manager_tx: Sender, iopub_tx: Sender, - positron_connected: bool, + dynamic_plots: bool, ) { // After R code has completed execution, we use this to check if any graphics // need to be created if self._changes { self._changes = false; - self.process_changes(comm_manager_tx, iopub_tx, positron_connected); + self.process_changes(comm_manager_tx, iopub_tx, dynamic_plots); } } @@ -221,7 +221,7 @@ impl DeviceContext { &mut self, comm_manager_tx: Sender, iopub_tx: Sender, - positron_connected: bool, + dynamic_plots: bool, ) { let id = unwrap!(self._id.clone(), None => { log::error!("Unexpected uninitialized `id`."); @@ -230,9 +230,9 @@ impl DeviceContext { if self._new_page { self._new_page = false; - self.process_new_plot(id.as_str(), comm_manager_tx, iopub_tx, positron_connected); + self.process_new_plot(id.as_str(), comm_manager_tx, iopub_tx, dynamic_plots); } else { - self.process_update_plot(id.as_str(), iopub_tx, positron_connected); + self.process_update_plot(id.as_str(), iopub_tx, dynamic_plots); } } @@ -241,9 +241,9 @@ impl DeviceContext { id: &str, comm_manager_tx: Sender, iopub_tx: Sender, - positron_connected: bool, + dynamic_plots: bool, ) { - if positron_connected { + if dynamic_plots { self.process_new_plot_positron(id, comm_manager_tx); } else { self.process_new_plot_jupyter_protocol(id, iopub_tx); @@ -354,8 +354,8 @@ impl DeviceContext { fn create_display_data_plot(&mut self, id: &str) -> Result { // TODO: Take these from R global options? Like `ark.plot.width`? - let width = 400; - let height = 650; + let width = 800; + let height = 600; let pixel_ratio = 1.0; let format = RenderFormat::Png; @@ -450,9 +450,9 @@ pub unsafe fn on_process_events() { pub unsafe fn on_did_execute_request( comm_manager_tx: Sender, iopub_tx: Sender, - positron_connected: bool, + dynamic_plots: bool, ) { - DEVICE_CONTEXT.on_did_execute_request(comm_manager_tx, iopub_tx, positron_connected); + DEVICE_CONTEXT.on_did_execute_request(comm_manager_tx, iopub_tx, dynamic_plots); } // NOTE: May be called when rendering a plot to file, since this is done by diff --git a/crates/ark/src/shell.rs b/crates/ark/src/shell.rs index 53c85fbe4..57571223a 100644 --- a/crates/ark/src/shell.rs +++ b/crates/ark/src/shell.rs @@ -1,7 +1,7 @@ // // shell.rs // -// Copyright (C) 2022 Posit Software, PBC. All rights reserved. +// Copyright (C) 2022-2024 Posit Software, PBC. All rights reserved. // // @@ -52,6 +52,7 @@ use crate::help::r_help::RHelp; use crate::help_proxy; use crate::interface::KernelInfo; use crate::interface::RMain; +use crate::interface::SessionMode; use crate::kernel::Kernel; use crate::plots::graphics_device; use crate::r_task; @@ -69,6 +70,7 @@ pub struct Shell { kernel_request_tx: Sender, kernel_init_rx: BusReader, kernel_info: Option, + session_mode: SessionMode, } #[derive(Debug)] @@ -86,6 +88,7 @@ impl Shell { kernel_init_rx: BusReader, kernel_request_tx: Sender, kernel_request_rx: Receiver, + session_mode: SessionMode, ) -> Self { // Start building the kernel object. It is shared by the shell, LSP, and main threads. let kernel = Kernel::new(); @@ -104,6 +107,7 @@ impl Shell { kernel_request_tx, kernel_init_rx, kernel_info: None, + session_mode, } } @@ -235,7 +239,7 @@ impl ShellHandler for Shell { graphics_device::on_did_execute_request( self.comm_manager_tx.clone(), self.iopub_tx.clone(), - kernel.ui_connected(), + kernel.ui_connected() && self.session_mode == SessionMode::Console, ) };