cytoscape.js - Cytoscape JS - 字体更改后重绘节点
问题描述
我的 Cytoscape 图的风格是
selector: 'node',
style: {
'background-color': '#efefef',
'label': function(ele) { return ele.data('name'); },
'font-family' : 'Calibri',
'font-size' : '10px',
'shape' : 'ellipse',
'text-halign' : 'center' ,
'text-valign' : 'center',
'width' : 'label' ,
'padding' : '8px' ,
'text-wrap' : 'wrap' ,
'text-max-width' : '120px' ,
'border-color' : '#ffbb33',
'border-style' : 'solid' ,
'border-width' : '1'
}
我有一个下拉框允许用户选择字体。当用户更改下拉菜单中的字体时,我基本上运行这段代码
$('#font').change(function(){
window.cy.nodes().forEach(function( ele ){
ele.style('font-family', $('#font').val());
});
window.cy.resize();
//window.cy.layout({name : 'klay'}).run();
//window.cy.elements('#13, #14, #15, #16, #17, #18').layout({name: 'cose'}).run();
});
节点会使用新字体进行更新,但由于字体已更改,文本不会保留在绘制的椭圆内。
应用样式更改后如何让节点重新渲染?
解决方案
好的。非常简单 - 使用 window.cy.json({}) 更改样式并更新;
$('.x-bold').click(function(){
let cyJson = window.cy.json(true);
let style = cyJson.style[0];
style.style['font-weight'] = 'bold';
cyJson.style[0] = style;
window.cy.json({style : cyJson.style });
});
推荐阅读
- wand - 仅从 blob 加载第一页
- iframe - 使用 url 在 iram 中加载私有驱动器演示文稿,但同样的事情不适用于 PDF
- android - 将光标返回到起始位置
- angular - 使用 JWT 和 Spring Boot 跟踪用户活动的最佳方法
- html - css三角形上的响应式vue样式绑定不起作用
- apache - 单页应用程序 - .htaccess 配置
- scala - Maven 不编译类
- snowflake-cloud-data-platform - 不同云平台上的雪花性能
- jenkins - 我如何找到新推送代码到 github 的人的用户名/详细信息?我正在使用 jenkins 管道来构建和部署
- firebase - Firebase 电话身份验证被阻止