Skip to content

Comments

Split label view data#1313

Open
StempunkDev wants to merge 19 commits intoAzgaar:masterfrom
StempunkDev:feature/split-label-view-data
Open

Split label view data#1313
StempunkDev wants to merge 19 commits intoAzgaar:masterfrom
StempunkDev:feature/split-label-view-data

Conversation

@StempunkDev
Copy link
Contributor

@StempunkDev StempunkDev commented Feb 11, 2026

Description

This PR aims to split the view and data of the state and burg labels. What will be missing are the province labels. The goal is to get labels working as data as much as possible for states and burgs.

Type of change

  • Refactoring / style
  • Documentation update / chore

Versioning

  • Version is updated
  • Changed files hash is updated

@netlify
Copy link

netlify bot commented Feb 11, 2026

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit fd32007
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/699de8a4958341000855ff51
😎 Deploy Preview https://deploy-preview-1313--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors label handling to move state and burg label information into a data layer (pack.labels) while keeping rendering in SVG renderers, aiming to make labels more data-driven and reusable across the app.

Changes:

  • Added a Labels module to generate/store/update state and burg label data in pack.labels
  • Extracted state-label raycast logic into a reusable src/utils/label-raycast.ts utility
  • Updated state/burg label renderers and map generation to use/populate the new label data

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/utils/label-raycast.ts New shared raycast + scoring utilities for state label path selection
src/types/PackedGraph.ts Extends PackedGraph with labels: LabelData[]
src/renderers/draw-state-labels.ts Renders state labels from Labels data and updates label data (text/font size) during fitting
src/renderers/draw-burg-labels.ts Renders burg labels from Labels data and syncs offsets back to label data
src/modules/labels.ts New global Labels module for label CRUD + generation from states/burgs
src/modules/index.ts Ensures Labels module is loaded/registered
public/main.js Calls Labels.generate() during map generation

Comment on lines +42 to +48
if (labels.length === 0) return 0;

const existingIds = labels.map((l) => l.i).sort((a, b) => a - b);
for (let id = 0; id < existingIds[existingIds.length - 1]; id++) {
if (!existingIds.includes(id)) return id;
}
return existingIds[existingIds.length - 1] + 1;
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNextId recomputes and sorts all IDs on every call and then uses includes inside a loop, which becomes quadratic as labels grow (burg labels can be numerous). Consider tracking the next id incrementally and/or using a Set to find gaps, or maintaining a monotonically increasing counter when gaps are not required.

Suggested change
if (labels.length === 0) return 0;
const existingIds = labels.map((l) => l.i).sort((a, b) => a - b);
for (let id = 0; id < existingIds[existingIds.length - 1]; id++) {
if (!existingIds.includes(id)) return id;
}
return existingIds[existingIds.length - 1] + 1;
if (!labels || labels.length === 0) return 0;
const existingIds = new Set<number>();
let maxId = -1;
for (const label of labels) {
const id = label.i;
existingIds.add(id);
if (id > maxId) maxId = id;
}
for (let id = 0; id <= maxId; id++) {
if (!existingIds.has(id)) return id;
}
return maxId + 1;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StempunkDev TODO: cache ids more intelligent if needed for performance

@StempunkDev
Copy link
Contributor Author

@SheepFromHeaven do you intend on migrating any of the editor in the near future? Since I would need to edit the burgs-editor.js for feature completeness. I hope I can safe both of us some merge conflicts

@SheepFromHeaven
Copy link
Collaborator

No worries. I will then leave it out for now. There is still enough other things. Incl. Fixing bugs 😂

@StempunkDev
Copy link
Contributor Author

Update: Mostly done. Custom Labels Migration from Older Maps still need to be tested.
Things to still apply if needed:

  • Renderer Optimization by composing HTML changes
  • getNextId Optimization
  • Generalize getNextId when wished for

@StempunkDev StempunkDev marked this pull request as ready for review February 19, 2026 18:48
@StempunkDev StempunkDev changed the title [WIP] Split label view data Split label view data Feb 24, 2026
@StempunkDev
Copy link
Contributor Author

Technically done. @Azgaar was the behavior of labels that they reset each time they are drawn/loaded or where there positions saved? Since when the labels are redrawn they reset due to group overriding the changes. I think this is both true for State and Burg Labels. Is that acceptable?

@Azgaar
Copy link
Owner

Azgaar commented Feb 24, 2026

Technically done. @Azgaar was the behavior of labels that they reset each time they are drawn/loaded or where there positions saved? Since when the labels are redrawn they reset due to group overriding the changes. I think this is both true for State and Burg Labels. Is that acceptable?

If we can not rerender them completely on minor changes, we should not reredner them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants