mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
Add command location to plots (#1474)
* poc of source on figures * update feature flag * fix reset on stocks/ba menu * improve aligment * remove source * make command location a global variable * add cmdloc to settings controller
This commit is contained in:
@@ -25,6 +25,9 @@ USE_ION = strtobool(os.getenv("GTFF_USE_ION", "True"))
|
||||
# Enable watermark in the figures
|
||||
USE_WATERMARK = strtobool(os.getenv("GTFF_USE_WATERMARK", "True"))
|
||||
|
||||
# Enable command and source in the figures
|
||||
USE_CMD_LOCATION_FIGURE = strtobool(os.getenv("GTFF_USE_CMD_LOCATION_FIGURE", "True"))
|
||||
|
||||
# Enable Prompt Toolkit
|
||||
USE_PROMPT_TOOLKIT = strtobool(os.getenv("GTFF_USE_PROMPT_TOOLKIT", "True"))
|
||||
|
||||
|
||||
@@ -316,20 +316,49 @@ class TerminalStyle:
|
||||
"""
|
||||
label = "Gamestonk Terminal"
|
||||
fig.text(
|
||||
0.69,
|
||||
0.99,
|
||||
0.0420,
|
||||
label,
|
||||
fontsize=12,
|
||||
color="gray",
|
||||
alpha=0.5,
|
||||
horizontalalignment="right",
|
||||
)
|
||||
|
||||
# pylint: disable=import-outside-toplevel
|
||||
def add_cmd_source(
|
||||
self,
|
||||
fig: plt.figure,
|
||||
):
|
||||
"""Add a text label to a figure in a funny position.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
fig : plt.figure
|
||||
A matplotlib figure
|
||||
"""
|
||||
from gamestonk_terminal.helper_funcs import command_location
|
||||
|
||||
if command_location:
|
||||
fig.text(
|
||||
0.01,
|
||||
0.5,
|
||||
command_location,
|
||||
rotation=90,
|
||||
fontsize=12,
|
||||
color="gray",
|
||||
alpha=0.5,
|
||||
verticalalignment="center",
|
||||
)
|
||||
|
||||
# pylint: disable=import-outside-toplevel
|
||||
def visualize_output(self, force_tight_layout: bool = True):
|
||||
"""Show chart in an interactive widget."""
|
||||
import gamestonk_terminal.feature_flags as gtff
|
||||
from gamestonk_terminal.rich_config import console
|
||||
|
||||
if gtff.USE_CMD_LOCATION_FIGURE:
|
||||
self.add_cmd_source(plt.gcf())
|
||||
if gtff.USE_WATERMARK:
|
||||
self.add_label(plt.gcf())
|
||||
if force_tight_layout:
|
||||
|
||||
@@ -43,6 +43,22 @@ MENU_GO_BACK = 0
|
||||
MENU_QUIT = 1
|
||||
MENU_RESET = 2
|
||||
|
||||
# Command location path to be shown in the figures depending on watermark flag
|
||||
command_location = ""
|
||||
|
||||
|
||||
# pylint: disable=global-statement
|
||||
def set_command_location(cmd_loc: str):
|
||||
"""Set command location
|
||||
|
||||
Parameters
|
||||
----------
|
||||
cmd_loc: str
|
||||
Command location called by user
|
||||
"""
|
||||
global command_location
|
||||
command_location = cmd_loc
|
||||
|
||||
|
||||
def log_and_raise(error: Union[argparse.ArgumentTypeError, ValueError]) -> None:
|
||||
logger.error(str(error))
|
||||
|
||||
@@ -26,6 +26,7 @@ from gamestonk_terminal.helper_funcs import (
|
||||
valid_date,
|
||||
parse_known_args_and_warn,
|
||||
valid_date_in_past,
|
||||
set_command_location,
|
||||
)
|
||||
from gamestonk_terminal.config_terminal import theme
|
||||
from gamestonk_terminal.rich_config import console
|
||||
@@ -176,6 +177,7 @@ class BaseController(metaclass=ABCMeta):
|
||||
elif known_args.cmd == "r":
|
||||
known_args.cmd = "reset"
|
||||
|
||||
set_command_location(f"{self.PATH}{known_args.cmd}")
|
||||
logger.info("CMD: %s", an_input)
|
||||
self.log_queue("QUEUE")
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class SettingsController(BaseController):
|
||||
"dt",
|
||||
"ion",
|
||||
"watermark",
|
||||
"cmdloc",
|
||||
"promptkit",
|
||||
"predict",
|
||||
"autoscaling",
|
||||
@@ -103,6 +104,8 @@ class SettingsController(BaseController):
|
||||
)
|
||||
color = "green" if gtff.USE_WATERMARK else "red"
|
||||
help_text += f" [{color}]watermark watermark in figures[/{color}]\n"
|
||||
color = "green" if gtff.USE_CMD_LOCATION_FIGURE else "red"
|
||||
help_text += f" [{color}]cmdloc command location displayed in figures[/{color}]\n"
|
||||
color = "green" if gtff.USE_PLOT_AUTOSCALING else "red"
|
||||
help_text += f" [{color}]autoscaling plot autoscaling[/{color}]\n\n"
|
||||
color = "green" if gtff.USE_DATETIME else "red"
|
||||
@@ -238,6 +241,17 @@ class SettingsController(BaseController):
|
||||
dotenv.set_key(self.env_file, "GTFF_USE_WATERMARK", str(gtff.USE_WATERMARK))
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_cmdloc(self, _):
|
||||
"""Process cmdloc command"""
|
||||
gtff.USE_CMD_LOCATION_FIGURE = not gtff.USE_CMD_LOCATION_FIGURE
|
||||
dotenv.set_key(
|
||||
self.env_file,
|
||||
"GTFF_USE_CMD_LOCATION_FIGURE",
|
||||
str(gtff.USE_CMD_LOCATION_FIGURE),
|
||||
)
|
||||
console.print("")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_autoscaling(self, _):
|
||||
"""Process autoscaling command"""
|
||||
|
||||
@@ -128,6 +128,12 @@ class BehaviouralAnalysisController(StockBaseController):
|
||||
"""
|
||||
console.print(text=help_text, menu="Stocks - Behavioural Analysis")
|
||||
|
||||
def custom_reset(self):
|
||||
"""Class specific component of reset command"""
|
||||
if self.ticker:
|
||||
return ["stocks", "ba", f"load {self.ticker}"]
|
||||
return []
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_watchlist(self, other_args: List[str]):
|
||||
"""Process watchlist command"""
|
||||
|
||||
@@ -159,7 +159,7 @@ def test_print_help():
|
||||
("help/help", ["help", "help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "ba"]),
|
||||
("r", ["quit", "quit", "reset", "stocks", "ba", "load TSLA"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
@@ -207,12 +207,12 @@ def test_call_cls(mocker):
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "ba"],
|
||||
["quit", "quit", "reset", "stocks", "ba", "load TSLA"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "ba", "help"],
|
||||
["quit", "quit", "reset", "stocks", "ba", "load TSLA", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user