4 <meta charset="UTF-8" />
5 <title>Rendering Benchmark Viewer</title>
6 <script type="text/javascript" src="./elm.js"></script>
10 <div id="elm-home"></div>
11 <canvas id="canvas"></canvas>
14 <script type="text/javascript">
15 // Calculations for canvas
16 var PIXEL_RATIO = (function () {
17 var ctx = document.createElement("canvas").getContext("2d"),
18 dpr = window.devicePixelRatio || 1,
20 ctx.webkitBackingStorePixelRatio ||
21 ctx.mozBackingStorePixelRatio ||
22 ctx.msBackingStorePixelRatio ||
23 ctx.oBackingStorePixelRatio ||
24 ctx.backingStorePixelRatio ||
30 function createHiDPICanvas(w, h, id, ratio) {
34 let can = document.getElementById(id);
35 can.width = w * ratio;
36 can.height = h * ratio;
37 can.style.width = w + "px";
38 can.style.height = h + "px";
39 can.getContext("2d").setTransform(ratio, 0, 0, ratio, 0, 0);
42 // create a canvas for text measurements
43 let canvas = createHiDPICanvas(200, 100, "canvas");
45 var app = Elm.WeirdCentering.init({
46 node: document.getElementById("elm-home"),
49 var test_results = "waiting..";
51 app.ports.report.subscribe(function (results) {
52 test_results = results;
55 app.ports.analyze.subscribe(function (ids) {
57 var idsLength = ids.length;
59 for (var i = 0; i < idsLength; i++) {
61 var element = document.getElementById(id);
62 if (element == null) {
63 console.log("id " + id + " not found");
65 var style = getStyle(element);
66 var bbox = getBoundingBox(element);
67 var metrics = getTextMetrics(element);
69 var visible = isVisible(id, bbox);
80 app.ports.styles.send(results);
83 function isVisible(id, bbox) {
84 var current = document.getElementById(id);
86 if (current == document.elementFromPoint(bbox["left"], bbox["top"])) {
90 current == document.elementFromPoint(bbox["left"], bbox["bottom"] - 1)
95 current == document.elementFromPoint(bbox["right"] - 1, bbox["top"])
101 document.elementFromPoint(bbox["right"] - 1, bbox["bottom"] - 1)
113 function getStyle(element) {
115 var style = window.getComputedStyle(element);
116 for (var i = style.length; i--; ) {
117 var name = style.item(i);
118 var value = style.getPropertyValue(name);
119 props.push([name, value]);
124 function getBoundingBox(element) {
125 var bbox = element.getBoundingClientRect();
126 var style = window.getComputedStyle(element, null);
129 top: parseFloat(style.getPropertyValue("padding-top")),
130 bottom: parseFloat(style.getPropertyValue("padding-bottom")),
131 left: parseFloat(style.getPropertyValue("padding-left")),
132 right: parseFloat(style.getPropertyValue("padding-right")),
145 function getTextMetrics(element) {
146 // Given our element, we want to return the text metrics on the text within.
147 // If it is an element we want to measure:
148 // we want to get the font family
149 // and the font size.
150 // We're going to presume that the font is loaded.
151 let childrenTextMetrics = [];
152 for (i = 0; i < element.children.length; i++) {
153 if (element.children[i].classList.contains("t")) {
154 let style = window.getComputedStyle(element, null);
155 let fontSize = style.getPropertyValue("font-size");
156 let fontFamily = style.getPropertyValue("font-family");
157 let ctx = canvas.getContext("2d");
159 ctx.font = fontSize + " " + fontFamily; //"16px Roboto";
160 let text = ctx.measureText(element.children[i].innerText);
162 childrenTextMetrics.push({
163 actualBoundingBoxAscent: text.actualBoundingBoxAscent,
164 actualBoundingBoxDescent: text.actualBoundingBoxDescent,
165 actualBoundingBoxLeft: text.actualBoundingBoxLeft,
166 actualBoundingBoxRight: text.actualBoundingBoxRight,
171 return childrenTextMetrics;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list