feat: burg group editor - apply changes

This commit is contained in:
Azgaar 2024-10-09 00:33:22 +02:00
parent b6708bf698
commit b700bf0630
8 changed files with 102 additions and 29 deletions

View file

@ -2,8 +2,7 @@
function drawBurgIcons() {
TIME && console.time("drawBurgIcons");
icons.selectAll("circle, use").remove(); // cleanup
createIconGroups();
for (const {name} of options.burgs.groups) {
const burgsInGroup = pack.burgs.filter(b => b.group === name && !b.removed);
@ -49,3 +48,27 @@ function drawBurgIcon(burg) {
.attr("x", burg.x)
.attr("y", burg.y);
}
function createIconGroups() {
const defaultStyle = style.burgIcons.towns || Object.values(style.burgIcons)[0];
// save existing styles and remove all groups
document.querySelectorAll("g#burgIcons > g").forEach(group => {
const groupStyle = Object.keys(defaultStyle).reduce((acc, key) => {
acc[key] = group.getAttribute(key);
return acc;
}, {});
style.burgIcons[group.id] = groupStyle;
group.remove();
});
// create groups for each burg group and apply stored or default style
const sortedGroups = [...options.burgs.groups].sort((a, b) => a.order - b.order);
for (const {name} of sortedGroups) {
const group = burgIcons.append("g").attr("id", name);
const styles = style.burgIcons[name] || defaultStyle;
Object.entries(styles).forEach(([key, value]) => {
group.attr(key, value);
});
}
}

View file

@ -2,8 +2,7 @@
function drawBurgLabels() {
TIME && console.time("drawBurgLabels");
burgLabels.selectAll("text").remove(); // cleanup
createLabelGroups();
for (const {name} of options.burgs.groups) {
const burgsInGroup = pack.burgs.filter(b => b.group === name && !b.removed);
@ -39,3 +38,27 @@ function drawBurgLabel(burg) {
.attr("dy", "-0.4em")
.text(burg.name);
}
function createLabelGroups() {
const defaultStyle = style.burgLabels.towns || Object.values(style.burgLabels)[0];
// save existing styles and remove all groups
document.querySelectorAll("g#burgLabels > g").forEach(group => {
const groupStyle = Object.keys(defaultStyle).reduce((acc, key) => {
acc[key] = group.getAttribute(key);
return acc;
}, {});
style.burgLabels[group.id] = groupStyle;
group.remove();
});
// create groups for each burg group and apply stored or default style
const sortedGroups = [...options.burgs.groups].sort((a, b) => a.order - b.order);
for (const {name} of sortedGroups) {
const group = burgLabels.append("g").attr("id", name);
const styles = style.burgLabels[name] || defaultStyle;
Object.entries(styles).forEach(([key, value]) => {
group.attr(key, value);
});
}
}