diff --git a/src/stellarisdashboard/dash_server.py b/src/stellarisdashboard/dash_server.py index 2d81f95..6b442ce 100644 --- a/src/stellarisdashboard/dash_server.py +++ b/src/stellarisdashboard/dash_server.py @@ -24,12 +24,17 @@ VERSION_ID = "v0.1.4" + +def is_old_version(requested_version: str) -> bool: + return requested_version != VERSION_ID + + @flask_app.route("/") @flask_app.route("/checkversion//") def index_page(version=None): show_old_version_notice = False if version is not None: - show_old_version_notice = version != VERSION_ID + show_old_version_notice = is_old_version(version) games = [dict(country=country, game_name=g) for g, country in models.get_available_games_dict().items()] return render_template( "index.html", @@ -46,7 +51,7 @@ def index_page(version=None): def history_page(game_name=None, version=None): show_old_version_notice = False if version is not None: - show_old_version_notice = version != VERSION_ID + show_old_version_notice = is_old_version(version) if game_name is None: game_name = "" @@ -240,7 +245,7 @@ def _get_line_plot_data(plot_data: visualization_data.EmpireProgressionPlotData, y=y_values, name=key, text=[f"{val:.2f} - {key}" for val in y_values], - line={"color": get_country_color(key, 0.75)}, + line={"color": get_country_color(key, 1.0)}, ) plot_list.append(line) return plot_list @@ -259,8 +264,8 @@ def _get_stacked_plot_data(plot_data: visualization_data.EmpireProgressionPlotDa line["y"] = y_previous[:] # make a copy if line["y"]: line["text"] = [f"{val:.2f} - {key}" if val else "" for val in y_values] - line["line"] = {"color": get_country_color(key, 0.75)} - line["fillcolor"] = get_country_color(key, 0.3) + line["line"] = {"color": get_country_color(key, 1.0)} + line["fillcolor"] = get_country_color(key, 0.75) plot_list.append(line) return plot_list @@ -303,7 +308,7 @@ def _get_budget_plot_data(plot_data: visualization_data.EmpireProgressionPlotDat 'x': plot_list[0]["x"], 'y': net_gain, 'name': 'Net gain', - 'line': {'color': 'rgba(0,0,0,1)'}, + 'line': {'color': 'rgba(255,255,255,1)'}, 'text': [f'{val:.2f} - net gain' for val in net_gain], 'hoverinfo': 'x+text', }) diff --git a/src/stellarisdashboard/visualization_data.py b/src/stellarisdashboard/visualization_data.py index 64787f5..a242efb 100644 --- a/src/stellarisdashboard/visualization_data.py +++ b/src/stellarisdashboard/visualization_data.py @@ -11,9 +11,9 @@ logger = logging.getLogger(__name__) -COLOR_PHYSICS = (30, 100, 170) -COLOR_SOCIETY = (60, 150, 90) -COLOR_ENGINEERING = (190, 150, 30) +COLOR_PHYSICS = (0.12, 0.4, 0.66) +COLOR_SOCIETY = (0.23, 0.59, 0.35) +COLOR_ENGINEERING = (0.75, 0.59, 0.12) @enum.unique @@ -58,13 +58,13 @@ class PlotSpecification: ) NET_MINERAL_INCOME_GRAPH = PlotSpecification( plot_id='net-mineral-income-graph', - title="Net Mineral Income (Warning: Might be inaccurate!)", + title="Net Mineral Income", plot_data_function=lambda pd: pd.net_mineral_income, style=PlotStyle.line, ) NET_ENERGY_INCOME_GRAPH = PlotSpecification( plot_id='net-energy-income-graph', - title="Net Energy Income (Warning: Might be inaccurate!)", + title="Net Energy Income", plot_data_function=lambda pd: pd.net_energy_income, style=PlotStyle.line, ) @@ -160,14 +160,16 @@ class PlotSpecification: # This specifies how the plots should be laid out in tabs by the plotly frontend # and how they should be split to different images by matplotlib THEMATICALLY_GROUPED_PLOTS = { + "Budget": [ + EMPIRE_ENERGY_ECONOMY_GRAPH, + EMPIRE_MINERAL_ECONOMY_GRAPH, + EMPIRE_FOOD_ECONOMY_GRAPH, + ], "Economy": [ PLANET_COUNT_GRAPH, SYSTEM_COUNT_GRAPH, NET_ENERGY_INCOME_GRAPH, NET_MINERAL_INCOME_GRAPH, - EMPIRE_ENERGY_ECONOMY_GRAPH, - EMPIRE_MINERAL_ECONOMY_GRAPH, - EMPIRE_FOOD_ECONOMY_GRAPH, ], "Population": [ POP_COUNT_GRAPH, @@ -187,7 +189,7 @@ class PlotSpecification: ], "Military": [ FLEET_SIZE_GRAPH, - MILITARY_POWER_GRAPH + MILITARY_POWER_GRAPH, ], } @@ -234,12 +236,12 @@ def show_military_info(country_data: models.CountryData): or country_data.has_federation_with_player) -def get_color_vals(key_str: str, range_min: float = 0.1, range_max: float = 1.0): - if key_str == "physics": +def get_color_vals(key_str: str, range_min: float = 0.1, range_max: float = 1.0) -> Tuple[float, float, float]: + if key_str.lower() == "physics": r, g, b = COLOR_PHYSICS - elif key_str == "society": + elif key_str.lower() == "society": r, g, b = COLOR_SOCIETY - elif key_str == "engineering": + elif key_str.lower() == "engineering": r, g, b = COLOR_ENGINEERING else: random.seed(key_str) diff --git a/src/stellarisdashboard/visualization_mpl.py b/src/stellarisdashboard/visualization_mpl.py index dc6fed4..001a116 100644 --- a/src/stellarisdashboard/visualization_mpl.py +++ b/src/stellarisdashboard/visualization_mpl.py @@ -44,7 +44,7 @@ def _line_plot(self, ax, plot_spec: visualization_data.PlotSpecification): if y: plot_kwargs = self._get_country_plot_kwargs(key) ax.plot(x, y, **plot_kwargs) - ax.legend() + ax.legend(loc='upper left') def _stacked_plot(self, ax, plot_spec: visualization_data.PlotSpecification): ax.set_title(plot_spec.title) @@ -55,8 +55,11 @@ def _stacked_plot(self, ax, plot_spec: visualization_data.PlotSpecification): for i, (key, x, y) in enumerate(data): stacked.append(y) labels.append(key) - color_index = i / max(1, len(data) - 1) - colors.append(MatplotLibVisualization.COLOR_MAP(color_index)) + if key in ["physics", "society", "engineering"]: + colors.append(visualization_data.get_color_vals(key)) + else: + color_index = i / max(1, len(data) - 1) + colors.append(MatplotLibVisualization.COLOR_MAP(color_index)) if stacked: ax.stackplot(self.plot_data.dates, stacked, labels=labels, colors=colors, alpha=0.75) ax.legend(loc='upper left', prop={'size': 6})