One can set the width of the node to label and the node width will be based on the label text. However, I cannot locate any documentation for this behavior. I happened across it with other google searches.
I do now see with the code snippet that this feature is deprecated...? Has it been replaced with a new, modern method...?
I am also wondering if it is possible to base the size of the node on the background svg image and where this might be documented, if possible.
const cy = cytoscape({
container: document.getElementById("chart"),
elements: [
{
data: { id: "a", custom: "\uf3c5" }
}
],
style: [
{
selector: "node",
style: {
width: "label",
"background-color": "#666",
"text-valign": "center",
"text-halign": "center",
shape: "round-rectangle",
label: "hello node width based on me"
}
}
],
layout: {
name: "grid",
rows: 1
}
});
.chart {
color: red;
width: 1000px;
height: 400px;
background-color: lightgrey;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.28.1/cytoscape.min.js"></script>
<div class="chart" id="chart">
</div>
The documentation you are looking for no longer exists. Using
width: 'label',has been deprecated since Sep 14, 2020.As you can see here, the main contributer of cytoscape.js deprecated this feature.
There are ways to still get a similar result, as can be seen in this StackOverflow answer:
Below, I added an MRE with a working solution: