简体   繁体   English

如何在vis js中设置标题的高度?

[英]How can I set the height ot the title in vis js?

I created a network graph within a modal. 我在模态中创建了一个网络图。 My problem is that if I want to put a long sentence into the title of the edge, the title is out of the modal and I can't see the full sentence. 我的问题是,如果我想在边的标题中添加一个长句子,则标题不在模态中,因此我看不到完整的句子。 I'm trying to set the title's width with widthConstraint , but it just works only with labels. 我正在尝试使用widthConstraint设置标题的宽度,但是它仅适用于标签。 I'm also trying to set the modal's with, but it doesn't work also. 我也试图设置模式的,但是它也不起作用。 How can I set the title's width? 如何设置标题的宽度?

demo 演示

 function drawNetwork() { var nodes = [ {id: 1, label: 'node 1'}, {id: 2, label: 'node 2'} ]; var edges = [ {from: 1, to: 2, title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."} ] var container = document.getElementById('network-container'); var data = { nodes: nodes, edges: edges }; var width = 550; var height = 400; var options = { width: width + 'px', height: height + 'px', nodes: { shape: 'dot' }, edges: { smooth: false }, physics: false, interaction: { dragNodes: true,// do not allow dragging nodes zoomView: false, // do not allow zooming dragView: true // do not allow dragging }, layout: { randomSeed:1, improvedLayout:true, hierarchical: { enabled:true, levelSeparation: 300, nodeSpacing: 100, treeSpacing: 10, blockShifting: false, edgeMinimization: true, parentCentralization: true, direction: 'LR', // UD, DU, LR, RL sortMethod: 'directed' // hubsize, directed } } }; var network = new vis.Network(container, data, options); } $('#model4temp').on('shown.bs.modal', function() { drawNetwork(); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.17.0/vis.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.17.0/vis.min.css" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <a href='#' data-toggle='modal' data-target='#model4temp'>Click here for network in modal</a> <div class="modal fade" id="model4temp" tabindex="-1" role="dialog" aria-labelledby="basicModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="myModalLabel">Sample Network in modal</h4> </div> <div class="modal-body"> <div id="network-container" style="height:400px;width:500px;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> 

The nice thing is, labels allow html and css inside them. 不错的是,标签允许在其中包含html和CSS。 Here's your snippet, modified in only one aspect: instead of 这是您的代码段,仅在一个方面进行了修改:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

I put a wrapped version into the label: 我将包装好的版本放入标签中:

<div style='white-space: normal;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>

For some (rather understandable) reason, label initially has something like white-space: nowrap and changing it back to normal fixes the issue: 出于某些(相当容易理解的原因),标签最初具有类似white-space: nowrap并将其更改回normal可解决此问题:

 function drawNetwork() { var nodes = [ {id: 1, label: 'node 1'}, {id: 2, label: 'node 2'} ]; var edges = [ {from: 1, to: 2, title: "<div style='white-space: normal; max-width: 15em;'>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>"} ] var container = document.getElementById('network-container'); var data = { nodes: nodes, edges: edges }; var width = 550; var height = 400; var options = { width: width + 'px', height: height + 'px', nodes: { shape: 'dot' }, edges: { smooth: false }, physics: false, interaction: { dragNodes: true,// do not allow dragging nodes zoomView: false, // do not allow zooming dragView: true // do not allow dragging }, layout: { randomSeed:1, improvedLayout:true, hierarchical: { enabled:true, levelSeparation: 300, nodeSpacing: 100, treeSpacing: 10, blockShifting: false, edgeMinimization: true, parentCentralization: true, direction: 'LR', // UD, DU, LR, RL sortMethod: 'directed' // hubsize, directed } } }; var network = new vis.Network(container, data, options); } $('#model4temp').on('shown.bs.modal', function() { drawNetwork(); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.17.0/vis.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.17.0/vis.min.css" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <a href='#' data-toggle='modal' data-target='#model4temp'>Click here for network in modal</a> <div class="modal fade" id="model4temp" tabindex="-1" role="dialog" aria-labelledby="basicModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="myModalLabel">Sample Network in modal</h4> </div> <div class="modal-body"> <div id="network-container" style="height:400px;width:500px;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> 

PS this still doesn't work always as desired: depends on where the edge was hovered. PS这仍然不能始终如愿地工作:取决于边缘的悬停位置。 Not sure why they made it work this way, but perhaps dealing with the container and its margins can fix the issue.. 不知道他们为什么要这样工作,但是也许处理容器及其边距可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM