vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.5 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Multifont Labels</title>
  5. <script type="text/javascript" src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. #mynetwork {
  9. width: 600px;
  10. height: 400px;
  11. border: 1px solid lightgray;
  12. }
  13. code {
  14. font-size: 15px;
  15. }
  16. p {
  17. max-width: 600px;
  18. }
  19. .indented {
  20. margin-left: 30px;
  21. }
  22. table {
  23. border-collapse: collapse;
  24. font-family: sans-serif;
  25. }
  26. table code {
  27. background: #dddddd;
  28. }
  29. th, td {
  30. border: 1px solid #aaaaaa;
  31. text-align: center;
  32. padding: 5px;
  33. font-weight: normal;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <p>Node and edge labels may be marked up to be drawn with multiple fonts.</p>
  39. <div id="mynetwork"></div>
  40. <p>The value of the <code>font.multi</code> property may be set to <code>'html'</code>, <code>'markdown'</code> or a boolean.</p>
  41. <table class="indented">
  42. <tr><th colspan='4'>Embedded Font Markup</th></tr>
  43. <tr><th rowspan=2>font mod</th><th colspan=3><code>font.multi</code> setting</th></tr>
  44. <tr><th><code>'html'</code> or <code>true</code></th><th><code>'markdown'</code> or <code>'md'</code></th><th><code>false<code></th></tr>
  45. <tr><th>bold</th><td><code>&lt;b&gt;</code> ... <code>&lt;/b></code></td><td><code>&nbsp;*</code> ... <code>*&nbsp;</code></td><td>n/a</td></tr>
  46. <tr><th>italic</th><td><code>&lt;i&gt;</code> ... <code>&lt;/i></code></td><td><code>&nbsp;_</code> ... <code>_&nbsp;</code></td><td>n/a</td></tr>
  47. <tr><th>mono-spaced</th><td><code>&lt;code&gt;</code> ... <code>&lt;/code&gt;</code></td><td><code>&nbsp;`</code> ... <code>`&nbsp;</code></td><td>n/a</td></tr>
  48. </table>
  49. <p>
  50. The <code>html</code> and <code>markdown</code> rendering is limited: bolds may be embedded in italics, italics may be embedded in bolds, and mono-spaced may be embedded in bold or italic, but will not be altered by those font mods, nor will embedded bolds or italics be handled.
  51. The only entities that will be observed in html are <code>&amp;lt;</code> and <code>&amp;amp;</code> and in <code>markdown</code> a backslash will escape the following character (including a backslash) from special processing.
  52. Any font mod that is started in a label line will be implicitly terminated at the end of that line.
  53. While this interpretation may not exactly match <i>official</i> rendering standards, it is a consistent compromise for drawing multifont strings in the non-multifont html canvas element underlying vis.
  54. </p>
  55. <p>This implies that four additional sets of font properties will be recognized in label processing.</p>
  56. <p class="indented"><code>font.bold</code> designates the font used for rendering bold font mods.
  57. <br/><code>font.ital</code> designates the font used for rendering italic font mods.
  58. <br/><code>font.boldital</code> designates the font used for rendering bold-<b><i>and</i></b>-italic font mods.
  59. <br/><code>font.mono</code> designates the font used for rendering monospaced font mods.</p>
  60. <p>Any font mod without a matching font will be rendered using the normal <code>font</code> (or default) value.</p>
  61. <p>The <code>font.multi</code> and extended font settings may be set in the network's <code>nodes</code> or <code>edges</code> properties, or on individual nodes and edges.
  62. Node and edge label fonts are separate.</p>
  63. <script type="text/javascript">
  64. var nodes = [
  65. { id: 1, label: 'This is a\nsingle-font label', x: -120, y: -120 },
  66. { id: 2, font: { multi: true }, label: '<b>This</b> is a\n<i>default</i> <b><i>multi-</i>font</b> <code>label</code>', x: -40, y: -40 },
  67. { id: 3, font: { multi: 'html', size: 20 }, label: '<b>This</b> is an\n<i>html</i> <b><i>multi-</i>font</b> <code>label</code>', x: 40, y: 40 },
  68. { id: 4, font: { multi: 'md', face: 'georgia' }, label: '*This* is a\n_markdown_ *_multi-_ font* `label`', x: 120, y: 120},
  69. ];
  70. var edges = [
  71. {from: 1, to: 2, label: "single to default"},
  72. {from: 2, to: 3, font: { multi: true }, label: "default to <b>html</b>" },
  73. {from: 3, to: 4, font: { multi: "md" }, label: "*html* to _md_" }
  74. ];
  75. var container = document.getElementById('mynetwork');
  76. var data = {
  77. nodes: nodes,
  78. edges: edges
  79. };
  80. var options = {
  81. edges: {
  82. font: {
  83. size: 12
  84. }
  85. },
  86. nodes: {
  87. shape: 'box',
  88. font: {
  89. bold: {
  90. color: '#0077aa'
  91. }
  92. }
  93. },
  94. physics: {
  95. enabled: false
  96. }
  97. };
  98. var network = new vis.Network(container, data, options);
  99. </script>
  100. </body>
  101. </html>