Skip to content

Commit 440338a

Browse files
author
Amelia Wattenbeger
committed
make tree more readable
1 parent c14acd0 commit 440338a

File tree

3 files changed

+87
-76
lines changed

3 files changed

+87
-76
lines changed

index.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14568,10 +14568,10 @@ var getAngleFromPosition = (x2, y2) => {
1456814568
return Math.atan2(y2, x2) * 180 / Math.PI;
1456914569
};
1457014570
var keepCircleInsideCircle = (parentR, parentPosition, childR, childPosition) => {
14571-
const padding = 6;
1457214571
const distance = Math.sqrt(Math.pow(parentPosition[0] - childPosition[0], 2) + Math.pow(parentPosition[1] - childPosition[1], 2));
14573-
if (distance > parentR + childR + padding) {
14574-
const angle = getAngleFromPosition(parentPosition[0] - childPosition[0], parentPosition[1] - childPosition[1]);
14572+
const angle = getAngleFromPosition(childPosition[0] - parentPosition[0], childPosition[1] - parentPosition[1]);
14573+
const padding = angle < -40 && angle > -150 ? 13 : 2;
14574+
if (distance > parentR - childR - padding) {
1457514575
const diff = getPositionFromAngleAndDistance(angle, parentR - childR - padding);
1457614576
return [
1457714577
parentPosition[0] + diff[0],
@@ -14593,15 +14593,18 @@ var fileColors = {
1459314593
svg: "#EA4C85",
1459414594
css: "#E97BF2",
1459514595
svelte: "#D9D2C2",
14596+
scss: "#9980FA",
1459614597
html: "#ffb8b8",
14598+
go: "#c7ecee",
14599+
rb: "#eb4d4b",
1459714600
m: "#0fb9b1",
1459814601
py: "#9980FA",
1459914602
sh: "#badc58"
1460014603
};
1460114604
var colorTheme = "file";
1460214605
var looseFilesId = "__structure_loose_file__";
14603-
var width = 1400;
14604-
var height = 700;
14606+
var width = 1e3;
14607+
var height = 1e3;
1460514608
var maxDepth = 9;
1460614609
var Tree = ({ data, filesChanged = [] }) => {
1460714610
const [selectedNodeId, setSelectedNodeId] = (0, import_react2.useState)(null);
@@ -14635,14 +14638,14 @@ var Tree = ({ data, filesChanged = [] }) => {
1463514638
});
1463614639
let packedTree = pack_default().size([width, height * 1.3]).padding((d) => {
1463714640
if (d.depth <= 0)
14638-
return 6;
14641+
return 0;
1463914642
const hasChildWithNoChildren = d.children.filter((d2) => {
1464014643
var _a;
1464114644
return !((_a = d2.children) == null ? void 0 : _a.length);
1464214645
}).length > 1;
1464314646
if (hasChildWithNoChildren)
14644-
return 6;
14645-
return 30;
14647+
return 9;
14648+
return 15;
1464614649
})(hierarchicalData);
1464714650
packedTree.children = reflowSiblings(packedTree.children, cachedPositions.current);
1464814651
const children2 = packedTree.descendants();
@@ -14786,7 +14789,7 @@ var Tree = ({ data, filesChanged = [] }) => {
1478614789
style: {
1478714790
pointerEvents: "none",
1478814791
opacity: 0.8,
14789-
fontSize: "10px",
14792+
fontSize: "14px",
1479014793
fontWeight: 500,
1479114794
transition: "all 0.5s ease-out"
1479214795
},
@@ -14799,7 +14802,7 @@ var Tree = ({ data, filesChanged = [] }) => {
1479914802
style: {
1480014803
pointerEvents: "none",
1480114804
opacity: 0.8,
14802-
fontSize: "10px",
14805+
fontSize: "14px",
1480314806
fontWeight: 500,
1480414807
transition: "all 0.5s ease-out"
1480514808
},
@@ -14810,7 +14813,7 @@ var Tree = ({ data, filesChanged = [] }) => {
1481014813
style: {
1481114814
pointerEvents: "none",
1481214815
opacity: 0.8,
14813-
fontSize: "10px",
14816+
fontSize: "14px",
1481414817
fontWeight: 500,
1481514818
mixBlendMode: "multiply",
1481614819
transition: "all 0.5s ease-out"
@@ -14859,24 +14862,24 @@ var Tree = ({ data, filesChanged = [] }) => {
1485914862
style: { pointerEvents: "none", transition: "all 0.5s ease-out" },
1486014863
transform: `translate(${x2}, ${y2})`
1486114864
}, /* @__PURE__ */ import_react2.default.createElement(CircleText, {
14862-
style: { fontSize: "10px", transition: "all 0.5s ease-out" },
14863-
r: r + 6,
14865+
style: { fontSize: "14px", transition: "all 0.5s ease-out" },
14866+
r: r - 3,
1486414867
fill: "#374151",
1486514868
stroke: "white",
14866-
strokeWidth: "4",
14869+
strokeWidth: "6",
1486714870
text: data2.label
1486814871
}), /* @__PURE__ */ import_react2.default.createElement(CircleText, {
14869-
style: { fontSize: "10px", transition: "all 0.5s ease-out" },
14872+
style: { fontSize: "14px", transition: "all 0.5s ease-out" },
1487014873
fill: "#374151",
14871-
r: r + 6,
14874+
r: r - 3,
1487214875
text: data2.label
1487314876
}));
1487414877
}), !!selectedNode && (!selectedNode.children || selectedNode.depth === maxDepth) && /* @__PURE__ */ import_react2.default.createElement("g", {
1487514878
transform: `translate(${selectedNode.x}, ${selectedNode.y})`
1487614879
}, /* @__PURE__ */ import_react2.default.createElement("text", {
1487714880
style: {
1487814881
pointerEvents: "none",
14879-
fontSize: "10px",
14882+
fontSize: "14px",
1488014883
fontWeight: 500,
1488114884
transition: "all 0.5s ease-out"
1488214885
},
@@ -14887,7 +14890,7 @@ var Tree = ({ data, filesChanged = [] }) => {
1488714890
}, selectedNode.data.label), /* @__PURE__ */ import_react2.default.createElement("text", {
1488814891
style: {
1488914892
pointerEvents: "none",
14890-
fontSize: "10px",
14893+
fontSize: "14px",
1489114894
fontWeight: 500,
1489214895
transition: "all 0.5s ease-out"
1489314896
},
@@ -14908,7 +14911,7 @@ var Legend = ({ fileTypes = [] }) => {
1490814911
fill: fileColors[extension]
1490914912
}), /* @__PURE__ */ import_react2.default.createElement("text", {
1491014913
x: "10",
14911-
style: { fontSize: "10px", fontWeight: 300 },
14914+
style: { fontSize: "14px", fontWeight: 300 },
1491214915
dominantBaseline: "middle"
1491314916
}, ".", extension))), /* @__PURE__ */ import_react2.default.createElement("div", {
1491414917
className: "w-20 whitespace-nowrap text-sm text-gray-500 font-light italic"
@@ -14966,7 +14969,7 @@ var processChild = (child, getColor, cachedOrders, i = 0) => {
1496614969
var reflowSiblings = (siblings, cachedPositions = {}, parentRadius, parentPosition) => {
1496714970
if (!siblings)
1496814971
return;
14969-
const items = [...siblings.map((d) => {
14972+
let items = [...siblings.map((d) => {
1497014973
var _a, _b;
1497114974
return {
1497214975
...d,
@@ -14982,23 +14985,23 @@ var reflowSiblings = (siblings, cachedPositions = {}, parentRadius, parentPositi
1498214985
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[0]) || width / 2;
1498314986
}).strength((d) => {
1498414987
var _a;
14985-
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[1]) ? 0.5 : 0.1;
14988+
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[1]) ? 0.5 : 0.2;
1498614989
})).force("y", y_default2((d) => {
1498714990
var _a;
1498814991
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[1]) || height / 2;
1498914992
}).strength((d) => {
1499014993
var _a;
14991-
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[0]) ? 0.5 : 0.6;
14992-
})).force("collide", collide_default((d) => d.children ? d.r + paddingScale(d.depth) : d.r + 3).iterations(13).strength(1)).stop();
14993-
for (let i = 0; i < 130; i++) {
14994+
return ((_a = cachedPositions[d.data.path]) == null ? void 0 : _a[0]) ? 0.5 : 0.1;
14995+
})).force("collide", collide_default((d) => d.children ? d.r + paddingScale(d.depth) : d.r + 3).iterations(9).strength(1)).stop();
14996+
for (let i = 0; i < 190; i++) {
1499414997
simulation.tick();
14995-
items.map((d) => {
14998+
items.forEach((d) => {
1499614999
d.x = keepBetween(d.r, d.x, width - d.r);
1499715000
d.y = keepBetween(d.r + 30, d.y, height - d.r);
1499815001
if (parentPosition && parentRadius) {
14999-
const newPosition = keepCircleInsideCircle(parentRadius, parentPosition, d.r, [d.x, d.y]);
15000-
d.x = newPosition[0];
15001-
d.y = newPosition[1];
15002+
const containedPosition = keepCircleInsideCircle(parentRadius, parentPosition, d.r, [d.x, d.y]);
15003+
d.x = containedPosition[0];
15004+
d.y = containedPosition[1];
1500215005
}
1500315006
});
1500415007
}
@@ -15025,8 +15028,6 @@ var reflowSiblings = (siblings, cachedPositions = {}, parentRadius, parentPositi
1502515028
];
1502615029
item.children = item.children.map((child) => repositionChildren(child, itemReflowDiff[0], itemReflowDiff[1]));
1502715030
if (item.children.length > 4) {
15028-
if (item.depth > 3)
15029-
return;
1503015031
item.children.forEach((child) => {
1503115032
const childCachedPosition = repositionedCachedPositions[child.data.path];
1503215033
if (childCachedPosition) {

0 commit comments

Comments
 (0)