UNPKG

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