Skip to content

Commit

Permalink
Set fixedLengthMs from outside of PerfCascade (#211)
Browse files Browse the repository at this point in the history
* Set row max time from outside of PerfCascade

The use case for this is when you wanna put to waterfall charts
on top on each other and you wanna make sure they have the
same time line, so it is easier to compare them.
  • Loading branch information
soulgalore authored Aug 26, 2017
1 parent 966a12f commit 4401f26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/ts/transformers/har.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "har-format";
import { roundNumber } from "../helpers/misc";
import { escapeHtml, toInt } from "../helpers/parse";
import { HarTransformerOptions } from "../typing/options";
import { ChartOptions, HarTransformerOptions } from "../typing/options";
import {
Mark,
TimingType,
Expand Down Expand Up @@ -89,12 +89,12 @@ const getPages = (data: Log) => {
* Transforms a HAR object into the format needed to render the PerfCascade
* @param {Har} harData - HAR document
* @param {number=0} pageIndex - page to parse (for multi-page HAR)
* @param {HarTransformerOptions} options - HAR-parser-specific options
* @param {ChartOptions} options - HAR-parser-specific options
* @returns WaterfallData
*/
export function transformPage(harData: Har | Log,
pageIndex: number = 0,
options: HarTransformerOptions): WaterfallData {
options: ChartOptions): WaterfallData {
// make sure it's the *.log base node
const data = (harData["log"] !== undefined ? harData["log"] : harData) as Log;

Expand Down Expand Up @@ -130,6 +130,11 @@ export function transformPage(harData: Har | Log,
}
});

// if we configured fixed length from the outside, use that!
if (options.fixedLengthMs) {
doneTime = options.fixedLengthMs;
}

// Add 100ms margin to make room for labels
doneTime += 100;

Expand All @@ -146,9 +151,9 @@ export function transformPage(harData: Har | Log,
* Extract all `Mark`s based on `PageTiming` and `UserTiming`
* @param {PageTiming} pageTimings - HARs `PageTiming` object
* @param {Page} currPage - active page
* @param {HarTransformerOptions} options - HAR-parser-specific options
* @param {ChartOptions} options - HAR options
*/
const getMarks = (pageTimings: PageTiming, currPage: Page, options: HarTransformerOptions) => {
const getMarks = (pageTimings: PageTiming, currPage: Page, options: ChartOptions) => {
const sortFn = (a: Mark, b: Mark) => a.startTime - b.startTime;
const marks = Object.keys(pageTimings)
.filter((k: keyof PageTiming) => (typeof pageTimings[k] === "number" && pageTimings[k] >= 0))
Expand All @@ -169,9 +174,9 @@ const getMarks = (pageTimings: PageTiming, currPage: Page, options: HarTransform
/**
* Extract all `Mark`s based on `UserTiming`
* @param {Page} currPage - active page
* @param {HarTransformerOptions} options - HAR-parser-specific options
* @param {ChartOptions} options - HAR options
*/
const getUserTimimngs = (currPage: Page, options: HarTransformerOptions) => {
const getUserTimimngs = (currPage: Page, options: ChartOptions) => {
const baseFilter = options.showUserTimingEndMarker ?
(k: string) => k.indexOf("_userTime.") === 0 :
(k: string) => k.indexOf("_userTime.") === 0 && k.indexOf("_userTime.endTimer-") !== 0;
Expand Down
2 changes: 2 additions & 0 deletions src/ts/typing/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ChartRenderOption {
legendHolder: HTMLElement;
/** Callback called when the HAR doc has been parsed into PerfCascases */
onParsed: (data: WaterfallDocs) => void;
/** Set a row length time in ms (if not set the time is calculated from the HAR) */
fixedLengthMs: number;
}

export interface HarTransformerOptions {
Expand Down

0 comments on commit 4401f26

Please sign in to comment.