From 32d1c0255289e1c86732b1490985fa03cfb35833 Mon Sep 17 00:00:00 2001 From: Adilet Soronov <74559101+adiletelf@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:48:54 +0600 Subject: [PATCH] Add formatting setting to manually resize cell height and width --- capabilities.json | 15 ++++++ src/timeLine.ts | 62 ++++++------------------- src/timeLineSettingsModel.ts | 40 +++++++++++++++- stringResources/en-US/resources.resjson | 3 ++ 4 files changed, 72 insertions(+), 48 deletions(-) diff --git a/capabilities.json b/capabilities.json index 84ff5e8..4e4fd97 100644 --- a/capabilities.json +++ b/capabilities.json @@ -296,6 +296,21 @@ "type": { "numeric": true } + }, + "enableManualSizing": { + "type": { + "bool": true + } + }, + "width": { + "type": { + "numeric": true + } + }, + "height": { + "type": { + "numeric": true + } } } }, diff --git a/src/timeLine.ts b/src/timeLine.ts index e54aaa3..c1c1e7d 100644 --- a/src/timeLine.ts +++ b/src/timeLine.ts @@ -73,7 +73,6 @@ import {CalendarFactory} from "./calendars/calendarFactory"; import { CalendarSettingsCard, CellsSettingsCard, - LabelsSettingsCard, RangeHeaderSettingsCard, TimeLineSettingsModel, } from "./timeLineSettingsModel"; @@ -209,7 +208,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual .length; Timeline.setMeasures( - settings.labels, + settings, timelineData.currentGranularity.getType(), countFullCells, viewport, @@ -442,7 +441,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual } private static setMeasures( - labelsSettings: LabelsSettingsCard, + settings: TimeLineSettingsModel, granularityType: GranularityType, datePeriodsCount: number, viewport: powerbiVisualsApi.IViewport, @@ -452,10 +451,10 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual timelineProperties.cellsYPosition = timelineProperties.textYPosition; - const labelSize: number = pixelConverter.fromPointToPixel(labelsSettings.textSize.value); + const labelSize: number = pixelConverter.fromPointToPixel(settings.labels.textSize.value); - if (labelsSettings.show.value) { - const granularityOffset: number = labelsSettings.displayAll.value ? granularityType + 1 : 1; + if (settings.labels.show.value) { + const granularityOffset: number = settings.labels.displayAll.value ? granularityType + 1 : 1; timelineProperties.cellsYPosition += labelSize * Timeline.LabelSizeFactor @@ -479,8 +478,16 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual timelineMargins.MinCellWidth, (viewport.width - height - Timeline.ViewportWidthAdjustment) / (datePeriodsCount)); - timelineProperties.cellHeight = height; - timelineProperties.cellWidth = width; + if (settings.cells.enableManualSizing.value) { + timelineProperties.cellHeight = settings.cells.height.value; + timelineProperties.cellWidth = settings.cells.width.value; + } else { + timelineProperties.cellHeight = height; + timelineProperties.cellWidth = width; + + settings.cells.height.value = Math.round(height); + settings.cells.width.value = Math.round(width); + } } private static applyJsonFilters( @@ -1031,45 +1038,6 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual return this.formattingSettingsService.buildFormattingModel(this.visualSettings); } - /** - * This function returns the values to be displayed in the property pane for each object. - * Usually it is a bind pass of what the property pane gave you, but sometimes you may want to do - * validation and return other values/defaults. - */ - // public enumerateObjectInstances(options: powerbiVisualsApi.EnumerateVisualObjectInstancesOptions): powerbiVisualsApi.VisualObjectInstanceEnumeration { - // if (options.objectName === "general") { - // return []; - // } - // - // const settings: Settings = (Settings.getDefault()); - // - // const instancesEnumerator: powerbiVisualsApi.VisualObjectInstanceEnumeration = Settings.enumerateObjectInstances( - // settings, - // options, - // ); - // - // const instances = (instancesEnumerator).instances - // ? (instancesEnumerator).instances - // : instancesEnumerator; - // - // if (options.objectName === "weekDay" - // && !settings.weekDay.daySelection - // && instances - // && instances[0] - // && instances[0].properties - // ) { - // delete instances[0].properties.day; - // } - // - // // This options have no sense if ISO standard was picked - // if ((options.objectName === "weekDay" || options.objectName === "calendar") - // && settings.weeksDetermintaionStandards.weekStandard !== WeekStandards.NotSet) { - // return null; - // } - // - // return instances; - // } - public selectPeriod(granularityType: GranularityType): void { if (this.timelineData.currentGranularity.getType() === granularityType) { return; diff --git a/src/timeLineSettingsModel.ts b/src/timeLineSettingsModel.ts index 494e8e0..e9e6e25 100644 --- a/src/timeLineSettingsModel.ts +++ b/src/timeLineSettingsModel.ts @@ -6,6 +6,7 @@ import {Month} from "./calendars/month"; import Card = formattingSettings.SimpleCard; import CompositeCard = formattingSettings.CompositeCard; import Model = formattingSettings.Model; +import Group = formattingSettings.Group; import IEnumMember = powerbi.IEnumMember; import ValidatorType = powerbi.visuals.ValidatorType; import {Weekday} from "./calendars/weekday"; @@ -260,10 +261,47 @@ export class CellsSettingsCard extends Card { } }); + enableManualSizing = new formattingSettings.ToggleSwitch({ + name: "enableManualSizing", + displayName: "Enable manual sizing", + displayNameKey: "Visual_Cell_EnableManualSizing", + value: false, + }); + + width = new formattingSettings.NumUpDown({ + name: "width", + displayName: "Cell width", + displayNameKey: "Visual_Cell_Width", + value: 40, + options: { + minValue: { value: 10, type: powerbi.visuals.ValidatorType.Min }, + }, + }); + + height = new formattingSettings.NumUpDown({ + name: "height", + displayName: "Cell height", + displayNameKey: "Visual_Cell_Height", + value: 60, + options: { + minValue: { value: 10, type: powerbi.visuals.ValidatorType.Min }, + }, + }); + name: string = "cells"; displayName: string = "Cells"; displayNameKey: string = "Visual_Cells"; - slices = [this.fillSelected, this.strokeSelected, this.fillUnselected, this.strokeUnselected, this.strokeWidth, this.gapWidth]; + slices = [ + this.fillSelected, + this.strokeSelected, + this.fillUnselected, + this.strokeUnselected, + this.strokeWidth, + this.gapWidth, + this.enableManualSizing, + this.width, + this.height, + ]; } export class GranularitySettingsCard extends Card { diff --git a/stringResources/en-US/resources.resjson b/stringResources/en-US/resources.resjson index 55be640..ebc2d3a 100644 --- a/stringResources/en-US/resources.resjson +++ b/stringResources/en-US/resources.resjson @@ -37,6 +37,9 @@ "Visual_Cell_UnselectedColor": "Unselected cell color", "Visual_Cell_SelectedStrokeColor": "Selected cell stroke color", "Visual_Cell_UnselectedStrokeColor": "Unselected cell stroke color", + "Visual_Cell_EnableManualSizing": "Enable manual sizing", + "Visual_Cell_Width": "Cell width", + "Visual_Cell_Height": "Cell height", "Visual_Cell_StrokeWidth": "Stroke width", "Visual_Cell_GapWidth": "Gap width", "Visual_Granularity": "Granularity",