暂无描述

webhtml.go 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. // Copyright 2017 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package driver
  15. import "html/template"
  16. // webTemplate defines a collection of related templates:
  17. // css
  18. // header
  19. // script
  20. // graph
  21. // top
  22. var webTemplate = template.Must(template.New("web").Parse(`
  23. {{define "css"}}
  24. <style type="text/css">
  25. html, body {
  26. height: 100%;
  27. min-height: 100%;
  28. margin: 0px;
  29. }
  30. body {
  31. width: 100%;
  32. height: 100%;
  33. min-height: 100%;
  34. overflow: hidden;
  35. }
  36. #graphcontainer {
  37. display: flex;
  38. flex-direction: column;
  39. height: 100%;
  40. min-height: 100%;
  41. width: 100%;
  42. min-width: 100%;
  43. margin: 0px;
  44. }
  45. #graph {
  46. flex: 1 1 auto;
  47. overflow: hidden;
  48. }
  49. svg {
  50. width: 100%;
  51. height: auto;
  52. }
  53. button {
  54. margin-top: 5px;
  55. margin-bottom: 5px;
  56. }
  57. #detailtext {
  58. display: none;
  59. position: fixed;
  60. top: 20px;
  61. right: 10px;
  62. background-color: #ffffff;
  63. min-width: 160px;
  64. border: 1px solid #888;
  65. box-shadow: 4px 4px 4px 0px rgba(0,0,0,0.2);
  66. z-index: 1;
  67. }
  68. #closedetails {
  69. float: right;
  70. margin: 2px;
  71. }
  72. #home {
  73. font-size: 14pt;
  74. padding-left: 0.5em;
  75. padding-right: 0.5em;
  76. float: right;
  77. }
  78. .menubar {
  79. display: inline-block;
  80. background-color: #f8f8f8;
  81. border: 1px solid #ccc;
  82. width: 100%;
  83. }
  84. .menu-header {
  85. position: relative;
  86. display: inline-block;
  87. padding: 2px 2px;
  88. cursor: default;
  89. font-size: 14pt;
  90. }
  91. .menu {
  92. display: none;
  93. position: absolute;
  94. background-color: #f8f8f8;
  95. border: 1px solid #888;
  96. box-shadow: 4px 4px 4px 0px rgba(0,0,0,0.2);
  97. z-index: 1;
  98. margin-top: 2px;
  99. left: 0px;
  100. min-width: 5em;
  101. }
  102. .menu hr {
  103. background-color: #fff;
  104. margin-top: 0px;
  105. margin-bottom: 0px;
  106. }
  107. .menu button {
  108. display: block;
  109. width: 100%;
  110. margin: 0px;
  111. text-align: left;
  112. padding-left: 2px;
  113. background-color: #fff;
  114. font-size: 12pt;
  115. border: none;
  116. }
  117. .menu-header:hover {
  118. background-color: #ccc;
  119. }
  120. .menu-header:hover .menu {
  121. display: block;
  122. }
  123. .menu button:hover {
  124. background-color: #ccc;
  125. }
  126. #searchbox {
  127. margin-left: 10pt;
  128. }
  129. #topcontainer {
  130. width: 100%;
  131. height: 100%;
  132. max-height: 100%;
  133. overflow: scroll;
  134. }
  135. #toptable {
  136. border-spacing: 0px;
  137. }
  138. #toptable tr th {
  139. border-bottom: 1px solid black;
  140. text-align: right;
  141. padding-left: 1em;
  142. }
  143. #toptable tr th:nth-child(6) { text-align: left; }
  144. #toptable tr th:nth-child(7) { text-align: left; }
  145. #toptable tr td {
  146. padding-left: 1em;
  147. font: monospace;
  148. text-align: right;
  149. white-space: nowrap;
  150. cursor: default;
  151. }
  152. #toptable tr td:nth-child(6) { text-align: left; }
  153. #toptable tr td:nth-child(7) { text-align: left; }
  154. .hilite {
  155. background-color: #ccf;
  156. }
  157. </style>
  158. {{end}}
  159. {{define "header"}}
  160. <div id="detailtext">
  161. <button id="closedetails">Close</button>
  162. {{range .Legend}}<div>{{.}}</div>{{end}}
  163. </div>
  164. <div class="menubar">
  165. <div class="menu-header">
  166. View
  167. <div class="menu">
  168. {{if (ne .Type "top")}}
  169. <button title="{{.Help.top}}" id="topbtn">Top</button>
  170. {{end}}
  171. {{if (ne .Type "dot")}}
  172. <button title="{{.Help.graph}}" id="graphbtn">Graph</button>
  173. {{end}}
  174. <hr>
  175. <button title="{{.Help.details}}" id="details">Details</button>
  176. </div>
  177. </div>
  178. <div class="menu-header">
  179. Functions
  180. <div class="menu">
  181. <button title="{{.Help.peek}}" id="peek">Peek</button>
  182. <button title="{{.Help.list}}" id="list">List</button>
  183. <button title="{{.Help.disasm}}" id="disasm">Disassemble</button>
  184. </div>
  185. </div>
  186. <div class="menu-header">
  187. Refine
  188. <div class="menu">
  189. <button title="{{.Help.focus}}" id="focus">Focus</button>
  190. <button title="{{.Help.ignore}}" id="ignore">Ignore</button>
  191. <button title="{{.Help.hide}}" id="hide">Hide</button>
  192. <button title="{{.Help.show}}" id="show">Show</button>
  193. <hr>
  194. <button title="{{.Help.reset}}" id="reset">Reset</button>
  195. </div>
  196. </div>
  197. <input id="searchbox" type="text" placeholder="Search regexp" autocomplete="off" autocapitalize="none" size=40>
  198. <span id="home">{{.Title}}</span>
  199. </div> <!-- menubar -->
  200. <div id="errors">{{range .Errors}}<div>{{.}}</div>{{end}}</div>
  201. {{end}}
  202. {{define "graph" -}}
  203. <!DOCTYPE html>
  204. <html>
  205. <head>
  206. <meta charset="utf-8">
  207. <title>{{.Title}}</title>
  208. {{template "css" .}}
  209. </head>
  210. <body>
  211. {{template "header" .}}
  212. <div id="graphcontainer">
  213. <div id="graph">
  214. {{.Svg}}
  215. </div>
  216. </div>
  217. {{template "script" .}}
  218. <script>viewer({{.BaseURL}}, {{.Nodes}})</script>
  219. </body>
  220. </html>
  221. {{end}}
  222. {{define "script"}}
  223. <script>
  224. // Make svg pannable and zoomable.
  225. // Call clickHandler(t) if a click event is caught by the pan event handlers.
  226. function initPanAndZoom(svg, clickHandler) {
  227. 'use strict';
  228. // Current mouse/touch handling mode
  229. const IDLE = 0
  230. const MOUSEPAN = 1
  231. const TOUCHPAN = 2
  232. const TOUCHZOOM = 3
  233. let mode = IDLE
  234. // State needed to implement zooming.
  235. let currentScale = 1.0
  236. const initWidth = svg.viewBox.baseVal.width
  237. const initHeight = svg.viewBox.baseVal.height
  238. // State needed to implement panning.
  239. let panLastX = 0 // Last event X coordinate
  240. let panLastY = 0 // Last event Y coordinate
  241. let moved = false // Have we seen significant movement
  242. let touchid = null // Current touch identifier
  243. // State needed for pinch zooming
  244. let touchid2 = null // Second id for pinch zooming
  245. let initGap = 1.0 // Starting gap between two touches
  246. let initScale = 1.0 // currentScale when pinch zoom started
  247. let centerPoint = null // Center point for scaling
  248. // Convert event coordinates to svg coordinates.
  249. function toSvg(x, y) {
  250. const p = svg.createSVGPoint()
  251. p.x = x
  252. p.y = y
  253. let m = svg.getCTM()
  254. if (m == null) m = svg.getScreenCTM() // Firefox workaround.
  255. return p.matrixTransform(m.inverse())
  256. }
  257. // Change the scaling for the svg to s, keeping the point denoted
  258. // by u (in svg coordinates]) fixed at the same screen location.
  259. function rescale(s, u) {
  260. // Limit to a good range.
  261. if (s < 0.2) s = 0.2
  262. if (s > 10.0) s = 10.0
  263. currentScale = s
  264. // svg.viewBox defines the visible portion of the user coordinate
  265. // system. So to magnify by s, divide the visible portion by s,
  266. // which will then be stretched to fit the viewport.
  267. const vb = svg.viewBox
  268. const w1 = vb.baseVal.width
  269. const w2 = initWidth / s
  270. const h1 = vb.baseVal.height
  271. const h2 = initHeight / s
  272. vb.baseVal.width = w2
  273. vb.baseVal.height = h2
  274. // We also want to adjust vb.baseVal.x so that u.x remains at same
  275. // screen X coordinate. In other words, want to change it from x1 to x2
  276. // so that:
  277. // (u.x - x1) / w1 = (u.x - x2) / w2
  278. // Simplifying that, we get
  279. // (u.x - x1) * (w2 / w1) = u.x - x2
  280. // x2 = u.x - (u.x - x1) * (w2 / w1)
  281. vb.baseVal.x = u.x - (u.x - vb.baseVal.x) * (w2 / w1)
  282. vb.baseVal.y = u.y - (u.y - vb.baseVal.y) * (h2 / h1)
  283. }
  284. function handleWheel(e) {
  285. if (e.deltaY == 0) return
  286. // Change scale factor by 1.1 or 1/1.1
  287. rescale(currentScale * (e.deltaY < 0 ? 1.1 : (1/1.1)),
  288. toSvg(e.offsetX, e.offsetY))
  289. }
  290. function setMode(m) {
  291. mode = m
  292. touchid = null
  293. touchid2 = null
  294. }
  295. function panStart(x, y) {
  296. moved = false
  297. panLastX = x
  298. panLastY = y
  299. }
  300. function panMove(x, y) {
  301. let dx = x - panLastX
  302. let dy = y - panLastY
  303. if (Math.abs(dx) <= 2 && Math.abs(dy) <= 2) return // Ignore tiny moves
  304. moved = true
  305. panLastX = x
  306. panLastY = y
  307. // Firefox workaround: get dimensions from parentNode.
  308. const swidth = svg.clientWidth || svg.parentNode.clientWidth
  309. const sheight = svg.clientHeight || svg.parentNode.clientHeight
  310. // Convert deltas from screen space to svg space.
  311. dx *= (svg.viewBox.baseVal.width / swidth)
  312. dy *= (svg.viewBox.baseVal.height / sheight)
  313. svg.viewBox.baseVal.x -= dx
  314. svg.viewBox.baseVal.y -= dy
  315. }
  316. function handleScanStart(e) {
  317. if (e.button != 0) return // Do not catch right-clicks etc.
  318. setMode(MOUSEPAN)
  319. panStart(e.clientX, e.clientY)
  320. e.preventDefault()
  321. svg.addEventListener("mousemove", handleScanMove)
  322. }
  323. function handleScanMove(e) {
  324. if (e.buttons == 0) {
  325. // Missed an end event, perhaps because mouse moved outside window.
  326. setMode(IDLE)
  327. svg.removeEventListener("mousemove", handleScanMove)
  328. return
  329. }
  330. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY)
  331. }
  332. function handleScanEnd(e) {
  333. if (mode == MOUSEPAN) panMove(e.clientX, e.clientY)
  334. setMode(IDLE)
  335. svg.removeEventListener("mousemove", handleScanMove)
  336. if (!moved) clickHandler(e.target)
  337. }
  338. // Find touch object with specified identifier.
  339. function findTouch(tlist, id) {
  340. for (const t of tlist) {
  341. if (t.identifier == id) return t
  342. }
  343. return null
  344. }
  345. // Return distance between two touch points
  346. function touchGap(t1, t2) {
  347. const dx = t1.clientX - t2.clientX
  348. const dy = t1.clientY - t2.clientY
  349. return Math.hypot(dx, dy)
  350. }
  351. function handleTouchStart(e) {
  352. if (mode == IDLE && e.changedTouches.length == 1) {
  353. // Start touch based panning
  354. const t = e.changedTouches[0]
  355. setMode(TOUCHPAN)
  356. touchid = t.identifier
  357. panStart(t.clientX, t.clientY)
  358. e.preventDefault()
  359. } else if (mode == TOUCHPAN && e.touches.length == 2) {
  360. // Start pinch zooming
  361. setMode(TOUCHZOOM)
  362. const t1 = e.touches[0]
  363. const t2 = e.touches[1]
  364. touchid = t1.identifier
  365. touchid2 = t2.identifier
  366. initScale = currentScale
  367. initGap = touchGap(t1, t2)
  368. centerPoint = toSvg((t1.clientX + t2.clientX) / 2,
  369. (t1.clientY + t2.clientY) / 2)
  370. e.preventDefault()
  371. }
  372. }
  373. function handleTouchMove(e) {
  374. if (mode == TOUCHPAN) {
  375. const t = findTouch(e.changedTouches, touchid)
  376. if (t == null) return
  377. if (e.touches.length != 1) {
  378. setMode(IDLE)
  379. return
  380. }
  381. panMove(t.clientX, t.clientY)
  382. e.preventDefault()
  383. } else if (mode == TOUCHZOOM) {
  384. // Get two touches; new gap; rescale to ratio.
  385. const t1 = findTouch(e.touches, touchid)
  386. const t2 = findTouch(e.touches, touchid2)
  387. if (t1 == null || t2 == null) return
  388. const gap = touchGap(t1, t2)
  389. rescale(initScale * gap / initGap, centerPoint)
  390. e.preventDefault()
  391. }
  392. }
  393. function handleTouchEnd(e) {
  394. if (mode == TOUCHPAN) {
  395. const t = findTouch(e.changedTouches, touchid)
  396. if (t == null) return
  397. panMove(t.clientX, t.clientY)
  398. setMode(IDLE)
  399. e.preventDefault()
  400. if (!moved) clickHandler(t.target)
  401. } else if (mode == TOUCHZOOM) {
  402. setMode(IDLE)
  403. e.preventDefault()
  404. }
  405. }
  406. svg.addEventListener("mousedown", handleScanStart)
  407. svg.addEventListener("mouseup", handleScanEnd)
  408. svg.addEventListener("touchstart", handleTouchStart)
  409. svg.addEventListener("touchmove", handleTouchMove)
  410. svg.addEventListener("touchend", handleTouchEnd)
  411. svg.addEventListener("wheel", handleWheel, true)
  412. }
  413. function viewer(baseUrl, nodes) {
  414. 'use strict';
  415. // Elements
  416. const search = document.getElementById("searchbox")
  417. const graph0 = document.getElementById("graph0")
  418. const svg = (graph0 == null ? null : graph0.parentElement)
  419. const toptable = document.getElementById("toptable")
  420. let regexpActive = false
  421. let selected = new Map()
  422. let origFill = new Map()
  423. let searchAlarm = null
  424. let buttonsEnabled = true
  425. function handleDetails() {
  426. const detailsText = document.getElementById("detailtext")
  427. if (detailsText != null) detailsText.style.display = "block"
  428. }
  429. function handleCloseDetails() {
  430. const detailsText = document.getElementById("detailtext")
  431. if (detailsText != null) detailsText.style.display = "none"
  432. }
  433. function handleReset() { window.location.href = baseUrl }
  434. function handleTop() { navigate("/top", "f", false) }
  435. function handleGraph() { navigate("/", "f", false) }
  436. function handleList() { navigate("/weblist", "f", true) }
  437. function handleDisasm() { navigate("/disasm", "f", true) }
  438. function handlePeek() { navigate("/peek", "f", true) }
  439. function handleFocus() { navigate(baseUrl, "f", false) }
  440. function handleShow() { navigate(baseUrl, "s", false) }
  441. function handleIgnore() { navigate(baseUrl, "i", false) }
  442. function handleHide() { navigate(baseUrl, "h", false) }
  443. function handleKey(e) {
  444. if (e.keyCode != 13) return
  445. handleFocus()
  446. e.preventDefault()
  447. }
  448. function handleSearch() {
  449. // Delay expensive processing so a flurry of key strokes is handled once.
  450. if (searchAlarm != null) {
  451. clearTimeout(searchAlarm)
  452. }
  453. searchAlarm = setTimeout(selectMatching, 300)
  454. regexpActive = true
  455. updateButtons()
  456. }
  457. function selectMatching() {
  458. searchAlarm = null
  459. let re = null
  460. if (search.value != "") {
  461. try {
  462. re = new RegExp(search.value)
  463. } catch (e) {
  464. // TODO: Display error state in search box
  465. return
  466. }
  467. }
  468. function match(text) {
  469. return re != null && re.test(text)
  470. }
  471. // drop currently selected items that do not match re.
  472. selected.forEach(function(v, n) {
  473. if (!match(nodes[n])) {
  474. unselect(n, document.getElementById("node" + n))
  475. }
  476. })
  477. // add matching items that are not currently selected.
  478. for (let n = 0; n < nodes.length; n++) {
  479. if (!selected.has(n) && match(nodes[n])) {
  480. select(n, document.getElementById("node" + n))
  481. }
  482. }
  483. updateButtons()
  484. }
  485. function toggleSvgSelect(elem) {
  486. // Walk up to immediate child of graph0
  487. while (elem != null && elem.parentElement != graph0) {
  488. elem = elem.parentElement
  489. }
  490. if (!elem) return
  491. // Disable regexp mode.
  492. regexpActive = false
  493. const n = nodeId(elem)
  494. if (n < 0) return
  495. if (selected.has(n)) {
  496. unselect(n, elem)
  497. } else {
  498. select(n, elem)
  499. }
  500. updateButtons()
  501. }
  502. function unselect(n, elem) {
  503. if (elem == null) return
  504. selected.delete(n)
  505. setBackground(elem, false)
  506. }
  507. function select(n, elem) {
  508. if (elem == null) return
  509. selected.set(n, true)
  510. setBackground(elem, true)
  511. }
  512. function nodeId(elem) {
  513. const id = elem.id
  514. if (!id) return -1
  515. if (!id.startsWith("node")) return -1
  516. const n = parseInt(id.slice(4), 10)
  517. if (isNaN(n)) return -1
  518. if (n < 0 || n >= nodes.length) return -1
  519. return n
  520. }
  521. function setBackground(elem, set) {
  522. // Handle table row highlighting.
  523. if (elem.nodeName == "TR") {
  524. elem.classList.toggle("hilite", set)
  525. return
  526. }
  527. // Handle svg element highlighting.
  528. const p = findPolygon(elem)
  529. if (p != null) {
  530. if (set) {
  531. origFill.set(p, p.style.fill)
  532. p.style.fill = "#ccccff"
  533. } else if (origFill.has(p)) {
  534. p.style.fill = origFill.get(p)
  535. }
  536. }
  537. }
  538. function findPolygon(elem) {
  539. if (elem.localName == "polygon") return elem
  540. for (const c of elem.children) {
  541. const p = findPolygon(c)
  542. if (p != null) return p
  543. }
  544. return null
  545. }
  546. // convert a string to a regexp that matches that string.
  547. function quotemeta(str) {
  548. return str.replace(/([\\\.?+*\[\](){}|^$])/g, '\\$1')
  549. }
  550. // Navigate to specified path with current selection reflected
  551. // in the named parameter.
  552. function navigate(path, param, newWindow) {
  553. // The selection can be in one of two modes: regexp-based or
  554. // list-based. Construct regular expression depending on mode.
  555. let re = regexpActive ? search.value : ""
  556. if (!regexpActive) {
  557. selected.forEach(function(v, key) {
  558. if (re != "") re += "|"
  559. re += quotemeta(nodes[key])
  560. })
  561. }
  562. const url = new URL(window.location.href)
  563. url.pathname = path
  564. url.hash = ""
  565. if (re != "") {
  566. // For focus/show, forget old parameter. For others, add to re.
  567. const params = url.searchParams
  568. if (param != "f" && param != "s" && params.has(param)) {
  569. const old = params.get(param)
  570. if (old != "") {
  571. re += "|" + old
  572. }
  573. }
  574. params.set(param, re)
  575. }
  576. if (newWindow) {
  577. window.open(url.toString(), "_blank")
  578. } else {
  579. window.location.href = url.toString()
  580. }
  581. }
  582. function handleTopClick(e) {
  583. // Walk back until we find TR and then get the Name column (index 5)
  584. let elem = e.target
  585. while (elem != null && elem.nodeName != "TR") {
  586. elem = elem.parentElement
  587. }
  588. if (elem == null || elem.children.length < 6) return
  589. e.preventDefault()
  590. const tr = elem
  591. const td = elem.children[5]
  592. if (td.nodeName != "TD") return
  593. const name = td.innerText
  594. const index = nodes.indexOf(name)
  595. if (index < 0) return
  596. // Disable regexp mode.
  597. regexpActive = false
  598. if (selected.has(index)) {
  599. unselect(index, elem)
  600. } else {
  601. select(index, elem)
  602. }
  603. updateButtons()
  604. }
  605. function updateButtons() {
  606. const enable = (search.value != "" || selected.size != 0)
  607. if (buttonsEnabled == enable) return
  608. buttonsEnabled = enable
  609. for (const id of ["peek", "list", "disasm", "focus", "ignore", "hide", "show"]) {
  610. const btn = document.getElementById(id)
  611. if (btn != null) {
  612. btn.disabled = !enable
  613. }
  614. }
  615. }
  616. // Initialize button states
  617. updateButtons()
  618. // Setup event handlers
  619. if (svg != null) {
  620. initPanAndZoom(svg, toggleSvgSelect)
  621. }
  622. if (toptable != null) {
  623. toptable.addEventListener("mousedown", handleTopClick)
  624. toptable.addEventListener("touchstart", handleTopClick)
  625. }
  626. // Bind action to button with specified id.
  627. function addAction(id, action) {
  628. const btn = document.getElementById(id)
  629. if (btn != null) {
  630. btn.addEventListener("click", action)
  631. btn.addEventListener("touchstart", action)
  632. }
  633. }
  634. addAction("details", handleDetails)
  635. addAction("closedetails", handleCloseDetails)
  636. addAction("topbtn", handleTop)
  637. addAction("graphbtn", handleGraph)
  638. addAction("reset", handleReset)
  639. addAction("peek", handlePeek)
  640. addAction("list", handleList)
  641. addAction("disasm", handleDisasm)
  642. addAction("focus", handleFocus)
  643. addAction("ignore", handleIgnore)
  644. addAction("hide", handleHide)
  645. addAction("show", handleShow)
  646. search.addEventListener("input", handleSearch)
  647. search.addEventListener("keydown", handleKey)
  648. }
  649. </script>
  650. {{end}}
  651. {{define "top" -}}
  652. <!DOCTYPE html>
  653. <html>
  654. <head>
  655. <meta charset="utf-8">
  656. <title>{{.Title}}</title>
  657. {{template "css" .}}
  658. </head>
  659. <body>
  660. {{template "header" .}}
  661. <div id="topcontainer">
  662. <table id="toptable">
  663. <tr><th>Flat<th>Flat%<th>Sum%<th>Cum<th>Cum%<th>Name<th>Inlined?</tr>
  664. {{range $i,$e := .Top}}
  665. <tr id="node{{$i}}"><td>{{$e.Flat}}<td>{{$e.FlatPercent}}<td>{{$e.SumPercent}}<td>{{$e.Cum}}<td>{{$e.CumPercent}}<td>{{$e.Name}}<td>{{$e.InlineLabel}}</tr>
  666. {{end}}
  667. </table>
  668. </div>
  669. {{template "script" .}}
  670. <script>viewer({{.BaseURL}}, {{.Nodes}})</script>
  671. </body>
  672. </html>
  673. {{end}}
  674. `))