This commit is contained in:
Azgaar 2023-01-08 14:36:07 +03:00
commit aceb7e29b9
4 changed files with 30 additions and 13 deletions

View file

@ -633,7 +633,7 @@ function togglePercentageMode() {
async function showHierarchy() { async function showHierarchy() {
if (customization) return; 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 getDescription = culture => {
const {name, type, rural, urban} = culture; const {name, type, rural, urban} = culture;

View file

@ -539,7 +539,7 @@ function togglePercentageMode() {
async function showHierarchy() { async function showHierarchy() {
if (customization) return; 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 getDescription = religion => {
const {name, type, form, rural, urban} = religion; const {name, type, form, rural, urban} = religion;

View file

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

View file

@ -1182,12 +1182,12 @@ async function editStates() {
async function editCultures() { async function editCultures() {
if (customization) return; 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(); Editor.open();
} }
async function editReligions() { async function editReligions() {
if (customization) return; 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(); Editor.open();
} }