fix: hierarchy-tree - make sure nodes have parents not removed

This commit is contained in:
Azgaar 2023-01-02 16:21:13 +03:00
parent 3883933385
commit 4ab0311d01
6 changed files with 32 additions and 15 deletions

View file

@ -7864,7 +7864,7 @@
<script defer src="modules/relief-icons.js"></script>
<script defer src="modules/ui/style.js"></script>
<script defer src="modules/ui/editors.js?v=1.87.07"></script>
<script defer src="modules/ui/editors.js?v=1.88.06"></script>
<script defer src="modules/ui/tools.js?v=1.88.05"></script>
<script defer src="modules/ui/world-configurator.js"></script>
<script defer src="modules/ui/heightmap-editor.js?v=1.88.03"></script>

View file

@ -630,7 +630,7 @@ function togglePercentageMode() {
async function showHierarchy() {
if (customization) return;
const HeirarchyTree = await import("../hierarchy-tree.js?v=1.87.01");
const HeirarchyTree = await import("../hierarchy-tree.js?v=1.88.06");
const getDescription = culture => {
const {name, type, rural, urban} = culture;

View file

@ -533,7 +533,7 @@ function togglePercentageMode() {
async function showHierarchy() {
if (customization) return;
const HeirarchyTree = await import("../hierarchy-tree.js?v=1.87.01");
const HeirarchyTree = await import("../hierarchy-tree.js?v=1.88.06");
const getDescription = religion => {
const {name, type, form, rural, urban} = religion;

View file

@ -29,8 +29,7 @@ export function open(props) {
closeDialogs("#hierarchyTree, .stable");
dataElements = props.data;
dataElements[0].origins = [null];
validElements = dataElements.filter(r => !r.removed);
validElements = cleanupOrigins(dataElements);
if (validElements.length < 3) return tip(`Not enough ${props.type} to show hierarchy`, false, "error");
onNodeEnter = props.onNodeEnter;
@ -39,6 +38,8 @@ export function open(props) {
getShape = props.getShape;
const root = getRoot();
if (!root) return;
const treeWidth = root.leaves().length * 50;
const treeHeight = root.height * 50;
@ -175,14 +176,30 @@ function insertHtml() {
byId("dialogs").insertAdjacentHTML("beforeend", html);
}
function getRoot() {
const root = d3
.stratify()
.id(d => d.i)
.parentId(d => d.origins[0])(validElements);
function cleanupOrigins(elements) {
const existingElements = elements.filter(d => !d.removed);
oldRoot = root;
return root;
return existingElements.map(d => {
if (d.i === 0) d.origins = [null]; // root element
else if (!d.origins.length) d.origins = [0];
else if (!existingElements.find(el => d.origins[0] === el.i)) d.origins = [0];
return d;
});
}
function getRoot() {
try {
const root = d3
.stratify()
.id(d => d.i)
.parentId(d => d.origins[0])(validElements);
oldRoot = root;
return root;
} catch (error) {
tip("Hierarchy data issue. " + error, false, "error", 6000);
return oldRoot;
}
}
function getLinkKey(d) {

View file

@ -1182,12 +1182,12 @@ async function editStates() {
async function editCultures() {
if (customization) return;
const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.87.06");
const Editor = await import("../dynamic/editors/cultures-editor.js?v=1.88.06");
Editor.open();
}
async function editReligions() {
if (customization) return;
const Editor = await import("../dynamic/editors/religions-editor.js?v=1.87.01");
const Editor = await import("../dynamic/editors/religions-editor.js?v=1.88.06");
Editor.open();
}

View file

@ -1,7 +1,7 @@
"use strict";
// version and caching control
const version = "1.88.05"; // generator version, update each time
const version = "1.88.06"; // generator version, update each time
{
document.title += " v" + version;