From d5a972ca374799991957852c66171dfb43747581 Mon Sep 17 00:00:00 2001 From: Saleh Mahameed Date: Wed, 23 Jun 2021 18:59:24 +0000 Subject: [PATCH] Merged PR 154398: [Embedded] Support Zoom Programmatically Added zoomLevel as an attribute of ISettings. Related Work Item: #527743 Related PRs: - JS SDK : https://powerbi.visualstudio.com/Embedded/_git/powerbi-javascript/pullrequest/154397 - PBIClients : https://powerbi.visualstudio.com/PowerBIClients/_git/PowerBIClients/pullrequest/154396 Related work items: #527743 --- src/models.ts | 6 ++++++ src/validators/core/typeValidator.ts | 26 ++++++++++++++++++++++++++ src/validators/core/validator.ts | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/models.ts b/src/models.ts index 064690c..8fd97f1 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1087,6 +1087,7 @@ export interface ISettings { visualRenderedEvents?: boolean; visualSettings?: IVisualSettings; localeSettings?: ILocaleSettings; + zoomLevel?: number; } export interface IReportBars { @@ -1769,3 +1770,8 @@ export function validateCustomTheme(input: any): IError[] { const errors: any[] = Validators.customThemeValidator.validate(input); return errors ? errors.map(normalizeError) : undefined; } + +export function validateZoomLevel(input: any): IError[] { + const errors: any[] = Validators.zoomLevelValidator.validate(input); + return errors ? errors.map(normalizeError) : undefined; +} \ No newline at end of file diff --git a/src/validators/core/typeValidator.ts b/src/validators/core/typeValidator.ts index 536bc4d..786c382 100644 --- a/src/validators/core/typeValidator.ts +++ b/src/validators/core/typeValidator.ts @@ -189,3 +189,29 @@ export class NumberArrayValidator extends ArrayValidator { return null; } } + +export class RangeValidator extends NumberValidator { + + constructor(private minValue: number, private maxValue: number) { + super(); + } + + public validate(input: any, path?: string, field?: string): IValidationError[] { + if (input == null) { + return null; + } + const errors = super.validate(input, path, field); + if (errors) { + return errors; + } + // input is a number, now check if it's in the given range + if(input > this.maxValue || input < this.minValue) { + return [{ + message: field + " must be a number between " + this.minValue + " and " + this.maxValue, + path: (path ? path + "." : "") + field, + keyword: "range" + }]; + } + return null; + } +} diff --git a/src/validators/core/validator.ts b/src/validators/core/validator.ts index cca8acb..1ce3f59 100644 --- a/src/validators/core/validator.ts +++ b/src/validators/core/validator.ts @@ -58,7 +58,7 @@ import { AnyOfValidator } from './anyOfValidator'; import { FieldForbiddenValidator } from './fieldForbiddenValidator'; import { FieldRequiredValidator } from './fieldRequiredValidator'; import { MapValidator } from './mapValidator'; -import { ArrayValidator, BooleanArrayValidator, BooleanValidator, EnumValidator, NumberArrayValidator, NumberValidator, StringArrayValidator, StringValidator } from './typeValidator'; +import { ArrayValidator, BooleanArrayValidator, BooleanValidator, EnumValidator, NumberArrayValidator, NumberValidator, RangeValidator, StringArrayValidator, StringValidator } from './typeValidator'; import { ParametersPanelValidator } from '../models/parameterPanelValidator'; export interface IValidationError { @@ -198,4 +198,5 @@ export const Validators = { visualSelectorValidator: new VisualSelectorValidator(), visualSettingsValidator: new VisualSettingsValidator(), visualTypeSelectorValidator: new VisualTypeSelectorValidator(), + zoomLevelValidator: new RangeValidator(0.25, 4), };