Skip to content

Commit

Permalink
Rename ambiguous topLevelSlice to show field. Revert MinCellWidth to …
Browse files Browse the repository at this point in the history
…fix a breaking change.
  • Loading branch information
adiletelf committed Jan 11, 2024
1 parent 4c8b5cc commit d62add3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add missing localization keys
* Add cursor color settings
* Add stroke color settings
* Update build.yml to use node 18, 20

## 2.3.0
* A new option group "Weeks Determination Standards" containing a list of two items where the first one enables US weeks numbering (default) and the second one enables ISO 8601 weeks numbering
Expand Down
31 changes: 18 additions & 13 deletions src/timeLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
previousCalendar: Calendar,
): Calendar {

if (this.isDataViewValid(dataView)) {
if (Timeline.isDataViewValid(dataView)) {
return null;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
LegendHeightRange: 20,
MaxCellHeight: 60,
MinCellHeight: 20,
MinCellWidth: 30,
MinCellWidth: 40,
PeriodSlicerRectHeight: 23,
PeriodSlicerRectWidth: 15,
RightMargin: 15,
Expand Down Expand Up @@ -441,7 +441,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual

const labelSize: number = pixelConverter.fromPointToPixel(timelineSettings.labels.textSize.value);

if (timelineSettings.labels.topLevelSlice.value) {
if (timelineSettings.labels.show.value) {
const granularityOffset: number = timelineSettings.labels.displayAll.value ? granularityType + 1 : 1;

timelineProperties.cellsYPosition += labelSize
Expand Down Expand Up @@ -472,6 +472,11 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual

timelineProperties.cellHeight = height;
timelineProperties.cellWidth = width;

// TODO: persist the values in dataview.metadata.objects
// Set the height and width so when the user enables manual resizing, the height and width are not reset
// timelineSettings.cells.height.value = Math.round(height);
// timelineSettings.cells.width.value = Math.round(width);
}
}

Expand Down Expand Up @@ -800,7 +805,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
.attr("fill", (dataPoint: ITimelineDataPoint, index: number) => {
const isSelected: boolean = Utils.IS_GRANULE_SELECTED(dataPoint, this.timelineData);

if (visSettings.scrollAutoAdjustment.topLevelSlice.value && isSelected && !singleCaseDone) {
if (visSettings.scrollAutoAdjustment.show.value && isSelected && !singleCaseDone) {
const selectedGranulaPos: number = (<any>(cellSelection.nodes()[index])).x.baseVal.value;
this.selectedGranulaPos = selectedGranulaPos;
singleCaseDone = true;
Expand Down Expand Up @@ -918,7 +923,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual

d3SelectAll("g." + Timeline.TimelineSelectors.RangeTextArea.className).remove();

if (rangeHeaderSettings.topLevelSlice.value && maxWidth > 0) {
if (rangeHeaderSettings.show.value && maxWidth > 0) {
this.rangeTextSelection = this.headerSelection
.append("g")
.classed(Timeline.TimelineSelectors.RangeTextArea.className, true)
Expand Down Expand Up @@ -1157,10 +1162,10 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual

private adjustHeightOfElements(viewportWidth: number): void {
this.timelineProperties.legendHeight = 0;
if (this.formattingSettings.rangeHeader.topLevelSlice.value) {
if (this.formattingSettings.rangeHeader.show.value) {
this.timelineProperties.legendHeight = Timeline.TimelineMargins.LegendHeightRange;
}
if (this.formattingSettings.granularity.topLevelSlice.value) {
if (this.formattingSettings.granularity.show.value) {
this.timelineProperties.legendHeight = Timeline.TimelineMargins.LegendHeight;
}

Expand All @@ -1175,7 +1180,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
private renderGranularityFrame(granularity: GranularityType): void {
d3SelectAll("g." + Timeline.TimelineSelectors.TimelineSlicer.className).remove();

if (this.formattingSettings.granularity.topLevelSlice.value) {
if (this.formattingSettings.granularity.show.value) {
const startXpoint: number = this.timelineProperties.startXpoint;
const elementWidth: number = this.timelineProperties.elementWidth;

Expand Down Expand Up @@ -1303,14 +1308,14 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
}
}

private updateCalendar(timelineFormat: TimeLineSettingsModel): void {
private updateCalendar(timeLineSettings: TimeLineSettingsModel): void {
this.calendar = Timeline.CONVERTER(
this.timelineData,
this.timelineProperties,
this.timelineGranularityData,
this.options.dataViews[0],
this.initialized,
timelineFormat,
timeLineSettings,
this.options.viewport,
this.calendar,
);
Expand Down Expand Up @@ -1417,7 +1422,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
const yDiff: number = Timeline.DefaultYDiff;
let yPos: number = 0;

if (timelineSettings.labels.topLevelSlice.value) {
if (timelineSettings.labels.show.value) {
if (timelineSettings.labels.displayAll.value || granularityType === GranularityType.year) {
this.renderLabels(
extendedLabels.yearLabels,
Expand Down Expand Up @@ -1480,7 +1485,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
}

private calculateYOffset(index: number): number {
if (!this.formattingSettings.labels.topLevelSlice.value) {
if (!this.formattingSettings.labels.show.value) {
return this.timelineProperties.textYPosition;
}

Expand All @@ -1497,7 +1502,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual
const labelTextSelection: D3Selection<any, ITimelineLabel, any, any> = labelsElement
.selectAll(Timeline.TimelineSelectors.TextLabel.selectorName);

if (!this.formattingSettings.labels.topLevelSlice.value) {
if (!this.formattingSettings.labels.show.value) {
labelTextSelection.remove();
return;
}
Expand Down
46 changes: 27 additions & 19 deletions src/timeLineSettingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class WeekDaySettingsCard extends Card {
day = new formattingSettings.ItemDropdown({
name: "day",
displayName: "Day",
displayNameKey: "Visual_day",
displayNameKey: "Visual_Day",
items: dayOptions,
value: dayOptions[0],
});
Expand All @@ -171,13 +171,15 @@ export class WeekDaySettingsCard extends Card {
}

export class RangeHeaderSettingsCard extends Card {
topLevelSlice: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
show: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
name: "show",
displayName: "Show",
displayNameKey: "Visual_Show",
value: true,
});

topLevelSlice = this.show;

fontColor = new formattingSettings.ColorPicker({
name: "fontColor",
displayName: "Font Color",
Expand Down Expand Up @@ -245,6 +247,17 @@ export class CellsSettingsCard extends Card {
}
});

gapWidth = new formattingSettings.NumUpDown({
name: "gapWidth",
displayName: "Gap width",
displayNameKey: "Visual_Cell_GapWidth",
value: 0,
options: {
minValue: { value: 0, type: powerbi.visuals.ValidatorType.Min },
maxValue: { value: 30, type: powerbi.visuals.ValidatorType.Max },
}
});

enableManualSizing = new formattingSettings.ToggleSwitch({
name: "enableManualSizing",
displayName: "Enable manual sizing",
Expand All @@ -266,24 +279,13 @@ export class CellsSettingsCard extends Card {
name: "height",
displayName: "Cell height",
displayNameKey: "Visual_Cell_height",
value: 25,
value: 60,
options: {
minValue: { value: 10, type: powerbi.visuals.ValidatorType.Min },
},
});


gapWidth = new formattingSettings.NumUpDown({
name: "gapWidth",
displayName: "Gap width",
displayNameKey: "Visual_Cell_GapWidth",
value: 0,
options: {
minValue: { value: 0, type: powerbi.visuals.ValidatorType.Min },
maxValue: { value: 30, type: powerbi.visuals.ValidatorType.Max },
}
});

name: string = "cells";
displayName: string = "Cells";
displayNameKey: string = "Visual_Cells";
Expand All @@ -293,21 +295,23 @@ export class CellsSettingsCard extends Card {
this.strokeColor,
this.selectedStrokeColor,
this.strokeWidth,
this.gapWidth,
this.enableManualSizing,
this.width,
this.height,
this.gapWidth,
];
}

export class GranularitySettingsCard extends Card {
topLevelSlice: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
show: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
name: "show",
displayName: "Show",
displayNameKey: "Visual_Show",
value: true,
});

topLevelSlice = this.show;

scaleColor = new formattingSettings.ColorPicker({
name: "scaleColor",
displayName: "Scale color",
Expand Down Expand Up @@ -382,13 +386,15 @@ export class GranularitySettingsCard extends Card {
}

export class LabelsSettingsCard extends Card {
topLevelSlice: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
show = new formattingSettings.ToggleSwitch({
name: "show",
displayName: "Show",
displayNameKey: "Visual_Show",
value: true,
});

topLevelSlice = this.show;

displayAll = new formattingSettings.ToggleSwitch({
name: "displayAll",
displayName: "Display all",
Expand Down Expand Up @@ -421,22 +427,24 @@ export class LabelsSettingsCard extends Card {
}

export class ScrollAutoAdjustment extends Card {
topLevelSlice: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
show: SimpleSlice<boolean> = new formattingSettings.ToggleSwitch({
name: "show",
displayName: "Show",
displayNameKey: "Visual_Show",
value: false,
});

topLevelSlice = this.show;

name: string = "scrollAutoAdjustment";
displayName: string = "Scroll Auto Adjustment";
displayNameKey: string = "Visual_ScrollAutoAdjustment";
}

export class TimeLineSettingsModel extends Model {
general = new GeneralSettings();
cursor = new CursorSettingsCard();

cursor = new CursorSettingsCard();
forceSelection = new ForceSelectionSettingsCard();
weeksDeterminationStandards = new WeeksDeterminationStandardsSettingsCard();
fiscalYearCalendar = new FiscalYearCalendarSettingsCard();
Expand Down
6 changes: 3 additions & 3 deletions test/visual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ describe("Timeline", () => {

if (fill !== "rgba(0, 0, 0, 0)" &&
fill !== Utils.DefaultCellColor &&
fillColorParsed.R !== unselectedFillColor.R &&
fillColorParsed.G !== unselectedFillColor.G &&
fillColorParsed.B !== unselectedFillColor.B
(fillColorParsed.R !== unselectedFillColor.R ||
fillColorParsed.G !== unselectedFillColor.G ||
fillColorParsed.B !== unselectedFillColor.B )
) {
selectedElements.push(element);
}
Expand Down

0 comments on commit d62add3

Please sign in to comment.