Skip to content

Commit

Permalink
Fixed some colors
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdoehne committed Jun 20, 2018
1 parent 4c6aae8 commit f48991b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
17 changes: 11 additions & 6 deletions src/stellarisdashboard/dash_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<version>/")
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",
Expand All @@ -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 = ""

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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',
})
Expand Down
28 changes: 15 additions & 13 deletions src/stellarisdashboard/visualization_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
Expand All @@ -187,7 +189,7 @@ class PlotSpecification:
],
"Military": [
FLEET_SIZE_GRAPH,
MILITARY_POWER_GRAPH
MILITARY_POWER_GRAPH,
],
}

Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/stellarisdashboard/visualization_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down

0 comments on commit f48991b

Please sign in to comment.