Skip to content

Commit cd41a58

Browse files
author
Michael Mrowetz
committed
#198 push icon inline rendering
1 parent b30d48f commit cd41a58

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

src/ts/helpers/icons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as svgLib from "./svg";
33
* SVG Icons
44
*/
55

6-
const wrapSvgIcon = (x: number, y: number, title: string,
6+
const wrapSvgIcon = (x: string | number, y: number, title: string,
77
className: string, scale: number, svgEl: SVGElement): SVGElement => {
88
const holder = svgLib.newSvg("", {
99
x,
@@ -239,7 +239,7 @@ export function audio(x: number, y: number, title: string, scale: number = 1): S
239239
}
240240

241241
let pushIconLazy: SVGPathElement;
242-
export function push(x: number, y: number, title: string, scale: number = 1): SVGElement {
242+
export function push(x: number | string, y: number, title: string, scale: number = 1): SVGElement {
243243
if (pushIconLazy === undefined) {
244244
const d = `M14.668 9q0 .416-.285.7L9.37 14.716Q9.067 15 8.667 15q-.393 0-.694-.285l-.577
245245
-.578q-.293-.292-.293-.7 0-.41.293-.7l2.256-2.258H4.23q-.4 0-.65-.29t-.25-.698v-.986q0-.408.25

src/ts/waterfall/row/svg-row-subcomponents.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
*/
44

55
import { getParentByClassName } from "../../helpers/dom";
6+
import { push } from "../../helpers/icons";
67
import * as misc from "../../helpers/misc";
78
import * as svg from "../../helpers/svg";
89
import { timingTypeToCssClass } from "../../transformers/styling-converters";
910
import { RectData } from "../../typing/rect-data";
10-
import { WaterfallEntryTiming } from "../../typing/waterfall";
11+
import { WaterfallEntry, WaterfallEntryTiming } from "../../typing/waterfall";
1112
import {
1213
onHoverInShowTooltip,
1314
onHoverOutShowTooltip,
@@ -105,14 +106,45 @@ function createTimingLabel(rectData: RectData, timeTotal: number, firstX: number
105106
return txtEl;
106107
}
107108

109+
function createPushIndicator(rectData: RectData): SVGElement {
110+
const scale = 0.6;
111+
const iconNaturalSize = 12; // default svg size (12px)
112+
const y = rectData.y + ((rectData.height - 4 - (iconNaturalSize * scale)) / 2);
113+
const percStart = (rectData.x + rectData.width) / rectData.unit;
114+
const iconEl = push(`${misc.roundNumber(percStart)}%`, y, "Http2 Push", scale);
115+
116+
const el = svg.newG(`push-inline-wrap`, {
117+
transform: `translate(-${rectData.height / 2})`,
118+
}, {
119+
fillOpacity: "0.5",
120+
});
121+
el.appendChild(iconEl);
122+
123+
return el;
124+
}
125+
126+
// function createPushIndicator(rectData: RectData): SVGElement {
127+
// const y = rectData.y + rectData.height / 1.5;
128+
// const x = `${misc.roundNumber(rectData.x / rectData.unit)}%`;
129+
// return svg.newTextEl("→", {
130+
// transform: `translate(-5)`,
131+
// x,
132+
// y,
133+
// }, {
134+
// "fillOpacity": "0.5",
135+
// "text-anchor": "end",
136+
// });
137+
// }
138+
108139
/**
109140
* Render the block and timings for a request
110141
* @param {RectData} rectData Basic dependencys and globals
111-
* @param {WaterfallEntryTiming[]} segments Request and Timing Data
112-
* @param {number} timeTotal - total time of the request
113-
* @return {SVGElement} Renerated SVG (rect or g element)
142+
* @param {WaterfallEntry} entry Request Details, e.g. Request and Timing Data
143+
* @return {SVGElement} Renerated SVG (rect or g element)
114144
*/
115-
export function createRect(rectData: RectData, segments: WaterfallEntryTiming[], timeTotal: number): SVGElement {
145+
export function createRect(rectData: RectData, entry: WaterfallEntry): SVGElement {
146+
// entry.responseDetails.indicators;
147+
const segments = entry.segments;
116148
const rect = makeBlock(rectData, `time-block ${rectData.cssClass}`);
117149
const rectHolder = svg.newG("rect-holder");
118150
let firstX = rectData.x;
@@ -129,7 +161,10 @@ export function createRect(rectData: RectData, segments: WaterfallEntryTiming[],
129161
}
130162
});
131163

132-
rectHolder.appendChild(createTimingLabel(rectData, timeTotal, firstX));
164+
if (misc.find(entry.responseDetails.indicators, (indicator) => indicator.id === "push")) {
165+
rectHolder.appendChild(createPushIndicator(rectData));
166+
}
167+
rectHolder.appendChild(createTimingLabel(rectData, entry.total, firstX));
133168
}
134169

135170
return rectHolder;

src/ts/waterfall/row/svg-row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function createRow(context: Context, index: number,
4747
x: `${leftColumnWidth}%`,
4848
});
4949

50-
const rect = rowSubComponents.createRect(rectData, entry.segments, entry.total);
50+
const rect = rowSubComponents.createRect(rectData, entry);
5151
const rowName = rowSubComponents.createNameRowBg(y, rowHeight);
5252
const rowBar = rowSubComponents.createRowBg(y, rowHeight);
5353
const bgStripe = rowSubComponents.createBgStripe(y, rowHeight, (index % 2 === 0));

0 commit comments

Comments
 (0)