Skip to content

Commit

Permalink
Add formatting setting to manually resize cell height and width
Browse files Browse the repository at this point in the history
  • Loading branch information
adiletelf committed Mar 11, 2024
1 parent ea4a626 commit 32d1c02
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 48 deletions.
15 changes: 15 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,21 @@
"type": {
"numeric": true
}
},
"enableManualSizing": {
"type": {
"bool": true
}
},
"width": {
"type": {
"numeric": true
}
},
"height": {
"type": {
"numeric": true
}
}
}
},
Expand Down
62 changes: 15 additions & 47 deletions src/timeLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import {CalendarFactory} from "./calendars/calendarFactory";
import {
CalendarSettingsCard,
CellsSettingsCard,
LabelsSettingsCard,
RangeHeaderSettingsCard,
TimeLineSettingsModel,
} from "./timeLineSettingsModel";
Expand Down Expand Up @@ -209,7 +208,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
.length;

Timeline.setMeasures(
settings.labels,
settings,
timelineData.currentGranularity.getType(),
countFullCells,
viewport,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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>(Settings.getDefault());
//
// const instancesEnumerator: powerbiVisualsApi.VisualObjectInstanceEnumeration = Settings.enumerateObjectInstances(
// settings,
// options,
// );
//
// const instances = (<powerbiVisualsApi.VisualObjectInstanceEnumerationObject>instancesEnumerator).instances
// ? (<powerbiVisualsApi.VisualObjectInstanceEnumerationObject>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;
Expand Down
40 changes: 39 additions & 1 deletion src/timeLineSettingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions stringResources/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 32d1c02

Please sign in to comment.