From 127eafb656c7690977305d70138825bb1116a5c8 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Thu, 9 Jun 2022 00:21:02 +0300 Subject: [PATCH 1/6] feat(hierarchy tree): UI buttons to remove origin, zoom --- modules/dynamic/editors/religions-editor.js | 108 ++++++++++++++------ 1 file changed, 77 insertions(+), 31 deletions(-) diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js index 745d1457..513b4d4b 100644 --- a/modules/dynamic/editors/religions-editor.js +++ b/modules/dynamic/editors/religions-editor.js @@ -261,7 +261,7 @@ function getTypeOptions(type) { function religionHighlightOn(event) { const religionId = Number(event.id || event.target.dataset.id); const $info = byId("religionInfo"); - if ($info) { + if ($info && religionId) { d3.select("#hierarchy").select(`g[data-id='${religionId}']`).classed("selected", 1); const {name, type, form, rural, urban} = pack.religions[religionId]; @@ -563,39 +563,55 @@ function showHierarchy() { const validReligions = pack.religions.filter(r => !r.removed); if (validReligions.length < 3) return tip("Not enough religions to show hierarchy", false, "error"); - const root = d3 - .stratify() - .id(d => d.i) - .parentId(d => d.origins[0])(validReligions); - const treeWidth = root.leaves().length; - const treeHeight = root.height; - const width = Math.max(treeWidth * 40, 300); - const height = treeHeight * 60; + const getRoot = () => + d3 + .stratify() + .id(d => d.i) + .parentId(d => d.origins[0])(validReligions); + + const root = getRoot(); + const treeWidth = root.leaves().length * 50; + const treeHeight = root.height * 50; const margin = {top: 10, right: 10, bottom: -5, left: 10}; - const w = width - margin.left - margin.right; - const h = height + 30 - margin.top - margin.bottom; + const w = treeWidth - margin.left - margin.right; + const h = treeHeight + 30 - margin.top - margin.bottom; const treeLayout = d3.tree().size([w, h]); - alertMessage.innerHTML = /* html */ `
-
-