Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 2 | * Visualize span annotations as a tree |
| 3 | * using Dagre. |
Akron | 7524be1 | 2016-06-01 17:31:33 +0200 | [diff] [blame] | 4 | * |
| 5 | * This should be lazy loaded! |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 6 | */ |
| 7 | define(['lib/dagre'], function (dagre) { |
| 8 | "use strict"; |
| 9 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 10 | const d = document; |
| 11 | const svgNS = "http://www.w3.org/2000/svg"; |
| 12 | const _TermRE = new RegExp("^(?:([^\/]+?)\/)?([^:]+?):(.+?)$"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 13 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 14 | // Node size |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 15 | var WIDTH = 55, HEIGHT = 20, LINEHEIGHT = 14; |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 16 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 17 | // Create path for node connections |
| 18 | function _line (src, target) { |
| 19 | var x1 = src.x, |
| 20 | y1 = src.y, |
| 21 | x2 = target.x, |
| 22 | y2 = target.y - target.height / 2; |
| 23 | |
| 24 | // c 0,0 -10,0 |
| 25 | return 'M ' + x1 + ',' + y1 + ' ' + |
| 26 | 'C ' + x1 + ',' + y1 + ' ' + |
| 27 | x2 + ',' + (y2 - (y2 - y1) / 2) + ' ' + |
| 28 | x2 + ',' + y2; |
| 29 | }; |
| 30 | |
| 31 | return { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Create new tree visualization based |
| 35 | * on a match snippet. |
| 36 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 37 | create : function (snippet) { |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 38 | return Object.create(this). |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 39 | _init(snippet); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 40 | }, |
| 41 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 42 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 43 | // Initialize the tree based on a snippet. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 44 | _init : function (snippet) { |
| 45 | this._next = new Number(0); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 46 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 47 | // Create html for traversal |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 48 | var html = d.createElement("div"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 49 | html.innerHTML = snippet; |
| 50 | var g = new dagre.graphlib.Graph({ |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 51 | "directed" : true |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 52 | }); |
| 53 | g.setGraph({ |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 54 | "nodesep" : 35, |
| 55 | "ranksep" : 15, |
| 56 | "marginx" : 40, |
| 57 | "marginy" : 10 |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 58 | }); |
| 59 | g.setDefaultEdgeLabel({}); |
| 60 | |
| 61 | this._graph = g; |
| 62 | |
| 63 | // This is a new root |
| 64 | this._addNode( |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 65 | this._next++, |
| 66 | { "class" : "root" } |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 67 | ); |
| 68 | |
| 69 | // Parse nodes from root |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 70 | this._parse(0, html.childNodes, undefined); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 71 | |
| 72 | // Root node has only one child - remove |
| 73 | if (g.outEdges(0).length === 1) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 74 | g.removeNode(0); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 75 | |
| 76 | html = undefined; |
| 77 | return this; |
| 78 | }, |
| 79 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 80 | |
| 81 | _c : function (tag) { |
| 82 | return d.createElementNS(svgNS, tag); |
| 83 | }, |
| 84 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 85 | /** |
| 86 | * The number of nodes in the tree. |
| 87 | */ |
| 88 | nodes : function () { |
| 89 | return this._next; |
| 90 | }, |
| 91 | |
| 92 | // Add new node to graph |
| 93 | _addNode : function (id, obj) { |
| 94 | obj["width"] = WIDTH; |
| 95 | obj["height"] = HEIGHT; |
| 96 | this._graph.setNode(id, obj) |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 97 | return obj; |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 98 | }, |
| 99 | |
| 100 | // Add new edge to graph |
| 101 | _addEdge : function (src, target) { |
| 102 | this._graph.setEdge(src, target); |
| 103 | }, |
| 104 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 105 | // Remove foundry and layer for labels |
| 106 | _clean : function (title) { |
| 107 | return title.replace(_TermRE, "$3"); |
| 108 | }, |
| 109 | |
| 110 | // Parse the snippet |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 111 | _parse : function (parent, children, mark) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 112 | for (var i in children) { |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 113 | var c = children[i]; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 114 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 115 | // Element node |
| 116 | if (c.nodeType == 1) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 117 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 118 | // Get title from html |
| 119 | if (c.getAttribute("title")) { |
| 120 | var title = this._clean(c.getAttribute("title")); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 121 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 122 | // Add child node |
| 123 | var id = this._next++; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 124 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 125 | var obj = this._addNode(id, { |
| 126 | "class" : "middle", |
| 127 | "label" : title |
| 128 | }); |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 129 | |
| 130 | if (mark !== undefined) { |
| 131 | obj.class += ' mark'; |
| 132 | }; |
| 133 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 134 | this._addEdge(parent, id); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 135 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 136 | // Check for next level |
| 137 | if (c.hasChildNodes()) |
| 138 | this._parse(id, c.childNodes, mark); |
| 139 | } |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 140 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 141 | // Step further |
| 142 | else if (c.hasChildNodes()) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 143 | |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 144 | if (c.tagName === 'MARK') { |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 145 | this._parse(parent, c.childNodes, true); |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 146 | } |
| 147 | else { |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 148 | this._parse(parent, c.childNodes, mark); |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 149 | }; |
| 150 | }; |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 151 | } |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 152 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 153 | // Text node |
| 154 | else if (c.nodeType == 3) |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 155 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 156 | if (c.nodeValue.match(/[-a-z0-9]/i)) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 157 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 158 | // Add child node |
| 159 | var id = this._next++; |
| 160 | this._addNode(id, { |
| 161 | "class" : "leaf", |
| 162 | "label" : c.nodeValue |
| 163 | }); |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 164 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 165 | this._addEdge(parent, id); |
| 166 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 167 | }; |
| 168 | return this; |
| 169 | }, |
| 170 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 171 | // Dummy method to be compatible with relTree |
| 172 | show : function () { |
| 173 | return; |
| 174 | }, |
| 175 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 176 | /** |
| 177 | * Center the viewport of the canvas |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 178 | * TODO: |
| 179 | * This is identical to relations |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 180 | */ |
| 181 | center : function () { |
| 182 | if (this._element === undefined) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 183 | return; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 184 | |
| 185 | var treeDiv = this._element.parentNode; |
| 186 | |
| 187 | var cWidth = parseFloat(window.getComputedStyle(this._element).width); |
| 188 | var treeWidth = parseFloat(window.getComputedStyle(treeDiv).width); |
| 189 | // Reposition: |
| 190 | if (cWidth > treeWidth) { |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 191 | var scrollValue = (cWidth - treeWidth) / 2; |
| 192 | treeDiv.scrollLeft = scrollValue; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 193 | }; |
| 194 | }, |
| 195 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 196 | |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 197 | /** |
| 198 | * Create svg and serialize as base64 |
| 199 | */ |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 200 | toBase64 : function () { |
Akron | 6f32f82 | 2016-11-10 00:23:40 +0100 | [diff] [blame] | 201 | |
| 202 | // First clone element |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 203 | var svgWrapper = d.createElement('div') |
Akron | 6f32f82 | 2016-11-10 00:23:40 +0100 | [diff] [blame] | 204 | svgWrapper.innerHTML = this.element().outerHTML; |
| 205 | var svg = svgWrapper.firstChild; |
| 206 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 207 | var style = this._c('style'); |
Akron | 6f32f82 | 2016-11-10 00:23:40 +0100 | [diff] [blame] | 208 | svg.getElementsByTagName('defs')[0].appendChild(style); |
| 209 | |
| 210 | style.innerHTML = |
| 211 | 'path.edge ' + '{ stroke: black; stroke-width: 2pt; fill: none; }' + |
| 212 | 'g.root rect.empty,' + |
| 213 | 'g.middle rect' + '{ stroke: black; stroke-width: 2pt; fill: #bbb; }' + |
| 214 | 'g.leaf > rect ' + '{ display: none }' + |
| 215 | 'g > text > tspan ' + '{ text-anchor: middle; font-size: 9pt }' + |
| 216 | 'g.leaf > text > tspan ' + '{ font-size: 10pt; overflow: visible; }'; |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame^] | 217 | |
| 218 | return btoa(unescape(encodeURIComponent(svg.outerHTML)).replace(/ /g, ' ')); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 219 | }, |
| 220 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 221 | /** |
| 222 | * Get the dom element of the tree view. |
| 223 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 224 | element : function () { |
| 225 | if (this._element !== undefined) |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 226 | return this._element; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 227 | |
| 228 | var g = this._graph; |
| 229 | |
| 230 | dagre.layout(g); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 231 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 232 | var canvas = this._c('svg'); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 233 | this._element = canvas; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 234 | var that = this; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 235 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 236 | canvas.appendChild(this._c('defs')); |
Akron | 6f32f82 | 2016-11-10 00:23:40 +0100 | [diff] [blame] | 237 | |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 238 | var height = g.graph().height; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 239 | |
| 240 | // Create edges |
| 241 | g.edges().forEach( |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 242 | function (e) { |
| 243 | var src = g.node(e.v); |
| 244 | var target = g.node(e.w); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 245 | var p = that._c('path'); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 246 | p.setAttributeNS(null, "d", _line(src, target)); |
| 247 | p.classList.add('edge'); |
| 248 | canvas.appendChild(p); |
| 249 | }); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 250 | |
| 251 | // Create nodes |
| 252 | g.nodes().forEach( |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 253 | function (v) { |
| 254 | v = g.node(v); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 255 | var group = that._c('g'); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 256 | group.setAttribute('class', v.class); |
| 257 | |
| 258 | // Add node box |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 259 | var rect = group.appendChild(that._c('rect')); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 260 | rect.setAttribute('x', v.x - v.width / 2); |
| 261 | rect.setAttribute('y', v.y - v.height / 2); |
| 262 | rect.setAttribute('rx', 5); |
| 263 | rect.setAttribute('ry', 5); |
| 264 | rect.setAttribute('width', v.width); |
| 265 | rect.setAttribute('height', v.height); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 266 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 267 | if (v.class === 'root' && v.label === undefined) { |
| 268 | rect.setAttribute('width', v.height); |
| 269 | rect.setAttribute('x', v.x - v.height / 2); |
| 270 | rect.setAttribute('class', 'empty'); |
| 271 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 272 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 273 | // Add label |
| 274 | if (v.label !== undefined) { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 275 | var text = group.appendChild(that._c('text')); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 276 | var y = v.y - v.height / 2; |
| 277 | text.setAttribute('y', y); |
| 278 | text.setAttribute( |
| 279 | 'transform', |
| 280 | 'translate(' + v.width/2 + ',' + ((v.height / 2) + 5) + ')' |
| 281 | ); |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame^] | 282 | |
| 283 | var vLabel = v.label.replace(/ /g, " ") |
| 284 | .replace(/&/g, '&') |
| 285 | .replace(/</g, '<') |
| 286 | .replace(/>/g, '>'); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 287 | |
| 288 | if (v.class === "leaf") { |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame^] | 289 | text.setAttribute('title', vLabel); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 290 | |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame^] | 291 | var labelPart = vLabel.split(" "); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 292 | var n = 0; |
| 293 | for (var i = 0; i < labelPart.length; i++) { |
| 294 | if (labelPart[i].length === 0) |
| 295 | continue; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 296 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 297 | var tspan = that._c('tspan'); |
| 298 | tspan.appendChild(d.createTextNode(labelPart[i])); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 299 | if (n !== 0) |
| 300 | tspan.setAttribute('dy', LINEHEIGHT + 'pt'); |
| 301 | else |
| 302 | n = 1; |
| 303 | tspan.setAttribute('x', v.x - v.width / 2); |
| 304 | y += LINEHEIGHT; |
| 305 | text.appendChild(tspan); |
| 306 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 307 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 308 | y += LINEHEIGHT; |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 309 | |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 310 | // The text is below the canvas - readjust the height! |
| 311 | if (y > height) |
| 312 | height = y; |
| 313 | } |
| 314 | else { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 315 | var tspan = that._c('tspan'); |
Akron | 3bdac53 | 2019-03-04 13:24:43 +0100 | [diff] [blame^] | 316 | tspan.appendChild(d.createTextNode(vLabel)); |
Akron | c56cf2d | 2016-11-09 22:02:38 +0100 | [diff] [blame] | 317 | tspan.setAttribute('x', v.x - v.width / 2); |
| 318 | text.appendChild(tspan); |
| 319 | }; |
| 320 | }; |
| 321 | canvas.appendChild(group); |
| 322 | } |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 323 | ); |
| 324 | |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 325 | canvas.setAttribute('width', g.graph().width); |
| 326 | canvas.setAttribute('height', height); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 327 | return this._element; |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 328 | }, |
| 329 | |
| 330 | downloadLink : function () { |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 331 | var a = d.createElement('a'); |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 332 | a.setAttribute('href-lang', 'image/svg+xml'); |
| 333 | a.setAttribute('href', 'data:image/svg+xml;base64,' + this.toBase64()); |
| 334 | a.setAttribute('download', 'tree.svg'); |
| 335 | a.target = '_blank'; |
| 336 | a.setAttribute('rel', 'noopener noreferrer'); |
| 337 | return a; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 338 | } |
| 339 | }; |
| 340 | }); |