Skip to content

Commit 4b4aa44

Browse files
author
Michael Mrowetz
committed
#128 remove fromPerfCascadeFormat and add onParsed callback
- reduces API surface, but it can still be intercepted via the CB, but it does not require the internal waterfall callbacks.
1 parent e70a236 commit 4b4aa44

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

Diff for: src/ts/main.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createWaterfallSvg } from "./waterfall/svg-chart";
1111
const defaultOptions: Readonly<ChartOptions> = {
1212
leftColumnWith: 25,
1313
legendHolder: undefined,
14+
onParsed: undefined,
1415
pageSelector: undefined,
1516
rowHeight: 23,
1617
selectedPage: 0,
@@ -20,7 +21,7 @@ const defaultOptions: Readonly<ChartOptions> = {
2021
};
2122

2223
function PerfCascade(waterfallDocsData: WaterfallDocs, chartOptions: Partial<ChartOptions> = {}): SVGSVGElement {
23-
const options: ChartOptions = validateOptions({...defaultOptions, ...chartOptions});
24+
const options: ChartOptions = validateOptions({ ...defaultOptions, ...chartOptions });
2425

2526
// setup paging helper
2627
let paging = new Paging(waterfallDocsData, options.selectedPage);
@@ -53,24 +54,14 @@ function PerfCascade(waterfallDocsData: WaterfallDocs, chartOptions: Partial<Cha
5354
* @returns {SVGSVGElement} - Chart SVG Element
5455
*/
5556
function fromHar(harData: Har, options: Partial<ChartOptions> = {}): SVGSVGElement {
56-
return PerfCascade(HarTransformer.transformDoc(harData), options);
57-
}
58-
59-
/**
60-
* Create new PerfCascade from PerfCascade's internal WaterfallData format
61-
* @param {WaterfallDocs} waterfallDocsData Object containing data to render
62-
* @param {ChartOptions} options - PerfCascade options object
63-
* @returns {SVGSVGElement} - Chart SVG Element
64-
*/
65-
function fromPerfCascadeFormat(waterfallDocsData: WaterfallDocs, options: Partial<ChartOptions> = {}): SVGSVGElement {
66-
return PerfCascade(waterfallDocsData, options);
57+
const data = HarTransformer.transformDoc(harData);
58+
if (typeof options.onParsed === "function") {
59+
options.onParsed(data);
60+
}
61+
return PerfCascade(data, options);
6762
}
6863

69-
let transformHarToPerfCascade = HarTransformer.transformDoc;
70-
7164
// global members that get exported via UMD
7265
export { fromHar };
73-
export { fromPerfCascadeFormat };
74-
export { transformHarToPerfCascade };
7566
export { makeLegend };
7667
export { ChartOptions };

Diff for: src/ts/typing/options.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { WaterfallDocs } from "./waterfall";
2+
13
export interface ChartOptions {
24
/** Height of every request bar block plus spacer pixel (in px) */
35
rowHeight: number;
@@ -15,4 +17,6 @@ export interface ChartOptions {
1517
selectedPage: number;
1618
/** Element that holds the Legend (if not set no Legend is sendered) */
1719
legendHolder: HTMLElement;
20+
/** Callback called when the HAR doc has been parsed into PerfCascases */
21+
onParsed: (data: WaterfallDocs) => void;
1822
}

0 commit comments

Comments
 (0)