Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix select system instructional text not displayed, and split selected system ledger link into system and country #175

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions stellarisdashboard/dashboard_app/graph_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,16 @@ def update_country_select_options(search):
)
def galaxy_map_system_info(clickData):
if not clickData:
return ""
return SELECT_SYSTEM_DEFAULT
points = clickData.get("points")
if not points:
return ""
return SELECT_SYSTEM_DEFAULT
p = points[0]
custom_data = p.get("customdata", {})
system_id = custom_data.get("system_id")
system_name = custom_data.get("system_name")
country_id = custom_data.get("country_id")
country_name = custom_data.get("country_name")
game_id = custom_data.get("game_id")
text = p.get("text")
if not system_id or not game_id or not text:
Expand All @@ -180,12 +183,21 @@ def galaxy_map_system_info(clickData):
children=[
f"Selected system: ",
html.A(
children=text,
children=system_name,
href=utils.flask.url_for(
"history_page", game_id=game_id, system=system_id
),
className="textlink",
),
" (",
html.A(
children=country_name,
href=utils.flask.url_for(
"history_page", game_id=game_id, country=country_id
),
className="textlink",
) if country_id is not None else country_name,
")"
]
)

Expand Down Expand Up @@ -628,6 +640,9 @@ def get_galaxy(game_id: str, slider_date: float) -> dcc.Graph:
customdata = {
"system_id": nx_graph.nodes[node]["system_id"],
"game_id": game_id,
"system_name": nx_graph.nodes[node]["name"],
"country_name": country,
"country_id": nx_graph.nodes[node]["country_id"],
}
country_system_markers[country]["customdata"].append(customdata)
if country != visualization_data.GalaxyMapData.UNCLAIMED:
Expand Down Expand Up @@ -932,7 +947,7 @@ def get_layout():
html.Div(id="hidden-div", style={"display": "none"}),
],
style={
"display": "block",
"display": "none",
"width": "100%",
"height": "100%",
"margin-left": "auto",
Expand Down
35 changes: 20 additions & 15 deletions stellarisdashboard/dashboard_app/visualization_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ def initialize_galaxy_graph(self):
name=system.rendered_name,
country=GalaxyMapData.UNCLAIMED,
system_id=system.system_id,
country_id=None,
pos=[-system.coordinate_x, -system.coordinate_y],
)
for hl in session.query(datamodel.HyperLane).all():
Expand All @@ -1573,10 +1574,14 @@ def update_graph_for_date(self, time_days: int):
start_time = time.process_time()
systems_by_owner = self._get_system_ids_by_owner(time_days)
owner_by_system = {}
for country, nodes in systems_by_owner.items():
owner_id_by_system = {}
for country_tuple, nodes in systems_by_owner.items():
country_id, country_name = country_tuple
for node in nodes:
owner_by_system[node] = country
self.galaxy_graph.nodes[node]["country"] = country
owner_by_system[node] = country_name
owner_id_by_system[node] = country_id
self.galaxy_graph.nodes[node]["country"] = country_name
self.galaxy_graph.nodes[node]["country_id"] = country_id

for edge in self.galaxy_graph.edges:
i, j = edge
Expand Down Expand Up @@ -1608,20 +1613,20 @@ def get_country_border_ridges(
for rv1, rv2 in intersecting_ridges:
yield [rv1[0], rv2[0]], [rv1[1], rv2[1]]

def _get_system_ids_by_owner(self, time_days) -> Dict[str, Set[int]]:
def _get_system_ids_by_owner(self, time_days) -> Dict[Tuple[str, str], Set[int]]:
owned_systems = set()
systems_by_owner = {GalaxyMapData.UNCLAIMED: set()}
systems_by_owner = {(None, GalaxyMapData.UNCLAIMED): set()}

with datamodel.get_db_session(self.game_id) as session:
for system in session.query(datamodel.System):
country = system.get_owner_country_at(time_days)
country = self._country_display_name(country)
country_tuple = self._country_display_tuple(country)
owned_systems.add(system.system_id_in_game)
if country not in systems_by_owner:
systems_by_owner[country] = set()
systems_by_owner[country].add(system.system_id_in_game)
if country_tuple not in systems_by_owner:
systems_by_owner[country_tuple] = set()
systems_by_owner[country_tuple].add(system.system_id_in_game)

systems_by_owner[GalaxyMapData.UNCLAIMED] |= (
systems_by_owner[(None, GalaxyMapData.UNCLAIMED)] |= (
set(self.galaxy_graph.nodes) - owned_systems
)
return systems_by_owner
Expand Down Expand Up @@ -1691,14 +1696,14 @@ def _extract_voronoi_ridges(self, voronoi: Voronoi):

self.galaxy_graph.graph["system_borders"][rp].add(rv_tuple)

def _country_display_name(self, country: datamodel.Country) -> str:
def _country_display_tuple(self, country: datamodel.Country) -> Tuple[str, str]:
if country is None:
return GalaxyMapData.UNCLAIMED
return (None, GalaxyMapData.UNCLAIMED)
if config.CONFIG.show_everything:
return country.rendered_name
return (country.country_id, country.rendered_name)
if not country.has_met_player():
return GalaxyMapData.UNCLAIMED
return country.rendered_name
return (None, GalaxyMapData.UNCLAIMED)
return (country.country_id, country.rendered_name)


_MIN_V = 0.4
Expand Down
Loading