Skip to content

Commit

Permalink
more typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Oct 20, 2020
1 parent 2e0a624 commit ca79e98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions x-pack/plugins/reporting/server/lib/layouts/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ContextPageSize } from 'pdfmake/interfaces';
import { ContextPageSize, PredefinedPageSize } from 'pdfmake/interfaces';
import { PageSizeParams, PdfImageSize, Size } from './';

export interface ViewZoomWidthHeight {
Expand All @@ -25,7 +25,9 @@ export abstract class Layout {

public abstract getPdfPageOrientation(): 'portrait' | 'landscape' | undefined;

public abstract getPdfPageSize(pageSizeParams: PageSizeParams): ContextPageSize;
public abstract getPdfPageSize(
pageSizeParams: PageSizeParams
): ContextPageSize | PredefinedPageSize;

public abstract getViewport(itemsCount: number): ViewZoomWidthHeight | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/

import path from 'path';
import { ContextPageSize, PageOrientation } from 'pdfmake/interfaces';
import {
getDefaultLayoutSelectors,
Layout,
LayoutInstance,
LayoutSelectorDictionary,
LayoutTypes,
PageSizeParams,
Size,
LayoutInstance,
} from './';

// We use a zoom of two to bump up the resolution of the screenshot a bit.
Expand All @@ -25,11 +26,13 @@ export class PreserveLayout extends Layout implements LayoutInstance {
public readonly width: number;
private readonly scaledHeight: number;
private readonly scaledWidth: number;
private readonly orientation: PageOrientation;

constructor(size: Size, layoutSelectors?: LayoutSelectorDictionary) {
super(LayoutTypes.PRESERVE_LAYOUT);
this.height = size.height;
this.width = size.width;
this.orientation = size.height > size.width ? 'portrait' : 'landscape';
this.scaledHeight = size.height * ZOOM;
this.scaledWidth = size.width * ZOOM;

Expand Down Expand Up @@ -72,7 +75,7 @@ export class PreserveLayout extends Layout implements LayoutInstance {
return undefined;
}

public getPdfPageSize(pageSizeParams: PageSizeParams) {
public getPdfPageSize(pageSizeParams: PageSizeParams): ContextPageSize {
return {
height:
this.height +
Expand All @@ -82,6 +85,7 @@ export class PreserveLayout extends Layout implements LayoutInstance {
pageSizeParams.headingHeight +
pageSizeParams.subheadingHeight,
width: this.width + pageSizeParams.pageMarginWidth * 2 + pageSizeParams.tableBorderWidth * 2,
orientation: this.orientation,
};
}
}
5 changes: 3 additions & 2 deletions x-pack/plugins/reporting/server/lib/layouts/print_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import path from 'path';
import { PageOrientation, PredefinedPageSize } from 'pdfmake/interfaces';
import { EvaluateFn, SerializableOrJSHandle } from 'puppeteer';
import { LevelLogger } from '../';
import { HeadlessChromiumDriver } from '../../browsers';
Expand Down Expand Up @@ -90,11 +91,11 @@ export class PrintLayout extends Layout implements LayoutInstance {
};
}

public getPdfPageOrientation() {
public getPdfPageOrientation(): PageOrientation {
return 'portrait';
}

public getPdfPageSize() {
public getPdfPageSize(): PredefinedPageSize {
return 'A4';
}
}

0 comments on commit ca79e98

Please sign in to comment.