Skip to content

Commit

Permalink
#128 remove fromPerfCascadeFormat and add onParsed callback
Browse files Browse the repository at this point in the history
- reduces API surface, but it can still be intercepted via the CB, but it does not require the internal waterfall callbacks.
  • Loading branch information
Michael Mrowetz committed Mar 14, 2017
1 parent e70a236 commit 4b4aa44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createWaterfallSvg } from "./waterfall/svg-chart";
const defaultOptions: Readonly<ChartOptions> = {
leftColumnWith: 25,
legendHolder: undefined,
onParsed: undefined,
pageSelector: undefined,
rowHeight: 23,
selectedPage: 0,
Expand All @@ -20,7 +21,7 @@ const defaultOptions: Readonly<ChartOptions> = {
};

function PerfCascade(waterfallDocsData: WaterfallDocs, chartOptions: Partial<ChartOptions> = {}): SVGSVGElement {
const options: ChartOptions = validateOptions({...defaultOptions, ...chartOptions});
const options: ChartOptions = validateOptions({ ...defaultOptions, ...chartOptions });

// setup paging helper
let paging = new Paging(waterfallDocsData, options.selectedPage);
Expand Down Expand Up @@ -53,24 +54,14 @@ function PerfCascade(waterfallDocsData: WaterfallDocs, chartOptions: Partial<Cha
* @returns {SVGSVGElement} - Chart SVG Element
*/
function fromHar(harData: Har, options: Partial<ChartOptions> = {}): SVGSVGElement {
return PerfCascade(HarTransformer.transformDoc(harData), options);
}

/**
* Create new PerfCascade from PerfCascade's internal WaterfallData format
* @param {WaterfallDocs} waterfallDocsData Object containing data to render
* @param {ChartOptions} options - PerfCascade options object
* @returns {SVGSVGElement} - Chart SVG Element
*/
function fromPerfCascadeFormat(waterfallDocsData: WaterfallDocs, options: Partial<ChartOptions> = {}): SVGSVGElement {
return PerfCascade(waterfallDocsData, options);
const data = HarTransformer.transformDoc(harData);
if (typeof options.onParsed === "function") {
options.onParsed(data);
}
return PerfCascade(data, options);
}

let transformHarToPerfCascade = HarTransformer.transformDoc;

// global members that get exported via UMD
export { fromHar };
export { fromPerfCascadeFormat };
export { transformHarToPerfCascade };
export { makeLegend };
export { ChartOptions };
4 changes: 4 additions & 0 deletions src/ts/typing/options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { WaterfallDocs } from "./waterfall";

export interface ChartOptions {
/** Height of every request bar block plus spacer pixel (in px) */
rowHeight: number;
Expand All @@ -15,4 +17,6 @@ export interface ChartOptions {
selectedPage: number;
/** Element that holds the Legend (if not set no Legend is sendered) */
legendHolder: HTMLElement;
/** Callback called when the HAR doc has been parsed into PerfCascases */
onParsed: (data: WaterfallDocs) => void;
}

0 comments on commit 4b4aa44

Please sign in to comment.