#11490 calculate font size in treemap
This commit is contained in:
parent
13dbed4327
commit
075cc1d372
|
@ -506,6 +506,7 @@ function treeMap(recipient, data, width, height, childLinks = false) {
|
|||
.attr("width", function(d) {
|
||||
return Math.max(0.01, d.dx);
|
||||
})
|
||||
.attr("style", "transition: all 0.5s ease-out;")
|
||||
.attr("height", headerHeight)
|
||||
.text(function(d) {
|
||||
return d.name;
|
||||
|
@ -636,6 +637,29 @@ function treeMap(recipient, data, width, height, childLinks = false) {
|
|||
|
||||
zoom(node);
|
||||
|
||||
function calculateSizeText() {
|
||||
$(recipient + " .parent .clip .label").each((key, node) => {
|
||||
const textElement = node;
|
||||
const containerWidth = parseFloat(
|
||||
$(textElement)
|
||||
.parent()
|
||||
.attr("width")
|
||||
);
|
||||
const originalFontSize = 12;
|
||||
|
||||
textElement.style.fontSize = "16px";
|
||||
const textWidth = textElement.getComputedTextLength() + 8;
|
||||
textElement.style.fontSize = originalFontSize;
|
||||
|
||||
const scaleFactor = containerWidth / textWidth;
|
||||
let scaledFontSize = parseFloat(originalFontSize) * scaleFactor;
|
||||
|
||||
scaledFontSize = scaledFontSize > 12 ? 12 : scaledFontSize;
|
||||
|
||||
textElement.style.fontSize = scaledFontSize;
|
||||
});
|
||||
}
|
||||
|
||||
function size(d) {
|
||||
return d.size;
|
||||
}
|
||||
|
@ -756,6 +780,9 @@ function treeMap(recipient, data, width, height, childLinks = false) {
|
|||
if (d3.event) {
|
||||
d3.event.stopPropagation();
|
||||
}
|
||||
setTimeout(() => {
|
||||
calculateSizeText();
|
||||
}, transitionDuration);
|
||||
}
|
||||
|
||||
function position() {
|
||||
|
|
|
@ -408,7 +408,7 @@ class GroupsStatusMapWidget extends Widget
|
|||
foreach ($level1['children'] as $id_grupo => $group) {
|
||||
$level2['children'][] = [
|
||||
'id' => uniqid(),
|
||||
'name' => $names[$id_grupo],
|
||||
'name' => io_safe_output($names[$id_grupo]),
|
||||
'children' => $group,
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue